]> git.lizzy.rs Git - signs_lib.git/blob - api.lua
allow rotation to all 6 faces for both wallmounted and facedir signs, make them follo...
[signs_lib.git] / api.lua
1 -- signs_lib api, backported from street_signs
2
3 local S = signs_lib.gettext
4
5 signs_lib.lbm_restore_nodes = {}
6 signs_lib.old_fenceposts = {}
7 signs_lib.old_fenceposts_replacement_signs = {}
8 signs_lib.old_fenceposts_with_signs = {}
9 signs_lib.allowed_poles = {}
10
11 -- Settings used for a standard wood or steel wall sign
12 signs_lib.standard_lines = 6
13 signs_lib.standard_hscale = 1.7
14 signs_lib.standard_vscale = 1.75
15 signs_lib.standard_lspace = 1
16 signs_lib.standard_fsize = 15
17 signs_lib.standard_xoffs = 5
18 signs_lib.standard_yoffs = 38
19 signs_lib.standard_cpl = 25
20
21 signs_lib.standard_wood_groups =  {choppy = 2, flammable = 2, oddly_breakable_by_hand = 3}
22 signs_lib.standard_steel_groups = {cracky = 2, oddly_breakable_by_hand = 3} 
23
24 signs_lib.standard_yaw = {
25         0,
26         math.pi / -2,
27         math.pi,
28         math.pi / 2,
29 }
30
31 signs_lib.wallmounted_yaw = {
32         nil,
33         nil,
34         math.pi / -2,
35         math.pi / 2,
36         0,
37         math.pi,
38 }
39
40 signs_lib.fdir_to_back = {
41         {  0, -1 },
42         { -1,  0 },
43         {  0,  1 },
44         {  1,  0 },
45 }
46
47 signs_lib.wall_fdir_to_back = {
48         nil,
49         nil,
50         {  0,  1 },
51         {  0, -1 },
52         { -1,  0 },
53         {  1,  0 },
54 }
55
56 signs_lib.rotate_facedir = {
57         [0] = 1,
58         [1] = 6,
59         [2] = 3,
60         [3] = 0,
61         [4] = 2,
62         [5] = 6,
63         [6] = 4
64 }
65
66 signs_lib.rotate_walldir = {
67         [0] = 1,
68         [1] = 5,
69         [2] = 0,
70         [3] = 4,
71         [4] = 2,
72         [5] = 3
73 }
74
75 -- Initialize character texture cache
76 local ctexcache = {}
77
78 signs_lib.wallmounted_rotate = function(pos, node, user, mode)
79         if not signs_lib.can_modify(pos, user) then return false end
80
81         if mode ~= screwdriver.ROTATE_FACE or string.match(node.name, "_onpole") then
82                 return false
83         end
84
85         local newparam2 = signs_lib.rotate_walldir[node.param2] or 0
86
87         minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
88         for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
89                 local e = v:get_luaentity()
90                 if e and e.name == "signs_lib:text" then
91                         v:remove()
92                 end
93         end
94         signs_lib.update_sign(pos)
95         return true
96 end
97
98 signs_lib.facedir_rotate = function(pos, node, user, mode)
99         if not signs_lib.can_modify(pos, user) then return false end
100
101         if mode ~= screwdriver.ROTATE_FACE or string.match(node.name, "_onpole") then
102                 return false
103         end
104
105         local newparam2 = signs_lib.rotate_facedir[node.param2] or 0
106
107         minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
108         for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
109                 local e = v:get_luaentity()
110                 if e and e.name == "signs_lib:text" then
111                         v:remove()
112                 end
113         end
114         signs_lib.update_sign(pos)
115         return true
116 end
117
118 local DEFAULT_TEXT_SCALE = {x=10, y=10}
119
120 -- infinite stacks
121
122 if not minetest.settings:get_bool("creative_mode") then
123         signs_lib.expect_infinite_stacks = false
124 else
125         signs_lib.expect_infinite_stacks = true
126 end
127
128 -- CONSTANTS
129
130 -- Path to the textures.
131 local TP = signs_lib.path .. "/textures"
132 -- Font file formatter
133 local CHAR_FILE = "%s_%02x.png"
134 -- Fonts path
135 local CHAR_PATH = TP .. "/" .. CHAR_FILE
136
137 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
138
139 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
140
141 -- check if a file does exist
142 -- to avoid reopening file after checking again
143 -- pass TRUE as second argument
144 local function file_exists(name, return_handle, mode)
145         mode = mode or "r";
146         local f = io.open(name, mode)
147         if f ~= nil then
148                 if (return_handle) then
149                         return f
150                 end
151                 io.close(f) 
152                 return true 
153         else 
154                 return false 
155         end
156 end
157
158 -- Read the image size from a PNG file.
159 -- Returns image_w, image_h.
160 -- Only the LSB is read from each field!
161 function signs_lib.read_image_size(filename)
162         local f = file_exists(filename, true, "rb")
163         -- file might not exist (don't crash the game)
164         if (not f) then
165                 return 0, 0
166         end
167         f:seek("set", 0x0)
168         local hdr = f:read(string.len(PNG_HDR))
169         if hdr ~= PNG_HDR then
170                 f:close()
171                 return
172         end
173         f:seek("set", 0x13)
174         local ws = f:read(1)
175         f:seek("set", 0x17)
176         local hs = f:read(1)
177         f:close()
178         return ws:byte(), hs:byte()
179 end
180
181 -- 4 rows, max 80 chars per, plus a bit of fudge to
182 -- avoid excess trimming (e.g. due to color codes)
183
184 local MAX_INPUT_CHARS = 400
185
186 -- helper functions to trim sign text input/output
187
188 local function trim_input(text)
189         return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
190 end
191
192 local function build_char_db(font_size)
193
194         local cw = {}
195
196         -- To calculate average char width.
197         local total_width = 0
198         local char_count = 0
199
200         for c = 32, 255 do
201                 local w, h = signs_lib.read_image_size(CHAR_PATH:format("signs_lib_font_"..font_size.."px", c))
202                 if w and h then
203                         local ch = string.char(c)
204                         cw[ch] = w
205                         total_width = total_width + w
206                         char_count = char_count + 1
207                 end
208         end
209
210         local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png")
211         assert(cbw and cbh, "error reading bg dimensions")
212         return cw, cbw, cbh, (total_width / char_count)
213 end
214
215 signs_lib.charwidth15,
216 signs_lib.colorbgw15,
217 signs_lib.lineheight15,
218 signs_lib.avgwidth15 = build_char_db(15)
219
220 signs_lib.charwidth31,
221 signs_lib.colorbgw31,
222 signs_lib.lineheight31,
223 signs_lib.avgwidth31 = build_char_db(31)
224
225 local sign_groups = {choppy=2, dig_immediate=2}
226 local fences_with_sign = { }
227
228 -- some local helper functions
229
230 local function split_lines_and_words(text)
231         if not text then return end
232         local lines = { }
233         for _, line in ipairs(text:split("\n")) do
234                 table.insert(lines, line:split(" "))
235         end
236         return lines
237 end
238
239 local math_max = math.max
240
241 local function fill_line(x, y, w, c, font_size, colorbgw)
242         c = c or "0"
243         local tex = { }
244         for xx = 0, math.max(0, w), colorbgw do
245                 table.insert(tex, (":%d,%d=signs_lib_color_"..font_size.."px_%s.png"):format(x + xx, y, c))
246         end
247         return table.concat(tex)
248 end
249
250 -- make char texture file name
251 -- if texture file does not exist use fallback texture instead
252 local function char_tex(font_name, ch)
253         if ctexcache[font_name..ch] then
254                 return ctexcache[font_name..ch], true
255         else
256                 local c = ch:byte()
257                 local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
258                 if exists and c ~= 14 then
259                         tex = CHAR_FILE:format(font_name, c)
260                 else
261                         tex = CHAR_FILE:format(font_name, 0x0)
262                 end
263                 ctexcache[font_name..ch] = tex
264                 return tex, exists
265         end
266 end
267
268 local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw)
269         local width = 0
270         local maxw = 0
271         local font_name = "signs_lib_font_"..font_size.."px"
272
273         local words = { }
274         local node = minetest.get_node(pos)
275         local def = minetest.registered_items[node.name]
276         local default_color = def.default_color or 0
277
278         local cur_color = tonumber(default_color, 16)
279
280         -- We check which chars are available here.
281         for word_i, word in ipairs(line) do
282                 local chars = { }
283                 local ch_offs = 0
284                 word = string.gsub(word, "%^[12345678abcdefgh]", {
285                         ["^1"] = string.char(0x81),
286                         ["^2"] = string.char(0x82),
287                         ["^3"] = string.char(0x83),
288                         ["^4"] = string.char(0x84),
289                         ["^5"] = string.char(0x85),
290                         ["^6"] = string.char(0x86),
291                         ["^7"] = string.char(0x87),
292                         ["^8"] = string.char(0x88),
293                         ["^a"] = string.char(0x8a),
294                         ["^b"] = string.char(0x8b),
295                         ["^c"] = string.char(0x8c),
296                         ["^d"] = string.char(0x8d),
297                         ["^e"] = string.char(0x8e),
298                         ["^f"] = string.char(0x8f),
299                         ["^g"] = string.char(0x90),
300                         ["^h"] = string.char(0x91)
301                 })
302                 local word_l = #word
303                 local i = 1
304                 while i <= word_l  do
305                         local c = word:sub(i, i)
306                         if c == "#" then
307                                 local cc = tonumber(word:sub(i+1, i+1), 16)
308                                 if cc then
309                                         i = i + 1
310                                         cur_color = cc
311                                 end
312                         else
313                                 local w = cwidth_tab[c]
314                                 if w then
315                                         width = width + w + 1
316                                         if width >= (line_width - cwidth_tab[" "]) then
317                                                 width = 0
318                                         else
319                                                 maxw = math_max(width, maxw)
320                                         end
321                                         if #chars < MAX_INPUT_CHARS then
322                                                 table.insert(chars, {
323                                                         off = ch_offs,
324                                                         tex = char_tex(font_name, c),
325                                                         col = ("%X"):format(cur_color),
326                                                 })
327                                         end
328                                         ch_offs = ch_offs + w
329                                 end
330                         end
331                         i = i + 1
332                 end
333                 width = width + cwidth_tab[" "] + 1
334                 maxw = math_max(width, maxw)
335                 table.insert(words, { chars=chars, w=ch_offs })
336         end
337
338         -- Okay, we actually build the "line texture" here.
339
340         local texture = { }
341
342         local start_xpos = math.floor((line_width - maxw) / 2) + def.x_offset
343
344         local xpos = start_xpos
345         local ypos = (line_height + def.line_spacing)* lineno + def.y_offset
346
347         cur_color = nil
348
349         for word_i, word in ipairs(words) do
350                 local xoffs = (xpos - start_xpos)
351                 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
352                         table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
353                         xpos = start_xpos
354                         ypos = ypos + line_height + def.line_spacing
355                         lineno = lineno + 1
356                         if lineno >= def.number_of_lines then break end
357                         table.insert(texture, fill_line(xpos, ypos, maxw, cur_color, font_size, colorbgw))
358                 end
359                 for ch_i, ch in ipairs(word.chars) do
360                         if ch.col ~= cur_color then
361                                 cur_color = ch.col
362                                 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color, font_size, colorbgw))
363                         end
364                         table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
365                 end
366                 table.insert(
367                         texture, 
368                         (":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ")
369                 )
370                 xpos = xpos + word.w + cwidth_tab[" "]
371                 if xpos >= (line_width + cwidth_tab[" "]) then break end
372         end
373
374         table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
375         table.insert(texture, fill_line(start_xpos, ypos + line_height, maxw, "n", font_size, colorbgw))
376
377         return table.concat(texture), lineno
378 end
379
380 local function make_sign_texture(lines, pos)
381         local node = minetest.get_node(pos)
382         local def = minetest.registered_items[node.name]
383
384         local font_size
385         local line_width
386         local line_height
387         local char_width
388         local colorbgw
389
390         if def.font_size and def.font_size == 31 then
391                 font_size = 31
392                 line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * def.horiz_scaling
393                 line_height = signs_lib.lineheight31
394                 char_width = signs_lib.charwidth31
395                 colorbgw = signs_lib.colorbgw31
396         else
397                 font_size = 15
398                 line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * def.horiz_scaling
399                 line_height = signs_lib.lineheight15
400                 char_width = signs_lib.charwidth15
401                 colorbgw = signs_lib.colorbgw15
402         end
403
404         local texture = { ("[combine:%dx%d"):format(line_width, (line_height + def.line_spacing) * def.number_of_lines * def.vert_scaling) }
405
406         local lineno = 0
407         for i = 1, #lines do
408                 if lineno >= def.number_of_lines then break end
409                 local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw)
410                 table.insert(texture, linetex)
411                 lineno = ln + 1
412         end
413         table.insert(texture, "^[makealpha:0,0,0")
414         return table.concat(texture, "")
415 end
416
417 local function set_obj_text(obj, text, x, pos)
418         local split = split_lines_and_words
419         local text_ansi = Utf8ToAnsi(text)
420         local n = minetest.registered_nodes[minetest.get_node(pos).name]
421         local text_scale = (n and n.text_scale) or DEFAULT_TEXT_SCALE
422         local texture = make_sign_texture(split(text_ansi), pos)
423         obj:set_properties({
424                 textures={texture},
425                 visual_size = text_scale,
426         })
427 end
428
429 signs_lib.construct_sign = function(pos)
430         local meta = minetest.get_meta(pos)
431         meta:set_string(
432                 "formspec",
433                 "size[6,4]"..
434                 "textarea[0,-0.3;6.5,3;text;;${text}]"..
435                 "button_exit[2,3.4;2,1;ok;"..S("Write").."]"..
436                 "background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]")
437         meta:set_string("infotext", "")
438 end
439
440 function signs_lib.destruct_sign(pos)
441         local objects = minetest.get_objects_inside_radius(pos, 0.5)
442         for _, v in ipairs(objects) do
443                 local e = v:get_luaentity()
444                 if e and e.name == "signs_lib:text" then
445                         v:remove()
446                 end
447         end
448 end
449
450 local function make_infotext(text)
451         text = trim_input(text)
452         local lines = split_lines_and_words(text) or {}
453         local lines2 = { }
454         for _, line in ipairs(lines) do
455                 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
456         end
457         return table.concat(lines2, "\n")
458 end
459
460 function signs_lib.update_sign(pos, fields)
461         local meta = minetest.get_meta(pos)
462
463         local text = fields and fields.text or meta:get_string("text")
464         text = trim_input(text)
465
466         local owner = meta:get_string("owner")
467         ownstr = ""
468         if owner ~= "" then ownstr = S("Locked sign, owned by @1\n", owner) end
469
470         meta:set_string("text", text)
471         meta:set_string("infotext", ownstr..make_infotext(text).." ")
472
473         local objects = minetest.get_objects_inside_radius(pos, 0.5)
474         local found
475         for _, v in ipairs(objects) do
476                 local e = v:get_luaentity()
477                 if e and e.name == "signs_lib:text" then
478                         if found then
479                                 v:remove()
480                         else
481                                 set_obj_text(v, text, nil, pos)
482                                 found = true
483                         end
484                 end
485         end
486         if found then
487                 return
488         end
489
490         -- if there is no entity
491         local signnode = minetest.get_node(pos)
492         local signname = signnode.name
493         local def = minetest.registered_items[signname]
494         if not def.entity_info or not def.entity_info.yaw[signnode.param2 + 1] then return end
495         local obj = minetest.add_entity(pos, "signs_lib:text")
496
497         obj:setyaw(def.entity_info.yaw[signnode.param2 + 1])
498         obj:set_properties({
499                 mesh = def.entity_info.mesh,
500         })
501 end
502
503 function signs_lib.receive_fields(pos, formname, fields, sender)
504         if fields and fields.text and fields.ok and signs_lib.can_modify(pos, sender) then
505                 minetest.log("action", S("@1 wrote \"@2\" to sign at @3",
506                         (sender:get_player_name() or ""),
507                         fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
508                         minetest.pos_to_string(pos)
509                 ))
510                 signs_lib.update_sign(pos, fields)
511         end
512 end
513
514 function signs_lib.can_modify(pos, player)
515         local meta = minetest.get_meta(pos)
516         local owner = meta:get_string("owner")
517         local playername = player:get_player_name()
518
519         if minetest.is_protected(pos, playername) then 
520                 minetest.record_protection_violation(pos, playername)
521                 return false
522         end
523
524         if owner == ""
525           or playername == owner
526           or (minetest.check_player_privs(playername, {sign_editor=true}))
527           or (playername == minetest.settings:get("name")) then
528                 return true
529         end
530         minetest.record_protection_violation(pos, playername)
531         return false
532 end
533
534 local signs_text_on_activate = function(self)
535         local pos = self.object:getpos()
536         local meta = minetest.get_meta(pos)
537         local signnode = minetest.get_node(pos)
538         local signname = signnode.name
539         local def = minetest.registered_items[signname]
540         local text = meta:get_string("text")
541         if text and def and def.entity_info then
542                 text = trim_input(text)
543                 set_obj_text(self.object, text, nil, pos)
544                 self.object:set_properties({
545                         mesh = def.entity_info.mesh,
546                 })
547         end
548 end
549
550 minetest.register_entity("signs_lib:text", {
551         collisionbox = { 0, 0, 0, 0, 0, 0 },
552         visual = "mesh",
553         mesh = "signs_lib_basic_entity.obj",
554         textures = {},
555         on_activate = signs_text_on_activate,
556 })
557
558 -- make selection boxes
559 -- sizex/sizey specified in inches because that's what MUTCD uses.
560
561 function signs_lib.make_selection_boxes(sizex, sizey, onpole, xoffs, yoffs, zoffs, fdir)
562
563         local tx = (sizex * 0.0254 ) / 2
564         local ty = (sizey * 0.0254 ) / 2
565         local xo = xoffs and xoffs * 0.0254 or 0
566         local yo = yoffs and yoffs * 0.0254 or 0
567         local zo = zoffs and zoffs * 0.0254 or 0
568
569         if onpole == "_onpole" then
570                 if not fdir then
571                         return {
572                                 type = "wallmounted",
573                                 wall_side =   { -0.5 - 0.3125 + zo, -ty + yo, -tx + xo, -0.4375 - 0.3125 + zo, ty + yo , tx + xo },
574                                 wall_top =    {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
575                                 wall_bottom = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
576                         }
577                 else
578                         return {
579                                 type = "fixed",
580                                 fixed = { -tx + xo, -ty + yo, 0.5 + 0.3125 + zo, tx + xo, ty + yo, 0.4375 + 0.3125 + zo }
581                         }
582                 end
583         else
584                 if not fdir then
585                         return {
586                                 type = "wallmounted",
587                                 wall_side =   { -0.5 + zo, -ty + yo, -tx + xo, -0.4375 + zo, ty + yo, tx + xo },
588                                 wall_top =    { -tx - xo, 0.5 + zo, -ty + yo, tx - xo, 0.4375 + zo, ty + yo},
589                                 wall_bottom = { -tx - xo, -0.5 + zo, -ty + yo, tx - xo, -0.4375 + zo, ty + yo }
590                         }
591                 else
592                         return {
593                                 type = "fixed",
594                                 fixed = { -tx + xo, -ty + yo, 0.5 + zo, tx + xo, ty + yo, 0.4375 + zo}
595                         }
596                 end
597         end
598 end
599
600 function signs_lib.check_for_pole(pos, pointed_thing)
601         local ppos = minetest.get_pointed_thing_position(pointed_thing)
602         local pnode = minetest.get_node(ppos)
603         local pdef = minetest.registered_items[pnode.name]
604
605         print(dump(pos))
606         print(dump(ppos))
607
608         if (signs_lib.allowed_poles[pnode.name]
609                   or (pdef and pdef.drawtype == "fencelike")
610                   or string.find(pnode.name, "default:fence_")
611                   or string.find(pnode.name, "_post")
612                   or string.find(pnode.name, "fencepost")
613                   or (pnode.name == "streets:bigpole" and pnode.param2 < 4)
614                   or (pnode.name == "streets:bigpole" and pnode.param2 > 19 and pnode.param2 < 24)
615                 )
616           and
617                 (pos.x ~= ppos.x or pos.z ~= ppos.z) then
618                 print("signs_lib.check_for_pole returned true")
619                 return true
620         end
621 end
622
623 function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locked)
624         local ppos = minetest.get_pointed_thing_position(pointed_thing)
625         local pnode = minetest.get_node(ppos)
626         local pdef = minetest.registered_items[pnode.name]
627         local playername = placer:get_player_name()
628
629         if signs_lib.check_for_pole(pos, pointed_thing) then
630                 local node = minetest.get_node(pos)
631                 minetest.swap_node(pos, {name = itemstack:get_name().."_onpole", param2 = node.param2})
632         end
633         if locked then
634                 local meta = minetest.get_meta(pos)
635                 meta:set_string("owner", playername)
636                 meta:set_string("infotext", S("Locked sign, owned by @1\n", playername))
637         end
638 end
639
640 function signs_lib.register_fence_with_sign()
641         minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
642 end
643
644 -- restore signs' text after /clearobjects and the like, the next time
645 -- a block is reloaded by the server.
646
647 minetest.register_lbm({
648         nodenames = signs_lib.lbm_restore_nodes,
649         name = "signs_lib:restore_sign_text",
650         label = "Restore sign text",
651         run_at_every_load = true,
652         action = function(pos, node)
653                 signs_lib.update_sign(pos,nil,nil,node)
654         end
655 })
656
657 -- Convert old signs on fenceposts into signs on.. um.. fence posts :P
658
659 minetest.register_lbm({
660         nodenames = signs_lib.old_fenceposts_with_signs,
661         name = "signs_lib:fix_fencepost_signs",
662         label = "Change single-node signs on fences into normal",
663         run_at_every_load = true,
664         action = function(pos, node)
665
666                 local fdir = node.param2 % 8
667                 local signpos = {
668                         x = pos.x + signs_lib.fdir_to_back[fdir+1][1],
669                         y = pos.y,
670                         z = pos.z + signs_lib.fdir_to_back[fdir+1][2]
671                 }
672
673                 if minetest.get_node(signpos).name == "air" then
674                         local new_wmdir = minetest.dir_to_wallmounted(minetest.facedir_to_dir(fdir))
675                         local oldfence =  signs_lib.old_fenceposts[node.name]
676                         local newsign =   signs_lib.old_fenceposts_replacement_signs[node.name]
677
678                         for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
679                                 local e = v:get_luaentity()
680                                 if e and e.name == "signs_lib:text" then
681                                         v:remove()
682                                 end
683                         end
684
685                         local oldmeta = minetest.get_meta(pos):to_table()
686                         minetest.set_node(pos, {name = oldfence})
687                         minetest.set_node(signpos, { name = newsign, param2 = new_wmdir })
688                         local newmeta = minetest.get_meta(signpos)
689                         newmeta:from_table(oldmeta)
690                         signs_lib.update_sign(signpos)
691                 end
692         end
693 })