42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# games/blackjack/start.py
|
|
from games.blackjack.views.blackjack_menu_view import BlackjackMenuView
|
|
from games.blackjack.views.blackjack_table_view import BlackjackTableView
|
|
from models.database import Database
|
|
from resources.code_res.game_constants import CAT_LUCK
|
|
|
|
GAME_TITLE_KEY = "game_title_blackjack"
|
|
GAME_FOLDER_ID = "blackjack"
|
|
GAME_CATEGORY = CAT_LUCK
|
|
|
|
|
|
def start_game(context):
|
|
pid = context.profile["id"]
|
|
devils_acc = Database.get_active_devils_bj_account(pid)
|
|
|
|
if devils_acc is not None:
|
|
saved = Database.load_game_state(pid, GAME_FOLDER_ID)
|
|
menu_ref = BlackjackMenuView(context)
|
|
if saved is not None:
|
|
BlackjackTableView(
|
|
context,
|
|
variant_key=saved["variant_key"],
|
|
bj_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]
|
|
BlackjackTableView(
|
|
context,
|
|
variant_key="bj_classic",
|
|
bj_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)
|
|
BlackjackMenuView(context).show() |