display objective awards in participant tables
This commit is contained in:
parent
53b1fc916c
commit
f55106c260
8 changed files with 160 additions and 24 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from typing import List, Dict, Tuple, TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
||||
from warchron.constants import (
|
||||
RefreshScope,
|
||||
|
|
@ -57,16 +58,30 @@ class CampaignController:
|
|||
self.app.view.display_campaign_sectors(sectors_for_display)
|
||||
scores = ScoreService.compute_scores(war, ContextType.CAMPAIGN, campaign_id)
|
||||
rows: List[CampaignParticipantScoreDTO] = []
|
||||
icon_map = {}
|
||||
vp_icon_map: Dict[str, QIcon] = {}
|
||||
objective_icon_maps: Dict[str, Dict[str, QIcon]] = {}
|
||||
if camp.is_over:
|
||||
icon_map = RankingIcon.compute_icons(
|
||||
vp_icon_map = RankingIcon.compute_icons(
|
||||
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():
|
||||
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]
|
||||
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(
|
||||
CampaignParticipantScoreDTO(
|
||||
campaign_participant_id=camp_part.id,
|
||||
|
|
@ -77,7 +92,8 @@ class CampaignController:
|
|||
victory_points=score.victory_points,
|
||||
narrative_points=dict(score.narrative_points),
|
||||
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 = [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from typing import List, Dict
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
||||
|
|
@ -118,6 +118,7 @@ class CampaignParticipantScoreDTO:
|
|||
narrative_points: Dict[str, int]
|
||||
tokens: int
|
||||
rank_icon: QIcon | None = None
|
||||
objective_icons: Dict[str, QIcon] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
|
|
@ -130,3 +131,4 @@ class WarParticipantScoreDTO:
|
|||
narrative_points: Dict[str, int]
|
||||
tokens: int
|
||||
rank_icon: QIcon | None = None
|
||||
objective_icons: Dict[str, QIcon] = field(default_factory=dict)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from warchron.constants import (
|
|||
ContextType,
|
||||
Icons,
|
||||
IconName,
|
||||
RANK_TO_ICON,
|
||||
VP_RANK_TO_ICON,
|
||||
NP_RANK_TO_ICON,
|
||||
)
|
||||
from warchron.model.war import War
|
||||
from warchron.model.score_service import ParticipantScore
|
||||
|
|
@ -20,16 +21,37 @@ class RankingIcon:
|
|||
context_type: ContextType,
|
||||
context_id: str,
|
||||
scores: Dict[str, ParticipantScore],
|
||||
*,
|
||||
objective_id: str | None = None,
|
||||
) -> Dict[str, QIcon]:
|
||||
|
||||
if objective_id is None:
|
||||
|
||||
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(
|
||||
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:
|
||||
base_icon = RANK_TO_ICON.get(rank, IconName.VPNTH)
|
||||
vp = scores[group[0]].victory_points
|
||||
if objective_id and rank not in icon_ranking:
|
||||
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(
|
||||
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:
|
||||
spent = token_map.get(pid, 0)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import List, Tuple, TYPE_CHECKING, Dict
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
||||
from warchron.constants import (
|
||||
RefreshScope,
|
||||
|
|
@ -53,12 +54,28 @@ class WarController:
|
|||
self.app.view.display_war_objectives(objectives_for_display)
|
||||
scores = ScoreService.compute_scores(war, ContextType.WAR, war.id)
|
||||
rows: List[WarParticipantScoreDTO] = []
|
||||
icon_map = {}
|
||||
vp_icon_map: dict[str, QIcon] = {}
|
||||
objective_icon_maps: Dict[str, Dict[str, QIcon]] = {}
|
||||
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():
|
||||
player_name = self.app.model.get_player_name(war_part.player_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(
|
||||
WarParticipantScoreDTO(
|
||||
war_participant_id=war_part.id,
|
||||
|
|
@ -68,7 +85,8 @@ class WarController:
|
|||
victory_points=score.victory_points,
|
||||
narrative_points=dict(score.narrative_points),
|
||||
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)
|
||||
|
|
@ -133,6 +151,7 @@ class WarController:
|
|||
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id
|
||||
)
|
||||
|
||||
# FIXME tie dialog with all participant even without tie
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue