mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Load campaign data lazily.
Error checking comes later, but the new game wizard opens much faster by not spending time creating theaters it doesn't need. Fixes https://github.com/Khopa/dcs_liberation/issues/469
This commit is contained in:
parent
5d4fccd438
commit
fd454dce74
@ -128,7 +128,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
def create_game(campaign_path: Path, blue: str, red: str,
|
def create_game(campaign_path: Path, blue: str, red: str,
|
||||||
supercarrier: bool) -> Game:
|
supercarrier: bool) -> Game:
|
||||||
campaign = Campaign.from_json(campaign_path)
|
campaign = Campaign.from_json(campaign_path)
|
||||||
generator = GameGenerator(blue, red, campaign.theater,
|
generator = GameGenerator(blue, red, campaign.load_theater(),
|
||||||
Settings(supercarrier=supercarrier),
|
Settings(supercarrier=supercarrier),
|
||||||
start_date=datetime.today(),
|
start_date=datetime.today(),
|
||||||
starting_budget=650,
|
starting_budget=650,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
from PySide2 import QtGui
|
from PySide2 import QtGui
|
||||||
from PySide2.QtCore import QItemSelectionModel
|
from PySide2.QtCore import QItemSelectionModel
|
||||||
@ -21,7 +21,8 @@ class Campaign:
|
|||||||
icon_name: str
|
icon_name: str
|
||||||
authors: str
|
authors: str
|
||||||
description: str
|
description: str
|
||||||
theater: ConflictTheater
|
data: Dict[str, Any]
|
||||||
|
path: Path
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, path: Path) -> Campaign:
|
def from_json(cls, path: Path) -> Campaign:
|
||||||
@ -29,10 +30,17 @@ class Campaign:
|
|||||||
data = json.load(campaign_file)
|
data = json.load(campaign_file)
|
||||||
|
|
||||||
sanitized_theater = data["theater"].replace(" ", "")
|
sanitized_theater = data["theater"].replace(" ", "")
|
||||||
return cls(data["name"], f"Terrain_{sanitized_theater}",
|
return cls(
|
||||||
data.get("authors", "???"),
|
data["name"],
|
||||||
data.get("description", ""),
|
f"Terrain_{sanitized_theater}",
|
||||||
ConflictTheater.from_json(path.parent, data))
|
data.get("authors", "???"),
|
||||||
|
data.get("description", ""),
|
||||||
|
data,
|
||||||
|
path
|
||||||
|
)
|
||||||
|
|
||||||
|
def load_theater(self) -> ConflictTheater:
|
||||||
|
return ConflictTheater.from_json(self.path.parent, self.data)
|
||||||
|
|
||||||
|
|
||||||
def load_campaigns() -> List[Campaign]:
|
def load_campaigns() -> List[Campaign]:
|
||||||
|
|||||||
@ -58,7 +58,7 @@ class NewGameWizard(QtWidgets.QWizard):
|
|||||||
if selectedCampaign is None:
|
if selectedCampaign is None:
|
||||||
selectedCampaign = self.campaigns[0]
|
selectedCampaign = self.campaigns[0]
|
||||||
|
|
||||||
conflictTheater = selectedCampaign.theater
|
conflictTheater = selectedCampaign.load_theater()
|
||||||
|
|
||||||
timePeriod = db.TIME_PERIODS[list(db.TIME_PERIODS.keys())[self.field("timePeriod")]]
|
timePeriod = db.TIME_PERIODS[list(db.TIME_PERIODS.keys())[self.field("timePeriod")]]
|
||||||
midGame = self.field("midGame")
|
midGame = self.field("midGame")
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
<strong>Author(s): {{ campaign.authors }}</strong>
|
<strong>Author(s): {{ campaign.authors }}</strong>
|
||||||
<br/>
|
|
||||||
<br/>
|
|
||||||
<strong>Number of control points:</strong> {{ campaign.theater.controlpoints|length }}
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
{{ campaign.description|safe }}
|
{{ campaign.description|safe }}
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
<strong>Auteur(s) : {{ campaign.authors }}</strong>
|
<strong>Auteur(s) : {{ campaign.authors }}</strong>
|
||||||
<br/>
|
|
||||||
<br/>
|
|
||||||
<strong>Nombre de points :</strong> {{ campaign.theater.controlpoints|length }}
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
{{ campaign.description|safe }}
|
{{ campaign.description|safe }}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user