From b1bde76319ce379c969ed5a7b42047dff7bd10b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20R=C3=A9aux?= Date: Thu, 5 Mar 2026 11:37:14 +0100 Subject: [PATCH] fix display campaign NP draw/break in participant table --- .../controller/campaign_controller.py | 3 +- src/warchron/controller/war_controller.py | 3 +- src/warchron/model/tie_manager.py | 51 +++++++------------ 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/warchron/controller/campaign_controller.py b/src/warchron/controller/campaign_controller.py index 00ffa3d..a5a81dc 100644 --- a/src/warchron/controller/campaign_controller.py +++ b/src/warchron/controller/campaign_controller.py @@ -67,7 +67,7 @@ class CampaignController: for obj in war.get_all_objectives(): objective_icon_maps[obj.id] = RankingIcon.compute_icons( war, - ContextType.CAMPAIGN, + ContextType.OBJECTIVE, f"{camp.id}:{obj.id}", scores, objective_id=obj.id, @@ -201,6 +201,7 @@ class CampaignController: context_name=objective.name, ) if not dialog.exec(): + # FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE) TieResolver.cancel_tie_break( war, ContextType.CAMPAIGN, ctx.context_id, ctx.score_value ) diff --git a/src/warchron/controller/war_controller.py b/src/warchron/controller/war_controller.py index ddec9ff..f5981c9 100644 --- a/src/warchron/controller/war_controller.py +++ b/src/warchron/controller/war_controller.py @@ -63,7 +63,7 @@ class WarController: for obj in war.get_all_objectives(): objective_icon_maps[obj.id] = RankingIcon.compute_icons( war, - ContextType.WAR, + ContextType.OBJECTIVE, f"{war.id}:{obj.id}", scores, objective_id=obj.id, @@ -188,6 +188,7 @@ class WarController: context_name=objective.name, ) if not dialog.exec(): + # FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE) TieResolver.cancel_tie_break( war, ContextType.WAR, ctx.context_id, ctx.score_value ) diff --git a/src/warchron/model/tie_manager.py b/src/warchron/model/tie_manager.py index 13a220b..74b2428 100644 --- a/src/warchron/model/tie_manager.py +++ b/src/warchron/model/tie_manager.py @@ -91,28 +91,25 @@ class TieResolver: campaign_id: str, objective_id: str, ) -> List[TieContext]: - base_scores = ScoreService.compute_scores( + scores = ScoreService.compute_scores( war, ContextType.CAMPAIGN, campaign_id, ) - scores = TieResolver._build_objective_scores( - base_scores, - objective_id, - ) buckets: DefaultDict[int, List[str]] = defaultdict(list) for pid, score in scores.items(): - buckets[score.victory_points].append(pid) + np_value = score.narrative_points.get(objective_id, 0) + buckets[np_value].append(pid) ties: List[TieContext] = [] context_id = f"{campaign_id}:{objective_id}" - for score_value, participants in buckets.items(): + for np_value, participants in buckets.items(): if len(participants) <= 1: continue if TieResolver.is_tie_resolved( war, ContextType.OBJECTIVE, context_id, - score_value, + np_value, ): continue if not TieResolver.can_tie_be_resolved( @@ -126,7 +123,7 @@ class TieResolver: None, ContextType.OBJECTIVE, context_id, - score_value, + np_value, ) ) continue @@ -135,7 +132,7 @@ class TieResolver: context_type=ContextType.OBJECTIVE, context_id=context_id, participants=participants, - score_value=score_value, + score_value=np_value, ) ) return ties @@ -181,33 +178,33 @@ class TieResolver: ) -> List[TieContext]: from warchron.model.result_checker import ResultChecker - base_scores = ScoreService.compute_scores( + scores = ScoreService.compute_scores( war, ContextType.WAR, war.id, ) - scores = TieResolver._build_objective_scores( - base_scores, - objective_id, - ) + + def value_getter(score: ParticipantScore) -> int: + return score.narrative_points.get(objective_id, 0) + ranking = ResultChecker.get_effective_ranking( war, ContextType.OBJECTIVE, f"{war.id}:{objective_id}", scores, - value_getter=lambda s: s.narrative_points.get(objective_id, 0), + value_getter=value_getter, ) ties: List[TieContext] = [] for _, group, _ in ranking: if len(group) <= 1: continue - score_value = scores[group[0]].victory_points + np_value = value_getter(scores[group[0]]) context_id = f"{war.id}:{objective_id}" if TieResolver.is_tie_resolved( war, ContextType.OBJECTIVE, context_id, - score_value, + np_value, ): continue if not TieResolver.can_tie_be_resolved( @@ -221,7 +218,7 @@ class TieResolver: None, ContextType.OBJECTIVE, context_id, - score_value, + np_value, ) ) continue @@ -230,24 +227,11 @@ class TieResolver: context_type=ContextType.OBJECTIVE, context_id=context_id, participants=group, - score_value=score_value, + score_value=np_value, ) ) return ties - @staticmethod - def _build_objective_scores( - base_scores: Dict[str, ParticipantScore], - objective_id: str, - ) -> Dict[str, ParticipantScore]: - return { - pid: ParticipantScore( - victory_points=score.narrative_points.get(objective_id, 0), - narrative_points={}, - ) - for pid, score in base_scores.items() - } - @staticmethod def apply_bids( war: War, @@ -269,6 +253,7 @@ class TieResolver: ) ) + # FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE) @staticmethod def cancel_tie_break( war: War,