Signs mod WIP
|
@ -0,0 +1,81 @@
|
|||
A
|
||||
_a_
|
||||
4
|
||||
B
|
||||
_b_
|
||||
4
|
||||
C
|
||||
_c_
|
||||
3
|
||||
D
|
||||
_d_
|
||||
4
|
||||
E
|
||||
_e_
|
||||
3
|
||||
F
|
||||
_f_
|
||||
3
|
||||
G
|
||||
_g_
|
||||
4
|
||||
H
|
||||
_h_
|
||||
4
|
||||
I
|
||||
_i_
|
||||
3
|
||||
J
|
||||
_j_
|
||||
4
|
||||
K
|
||||
_k_
|
||||
4
|
||||
L
|
||||
_l_
|
||||
3
|
||||
M
|
||||
_m_
|
||||
5
|
||||
N
|
||||
_n_
|
||||
4
|
||||
O
|
||||
_o_
|
||||
4
|
||||
P
|
||||
_p_
|
||||
4
|
||||
Q
|
||||
_q_
|
||||
4
|
||||
R
|
||||
_r_
|
||||
4
|
||||
S
|
||||
_s_
|
||||
4
|
||||
T
|
||||
_t_
|
||||
3
|
||||
U
|
||||
_u_
|
||||
4
|
||||
V
|
||||
_v_
|
||||
4
|
||||
W
|
||||
_w_
|
||||
5
|
||||
X
|
||||
_x_
|
||||
4
|
||||
Y
|
||||
_y_
|
||||
4
|
||||
Z
|
||||
_z_
|
||||
3
|
||||
|
||||
_sp
|
||||
2
|
|
@ -0,0 +1,140 @@
|
|||
-- Font: 04.jp.org
|
||||
|
||||
-- load characters map
|
||||
local chars_file = io.open(minetest.get_modpath("signs").."/characters", "r")
|
||||
local charmap = {}
|
||||
local charwidth = {}
|
||||
local max_chars = 16
|
||||
if not chars_file then
|
||||
print("[signs] E: character map file not found")
|
||||
else
|
||||
while true do
|
||||
local char = chars_file:read("*l")
|
||||
if char == nil then
|
||||
break
|
||||
end
|
||||
local img = chars_file:read("*l")
|
||||
local width = chars_file:read("*n")
|
||||
chars_file:read("*l")
|
||||
charmap[char] = img
|
||||
charwidth[img] = width
|
||||
end
|
||||
end
|
||||
|
||||
print(dump(charmap))
|
||||
|
||||
local metas = {"line1", "line2", "line3", "line4", "line5", "line6", "line7"}
|
||||
|
||||
minetest.register_node("signs:sign", {
|
||||
description = "Sign",
|
||||
drawtype = "nodebox",
|
||||
inventory_image = "default_sign_wall.png",
|
||||
stack_max = 1,
|
||||
tiles = {"default_wood.png"},
|
||||
node_box = {type = "fixed", fixed = {-0.498, -0.15, -0.45, -0.4, 0.45, 0.45}},
|
||||
selection_box = {type = "fixed", fixed = {-0.498, -0.15, -0.45, -0.4, 0.45, 0.45}},
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local dir = {x = under.x - above.x,
|
||||
y = under.y - above.y,
|
||||
z = under.z - above.z}
|
||||
|
||||
minetest.env:add_node(above, {name="signs:sign"})
|
||||
|
||||
print(minetest.dir_to_wallmounted(dir))
|
||||
|
||||
local text = minetest.env:add_entity({x=above.x-0.399, y=above.y, z=above.z}, "signs:text")
|
||||
text:setyaw(math.pi/2)
|
||||
|
||||
return ItemStack("")
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec", "size[7,8]"..
|
||||
"field[1,0;6,3;line1;;${line1}]"..
|
||||
"field[1,1;6,3;line2;;${line2}]"..
|
||||
"field[1,2;6,3;line3;;${line3}]"..
|
||||
"field[1,3;6,3;line4;;${line4}]"..
|
||||
"field[1,4;6,3;line5;;${line5}]"..
|
||||
"field[1,5;6,3;line6;;${line6}]"..
|
||||
"field[1,6;6,3;line7;;${line7}]")
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local text = {}
|
||||
for i = 1, #metas do
|
||||
table.insert(text, fields[metas[i]])
|
||||
meta:set_string(metas[i], fields[metas[i]])
|
||||
end
|
||||
local object = minetest.env:get_objects_inside_radius(pos, 0.5)[1]
|
||||
object:set_properties({textures={generate_texture(text)}})
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity("signs:text", {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "upright_sprite",
|
||||
textures = {},
|
||||
|
||||
on_activate = function(self)
|
||||
local meta = minetest.env:get_meta(self.object:getpos())
|
||||
local text = {}
|
||||
for i = 1, #metas do
|
||||
table.insert(text, meta:get_string(metas[i]))
|
||||
end
|
||||
self.object:set_properties({textures={generate_texture(text)}})
|
||||
end
|
||||
})
|
||||
|
||||
local table_width = 110
|
||||
local table_padding = 8
|
||||
|
||||
generate_texture = function(lines)
|
||||
local texture = "[combine:"..table_width.."x"..table_width
|
||||
local ypos = 12
|
||||
for i = 1, #lines do
|
||||
texture = texture..generate_line(lines[i], ypos)
|
||||
ypos = ypos + 8
|
||||
end
|
||||
return texture
|
||||
end
|
||||
|
||||
generate_line = function(s, ypos)
|
||||
local i = 1
|
||||
local parsed = {}
|
||||
local width = 0
|
||||
local chars = 0
|
||||
while chars < max_chars and i <= #s do
|
||||
local file = nil
|
||||
if charmap[s:sub(i, i)] ~= nil then
|
||||
file = charmap[s:sub(i, i)]
|
||||
i = i + 1
|
||||
elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then
|
||||
file = charmap[s:sub(i, i + 1)]
|
||||
i = i + 2
|
||||
else
|
||||
print("[signs] W: unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
|
||||
i = i + 1
|
||||
end
|
||||
if file ~= nil then
|
||||
width = width + charwidth[file] + 1
|
||||
table.insert(parsed, file)
|
||||
chars = chars + 1
|
||||
end
|
||||
end
|
||||
width = width - 1
|
||||
|
||||
print("width("..s..") = "..width)
|
||||
|
||||
local texture = ""
|
||||
local xpos = math.floor((table_width - 2 * table_padding - width) / 2 + table_padding)
|
||||
for i = 1, #parsed do
|
||||
texture = texture..":"..xpos..","..ypos.."="..parsed[i]..".png"
|
||||
xpos = xpos + charwidth[parsed[i]] + 1
|
||||
end
|
||||
return texture
|
||||
end
|
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 153 B |
After Width: | Height: | Size: 148 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 148 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 151 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 149 B |
After Width: | Height: | Size: 149 B |
After Width: | Height: | Size: 160 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 148 B |
After Width: | Height: | Size: 139 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 148 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 155 B |
After Width: | Height: | Size: 135 B |
After Width: | Height: | Size: 148 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 155 B |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 151 B |
After Width: | Height: | Size: 158 B |
After Width: | Height: | Size: 153 B |
After Width: | Height: | Size: 160 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 156 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 128 B |
After Width: | Height: | Size: 147 B |
After Width: | Height: | Size: 143 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 151 B |
After Width: | Height: | Size: 142 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 147 B |
After Width: | Height: | Size: 149 B |
After Width: | Height: | Size: 158 B |
After Width: | Height: | Size: 155 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 151 B |