added custom message for when an installation end

This commit is contained in:
Faraphel 2022-07-25 23:52:31 +02:00
parent d37ee5a79c
commit 0555539543
3 changed files with 32 additions and 4 deletions

View file

@ -0,0 +1,8 @@
{
"installation_completed": {
"text": {
"fr": "TODO",
"en": "Thanks for downloading Mario Kart Wii Faraphel !\nIf You have an issue starting the game with Dolphin, try in Config > Advanced > Enable Emulated Memory Size Override and set MEM2 to 128Mo\n\nHave fun !"
}
}
}

View file

@ -413,6 +413,20 @@ class ButtonInstall(ttk.Button):
) )
) )
# TODO: make this code more readable
message = mod_config.messages.get('installation_completed', {}).get('text', _('NO_MESSAGE_FROM_AUTHOR'))
if isinstance(message, str): message = {"_": message}
message = mod_config.safe_eval(
message[self.master.options["language"]]
if self.master.options["language"] in message else message["_"],
multiple=True
)
messagebox.showinfo(
_("INSTALLATION_COMPLETED"),
f"{_('INSTALLATION_FINISHED_WITH_SUCCESS')}\n{_('MESSAGE_FROM_MOD_AUTHOR')}:\n\n{message}"
)
finally: finally:
self.master.set_state(InstallerState.IDLE) self.master.set_state(InstallerState.IDLE)

View file

@ -28,7 +28,7 @@ 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", "macros") "multiplayer_disable_if", "macros", "messages")
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,
@ -36,10 +36,12 @@ class ModConfig:
default_track: "Track | TrackGroup" = None, tracks: list["Track | TrackGroup"] = None, default_track: "Track | TrackGroup" = None, tracks: list["Track | TrackGroup"] = None,
original_track_prefix: bool = None, swap_original_order: bool = None, original_track_prefix: bool = None, swap_original_order: bool = None,
keep_original_track: bool = None, enable_random_cup: bool = None, keep_original_track: bool = None, enable_random_cup: bool = None,
track_file_template: str = None, multiplayer_disable_if: str = None, macros: dict | None = None): track_file_template: str = None, multiplayer_disable_if: str = None, macros: dict[str, str] = None,
messages: dict[str, dict[str, 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 {}
self.messages: dict = messages if messages is not None else {}
self.name: str = name self.name: str = name
self.nickname: str = nickname if nickname is not None else name self.nickname: str = nickname if nickname is not None else name
@ -65,9 +67,10 @@ class ModConfig:
return f"<ModConfig name={self.name} version={self.version}>" return f"<ModConfig name={self.name} version={self.version}>"
@classmethod @classmethod
def from_dict(cls, path: Path | str, config_dict: dict, macros: dict | None) -> "ModConfig": def from_dict(cls, path: Path | str, config_dict: dict, macros: dict, messages: dict) -> "ModConfig":
""" """
Create a ModConfig from a dict Create a ModConfig from a dict
:param messages: messages that can be shown to the user at some moment
:param path: path of the mod_config.json :param path: path of the mod_config.json
:param config_dict: dict containing the configuration :param config_dict: dict containing the configuration
:param macros: macro that can be used for safe_eval :param macros: macro that can be used for safe_eval
@ -76,7 +79,7 @@ class ModConfig:
kwargs = { kwargs = {
attr: config_dict.get(attr) attr: config_dict.get(attr)
for attr in cls.__slots__ for attr in cls.__slots__
if attr not in ["name", "default_track", "_tracks", "tracks", "path", "macros"] if attr not in ["name", "default_track", "_tracks", "tracks", "path", "macros", "messages"]
# these keys are treated after or are reserved # these keys are treated after or are reserved
} }
@ -89,6 +92,7 @@ class ModConfig:
default_track=Track.from_dict(config_dict.get("default_track", {})), default_track=Track.from_dict(config_dict.get("default_track", {})),
tracks=[Track.from_dict(track) for track in config_dict.get("tracks", [])], tracks=[Track.from_dict(track) for track in config_dict.get("tracks", [])],
macros=macros, macros=macros,
messages=messages,
) )
@classmethod @classmethod
@ -100,11 +104,13 @@ class ModConfig:
""" """
config_file = Path(config_file) config_file = Path(config_file)
macros_file = config_file.parent / "macros.json" macros_file = config_file.parent / "macros.json"
messages_file = config_file.parent / "messages.json"
return cls.from_dict( return cls.from_dict(
path=config_file, path=config_file,
config_dict=json.loads(config_file.read_text(encoding="utf8")), config_dict=json.loads(config_file.read_text(encoding="utf8")),
macros=json.loads(macros_file.read_text(encoding="utf8")) if macros_file.exists() else None, macros=json.loads(macros_file.read_text(encoding="utf8")) if macros_file.exists() else None,
messages=json.loads(messages_file.read_text(encoding="utf8")) if messages_file.exists() else None,
) )
def safe_eval(self, template: str, multiple: bool = False, env: dict[str, any] = None) -> str: def safe_eval(self, template: str, multiple: bool = False, env: dict[str, any] = None) -> str: