Signs mod WIP

master
Ilya Zhuravlev 2012-08-07 19:32:42 +04:00
parent 486f491364
commit bc21fbc785
55 changed files with 221 additions and 0 deletions

81
signs/characters Normal file
View File

@ -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

140
signs/init.lua Normal file
View File

@ -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

BIN
signs/textures/_a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

BIN
signs/textures/_a_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
signs/textures/_b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

BIN
signs/textures/_b_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
signs/textures/_c.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
signs/textures/_c_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
signs/textures/_d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

BIN
signs/textures/_d_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

BIN
signs/textures/_e.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_e_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
signs/textures/_f.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

BIN
signs/textures/_f_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

BIN
signs/textures/_g.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

BIN
signs/textures/_g_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
signs/textures/_h.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
signs/textures/_h_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
signs/textures/_i.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

BIN
signs/textures/_i_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
signs/textures/_j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
signs/textures/_j_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
signs/textures/_k.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

BIN
signs/textures/_k_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
signs/textures/_l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

BIN
signs/textures/_l_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
signs/textures/_m.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_m_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
signs/textures/_n.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
signs/textures/_n_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
signs/textures/_o.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
signs/textures/_o_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

BIN
signs/textures/_p.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
signs/textures/_p_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

BIN
signs/textures/_q.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

BIN
signs/textures/_q_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
signs/textures/_r.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_r_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

BIN
signs/textures/_s_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

BIN
signs/textures/_sp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

BIN
signs/textures/_t.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
signs/textures/_t_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

BIN
signs/textures/_u.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_u_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_v.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

BIN
signs/textures/_v_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

BIN
signs/textures/_w.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

BIN
signs/textures/_w_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

BIN
signs/textures/_x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
signs/textures/_x_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

BIN
signs/textures/_y.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

BIN
signs/textures/_y_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
signs/textures/_z.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

BIN
signs/textures/_z_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B