Implement prelim enums
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"keysanity": {
|
||||
"mapshuffle": { "type": "checkbox" },
|
||||
"compassshuffle": { "type": "checkbox" },
|
||||
"smallkeyshuffle": { "type": "checkbox" },
|
||||
"bigkeyshuffle": { "type": "checkbox" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"widgets": {
|
||||
"dungeondoorshuffle": {
|
||||
"type": "selectbox",
|
||||
"default": "basic",
|
||||
@@ -20,3 +21,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"checkboxes": {
|
||||
"spoiler": { "type": "checkbox" },
|
||||
"suppressrom": { "type": "checkbox" },
|
||||
"usestartinventory": { "type": "checkbox" },
|
||||
"usecustompool": { "type": "checkbox" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"widgets": {
|
||||
"saveonexit": {
|
||||
"type": "selectbox",
|
||||
"options": [
|
||||
@@ -8,3 +9,4 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{
|
||||
"widgets": {
|
||||
"worlds": { "type": "spinbox" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
aenum
|
||||
|
||||
@@ -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
|
||||
|
||||
109
test-options.py
Normal file
109
test-options.py
Normal file
@@ -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])))
|
||||
Reference in New Issue
Block a user