25
25
26
26
from worlds .alttp .Rom import Sprite , LocalRom , apply_rom_settings , get_base_rom_bytes
27
27
from Utils import output_path , local_path , user_path , open_file , get_cert_none_ssl_context , persistent_store , \
28
- get_adjuster_settings , tkinter_center_window , init_logging
28
+ get_adjuster_settings , get_adjuster_settings_no_defaults , tkinter_center_window , init_logging
29
29
30
30
31
31
GAME_ALTTP = "A Link to the Past"
@@ -43,6 +43,47 @@ class ArgumentDefaultsHelpFormatter(argparse.RawTextHelpFormatter):
43
43
def _get_help_string (self , action ):
44
44
return textwrap .dedent (action .help )
45
45
46
+ # See argparse.BooleanOptionalAction
47
+ class BooleanOptionalActionWithDisable (argparse .Action ):
48
+ def __init__ (self ,
49
+ option_strings ,
50
+ dest ,
51
+ default = None ,
52
+ type = None ,
53
+ choices = None ,
54
+ required = False ,
55
+ help = None ,
56
+ metavar = None ):
57
+
58
+ _option_strings = []
59
+ for option_string in option_strings :
60
+ _option_strings .append (option_string )
61
+
62
+ if option_string .startswith ('--' ):
63
+ option_string = '--disable' + option_string [2 :]
64
+ _option_strings .append (option_string )
65
+
66
+ if help is not None and default is not None :
67
+ help += " (default: %(default)s)"
68
+
69
+ super ().__init__ (
70
+ option_strings = _option_strings ,
71
+ dest = dest ,
72
+ nargs = 0 ,
73
+ default = default ,
74
+ type = type ,
75
+ choices = choices ,
76
+ required = required ,
77
+ help = help ,
78
+ metavar = metavar )
79
+
80
+ def __call__ (self , parser , namespace , values , option_string = None ):
81
+ if option_string in self .option_strings :
82
+ setattr (namespace , self .dest , not option_string .startswith ('--disable' ))
83
+
84
+ def format_usage (self ):
85
+ return ' | ' .join (self .option_strings )
86
+
46
87
47
88
def get_argparser () -> argparse .ArgumentParser :
48
89
parser = argparse .ArgumentParser (formatter_class = ArgumentDefaultsHelpFormatter )
@@ -52,6 +93,8 @@ def get_argparser() -> argparse.ArgumentParser:
52
93
help = 'Path to an ALttP Japan(1.0) rom to use as a base.' )
53
94
parser .add_argument ('--loglevel' , default = 'info' , const = 'info' , nargs = '?' ,
54
95
choices = ['error' , 'info' , 'warning' , 'debug' ], help = 'Select level of logging for output.' )
96
+ parser .add_argument ('--auto_apply' , default = 'ask' ,
97
+ choices = ['ask' , 'always' , 'never' ], help = 'Whether or not to apply settings automatically in the future.' )
55
98
parser .add_argument ('--menuspeed' , default = 'normal' , const = 'normal' , nargs = '?' ,
56
99
choices = ['normal' , 'instant' , 'double' , 'triple' , 'quadruple' , 'half' ],
57
100
help = '''\
@@ -61,7 +104,7 @@ def get_argparser() -> argparse.ArgumentParser:
61
104
parser .add_argument ('--quickswap' , help = 'Enable quick item swapping with L and R.' , action = 'store_true' )
62
105
parser .add_argument ('--deathlink' , help = 'Enable DeathLink system.' , action = 'store_true' )
63
106
parser .add_argument ('--allowcollect' , help = 'Allow collection of other player items' , action = 'store_true' )
64
- parser .add_argument ('--disablemusic ' , help = 'Disables game music.' , action = 'store_true' )
107
+ parser .add_argument ('--music ' , default = True , help = 'Enables/ Disables game music.' , action = BooleanOptionalActionWithDisable )
65
108
parser .add_argument ('--triforcehud' , default = 'hide_goal' , const = 'hide_goal' , nargs = '?' ,
66
109
choices = ['normal' , 'hide_goal' , 'hide_required' , 'hide_both' ],
67
110
help = '''\
@@ -104,21 +147,23 @@ def get_argparser() -> argparse.ArgumentParser:
104
147
Alternatively, can be a ALttP Rom patched with a Link
105
148
sprite that will be extracted.
106
149
''' )
150
+ parser .add_argument ('--sprite_pool' , nargs = '+' , default = [], help = '''
151
+ A list of sprites to pull from.
152
+ ''' )
107
153
parser .add_argument ('--oof' , help = '''\
108
154
Path to a sound effect to replace Link's "oof" sound.
109
155
Needs to be in a .brr format and have a length of no
110
156
more than 2673 bytes, created from a 16-bit signed PCM
111
157
.wav at 12khz. https://github.com/boldowa/snesbrr
112
158
''' )
113
- parser .add_argument ('--names' , default = '' , type = str )
114
159
parser .add_argument ('--update_sprites' , action = 'store_true' , help = 'Update Sprite Database, then exit.' )
115
160
return parser
116
161
117
162
118
163
def main ():
119
164
parser = get_argparser ()
120
- args = parser .parse_args ()
121
- args . music = not args . disablemusic
165
+ args = parser .parse_args (namespace = get_adjuster_settings_no_defaults ( GAME_ALTTP ) )
166
+
122
167
# set up logger
123
168
loglevel = {'error' : logging .ERROR , 'info' : logging .INFO , 'warning' : logging .WARNING , 'debug' : logging .DEBUG }[
124
169
args .loglevel ]
@@ -530,9 +575,6 @@ def hide(self):
530
575
531
576
def get_rom_frame (parent = None ):
532
577
adjuster_settings = get_adjuster_settings (GAME_ALTTP )
533
- if not adjuster_settings :
534
- adjuster_settings = Namespace ()
535
- adjuster_settings .baserom = "Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"
536
578
537
579
romFrame = Frame (parent )
538
580
baseRomLabel = Label (romFrame , text = 'LttP Base Rom: ' )
@@ -560,33 +602,8 @@ def RomSelect():
560
602
561
603
return romFrame , romVar
562
604
563
-
564
605
def get_rom_options_frame (parent = None ):
565
606
adjuster_settings = get_adjuster_settings (GAME_ALTTP )
566
- defaults = {
567
- "auto_apply" : 'ask' ,
568
- "music" : True ,
569
- "reduceflashing" : True ,
570
- "deathlink" : False ,
571
- "sprite" : None ,
572
- "oof" : None ,
573
- "quickswap" : True ,
574
- "menuspeed" : 'normal' ,
575
- "heartcolor" : 'red' ,
576
- "heartbeep" : 'normal' ,
577
- "ow_palettes" : 'default' ,
578
- "uw_palettes" : 'default' ,
579
- "hud_palettes" : 'default' ,
580
- "sword_palettes" : 'default' ,
581
- "shield_palettes" : 'default' ,
582
- "sprite_pool" : [],
583
- "allowcollect" : False ,
584
- }
585
- if not adjuster_settings :
586
- adjuster_settings = Namespace ()
587
- for key , defaultvalue in defaults .items ():
588
- if not hasattr (adjuster_settings , key ):
589
- setattr (adjuster_settings , key , defaultvalue )
590
607
591
608
romOptionsFrame = LabelFrame (parent , text = "Rom options" )
592
609
romOptionsFrame .columnconfigure (0 , weight = 1 )
0 commit comments