pixi integration is improving

This commit is contained in:
2020-12-14 23:07:03 +01:00
parent c194164e3c
commit 965b7a5ad7
4 changed files with 76 additions and 35 deletions

View File

@ -80,28 +80,44 @@ async def initGame(ws):
await ws.send_json(msg)
@api.route('/ws', websocket=True)
async def websocket(ws):
async def getHand(player, ws):
p = int(player)
c = the_game.players[p].cards
s = [x.json_serialise() for x in c]
msg = {"type": "message", "fct": "getHand", "cards": s}
await ws.send_json(msg)
async def ws_handler(ws):
await ws.accept()
the_game.websockets.append(ws)
try:
x = await ws.receive_json()
fct = x['fct']
if fct == 'playcard':
p = int(x['player'])
c = int(x['card'])
await play_card(p, c)
elif fct == 'setTrumpColor':
player = x['player']
color = x['color']
await set_trump_color(player, color)
elif fct == "requestInit":
print("before init")
await initGame(ws);
print("after init")
else:
print("confused :(")
while True:
try:
x = await ws.receive_json()
fct = x['fct']
if fct == 'playcard':
p = int(x['player'])
c = int(x['card'])
await play_card(p, c)
elif fct == 'setTrumpColor':
player = x['player']
color = x['color']
await set_trump_color(player, color)
elif fct == "requestInit":
await initGame(ws);
elif fct == "getHand":
player = x['player']
await getHand(player, ws)
else:
print("confused :(")
except WebSocketDisconnect:
the_game.websockets.remove(ws)
break;
except WebSocketDisconnect:
the_game.websockets.remove(ws)
@api.route('/ws', websocket=True)
async def websocket(ws):
task = asyncio.create_task(ws_handler(ws))
the_game.ws_tasks.append(task)
await task;