def room_settings(request, encoded_room_uuid): room = Room.get_for_encoded_uuid(encoded_room_uuid) panel = loader.get_template("bingosync/room_settings_panel.html").render( { "game": room.current_game, "room": room }, request) return JsonResponse({ "panel": panel, "settings": room.settings })
def new_card(request): data = json.loads(request.body.decode("utf8")) room = Room.get_for_encoded_uuid(data["room"]) player = _get_session_player(request.session, room) lockout_mode = LockoutMode.for_value(int(data["lockout_mode"])) hide_card = data["hide_card"] seed = data["seed"] custom_json = data.get("custom_json", "") #create new game game_type = GameType.for_value(int(data["game_type"])) try: # variant_type is not sent if the game only has 1 variant, so use it if # it's present but fall back to the regular game_type otherwise if "variant_type" in data: game_type = GameType.for_value(int(data["variant_type"])) except ValueError: pass generator = game_type.generator_instance() try: custom_board = generator.validate_custom_json(custom_json) except InvalidBoardException as e: return HttpResponseBadRequest("Invalid board: " + str(e)) if not seed: seed = str(random.randint(1, 1000000)) if game_type.uses_seed else "0" board_json = game_type.generator_instance().get_card(seed, custom_board) with transaction.atomic(): game = Game.from_board(board_json, room=room, game_type_value=game_type.value, lockout_mode_value=lockout_mode.value, seed=seed) if hide_card != room.hide_card: room.hide_card = hide_card room.update_active() # This saves the room new_card_event = NewCardEvent(player=player, player_color_value=player.color.value, game_type_value=game_type.value, seed=seed, hide_card=hide_card) new_card_event.save() publish_new_card_event(new_card_event) return HttpResponse("Recieved data: " + str(data))