Solutions tests now works for level packs, too

This commit is contained in:
Wuzzy 2024-12-14 19:16:40 +01:00
parent 4a2c3852da
commit 92b78d2fb8
2 changed files with 39 additions and 28 deletions

View File

@ -139,7 +139,7 @@ it only records interactions with nodes but not player movement.
This feature is EXPERIMENTAL and has some rough edges, so This feature is EXPERIMENTAL and has some rough edges, so
use with care! The main use case for this feature is to record use with care! The main use case for this feature is to record
solutions in the core levels. solutions in level packs, most importantly the core levels.
This feature is useful to test and verify if the levels are still solvable This feature is useful to test and verify if the levels are still solvable
in a later update in case the behavior of a laser block was accidentally in a later update in case the behavior of a laser block was accidentally
@ -158,9 +158,9 @@ Commands:
a file is saved into the world directory on success. a file is saved into the world directory on success.
WARNING: Existing files will be silently overwritten! WARNING: Existing files will be silently overwritten!
* `/replay_solution`: Replay the solution for the current level. This * `/replay_solution`: Replay the solution for the current level. This
only works for core levels and only when you're at the beginning only works for level pack levels and only when you're at the beginning
of a level. of a level.
* `/test_core_solutions`: Mass-test ALL core levels in sequential * `/test_pack_solutions`: Mass-test ALL levels of a level pack in sequence
The solution test will halt automatically when any inconsistency was The solution test will halt automatically when any inconsistency was
detected. You can always abort the solution test or a recording by detected. You can always abort the solution test or a recording by

View File

