mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-17 11:11:10 +02:00
Export versioned mod option schemas
This commit is contained in:
@@ -19,6 +19,8 @@ local Loader = {}
|
||||
Loader.__index = Loader
|
||||
|
||||
local MOD_STATE_FILE = "mod_state.lua" -- legacy migration only
|
||||
local OPTION_SCHEMAS_FILENAME = "mod_option_schemas.json"
|
||||
local OPTION_SCHEMAS_VERSION = 1
|
||||
|
||||
-- walk a dotted target path without creating anything; the base view a
|
||||
-- registry folds against must never perturb Data on a mod-free boot
|
||||
@@ -191,6 +193,43 @@ function Loader:_saveState()
|
||||
SaveData.saveOptions(options, self.fs)
|
||||
end
|
||||
|
||||
-- Export the runtime option schemas after mod entry chunks have run. This
|
||||
-- is an optional, data-only handoff for native launchers: they must not run
|
||||
-- arbitrary mod code before boot just to discover settings. The snapshot is
|
||||
-- deliberately written beside options.lua so every platform's native shell
|
||||
-- can use the same filesystem contract.
|
||||
function Loader:_writeOptionSchemas()
|
||||
if not self.fs.write then return end
|
||||
|
||||
local mods = {}
|
||||
for id, schema in pairs(self.optionSchemas) do
|
||||
if self.mods[id] and self.mods[id].enabled and not self.mods[id].failed then
|
||||
mods[id] = schema
|
||||
end
|
||||
end
|
||||
|
||||
-- Do not create storage on a fresh mod-free boot, but do overwrite an old
|
||||
-- snapshot when the current boot has no schemas so disabled/failed mods do
|
||||
-- not leave stale native settings rows behind.
|
||||
if next(mods) == nil
|
||||
and not (self.fs.getInfo and self.fs.getInfo(OPTION_SCHEMAS_FILENAME)) then
|
||||
return
|
||||
end
|
||||
|
||||
local ok, encoded = pcall(Json.encode, {
|
||||
schema_version = OPTION_SCHEMAS_VERSION,
|
||||
mods = mods,
|
||||
})
|
||||
if not ok then
|
||||
Logger.warn("mod option schema export: failed to encode: %s", tostring(encoded))
|
||||
return
|
||||
end
|
||||
local written, err = self.fs.write(OPTION_SCHEMAS_FILENAME, encoded)
|
||||
if not written then
|
||||
Logger.warn("mod option schema export: failed to write: %s", tostring(err))
|
||||
end
|
||||
end
|
||||
|
||||
function Loader:setEnabled(id, enabled)
|
||||
if not self.mods[id] then return false end
|
||||
self.disabled[id] = not enabled
|
||||
@@ -1089,6 +1128,7 @@ function Loader:load(data)
|
||||
-- which resolves every path to itself (14 §asset resolution).
|
||||
Assets.installLoader(self)
|
||||
self.events:emit("mods.loaded", { loader = self, data = data })
|
||||
self:_writeOptionSchemas()
|
||||
self.initialized = true
|
||||
return #self.errors == 0
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user