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
click==8.1.3
colorama==0.4.6
Flask==2.2.2
Flask-SocketIO==5.3.2
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
python-engineio==4.3.4
python-socketio==5.7.2
Werkzeug==2.2.2
bidict==0.22.1
click==8.1.3
colorama==0.4.6
dnspython==2.3.0
eventlet==0.33.3
Flask==2.2.2
Flask-SocketIO==5.3.2
greenlet==2.0.2
itsdangerous==2.1.2
Jinja2==3.1.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_socketio import SocketIO, emit, join_room, rooms
from venture.code import make_code
from venture.game import Game
games = {}
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, cors_allowed_origins="*")
if __name__ == '__main__':
socketio.run(app)
def with_game(listener):
global games
room = rooms()[1]
game = games[room]
def inner(event, data={}):
data['game'] = game
listener(game, data)
return inner
@socketio.on('new-game')
def on_newgame():
data = {}
code = make_code()
games[code] = Game(code)
join_room(code)
emit('set-code', {'code': code})
@socketio.on('contestant-join')
def on_join_contestant(data):
sid = request.sid
signature = data['signature']
room = data['room']
join_room(room)
games[room].add_contestant(sid, signature)
emit('contestant-joined', {'sid': sid, 'signature': signature }, to=room)
from flask import Flask, request
from flask_socketio import SocketIO, emit, join_room, rooms
from gencode import make_code
from game import Game
games = {}
app = Flask('venture')
socketio = SocketIO(app, cors_allowed_origins="*")
def with_game(listener):
global games
room = rooms()[1]
game = games[room]
def inner(event, data={}):
data['game'] = game
listener(game, data)
return inner
@socketio.on('new-game')
def on_newgame():
data = {}
code = make_code()
games[code] = Game(code)
join_room(code)
emit('set-code', {'code': code})
@socketio.on('contestant-join')
def on_join_contestant(data):
sid = request.sid
signature = data['signature']
room = data['room']
join_room(room)
games[room].add_contestant(sid, signature)
emit('contestant-joined', {'sid': sid, 'signature': signature }, to=room)
def main():
socketio.run(app, host='0.0.0.0', debug=True)
if __name__ == '__main__':
main()