mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Remember mod choices in the NGW.
This commit is contained in:
parent
cf47dd82d7
commit
47831d43b5
@ -2,11 +2,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, fields
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import dcs.statics
|
import dcs.statics
|
||||||
|
import yaml
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
from game.factions.faction import Faction
|
from game.factions.faction import Faction
|
||||||
@ -31,6 +33,7 @@ from ..armedforces.armedforces import ArmedForces
|
|||||||
from ..armedforces.forcegroup import ForceGroup
|
from ..armedforces.forcegroup import ForceGroup
|
||||||
from ..campaignloader.campaignairwingconfig import CampaignAirWingConfig
|
from ..campaignloader.campaignairwingconfig import CampaignAirWingConfig
|
||||||
from ..data.groups import GroupTask
|
from ..data.groups import GroupTask
|
||||||
|
from ..persistence.paths import liberation_user_dir
|
||||||
from ..plugins import LuaPluginManager
|
from ..plugins import LuaPluginManager
|
||||||
from ..profiling import logged_duration
|
from ..profiling import logged_duration
|
||||||
from ..settings import Settings
|
from ..settings import Settings
|
||||||
@ -64,6 +67,38 @@ class ModSettings:
|
|||||||
high_digit_sams: bool = False
|
high_digit_sams: bool = False
|
||||||
ov10a_bronco: bool = False
|
ov10a_bronco: bool = False
|
||||||
|
|
||||||
|
def save_player_settings(self) -> None:
|
||||||
|
"""Saves the player's global settings to the user directory."""
|
||||||
|
settings: dict[str, dict[str, bool]] = {}
|
||||||
|
for field in fields(self):
|
||||||
|
settings[field.name] = self.__dict__[field.name]
|
||||||
|
|
||||||
|
with self._player_settings_file.open("w", encoding="utf-8") as settings_file:
|
||||||
|
yaml.dump(settings, settings_file, sort_keys=False, explicit_start=True)
|
||||||
|
|
||||||
|
def merge_player_settings(self) -> None:
|
||||||
|
"""Updates with the player's global settings."""
|
||||||
|
settings_path = self._player_settings_file
|
||||||
|
if not settings_path.exists():
|
||||||
|
return
|
||||||
|
with settings_path.open(encoding="utf-8") as settings_file:
|
||||||
|
data = yaml.safe_load(settings_file)
|
||||||
|
|
||||||
|
for mod_name, enabled in data.items():
|
||||||
|
if mod_name not in self.__dict__:
|
||||||
|
logging.warning(
|
||||||
|
"Unexpected mod key found in %s: %s. Ignoring.",
|
||||||
|
settings_path,
|
||||||
|
mod_name,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
self.__dict__[mod_name] = enabled
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _player_settings_file(self) -> Path:
|
||||||
|
"""Returns the path to the player's global settings file."""
|
||||||
|
return liberation_user_dir() / "mods.yaml"
|
||||||
|
|
||||||
|
|
||||||
class GameGenerator:
|
class GameGenerator:
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|||||||
@ -96,6 +96,9 @@ class NewGameWizard(QtWidgets.QWizard):
|
|||||||
default_settings = Settings()
|
default_settings = Settings()
|
||||||
default_settings.merge_player_settings()
|
default_settings.merge_player_settings()
|
||||||
|
|
||||||
|
mod_settings = ModSettings()
|
||||||
|
mod_settings.merge_player_settings()
|
||||||
|
|
||||||
self.lua_plugin_manager = LuaPluginManager.load()
|
self.lua_plugin_manager = LuaPluginManager.load()
|
||||||
self.lua_plugin_manager.merge_player_settings()
|
self.lua_plugin_manager.merge_player_settings()
|
||||||
|
|
||||||
@ -110,7 +113,7 @@ class NewGameWizard(QtWidgets.QWizard):
|
|||||||
)
|
)
|
||||||
self.addPage(self.theater_page)
|
self.addPage(self.theater_page)
|
||||||
self.addPage(self.faction_selection_page)
|
self.addPage(self.faction_selection_page)
|
||||||
self.addPage(GeneratorOptions(default_settings))
|
self.addPage(GeneratorOptions(default_settings, mod_settings))
|
||||||
self.difficulty_page = DifficultyAndAutomationOptions(default_settings)
|
self.difficulty_page = DifficultyAndAutomationOptions(default_settings)
|
||||||
self.plugins_page = PluginsPage(self.lua_plugin_manager)
|
self.plugins_page = PluginsPage(self.lua_plugin_manager)
|
||||||
|
|
||||||
@ -194,6 +197,7 @@ class NewGameWizard(QtWidgets.QWizard):
|
|||||||
frenchpack=self.field("frenchpack"),
|
frenchpack=self.field("frenchpack"),
|
||||||
high_digit_sams=self.field("high_digit_sams"),
|
high_digit_sams=self.field("high_digit_sams"),
|
||||||
)
|
)
|
||||||
|
mod_settings.save_player_settings()
|
||||||
|
|
||||||
blue_faction = self.faction_selection_page.selected_blue_faction
|
blue_faction = self.faction_selection_page.selected_blue_faction
|
||||||
red_faction = self.faction_selection_page.selected_red_faction
|
red_faction = self.faction_selection_page.selected_red_faction
|
||||||
@ -708,7 +712,9 @@ class PluginsPage(QtWidgets.QWizardPage):
|
|||||||
|
|
||||||
|
|
||||||
class GeneratorOptions(QtWidgets.QWizardPage):
|
class GeneratorOptions(QtWidgets.QWizardPage):
|
||||||
def __init__(self, default_settings: Settings, parent=None):
|
def __init__(
|
||||||
|
self, default_settings: Settings, mod_settings: ModSettings, parent=None
|
||||||
|
) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setTitle("Generator settings")
|
self.setTitle("Generator settings")
|
||||||
self.setSubTitle("\nOptions affecting the generation of the game.")
|
self.setSubTitle("\nOptions affecting the generation of the game.")
|
||||||
@ -753,27 +759,49 @@ class GeneratorOptions(QtWidgets.QWizardPage):
|
|||||||
generatorSettingsGroup.setLayout(generatorLayout)
|
generatorSettingsGroup.setLayout(generatorLayout)
|
||||||
|
|
||||||
modSettingsGroup = QtWidgets.QGroupBox("Mod Settings")
|
modSettingsGroup = QtWidgets.QGroupBox("Mod Settings")
|
||||||
|
|
||||||
a4_skyhawk = QtWidgets.QCheckBox()
|
a4_skyhawk = QtWidgets.QCheckBox()
|
||||||
|
a4_skyhawk.setChecked(mod_settings.a4_skyhawk)
|
||||||
self.registerField("a4_skyhawk", a4_skyhawk)
|
self.registerField("a4_skyhawk", a4_skyhawk)
|
||||||
|
|
||||||
hercules = QtWidgets.QCheckBox()
|
hercules = QtWidgets.QCheckBox()
|
||||||
|
hercules.setChecked(mod_settings.hercules)
|
||||||
self.registerField("hercules", hercules)
|
self.registerField("hercules", hercules)
|
||||||
|
|
||||||
uh_60l = QtWidgets.QCheckBox()
|
uh_60l = QtWidgets.QCheckBox()
|
||||||
|
uh_60l.setChecked(mod_settings.uh_60l)
|
||||||
self.registerField("uh_60l", uh_60l)
|
self.registerField("uh_60l", uh_60l)
|
||||||
|
|
||||||
f22_raptor = QtWidgets.QCheckBox()
|
f22_raptor = QtWidgets.QCheckBox()
|
||||||
|
f22_raptor.setChecked(mod_settings.f22_raptor)
|
||||||
self.registerField("f22_raptor", f22_raptor)
|
self.registerField("f22_raptor", f22_raptor)
|
||||||
|
|
||||||
f104_starfighter = QtWidgets.QCheckBox()
|
f104_starfighter = QtWidgets.QCheckBox()
|
||||||
|
f104_starfighter.setChecked(mod_settings.f104_starfighter)
|
||||||
self.registerField("f104_starfighter", f104_starfighter)
|
self.registerField("f104_starfighter", f104_starfighter)
|
||||||
|
|
||||||
f4_phantom = QtWidgets.QCheckBox()
|
f4_phantom = QtWidgets.QCheckBox()
|
||||||
|
f4_phantom.setChecked(mod_settings.f4_phantom)
|
||||||
self.registerField("f4_phantom", f4_phantom)
|
self.registerField("f4_phantom", f4_phantom)
|
||||||
|
|
||||||
jas39_gripen = QtWidgets.QCheckBox()
|
jas39_gripen = QtWidgets.QCheckBox()
|
||||||
|
jas39_gripen.setChecked(mod_settings.jas39_gripen)
|
||||||
self.registerField("jas39_gripen", jas39_gripen)
|
self.registerField("jas39_gripen", jas39_gripen)
|
||||||
|
|
||||||
su57_felon = QtWidgets.QCheckBox()
|
su57_felon = QtWidgets.QCheckBox()
|
||||||
|
su57_felon.setChecked(mod_settings.su57_felon)
|
||||||
self.registerField("su57_felon", su57_felon)
|
self.registerField("su57_felon", su57_felon)
|
||||||
|
|
||||||
ov10a_bronco = QtWidgets.QCheckBox()
|
ov10a_bronco = QtWidgets.QCheckBox()
|
||||||
|
ov10a_bronco.setChecked(mod_settings.ov10a_bronco)
|
||||||
self.registerField("ov10a_bronco", ov10a_bronco)
|
self.registerField("ov10a_bronco", ov10a_bronco)
|
||||||
|
|
||||||
frenchpack = QtWidgets.QCheckBox()
|
frenchpack = QtWidgets.QCheckBox()
|
||||||
|
frenchpack.setChecked(mod_settings.frenchpack)
|
||||||
self.registerField("frenchpack", frenchpack)
|
self.registerField("frenchpack", frenchpack)
|
||||||
|
|
||||||
high_digit_sams = QtWidgets.QCheckBox()
|
high_digit_sams = QtWidgets.QCheckBox()
|
||||||
|
high_digit_sams.setChecked(mod_settings.high_digit_sams)
|
||||||
self.registerField("high_digit_sams", high_digit_sams)
|
self.registerField("high_digit_sams", high_digit_sams)
|
||||||
|
|
||||||
modHelpText = QtWidgets.QLabel(
|
modHelpText = QtWidgets.QLabel(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user