Compare commits

..

2 commits

Author SHA1 Message Date
Maxime Réaux
f55106c260 display objective awards in participant tables 2026-03-03 15:39:30 +01:00
Maxime Réaux
53b1fc916c tie-break for narrative points 2026-03-03 11:52:07 +01:00
10 changed files with 354 additions and 41 deletions

View file

@ -15,6 +15,8 @@ RESOURCES_DIR = VIEW_ROOT / "resources"
ROLE_TYPE = Qt.ItemDataRole.UserRole ROLE_TYPE = Qt.ItemDataRole.UserRole
ROLE_ID = Qt.ItemDataRole.UserRole + 1 ROLE_ID = Qt.ItemDataRole.UserRole + 1
# TODO use StrEnum and auto() instead of str,Enum and "name"
class IconName(str, Enum): class IconName(str, Enum):
UNDO = "undo" UNDO = "undo"
@ -62,15 +64,30 @@ class IconName(str, Enum):
VPNTHDRAW = auto() VPNTHDRAW = auto()
VPNTHBREAK = auto() VPNTHBREAK = auto()
VPNTHTIEDRAW = auto() VPNTHTIEDRAW = auto()
NP1STDRAW = auto()
NP1STBREAK = auto()
NP1STTIEDRAW = auto()
NP2NDDRAW = auto()
NP2NDBREAK = auto()
NP2NDTIEDRAW = auto()
NP3RDDRAW = auto()
NP3RDBREAK = auto()
NP3RDTIEDRAW = auto()
RANK_TO_ICON = { VP_RANK_TO_ICON = {
1: IconName.VP1ST, 1: IconName.VP1ST,
2: IconName.VP2ND, 2: IconName.VP2ND,
3: IconName.VP3RD, 3: IconName.VP3RD,
4: IconName.VPNTH, 4: IconName.VPNTH,
} }
NP_RANK_TO_ICON = {
1: IconName.NP1ST,
2: IconName.NP2ND,
3: IconName.NP3RD,
}
class Icons: class Icons:
_icon_cache: Dict[IconName, QIcon] = {} _icon_cache: Dict[IconName, QIcon] = {}
@ -192,6 +209,54 @@ class Icons:
cls.get_pixmap(IconName.DRAW), cls.get_pixmap(IconName.DRAW),
cls.get_pixmap(IconName.TOKEN), cls.get_pixmap(IconName.TOKEN),
) )
elif name == IconName.NP1STDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP1ST),
cls.get_pixmap(IconName.DRAW),
)
elif name == IconName.NP1STBREAK:
pix = cls._compose(
cls.get_pixmap(IconName.NP1ST),
cls.get_pixmap(IconName.TOKEN),
)
elif name == IconName.NP1STTIEDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP1ST),
cls.get_pixmap(IconName.DRAW),
cls.get_pixmap(IconName.TOKEN),
)
elif name == IconName.NP2NDDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP2ND),
cls.get_pixmap(IconName.DRAW),
)
elif name == IconName.NP2NDBREAK:
pix = cls._compose(
cls.get_pixmap(IconName.NP2ND),
cls.get_pixmap(IconName.TOKEN),
)
elif name == IconName.NP2NDTIEDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP2ND),
cls.get_pixmap(IconName.DRAW),
cls.get_pixmap(IconName.TOKEN),
)
elif name == IconName.NP3RDDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP3RD),
cls.get_pixmap(IconName.DRAW),
)
elif name == IconName.NP3RDBREAK:
pix = cls._compose(
cls.get_pixmap(IconName.NP3RD),
cls.get_pixmap(IconName.TOKEN),
)
elif name == IconName.NP3RDTIEDRAW:
pix = cls._compose(
cls.get_pixmap(IconName.NP3RD),
cls.get_pixmap(IconName.DRAW),
cls.get_pixmap(IconName.TOKEN),
)
else: else:
path = RESOURCES_DIR / cls._paths[name] path = RESOURCES_DIR / cls._paths[name]
pix = QPixmap(path.as_posix()) pix = QPixmap(path.as_posix())
@ -245,3 +310,4 @@ class ContextType(StrEnum):
CAMPAIGN = "campaign" CAMPAIGN = "campaign"
CHOICE = "choice" CHOICE = "choice"
BATTLE = "battle" BATTLE = "battle"
OBJECTIVE = auto()

