build-over tests
This commit is contained in:
parent
5b820547c4
commit
6a036e3ec2
55
build_over.spec.lua
Normal file
55
build_over.spec.lua
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
building_lib.register_building("building_lib:dummy_base", {
|
||||
placement = "dummy",
|
||||
size = { x=3, y=1, z=1 }
|
||||
})
|
||||
|
||||
-- building can only be placed over "dummy"
|
||||
building_lib.register_building("building_lib:dummy_extension", {
|
||||
placement = "dummy",
|
||||
size = { x=3, y=1, z=1 },
|
||||
conditions = {
|
||||
{
|
||||
["*"] = { name = "building_lib:dummy_base" }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
mtt.register("build-over", function(callback)
|
||||
-- clear store
|
||||
building_lib.store:clear()
|
||||
|
||||
local mapblock_pos = {x=0, y=0, z=0}
|
||||
local rotation = 0
|
||||
local playername = "singleplayer"
|
||||
|
||||
-- build
|
||||
local callback_called = false
|
||||
local success, err = building_lib.build(mapblock_pos, playername, "building_lib:dummy_base", rotation,
|
||||
function() callback_called = true end
|
||||
)
|
||||
assert(not err)
|
||||
assert(success)
|
||||
assert(callback_called)
|
||||
|
||||
-- build over (wrong angle)
|
||||
success, err = building_lib.build(mapblock_pos, playername, "building_lib:dummy_extension", 90)
|
||||
assert(err)
|
||||
assert(not success)
|
||||
|
||||
-- build over (wrong angle 2)
|
||||
success, err = building_lib.build(mapblock_pos, playername, "building_lib:dummy_extension", 270)
|
||||
assert(err)
|
||||
assert(not success)
|
||||
|
||||
-- build over (180° rotated)
|
||||
callback_called = false
|
||||
success, err = building_lib.build(mapblock_pos, playername, "building_lib:dummy_extension", 180,
|
||||
function() callback_called = true end
|
||||
)
|
||||
assert(not err)
|
||||
assert(success)
|
||||
assert(callback_called)
|
||||
|
||||
callback()
|
||||
end)
|
@ -15,7 +15,7 @@ function building_lib.check_condition_table(map, mapblock_pos)
|
||||
local success, msg = check_condition(key, value, mapblock_pos)
|
||||
if not success then
|
||||
-- failure and in AND mode, return immediately
|
||||
return false, msg or "condition failed: '" .. key .. "'"
|
||||
return false, msg or "condition failed: '" .. key .. "' pos: " .. minetest.pos_to_string(mapblock_pos)
|
||||
end
|
||||
end
|
||||
return true
|
||||
@ -50,17 +50,19 @@ end
|
||||
|
||||
-- go through all condition groups and return true if any of them matches
|
||||
function building_lib.check_condition_groups(mapblock_pos1, mapblock_pos2, condition_groups)
|
||||
local success, err
|
||||
for _, condition_group in ipairs(condition_groups or default_condition_groups) do
|
||||
local success = building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condition_group)
|
||||
success, err = building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condition_group)
|
||||
if success then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false, "no matching condition found"
|
||||
return false, "no matching condition found" .. (err and ", last error: " .. err or "")
|
||||
end
|
||||
|
||||
function building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condition_group)
|
||||
local group_match = true
|
||||
local success, err
|
||||
|
||||
for selector, conditions in pairs(condition_group) do
|
||||
local it
|
||||
@ -95,7 +97,7 @@ function building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condit
|
||||
break
|
||||
end
|
||||
|
||||
local success = building_lib.check_condition_table(conditions, mapblock_pos)
|
||||
success, err = building_lib.check_condition_table(conditions, mapblock_pos)
|
||||
if not success then
|
||||
group_match = false
|
||||
break
|
||||
@ -110,6 +112,8 @@ function building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condit
|
||||
if group_match then
|
||||
return true
|
||||
end
|
||||
|
||||
return false, err
|
||||
end
|
||||
|
||||
-- checks if a building with specified group is placed there already
|
||||
|
1
init.lua
1
init.lua
@ -32,4 +32,5 @@ if minetest.get_modpath("mtt") and mtt.enabled then
|
||||
dofile(MP .. "/events.spec.lua")
|
||||
dofile(MP .. "/conditions.spec.lua")
|
||||
dofile(MP .. "/build.spec.lua")
|
||||
dofile(MP .. "/build_over.spec.lua")
|
||||
end
|
||||
|
5
mtt.lua
5
mtt.lua
@ -1,5 +1,8 @@
|
||||
building_lib.register_placement("dummy", {
|
||||
check = function() return true end,
|
||||
get_size = function() return {x=1,y=1,z=1} end,
|
||||
get_size = function(_, _, building_def, rotation)
|
||||
local size = building_def.size or {x=1,y=1,z=1}
|
||||
return mapblock_lib.rotate_size(size, rotation)
|
||||
end,
|
||||
place = function(_, _, _, _, callback) callback() end
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user