the_goth_cardgame_collection/games/poker/views/poker_menu_view.py

82 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
# games/poker/views/poker_menu_view.py
from __future__ import annotations
from games.poker.views.poker_table_view import PokerTableView
from models.database import Database
from resources.code_res.game_constants import (
GOLD_MAX_ACCOUNTS,
PK_MAX_BOTS,
PK_STARTING_GOLD,
PK_VARIANTS,
XP_TO_GOLD_AMOUNT,
)
from resources.code_res.i18n import t
from view.widgets.luck_pouch_menu_base import LuckPouchMenuBase
GAME_FOLDER_ID = "poker"
class PokerMenuView(LuckPouchMenuBase):
GAME_FOLDER_ID = GAME_FOLDER_ID
LAST_ACC_SETTING_PREFIX = "last_pk_account"
STARTING_GOLD = PK_STARTING_GOLD
MAX_BOTS = PK_MAX_BOTS
REQUIRES_MIN_ONE_BOT = True
DEVILS_DEFAULT_VARIANT = "poker_holdem"
KEY_TOPBAR = "pk_menu_topbar"
KEY_HEADER_GOLD = "pk_header_gold"
KEY_SEC1_TITLE = "pk_sec1_title"
KEY_BOTS_TITLE = "pk_bots_sec_title"
KEY_SEC3_TITLE = "pk_sec3_title"
KEY_GOLD_DISPLAY = "pk_gold_display_lbl"
KEY_DEFAULT_ACC_NAME = "pk_default_acc_name"
KEY_ERR_DUPLICATE = "pk_err_duplicate_name"
def _default_bot_configs(self) -> dict[int, tuple[str, int]]:
return {
0: (t("bot_default_name", 1), 1),
1: (t("bot_default_name", 2), 2),
}
def _get_active_devils_account(self, pid: int):
return Database.get_active_devils_pk_account(pid)
def _get_accounts(self, pid: int):
return Database.get_poker_accounts(pid)
def _get_account(self, acc_id: int):
return Database.get_poker_account(acc_id)
def _create_account(self, pid: int, name: str):
return Database.create_poker_account(pid, name)
def _delete_account(self, acc_id: int):
Database.delete_poker_account(acc_id)
def _exchange_xp(self, pid: int, acc_id: int):
return Database.exchange_xp_for_pk_gold(pid, acc_id)
def _variants_dict(self) -> dict[str, dict]:
return PK_VARIANTS
def _min_entry_for_variant(self, _v_key: str, cfg: dict) -> int:
return cfg["min_entry"]
def _format_variant_desc(self, _v_key: str, cfg: dict) -> str:
return t("pk_variant_desc", cfg["sb"], cfg["bb"], cfg["min_entry"])
def _format_limit_info(self, dyn_xp_cost: int) -> str:
classic = PK_VARIANTS["poker_holdem"]
return t("pk_acc_limit_info", GOLD_MAX_ACCOUNTS, classic["sb"], classic["bb"], dyn_xp_cost, XP_TO_GOLD_AMOUNT)
def _launch_table(self, variant_key: str, acc_id: int, bots: list, resume_json: str | None = None):
PokerTableView(
self.ctx,
variant_key=variant_key,
pk_account_id=acc_id,
bot_configs=bots,
on_back_to_menu=lambda aid, msg="": self.show(preselect_id=aid, status_msg=msg),
resume_state_json=resume_json,
)