Dynamically read the number of available levels
parent
28a6e96b7b
commit
b0bc4f350a
|
@ -0,0 +1,5 @@
|
|||
lzr_levels_level_1.mts,Level 1
|
||||
lzr_levels_level_2.mts,Level 2
|
||||
lzr_levels_level_3.mts,Level 3
|
||||
lzr_levels_level_4.mts,Level 4
|
||||
lzr_levels_level_5.mts,Level 5
|
|
|
@ -6,24 +6,38 @@ local ROOM_NODE = "lzr_core:wood"
|
|||
local WINDOW_NODE = "lzr_decor:woodframed_glass"
|
||||
local WINDOW_HEIGHT = 3
|
||||
local WINDOW_DIST = 3
|
||||
lzr_levels.LAST_LEVEL = 10
|
||||
|
||||
local current_level = nil
|
||||
|
||||
local level_data = {}
|
||||
lzr_levels.LAST_LEVEL = 0
|
||||
|
||||
-- Mod storage for game progress
|
||||
local mod_storage = minetest.get_mod_storage()
|
||||
|
||||
-- Read the level schematics to find out some metadata about them
|
||||
-- and count the number of levels
|
||||
local analyze_levels = function()
|
||||
local level_list_path = minetest.get_modpath("lzr_levels").."/data/level_data.csv"
|
||||
local level_list_file = io.open(level_list_path, "r")
|
||||
assert(level_list_file, "Could not load level_data.csv")
|
||||
|
||||
for line in level_list_file:lines() do
|
||||
local matches = string.split(line, ",")
|
||||
assert(matches ~= nil, "Malformed level_data.csv")
|
||||
local filename = matches[1]
|
||||
table.insert(level_data, {filename=filename})
|
||||
end
|
||||
lzr_levels.LAST_LEVEL = #level_data
|
||||
|
||||
-- Mark levels that contain at least 1 rotatable block
|
||||
for l=1, lzr_levels.LAST_LEVEL do
|
||||
local schem = minetest.read_schematic(minetest.get_modpath("lzr_levels").."/schematics/lzr_levels_level_"..l..".mts", {write_yslice_prob="none"})
|
||||
level_data[l] = {
|
||||
contains_rotatable_block = false,
|
||||
size = schem.size,
|
||||
}
|
||||
for l=1, #level_data do
|
||||
local filename = level_data[l].filename
|
||||
local filepath = minetest.get_modpath("lzr_levels").."/schematics/"..filename
|
||||
local schem = minetest.read_schematic(filepath, {write_yslice_prob="none"})
|
||||
assert(schem, "Could not load level file: "..filename)
|
||||
level_data[l].contains_rotatable_block = false
|
||||
level_data[l].size = schem.size
|
||||
for d=1, #schem.data do
|
||||
local nodename = schem.data[d].name
|
||||
local is_rotatable = minetest.get_item_group(nodename, "rotatable") == 1
|
||||
|
@ -93,7 +107,8 @@ function lzr_levels.prepare_and_build_level(level)
|
|||
end
|
||||
|
||||
function lzr_levels.build_level(level)
|
||||
local schem = minetest.place_schematic(lzr_globals.LEVEL_POS, minetest.get_modpath("lzr_levels").."/schematics/lzr_levels_level_"..level..".mts", "0", {}, true, "")
|
||||
local filepath = minetest.get_modpath("lzr_levels").."/schematics/"..level_data[level].filename
|
||||
local schem = minetest.place_schematic(lzr_globals.LEVEL_POS, filepath, "0", {}, true, "")
|
||||
if schem then
|
||||
-- Propagate lasers and check for insta-win
|
||||
lzr_laser.full_laser_update(lzr_globals.PLAYFIELD_START, lzr_globals.PLAYFIELD_END)
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue