the_goth_cardgame_collection/games/poker/start.py

45 lines
1.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# games/poker/start.py
from games.poker.views.poker_menu_view import PokerMenuView
from games.poker.views.poker_table_view import PokerTableView
from models.database import Database
from resources.code_res.game_constants import CAT_LUCK, PK_MAX_BOTS
from resources.code_res.i18n import t
GAME_TITLE_KEY = "game_title_poker"
GAME_FOLDER_ID = "poker"
GAME_CATEGORY = CAT_LUCK
def start_game(context):
pid = context.profile["id"]
devils_acc = Database.get_active_devils_pk_account(pid)
if devils_acc is not None:
saved = Database.load_game_state(pid, GAME_FOLDER_ID)
menu_ref = PokerMenuView(context)
if saved is not None:
PokerTableView(
context,
variant_key=saved["variant_key"],
pk_account_id=devils_acc["id"],
bot_configs=[],
on_back_to_menu=lambda acc_id, msg="": menu_ref.show(preselect_id=acc_id, status_msg=msg),
resume_state_json=saved["state_json"],
)
else:
saved_bots = Database.load_bot_configs(pid, GAME_FOLDER_ID)
active_bots = [(lvl, name) for _idx, (name, lvl) in sorted(saved_bots.items()) if lvl >= 0][:PK_MAX_BOTS]
if not active_bots:
active_bots = [(2, t("bot_default_name", 1))]
PokerTableView(
context,
variant_key="poker_holdem",
pk_account_id=devils_acc["id"],
bot_configs=active_bots,
on_back_to_menu=lambda acc_id, msg="": menu_ref.show(preselect_id=acc_id, status_msg=msg),
)
return
Database.delete_game_state(pid, GAME_FOLDER_ID)
PokerMenuView(context).show()