View file

@ -1,6 +1,7 @@
from typing import List, Dict, Tuple, TYPE_CHECKING from typing import List, Dict, Tuple, TYPE_CHECKING
from PyQt6.QtWidgets import QMessageBox, QDialog from PyQt6.QtWidgets import QMessageBox, QDialog
from PyQt6.QtGui import QIcon
from warchron.constants import ( from warchron.constants import (
RefreshScope, RefreshScope,
@ -57,16 +58,30 @@ class CampaignController:
self.app.view.display_campaign_sectors(sectors_for_display) self.app.view.display_campaign_sectors(sectors_for_display)
scores = ScoreService.compute_scores(war, ContextType.CAMPAIGN, campaign_id) scores = ScoreService.compute_scores(war, ContextType.CAMPAIGN, campaign_id)
rows: List[CampaignParticipantScoreDTO] = [] rows: List[CampaignParticipantScoreDTO] = []
icon_map = {} vp_icon_map: Dict[str, QIcon] = {}
objective_icon_maps: Dict[str, Dict[str, QIcon]] = {}
if camp.is_over: if camp.is_over:
icon_map = RankingIcon.compute_icons( vp_icon_map = RankingIcon.compute_icons(
war, ContextType.CAMPAIGN, campaign_id, scores war, ContextType.CAMPAIGN, campaign_id, scores
) )
for obj in war.get_all_objectives():
objective_icon_maps[obj.id] = RankingIcon.compute_icons(
war,
ContextType.CAMPAIGN,
f"{camp.id}:{obj.id}",
scores,
objective_id=obj.id,
)
for camp_part in camp.get_all_campaign_participants(): for camp_part in camp.get_all_campaign_participants():
war_part_id = camp_part.war_participant_id war_part_id = camp_part.war_participant_id
war_part = war.get_war_participant(war_part_id) war_part = war.get_war_participant(war_part_id)
player_name = self.app.model.get_player_name(war_part.player_id) player_name = self.app.model.get_player_name(war_part.player_id)
score = scores[war_part_id] score = scores[war_part_id]
objective_icons = {
obj_id: icon_map[war_part_id]
for obj_id, icon_map in objective_icon_maps.items()
if war_part_id in icon_map
}
rows.append( rows.append(
CampaignParticipantScoreDTO( CampaignParticipantScoreDTO(
campaign_participant_id=camp_part.id, campaign_participant_id=camp_part.id,
@ -77,7 +92,8 @@ class CampaignController:
victory_points=score.victory_points, victory_points=score.victory_points,
narrative_points=dict(score.narrative_points), narrative_points=dict(score.narrative_points),
tokens=war.get_influence_tokens(war_part.id), tokens=war.get_influence_tokens(war_part.id),
rank_icon=icon_map.get(war_part_id), rank_icon=vp_icon_map.get(war_part_id),
objective_icons=objective_icons,
) )
) )
objectives = [ objectives = [
@ -171,6 +187,18 @@ class CampaignController:
counters=counters, counters=counters,
context_type=ContextType.CAMPAIGN, context_type=ContextType.CAMPAIGN,
context_id=ctx.context_id, context_id=ctx.context_id,
context_name=None,
)
if ctx.context_type == ContextType.OBJECTIVE:
campaign_id, objective_id = ctx.context_id.split(":")
objective = war.objectives[objective_id]
dialog = TieDialog(
parent=self.app.view,
players=players,
counters=counters,
context_type=ctx.context_type,
context_id=ctx.context_id,
context_name=objective.name,
) )
if not dialog.exec(): if not dialog.exec():
TieResolver.cancel_tie_break( TieResolver.cancel_tie_break(

View file

@ -2,7 +2,6 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from warchron.controller.app_controller import AppController from warchron.controller.app_controller import AppController
from warchron.model.war import War from warchron.model.war import War
from warchron.model.campaign import Campaign from warchron.model.campaign import Campaign
from warchron.model.round import Round from warchron.model.round import Round
@ -45,6 +44,23 @@ class CampaignClosureWorkflow(ClosureWorkflow):
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids) TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
TieResolver.resolve_tie_state(war, tie, bids) TieResolver.resolve_tie_state(war, tie, bids)
ties = TieResolver.find_campaign_ties(war, campaign.id) ties = TieResolver.find_campaign_ties(war, campaign.id)
for objective_id in war.objectives:
ties = TieResolver.find_campaign_objective_ties(
war,
campaign.id,
objective_id,
)
while ties:
bids_map = self.app.campaigns.resolve_ties(war, ties)
for tie in ties:
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
TieResolver.resolve_tie_state(war, tie, bids)
ties = TieResolver.find_campaign_objective_ties(
war,
campaign.id,
objective_id,
)
ClosureService.finalize_campaign(campaign) ClosureService.finalize_campaign(campaign)
@ -60,4 +76,19 @@ class WarClosureWorkflow(ClosureWorkflow):
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids) TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
TieResolver.resolve_tie_state(war, tie, bids) TieResolver.resolve_tie_state(war, tie, bids)
ties = TieResolver.find_war_ties(war) ties = TieResolver.find_war_ties(war)
for objective_id in war.objectives:
ties = TieResolver.find_war_objective_ties(
war,
objective_id,
)
while ties:
bids_map = self.app.wars.resolve_ties(war, ties)
for tie in ties:
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
TieResolver.resolve_tie_state(war, tie, bids)
ties = TieResolver.find_war_objective_ties(
war,
objective_id,
)
ClosureService.finalize_war(war) ClosureService.finalize_war(war)

View file

@ -1,5 +1,5 @@
from typing import List, Dict from typing import List, Dict
from dataclasses import dataclass from dataclasses import dataclass, field
from PyQt6.QtGui import QIcon from PyQt6.QtGui import QIcon
@ -107,14 +107,6 @@ class BattleDTO:
player2_tooltip: str | None = None player2_tooltip: str | None = None
@dataclass(frozen=True, slots=True)
class ParticipantScoreDTO:
participant_id: str
player_name: str
victory_points: int
narrative_points: Dict[str, int]
@dataclass(frozen=True, slots=True) @dataclass(frozen=True, slots=True)
class CampaignParticipantScoreDTO: class CampaignParticipantScoreDTO:
campaign_participant_id: str campaign_participant_id: str
@ -126,6 +118,7 @@ class CampaignParticipantScoreDTO:
narrative_points: Dict[str, int] narrative_points: Dict[str, int]
tokens: int tokens: int
rank_icon: QIcon | None = None rank_icon: QIcon | None = None
objective_icons: Dict[str, QIcon] = field(default_factory=dict)
@dataclass(frozen=True, slots=True) @dataclass(frozen=True, slots=True)
@ -138,3 +131,4 @@ class WarParticipantScoreDTO:
narrative_points: Dict[str, int] narrative_points: Dict[str, int]
tokens: int tokens: int
rank_icon: QIcon | None = None rank_icon: QIcon | None = None
objective_icons: Dict[str, QIcon] = field(default_factory=dict)

View file

@ -6,7 +6,8 @@ from warchron.constants import (
ContextType, ContextType,
Icons, Icons,
IconName, IconName,
RANK_TO_ICON, VP_RANK_TO_ICON,
NP_RANK_TO_ICON,
) )
from warchron.model.war import War from warchron.model.war import War
from warchron.model.score_service import ParticipantScore from warchron.model.score_service import ParticipantScore
@ -20,21 +21,37 @@ class RankingIcon:
context_type: ContextType, context_type: ContextType,
context_id: str, context_id: str,
scores: Dict[str, ParticipantScore], scores: Dict[str, ParticipantScore],
*,
objective_id: str | None = None,
) -> Dict[str, QIcon]: ) -> Dict[str, QIcon]:
# scores = ScoreService.compute_scores(
# war, if objective_id is None:
# context_type,
# context_id, def value_getter(score: ParticipantScore) -> int:
# ) return score.victory_points
icon_ranking = VP_RANK_TO_ICON
else:
def value_getter(score: ParticipantScore) -> int:
return score.narrative_points.get(objective_id, 0)
icon_ranking = NP_RANK_TO_ICON
ranking = ResultChecker.get_effective_ranking( ranking = ResultChecker.get_effective_ranking(
war, context_type, context_id, scores war, context_type, context_id, scores, value_getter=value_getter
) )
icon_map = {} icon_map: Dict[str, QIcon] = {}
for rank, group, token_map in ranking: for rank, group, token_map in ranking:
base_icon = RANK_TO_ICON.get(rank, IconName.VPNTH) if objective_id and rank not in icon_ranking:
vp = scores[group[0]].victory_points continue
base_icon = icon_ranking.get(
rank, IconName.VPNTH if objective_id is None else None
)
if base_icon is None:
continue
value = value_getter(scores[group[0]])
original_group_size = sum( original_group_size = sum(
1 for s in scores.values() if s.victory_points == vp 1 for s in scores.values() if value_getter(s) == value
) )
for pid in group: for pid in group:
spent = token_map.get(pid, 0) spent = token_map.get(pid, 0)

