detect campaign tie
This commit is contained in:
parent
7c9c941864
commit
60d8e6ca15
9 changed files with 203 additions and 116 deletions
|
|
@ -1,8 +1,8 @@
|
|||
from typing import List, TYPE_CHECKING
|
||||
from typing import List, Dict, TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
|
||||
from warchron.constants import RefreshScope, ContextType
|
||||
from warchron.constants import RefreshScope, ContextType, ItemType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from warchron.controller.app_controller import AppController
|
||||
|
|
@ -13,14 +13,18 @@ from warchron.controller.dtos import (
|
|||
RoundDTO,
|
||||
CampaignParticipantScoreDTO,
|
||||
)
|
||||
from warchron.model.exception import ForbiddenOperation, DomainError
|
||||
from warchron.model.war import War
|
||||
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.tie_manager import TieContext
|
||||
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
|
||||
from warchron.controller.closure_workflow import CampaignClosureWorkflow
|
||||
from warchron.view.tie_dialog import TieDialog
|
||||
|
||||
|
||||
class CampaignController:
|
||||
|
|
@ -101,10 +105,6 @@ class CampaignController:
|
|||
return self.app.model.add_campaign(
|
||||
self.app.navigation.selected_war_id, name, month
|
||||
)
|
||||
# self.app.is_dirty = True
|
||||
# self.app.navigation.refresh_and_select(
|
||||
# RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp.id
|
||||
# )
|
||||
|
||||
def edit_campaign(self, campaign_id: str) -> None:
|
||||
camp = self.app.model.get_campaign(campaign_id)
|
||||
|
|
@ -123,25 +123,46 @@ class CampaignController:
|
|||
if not campaign_id:
|
||||
return
|
||||
camp = self.app.model.get_campaign(campaign_id)
|
||||
if camp.is_over:
|
||||
return
|
||||
war = self.app.model.get_war_by_campaign(campaign_id)
|
||||
workflow = CampaignClosureWorkflow(self.app)
|
||||
try:
|
||||
ties = ClosureService.close_campaign(camp)
|
||||
except RuntimeError as e:
|
||||
QMessageBox.warning(self.app.view, "Cannot close campaign", str(e))
|
||||
return
|
||||
if ties:
|
||||
QMessageBox.information(
|
||||
workflow.start(war, camp)
|
||||
except DomainError as e:
|
||||
QMessageBox.warning(
|
||||
self.app.view,
|
||||
"Tie detected",
|
||||
"Campaign has unresolved ties.",
|
||||
"Deletion forbidden",
|
||||
str(e),
|
||||
)
|
||||
return
|
||||
self.app.is_dirty = True
|
||||
self.app.navigation.refresh(RefreshScope.CURRENT_SELECTION_DETAILS)
|
||||
self.app.navigation.refresh(RefreshScope.WARS_TREE)
|
||||
self.app.navigation.refresh_and_select(
|
||||
RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=campaign_id
|
||||
)
|
||||
|
||||
# Campaign participant methods
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[str, Dict[str, bool]]:
|
||||
bids_map = {}
|
||||
for ctx in contexts:
|
||||
players = [
|
||||
ParticipantOption(
|
||||
id=pid,
|
||||
name=self.app.model.get_participant_name(pid),
|
||||
)
|
||||
for pid in ctx.participants
|
||||
]
|
||||
counters = [war.get_influence_tokens(pid) for pid in ctx.participants]
|
||||
dialog = TieDialog(
|
||||
parent=self.app.view,
|
||||
players=players,
|
||||
counters=counters,
|
||||
context_type=ContextType.CAMPAIGN,
|
||||
context_id=ctx.context_id,
|
||||
)
|
||||
if not dialog.exec():
|
||||
raise ForbiddenOperation("Tie resolution cancelled")
|
||||
bids_map[ctx.context_id] = dialog.get_bids()
|
||||
return bids_map
|
||||
|
||||
def create_campaign_participant(self) -> CampaignParticipant | None:
|
||||
if not self.app.navigation.selected_campaign_id:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue