Skip to content
Snippets Groups Projects
Commit 59591e9b authored by dg's avatar dg
Browse files

Savefiles are now bound to the addons that created them, they forceload only...

Savefiles are now bound to the addons that created them, they forceload only those, and cant load if they do not exist

git-svn-id: http://svn.net-core.org/repos/t-engine4@5701 51575b47-30f0-44d4-a5cc-537603b46e54
parent 470067e1
No related branches found
No related tags found
No related merge requests found
......@@ -292,22 +292,31 @@ function _M:listAddons(mod, ignore_compat)
return adds
end
function _M:loadAddons(mod)
function _M:loadAddons(mod, saveuse)
local adds = self:listAddons(mod, true)
if saveuse then saveuse = table.reverse(saveuse) end
-- Filter based on settings
for i = #adds, 1, -1 do
local add = adds[i]
if config.settings.addons[add.for_module] and config.settings.addons[add.for_module][add.short_name] ~= nil then
-- Forbidden by config
if config.settings.addons[add.for_module][add.short_name] == false then
print("Removing addon"..add.short_name..": not allowed by config")
if saveuse then
if not saveuse[add.short_name] then
print("Removing addon "..add.short_name..": not allowed by savefile")
table.remove(adds, i)
end
else
-- Forbidden by version
if not add.natural_compatible then
table.remove(adds, i)
if config.settings.addons[add.for_module] and config.settings.addons[add.for_module][add.short_name] ~= nil then
-- Forbidden by config
if config.settings.addons[add.for_module][add.short_name] == false then
print("Removing addon "..add.short_name..": not allowed by config")
table.remove(adds, i)
end
else
-- Forbidden by version
if not add.natural_compatible then
table.remove(adds, i)
end
end
end
end
......@@ -532,8 +541,10 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- Load the savefile if it exists, or create a new one if not (or if requested)
local save = engine.Savefile.new(name)
local save_desc
if save:check() and not new_game then
savesize = savesize + save:loadGameSize()
save_desc = self:loadSavefileDescription(save.save_dir)
end
save:close()
......@@ -577,7 +588,7 @@ function _M:instanciate(mod, name, new_game, no_reboot)
end
end
self:loadAddons(mod)
self:loadAddons(mod, save_desc and save_desc.addons)
-- Check addons
if hash_valid then
......
......@@ -225,6 +225,9 @@ function _M:saveGame(game, no_dialog)
local f = fs.open(self.save_dir.."desc.lua", "w")
f:write(("module = %q\n"):format(game.__mod_info.short_name))
f:write(("module_version = {%d,%d,%d}\n"):format(game.__mod_info.version[1], game.__mod_info.version[2], game.__mod_info.version[3]))
local addons = {}
for add, _ in pairs(game.__mod_info.addons) do addons[#addons+1] = "'"..add.."'" end
f:write(("addons = {%s}\n"):format(table.concat(addons, ", ")))
f:write(("name = %q\n"):format(desc.name))
f:write(("short_name = %q\n"):format(self.short_name))
f:write(("timestamp = %d\n"):format(os.time()))
......
......@@ -188,6 +188,12 @@ function table.reverse(t)
return tt
end
function table.reversekey(t, k)
local tt = {}
for i, e in ipairs(t) do tt[e[k]] = i end
return tt
end
function table.listify(t)
local tt = {}
for k, e in pairs(t) do tt[#tt+1] = {k, e} end
......
......@@ -49,13 +49,20 @@ function _M:init()
local mod_string = ("%s-%d.%d.%d"):format(m.short_name, save.module_version and save.module_version[1] or -1, save.module_version and save.module_version[2] or -1, save.module_version and save.module_version[3] or -1)
local mod = list[mod_string]
if mod and save.loadable then
local laddons = table.reversekey(Module:listAddons(mod, true), "short_name")
local addons = {}
save.usable = true
for i, add in ipairs(save.addons or {}) do
if laddons[add] then addons[#addons+1] = "#LIGHT_GREEN#"..add.."#WHITE#"
else addons[#addons+1] = "#LIGHT_RED#"..add.."#WHITE#" save.usable = false
end
end
save.mod = mod
save.base_name = save.short_name
save.zone = Textzone.new{
width=self.c_desc.w,
height=self.c_desc.h,
text=("#{bold}##GOLD#%s: %s#WHITE##{normal}#\nGame version: %d.%d.%d\n\n%s"):format(mod.long_name, save.name, mod.version[1], mod.version[2], mod.version[3], save.description)
text=("#{bold}##GOLD#%s: %s#WHITE##{normal}#\nGame version: %d.%d.%d\nRequires addons: %s\n\n%s"):format(mod.long_name, save.name, mod.version[1], mod.version[2], mod.version[3], save.addons and table.concat(addons, ", ") or "none", save.description)
}
if save.screenshot then
local w, h = save.screenshot:getSize()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment