def import_table(): tablename = tables.generate_new_tablename() app.logger.info(f"importing table <{tablename}>") if 'data' not in request.files: return redirect(url_for('/')) file = request.files['data'] table = json.loads(file.read()) tables.store(tablename, table) return redirect(url_for('tables.play_table', tablename=tablename))
def test_update_components_only_specified_value(self, simple_table): tables.store('table1', { 'components': { 'component1': {'value1': 100, 'value2': 200}, }, 'kits': [], 'players': {}, }) tables.update_components('table1', [{'component1': {'value1': 11}}]) assert tables.get('table1')['components']['component1'] == {'value1': 11, 'value2': 200}
def simple_table(): table = { 'components': { 'component1': {'value1': 10, 'value2': 20}, }, 'kits': [], 'players': {}, } tables.store('table1', table) return table
def handle_sync_with_me(json): current_app.logger.info(f'sync with me') current_app.logger.debug(f'sync with me: {json}') tables.store(json['tablename'], json['tableData']) table = tables.get(json["tablename"]) emit("refresh table", { "tablename": json["tablename"], "table": table }, broadcast=True, room=json["tablename"])
def test_store_to_create_new(self): table = { 'components': { 'component1': {'value1': 10, 'value2': 20}, }, 'kits': [], 'players': {}, } tables.store('table1', table) read = tables.get('table1') assert read['components']['component1'] == {'value1': 10, 'value2': 20}
def table_with_several_components(): table = { 'components': { 'component1': {'value1': 10, 'value2': 20}, 'component2': {'value1': 110, 'value2': 120}, 'component3': {'value1': 210, 'value2': 220}, }, 'kits': [], 'players': {}, } tables.store('table1', table) return table
def handle_set_player(json): current_app.logger.info(f'set player') current_app.logger.debug(f'set player: {json}') table = tables.get(json["tablename"]) if not table: current_app.logger.error(f"table {json['tablename']} on set player") raise RuntimeError('table does not exist') player_name = json['player']['name'] table["players"][player_name] = { "name": player_name, "isHost": json['player']['isHost'], } tables.store(json["tablename"], table) emit("confirmed player name", {"player": {"name": player_name}})