!hex swap

This commit is contained in:
jona605a
2020-08-11 21:27:46 +02:00
parent 1d9831d773
commit 71467bbe16
3 changed files with 52 additions and 2 deletions

View File

@ -150,3 +150,40 @@ def drawHexPlacement(channel,player,position):
im.save(FILEPATH)
except:
logThis("Error drawing new hex on board (error code 1541")
def drawSwap(channel):
FILEPATH = "resources/games/hexBoards/board"+channel+".png"
with open("resources/games/hexGames.json", "r") as f:
data = json.load(f)
# Opens the image
try:
with Image.open(FILEPATH) as im:
d = ImageDraw.Draw(im,"RGBA")
# Write player names and color
for p in [1,2]:
playername = getName(data[channel]["players"][p-1])
x = X_NAME[p]
x -= NAME_fnt.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned
y = Y_NAME[p]
# Draw a half-size Hexagon to indicate the player's color
x -= NAMEHEXPADDING # To the left of both names
d.polygon([
(x, y),
(x+SMOL_WIDTH/2, y-SMOL_SIDELENGTH/2),
(x+SMOL_WIDTH, y),
(x+SMOL_WIDTH, y+SMOL_SIDELENGTH),
(x+SMOL_WIDTH/2, y+SMOL_SIDELENGTH*3/2),
(x, y+SMOL_SIDELENGTH),
],fill = PIECECOLOR[p % 2 + 1])
# Save
im.save(FILEPATH)
except:
logThis("Error drawing swap (error code 1542)")