Converting enum-like string settings to proper enums (attempt #3)#1306
Merged
Conversation
Frontend work should hopefully be done
Also relocating the Settings enums to prevent a circular reference
Also renaming the Settings enum to FormSettings
Not really sure what I was thinking, turning the keys into enums is overkill for sore
Changing imported JSON data to use enums for the test
Why does MoveRando.item_shuffle exist? Double-check to see why.
Rearranging a couple of enums so default values are first.
Another minor lint issue
Simplifying the import into Settings.py
Added conversion from strings to enums in cli.py, and a failsafe in Settings.py. Additional fixes: - Removed dumps in Fill.py - Changing from strings to enums in Prices.py (which I previously missed) - Added boulder_clips to GlitchesSelected - Fixed "moonkick" -> "moonkicks" in Logic.py - Fixed "skipped" -> "skip" in ShuffleBarrels.py - Fixed "starts_with" -> "start_with" in PriceRando.py
Covering the last item in the Settings object
Adjust cli.py so that it can accept data already converted to enums
Minor typo
Killklli
approved these changes
Feb 21, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original PR description:
This pull request takes all of the web page settings that acted as enums, but used string values (
"move_rando","win_condition", etc.), and replaces them with explicit enums. Other settings in the mainSettingsobject have also been replaced with enums for safety. (Incorrect strings will fail silently, but incorrect enums will crash and direct users to the bug in the code.)All of the new enums have been placed in
randomizer.Enums.Settings. This file also includes aSettingsMapdictionary, to allow for easy conversion from strings to enums. For example: callingSettingsMap["damage_amount"]["ohko"]returnsDamageAmount.ohko, andSettingsMap["starting_keys_list_selected"]["AngryAztecKey"]returnsItems.AngryAztecKey. Conversion from ints to enums also works: callingSettingsMap["damage_amount"](2)returnsDamageAmount.ohko.Four of the enums (
ActivateAllBananaports,WinCondition,HelmSetting, andMicrohintsEnabled) have been explicitly indexed, starting from zero, so they can be directly written to the ROM inApplyRandomizer.py.The
KeySelectorandEnemySelectorhave been changed, so that the value is the string name of the corresponding enum. This simplifies the code and automates the enum conversion process.This PR also identified a small bug in
MoveLocationRando.py, where"start_with"was accidentally written as"starts_with". (Another good reason to favor enums.)I was able to generate a seed with a legible spoiler log using this code, which hopefully means it works correctly.
Updates (attempt #2):
This new PR should fix the enum-conversion issue that existed when using
cli.py. That file has been changed. A failsafe was also added intoSettings.py, so if a string gets passed in place of an enum value, the code will convert that string to the enum if possible. Both of these fixes work independently of each other, as well as together.Other changes.
dumpsinFill.py, as they crashed the code and they were obsolete anyway.boulder_clipsto theGlitchesSelectedenum, in case it becomes re-enabled at some point.RandomPricesenum inPrices.py, which I previously missed."moonkick"->"moonkicks"inLogic.py"skipped"->"skip'inShuffleBarrels.py"starts_with"->"start_with"inPriceRando.pyUpdates (attempt #3):
Fixed
cli.pyso that it can accept both enum and string values for the relevant settings. (I had previously assumed that only strings would be passed throughcli.py, based on presets.)