API for external mods to query TM:PE mod options
See original GitHub issueAs part of #1356 there is likely going to be a lot of chainsawing of mod options, UI, etc. This could break external mods if they query stuff directly.
Is there already a stable API they can use and, if not, should we make one? That way any mod breakages can at least know the updates will be the last they’ll need for a long time due to proper API.
If my understnading is correct, we’d update TrafficManager.API.Manager.IOptionsManager
to give it some new method signatures, and then implement those methods in TrafficManager.Manager.Impl.OptionsManager
?
The methods I suggest are as follows:
// returns true if options are in a stable state to query
// eg. it would be false from Main Menu, false while loading/saving options, etc.
bool AreOptionsSafeToQuery();
// returns null if option not found or some other error
bool? GetBoolOptionByName(string optionName);
// returns null if option not found or some other error
string? GetStringOptionByName(string optionName);
The string one can be useful for stuff like language code, icon theme name, or anything enum based.
The benefit of specifying options by name is that if we rename an option we can do a simple lookup table to get new option name, thus no need for external mods to update. Additionally, if we change from fields to properties, we can handle that change internally with no action required by external mods.
LMK if this makes sense and I’ll send in a PR to get things started. The API should be available on both STABLE and TEST workshop pages before #1356 start getting merged.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
I’d say, readonly is fine. Other mods should not be able to mess with the options but check the options to see what the user picked via our API.
I’m thinking of stuff like Roundabout Builder mod, which, if memory serves, can customise the roads it places with some TMPE stuff but obviously only if those TMPE features are active. Also, I suspect Kian’s mods might need similar info.
The goal is to ensure there is already an API interface available on TEST/STABLE prior to me chainsawing the existing options code as part of https://github.com/CitiesSkylinesMods/TMPE/issues/1356