auto create & edit battles

This commit is contained in:
Maxime Réaux 2026-01-30 18:55:39 +01:00
parent 9f676f6b9d
commit 6bd3ee31dc
10 changed files with 442 additions and 55 deletions

View file

@ -6,7 +6,7 @@ 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
from warchron.view.view import PlayerDialog, WarDialog, CampaignDialog, ObjectiveDialog, WarParticipantDialog, CampaignParticipantDialog, SectorDialog, ChoicesDialog, BattlesDialog
class Controller:
def __init__(self, model: Model, view: View):
@ -169,6 +169,7 @@ class Controller:
camp = self.model.get_campaign_by_round(round_id)
self.view.show_round_details(index=camp.get_round_index(round_id))
participants = self.model.get_round_participants(round_id)
sectors = camp.get_all_sectors()
choices_for_display = []
for part in participants:
choice = rnd.get_choice(part.id)
@ -183,6 +184,20 @@ class Controller:
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
))
self.view.display_round_battles(battles_for_display)
def on_tree_selection_changed(self, selection):
self.selected_war_id = None
@ -344,6 +359,9 @@ class Controller:
elif item_type == ItemType.CHOICE:
self.edit_round_choice(item_id)
self.refresh(RefreshScope.ROUND_DETAILS)
elif item_type == ItemType.BATTLE:
self.edit_round_battle(item_id)
self.refresh(RefreshScope.ROUND_DETAILS)
def delete_item(self, item_type: str, item_id: str):
reply = QMessageBox.question(
@ -576,13 +594,16 @@ class Controller:
self.is_dirty = True
self.refresh_and_select(RefreshScope.WARS_TREE, item_type=ItemType.ROUND, item_id=rnd.id)
# Choices methods
# Choice methods
def edit_round_choice(self, choice_id: str):
round_id = self.selected_round_id
if not round_id:
return
camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id)
# camp, rnd, participants, sectors = self.model.get_round_choices_data(round_id)
camp = self.model.get_campaign_by_round(round_id)
rnd = camp.get_round(round_id)
sectors = camp.get_sectors_in_round(round_id)
choice = rnd.get_choice(choice_id)
if not choice:
return
@ -591,17 +612,64 @@ class Controller:
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_priority_id = choice.priority_sector_id,
default_secondary_id = choice.secondary_sector_id,
default_comment = choice.comment,
)
if dialog.exec() != QDialog.DialogCode.Accepted:
return
rnd.set_choice(
participant_id=part.id,
priority_sector_id=dialog.get_priority_id(),
secondary_sector_id=dialog.get_secondary_id(),
# 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()
)
# Battle methods
def edit_round_battle(self, battle_id: str):
round_id = self.selected_round_id
if not round_id:
return
camp = self.model.get_campaign_by_round(round_id)
rnd = camp.get_round(round_id)
participants = camp.get_all_campaign_participants()
battle = rnd.get_battle(battle_id)
if not battle:
return
sect = camp.sectors[battle.sector_id]
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)
)
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,
)
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(),
)