Fix precedence of vars

This commit is contained in:
Mike A. Trethewey
2020-02-15 03:52:33 -08:00
parent 01fd3d418f
commit 901e5fc0c6
3 changed files with 95 additions and 62 deletions

9
Gui.py
View File

@@ -9,7 +9,7 @@ from CLI import get_settings
from DungeonRandomizer import parse_arguments from DungeonRandomizer import parse_arguments
from gui.adjust.overview import adjust_page from gui.adjust.overview import adjust_page
from gui.custom.overview import custom_page from gui.custom.overview import custom_page
from gui.loadcliargs import loadcliargs from gui.loadcliargs import loadcliargs, loadadjustargs
from gui.randomize.item import item_page from gui.randomize.item import item_page
from gui.randomize.entrando import entrando_page from gui.randomize.entrando import entrando_page
from gui.randomize.enemizer import enemizer_page from gui.randomize.enemizer import enemizer_page
@@ -29,6 +29,8 @@ def guiMain(args=None):
settings_path = os.path.join(user_resources_path) settings_path = os.path.join(user_resources_path)
if not os.path.exists(settings_path): if not os.path.exists(settings_path):
os.makedirs(settings_path) os.makedirs(settings_path)
for widget in self.pages["adjust"].content.widgets:
args["adjust." + widget] = self.pages["adjust"].content.widgets[widget].storageVar.get()
with open(os.path.join(settings_path, "settings.json"), "w+") as f: with open(os.path.join(settings_path, "settings.json"), "w+") as f:
f.write(json.dumps(args, indent=2)) f.write(json.dumps(args, indent=2))
os.chmod(os.path.join(settings_path, "settings.json"),0o755) os.chmod(os.path.join(settings_path, "settings.json"),0o755)
@@ -141,8 +143,11 @@ def guiMain(args=None):
return False return False
vcmd=(self.pages["custom"].content.register(validation), '%P') vcmd=(self.pages["custom"].content.register(validation), '%P')
# load adjust settings into options
loadadjustargs(self, self.settings)
# load args from CLI into options # load args from CLI into options
loadcliargs(self, args) loadcliargs(self, args, self.settings)
mainWindow.mainloop() mainWindow.mainloop()

View File

@@ -180,14 +180,19 @@ def adjust_page(top, parent, settings):
adjustRomFrame.pack(fill=X, expand=True) adjustRomFrame.pack(fill=X, expand=True)
def adjustRom(): def adjustRom():
options = {
"heartbeep": "heartbeep",
"heartcolor": "heartcolor",
"menuspeed": "fastmenu",
"owpalettes": "ow_palettes",
"uwpalettes": "uw_palettes",
"quickswap": "quickswap",
"nobgm": "disablemusic"
}
guiargs = Namespace() guiargs = Namespace()
guiargs.heartbeep = self.widgets["heartbeep"].storageVar.get() for option in options:
guiargs.heartcolor = self.widgets["heartcolor"].storageVar.get() arg = options[option]
guiargs.fastmenu = self.widgets["menuspeed"].storageVar.get() setattr(guiargs, arg, self.widgets[option].storageVar.get())
guiargs.ow_palettes = self.widgets["owpalettes"].storageVar.get()
guiargs.uw_palettes = self.widgets["uwpalettes"].storageVar.get()
guiargs.quickswap = bool(self.widgets["quickswap"].storageVar.get())
guiargs.disablemusic = bool(self.widgets["nobgm"].storageVar.get())
guiargs.rom = self.romVar2.get() guiargs.rom = self.romVar2.get()
guiargs.baserom = top.pages["randomizer"].pages["generation"].romVar.get() guiargs.baserom = top.pages["randomizer"].pages["generation"].romVar.get()
guiargs.sprite = self.sprite guiargs.sprite = self.sprite

View File

