dynamically loaded presets
Marco Andronaco andronacomarco@gmail.com
Wed, 06 Jul 2022 17:07:48 +0200
4 files changed,
24 insertions(+),
31 deletions(-)
M
Constants.py
→
Constants.py
@@ -29,28 +29,28 @@ PATH_ALT = os.path.join(PATH_TOOLS, 'alt')
PRESETS = { "Scelte consigliate": { # default preset - 'font': 'fonts_og', + 'font': 'font_og', 'sprites': 'sprites_mix', 'places': 'places_us', 'nes_palette': 'nes_palette_yes', 'skip_m1': 'skip_m1_yes' }, - "EB Beginnings (US)": { - 'font': 'fonts_og', + "Earthbound Beginnings (US)": { + 'font': 'font_og', 'sprites': 'sprites_us', 'places': 'places_us', 'nes_palette': 'nes_palette_yes', 'skip_m1': 'skip_m1_yes' }, "Mother 1 (JP)": { - 'font': 'fonts_og', + 'font': 'font_og', 'sprites': 'sprites_jp', 'places': 'places_jp', 'nes_palette': 'nes_palette_yes', 'skip_m1': 'skip_m1_yes' }, "Mother 1+2": { - 'font': 'fonts_og', + 'font': 'font_og', 'sprites': 'sprites_us', 'places': 'places_jp', 'nes_palette': 'nes_palette_no',@@ -59,9 +59,9 @@ }
} ALT_FILENAMES = { - 'fonts_og': + 'font_og': ['m1_gfx_font_og.bin'], - 'fonts_new': + 'font_new': ['m1_gfx_font_new.bin'], 'sprites_mix': ['m1_restoration_gfx_sprites_mix.bin',
M
Functions.py
→
Functions.py
@@ -36,26 +36,22 @@
def show_warning(message): showwarning(title=Constants.WARNING_TITLE, message=message) -def show_success(message): - showinfo(title=Constants.SUCCESS_TITLE, message=message) - def set_progress(app, percent, message): app.progress.set(percent) app.status_text.set(message) -def read_options(app, output, keys): +def read_options(app, keys): + output = {} for key in keys: new_option = getattr(app, key).get() output[key] = Constants.ALT_FILENAMES[new_option] + return output def start_patching(app): set_progress(app, 20, Constants.STATUS_MD5) delete_list = [] - #sel_filenames = {} - #sel_patches = {} - read_options(app, sel_filenames, Constants.DEF_FILENAMES.keys()) - read_options(app, sel_patches, Constants.DEF_PATCHES) + sel_filenames = read_options(app, Constants.DEF_FILENAMES.keys()) for key in sel_filenames.keys(): sel_list = sel_filenames[key]@@ -70,18 +66,20 @@ delete_list.append(target)
target = os.path.join(Constants.PATH_TOOLS, 'test.gba') copyfile(app.baserom, target) - set_progress(app, 40, Constants.STATUS_COPIED) + p = subprocess.Popen([Constants.OS_FILENAMES['xkas'], '-o', 'test.gba', 'm12.asm'], cwd=Constants.PATH_TOOLS, shell=Constants.OS_SHELL) p.wait() - set_progress(app, 50, Constants.STATUS_ASSEMBLY) + p = subprocess.Popen([Constants.OS_FILENAMES['insert']], cwd=Constants.PATH_TOOLS, shell=Constants.OS_SHELL) p.wait() - set_progress(app, 70, Constants.STATUS_INJECTED) + + sel_patches = read_options(app, Constants.DEF_PATCHES) + for key in sel_patches.keys(): val = sel_patches[key]@@ -90,10 +88,10 @@ path = os.path.join(Constants.PATH_ALT, val)
apply_patch(target, path) os.replace(target, Constants.FINAL_ROM_NAME) - set_progress(app, 90, Constants.STATUS_PATCHED) + for item in delete_list: os.remove(item) set_progress(app, 100, Constants.STATUS_CLEANED) - show_success(Constants.SUCCESS_CONTENT) + showinfo(title=Constants.SUCCESS_TITLE, message=Constants.SUCCESS_CONTENT)
M
patcher.py
→
patcher.py
@@ -8,8 +8,6 @@
PROJECT_PATH = Path(__file__).parent PROJECT_UI = PROJECT_PATH / "patcher.ui" - - class PatcherApp: def __init__(self, master=None): self.builder = builder = Builder()@@ -18,6 +16,7 @@ builder.add_from_file(PROJECT_UI)
# Main widget self.mainwindow = builder.get_object("main_frame", master) self.apply_button = builder.get_object("apply_button") + self.preset_combo = builder.get_object("preset_combo") self.browse_path = None self.preset = None@@ -42,7 +41,9 @@ "nes_palette",
"skip_m1", ], ) - + + for preset in Constants.PRESETS.keys(): + self.preset_combo['values'] = (*self.preset_combo['values'], preset) self.preset.trace('w', self.on_change_preset) self.preset.set(Constants.DEF_PRESET[0]) self.status_text.set(Constants.STATUS_START)@@ -63,11 +64,6 @@
def on_browse_button(self): fn = askopenfilename(filetypes=[(Constants.VAR_FILEPICKER, '*.gba')]) self.browse_path.set(fn) - - def trace_f(self, var, index, mode): - preset = var.get() - if apply_preset(self, preset): - set_progress(self, 0, Constants.STATUS_PRESET) def on_change_preset(self, *arg): preset = self.preset.get()
M
patcher.ui
→
patcher.ui
@@ -68,7 +68,6 @@ <child>
<object class="ttk.Combobox" id="preset_combo"> <property name="state">readonly</property> <property name="textvariable">string:preset</property> - <property name="values">"Scelte consigliate" "EB Beginnings (US)" "Mother 1 (JP)" "Mother 1+2"</property> <layout manager="pack"> <property name="fill">x</property> <property name="padx">5</property>@@ -96,7 +95,7 @@ </layout>
<child> <object class="ttk.Radiobutton" id="font_serif"> <property name="text" translatable="yes">Serif (originale)</property> - <property name="value">fonts_og</property> + <property name="value">font_og</property> <property name="variable">string:font</property> <layout manager="pack"> <property name="anchor">w</property>@@ -109,7 +108,7 @@ </child>
<child> <object class="ttk.Radiobutton" id="font_sans"> <property name="text" translatable="yes">Sans serif (alternativa di Tomato)</property> - <property name="value">fonts_new</property> + <property name="value">font_new</property> <property name="variable">string:font</property> <layout manager="pack"> <property name="anchor">w</property>