]> git.lizzy.rs Git - signs_lib.git/blobdiff - api.lua
attempt to work around engine player model bug
[signs_lib.git] / api.lua
diff --git a/api.lua b/api.lua
index 3715c59886c90f2563f45fecddf4eac8002cc0f7..cac59a81ed55f5f5770d2af8b3a140a1f8976fb5 100644 (file)
--- a/api.lua
+++ b/api.lua
@@ -168,7 +168,12 @@ minetest.register_entity("signs_lib:text", {
 function signs_lib.delete_objects(pos)
        local objects = minetest.get_objects_inside_radius(pos, 0.5)
        for _, v in ipairs(objects) do
-               v:remove()
+               if v then
+                       local e = v:get_luaentity()
+                       if e and string.match(e.name, "sign.*text") then
+                               v:remove()
+                       end
+               end
        end
 end
 
@@ -182,8 +187,17 @@ function signs_lib.spawn_entity(pos, texture)
        local obj
 
        if #objects > 0 then
-               obj = objects[1]
-       else
+               for _, v in ipairs(objects) do
+                       if v then
+                               local e = v:get_luaentity()
+                               if e and e.name == "signs_lib:text" then
+                                       obj = v
+                               end
+                       end
+               end
+       end
+
+       if not obj then
                obj = minetest.add_entity(pos, "signs_lib:text")
        end
 
@@ -230,6 +244,14 @@ function signs_lib.spawn_entity(pos, texture)
        end
 end
 
+function signs_lib.set_obj_text(pos, text)
+       local split = signs_lib.split_lines_and_words
+       local text_ansi = Utf8ToAnsi(text)
+       local n = minetest.registered_nodes[minetest.get_node(pos).name]
+       signs_lib.delete_objects(pos)
+       signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
+end
+
 -- rotation
 
 function signs_lib.handle_rotation(pos, node, user, mode)
@@ -288,7 +310,6 @@ function signs_lib.handle_rotation(pos, node, user, mode)
                minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_facedir[node.param2] or 0 })
        end
 
-       signs_lib.delete_objects(tpos)
        signs_lib.update_sign(tpos)
        return true
 end
@@ -544,7 +565,7 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
        return table.concat(texture), lineno
 end
 
-local function make_sign_texture(lines, pos)
+function signs_lib.make_sign_texture(lines, pos)
        local node = minetest.get_node(pos)
        local meta = minetest.get_meta(pos)
 
@@ -598,14 +619,6 @@ function signs_lib.split_lines_and_words(text)
        return lines
 end
 
-function signs_lib.set_obj_text(pos, text)
-       local split = signs_lib.split_lines_and_words
-       local text_ansi = Utf8ToAnsi(text)
-       local n = minetest.registered_nodes[minetest.get_node(pos).name]
-       signs_lib.delete_objects(pos)
-       signs_lib.spawn_entity(pos, make_sign_texture(split(text_ansi), pos))
-end
-
 function signs_lib.construct_sign(pos)
        local form = "size[6,4]"..
                "textarea[0,-0.3;6.5,3;text;;${text}]"..
@@ -841,52 +854,6 @@ function signs_lib.register_fence_with_sign()
        minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
 end
 
---[[
-The main sign registration function
-===================================
-
-Example minimal recommended def for writable signs:
-
-signs_lib.register_sign("foo:my_cool_sign", {
-       description = "Wooden cool sign",
-       inventory_image = "signs_lib_sign_cool_inv.png",
-       tiles = {
-               "signs_lib_sign_cool.png",
-               "signs_lib_sign_cool_edges.png"
-       },
-       number_of_lines = 2,
-       horiz_scaling = 0.8,
-       vert_scaling = 1,
-       line_spacing = 9,
-       font_size = 31,
-       x_offset = 7,
-       y_offset = 4,
-       chars_per_line = 40,
-       entity_info = "standard"
-})
-
-* default def assumes a wallmounted sign with on-pole being allowed.
-
-*For signs that can support being on a pole, include in the def:
-       allow_onpole = true,
-       (defaults to disabled)
-
-*For signs that can support being on a horizontal pole, include in the def:
-       allow_onpole_horizontal = true,
-       (defaults to disabled)
-
-* onpole/onpole_horizontal are independent; one may be allowed without the other
-
-* "standard" entity info implies the standard wood/steel sign model, in
-  wallmounted mode.  For facedir signs using the standard model, use:
-
-       entity_info = {
-               mesh = "signs_lib_standard_wall_sign_entity.obj",
-               yaw = signs_lib.standard_yaw
-       },
-
-]]--
-
 function signs_lib.register_sign(name, rdef)
        local def = table.copy(rdef)
 
@@ -1029,6 +996,7 @@ function signs_lib.register_sign(name, rdef)
        if rdef.allow_widefont then
                table.insert(signs_lib.old_widefont_signs, name.."_widefont")
                table.insert(signs_lib.old_widefont_signs, name.."_widefont_onpole")
+               table.insert(signs_lib.old_widefont_signs, name.."_widefont_hanging")
        end
 end
 
@@ -1090,7 +1058,6 @@ minetest.register_lbm({
                minetest.swap_node(pos, {name = basename, param2 = node.param2})
                local meta = minetest.get_meta(pos)
                meta:set_int("widefont", 1)
-               signs_lib.delete_objects(pos)
                signs_lib.update_sign(pos)
        end
 })