init.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. --[[
  2. boards mod for Minetest. Black boards with text on it.
  3. (c) Pierre-Yves Rollo
  4. This file is part of boards.
  5. boards 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. boards 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 boards. If not, see <http://www.gnu.org/licenses/>.
  15. --]]
  16. boards = {}
  17. boards.name = minetest.get_current_modname()
  18. boards.path = minetest.get_modpath(boards.name)
  19. -- Load support for intllib.
  20. local S, NS = dofile(boards.path.."/intllib.lua")
  21. boards.intllib = S
  22. local F = function(...) return minetest.formspec_escape(S(...)) end
  23. -- Load font
  24. dofile(boards.path.."/font_tinycurs.lua")
  25. local function set_formspec(pos)
  26. local meta = minetest.get_meta(pos)
  27. meta:set_string("formspec",
  28. "size[6,4]"..default.gui_bg..default.gui_bg_img..default.gui_slots..
  29. "textarea[0.5,0.7;5.5,3;display_text;"..F("Text")..";${display_text}]"..
  30. "button_exit[3,3.5;2,1;ok;"..F("Write").."]"..
  31. "button_exit[1,3.5;2,1;wipe;"..F("Wipe").."]")
  32. end
  33. -- On boards, everyone is allowed to write and wipe
  34. local function on_receive_fields(pos, formname, fields, player)
  35. if fields then
  36. if fields.ok or fields.key_enter then
  37. signs_api.set_display_text(pos, fields.display_text, fields.font)
  38. end
  39. if fields.wipe then
  40. signs_api.set_display_text(pos, "", fields.font)
  41. end
  42. end
  43. end
  44. models = {
  45. black_board = {
  46. depth = 1/16, width = 1, height = 1,
  47. entity_fields = {
  48. top = -1/32,
  49. size = { x = 1, y = 15/16 },
  50. maxlines = 5,
  51. color = "#fff",
  52. font_name = "tinycurs",
  53. valign = "top",
  54. },
  55. node_fields = {
  56. description = S("Black board"),
  57. tiles = { "default_wood.png", "default_wood.png",
  58. "default_wood.png", "default_wood.png",
  59. "default_wood.png", "board_black_front.png" },
  60. drawtype = "nodebox",
  61. node_box = {
  62. type = "fixed",
  63. fixed = {
  64. {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5},
  65. {-0.5, -7/16, 6/16, 0.5, -0.5, 7/16}
  66. },
  67. },
  68. on_construct = function(pos)
  69. set_formspec(pos)
  70. display_api.on_construct(pos)
  71. end,
  72. on_receive_fields = on_receive_fields,
  73. },
  74. },
  75. green_board = {
  76. depth = 1/16, width = 1, height = 1,
  77. entity_fields = {
  78. top = -1/32,
  79. size = { x = 1, y = 15/16 },
  80. maxlines = 5,
  81. color = "#fff",
  82. font_name = "tinycurs",
  83. valign = "top",
  84. },
  85. node_fields = {
  86. description = S("Green board"),
  87. tiles = { "default_wood.png", "default_wood.png",
  88. "default_wood.png", "default_wood.png",
  89. "default_wood.png", "board_green_front.png" },
  90. drawtype = "nodebox",
  91. node_box = {
  92. type = "fixed",
  93. fixed = {
  94. {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5},
  95. {-0.5, -7/16, 6/16, 0.5, -0.5, 7/16}
  96. },
  97. },
  98. on_construct = function(pos)
  99. set_formspec(pos)
  100. display_api.on_construct(pos)
  101. end,
  102. on_receive_fields = on_receive_fields,
  103. },
  104. },
  105. }
  106. -- Node registration
  107. for name, model in pairs(models)
  108. do
  109. signs_api.register_sign("boards", name, model)
  110. end
  111. -- Recipes
  112. minetest.register_craft(
  113. {
  114. output = "boards:black_board",
  115. recipe = {
  116. {"group:wood", "group:stone", "dye:black"},
  117. }
  118. })
  119. minetest.register_craft(
  120. {
  121. output = "boards:green_board",
  122. recipe = {
  123. {"group:wood", "group:stone", "dye:dark_green"},
  124. }
  125. })