split controller
This commit is contained in:
parent
701f6b3292
commit
7792a76f8e
11 changed files with 1212 additions and 987 deletions
42
src/warchron/controller/player_controller.py
Normal file
42
src/warchron/controller/player_controller.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
|
||||
from warchron.constants import RefreshScope
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from warchron.controller.app_controller import AppController
|
||||
from warchron.view.player_dialog import PlayerDialog
|
||||
|
||||
|
||||
class PlayerController:
|
||||
def __init__(self, app: "AppController"):
|
||||
self.app: AppController = app
|
||||
|
||||
def _validate_player_inputs(self, name: str) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.app.view, "Invalid name", "Player name cannot be empty."
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
def add_player(self) -> None:
|
||||
dialog = PlayerDialog(self.app.view)
|
||||
result = dialog.exec() # modal blocking dialog
|
||||
if result == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_player_name()
|
||||
if not self._validate_player_inputs(name):
|
||||
return
|
||||
self.app.model.add_player(name)
|
||||
self.app.is_dirty = True
|
||||
self.app.navigation.refresh(RefreshScope.PLAYERS_LIST)
|
||||
|
||||
def edit_player(self, player_id: str) -> None:
|
||||
play = self.app.model.get_player(player_id)
|
||||
player_dialog = PlayerDialog(self.app.view, default_name=play.name)
|
||||
if player_dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
name = player_dialog.get_player_name()
|
||||
if not self._validate_player_inputs(name):
|
||||
return
|
||||
self.app.model.update_player(player_id, name=name)
|
||||
Loading…
Add table
Add a link
Reference in a new issue