marker util

This commit is contained in:
BuckarooBanzay 2024-04-28 20:13:19 +02:00
parent 48bdc34fcb
commit 5de9594201
3 changed files with 41 additions and 1 deletions

View File

@ -13,6 +13,7 @@ dofile(MP .. "/entity.lua")
dofile(MP .. "/preview.lua")
dofile(MP .. "/api.lua")
dofile(MP .. "/common.lua")
dofile(MP .. "/markers.lua")
dofile(MP .. "/placements/mapblock_lib.lua")
dofile(MP .. "/placements/dummy.lua")
dofile(MP .. "/conditions.lua")

38
markers.lua Normal file
View File

@ -0,0 +1,38 @@
-- type -> texture-name
local textures = {
arrow = "building_lib_arrow.png"
}
-- name -> vector
-- assuming texture points upwards originally
local rotations = {
["z-"] = { x=math.pi/2, y=0, z=0 },
["z+"] = { x=math.pi/2, y=0, z=math.pi },
["x+"] = { x=math.pi/2, y=0, z=math.pi/2 },
["x-"] = { x=math.pi/2, y=0, z=-math.pi/2 }
}
function building_lib.create_marker(type, opts)
-- apply sane defaults
if not textures[type] then
type = "arrow"
end
opts = opts or {}
opts.pos = opts.pos or {}
opts.pos.x = opts.pos.x or 0
opts.pos.y = opts.pos.y or 0
opts.pos.z = opts.pos.z or 0
opts.size = opts.size or 10
if not rotations[opts.rotation] then
opts.rotation = "z-"
end
return {
texture = textures[type],
position = opts.pos,
rotation = rotations[opts.rotation],
size = {x=opts.size, y=opts.size}
}
end

View File

@ -48,7 +48,8 @@ function building_lib.show_preview(playername, texture, color, building_def, map
local unrotated_size = building_lib.get_building_size(building_def, 360 - rotation)
for _, marker in ipairs(building_def.markers) do
local rotated_position = mapblock_lib.rotate_pos(marker.position, unrotated_size, rotation)
local center_rel_pos = vector.add(marker.position, 0.5)
local rotated_position = mapblock_lib.rotate_pos(center_rel_pos, unrotated_size, rotation)
local node_pos = vector.multiply(vector.add(mapblock_pos1, rotated_position), 16)
node_pos = vector.subtract(node_pos, 0.5)
local z_rotation = marker.rotation.z