refacto update ; pretify code
This commit is contained in:
parent
6bd3ee31dc
commit
fbb1c913ba
11 changed files with 594 additions and 310 deletions
|
|
@ -6,7 +6,18 @@ from warchron.view.view import View
|
|||
|
||||
from warchron.constants import ItemType, RefreshScope
|
||||
from warchron.controller.dtos import ParticipantOption
|
||||
from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, ObjectiveDialog, WarParticipantDialog, CampaignParticipantDialog, SectorDialog, ChoicesDialog, BattlesDialog
|
||||
from warchron.view.view import (
|
||||
PlayerDialog,
|
||||
WarDialog,
|
||||
CampaignDialog,
|
||||
ObjectiveDialog,
|
||||
WarParticipantDialog,
|
||||
CampaignParticipantDialog,
|
||||
SectorDialog,
|
||||
ChoicesDialog,
|
||||
BattlesDialog,
|
||||
)
|
||||
|
||||
|
||||
class Controller:
|
||||
def __init__(self, model: Model, view: View):
|
||||
|
|
@ -38,7 +49,9 @@ class Controller:
|
|||
self.view.addObjectiveBtn.clicked.connect(self.add_objective)
|
||||
self.view.addWarParticipantBtn.clicked.connect(self.add_war_participant)
|
||||
self.view.addSectorBtn.clicked.connect(self.add_sector)
|
||||
self.view.addCampaignParticipantBtn.clicked.connect(self.add_campaign_participant)
|
||||
self.view.addCampaignParticipantBtn.clicked.connect(
|
||||
self.add_campaign_participant
|
||||
)
|
||||
self.view.on_edit_item = self.edit_item
|
||||
self.view.on_delete_item = self.delete_item
|
||||
|
||||
|
|
@ -48,7 +61,9 @@ class Controller:
|
|||
self.view,
|
||||
"Unsaved changes",
|
||||
"You have unsaved changes. Do you want to save before quitting?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel
|
||||
QMessageBox.StandardButton.Yes
|
||||
| QMessageBox.StandardButton.No
|
||||
| QMessageBox.StandardButton.Cancel,
|
||||
)
|
||||
if reply == QMessageBox.StandardButton.Yes:
|
||||
self.save()
|
||||
|
|
@ -56,15 +71,15 @@ class Controller:
|
|||
return False
|
||||
return True
|
||||
|
||||
# Menu bar methods
|
||||
|
||||
# Menu bar methods
|
||||
|
||||
def new(self):
|
||||
if self.is_dirty:
|
||||
reply = QMessageBox.question(
|
||||
self.view,
|
||||
"Unsaved changes",
|
||||
"Discard current campaign?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
|
@ -81,7 +96,7 @@ class Controller:
|
|||
self.view,
|
||||
"Unsaved changes",
|
||||
"Discard current campaign?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
|
@ -94,7 +109,7 @@ class Controller:
|
|||
self.refresh_players_view()
|
||||
self.refresh_wars_view()
|
||||
self.update_window_title()
|
||||
|
||||
|
||||
def save(self):
|
||||
if not self.current_file:
|
||||
self.save_as()
|
||||
|
|
@ -112,7 +127,7 @@ class Controller:
|
|||
self.is_dirty = False
|
||||
self.update_window_title()
|
||||
|
||||
# Display methods
|
||||
# Display methods
|
||||
|
||||
def update_window_title(self):
|
||||
base = "WarChron"
|
||||
|
|
@ -139,10 +154,9 @@ class Controller:
|
|||
self.view.display_war_objectives(objectives)
|
||||
participants = war.get_all_war_participants()
|
||||
participants_for_display = [
|
||||
(self.model.get_player_name(p.id), p.faction, p.id)
|
||||
for p in participants
|
||||
(self.model.get_player_name(p.id), p.faction, p.id) for p in participants
|
||||
]
|
||||
self.view.display_war_participants(participants_for_display)
|
||||
self.view.display_war_participants(participants_for_display)
|
||||
|
||||
def _fill_campaign_details(self, campaign_id: str):
|
||||
camp = self.model.get_campaign(campaign_id)
|
||||
|
|
@ -155,14 +169,23 @@ class Controller:
|
|||
major_name = war.get_objective_name(sect.major_objective_id)
|
||||
minor_name = war.get_objective_name(sect.minor_objective_id)
|
||||
influence_name = war.get_objective_name(sect.influence_objective_id)
|
||||
sectors_for_display.append((sect.name,round_index,major_name,minor_name,influence_name,sect.id))
|
||||
sectors_for_display.append(
|
||||
(
|
||||
sect.name,
|
||||
round_index,
|
||||
major_name,
|
||||
minor_name,
|
||||
influence_name,
|
||||
sect.id,
|
||||
)
|
||||
)
|
||||
self.view.display_campaign_sectors(sectors_for_display)
|
||||
participants = camp.get_all_campaign_participants()
|
||||
participants_for_display = [
|
||||
(self.model.get_player_name(p.id), p.leader, p.theme, p.id)
|
||||
for p in participants
|
||||
]
|
||||
self.view.display_campaign_participants(participants_for_display)
|
||||
self.view.display_campaign_participants(participants_for_display)
|
||||
|
||||
def _fill_round_details(self, round_id: str):
|
||||
rnd = self.model.get_round(round_id)
|
||||
|
|
@ -174,29 +197,47 @@ class Controller:
|
|||
for part in participants:
|
||||
choice = rnd.get_choice(part.id)
|
||||
if not choice:
|
||||
choice=self.model.create_choice(round_id=rnd.id, participant_id=part.id)
|
||||
priority_name = camp.get_sector_name(choice.priority_sector_id) if choice else ""
|
||||
secondary_name = camp.get_sector_name(choice.secondary_sector_id) if choice else ""
|
||||
choices_for_display.append((
|
||||
self.model.get_player_name(part.id),
|
||||
priority_name,
|
||||
secondary_name,
|
||||
choice.participant_id
|
||||
))
|
||||
choice = self.model.create_choice(
|
||||
round_id=rnd.id, participant_id=part.id
|
||||
)
|
||||
priority_name = (
|
||||
camp.get_sector_name(choice.priority_sector_id) if choice else ""
|
||||
)
|
||||
secondary_name = (
|
||||
camp.get_sector_name(choice.secondary_sector_id) if choice else ""
|
||||
)
|
||||
choices_for_display.append(
|
||||
(
|
||||
self.model.get_player_name(part.id),
|
||||
priority_name,
|
||||
secondary_name,
|
||||
choice.participant_id,
|
||||
)
|
||||
)
|
||||
self.view.display_round_choices(choices_for_display)
|
||||
battles_for_display = []
|
||||
for sect in sectors:
|
||||
battle = rnd.get_battle(sect.id)
|
||||
if not battle:
|
||||
battle=self.model.create_battle(round_id=rnd.id, sector_id=sect.id)
|
||||
player_1_name = self.model.get_player_name(battle.player_1_id) if battle.player_1_id else ""
|
||||
player_2_name = self.model.get_player_name(battle.player_2_id) if battle.player_2_id else ""
|
||||
battles_for_display.append((
|
||||
camp.get_sector_name(battle.sector_id),
|
||||
player_1_name,
|
||||
player_2_name,
|
||||
battle.sector_id
|
||||
))
|
||||
battle = self.model.create_battle(round_id=rnd.id, sector_id=sect.id)
|
||||
player_1_name = (
|
||||
self.model.get_player_name(battle.player_1_id)
|
||||
if battle.player_1_id
|
||||
else ""
|
||||
)
|
||||
player_2_name = (
|
||||
self.model.get_player_name(battle.player_2_id)
|
||||
if battle.player_2_id
|
||||
else ""
|
||||
)
|
||||
battles_for_display.append(
|
||||
(
|
||||
camp.get_sector_name(battle.sector_id),
|
||||
player_1_name,
|
||||
player_2_name,
|
||||
battle.sector_id,
|
||||
)
|
||||
)
|
||||
self.view.display_round_battles(battles_for_display)
|
||||
|
||||
def on_tree_selection_changed(self, selection):
|
||||
|
|
@ -248,9 +289,11 @@ class Controller:
|
|||
self._fill_round_details(self.selected_round_id)
|
||||
self.update_window_title()
|
||||
|
||||
# Common command methods
|
||||
# Common command methods
|
||||
|
||||
def refresh_and_select(self, scope: RefreshScope, *, item_type: ItemType, item_id: str):
|
||||
def refresh_and_select(
|
||||
self, scope: RefreshScope, *, item_type: ItemType, item_id: str
|
||||
):
|
||||
self.refresh(scope)
|
||||
self.view.select_tree_item(item_type=item_type, item_id=item_id)
|
||||
|
||||
|
|
@ -261,7 +304,7 @@ class Controller:
|
|||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_player_name()
|
||||
if not self._validate_player_inputs(name):
|
||||
return
|
||||
return
|
||||
self.model.update_player(item_id, name=name)
|
||||
self.refresh(RefreshScope.PLAYERS_LIST)
|
||||
elif item_type == ItemType.WAR:
|
||||
|
|
@ -273,20 +316,28 @@ class Controller:
|
|||
if not self._validate_war_inputs(name, year):
|
||||
return
|
||||
self.model.update_war(item_id, name=name, year=year)
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war.id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war.id
|
||||
)
|
||||
elif item_type == ItemType.CAMPAIGN:
|
||||
camp = self.model.get_campaign(item_id)
|
||||
dialog = CampaignDialog(self.view, default_name=camp.name, default_month=camp.month)
|
||||
dialog = CampaignDialog(
|
||||
self.view, default_name=camp.name, default_month=camp.month
|
||||
)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_campaign_name()
|
||||
month = dialog.get_campaign_month()
|
||||
if not self._validate_campaign_inputs(name, month):
|
||||
return
|
||||
self.model.update_campaign(item_id, name=name, month=month)
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp.id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp.id
|
||||
)
|
||||
elif item_type == ItemType.OBJECTIVE:
|
||||
obj = self.model.get_objective(item_id)
|
||||
dialog = ObjectiveDialog(self.view, default_name=obj.name, default_description=obj.description)
|
||||
dialog = ObjectiveDialog(
|
||||
self.view, default_name=obj.name, default_description=obj.description
|
||||
)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_objective_name()
|
||||
description = dialog.get_objective_description()
|
||||
|
|
@ -298,11 +349,11 @@ class Controller:
|
|||
part = self.model.get_war_participant(item_id)
|
||||
player = self.model.get_player(part.id)
|
||||
dialog = WarParticipantDialog(
|
||||
self.view,
|
||||
players=[player],
|
||||
default_player_id=part.id,
|
||||
default_faction=part.faction,
|
||||
editable_player=False
|
||||
self.view,
|
||||
players=[player],
|
||||
default_player_id=part.id,
|
||||
default_faction=part.faction,
|
||||
editable_player=False,
|
||||
)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
faction = dialog.get_participant_faction()
|
||||
|
|
@ -331,12 +382,12 @@ class Controller:
|
|||
minor_id = dialog.get_minor_id()
|
||||
influence_id = dialog.get_influence_id()
|
||||
self.model.update_sector(
|
||||
item_id,
|
||||
item_id,
|
||||
name=name,
|
||||
round_id=round_id,
|
||||
major_id=major_id,
|
||||
minor_id=minor_id,
|
||||
influence_id=influence_id
|
||||
round_id=round_id,
|
||||
major_id=major_id,
|
||||
minor_id=minor_id,
|
||||
influence_id=influence_id,
|
||||
)
|
||||
self.refresh(RefreshScope.CAMPAIGN_DETAILS)
|
||||
elif item_type == ItemType.CAMPAIGN_PARTICIPANT:
|
||||
|
|
@ -344,17 +395,19 @@ class Controller:
|
|||
player = self.model.get_player(part.id)
|
||||
part_opt = [ParticipantOption(id=player.id, name=player.name)]
|
||||
dialog = CampaignParticipantDialog(
|
||||
self.view,
|
||||
participants=part_opt,
|
||||
default_participant_id=part.id,
|
||||
default_leader=part.leader,
|
||||
default_theme=part.theme,
|
||||
editable_player=False
|
||||
self.view,
|
||||
participants=part_opt,
|
||||
default_participant_id=part.id,
|
||||
default_leader=part.leader,
|
||||
default_theme=part.theme,
|
||||
editable_player=False,
|
||||
)
|
||||
if dialog.exec() == QDialog.DialogCode.Accepted:
|
||||
leader = dialog.get_participant_leader()
|
||||
theme = dialog.get_participant_theme()
|
||||
self.model.update_campaign_participant(item_id, leader=leader, theme=theme)
|
||||
self.model.update_campaign_participant(
|
||||
item_id, leader=leader, theme=theme
|
||||
)
|
||||
self.refresh(RefreshScope.CAMPAIGN_DETAILS)
|
||||
elif item_type == ItemType.CHOICE:
|
||||
self.edit_round_choice(item_id)
|
||||
|
|
@ -368,7 +421,7 @@ class Controller:
|
|||
self.view,
|
||||
"Confirm deletion",
|
||||
"Are you sure you want to delete this item?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
|
|
@ -382,7 +435,9 @@ class Controller:
|
|||
war = self.model.get_war_by_campaign(item_id)
|
||||
war_id = war.id
|
||||
self.model.remove_campaign(item_id)
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id
|
||||
)
|
||||
elif item_type == ItemType.OBJECTIVE:
|
||||
self.model.remove_objective(item_id)
|
||||
self.refresh(RefreshScope.WAR_DETAILS)
|
||||
|
|
@ -399,22 +454,22 @@ class Controller:
|
|||
camp = self.model.get_campaign_by_round(item_id)
|
||||
camp_id = camp.id
|
||||
self.model.remove_round(item_id)
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp_id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp_id
|
||||
)
|
||||
self.is_dirty = True
|
||||
|
||||
# Player methods
|
||||
# Player methods
|
||||
|
||||
def _validate_player_inputs(self, name: str) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"Player name cannot be empty."
|
||||
self.view, "Invalid name", "Player name cannot be empty."
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
def add_player(self):
|
||||
|
||||
def add_player(self):
|
||||
dialog = PlayerDialog(self.view)
|
||||
result = dialog.exec() # modal blocking dialog
|
||||
if result == QDialog.DialogCode.Accepted:
|
||||
|
|
@ -423,29 +478,25 @@ class Controller:
|
|||
return
|
||||
self.model.add_player(name)
|
||||
self.is_dirty = True
|
||||
self.refresh(RefreshScope.PLAYERS_LIST)
|
||||
self.refresh(RefreshScope.PLAYERS_LIST)
|
||||
|
||||
# War methods
|
||||
# War methods
|
||||
|
||||
def _validate_war_inputs(self, name: str, year: int) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"War name cannot be empty."
|
||||
)
|
||||
QMessageBox.warning(self.view, "Invalid name", "War name cannot be empty.")
|
||||
return False
|
||||
if not (1970 <= year <= 3000):
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid year",
|
||||
"Year must be between 1970 and 3000."
|
||||
self.view, "Invalid year", "Year must be between 1970 and 3000."
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
def add_war(self):
|
||||
dialog = WarDialog(self.view, default_year=self.model.get_default_war_values()["year"])
|
||||
def add_war(self):
|
||||
dialog = WarDialog(
|
||||
self.view, default_year=self.model.get_default_war_values()["year"]
|
||||
)
|
||||
result = dialog.exec() # modal blocking dialog
|
||||
if result == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_war_name()
|
||||
|
|
@ -454,16 +505,16 @@ class Controller:
|
|||
return
|
||||
war = self.model.add_war(name, year)
|
||||
self.is_dirty = True
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war.id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war.id
|
||||
)
|
||||
|
||||
# Objective methods
|
||||
# Objective methods
|
||||
|
||||
def _validate_objective_inputs(self, name: str, description: str) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"Objective name cannot be empty."
|
||||
self.view, "Invalid name", "Objective name cannot be empty."
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
|
@ -477,12 +528,12 @@ class Controller:
|
|||
name = dialog.get_objective_name()
|
||||
description = dialog.get_objective_description()
|
||||
if not self._validate_objective_inputs(name, description):
|
||||
return
|
||||
return
|
||||
self.model.add_objective(self.selected_war_id, name, description)
|
||||
self.is_dirty = True
|
||||
self.refresh(RefreshScope.WAR_DETAILS)
|
||||
|
||||
# War participant methods
|
||||
# War participant methods
|
||||
|
||||
def add_war_participant(self):
|
||||
if not self.selected_war_id:
|
||||
|
|
@ -494,26 +545,22 @@ class Controller:
|
|||
player_id = dialog.get_player_id()
|
||||
faction = dialog.get_participant_faction()
|
||||
if not player_id:
|
||||
return
|
||||
return
|
||||
self.model.add_war_participant(self.selected_war_id, player_id, faction)
|
||||
self.is_dirty = True
|
||||
self.refresh(RefreshScope.WAR_DETAILS)
|
||||
|
||||
# Campaign methods
|
||||
# Campaign methods
|
||||
|
||||
def _validate_campaign_inputs(self, name: str, month: int) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"Campaign name cannot be empty."
|
||||
self.view, "Invalid name", "Campaign name cannot be empty."
|
||||
)
|
||||
return False
|
||||
if not (1 <= month <= 12):
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid month",
|
||||
"Month must be between 1 and 12."
|
||||
self.view, "Invalid month", "Month must be between 1 and 12."
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
|
@ -521,7 +568,12 @@ class Controller:
|
|||
def add_campaign(self):
|
||||
if not self.selected_war_id:
|
||||
return
|
||||
dialog = CampaignDialog(self.view, default_month=self.model.get_default_campaign_values(self.selected_war_id)["month"])
|
||||
dialog = CampaignDialog(
|
||||
self.view,
|
||||
default_month=self.model.get_default_campaign_values(self.selected_war_id)[
|
||||
"month"
|
||||
],
|
||||
)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
name = dialog.get_campaign_name()
|
||||
|
|
@ -530,15 +582,22 @@ class Controller:
|
|||
return
|
||||
camp = self.model.add_campaign(self.selected_war_id, name, month)
|
||||
self.is_dirty = True
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp.id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp.id
|
||||
)
|
||||
|
||||
# Campaign participant methods
|
||||
# Campaign participant methods
|
||||
|
||||
def add_campaign_participant(self):
|
||||
if not self.selected_campaign_id:
|
||||
return
|
||||
participants = self.model.get_available_war_participants(self.selected_campaign_id)
|
||||
part_opts = [ParticipantOption(id=p.id, name=self.model.get_player_name(p.id)) for p in participants]
|
||||
participants = self.model.get_available_war_participants(
|
||||
self.selected_campaign_id
|
||||
)
|
||||
part_opts = [
|
||||
ParticipantOption(id=p.id, name=self.model.get_player_name(p.id))
|
||||
for p in participants
|
||||
]
|
||||
dialog = CampaignParticipantDialog(self.view, participants=part_opts)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
|
|
@ -546,19 +605,21 @@ class Controller:
|
|||
leader = dialog.get_participant_leader()
|
||||
theme = dialog.get_participant_theme()
|
||||
if not player_id:
|
||||
return
|
||||
self.model.add_campaign_participant(self.selected_campaign_id, player_id, leader, theme)
|
||||
return
|
||||
self.model.add_campaign_participant(
|
||||
self.selected_campaign_id, player_id, leader, theme
|
||||
)
|
||||
self.is_dirty = True
|
||||
self.refresh(RefreshScope.CAMPAIGN_DETAILS)
|
||||
|
||||
# Sector methods
|
||||
# Sector methods
|
||||
|
||||
def _validate_sector_inputs(self, name: str, round_id: str, major_id: str, minor_id: str, influence_id:str) -> bool:
|
||||
def _validate_sector_inputs(
|
||||
self, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str
|
||||
) -> bool:
|
||||
if not name.strip():
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"Sector name cannot be empty."
|
||||
self.view, "Invalid name", "Sector name cannot be empty."
|
||||
)
|
||||
return False
|
||||
# allow same objectives in different fields?
|
||||
|
|
@ -571,7 +632,9 @@ class Controller:
|
|||
camp = self.model.get_campaign(self.selected_campaign_id)
|
||||
rounds = camp.get_all_rounds()
|
||||
objectives = war.get_all_objectives()
|
||||
dialog = SectorDialog(self.view, default_name="", rounds=rounds, objectives=objectives)
|
||||
dialog = SectorDialog(
|
||||
self.view, default_name="", rounds=rounds, objectives=objectives
|
||||
)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
name = dialog.get_sector_name()
|
||||
|
|
@ -579,22 +642,28 @@ class Controller:
|
|||
major_id = dialog.get_major_id()
|
||||
minor_id = dialog.get_minor_id()
|
||||
influence_id = dialog.get_influence_id()
|
||||
if not self._validate_sector_inputs(name, round_id, major_id, minor_id, influence_id):
|
||||
return
|
||||
self.model.add_sector(self.selected_campaign_id, name, round_id, major_id, minor_id, influence_id)
|
||||
if not self._validate_sector_inputs(
|
||||
name, round_id, major_id, minor_id, influence_id
|
||||
):
|
||||
return
|
||||
self.model.add_sector(
|
||||
self.selected_campaign_id, name, round_id, major_id, minor_id, influence_id
|
||||
)
|
||||
self.is_dirty = True
|
||||
self.refresh(RefreshScope.CAMPAIGN_DETAILS)
|
||||
|
||||
# Round methods
|
||||
# Round methods
|
||||
|
||||
def add_round(self):
|
||||
if not self.selected_campaign_id:
|
||||
return
|
||||
rnd = self.model.add_round(self.selected_campaign_id)
|
||||
self.is_dirty = True
|
||||
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id)
|
||||
self.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id
|
||||
)
|
||||
|
||||
# Choice methods
|
||||
# Choice methods
|
||||
|
||||
def edit_round_choice(self, choice_id: str):
|
||||
round_id = self.selected_round_id
|
||||
|
|
@ -609,27 +678,27 @@ class Controller:
|
|||
return
|
||||
part = camp.participants[choice.participant_id]
|
||||
player = self.model.get_player(part.id)
|
||||
part_opt = ParticipantOption(id=player.id, name=player.name)
|
||||
part_opt = ParticipantOption(id=player.id, name=player.name)
|
||||
dialog = ChoicesDialog(
|
||||
self.view,
|
||||
participants = [part_opt],
|
||||
participants=[part_opt],
|
||||
default_participant_id=part.id,
|
||||
sectors=sectors,
|
||||
default_priority_id = choice.priority_sector_id,
|
||||
default_secondary_id = choice.secondary_sector_id,
|
||||
default_comment = choice.comment,
|
||||
default_priority_id=choice.priority_sector_id,
|
||||
default_secondary_id=choice.secondary_sector_id,
|
||||
default_comment=choice.comment,
|
||||
)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
# TODO replace by update_choice through self.model...
|
||||
rnd.update_choice(
|
||||
participant_id = part.id,
|
||||
priority_sector_id = dialog.get_priority_id(),
|
||||
secondary_sector_id = dialog.get_secondary_id(),
|
||||
comment = dialog.get_comment()
|
||||
self.model.update_choice(
|
||||
round_id=round_id,
|
||||
participant_id=part.id,
|
||||
priority_sector_id=dialog.get_priority_id(),
|
||||
secondary_sector_id=dialog.get_secondary_id(),
|
||||
comment=dialog.get_comment(),
|
||||
)
|
||||
|
||||
# Battle methods
|
||||
# Battle methods
|
||||
|
||||
def edit_round_battle(self, battle_id: str):
|
||||
round_id = self.selected_round_id
|
||||
|
|
@ -645,31 +714,28 @@ class Controller:
|
|||
part_opts: list[ParticipantOption] = []
|
||||
for part in participants:
|
||||
player = self.model.get_player(part.id)
|
||||
part_opts.append(
|
||||
ParticipantOption(id=part.id, name=player.name)
|
||||
)
|
||||
part_opts.append(ParticipantOption(id=part.id, name=player.name))
|
||||
dialog = BattlesDialog(
|
||||
self.view,
|
||||
sectors = [sect],
|
||||
default_sector_id = sect.id,
|
||||
players = part_opts,
|
||||
default_player_1_id = battle.player_1_id,
|
||||
default_player_2_id = battle.player_2_id,
|
||||
default_winner_id = battle.winner_id,
|
||||
default_score = battle.score,
|
||||
default_victory_condition = battle.victory_condition,
|
||||
default_comment = battle.comment,
|
||||
sectors=[sect],
|
||||
default_sector_id=sect.id,
|
||||
players=part_opts,
|
||||
default_player_1_id=battle.player_1_id,
|
||||
default_player_2_id=battle.player_2_id,
|
||||
default_winner_id=battle.winner_id,
|
||||
default_score=battle.score,
|
||||
default_victory_condition=battle.victory_condition,
|
||||
default_comment=battle.comment,
|
||||
)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
# TODO replace by update_battle through self.model...
|
||||
rnd.update_battle(
|
||||
sector_id = sect.id,
|
||||
player_1_id = dialog.get_player_1_id(),
|
||||
player_2_id = dialog.get_player_2_id(),
|
||||
winner_id = dialog.get_winner_id(),
|
||||
score = dialog.get_score(),
|
||||
victory_condition = dialog.get_victory_condition(),
|
||||
comment = dialog.get_comment(),
|
||||
self.model.update_battle(
|
||||
round_id=round_id,
|
||||
sector_id=sect.id,
|
||||
player_1_id=dialog.get_player_1_id(),
|
||||
player_2_id=dialog.get_player_2_id(),
|
||||
winner_id=dialog.get_winner_id(),
|
||||
score=dialog.get_score(),
|
||||
victory_condition=dialog.get_victory_condition(),
|
||||
comment=dialog.get_comment(),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ParticipantOption:
|
||||
id: str
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue