compute campaign points from rounds

This commit is contained in:
Maxime Réaux 2026-02-19 14:17:42 +01:00
parent 45c1d69a3f
commit 7c9c941864
9 changed files with 165 additions and 75 deletions

View file

@ -2,21 +2,22 @@ from typing import List, TYPE_CHECKING
from PyQt6.QtWidgets import QMessageBox, QDialog
from warchron.constants import RefreshScope
from warchron.constants import RefreshScope, ContextType
if TYPE_CHECKING:
from warchron.controller.app_controller import AppController
from warchron.controller.dtos import (
ParticipantOption,
ObjectiveDTO,
CampaignParticipantDTO,
SectorDTO,
RoundDTO,
CampaignParticipantScoreDTO,
)
from warchron.model.campaign import Campaign
from warchron.model.campaign_participant import CampaignParticipant
from warchron.model.sector import Sector
from warchron.model.closure_service import ClosureService
from warchron.model.score_service import ScoreService
from warchron.view.campaign_dialog import CampaignDialog
from warchron.view.campaign_participant_dialog import CampaignParticipantDialog
from warchron.view.sector_dialog import SectorDialog
@ -45,17 +46,28 @@ class CampaignController:
for sect in sectors
]
self.app.view.display_campaign_sectors(sectors_for_display)
camp_parts = camp.get_all_campaign_participants()
participants_for_display: List[CampaignParticipantDTO] = [
CampaignParticipantDTO(
id=p.id,
player_name=self.app.model.get_participant_name(p.war_participant_id),
leader=p.leader or "",
theme=p.theme or "",
scores = ScoreService.compute_scores(war, ContextType.CAMPAIGN, campaign_id)
rows: List[CampaignParticipantScoreDTO] = []
for camp_part in camp.get_all_campaign_participants():
war_part_id = camp_part.war_participant_id
war_part = war.get_war_participant(war_part_id)
player_name = self.app.model.get_player_name(war_part.player_id)
score = scores[war_part_id]
rows.append(
CampaignParticipantScoreDTO(
campaign_participant_id=camp_part.id,
war_participant_id=war_part_id,
player_name=player_name,
leader=camp_part.leader or "",
theme=camp_part.theme or "",
victory_points=score.victory_points,
narrative_points=dict(score.narrative_points),
)
)
for p in camp_parts
objectives = [
ObjectiveDTO(o.id, o.name, o.description) for o in war.get_all_objectives()
]
self.app.view.display_campaign_participants(participants_for_display)
self.app.view.display_campaign_participants(rows, objectives)
self.app.view.endCampaignBtn.setEnabled(not camp.is_over)
def _validate_campaign_inputs(self, name: str, month: int) -> bool:
@ -189,7 +201,7 @@ class CampaignController:
self.app.view, "Invalid name", "Sector name cannot be empty."
)
return False
# allow same objectives in different fields?
# TODO allow same objectives in different fields?
return True
def create_sector(self) -> Sector | None: