mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 20:41:11 +01:00
Tweak indents in signs mod
This commit is contained in:
parent
22f3d368d5
commit
7fe3cae934
1 changed files with 165 additions and 164 deletions
|
@ -5,17 +5,17 @@ local chars_file = io.open(minetest.get_modpath("signs").."/characters", "r")
|
||||||
local charmap = {}
|
local charmap = {}
|
||||||
local max_chars = 16
|
local max_chars = 16
|
||||||
if not chars_file then
|
if not chars_file then
|
||||||
minetest.log("error", "[signs] : character map file not found")
|
minetest.log("error", "[signs] : character map file not found")
|
||||||
else
|
else
|
||||||
while true do
|
while true do
|
||||||
local char = chars_file:read("*l")
|
local char = chars_file:read("*l")
|
||||||
if char == nil then
|
if char == nil then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
local img = chars_file:read("*l")
|
local img = chars_file:read("*l")
|
||||||
chars_file:read("*l")
|
chars_file:read("*l")
|
||||||
charmap[char] = img
|
charmap[char] = img
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- CONSTANTS
|
-- CONSTANTS
|
||||||
|
@ -80,85 +80,85 @@ local create_lines = function(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
local generate_line = function(s, ypos)
|
local generate_line = function(s, ypos)
|
||||||
local i = 1
|
local i = 1
|
||||||
local parsed = {}
|
local parsed = {}
|
||||||
local width = 0
|
local width = 0
|
||||||
local chars = 0
|
local chars = 0
|
||||||
while chars < max_chars and i <= #s do
|
while chars < max_chars and i <= #s do
|
||||||
local file = nil
|
local file = nil
|
||||||
if charmap[s:sub(i, i)] ~= nil then
|
if charmap[s:sub(i, i)] ~= nil then
|
||||||
file = charmap[s:sub(i, i)]
|
file = charmap[s:sub(i, i)]
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
|
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
|
||||||
file = charmap[s:sub(i, i + 1)]
|
file = charmap[s:sub(i, i + 1)]
|
||||||
i = i + 2
|
i = i + 2
|
||||||
else
|
else
|
||||||
minetest.log("warning", "[signs] Unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
|
minetest.log("warning", "[signs] Unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
width = width + CHAR_WIDTH
|
width = width + CHAR_WIDTH
|
||||||
table.insert(parsed, file)
|
table.insert(parsed, file)
|
||||||
chars = chars + 1
|
chars = chars + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
width = width - 1
|
width = width - 1
|
||||||
|
|
||||||
local texture = ""
|
local texture = ""
|
||||||
local xpos = math.floor((SIGN_WITH - 2 * SIGN_PADDING - width) / 2 + SIGN_PADDING)
|
local xpos = math.floor((SIGN_WITH - 2 * SIGN_PADDING - width) / 2 + SIGN_PADDING)
|
||||||
for i = 1, #parsed do
|
for i = 1, #parsed do
|
||||||
texture = texture..":"..xpos..","..ypos.."="..parsed[i]..".png"
|
texture = texture..":"..xpos..","..ypos.."="..parsed[i]..".png"
|
||||||
xpos = xpos + CHAR_WIDTH + 1
|
xpos = xpos + CHAR_WIDTH + 1
|
||||||
end
|
end
|
||||||
return texture
|
return texture
|
||||||
end
|
end
|
||||||
|
|
||||||
local generate_texture = function(lines)
|
local generate_texture = function(lines)
|
||||||
local texture = "[combine:"..SIGN_WITH.."x"..SIGN_WITH
|
local texture = "[combine:"..SIGN_WITH.."x"..SIGN_WITH
|
||||||
local ypos = 12
|
local ypos = 12
|
||||||
for i = 1, #lines do
|
for i = 1, #lines do
|
||||||
texture = texture..generate_line(lines[i], ypos)
|
texture = texture..generate_line(lines[i], ypos)
|
||||||
ypos = ypos + LINE_HEIGHT
|
ypos = ypos + LINE_HEIGHT
|
||||||
end
|
end
|
||||||
return texture
|
return texture
|
||||||
end
|
end
|
||||||
|
|
||||||
local n = 7/16 - 1/128
|
local n = 7/16 - 1/128
|
||||||
|
|
||||||
local signs = {
|
local signs = {
|
||||||
{delta = {x = 0, y = 0, z = n}, yaw = 0},
|
{delta = {x = 0, y = 0, z = n}, yaw = 0},
|
||||||
{delta = {x = n, y = 0, z = 0}, yaw = math.pi / -2},
|
{delta = {x = n, y = 0, z = 0}, yaw = math.pi / -2},
|
||||||
{delta = {x = 0, y = 0, z = -n}, yaw = math.pi},
|
{delta = {x = 0, y = 0, z = -n}, yaw = math.pi},
|
||||||
{delta = {x = -n, y = 0, z = 0}, yaw = math.pi / 2},
|
{delta = {x = -n, y = 0, z = 0}, yaw = math.pi / 2},
|
||||||
}
|
}
|
||||||
|
|
||||||
local m = 1/16 + 1/128
|
local m = 1/16 + 1/128
|
||||||
|
|
||||||
local signs_yard = {
|
local signs_yard = {
|
||||||
{delta = {x = 0, y = 0, z = -m}, yaw = 0},
|
{delta = {x = 0, y = 0, z = -m}, yaw = 0},
|
||||||
{delta = {x = -m, y = 0, z = 0}, yaw = math.pi / -2},
|
{delta = {x = -m, y = 0, z = 0}, yaw = math.pi / -2},
|
||||||
{delta = {x = 0, y = 0, z = m}, yaw = math.pi},
|
{delta = {x = 0, y = 0, z = m}, yaw = math.pi},
|
||||||
{delta = {x = m, y = 0, z = 0}, yaw = math.pi / 2},
|
{delta = {x = m, y = 0, z = 0}, yaw = math.pi / 2},
|
||||||
}
|
}
|
||||||
|
|
||||||
local sign_groups = {handy=1,axey=1, flammable=1, deco_block=1, material_wood=1}
|
local sign_groups = {handy=1,axey=1, flammable=1, deco_block=1, material_wood=1}
|
||||||
|
|
||||||
local construct_sign = function(pos)
|
local construct_sign = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec", "field[text;;${text}]")
|
meta:set_string("formspec", "field[text;;${text}]")
|
||||||
end
|
end
|
||||||
|
|
||||||
local destruct_sign = function(pos)
|
local destruct_sign = function(pos)
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
if v:get_entity_name() == "signs:text" then
|
if v:get_entity_name() == "signs:text" then
|
||||||
v:remove()
|
v:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local update_sign = function(pos, fields, sender)
|
local update_sign = function(pos, fields, sender)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
local text = meta:get_string("text")
|
local text = meta:get_string("text")
|
||||||
if fields and sender:get_player_name() == owner or text == "" and fields then
|
if fields and sender:get_player_name() == owner or text == "" and fields then
|
||||||
|
@ -166,13 +166,13 @@ local update_sign = function(pos, fields, sender)
|
||||||
meta:set_string("owner", sender:get_player_name() or "")
|
meta:set_string("owner", sender:get_player_name() or "")
|
||||||
end
|
end
|
||||||
text = meta:get_string("text")
|
text = meta:get_string("text")
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
if v:get_entity_name() == "signs:text" then
|
if v:get_entity_name() == "signs:text" then
|
||||||
v:set_properties({textures={generate_texture(create_lines(text))}})
|
v:set_properties({textures={generate_texture(create_lines(text))}})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if there is no entity
|
-- if there is no entity
|
||||||
local sign_info
|
local sign_info
|
||||||
|
@ -191,91 +191,92 @@ local update_sign = function(pos, fields, sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("signs:sign_wall", {
|
minetest.register_node("signs:sign_wall", {
|
||||||
description = "Sign",
|
description = "Sign",
|
||||||
_doc_items_longdesc = "Signs can be written and come in two variants: Wall sign and sign on a sign post. Signs can be placed on the top and the sides of other blocks, but not below them.",
|
_doc_items_longdesc = "Signs can be written and come in two variants: Wall sign and sign on a sign post. Signs can be placed on the top and the sides of other blocks, but not below them.",
|
||||||
_doc_items_usagehelp = "Place the sign at the side to build a wall sign, place it on top of another block to build a sign with a sign post. Rightclick the sign to edit its text.",
|
_doc_items_usagehelp = "Place the sign at the side to build a wall sign, place it on top of another block to build a sign with a sign post. Rightclick the sign to edit its text.",
|
||||||
inventory_image = "default_sign.png",
|
inventory_image = "default_sign.png",
|
||||||
walkable = false,
|
walkable = false,
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
wield_image = "default_sign.png",
|
wield_image = "default_sign.png",
|
||||||
node_placement_prediction = "",
|
node_placement_prediction = "",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {type = "fixed", fixed = {-7/16, -1/16, 7/16, 7/16, 7/16, 0.498}},
|
node_box = {type = "fixed", fixed = {-7/16, -1/16, 7/16, 7/16, 7/16, 0.498}},
|
||||||
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
|
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
|
||||||
groups = sign_groups,
|
groups = sign_groups,
|
||||||
stack_max = 16,
|
stack_max = 16,
|
||||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||||
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
|
|
||||||
-- Use pointed node's on_rightclick function first, if present
|
-- Use pointed node's on_rightclick function first, if present
|
||||||
local node = minetest.get_node(under)
|
local node = minetest.get_node(under)
|
||||||
if placer and not placer:get_player_control().sneak then
|
if placer and not placer:get_player_control().sneak then
|
||||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local dir = {x = under.x - above.x,
|
local dir = {x = under.x - above.x,
|
||||||
y = under.y - above.y,
|
y = under.y - above.y,
|
||||||
z = under.z - above.z}
|
z = under.z - above.z}
|
||||||
|
|
||||||
-- Only build when it's legal
|
-- Only build when it's legal
|
||||||
local abovenodedef = minetest.registered_nodes[minetest.get_node(above).name]
|
local abovenodedef = minetest.registered_nodes[minetest.get_node(above).name]
|
||||||
if not abovenodedef or abovenodedef.buildable_to == false then
|
if not abovenodedef or abovenodedef.buildable_to == false then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
local wdir = minetest.dir_to_wallmounted(dir)
|
||||||
|
|
||||||
|
local placer_pos = placer:getpos()
|
||||||
|
if placer_pos then
|
||||||
|
dir = {
|
||||||
|
x = above.x - placer_pos.x,
|
||||||
|
y = above.y - placer_pos.y,
|
||||||
|
z = above.z - placer_pos.z
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local fdir = minetest.dir_to_facedir(dir)
|
||||||
|
|
||||||
|
local sign_info
|
||||||
|
if wdir == 0 then
|
||||||
|
--how would you add sign to ceiling?
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
elseif wdir == 1 then
|
||||||
|
minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
|
||||||
|
sign_info = signs_yard[fdir + 1]
|
||||||
|
else
|
||||||
|
minetest.add_node(above, {name = "signs:sign_wall", param2 = fdir})
|
||||||
|
sign_info = signs[fdir + 1]
|
||||||
|
end
|
||||||
|
|
||||||
local wdir = minetest.dir_to_wallmounted(dir)
|
local text = minetest.add_entity({
|
||||||
|
x = above.x + sign_info.delta.x,
|
||||||
local placer_pos = placer:getpos()
|
y = above.y + sign_info.delta.y,
|
||||||
if placer_pos then
|
z = above.z + sign_info.delta.z}, "signs:text")
|
||||||
dir = {
|
text:setyaw(sign_info.yaw)
|
||||||
x = above.x - placer_pos.x,
|
|
||||||
y = above.y - placer_pos.y,
|
|
||||||
z = above.z - placer_pos.z
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local fdir = minetest.dir_to_facedir(dir)
|
|
||||||
|
|
||||||
local sign_info
|
|
||||||
if wdir == 0 then
|
|
||||||
--how would you add sign to ceiling?
|
|
||||||
return itemstack
|
|
||||||
elseif wdir == 1 then
|
|
||||||
minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
|
|
||||||
sign_info = signs_yard[fdir + 1]
|
|
||||||
else
|
|
||||||
minetest.add_node(above, {name = "signs:sign_wall", param2 = fdir})
|
|
||||||
sign_info = signs[fdir + 1]
|
|
||||||
end
|
|
||||||
|
|
||||||
local text = minetest.add_entity({x = above.x + sign_info.delta.x,
|
|
||||||
y = above.y + sign_info.delta.y,
|
|
||||||
z = above.z + sign_info.delta.z}, "signs:text")
|
|
||||||
text:setyaw(sign_info.yaw)
|
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
minetest.sound_play({name="default_place_node_hard", gain=1.0}, {pos = under})
|
minetest.sound_play({name="default_place_node_hard", gain=1.0}, {pos = under})
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
construct_sign(pos)
|
construct_sign(pos)
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
destruct_sign(pos)
|
destruct_sign(pos)
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
update_sign(pos, fields, sender)
|
update_sign(pos, fields, sender)
|
||||||
end,
|
end,
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
update_sign(pos)
|
update_sign(pos)
|
||||||
end,
|
end,
|
||||||
|
@ -284,33 +285,33 @@ minetest.register_node("signs:sign_wall", {
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("signs:sign_yard", {
|
minetest.register_node("signs:sign_yard", {
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
node_box = {type = "fixed", fixed = {
|
node_box = {type = "fixed", fixed = {
|
||||||
{-7/16, -1/16, -1/16, 7/16, 7/16, 0},
|
{-7/16, -1/16, -1/16, 7/16, 7/16, 0},
|
||||||
{-1/16, -0.5, -1/16, 1/16, -1/16, 0},
|
{-1/16, -0.5, -1/16, 1/16, -1/16, 0},
|
||||||
{-1/16, 7/16, -1/16, 1/16, 0.5, 0},
|
{-1/16, 7/16, -1/16, 1/16, 0.5, 0},
|
||||||
}},
|
}},
|
||||||
selection_box = {type = "fixed", fixed = {-7/16, -0.5, -1/16, 7/16, 0.5, 0}},
|
selection_box = {type = "fixed", fixed = {-7/16, -0.5, -1/16, 7/16, 0.5, 0}},
|
||||||
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
|
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
|
||||||
groups = sign_groups,
|
groups = sign_groups,
|
||||||
drop = "signs:sign_wall",
|
drop = "signs:sign_wall",
|
||||||
stack_max = 16,
|
stack_max = 16,
|
||||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||||
|
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
construct_sign(pos)
|
construct_sign(pos)
|
||||||
end,
|
end,
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
destruct_sign(pos)
|
destruct_sign(pos)
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
update_sign(pos, fields, sender)
|
update_sign(pos, fields, sender)
|
||||||
end,
|
end,
|
||||||
on_punch = function(pos, node, puncher)
|
on_punch = function(pos, node, puncher)
|
||||||
update_sign(pos)
|
update_sign(pos)
|
||||||
end,
|
end,
|
||||||
|
@ -319,15 +320,15 @@ minetest.register_node("signs:sign_yard", {
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_entity("signs:text", {
|
minetest.register_entity("signs:text", {
|
||||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||||
visual = "upright_sprite",
|
visual = "upright_sprite",
|
||||||
textures = {},
|
textures = {},
|
||||||
|
|
||||||
on_activate = function(self)
|
on_activate = function(self)
|
||||||
local meta = minetest.get_meta(self.object:getpos())
|
local meta = minetest.get_meta(self.object:getpos())
|
||||||
local text = meta:get_string("text")
|
local text = meta:get_string("text")
|
||||||
self.object:set_properties({textures={generate_texture(create_lines(text))}})
|
self.object:set_properties({textures={generate_texture(create_lines(text))}})
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
if minetest.setting_get("log_mods") then
|
if minetest.setting_get("log_mods") then
|
||||||
|
|
Loading…
Reference in a new issue