diff --git a/resources/app/gui/lang/en.json b/resources/app/gui/lang/en.json index fcb28072..d67963e5 100644 --- a/resources/app/gui/lang/en.json +++ b/resources/app/gui/lang/en.json @@ -155,9 +155,9 @@ "randomizer.generation.spoiler": "Create Spoiler Log", - "randomizer.generation.suppressrom": "Do not create patched ROM", - "randomizer.generation.usestartinventory": "Use starting inventory", - "randomizer.generation.usecustompool": "Use custom item pool", + "randomizer.generation.suppressrom": "Do Not create Patched ROM", + "randomizer.generation.usestartinventory": "Use Starting Inventory", + "randomizer.generation.usecustompool": "Use Custom Item Pool", "randomizer.generation.saveonexit": "Save Settings on Exit", "randomizer.generation.saveonexit.ask": "Ask Me", diff --git a/resources/app/gui/randomize/dungeon/keysanity.json b/resources/app/gui/randomize/dungeon/keysanity.json index 29efc0e4..49a17237 100644 --- a/resources/app/gui/randomize/dungeon/keysanity.json +++ b/resources/app/gui/randomize/dungeon/keysanity.json @@ -1,6 +1,8 @@ { - "mapshuffle": { "type": "checkbox" }, - "compassshuffle": { "type": "checkbox" }, - "smallkeyshuffle": { "type": "checkbox" }, - "bigkeyshuffle": { "type": "checkbox" } + "keysanity": { + "mapshuffle": { "type": "checkbox" }, + "compassshuffle": { "type": "checkbox" }, + "smallkeyshuffle": { "type": "checkbox" }, + "bigkeyshuffle": { "type": "checkbox" } + } } diff --git a/resources/app/gui/randomize/dungeon/widgets.json b/resources/app/gui/randomize/dungeon/widgets.json index 3cbd7962..04082822 100644 --- a/resources/app/gui/randomize/dungeon/widgets.json +++ b/resources/app/gui/randomize/dungeon/widgets.json @@ -1,22 +1,24 @@ { - "dungeondoorshuffle": { - "type": "selectbox", - "default": "basic", - "options": [ - "vanilla", - "basic", - "crossed" - ] - }, - "experimental": { "type": "checkbox" }, - "dungeon_counters": { - "type": "selectbox", - "default": "default", - "options": [ - "default", - "off", - "on", - "pickup" - ] + "widgets": { + "dungeondoorshuffle": { + "type": "selectbox", + "default": "basic", + "options": [ + "vanilla", + "basic", + "crossed" + ] + }, + "experimental": { "type": "checkbox" }, + "dungeon_counters": { + "type": "selectbox", + "default": "default", + "options": [ + "default", + "off", + "on", + "pickup" + ] + } } } diff --git a/resources/app/gui/randomize/generation/checkboxes.json b/resources/app/gui/randomize/generation/checkboxes.json index d609e866..5839e0d4 100644 --- a/resources/app/gui/randomize/generation/checkboxes.json +++ b/resources/app/gui/randomize/generation/checkboxes.json @@ -1,6 +1,8 @@ { - "spoiler": { "type": "checkbox" }, - "suppressrom": { "type": "checkbox" }, - "usestartinventory": { "type": "checkbox" }, - "usecustompool": { "type": "checkbox" } + "checkboxes": { + "spoiler": { "type": "checkbox" }, + "suppressrom": { "type": "checkbox" }, + "usestartinventory": { "type": "checkbox" }, + "usecustompool": { "type": "checkbox" } + } } diff --git a/resources/app/gui/randomize/generation/widgets.json b/resources/app/gui/randomize/generation/widgets.json index d22de592..22f9decc 100644 --- a/resources/app/gui/randomize/generation/widgets.json +++ b/resources/app/gui/randomize/generation/widgets.json @@ -1,10 +1,12 @@ { - "saveonexit": { - "type": "selectbox", - "options": [ - "ask", - "always", - "never" - ] + "widgets": { + "saveonexit": { + "type": "selectbox", + "options": [ + "ask", + "always", + "never" + ] + } } } diff --git a/resources/app/gui/randomize/multiworld/widgets.json b/resources/app/gui/randomize/multiworld/widgets.json index 4038bed7..327b9434 100644 --- a/resources/app/gui/randomize/multiworld/widgets.json +++ b/resources/app/gui/randomize/multiworld/widgets.json @@ -1,3 +1,5 @@ { - "worlds": { "type": "spinbox" } + "widgets": { + "worlds": { "type": "spinbox" } + } } diff --git a/resources/app/meta/manifests/pip_requirements.txt b/resources/app/meta/manifests/pip_requirements.txt index e69de29b..93e06fa8 100644 --- a/resources/app/meta/manifests/pip_requirements.txt +++ b/resources/app/meta/manifests/pip_requirements.txt @@ -0,0 +1 @@ +aenum diff --git a/source/classes/BabelFish.py b/source/classes/BabelFish.py index 3be79c09..40b6463f 100644 --- a/source/classes/BabelFish.py +++ b/source/classes/BabelFish.py @@ -38,7 +38,7 @@ class BabelFish(): pass # print(langs_filename + " not found for translation!") - def translate(self, domain="", key="", subkey=""): #three levels of keys + def translate(self, domain="", key="", subkey="", uselang=None): #three levels of keys # start with nothing display_text = "" @@ -94,7 +94,7 @@ class BabelFish(): subkey = " - ".join(tmp) subkey = subkey.strip() - my_lang = self.lang_defns[self.locale] #handle for localization + my_lang = self.lang_defns[uselang if uselang is not None else self.locale ] #handle for localization en_lang = self.lang_defns["en"] #handle for English if domain in my_lang and key in my_lang[domain] and subkey in my_lang[domain][key] and not my_lang[domain][key][subkey] == "": #get localization first diff --git a/test-options.py b/test-options.py new file mode 100644 index 00000000..60386860 --- /dev/null +++ b/test-options.py @@ -0,0 +1,109 @@ +from __future__ import annotations +from aenum import Enum, IntEnum, extend_enum +from source.classes.BabelFish import BabelFish +import json +import os + +fish = BabelFish(lang="en") + +def tokenize(token): + for search,replace in ( + ('(', ""), + (')',""), + ("'", ""), + ('-'," "), + ('/',""), + ("\\","") + ): + token = token.replace(search, replace) + tokens = token.split(" ") + i = 0 + for check in tokens: + if check.lower() == check: + tokens[i] = "" + i += 1 + return " ".join(tokens).replace(" ","") + +class Toggle(IntEnum): + Off = 0 + On = 1 + + @classmethod + def from_text(cls, text: str) -> Toggle: + if text.lower() in {"off", "0", "false", "none", "null"}: + return Toggle.Off + else: + return Toggle.On + +class Choice(IntEnum): + @classmethod + def from_text(cls, text: str) -> Choice: + for option in cls: + if option.name == text.upper(): + return option + raise KeyError( + 'KeyError: Could not find option "%s" for "%s", known options are %s' % + ( + text, + cls.__name__, + ", ".join(option.name for option in cls) + ) + ) + +def create_choice(option_name,option_vals): + option = type(option_name,(Choice,),{}) + for name in option_vals: + extend_enum(option,str(name).upper(),len(option)) + return option + +def load_options(filepath): + theseCompiled = {} + with open(filepath) as widgetsDefn: + filepath = filepath.split(os.sep) + domain = filepath[3] + key = filepath[4] + theseOptions = json.load(widgetsDefn) + for section in theseOptions: + widgets = theseOptions[section] + for widget in widgets: + thisWidget = widgets[widget] + if domain == "randomize": + domain = "randomizer" + if key == "entrando": + key = "entrance" + fish_key = domain + '.' + key + '.' + widget + option_name = tokenize(fish.translate("gui","gui",fish_key,"en")) + if thisWidget["type"] == "checkbox": + theseCompiled[option_name] = Toggle + elif thisWidget["type"] == "selectbox": + option_vals = thisWidget["options"] + theseCompiled[option_name] = create_choice(option_name,option_vals) + return theseCompiled + + +if __name__ == "__main__": + import argparse + + compiledOptions = {} + notebooks = { + "randomize": [ "dungeon", "enemizer", "entrando", "gameoptions", "generation", "item", "multiworld" ] + } + for notebook in notebooks: + for page in notebooks[notebook]: + for filename in ["keysanity","checkboxes","widgets"]: + defn = os.path.join("resources", "app", "gui", notebook, page, filename + ".json") + if os.path.isfile(defn): + compiledOptions.update(load_options(defn)) + + test = argparse.Namespace() + test.logic = compiledOptions["LogicLevel"].from_text("nologic") + test.mapshuffle = compiledOptions["Maps"].from_text("ON") + try: + test.logic = compiledOptions["LogicLevel"].from_text("overworldglitches") + except KeyError as e: + print(e) + if test.mapshuffle: + print("Map Shuffle is on") + print(test) + for option in compiledOptions: + print("%s: %s" % (option, list(compiledOptions[option])))