Skip to content

Commit

Permalink
update-presets: Trailing commas in arrays/objects when generating Rus…
Browse files Browse the repository at this point in the history
…t syntax
  • Loading branch information
fenhl committed Jan 27, 2025
1 parent 9bb3f11 commit 94680a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions update-presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ def get_preset(presets, name):
else:
return None

def print_rust_json_setting(name, value, indent):
if isinstance(value, list):
if value:
print(' ' * indent + f'format!("{name}") => json!([')
for elt in value:
for line in (json.dumps(elt, indent=4) + ',').splitlines():
print(' ' * (indent + 4) + line)
print(' ' * indent + ']),')
else:
print(' ' * indent + f'format!("{name}") => json!([]),')
elif isinstance(value, dict):
if value:
print(' ' * indent + f'format!("{name}") => json!({{')
for key, elt in value.items():
print_rust_json_setting(key, elt, indent + 4)
print('}),')
else:
print(' ' * indent + f'format!("{name}") => json!({{}}),')
else:
print(' ' * indent + f'format!("{name}") => json!({json.dumps(value)}),')

if __name__ == '__main__':
arguments = docopt.docopt(__doc__)
new_presets = {}
Expand All @@ -108,12 +129,12 @@ def get_preset(presets, name):
preset = json.loads(subprocess.run([sys.executable, 'OoTRandomizer.py', '--convert_settings', '--settings_string', arguments['<preset>']], stdout=subprocess.PIPE, encoding='utf-8', check=True).stdout)
non_default = {name: value for name, value in preset.items() if value != SETTINGS_DICT[name].default}
if arguments['--rust']:
print('collect![')
print(' collect![')
for name, value in non_default.items():
if name == 'aliases':
continue
print('\n '.join(f' format!("{name}") => json!({json.dumps(value, indent=4)}),'.splitlines())) #TODO trailing commas in arrays/objects
print(']')
print_rust_json_setting(name, value, 8)
print(' ]')
else:
print(json.dumps(non_default, indent=4))
elif arguments['diff']:
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__version__ = '8.2.50'

# This is a supplemental version number for branches based off of main dev.
supplementary_version = 1
supplementary_version = 2

# Pick a unique identifier byte for your fork if you are intending to have a long-lasting branch.
# This will be 0x00 for main releases and 0x01 for main dev.
Expand Down

0 comments on commit 94680a4

Please sign in to comment.