Hook in the new marker wall system

it works!
now for the other walls.
This commit is contained in:
Starbeamrainbowlabs 2023-06-29 00:39:55 +01:00
parent 1b0001d88e
commit c622fb554f
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 103 additions and 7 deletions

@ -11,4 +11,5 @@ local wea_c = worldeditadditions_core
return {
pos_marker = dofile(wea_c.modpath.."/core/entities/pos_marker.lua"),
pos_marker_wall = dofile(wea_c.modpath.."/core/entities/pos_marker_wall.lua")
}

@ -38,16 +38,19 @@ local WEAPositionMarkerWall = {
end
}
minetest.register_entity(":worldeditadditions:marker_wall", WEAPositionMarker)
minetest.register_entity(
":worldeditadditions:marker_wall",
WEAPositionMarkerWall
)
--- Updates the properties of a single wall to match it's side and size
local function single_setup(entity, size, side)
local new_props = {
visual_size = {
x = math.min(10, size.x),
y = math.min(10, size.y),
z = math.min(10, size.z)
x = math.min(10, math.abs(size.x)+1),
y = math.min(10, math.abs(size.y)+1),
z = math.min(10, math.abs(size.z)+1)
}
}
@ -80,6 +83,8 @@ local function single_setup(entity, size, side)
cpos2.x, cpos2.y, cpos2.z
}
print("DEBUG:marker_wall setup_single new_props", wea_c.inspect(new_props))
entity:set_properties(new_props)
end
@ -90,8 +95,19 @@ end
-- @param side string The side that this wall is on. Valid values: x, -x, y, -y, z, -z.
-- @returns Entity<WEAPositionMarkerWall>
local function create_single(player_name, pos1, pos2, side)
local pos_centre = pos2 - pos1
local entity = minetest.add_entity(pos_centre, name)
print("DEBUG:marker_wall create_single --> START player_name", player_name, "pos1", pos1, "pos2", pos2, "side", side)
local offset = Vector3.new()
if side == "x" then offset.x = 0.5
elseif side == "-x" then offset.x = -0.5
elseif side == "y" then offset.y = 0.5
elseif side == "-y" then offset.y = -0.5
elseif side == "z" then offset.z = 0.5
elseif side == "-z" then offset.z = -0.5 end
local pos_centre = ((pos2 - pos1) / 2) + pos1 + offset
local entity = minetest.add_entity(pos_centre, "worldeditadditions:marker_wall")
print("DEBUG:marker_wall create_single --> spawned at", pos_centre)
entity:get_luaentity().player_name = player_name
@ -107,6 +123,7 @@ end
-- @param pos2 Vector3 pos2 of the defined region.
-- @returns table<entitylist> A list of all created entities.
local function create_wall(player_name, pos1, pos2)
print("DEBUG:marker_wall create_wall --> START player_name", player_name, "pos1", pos1, "pos2", pos2)
local pos1s, pos2s = Vector3.sort(pos1, pos2)
local entities = {}
@ -176,6 +193,7 @@ end
--- Deletes all entities in the given entity list
-- @param entitylist table<entity> A list of wall entities that make up the wall to delete.
local function delete(entitylist)
print("DEBUG:marker_wall delete --> START with "..#entitylist.." entities")
local player_name
for _, entity in ipairs(entitylist) do
if not entity.get_luaentity or not entity:get_luaentity() then return end -- Ensure the entity is still valid
@ -183,6 +201,8 @@ local function delete(entitylist)
if not player_name then
player_name = entity:get_luaentity().player_name
end
entity:remove()
end
anchor:emit("delete", {
@ -194,3 +214,5 @@ anchor = EventEmitter.new({
create = create_wall,
delete = delete
})
return anchor

@ -0,0 +1,72 @@
local weac = worldeditadditions_core
local wall_entity_lists = {}
--- Ensures that a table exists for the given player.
-- @param player_name string The name of the player to check.
local function ensure_player(player_name)
if player_name == nil then
minetest.log("error", "[wea core:pos_manage:ensure_player] player_name is nil")
end
if not wall_entity_lists[player_name] then
wall_entity_lists[player_name] = {}
end
end
--- Deletes the currently displayed marker wall.
-- @param event EventArgs<wea_c.pos.set> The event args for the set, push, pop, or clear events on wea_c.pos.
-- @returns void
local function do_delete(event)
if not wall_entity_lists[event.player_name] then return end
print("DEBUG:marker_wall_manage do_delete --> deleting pre-existing wall with "..tostring(#wall_entity_lists[event.player_name]).." entities")
if #wall_entity_lists[event.player_name] > 0 then
weac.entities.pos_marker_wall.delete(wall_entity_lists[event.player_name])
end
wall_entity_lists[event.player_name] = nil
end
--- Updates the marker wall as appropriate.
-- @param event EventArgs<wea_c.pos.set> The event args for the set, push, or pop events on wea_c.pos.
-- @returns void
local function do_update(event)
print("DEBUG:marker_wall_manage do_update --> START")
-- We don't dynamically update, as that'd be too much work.
-- Instead, we just delete & recreate each time.
if wall_entity_lists[event.player_name] then
print("DEBUG:marker_wall_manage do_update --> do_delete")
do_delete(event)
end
local pos1 = weac.pos.get1(event.player_name)
local pos2 = weac.pos.get2(event.player_name)
print("DEBUG:marker_wall_manage do_update --> pos1", pos1, "pos2", pos2)
if not pos1 or not pos2 then return end
wall_entity_lists[event.player_name] = weac.entities.pos_marker_wall.create(
event.player_name,
pos1,
pos2
)
print("DEBUG:marker_wall_manage do_update --> entitylist", weac.inspect(wall_entity_lists[event.player_name]))
end
local function needs_update(event)
if event.i > 2 then
return false
end
return true
end
local function handle_event(event)
if needs_update(event) then do_update(event) end
end
weac.pos:addEventListener("set", handle_event)
weac.pos:addEventListener("pop", handle_event)
weac.pos:addEventListener("push", handle_event)
weac.pos:addEventListener("clear", do_delete)

@ -67,6 +67,7 @@ wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua")
wea_c.register_alias = dofile(modpath.."/core/register_alias.lua")
wea_c.entities = dofile(modpath.."/core/entities/init.lua") -- AFTER pos
dofile(modpath.."/core/pos_marker_manage.lua") -- AFTER pos, entities
dofile(modpath.."/core/pos_marker_wall_manage.lua") -- AFTER pos, entities
-- Initialise WorldEdit stuff if the WorldEdit mod is not present
if minetest.global_exists("worldedit") then