How to persist values across saves

i'm currently implementing the config options that i've been planning for my mods. after that, i'm going to try to create a decorator-based extension to the options panel, based on my experience with the similar City Details panel. if that works out, it'll be much more resistant to breakage from game updates and other mods. goal is to create a single script that handles the Mods tab and the ModSettings singleton just by dropping it into your mod. if it works then i also have a plan for decentralized updates, so that other folks won't be dependent on me if a game update breaks the system while i'm unavailable.
 
I agree with this. Seeing all the mod options at a glance is preferable, and if there are too many a scrollbar would be better, and more in style with the other options tabs, than a dropdown.

How many users will have 15+ mods with options? By the time we get there, Firaxis might have brought us modding tools and some form of mod options / manager. For now, I'd say we go with all options visible directly in the tab.
dropdown was a quick win to make it work if lot of options. considering each mod have only one group, make group collapsible will be a good solution.

if you only wait for firaxis. ne need for mod, just put in in unused category (there are 2 or 3) and UpdateText of that category ... but i prefer avoid that
 
ok, this was way easier than i expected. i thought i was going to need to make a pretty complex decorator, but it turns out that i just needed to add a couple of property definitions to the current templates:

JavaScript:
import { CategoryData, CategoryType } from '/core/ui/options/options-helpers.js';

CategoryType["Mods"] = "mods";
CategoryData[CategoryType.Mods] = {
    title: "LOC_UI_CONTENT_MGR_SUBTITLE",
    description: "LOC_UI_CONTENT_MGR_SUBTITLE_DESCRIPTION",
};

and then change your mod category to Category.Mods. i'm testing to see if there are any more subtleties to it, but these panels are autogenerated from the CategoryData properties with only a few custom behaviors. you don't need to override the game scripts at all, they're already extensible through data definitions.

so far it works for me, the main drawback is that the tab bar is ugly. gonna see if i can style that in a conflict-free way. the other difference from the built-in tabs is that some of those have custom logic for cancel & reset, but i don't think those features were working for mods anyway. [update: i took a closer look at this, and "Graphics" is the only tab that looks like it might be hooked up to specific behavior. the rest all hit default clauses with generic behavior, same as my new tab.]

mod-config.jpg
 
Last edited:
dropdown was a quick win to make it work if lot of options. considering each mod have only one group, make group collapsible will be a good solution.

if you only wait for firaxis. ne need for mod, just put in in unused category (there are 2 or 3) and UpdateText of that category ... but i prefer avoid that
it's even simpler than that, you can just add your own tab definitions with whatever title and tooltip you want, see above
 
if you have multiple mods, you can also share a heading between all of them. you just need to define the heading with <InsertOrIgnore> instead of <Row> so that you don't get data validation errors. for example, here's all three of my mods joined into one group:

XML:
<InsertOrIgnore Tag="LOC_OPTIONS_GROUP_BZ_MODS">
    <Text>trixie's mods</Text>
</InsertOrIgnore>

1741873709805.png
 
if you have multiple mods, you can also share a heading between all of them. you just need to define the heading with <InsertOrIgnore> instead of <Row> so that you don't get data validation errors. for example, here's all three of my mods joined into one group:

Ow, I love that. That is looking good!

Edit: Is the order in which these options from different mods appear random, and thus different between game sessions? I noticed that this differs from your previous post.
 
Ow, I love that. That is looking good!

Edit: Is the order in which these options from different mods appear random, and thus different between game sessions? I noticed that this differs from your previous post.
yeah, it depends on the load order, which is not consistent. fixing that would be a good candidate for a small data mod like i did with Resource Re-sorts for the resource screen. the game collects all of the options into a data model, so it should be possible to sort it before presentation.

similarly you could make a mod to turn the option groups into accordions, or a dropdown like Mattifus's gif earlier. none of that is necessary to create the tab and put your mods on it, though. that just takes a few lines of code that you can add to the ModSettings script like i did. you can do it from multiple mods without conflict – i did it in all three of mine.
 
btw the option order is stable within a mod, it's just the order of the mods that varies according to the whims of the mod loader. the six options in that last pic are from three different mods. (some of the variance in the pictures is also because i was still working out what order to present the options within each mod)
 
Sorting
btw the option order is stable within a mod, it's just the order of the mods that varies according to the whims of the mod loader. the six options in that last pic are from three different mods. (some of the variance in the pictures is also because i was still working out what order to present the options within each mod)
Yeah, I figured that. Sorting would be a good idea for the headings (especially if the number of mods using this grows), but not for the options under one header. But that makes combining multiple mods under one header a bit weird, with options being in a different order between game sessions.
 
Sorting

Yeah, I figured that. Sorting would be a good idea for the headings (especially if the number of mods using this grows), but not for the options under one header. But that makes combining multiple mods under one header a bit weird, with options being in a different order between game sessions.
heh, it just occurred to me that i could force the order by giving my mods slightly different LoadOrder
 
ok, this was way easier than i expected. i thought i was going to need to make a pretty complex decorator, but it turns out that i just needed to add a couple of property definitions to the current templates:

JavaScript:
import { CategoryData, CategoryType } from '/core/ui/options/options-helpers.js';

CategoryType["Mods"] = "mods";
CategoryData[CategoryType.Mods] = {
    title: "LOC_UI_CONTENT_MGR_SUBTITLE",
    description: "LOC_UI_CONTENT_MGR_SUBTITLE_DESCRIPTION",
};

and then change your mod category to Category.Mods. i'm testing to see if there are any more subtleties to it, but these panels are autogenerated from the CategoryData properties with only a few custom behaviors. you don't need to override the game scripts at all, they're already extensible through data definitions.

so far it works for me, the main drawback is that the tab bar is ugly. gonna see if i can style that in a conflict-free way. the other difference from the built-in tabs is that some of those have custom logic for cancel & reset, but i don't think those features were working for mods anyway. [update: i took a closer look at this, and "Graphics" is the only tab that looks like it might be hooked up to specific behavior. the rest all hit default clauses with generic behavior, same as my new tab.]

View attachment 724945
Lol u juste copy the way I build it too....
But totally annilaye possibility to centralized way ti build collapsible after
 
it's even simpler than that, you can just add your own tab definitions with whatever title and tooltip you want, see above
you know i'm not stupid that u can make that. the goal was to allow light view without tons of options. And also let end user decision to have a Mod Category
 
Lol u juste copy the way I build it too....
But totally annilaye possibility to centralized way ti build collapsible after
i did not copy anything from your mod, and i don't appreciate the accusation of plagiarism.

i started to review your mod last night to see if it was stable enough to trust an external dependency. right away i found problems in your .modinfo, and you ignored me when i asked about it on discord. i told you this last night when you suggested that i fork your project: "i don't find this useful as a starting point, i stopped reviewing the code after i noticed the first couple problems."

i started writing a decorator class, but first i saw that i was going to need to create a CategoryType. once i saw how they were defined, i realized that they were trivial to extend, and the game even had a perfect set of locale strings from the Additional Content menu.

if you already knew that, why didn't you share that information? i even specifically told you that i was looking for solutions like this, without overriding screen-options.js, and several other people said the same. that's why i immediately shared my discovery!
 
really ... anyways, there isn't on other way, but say you don't see it in a 2 file mode he's hard to think
Can't it just be that two people got to the same code for the same solution? It's a small code snippet.

I don't think we'll get anywhere with pointing fingers. Let's just work together, or otherwise leave each other be.
 
Can't it just be that two people got to the same code for the same solution? It's a small code snippet.
seriously! plus i did the research to find & reuse existing localized text from the base game, so that we can use it in any language without needing extra translations. was not a ton of effort, but it's an important part of the snippet and the only "creative" element because the rest was directly from the game scripts.

speaking of which, i adapted my snippet from the CategoryData definitions in the base game scripts (core/ui/options/options-helpers.js):
JavaScript:
export const CategoryData = {
    [CategoryType.Accessibility]: {
        title: "LOC_OPTIONS_CATEGORY_ACCESSIBILITY",
        description: "LOC_OPTIONS_CATEGORY_ACCESSIBILITY_DESCRIPTION"
    },
    // ...
};
based on the filenames i'd guess this is also where Mattifus got the code. it's no surprise that they look similar.
 
Last edited:
i update description/ReadMe of ModSettingManager to be clear of how to add option in mod settings

Also update mod to take any mod put option into Mods Category.
Modder have 2 poperties available if they want a custom rendering if user have ModSettingsManager installed.
 
Back
Top Bottom