Some restructuring

This commit is contained in:
Dane Johnson 2023-02-08 15:04:04 -06:00
parent 2be456964a
commit 872cd8bec4
3 changed files with 57 additions and 52 deletions

View File

@ -1,11 +1,15 @@
bidict==0.22.1 bidict==0.22.1
click==8.1.3 click==8.1.3
colorama==0.4.6 colorama==0.4.6
Flask==2.2.2 dnspython==2.3.0
Flask-SocketIO==5.3.2 eventlet==0.33.3
itsdangerous==2.1.2 Flask==2.2.2
Jinja2==3.1.2 Flask-SocketIO==5.3.2
MarkupSafe==2.1.2 greenlet==2.0.2
python-engineio==4.3.4 itsdangerous==2.1.2
python-socketio==5.7.2 Jinja2==3.1.2
Werkzeug==2.2.2 MarkupSafe==2.1.2
python-engineio==4.3.4
python-socketio==5.7.2
six==1.16.0
Werkzeug==2.2.2

View File

@ -1,41 +1,42 @@
from flask import Flask, request from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room, rooms from flask_socketio import SocketIO, emit, join_room, rooms
from venture.code import make_code from gencode import make_code
from venture.game import Game from game import Game
games = {} games = {}
app = Flask(__name__) app = Flask('venture')
app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app, cors_allowed_origins="*")
socketio = SocketIO(app, cors_allowed_origins="*")
def with_game(listener):
if __name__ == '__main__': global games
socketio.run(app) room = rooms()[1]
game = games[room]
def with_game(listener): def inner(event, data={}):
global games data['game'] = game
room = rooms()[1] listener(game, data)
game = games[room] return inner
def inner(event, data={}):
data['game'] = game @socketio.on('new-game')
listener(game, data) def on_newgame():
return inner data = {}
code = make_code()
@socketio.on('new-game') games[code] = Game(code)
def on_newgame(): join_room(code)
data = {} emit('set-code', {'code': code})
code = make_code()
@socketio.on('contestant-join')
games[code] = Game(code) def on_join_contestant(data):
join_room(code) sid = request.sid
emit('set-code', {'code': code}) signature = data['signature']
room = data['room']
@socketio.on('contestant-join') join_room(room)
def on_join_contestant(data): games[room].add_contestant(sid, signature)
sid = request.sid emit('contestant-joined', {'sid': sid, 'signature': signature }, to=room)
signature = data['signature']
room = data['room'] def main():
join_room(room) socketio.run(app, host='0.0.0.0', debug=True)
games[room].add_contestant(sid, signature)
emit('contestant-joined', {'sid': sid, 'signature': signature }, to=room) if __name__ == '__main__':
main()