Solutions tests now works for level packs, too
This commit is contained in:
parent
4a2c3852da
commit
92b78d2fb8
@ -139,7 +139,7 @@ it only records interactions with nodes but not player movement.
|
||||
|
||||
This feature is EXPERIMENTAL and has some rough edges, so
|
||||
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
|
||||
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.
|
||||
WARNING: Existing files will be silently overwritten!
|
||||
* `/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.
|
||||
* `/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
|
||||
detected. You can always abort the solution test or a recording by
|
||||
|
@ -8,10 +8,12 @@ local state = "idle"
|
||||
-- and trigger a file save
|
||||
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
|
||||
-- level number of currently tested core level
|
||||
-- level number of currently tested level pack level
|
||||
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_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
|
||||
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
|
||||
-- No solutions path. Nothing to test!
|
||||
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]
|
||||
if not level then
|
||||
-- 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
|
||||
end
|
||||
|
||||
if not level.filename_solution then
|
||||
-- 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
|
||||
end
|
||||
|
||||
@ -89,25 +91,25 @@ local test_next_core_solution_callback = function()
|
||||
local solution = lzr_solutions.csv_to_solution(csv)
|
||||
if solution then
|
||||
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
|
||||
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
|
||||
end
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
local test_next_core_solution = function()
|
||||
local level_data = lzr_levels.get_level_pack("__core")
|
||||
local test_next_pack_solution = function(pack)
|
||||
local level_data = lzr_levels.get_level_pack(pack)
|
||||
full_test_level = full_test_level + 1
|
||||
if full_test_level > #level_data then
|
||||
return false
|
||||
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_levels.start_level(full_test_level, level_data)
|
||||
return true
|
||||
@ -115,14 +117,15 @@ end
|
||||
lzr_levels.register_on_level_start(function()
|
||||
minetest.log("verbose", "[lzr_solutions] on_level_start event")
|
||||
if full_test then
|
||||
test_next_core_solution_callback()
|
||||
test_next_pack_solution_callback()
|
||||
end
|
||||
end)
|
||||
|
||||
lzr_solutions.test_core_solutions = function()
|
||||
lzr_solutions.test_pack_solutions = function(pack)
|
||||
full_test = true
|
||||
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
|
||||
full_test = false
|
||||
end
|
||||
@ -444,11 +447,11 @@ minetest.register_globalstep(function(dtime)
|
||||
if full_test then
|
||||
if not lzr_gamestate.is_loading() then
|
||||
if lzr_laser.check_level_won() then
|
||||
minetest.log("action", "[lzr_solutions] Solution for core level "..full_test_level.." completed!")
|
||||
local ok = test_next_core_solution()
|
||||
minetest.log("action", "[lzr_solutions] Solution for level "..full_test_level.." of level pack '"..full_test_pack.."' completed!")
|
||||
local ok = test_next_pack_solution(full_test_pack)
|
||||
if not ok then
|
||||
minetest.log("action", "[lzr_solutions] Core level solution test successfully completed!")
|
||||
passed_message(S("Core level solution test PASSED!"))
|
||||
minetest.log("action", "[lzr_solutions] Level pack solution test for '"..full_test_pack.."' successfully completed!")
|
||||
passed_message(S("Level pack solution test PASSED!"))
|
||||
|
||||
full_test = false
|
||||
current_solution = nil
|
||||
@ -593,18 +596,26 @@ if minetest.settings:get_bool("lzr_debug", false) == true then
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("test_core_solutions", {
|
||||
minetest.register_chatcommand("test_pack_solutions", {
|
||||
privs = { debug = true, server = true },
|
||||
params = "",
|
||||
description = S("Test the solution of all core levels"),
|
||||
params = S("[<level pack>]"),
|
||||
description = S("Test the solutions of all levels of a level pack"),
|
||||
func = function(name, param)
|
||||
if state == "playing" then
|
||||
return false, S("Already replaying a solution!")
|
||||
elseif state == "recording" then
|
||||
return false, S("Already recording!")
|
||||
end
|
||||
lzr_solutions.test_core_solutions()
|
||||
return true
|
||||
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
|
||||
else
|
||||
return false, S("This level pack doesn’t exist!")
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user