Some restructuring
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user