the extension settings is now saved in the option.json file

This commit is contained in:
Faraphel 2022-08-21 01:12:20 +02:00
parent 2d50619b6c
commit e88fb57143
6 changed files with 50 additions and 61 deletions

View file

@ -12,14 +12,14 @@ from typing import Generator
from source.gui import better_gui_error, mystuff, mod_settings
from source.mkw.Game import Game
from source.mkw.ModConfig import ModConfig
from source.option import Option
from source.option import Options
from source.progress import Progress
from source.translation import translate as _, translate_external
from source import plugins
from source import *
import os
from source.wt.wit import Extension
from source.mkw.collection.Extension import Extension
class SourceGameError(Exception):
@ -39,11 +39,11 @@ class InstallerState(enum.Enum):
# Main window for the installer
class Window(tkinter.Tk):
def __init__(self, options: Option):
def __init__(self, options: Options):
super().__init__()
self.root = self
self.options: Option = options
self.options: Options = options
self.title(_("INSTALLER_TITLE"))
self.resizable(False, False)
@ -161,19 +161,12 @@ class Menu(tkinter.Menu):
master.add_cascade(label=_("LANGUAGE_SELECTION"), menu=self)
self.variable = tkinter.StringVar(value=self.root.options["language"])
def callback(file: Path):
def func(): self.root.options["language"] = file.stem
return func
for file in Path("./assets/language/").iterdir():
lang_json = json.loads(file.read_text(encoding="utf8"))
self.add_radiobutton(
label=lang_json["name"],
value=file.stem,
variable=self.variable,
command=callback(file)
variable=self.root.options.language
)
# Advanced menu
@ -194,18 +187,11 @@ class Menu(tkinter.Menu):
master.add_cascade(label=_("THREADS_USAGE"), menu=self)
self.variable = tkinter.IntVar(value=self.root.options["threads"])
def callback(threads_amount: int):
def func(): self.root.options["threads"] = threads_amount
return func
for i in [1, 2, 4, 8, 12, 16]:
self.add_radiobutton(
label=_("USE", f" {i} ", "THREADS"),
value=i,
variable=self.variable,
command=callback(i),
variable=self.root.options.threads,
)
# Help menu
@ -324,13 +310,10 @@ class DestinationGame(ttk.LabelFrame):
self.entry = ttk.Entry(self)
self.entry.grid(row=1, column=1, sticky="nsew")
self.output_type = ttk.Combobox(self, width=5, values=[extension.name for extension in Extension])
self.output_type.set(self.root.options["extension"])
self.output_type = ttk.Combobox(self, width=5, values=[extension.name for extension in Extension],
textvariable=self.root.options.extension)
self.output_type.grid(row=1, column=2, sticky="nsew")
def output_type_callback(_: tkinter.Event): self.root.options["extension"] = self.output_type.get()
self.output_type.bind("<<ComboboxSelected>>", output_type_callback)
self.button = ttk.Button(self, text="...", width=2, command=self.select)
self.button.grid(row=1, column=3, sticky="nsew")
@ -437,7 +420,7 @@ class ButtonInstall(ttk.Button):
message: str = translate_external(
mod_config,
self.root.options["language"],
self.root.options.language.value,
mod_config.messages.get("installation_completed", {}).get("text", {})
)

View file

@ -5,6 +5,7 @@ from typing import Generator, IO, TYPE_CHECKING
from source.mkw.ModConfig import ModConfig
from source.mkw.Patch.Patch import Patch
from source.mkw.collection.Extension import Extension
from source.progress import Progress
from source.wt import szs, lec, wit
from source.wt.wstrt import StrPath
@ -175,14 +176,14 @@ class ExtractedGame:
yield Progress(description=_("INSTALLING_ALL", " Patchs..."), determinate=False)
yield from self._install_all_patch(mod_config, "_PATCH/")
def convert_to(self, output_type: wit.Extension) -> Generator[Progress, None, wit.WITPath | None]:
def convert_to(self, output_type: Extension) -> Generator[Progress, None, wit.WITPath | None]:
"""
Convert the extracted game to another format
:param output_type: path to the destination of the game
:output_type: format of the destination game
"""
yield Progress(description=_("CONVERTING_GAME_TO", " ", output_type.name), determinate=False)
if output_type == wit.Extension.FST: return
if output_type == Extension.FST: return
destination_file = self.path.with_suffix(self.path.suffix + output_type.value)
dest_stem: str = destination_file.stem

View file

@ -3,9 +3,11 @@ from typing import Generator
from source.mkw.ExtractedGame import ExtractedGame
from source.mkw.ModConfig import ModConfig
from source.mkw.collection.Extension import Extension
from source.mkw.collection.Region import Region
from source.option import Option
from source.progress import Progress
from source.wt.wit import WITPath, Region, Extension
from source.wt.wit import WITPath
from source.translation import translate as _

View file

@ -0,0 +1,22 @@
import enum
class Extension(enum.Enum):
"""
Enum for game extension
"""
WBFS = ".wbfs"
FST = ".dol"
CISO = ".ciso"
ISO = ".iso"
@classmethod
def _missing_(cls, value: str) -> "Extension | None":
"""
if not found, search for the same value with lower case
:param value: value to search for
:return: None if nothing found, otherwise the found value
"""
value = value.lower()
for member in filter(lambda m: m.value == value, cls): return member
return None

View file

@ -0,0 +1,11 @@
import enum
class Region(enum.Enum):
"""
Enum for game region
"""
PAL = "PAL"
USA = "USA"
JAP = "JAP"
KOR = "KOR"

View file

@ -1,8 +1,9 @@
import enum
import re
import shutil
from typing import Generator
from source.mkw.collection.Extension import Extension
from source.mkw.collection.Region import Region
from source.wt import *
tools_path = tools_wit_dir / "wit"
@ -24,37 +25,6 @@ def copy(source_directory: Path | str, destination_file: Path | str) -> "WITPath
return WITPath(destination_file)
class Extension(enum.Enum):
"""
Enum for game extension
"""
WBFS = ".wbfs"
FST = ".dol"
CISO = ".ciso"
ISO = ".iso"
@classmethod
def _missing_(cls, value: str) -> "Extension | None":
"""
if not found, search for the same value with lower case
:param value: value to search for
:return: None if nothing found, otherwise the found value
"""
value = value.lower()
for member in filter(lambda m: m.value == value, cls): return member
return None
class Region(enum.Enum):
"""
Enum for game region
"""
PAL = "PAL"
USA = "USA"
JAP = "JAP"
KOR = "KOR"
class WITPath:
__slots__ = ("path", "_analyze")