compatibility.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. --[[
  2. signs mod for Minetest - Various signs with text displayed on
  3. (c) Pierre-Yves Rollo
  4. This file is part of signs.
  5. signs is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. signs is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with signs. If not, see <http://www.gnu.org/licenses/>.
  15. --]]
  16. -- Wallmounted to facedir conversion
  17. ------------------------------------
  18. local wallmounted_to_facedir = {
  19. [0]=1, -- Should not happend with signs
  20. [1]=1, -- Should not happend with signs
  21. [2]=1,
  22. [3]=3,
  23. [4]=0,
  24. [5]=2
  25. }
  26. -- Nodes conversions
  27. local convert_nodes = {
  28. ['signs:wooden_right'] = 'signs:wooden_right_sign',
  29. ['signs:wooden_left'] = 'signs:wooden_left_sign',
  30. ['signs:poster'] = 'signs:paper_poster'
  31. }
  32. local function compatibility_check_1(pos, node)
  33. -- Old wallmounted modes to new facedir nodes conversion
  34. node.name = convert_nodes[node.name]
  35. if node.name then
  36. node.param2 = wallmounted_to_facedir[node.param2]
  37. display_api.on_destruct(pos)
  38. minetest.swap_node(pos, node)
  39. display_api.on_construct(pos)
  40. end
  41. end
  42. minetest.register_lbm({ name = "signs:conpatibility_1",
  43. nodenames = {"signs:wooden_right", "signs:wooden_left", "signs:poster"},
  44. action = compatibility_check_1,
  45. })
  46. -- Text entity name change because of signs_lib using signs prefix
  47. ------------------------------------------------------------------
  48. -- If no other mod registered signs:text, register it.
  49. -- We need to have this entity registered to be able to remove it.
  50. if minetest.registered_entities["signs:text"] == nil then
  51. minetest.register_entity("signs:text", {
  52. collisionbox = { 0, 0, 0, 0, 0, 0 },
  53. visual = "upright_sprite",
  54. textures = {},
  55. })
  56. end
  57. local function compatibility_check_2(pos, node)
  58. -- Remove old entity
  59. for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
  60. local entity = objref:get_luaentity()
  61. if entity and entity.name == "signs:text" then
  62. objref:remove()
  63. end
  64. end
  65. -- Create new entity
  66. display_api.update_entities(pos)
  67. end
  68. minetest.register_lbm({ name = "signs:conpatibility_2",
  69. nodenames = {"signs:wooden_right_sign", "signs:wooden_left_sign", "signs:paper_poster"},
  70. action = compatibility_check_2,
  71. })
  72. --Backwards compatibility API functions
  73. signs.set_display_text = function(...)
  74. minetest.log("warning", "signs.set_display_text() is deprecated, please use signs_api.set_display_text() instead.")
  75. return signs_api.set_display_text(...)
  76. end
  77. signs.set_formspec = function(...)
  78. minetest.log("warning", "signs.set_formspec() is deprecated, please use signs_api.set_formspec() instead.")
  79. return signs_api.set_formspec(...)
  80. end
  81. signs.on_receive_fields = function(...)
  82. minetest.log("warning", "signs.on_receive_fields() is deprecated, please use signs_api.on_receive_fields() instead.")
  83. return signs_api.on_receive_fields(...)
  84. end
  85. signs.on_place_direction = function(...)
  86. minetest.log("warning", "signs.on_place_direction() is deprecated, please use signs_api.on_place_direction() instead.")
  87. return signs_api.on_place_direction(...)
  88. end
  89. signs.on_rotate = function(...)
  90. minetest.log("warning", "signs.on_rotate() is deprecated, please use signs_api.on_rotate() instead.")
  91. return signs_api.on_rotate(...)
  92. end
  93. signs.register_sign = function(...)
  94. minetest.log("warning", "signs.register_sign() is deprecated, please use signs_api.register_sign() instead.")
  95. return signs_api.register_sign(...)
  96. end