marker util
This commit is contained in:
parent
48bdc34fcb
commit
5de9594201
1
init.lua
1
init.lua
@ -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
38
markers.lua
Normal 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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user