@@ -3,7 +3,7 @@ from gui.randomize.gameoptions import set_sprite
from Rom import Sprite from Rom import Sprite
def loadcliargs(gui, args): def loadcliargs(gui, args, settings=None):
if args is not None: if args is not None:
for k, v in vars(args).items(): for k, v in vars(args).items():
if type(v) is dict: if type(v) is dict:
@@ -13,57 +13,57 @@ def loadcliargs(gui, args):
# set up options to get # set up options to get
# Page::Subpage::GUI-id::param-id # Page::Subpage::GUI-id::param-id
options = { options = {
"randomizer": { "randomizer": {
"item": { "item": {
"retro": "retro", "retro": "retro",
"worldstate": "mode", "worldstate": "mode",
"logiclevel": "logic", "logiclevel": "logic",
"goal": "goal", "goal": "goal",
"crystals_gt": "crystals_gt", "crystals_gt": "crystals_gt",
"crystals_ganon": "crystals_ganon", "crystals_ganon": "crystals_ganon",
"weapons": "swords", "weapons": "swords",
"itempool": "difficulty", "itempool": "difficulty",
"itemfunction": "item_functionality", "itemfunction": "item_functionality",
"timer": "timer", "timer": "timer",
"progressives": "progressive", "progressives": "progressive",
"accessibility": "accessibility", "accessibility": "accessibility",
"sortingalgo": "algorithm" "sortingalgo": "algorithm"
}, },
"entrance": { "entrance": {
"openpyramid": "openpyramid", "openpyramid": "openpyramid",
"shuffleganon": "shuffleganon", "shuffleganon": "shuffleganon",
"entranceshuffle": "shuffle" "entranceshuffle": "shuffle"
}, },
"enemizer": { "enemizer": {
"potshuffle": "shufflepots", "potshuffle": "shufflepots",
"enemyshuffle": "shuffleenemies", "enemyshuffle": "shuffleenemies",
"bossshuffle": "shufflebosses", "bossshuffle": "shufflebosses",
"enemydamage": "enemy_damage", "enemydamage": "enemy_damage",
"enemyhealth": "enemy_health" "enemyhealth": "enemy_health"
}, },
"dungeon": { "dungeon": {
"mapshuffle": "mapshuffle", "mapshuffle": "mapshuffle",
"compassshuffle": "compassshuffle", "compassshuffle": "compassshuffle",
"smallkeyshuffle": "keyshuffle", "smallkeyshuffle": "keyshuffle",
"bigkeyshuffle": "bigkeyshuffle", "bigkeyshuffle": "bigkeyshuffle",
"dungeondoorshuffle": "door_shuffle", "dungeondoorshuffle": "door_shuffle",
"experimental": "experimental" "experimental": "experimental"
}, },
"gameoptions": { "gameoptions": {
"hints": "hints", "hints": "hints",
"nobgm": "disablemusic", "nobgm": "disablemusic",
"quickswap": "quickswap", "quickswap": "quickswap",
"heartcolor": "heartcolor", "heartcolor": "heartcolor",
"heartbeep": "heartbeep", "heartbeep": "heartbeep",
"menuspeed": "fastmenu", "menuspeed": "fastmenu",
"owpalettes": "ow_palettes", "owpalettes": "ow_palettes",
"uwpalettes": "uw_palettes" "uwpalettes": "uw_palettes"
}, },
"generation": { "generation": {
"spoiler": "create_spoiler", "spoiler": "create_spoiler",
"suppressrom": "suppress_rom" "suppressrom": "suppress_rom"
}
} }
}
} }
for mainpage in options: for mainpage in options:
for subpage in options[mainpage]: for subpage in options[mainpage]:
@@ -71,7 +71,10 @@ def loadcliargs(gui, args):
arg = options[mainpage][subpage][widget] arg = options[mainpage][subpage][widget]
gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(getattr(args, arg)) gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(getattr(args, arg))
if subpage == "gameoptions" and not widget == "hints": if subpage == "gameoptions" and not widget == "hints":
gui.pages["adjust"].content.widgets[widget].storageVar.set(getattr(args, arg)) hasSettings = settings is not None
hasWidget = ("adjust." + widget) in settings if hasSettings else None
if hasWidget is None:
gui.pages["adjust"].content.widgets[widget].storageVar.set(getattr(args, arg))
gui.pages["randomizer"].pages["enemizer"].enemizerCLIpathVar.set(args.enemizercli) gui.pages["randomizer"].pages["enemizer"].enemizerCLIpathVar.set(args.enemizercli)
gui.pages["randomizer"].pages["generation"].romVar.set(args.rom) gui.pages["randomizer"].pages["generation"].romVar.set(args.rom)
@@ -101,3 +104,23 @@ def loadcliargs(gui, args):
set_sprite(sprite_obj, r_sprite_flag, spriteSetter=sprite_setter_adj, set_sprite(sprite_obj, r_sprite_flag, spriteSetter=sprite_setter_adj,
spriteNameVar=gui.pages["adjust"].content.spriteNameVar2, spriteNameVar=gui.pages["adjust"].content.spriteNameVar2,
randomSpriteVar=gui.randomSprite) randomSpriteVar=gui.randomSprite)
def loadadjustargs(gui, settings):
options = {
"adjust": {
"content": {
"nobgm": "adjust.nobgm",
"quickswap": "adjust.quickswap",
"heartcolor": "adjust.heartcolor",
"heartbeep": "adjust.heartbeep",
"menuspeed": "adjust.menuspeed",
"owpalettes": "adjust.owpalettes",
"uwpalettes": "adjust.uwpalettes"
}
}
}
for mainpage in options:
for subpage in options[mainpage]:
for widget in options[mainpage][subpage]:
key = options[mainpage][subpage][widget]
gui.pages[mainpage].content.widgets[widget].storageVar.set(settings[key])