[EXAMPLE] Dynamic Loading of RSO Configs directly from the mods
Posted: Wed Apr 03, 2019 5:35 pm
Hi,
While I love RSO, i find it a bit irritating that people have to badger you in order to add their configs for their new mods, however I have found a simple elegant solution to the problem.
Instead of people having to badger you to do it, why not make RSO dynamically call each mod, and request the configuration for their ores?
Well, that's what I have done and it works very well.
I simply added this code to the end of your mainconfig.lua:
Then, i added a remote interface to my mod:
This way, the mod creators themselves could add their own interface, with the name of "rsoconfig-MODNAME", as long as their handle is called getConfig RSO will pick it up dynamically when a new level loads.
I hope that you'll consider adding something like this into your mod, as it really saves you a whole lot of time, plus it's possible for mod creators to change RSO's config when they release a new version of their mod, or even a brand new one.
While I love RSO, i find it a bit irritating that people have to badger you in order to add their configs for their new mods, however I have found a simple elegant solution to the problem.
Instead of people having to badger you to do it, why not make RSO dynamically call each mod, and request the configuration for their ores?
Well, that's what I have done and it works very well.
I simply added this code to the end of your mainconfig.lua:
Code: Select all
-- Dynamically load config from other mods
for name,version in pairs(game.active_mods) do
local interfaceName = "rsoconfig-" .. name
if ( remote.interfaces[interfaceName] ~= nil and remote.interfaces[interfaceName]["getConfig"] ~= nil ) then
log("RSO -> Mod " .. name .. " configuration interface found, calling it now")
local modConfigRequest = remote.call(interfaceName, "getConfig")
if ( modConfigRequest ~= nil ) then
for key, configElement in pairs(modConfigRequest) do
config[key] = configElement
end
end
else
log("RSO -> Mod " .. name .. " does not have a configuration interface")
end
end
Then, i added a remote interface to my mod:
Code: Select all
function getRsoConfig()
local config = {}
config["ax-matter-ore"] = {
type="resource-ore",
allotment=40,
spawns_per_region={min=1, max=1},
richness=6000,
size={min=10, max=15},
min_amount=300,
starting={richness=8000, size=25, probability=1},
}
config["ax-liquid-matter"] = {
type="resource-liquid",
minimum_amount=240000,
allotment=70,
spawns_per_region={min=1, max=2},
richness={min=240000, max=400000},
size={min=2, max=5},
starting={richness=400000, size=2, probability=1},
multi_resource_chance=0.20,
multi_resource={
["coal"] = 4,
["uranium-ore"] = 1,
}
}
return config
end
remote.add_interface("rsoconfig-aix_matter", {getConfig = function() return getRsoConfig() end})
I hope that you'll consider adding something like this into your mod, as it really saves you a whole lot of time, plus it's possible for mod creators to change RSO's config when they release a new version of their mod, or even a brand new one.