-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Add settings API ("auto settings") for host.yaml #1871
Conversation
17cc91c
to
8d971f8
Compare
Co-authored-by: el-u <[email protected]>
8d971f8
to
2ae1d6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, also did some testing of the LttP Adjuster and I didn't find any breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully generated a new host.yaml and made sure nothing was broken in regards to TLOZ, so gets an OK from me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on a new venv with both 3.10 and 3.11 on windows 11 and packaged the host.yaml correctly. There's still a lot of mixing of terms. I really think it should just all be renamed to settings where possible, and the use of the word options for any of these completely dropped. {world_folder_name}_options for example should be {world_folder_name}_settings if possible.
which either points to the installation directory, if writable, or to %home%/Archipelago otherwise. | ||
|
||
**Examples:** | ||
* C:\Program Data\Archipelago\options.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already brought up to unify the nomenclature and I agree. This feature isn't documented anywhere currently so this seems like a good idea to change. Instead of options.yaml
it can be settings.yaml
, and just support options.yaml
until we drop the old API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't touch filenames in this PR because migrating from one filename to another is gonna be easier once that's in and breaking someone's options.yaml will make sad faces.
## World Settings | ||
|
||
Worlds can define the top level key to use by defining `settings_key: ClassVar[str]` in their World class. | ||
It defaults to `{folder_name}_options` if undefined, i.e. `worlds/factorio/...` defaults to `factorio_options`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma after i.e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma after i.e. (or e.g. for that matter) is usually optional and depend on which "fork" of English you use. They all agree one should precede it though, so I'm less concerned about this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick search says that's a difference between American and British english. We had mostly BE in school, so not my fault :-D
docs/settings api.md
Outdated
|
||
Worlds define the layout of their config section using type annotation of the variable `settings` in the class. | ||
The type has to inherit from `settings.Group`. Each value in the config can have a comment by subclassing a builtin | ||
type. Some helper types are defined `settings.py`, see [Types](#Types) for a list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defined in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type. Some helper types are defined `settings.py`, see [Types](#Types) for a list. | |
The type has to inherit from `settings.Group`. Each value in the config can have a comment by subclassing a built-in | |
type. Some helper types are defined in `settings.py`, see [Types](#Types) for a list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to python builtins
. The doc page for builtins
calls it "built-in objects", so we should probably follow that doc style? Your suggestion did not select the correct lines, by the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, can worry about renaming the root filename later because that can happen without worrying about breaking existing worlds. This does open a lot of possibilities for also auto-generating some of the innosetup aspects, so I'm very excited for that.
Confirmed working on Windows 3.10 and 3.11 (with exception of OOT, but that should be fixed by #1936, as it's unrelated.)
Co-authored-by: Zach Parks <[email protected]>
…#1871) * Add settings API ("auto settings") for host.yaml * settings: no BOM when saving * settings: fix saving / groups resetting themselves * settings: fix AutoWorldRegister import Co-authored-by: el-u <[email protected]> * Lufia2: settings: clean up imports * settings: more consistent class naming * Docs: update world api for settings api refactor * settings: fix access from World instance * settings: update migration timeline * Docs: Apply suggestions from code review Co-authored-by: Zach Parks <[email protected]> * Settings: correctly resolve .exe in UserPath and LocalPath --------- Co-authored-by: el-u <[email protected]> Co-authored-by: Zach Parks <[email protected]>
…#1871) * Add settings API ("auto settings") for host.yaml * settings: no BOM when saving * settings: fix saving / groups resetting themselves * settings: fix AutoWorldRegister import Co-authored-by: el-u <[email protected]> * Lufia2: settings: clean up imports * settings: more consistent class naming * Docs: update world api for settings api refactor * settings: fix access from World instance * settings: update migration timeline * Docs: Apply suggestions from code review Co-authored-by: Zach Parks <[email protected]> * Settings: correctly resolve .exe in UserPath and LocalPath --------- Co-authored-by: el-u <[email protected]> Co-authored-by: Zach Parks <[email protected]>
What is this fixing or adding?
Instead of relying on
Utils.default_options
and a hand-writtenhost.yaml
, we generate the host.yaml now from type hints in settings.py (global) and each individual world.This way APWorlds have proper access to the host.yaml and having typed
settings
allows for cleaner code with automatic type-checking, likeself.settings.rom_path
. When saving/loading it will lazily load the type information from worlds and downcast/upcast accordingly.In addition to that, the new API also automatically opens a file-browser and auto-saves changes when a file is requested that does not exist.
Backwards compat is provided by implementing most of the dict API in settings.Group as well as keeping Utils.get_options as an alternative name.
How was this tested?
What was not tested?
What is left to do?
Utils.user_path(Utils.get_options()[...])
, which is not required anymore. Accessing a UserPath path will automatically resolve to be a user path.