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
Some redesigning of the settings API #408
Conversation
- The store is now split into two sections: - A list of possible options, with their description and default value. - A list of values which have been changed. - settings.{set,unset,clear,load,store} operate using this value list. This means that only values which have been changed are stored to disk. Furthermore, clearing/unsetting will reset to the /default/ value, rather than removing entirely. - settings.add can be used to register a new option. We have migrated all existing options over to use it. - The set program will now display descriptions.
I wonder if I agree that batching things into a table doesn't feel very CC. Two alternative (but perhaps not any better) options come to mind, as food for thought:
|
3f30fbf
to
199b75d
Compare
We could also add a type check for settings |
Yeah, I did wonder about allowing some basic |
You can use a table |
I'm leaving off anything more complex for now, as I want to have a think about design. This is good enough for CC:T itself, which I guess is the main thing.
I'm not entirely with some of the error messages, especially the ones that the |
This is based on some of the comments in #351, and some other things I've wanted to do. There's a couple of things going on in this change:
Add the ability to describe a specific setting.
settings.define("my_setting", { ... })
allows you to provide a default value and description about a specific setting. This has several benefits:/.settings
now only stores options which have been changed, as the bios registers default values, rather than stating their value exactly.settings.clear
andsettings.unset
reset something to its default value, rather than clearing it entirely.The
set
program can now print whether an option has been changed, and its description:settings.load
/settings.save
now default to/.settings
settings.set
and any other modifying function will fire asettings_changed
event, with the argumentsname:string, new_value, old_value
.I'd like to get some feedback from others before merging with this - there's definitely some design decisions I'm not happy with. As always, the PR can be tried online using cloud-catcher.
settings.add
is a bit of a confusing name. We probably also need a way to remove a setting's metadata, and really don't want to go withsettings.remove
.Firing an event whenever a setting changes feels somewhat inefficient, especially when doing bulk actions such as loading from
/.settings
. On one hand, this is exactly what the event system is for, but given that 99% of programs won't care about this, I wonder if there's another way. Ideas?The original issue (Settings API Improvements #351) suggested batching all changes into one single event. It works, but it also feels inelegant in its own way. Ughr, I don't know :).