View file

@ -1,6 +1,7 @@
from typing import List, Tuple, TYPE_CHECKING, Dict from typing import List, Tuple, TYPE_CHECKING, Dict
from PyQt6.QtWidgets import QMessageBox, QDialog from PyQt6.QtWidgets import QMessageBox, QDialog
from PyQt6.QtGui import QIcon
from warchron.constants import ( from warchron.constants import (
RefreshScope, RefreshScope,
@ -53,12 +54,28 @@ class WarController:
self.app.view.display_war_objectives(objectives_for_display) self.app.view.display_war_objectives(objectives_for_display)
scores = ScoreService.compute_scores(war, ContextType.WAR, war.id) scores = ScoreService.compute_scores(war, ContextType.WAR, war.id)
rows: List[WarParticipantScoreDTO] = [] rows: List[WarParticipantScoreDTO] = []
icon_map = {} vp_icon_map: dict[str, QIcon] = {}
objective_icon_maps: Dict[str, Dict[str, QIcon]] = {}
if war.is_over: if war.is_over:
icon_map = RankingIcon.compute_icons(war, ContextType.WAR, war_id, scores) vp_icon_map = RankingIcon.compute_icons(
war, ContextType.WAR, war_id, scores
)
for obj in war.get_all_objectives():
objective_icon_maps[obj.id] = RankingIcon.compute_icons(
war,
ContextType.WAR,
f"{war.id}:{obj.id}",
scores,
objective_id=obj.id,
)
for war_part in war.get_all_war_participants(): for war_part in war.get_all_war_participants():
player_name = self.app.model.get_player_name(war_part.player_id) player_name = self.app.model.get_player_name(war_part.player_id)
score = scores[war_part.id] score = scores[war_part.id]
objective_icons = {
obj_id: icon_map[war_part.id]
for obj_id, icon_map in objective_icon_maps.items()
if war_part.id in icon_map
}
rows.append( rows.append(
WarParticipantScoreDTO( WarParticipantScoreDTO(
war_participant_id=war_part.id, war_participant_id=war_part.id,
@ -68,7 +85,8 @@ class WarController:
victory_points=score.victory_points, victory_points=score.victory_points,
narrative_points=dict(score.narrative_points), narrative_points=dict(score.narrative_points),
tokens=war.get_influence_tokens(war_part.id), tokens=war.get_influence_tokens(war_part.id),
rank_icon=icon_map.get(war_part.id), rank_icon=vp_icon_map.get(war_part.id),
objective_icons=objective_icons,
) )
) )
self.app.view.display_war_participants(rows, objectives_for_display) self.app.view.display_war_participants(rows, objectives_for_display)
@ -133,6 +151,7 @@ class WarController:
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id
) )
# FIXME tie dialog with all participant even without tie
def resolve_ties( def resolve_ties(
self, war: War, contexts: List[TieContext] self, war: War, contexts: List[TieContext]
) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]: ) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]:
@ -155,6 +174,18 @@ class WarController:
counters=counters, counters=counters,
context_type=ContextType.WAR, context_type=ContextType.WAR,
context_id=ctx.context_id, context_id=ctx.context_id,
context_name=None,
)
if ctx.context_type == ContextType.OBJECTIVE:
_, objective_id = ctx.context_id.split(":")
objective = war.objectives[objective_id]
dialog = TieDialog(
parent=self.app.view,
players=players,
counters=counters,
context_type=ctx.context_type,
context_id=ctx.context_id,
context_name=objective.name,
) )
if not dialog.exec(): if not dialog.exec():
TieResolver.cancel_tie_break( TieResolver.cancel_tie_break(

View file

@ -1,5 +1,5 @@
from __future__ import annotations from __future__ import annotations
from typing import List, Tuple, Dict, TYPE_CHECKING from typing import List, Tuple, Dict, TYPE_CHECKING, Callable
from collections import defaultdict from collections import defaultdict
from warchron.constants import ContextType from warchron.constants import ContextType
@ -36,15 +36,16 @@ class ResultChecker:
context_type: ContextType, context_type: ContextType,
context_id: str, context_id: str,
scores: Dict[str, ParticipantScore], scores: Dict[str, ParticipantScore],
value_getter: Callable[[ParticipantScore], int],
) -> List[Tuple[int, List[str], Dict[str, int]]]: ) -> List[Tuple[int, List[str], Dict[str, int]]]:
vp_buckets: Dict[int, List[str]] = defaultdict(list) buckets: Dict[int, List[str]] = defaultdict(list)
for pid, score in scores.items(): for pid, score in scores.items():
vp_buckets[score.victory_points].append(pid) buckets[value_getter(score)].append(pid)
sorted_vps = sorted(vp_buckets.keys(), reverse=True) sorted_vps = sorted(buckets.keys(), reverse=True)
ranking: List[Tuple[int, List[str], Dict[str, int]]] = [] ranking: List[Tuple[int, List[str], Dict[str, int]]] = []
current_rank = 1 current_rank = 1
for vp in sorted_vps: for value in sorted_vps:
participants = vp_buckets[vp] participants = buckets[value]
if context_type == ContextType.WAR and len(participants) > 1: if context_type == ContextType.WAR and len(participants) > 1:
subgroups = ResultChecker._secondary_sorting_war(war, participants) subgroups = ResultChecker._secondary_sorting_war(war, participants)
for subgroup in subgroups: for subgroup in subgroups:
@ -57,7 +58,7 @@ class ResultChecker:
continue continue
# normal tie-break if tie persists # normal tie-break if tie persists
if not TieResolver.is_tie_resolved( if not TieResolver.is_tie_resolved(
war, context_type, context_id, vp war, context_type, context_id, value
): ):
ranking.append( ranking.append(
(current_rank, subgroup, {pid: 0 for pid in subgroup}) (current_rank, subgroup, {pid: 0 for pid in subgroup})
@ -80,7 +81,7 @@ class ResultChecker:
continue continue
# no tie # no tie
if len(participants) == 1 or not TieResolver.is_tie_resolved( if len(participants) == 1 or not TieResolver.is_tie_resolved(
war, context_type, context_id, vp war, context_type, context_id, value
): ):
ranking.append( ranking.append(
(current_rank, participants, {pid: 0 for pid in participants}) (current_rank, participants, {pid: 0 for pid in participants})
@ -118,7 +119,11 @@ class ResultChecker:
war, ContextType.CAMPAIGN, campaign.id war, ContextType.CAMPAIGN, campaign.id
) )
ranking = ResultChecker.get_effective_ranking( ranking = ResultChecker.get_effective_ranking(
war, ContextType.CAMPAIGN, campaign.id, scores war,
ContextType.CAMPAIGN,
campaign.id,
scores,
lambda s: s.victory_points,
) )
for rank, group, _ in ranking: for rank, group, _ in ranking:
if pid in group: if pid in group:

View file

@ -6,7 +6,7 @@ from warchron.constants import ContextType
from warchron.model.exception import ForbiddenOperation from warchron.model.exception import ForbiddenOperation
from warchron.model.war import War from warchron.model.war import War
from warchron.model.war_event import InfluenceSpent, TieResolved from warchron.model.war_event import InfluenceSpent, TieResolved
from warchron.model.score_service import ScoreService from warchron.model.score_service import ScoreService, ParticipantScore
@dataclass @dataclass
@ -85,13 +85,72 @@ class TieResolver:
) )
return ties return ties
@staticmethod
def find_campaign_objective_ties(
war: War,
campaign_id: str,
objective_id: str,
) -> List[TieContext]:
base_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)
ties: List[TieContext] = []
context_id = f"{campaign_id}:{objective_id}"
for score_value, participants in buckets.items():
if len(participants) <= 1:
continue
if TieResolver.is_tie_resolved(
war,
ContextType.OBJECTIVE,
context_id,
score_value,
):
continue
if not TieResolver.can_tie_be_resolved(
war,
ContextType.OBJECTIVE,
context_id,
participants,
):
war.events.append(
TieResolved(
None,
ContextType.OBJECTIVE,
context_id,
score_value,
)
)
continue
ties.append(
TieContext(
context_type=ContextType.OBJECTIVE,
context_id=context_id,
participants=participants,
score_value=score_value,
)
)
return ties
@staticmethod @staticmethod
def find_war_ties(war: War) -> List[TieContext]: def find_war_ties(war: War) -> List[TieContext]:
from warchron.model.result_checker import ResultChecker from warchron.model.result_checker import ResultChecker
scores = ScoreService.compute_scores(war, ContextType.WAR, war.id) scores = ScoreService.compute_scores(war, ContextType.WAR, war.id)
ranking = ResultChecker.get_effective_ranking( ranking = ResultChecker.get_effective_ranking(
war, ContextType.WAR, war.id, scores war,
ContextType.WAR,
war.id,
scores,
value_getter=lambda s: s.victory_points,
) )
ties: List[TieContext] = [] ties: List[TieContext] = []
for _, group, _ in ranking: for _, group, _ in ranking:
@ -115,6 +174,80 @@ class TieResolver:
) )
return ties return ties
@staticmethod
def find_war_objective_ties(
war: War,
objective_id: str,
) -> List[TieContext]:
from warchron.model.result_checker import ResultChecker
base_scores = ScoreService.compute_scores(
war,
ContextType.WAR,
war.id,
)
scores = TieResolver._build_objective_scores(
base_scores,
objective_id,
)
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),
)
ties: List[TieContext] = []
for _, group, _ in ranking:
if len(group) <= 1:
continue
score_value = scores[group[0]].victory_points
context_id = f"{war.id}:{objective_id}"
if TieResolver.is_tie_resolved(
war,
ContextType.OBJECTIVE,
context_id,
score_value,
):
continue
if not TieResolver.can_tie_be_resolved(
war,
ContextType.OBJECTIVE,
context_id,
group,
):
war.events.append(
TieResolved(
None,
ContextType.OBJECTIVE,
context_id,
score_value,
)
)
continue
ties.append(
TieContext(
context_type=ContextType.OBJECTIVE,
context_id=context_id,
participants=group,
score_value=score_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 @staticmethod
def apply_bids( def apply_bids(
war: War, war: War,

View file

@ -26,6 +26,7 @@ class TieDialog(QDialog):
counters: List[int], counters: List[int],
context_type: ContextType, context_type: ContextType,
context_id: str, context_id: str,
context_name: str | None = None,
) -> None: ) -> None:
super().__init__(parent) super().__init__(parent)
self._context_id = context_id self._context_id = context_id
@ -33,7 +34,7 @@ class TieDialog(QDialog):
self.ui: Ui_tieDialog = Ui_tieDialog() self.ui: Ui_tieDialog = Ui_tieDialog()
self.ui.setupUi(self) # type: ignore self.ui.setupUi(self) # type: ignore
self.setWindowIcon(Icons.get(IconName.WARCHRONICO)) self.setWindowIcon(Icons.get(IconName.WARCHRONICO))
self.ui.tieContext.setText(self._get_context_title(context_type)) self.ui.tieContext.setText(self._get_context_title(context_type, context_name))
grid = self.ui.playersGridLayout grid = self.ui.playersGridLayout
icon_path = (RESOURCES_DIR / Icons._paths[IconName.TOKENS]).as_posix() icon_path = (RESOURCES_DIR / Icons._paths[IconName.TOKENS]).as_posix()
token_html = ( token_html = (
@ -72,11 +73,14 @@ class TieDialog(QDialog):
return {pid: checkbox.isChecked() for pid, checkbox in self._checkboxes.items()} return {pid: checkbox.isChecked() for pid, checkbox in self._checkboxes.items()}
@staticmethod @staticmethod
def _get_context_title(context_type: ContextType) -> str: def _get_context_title(
context_type: ContextType, context_name: str | None = None
) -> str:
titles = { titles = {
ContextType.BATTLE: "Battle tie", ContextType.BATTLE: "Battle tie",
ContextType.CAMPAIGN: "Campaign tie", ContextType.CAMPAIGN: "Campaign tie",
ContextType.WAR: "War tie", ContextType.WAR: "War tie",
ContextType.CHOICE: "Choice tie", ContextType.CHOICE: "Choice tie",
ContextType.OBJECTIVE: f"Objective tie: {context_name}",
} }
return titles.get(context_type, "Tie") return titles.get(context_type, "Tie")

View file

@ -413,6 +413,8 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
for obj in objectives: for obj in objectives:
value = part.narrative_points.get(obj.id, 0) value = part.narrative_points.get(obj.id, 0)
NP_item = QtWidgets.QTableWidgetItem(str(value)) NP_item = QtWidgets.QTableWidgetItem(str(value))
if part.objective_icons.get(obj.id):
NP_item.setIcon(part.objective_icons[obj.id])
table.setItem(row, col, NP_item) table.setItem(row, col, NP_item)
col += 1 col += 1
table.setItem(row, col, token_item) table.setItem(row, col, token_item)
@ -545,6 +547,8 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
for obj in objectives: for obj in objectives:
value = part.narrative_points.get(obj.id, 0) value = part.narrative_points.get(obj.id, 0)
NP_item = QtWidgets.QTableWidgetItem(str(value)) NP_item = QtWidgets.QTableWidgetItem(str(value))
if part.objective_icons.get(obj.id):
NP_item.setIcon(part.objective_icons[obj.id])
table.setItem(row, col, NP_item) table.setItem(row, col, NP_item)
col += 1 col += 1
table.setItem(row, col, token_item) table.setItem(row, col, token_item)