Remember progress of non-core level packs

This commit is contained in:
Wuzzy 2024-12-14 04:14:42 +01:00
parent fc4dc029c8
commit b48ec05250

View File

@ -1038,8 +1038,12 @@ function lzr_levels.clear_level_progress(level_data)
return
end
level_packs_completed[level_data.name] = nil
local levels = minetest.deserialize(mod_storage:get_string("lzr_levels:levels"), true)
levels[level_data.name] = {}
mod_storage:set_string("lzr_levels:levels", minetest.serialize(levels))
if level_data.name == "__core" then
mod_storage:set_string("lzr_levels:levels", "")
lzr_menu.remove_painting("perfect_plunderer")
-- Also needs to notify mods about changed
@ -1056,13 +1060,9 @@ function lzr_levels.mark_level_as_complete(level, level_data)
if level_data.is_singleton then
return
end
-- Only core levels are supported
if level_data.name ~= "__core" then
return
end
local levels = minetest.deserialize(mod_storage:get_string("lzr_levels:levels"), true)
if not levels then
levels = { __core = {} }
levels = { [level_data.name] = {} }
end
if not level_data[level] then
return false
@ -1070,7 +1070,7 @@ function lzr_levels.mark_level_as_complete(level, level_data)
local levelname = level_data[level].filename
levelname = string.sub(levelname, 1, -5) -- remove .mts suffix
levels.__core[levelname] = true
levels[level_data.name][levelname] = true
mod_storage:set_string("lzr_levels:levels", minetest.serialize(levels))
-- Notify mods that the treasure count has changed
@ -1081,7 +1081,7 @@ function lzr_levels.mark_level_as_complete(level, level_data)
-- Place 'Perfect Plunderer' painting in ship
-- as some kind of "mini-achievement"
if lzr_levels.are_all_levels_completed(level_data) then
if level_data.name == "__core" and lzr_levels.are_all_levels_completed(level_data) then
lzr_menu.place_painting("perfect_plunderer")
end