mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 19:28:25 +02:00
the lpar file is now customizable with the mod settings function
This commit is contained in:
parent
56b03f22c6
commit
d1b17e0a77
7 changed files with 32 additions and 11 deletions
|
@ -8,5 +8,7 @@
|
||||||
"TRACK_TEXT_AUTHORS": "'\\n'.join(getattr(track, 'author')) if isinstance(getattr(track, 'author', ''), list) else getattr(track, 'author', '/')",
|
"TRACK_TEXT_AUTHORS": "'\\n'.join(getattr(track, 'author')) if isinstance(getattr(track, 'author', ''), list) else getattr(track, 'author', '/')",
|
||||||
"TRACK_TEXT_WARNING_IF_DISABLED": "bmg_color_text('red', '/') if getattr(track, 'warning', 0) != 0 else ''",
|
"TRACK_TEXT_WARNING_IF_DISABLED": "bmg_color_text('red', '/') if getattr(track, 'warning', 0) != 0 else ''",
|
||||||
|
|
||||||
|
"SETTINGS_MODE": "getattr(getattr(mod_config, 'specific_settings')['mode'], 'value')",
|
||||||
|
|
||||||
"IF_NO_WARNING": "if getattr(track, 'warning', 0) == 0 else ''"
|
"IF_NO_WARNING": "if getattr(track, 'warning', 0) == 0 else ''"
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"track_new_if": "'Retro' not in getattr(track, 'tags', []) and getattr(track, 'warning', 0) == 0",
|
"track_new_if": "'Retro' not in getattr(track, 'tags', []) and getattr(track, 'warning', 0) == 0",
|
||||||
|
"lpar_template": "{{ ## SETTINGS_MODE ## if ## SETTINGS_MODE ## is not None else 'normal' }}.lpar",
|
||||||
|
|
||||||
"tags_prefix": {
|
"tags_prefix": {
|
||||||
"MSRDS": "{{ bmg_color_text('green', TAG) }}",
|
"MSRDS": "{{ bmg_color_text('green', TAG) }}",
|
||||||
|
|
|
@ -12,6 +12,11 @@ from source.wt.wstrt import StrPath
|
||||||
Game: any
|
Game: any
|
||||||
|
|
||||||
|
|
||||||
|
class PathOutsideMod(Exception):
|
||||||
|
def __init__(self, forbidden_path: Path, allowed_range: Path):
|
||||||
|
super().__init__(f"Error : path {forbidden_path} outside of allowed range {allowed_range}")
|
||||||
|
|
||||||
|
|
||||||
class ExtractedGame:
|
class ExtractedGame:
|
||||||
"""
|
"""
|
||||||
Class that represents an extracted game
|
Class that represents an extracted game
|
||||||
|
@ -116,12 +121,15 @@ class ExtractedGame:
|
||||||
ct_file = (cache_directory / "ctfile.lpar")
|
ct_file = (cache_directory / "ctfile.lpar")
|
||||||
ct_file.write_text(mod_config.get_ctfile(template="-"))
|
ct_file.write_text(mod_config.get_ctfile(template="-"))
|
||||||
|
|
||||||
# TODO: the lpar file should be customizable
|
lpar_dir: Path = mod_config.path.parent / "_LPAR/"
|
||||||
|
lpar: Path = lpar_dir / mod_config.safe_eval(mod_config.lpar_template, multiple=True)
|
||||||
|
if not lpar.is_relative_to(lpar_dir): raise PathOutsideMod(lpar, lpar_dir)
|
||||||
|
|
||||||
for lecode_file in (self.path / "files/rel/").glob("lecode-*.bin"):
|
for lecode_file in (self.path / "files/rel/").glob("lecode-*.bin"):
|
||||||
lec.patch(
|
lec.patch(
|
||||||
lecode_file=lecode_file,
|
lecode_file=lecode_file,
|
||||||
ct_file=ct_file,
|
ct_file=ct_file,
|
||||||
lpar=mod_config.path.parent / "_LPAR/normal.lpar",
|
lpar=lpar,
|
||||||
game_tracks_directory=self.path / "files/Race/Course/",
|
game_tracks_directory=self.path / "files/Race/Course/",
|
||||||
copy_tracks_directories=[cache_directory / "original-tracks/", cache_directory / "custom-tracks/"]
|
copy_tracks_directories=[cache_directory / "original-tracks/", cache_directory / "custom-tracks/"]
|
||||||
)
|
)
|
||||||
|
|
|
@ -50,7 +50,8 @@ class ModConfig:
|
||||||
__slots__ = ("name", "path", "nickname", "variant", "tags_prefix", "tags_suffix",
|
__slots__ = ("name", "path", "nickname", "variant", "tags_prefix", "tags_suffix",
|
||||||
"default_track", "_tracks", "version", "original_track_prefix", "swap_original_order",
|
"default_track", "_tracks", "version", "original_track_prefix", "swap_original_order",
|
||||||
"keep_original_track", "enable_random_cup", "tags_cups", "track_file_template",
|
"keep_original_track", "enable_random_cup", "tags_cups", "track_file_template",
|
||||||
"multiplayer_disable_if", "track_new_if", "macros", "messages", "global_settings", "specific_settings")
|
"multiplayer_disable_if", "track_new_if", "macros", "messages", "global_settings",
|
||||||
|
"specific_settings", "lpar_template")
|
||||||
|
|
||||||
def __init__(self, path: Path | str, name: str, nickname: str = None, version: str = None, variant: str = None,
|
def __init__(self, path: Path | str, name: str, nickname: str = None, version: str = None, variant: str = None,
|
||||||
tags_prefix: dict[Tag, str] = None, tags_suffix: dict[Tag, str] = None,
|
tags_prefix: dict[Tag, str] = None, tags_suffix: dict[Tag, str] = None,
|
||||||
|
@ -59,7 +60,7 @@ class ModConfig:
|
||||||
swap_original_order: bool = None, keep_original_track: bool = None, enable_random_cup: bool = None,
|
swap_original_order: bool = None, keep_original_track: bool = None, enable_random_cup: bool = None,
|
||||||
track_file_template: str = None, multiplayer_disable_if: str = None, macros: dict[str, str] = None,
|
track_file_template: str = None, multiplayer_disable_if: str = None, macros: dict[str, str] = None,
|
||||||
track_new_if: str = None, messages: dict[str, dict[str, str]] = None,
|
track_new_if: str = None, messages: dict[str, dict[str, str]] = None,
|
||||||
specific_settings: dict[str, dict[str, str]] = None):
|
specific_settings: dict[str, dict[str, str]] = None, lpar_template: str = None):
|
||||||
|
|
||||||
self.path = Path(path)
|
self.path = Path(path)
|
||||||
self.macros: dict = macros if macros is not None else {}
|
self.macros: dict = macros if macros is not None else {}
|
||||||
|
@ -85,6 +86,7 @@ class ModConfig:
|
||||||
if track_file_template is not None else "{{ getattr(track, 'sha1', '_') }}"
|
if track_file_template is not None else "{{ getattr(track, 'sha1', '_') }}"
|
||||||
self.multiplayer_disable_if: str = multiplayer_disable_if if multiplayer_disable_if is not None else "False"
|
self.multiplayer_disable_if: str = multiplayer_disable_if if multiplayer_disable_if is not None else "False"
|
||||||
self.track_new_if: str = track_new_if if track_new_if is not None else "True"
|
self.track_new_if: str = track_new_if if track_new_if is not None else "True"
|
||||||
|
self.lpar_template: str = lpar_template if lpar_template is not None else "normal.lpar"
|
||||||
|
|
||||||
self.original_track_prefix: bool = original_track_prefix if original_track_prefix is not None else True
|
self.original_track_prefix: bool = original_track_prefix if original_track_prefix is not None else True
|
||||||
self.swap_original_order: bool = swap_original_order if swap_original_order is not None else True
|
self.swap_original_order: bool = swap_original_order if swap_original_order is not None else True
|
||||||
|
|
|
@ -13,15 +13,15 @@ class Choices(AbstractModSettings):
|
||||||
type = "choices"
|
type = "choices"
|
||||||
|
|
||||||
def __init__(self, choices: list[str], value: str = None, enabled: bool = False):
|
def __init__(self, choices: list[str], value: str = None, enabled: bool = False):
|
||||||
self.value = value if value is not None else choices[0]
|
self._value = value if value is not None else choices[0]
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.choices = choices
|
self.choices = choices
|
||||||
|
|
||||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||||
super().tkinter_show(master, checkbox)
|
super().tkinter_show(master, checkbox)
|
||||||
|
|
||||||
value_variable = tkinter.StringVar(master, value=self.value)
|
value_variable = tkinter.StringVar(master, value=self._value)
|
||||||
value_variable.trace_add("write", lambda *_: setattr(self, "value", value_variable.get()))
|
value_variable.trace_add("write", lambda *_: setattr(self, "_value", value_variable.get()))
|
||||||
|
|
||||||
combobox = ttk.Combobox(master, values=self.choices, textvariable=value_variable)
|
combobox = ttk.Combobox(master, values=self.choices, textvariable=value_variable)
|
||||||
combobox.grid(row=1, column=1, sticky="EW")
|
combobox.grid(row=1, column=1, sticky="EW")
|
||||||
|
|
|
@ -14,15 +14,15 @@ class String(AbstractModSettings):
|
||||||
type = "string"
|
type = "string"
|
||||||
|
|
||||||
def __init__(self, value: str = None, preview: str = None, enabled: bool = False):
|
def __init__(self, value: str = None, preview: str = None, enabled: bool = False):
|
||||||
self.value: str = value if value is not None else ""
|
self._value: str = value if value is not None else ""
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.preview: str | None = preview
|
self.preview: str | None = preview
|
||||||
|
|
||||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||||
super().tkinter_show(master, checkbox)
|
super().tkinter_show(master, checkbox)
|
||||||
|
|
||||||
value_variable = tkinter.StringVar(master, value=self.value)
|
value_variable = tkinter.StringVar(master, value=self._value)
|
||||||
value_variable.trace_add("write", lambda *_: setattr(self, "value", value_variable.get()))
|
value_variable.trace_add("write", lambda *_: setattr(self, "_value", value_variable.get()))
|
||||||
|
|
||||||
entry = ttk.Entry(master, textvariable=value_variable)
|
entry = ttk.Entry(master, textvariable=value_variable)
|
||||||
entry.grid(row=1, column=1, sticky="EW")
|
entry.grid(row=1, column=1, sticky="EW")
|
||||||
|
|
|
@ -14,13 +14,21 @@ class AbstractModSettings(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type: str # type name of the settings
|
type: str # type name of the settings
|
||||||
value: str # value for the settings
|
|
||||||
enabled: bool # is the settings enabled
|
enabled: bool # is the settings enabled
|
||||||
|
_value: str # value for the settings
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, value: str = None, preview: str = None, enabled: bool = False):
|
def __init__(self, value: str = None, preview: str = None, enabled: bool = False):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self) -> "any | None":
|
||||||
|
"""
|
||||||
|
If the option is enabled, return the value, else return None
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
return self._value if self.enabled else None
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue