Mod "Setting"/"Config" Interface

User avatar
DaCyclops
Long Handed Inserter
Long Handed Inserter
Posts: 85
Joined: Mon Aug 25, 2014 12:37 am
Contact:

Mod "Setting"/"Config" Interface

Post by DaCyclops »

With the progression of the modding portal and the integration possible thanks to it, you have mentioned a wish for having features like "automatic downloading of mods when connecting to a server" and other useful features. This would greatly increase the ease-of-use of mods, however I can see a major limiter that will be encountered with this, and would have to be dealt with eventually...

At the current moment, if a mod has a "config" setting, it is stored as LUA within the mod itself (either a standalone config.lua file, or part of control.lua), which users can open and edit themselves. However, if a user does this, their mod file is different to the "normal" file. If another player wants to join their server, they need to have the exact same version of the mod, down to these adjustments, or the Mod will have a different signature to the other version, and be rejected. Or if it isnt rejected, it will cause a desync the first moment the unmodified mod does something different to the modified mod.

I wish to suggest the idea of a unified "Setting" interface be implemented for Mod use. Its use would be storing settings that could be considered "install-wide" as opposed to "map-wide" (though it could be expanded). You could also handily provide users an easier interface for modifying their config without needing to extract the file, edit it, recompress it, and reload the game.

You already have the perfect file and GUI location for all this - the "Mods" button on the main menu, and mod-list.json file already used for mods.

Some things I could see happening with this:
  • A mod like Foreman mod could "read" commonly used blueprint strings from a user's install, saving time when starting a new world, and export those same strings on command.
  • EvoGUI could have a "default" settings string for their users, so they can pre-configure what is turned on/off when they start a new world
  • A tweak mod could do multiple things, and have them all disabled by default, so users opt-in to their tweaks
  • a mod could provide multiple interface-only adjustments that don't require the server to know/care (for example the Red Alerts mod)
And the biggest bonus, mod files wouldn't need to be edited per-user, meaning automatic updating/downloading is easier to perform.


Details
Imagine if in info.json a mod could define a list of "settings" with a default value. Something like this

Code: Select all

{
  "name": "crazylagmaker",
  "version": "0.1.0",
  "title": "Crazy Lagmaker",
  "author": "DaCyclops",
  "homepage": "",
  "contact": "dacyclops@dacyclops.com",
  "description": "Adds something that polls to much, and causes lag...",
  "dependencies": ["base >= 0.12.11"],
  "settings": [{"poll_rate": 180, "poll_rate_2": 60 }]
}
When the mod is loaded for the first time, in the same way they are added to mod-list.json, it reads those settings, and adds any new ones using the defined "default" value. If it finds a value already, it just leaves it there at its current value.

Code: Select all

{
    "mods": [
        {
            "name": "base",
            "enabled": "true"
        },
        {
            "name": "crazylagmaker",
            "enabled": "true"
            "settings": [
               {
                 "poll_rate": "180",
                 "poll_rate_2": "60"
               }
            ]
        }
    ]
}
In turn, you could place these Settings below a linebreak on the Mods list, allowing ease of user modifying settings for their own local use.
(No example Pic, dont have time to Photoshop an example)

These settings, defined in mod-list.json, would be retained install-wide, and then could be "called" as part of the initialization of the mod's control.lua - Mods usually can only call their own "settings". And there could be a function for writing as well (useful in the EvoGUI and Foreman examples above). This would only be doable in the code that is called when the map itself is loaded (control.lua, not data.lua and its cousins, and the prototypes and such.)

For example, in its control.lua on_init section a mod could call something like

Code: Select all

 PollRate = data.mod_config.readConfig("poll_rate")
 Poll_Rate2 = data.mod_config.readConfig("poll_rate_2")
This would load the "Settings" assigned to it by its info.json and potentially modified in mod-list.json into the current code to be used. If a user wants to adjust a setting, they quit back to the main menu, and change the setting. Since its only read during map load, the setting itself should be re-read every time the map loads.

If the implementation was like this, users could have a single downloaded version of "crazylagmaker", but each have their own settings for how often it makes its lag. If they wanted more lag, they just goto the main menu, click on Mods, choose "crazylagmaker" and change the "PollRate" to 120. And features like Automatic Updating of mods would be possible, as the settings are not stored in the mod file itself. And servers would not need to distribute their own copy of the mod if they want "crazylagmaker" to make crazy lag less often..

The bonus to an implementation like this, is the potential to pass a pre-defined list of "settings" from a server when connected. since these settings would potentially only effect connections to that exact server. And again, all the server would need would to stream its own mod-list.json and let the local user read the required files. Then when connecting to the server, instead of reading its local "settings" it reads the server's "Settings" and init's the control.lua the way the server would expect. I am aware that some of this could be replicated by clever use of Globals inside the control.LUA, but that wouldnt help with ease-of-modifying. It also requires the Mod to implement the clever use, not the Engine.

Of course there is plenty missing from my examples, especially as my knowledge of LUA/JSON is very... limited. But I think an interface as such might make the process of going forward much more straightforward for modders and users alike.

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Supercheese »

This would be great to have; OpenTTD implements its mod "parameters" in a fashion very similar to your suggestion: https://wiki.openttd.org/NewGRF#Version_1.1_and_later

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

I have suggested something like this before, but just a little more basic. I think the main issue is that any change in entities will currently require a full game restart. Other than that, I think one of the devs said it is worth looking into.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DedlySpyder
Filter Inserter
Filter Inserter
Posts: 253
Joined: Fri Jun 20, 2014 11:42 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by DedlySpyder »

bobingabout wrote:I have suggested something like this before, but just a little more basic. I think the main issue is that any change in entities will currently require a full game restart. Other than that, I think one of the devs said it is worth looking into.
If the new mod being downloaded adds any prototypes, then the game would need a restart, so the game with most likely need restarting to add a new mod anyways

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

DedlySpyder wrote:
bobingabout wrote:I have suggested something like this before, but just a little more basic. I think the main issue is that any change in entities will currently require a full game restart. Other than that, I think one of the devs said it is worth looking into.
If the new mod being downloaded adds any prototypes, then the game would need a restart, so the game with most likely need restarting to add a new mod anyways
this discussion, as far as I understand it, isn't about adding new mods, it's changing configs within a mod, which will likely change the contents of that mod (As if it was a different version of the mod)

Anyway, the OP mentions changes in the control.lua file, which wouldn't require a restart. My config is for the data.lua series of files, which would require a restart.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
DaCyclops
Long Handed Inserter
Long Handed Inserter
Posts: 85
Joined: Mon Aug 25, 2014 12:37 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by DaCyclops »

bobingabout wrote:
DedlySpyder wrote:
bobingabout wrote:I have suggested something like this before, but just a little more basic. I think the main issue is that any change in entities will currently require a full game restart. Other than that, I think one of the devs said it is worth looking into.
If the new mod being downloaded adds any prototypes, then the game would need a restart, so the game with most likely need restarting to add a new mod anyways
this discussion, as far as I understand it, isn't about adding new mods, it's changing configs within a mod, which will likely change the contents of that mod (As if it was a different version of the mod)

Anyway, the OP mentions changes in the control.lua file, which wouldn't require a restart. My config is for the data.lua series of files, which would require a restart.
Yeah, the idea does kinda fall under when you look at mods that do all their config in data.lua files. Though, taking a quick look at bobmodules... couldnt you technically just have all the prototypes load, and then disable/hidden the things that are disabled upon map init??

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

DaCyclops wrote:
bobingabout wrote:
DedlySpyder wrote:
bobingabout wrote:I have suggested something like this before, but just a little more basic. I think the main issue is that any change in entities will currently require a full game restart. Other than that, I think one of the devs said it is worth looking into.
If the new mod being downloaded adds any prototypes, then the game would need a restart, so the game with most likely need restarting to add a new mod anyways
this discussion, as far as I understand it, isn't about adding new mods, it's changing configs within a mod, which will likely change the contents of that mod (As if it was a different version of the mod)

Anyway, the OP mentions changes in the control.lua file, which wouldn't require a restart. My config is for the data.lua series of files, which would require a restart.
Yeah, the idea does kinda fall under when you look at mods that do all their config in data.lua files. Though, taking a quick look at bobmodules... couldnt you technically just have all the prototypes load, and then disable/hidden the things that are disabled upon map init??
Except in that modules mod you mentioned, one of the things that changes is the values of each module. you can't change those once the game is initiated.

Although there are some things that could simply be disabled, like additional entities, most of them are recipe changes. Can you change the ingredients of a recipe in control.lua?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 14152
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Rseding91 »

Some initial thoughts:

This is something I've wanted to do for a while and I think I might know how to do it.

1. We would add a new bit of data that is processed per mod: settings.lua

2. The settings.lua would work similar to how the data.lua file works in that you'd define key value pairs along with maybe "is restart required" for each setting:

Code: Select all

settings:extend(
{
    {
        type = "string",
        name = "default-name",
        value = "test-name"
    },
    {
        type = "boolean"
        name = "hard-mode",
        value = false,
        requires_restart = true -- this defaults to false if not defined
    }
})
3. Name would be unique for your mod

4. Mods would not share settings - the settings would get processed in series like data.lua does but each mods settings would be stored uniquely in something like "data.settings["mod-name"][... values ...]"

5. When a game is loaded:
* Any settings that no longer exist in the settings.lua file would be removed from the saved data.
* Any settings that still exist in the settings.lua file would keep the values they had from the save file.
* Any settings that are new in the settings.lua file would get added to the save file.

6. When a setting is changed that *is not* marked as "requires_restart" an in-game event would be fired for all mods: "on_settings_changed" that would contain a table of mod name + settings changed (with old and new values) for each mod settings changed.

The settings would be accessible under options->mod settings with a tab for each mod that had settings defined. Similar to how controls are setup.

One thing that this wouldn't cover initially but might be possible with some more thought: lists. If you had a setting like "machines this module works in" that was a list of entity names although I don't know how common that is as a setting it might still be possible to implement as a setting option.

Thoughts?
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

I think that's definitely a good starting point. A reasonable file structure too.


Though I would have to ask a couple of question.

1. Would the settings (your value= tag) stored within this settings file, be updated when they are changed, or stored somewhere else?
2. Would the settings be accessable in the data phases of mod loading, and the in game control.lua scripts? (Most of my settings are actually used in my data.lua and some in data.updates.lua)

The answer to question 1 isn't that important from a modders point of view, but It would be useful if the settings were stored externally to the mod, which would allow me to change the values while testing, without changing the default values stored in the mod (Currently, care has to be taken that I revert everything back to defaults before distributing my mods)

The answer to question 2 is very important to me though. If it doesn't effect data.lua and that series of files, then I wouldn't be able to use it.


Also, assuming the answer to question 1 is stored separately, would it be possible to list something other than the mods name? (For example, just list everything as being under bobmods), since moving to the config mod, some of my options are actually used through more than one mod.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 14152
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Rseding91 »

bobingabout wrote:1. Would the settings (your value= tag) stored within this settings file, be updated when they are changed, or stored somewhere else?
The settings would be stored in the save file and not updated when the mod was changed. They would be deleted if the mod ones got deleted and added if the mod added ones but existing ones would keep the value from the save file. If it didn't work that way it would reset settings every time you restarted the game :)
bobingabout wrote:2. Would the settings be accessable in the data phases of mod loading, and the in game control.lua scripts? (Most of my settings are actually used in my data.lua and some in data.updates.lua)
Yes, they would be in a global table populated before the data phase of loading starts. Probably "settings". The "settings.lua" load phase would happen before the "data.lua" phase.
bobingabout wrote:Would it be possible to list something other than the mods name? (For example, just list everything as being under bobmods), since moving to the config mod, some of my options are actually used through more than one mod.
I imagine it working in that if you use "settings:extend" it would go under the mod currently doing the extending. If you manually defined values you could put them under any mod name you wanted "settings.raw['bobsmods'][...] = ..."
If you want to get ahold of me I'm almost always on Discord.

orzelek
Smart Inserter
Smart Inserter
Posts: 3922
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by orzelek »

Ohhhh shiny :D

Would be really cool to expose some of settings outside of config file.
One addition could be a tooltip text for the setting describing what it does.

User avatar
DaCyclops
Long Handed Inserter
Long Handed Inserter
Posts: 85
Joined: Mon Aug 25, 2014 12:37 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by DaCyclops »

Rseding91 wrote:Some initial thoughts:

...

Thoughts?
This is why I leave the real coding to real coders, who actually think a little better about this stuff than me :P

This would meet my suggestion as well, but opens the question of how it would handle porting to a "server sends settings" structure when requires_restart is true. Though, the suggestion of "install-based" settings (like EvoGUI config, or Foreman saved blueprints) doesnt match up with it.

I just think that having whatever "settings" are required listed in mod-list.json means that renaming the mods folder could also be used as a "switch settings" method.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

Rseding91 wrote:
bobingabout wrote:1. Would the settings (your value= tag) stored within this settings file, be updated when they are changed, or stored somewhere else?
The settings would be stored in the save file and not updated when the mod was changed. They would be deleted if the mod ones got deleted and added if the mod added ones but existing ones would keep the value from the save file. If it didn't work that way it would reset settings every time you restarted the game :)
I'm not sure I'm keen on the idea of not being able to change the settings once they're saved in a save file... I quite often use the same savegame to do testing, changing settings to see the results in the game, change values to see how balanced they are, and change them, well, pretty much constantly.

I can see why this would be good from the player's perspective, but it does make things awkward for the modder.

Is there any way to compromise on this idea? Perhaps an option in the config file to enable editing settings in existing savegames?
I'd put this sort of thing in the same field as changing mods and using migration scripts.

Also, I'm not entirely sure saving the "requires_restart = true" settings in the save game. Those that don't though, no problem!
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 14152
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Rseding91 »

bobingabout wrote:
Rseding91 wrote:
bobingabout wrote:1. Would the settings (your value= tag) stored within this settings file, be updated when they are changed, or stored somewhere else?
The settings would be stored in the save file and not updated when the mod was changed. They would be deleted if the mod ones got deleted and added if the mod added ones but existing ones would keep the value from the save file. If it didn't work that way it would reset settings every time you restarted the game :)
I'm not sure I'm keen on the idea of not being able to change the settings once they're saved in a save file... I quite often use the same savegame to do testing, changing settings to see the results in the game, change values to see how balanced they are, and change them, well, pretty much constantly.

I can see why this would be good from the player's perspective, but it does make things awkward for the modder.

Is there any way to compromise on this idea? Perhaps an option in the config file to enable editing settings in existing savegames?
I'd put this sort of thing in the same field as changing mods and using migration scripts.

Also, I'm not entirely sure saving the "requires_restart = true" settings in the save game. Those that don't though, no problem!
You'd just change them in the game settings screen.
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

Rseding91 wrote:
bobingabout wrote:
Rseding91 wrote:
bobingabout wrote:1. Would the settings (your value= tag) stored within this settings file, be updated when they are changed, or stored somewhere else?
The settings would be stored in the save file and not updated when the mod was changed. They would be deleted if the mod ones got deleted and added if the mod added ones but existing ones would keep the value from the save file. If it didn't work that way it would reset settings every time you restarted the game :)
I'm not sure I'm keen on the idea of not being able to change the settings once they're saved in a save file... I quite often use the same savegame to do testing, changing settings to see the results in the game, change values to see how balanced they are, and change them, well, pretty much constantly.

I can see why this would be good from the player's perspective, but it does make things awkward for the modder.

Is there any way to compromise on this idea? Perhaps an option in the config file to enable editing settings in existing savegames?
I'd put this sort of thing in the same field as changing mods and using migration scripts.

Also, I'm not entirely sure saving the "requires_restart = true" settings in the save game. Those that don't though, no problem!
You'd just change them in the game settings screen.
oh, okay, I thought you meant in the save game :lol:
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

Just a couple of questions.

in the case of Float and Int type values, could a min and max be specified also? I mean, you might allow for a multiplier somewhere, but it starts acting strange, or even causes crashes if set too high, so to prevent silliness, you could use some known sane values and have a max set to 10, and a min of 0.1.

Aaand, although I don't really expect it for 0.13.0 launch (even though it would be insanely useful), you do appear to have a plan, any idea when we might see such a feature in the game?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 14152
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Rseding91 »

I'm not sure when I might get around to this. Something that will still need to be addressed is prototype config data vs runtime config data.

Prototype data has to be available before the game even loads fully so it would need to be split and saved locally on disk. That means if you tried to connect to someone with a different set of prototype config data you would need to restart your game.
If you want to get ahold of me I'm almost always on Discord.

User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1524
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by binbinhfr »

very nice idea this settings.lua, saved in the map.
The settings would be accessible under options->mod settings with a tab for each mod that had settings defined. Similar to how controls are setup.
I just wonder how it would work in MP, to avoid desync ?

If a client change one setting, it should duplicate on all other clients, no ?
My mods on the Factorio Mod Portal :geek:

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Mod "Setting"/"Config" Interface

Post by bobingabout »

Rseding91 wrote:I'm not sure when I might get around to this. Something that will still need to be addressed is prototype config data vs runtime config data.

Prototype data has to be available before the game even loads fully so it would need to be split and saved locally on disk. That means if you tried to connect to someone with a different set of prototype config data you would need to restart your game.
Prototype data must require restart. Which could be annoying when trying to join a multiplayer game, but a necasary evil that I could live with (better than trying to manually send config files, like you have to now) until you can come up with a way to reload prototype data without restarting the client.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Glockshna
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Tue Jan 21, 2014 7:57 am
Contact:

Re: Mod "Setting"/"Config" Interface

Post by Glockshna »

Posting to +1. I would like to see this implemented.

Post Reply

Return to “Implemented mod requests”