Add I18N support for arrow signs
[minetest_tutorial_subgame.git] / mods / arrow_signs / init.lua
blob646ba7d25977b9e14b0d7e1469cd3eb1cd5dd80f
1 --more_signs by addi
2 --Code and Textures are under the CC by-sa 3.0 licence
3 --see: http://creativecommons.org/licenses/by-sa/3.0/
5 -- intllib support
6 local S
7 if (minetest.get_modpath("intllib")) then
8 dofile(minetest.get_modpath("intllib").."/intllib.lua")
9 S = intllib.Getter(minetest.get_current_modname())
10 else
11 S = function ( s ) return s end
12 end
14 arrow_signs={}
16 function arrow_signs:savetext(pos, formname, fields, sender)
18 if not minetest.get_player_privs(sender:get_player_name())["interact"] then
19 minetest.chat_send_player(sender:get_player_name(), "error: you don't have permission to edit the sign. you need the interact priv")
20 return
21 end
22 local meta = minetest.env:get_meta(pos)
23 fields.text = fields.text or ""
24 print((sender:get_player_name() or "").." wrote \""..fields.text..
25 "\" to sign at "..minetest.pos_to_string(pos))
26 meta:set_string("text", fields.text)
27 text = arrow_signs:create_lines(fields.text)
28 meta:set_string("infotext", text)
29 i=0
30 for wort in text:gfind("\n") do
31 i=i+1
32 end
33 if i > 4 then
34 minetest.chat_send_player(sender:get_player_name(),"\tInformation: \nYou've written more than 5 lines. \n it may be that not all lines are displayed. \n Please remove the last entry")
35 end
36 return true
37 end
39 function arrow_signs:create_lines(text)
40 text = text:gsub("/", "\"\n\"")
41 text = text:gsub("|", "\"\n\"")
42 return text
43 end
46 local clone_registered = function(case,name)
47 local params = {}
48 local list
49 if case == "item" then list = minetest.registered_items end
50 if case == "node" then list = minetest.registered_nodes end
51 if case == "craftitem" then list = minetest.registered_craftitems end
52 if case == "tool" then list = minetest.registered_tools end
53 if case == "entity" then list = minetest.registered_entities end
54 if list then
55 for k,v in pairs(list[name]) do
56 params[k] = v
57 end
58 end
59 return params
60 end
62 --Sign right
63 minetest.register_node("arrow_signs:wall_right", {
64 description = S("rightwards-pointing sign"),
65 drawtype = "signlike",
66 tiles = {"arrow_sign_right.png"},
67 inventory_image = "arrow_sign_right.png",
68 paramtype = "light",
69 paramtype2 = "wallmounted",
70 sunlight_propagates = true,
71 walkable = false,
72 selection_box = {
73 type = "wallmounted",
74 --wall_top = <default>
75 --wall_bottom = <default>
76 --wall_side = <default>
78 groups = {immortal=1,attached_node=1,arrow_sign=1},
79 legacy_wallmounted = true,
80 sounds = default.node_sound_defaults(),
81 on_construct = function(pos)
82 --local n = minetest.env:get_node(pos)
83 local meta = minetest.env:get_meta(pos)
84 meta:set_string("formspec", "field[text;;${text}]")
85 meta:set_string("infotext", "\"\"")
86 end,
87 on_receive_fields = function(pos, formname, fields, sender)
88 arrow_signs:savetext(pos, formname, fields, sender)
89 end,
90 on_punch = function(pos)
91 local meta = minetest.env:get_meta(pos)
92 meta:set_string("formspec", "")
93 end,
98 -- sign left
99 minetest.register_node("arrow_signs:wall_left", {
100 description = S("leftwards-pointing sign"),
101 drawtype = "signlike",
102 tiles = {"arrow_sign_left.png"},
103 inventory_image = "arrow_sign_left.png",
104 paramtype = "light",
105 paramtype2 = "wallmounted",
106 sunlight_propagates = true,
107 walkable = false,
108 selection_box = {
109 type = "wallmounted",
110 --wall_top = <default>
111 --wall_bottom = <default>
112 --wall_side = <default>
114 groups = {immortal=1,attached_node=1,arrow_sign=1},
115 legacy_wallmounted = true,
116 sounds = default.node_sound_defaults(),
117 on_construct = function(pos)
118 --local n = minetest.env:get_node(pos)
119 local meta = minetest.env:get_meta(pos)
120 meta:set_string("formspec", "field[text;;${text}]")
121 meta:set_string("infotext", "\"\"")
122 end,
123 on_receive_fields = function(pos, formname, fields, sender)
124 arrow_signs:savetext(pos, formname, fields, sender)
125 end,
126 on_punch = function(pos)
127 local meta = minetest.env:get_meta(pos)
128 meta:set_string("formspec", "")
129 end,
133 --Sign up
134 minetest.register_node("arrow_signs:wall_up", {
135 description = S("upwards-pointing sign"),
136 drawtype = "signlike",
137 tiles = {"arrow_sign_up.png"},
138 inventory_image = "arrow_sign_up.png",
139 paramtype = "light",
140 paramtype2 = "wallmounted",
141 sunlight_propagates = true,
142 walkable = false,
143 selection_box = {
144 type = "wallmounted",
145 --wall_top = <default>
146 --wall_bottom = <default>
147 --wall_side = <default>
149 groups = {immortal=1,attached_node=1,arrow_sign=1},
150 legacy_wallmounted = true,
151 sounds = default.node_sound_defaults(),
152 on_construct = function(pos)
153 --local n = minetest.env:get_node(pos)
154 local meta = minetest.env:get_meta(pos)
155 meta:set_string("formspec", "field[text;;${text}]")
156 meta:set_string("infotext", "\"\"")
157 end,
158 on_receive_fields = function(pos, formname, fields, sender)
159 arrow_signs:savetext(pos, formname, fields, sender)
160 end,
161 on_punch = function(pos)
162 local meta = minetest.env:get_meta(pos)
163 meta:set_string("formspec", "")
164 end,
168 --Sign down
169 minetest.register_node("arrow_signs:wall_down", {
170 description = S("downwards-pointing sign"),
171 drawtype = "signlike",
172 tiles = {"arrow_sign_down.png"},
173 inventory_image = "arrow_sign_down.png",
174 paramtype = "light",
175 paramtype2 = "wallmounted",
176 sunlight_propagates = true,
177 walkable = false,
178 selection_box = {
179 type = "wallmounted",
180 --wall_top = <default>
181 --wall_bottom = <default>
182 --wall_side = <default>
184 groups = {immortal=1,attached_node=1,arrow_sign=1},
185 legacy_wallmounted = true,
186 sounds = default.node_sound_defaults(),
187 on_construct = function(pos)
188 --local n = minetest.env:get_node(pos)
189 local meta = minetest.env:get_meta(pos)
190 meta:set_string("formspec", "field[text;;${text}]")
191 meta:set_string("infotext", "\"\"")
192 end,
193 on_receive_fields = function(pos, formname, fields, sender)
194 arrow_signs:savetext(pos, formname, fields, sender)
195 end,
196 on_punch = function(pos)
197 local meta = minetest.env:get_meta(pos)
198 meta:set_string("formspec", "")
199 end,
203 minetest.register_abm( {
204 nodenames = {"group:arrow_sign"},
205 interval = 5,
206 chance = 1,
207 action = function(pos, node, active_object_count, active_object_cound_wider)
208 local meta = minetest.get_meta(pos)
209 local original = meta:get_string("text")
210 if(original ~= "") then
211 meta:set_string("infotext", S(original))
213 end }