@ -8,10 +8,12 @@ local state = "idle"
-- and trigger a file save -- and trigger a file save
local autostop = false local autostop = false
-- true if running a full solution test of the core levels -- true if running a full solution test of a level pack
local full_test = false local full_test = false
-- level number of currently tested core level -- level number of currently tested level pack level
local full_test_level = 0 local full_test_level = 0
-- level pack name for the full solution test
local full_test_pack = nil
local current_replay_time = 0 local current_replay_time = 0
local current_action local current_action
@ -58,11 +60,11 @@ action: {
]] ]]
local test_next_core_solution_callback = function() local test_next_pack_solution_callback = function()
local level_id = full_test_level local level_id = full_test_level
minetest.log("action", "[lzr_solutions] Testing solution for core level "..level_id) minetest.log("action", "[lzr_solutions] Testing solution for level "..level_id.." of level pack '"..full_test_pack.."'")
local level_data = lzr_levels.get_level_pack("__core") local level_data = lzr_levels.get_level_pack(full_test_pack)
if not level_data.solutions_path then if not level_data.solutions_path then
-- No solutions path. Nothing to test! -- No solutions path. Nothing to test!
minetest.log("error", "[lzr_solutions] No solutions path") minetest.log("error", "[lzr_solutions] No solutions path")
@ -72,13 +74,13 @@ local test_next_core_solution_callback = function()
local level = level_data[level_id] local level = level_data[level_id]
if not level then if not level then
-- Level does not exist -- Level does not exist
minetest.log("error", "[lzr_solutions] Core level "..tostring(level_id).." does not exist") minetest.log("error", "[lzr_solutions] Level "..tostring(level_id).." does not exist in level pack '"..full_test_pack.."'")
return false return false
end end
if not level.filename_solution then if not level.filename_solution then
-- No solution in level. Skip test. -- No solution in level. Skip test.
minetest.log("error", "[lzr_solutions] Core level "..tostring(level_id).." doesn't have solution") minetest.log("error", "[lzr_solutions] Level "..tostring(level_id).." of level pack '"..full_test_pack.."' doesn't have a solution file")
return false return false
end end
@ -89,25 +91,25 @@ local test_next_core_solution_callback = function()
local solution = lzr_solutions.csv_to_solution(csv) local solution = lzr_solutions.csv_to_solution(csv)
if solution then if solution then
lzr_solutions.replay_solution(solution) lzr_solutions.replay_solution(solution)
minetest.log("action", "[lzr_solutions] Playing solution for core level "..level_id) minetest.log("action", "[lzr_solutions] Playing solution for level "..level_id.." of level pack '"..full_test_pack.."'")
return true return true
else else
minetest.log("error", "[lzr_solutions] Error in solution CSV file for core level "..level_id) minetest.log("error", "[lzr_solutions] Error in solution CSV file for level "..level_id.." of level pack '"..full_test_pack.."'")
return false return false
end end
else else
minetest.log("error", "[lzr_solutions] Error while loading solution CSV file for core level "..level_id) minetest.log("error", "[lzr_solutions] Error while loading solution CSV file for level "..level_id.." of level pack '"..full_test_pack.."'")
return false return false
end end
end end
local test_next_core_solution = function() local test_next_pack_solution = function(pack)
local level_data = lzr_levels.get_level_pack("__core") local level_data = lzr_levels.get_level_pack(pack)
full_test_level = full_test_level + 1 full_test_level = full_test_level + 1
if full_test_level > #level_data then if full_test_level > #level_data then
return false return false
end end
minetest.log("info", "[lzr_solutions] Loading core level "..full_test_level.." ...") minetest.log("info", "[lzr_solutions] Loading level "..full_test_level.." of level pack '"..pack.."' ...")
lzr_gamestate.set_state(lzr_gamestate.LEVEL_TEST) lzr_gamestate.set_state(lzr_gamestate.LEVEL_TEST)
lzr_levels.start_level(full_test_level, level_data) lzr_levels.start_level(full_test_level, level_data)
return true return true
@ -115,14 +117,15 @@ end
lzr_levels.register_on_level_start(function() lzr_levels.register_on_level_start(function()
minetest.log("verbose", "[lzr_solutions] on_level_start event") minetest.log("verbose", "[lzr_solutions] on_level_start event")
if full_test then if full_test then
test_next_core_solution_callback() test_next_pack_solution_callback()
end end
end) end)
lzr_solutions.test_core_solutions = function() lzr_solutions.test_pack_solutions = function(pack)
full_test = true full_test = true
full_test_level = 0 full_test_level = 0
local ok = test_next_core_solution() full_test_pack = pack
local ok = test_next_pack_solution(pack)
if not ok then if not ok then
full_test = false full_test = false
end end
@ -444,11 +447,11 @@ minetest.register_globalstep(function(dtime)
if full_test then if full_test then
if not lzr_gamestate.is_loading() then if not lzr_gamestate.is_loading() then
if lzr_laser.check_level_won() then if lzr_laser.check_level_won() then
minetest.log("action", "[lzr_solutions] Solution for core level "..full_test_level.." completed!") minetest.log("action", "[lzr_solutions] Solution for level "..full_test_level.." of level pack '"..full_test_pack.."' completed!")
local ok = test_next_core_solution() local ok = test_next_pack_solution(full_test_pack)
if not ok then if not ok then
minetest.log("action", "[lzr_solutions] Core level solution test successfully completed!") minetest.log("action", "[lzr_solutions] Level pack solution test for '"..full_test_pack.."' successfully completed!")
passed_message(S("Core level solution test PASSED!")) passed_message(S("Level pack solution test PASSED!"))
full_test = false full_test = false
current_solution = nil current_solution = nil
@ -593,18 +596,26 @@ if minetest.settings:get_bool("lzr_debug", false) == true then
end, end,
}) })
minetest.register_chatcommand("test_core_solutions", { minetest.register_chatcommand("test_pack_solutions", {
privs = { debug = true, server = true }, privs = { debug = true, server = true },
params = "", params = S("[<level pack>]"),
description = S("Test the solution of all core levels"), description = S("Test the solutions of all levels of a level pack"),
func = function(name, param) func = function(name, param)
if state == "playing" then if state == "playing" then
return false, S("Already replaying a solution!") return false, S("Already replaying a solution!")
elseif state == "recording" then elseif state == "recording" then
return false, S("Already recording!") return false, S("Already recording!")
end end
lzr_solutions.test_core_solutions() local pack = param
if pack == "" then
pack = "__core"
end
if lzr_levels.get_level_pack(pack) then
lzr_solutions.test_pack_solutions(pack)
return true return true
else
return false, S("This level pack doesnt exist!")
end
end, end,
}) })