Skip to content

Commit e518976

Browse files
authoredJul 16, 2017
Default: Expose the formspec getter functions (#1783)
1 parent 1d5bc15 commit e518976

File tree

3 files changed

+74
-32
lines changed

3 files changed

+74
-32
lines changed
 

Diff for: ‎game_api.txt

+42
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,48 @@ Default constants
592592

593593
`default.LIGHT_MAX` The maximum light level (see [Node definition] light_source)
594594

595+
596+
GUI and formspecs
597+
-----------------
598+
599+
`default.get_hotbar_bg(x, y)`
600+
601+
* Get the hotbar background as string, containing the formspec elements
602+
* x: Horizontal position in the formspec
603+
* y: Vertical position in the formspec
604+
605+
`default.gui_bg`
606+
607+
* Background color formspec element
608+
609+
`default.gui_bg_img`
610+
611+
* Image overlay formspec element for the background to use in formspecs
612+
613+
`default.gui_slots`
614+
615+
* `listcolors` formspec element that is used to format the slots in formspecs
616+
617+
`default.gui_survival_form`
618+
619+
* Entire formspec for the survival inventory
620+
621+
`default.get_chest_formspec(pos)`
622+
623+
* Get the chest formspec using the defined GUI elements
624+
* pos: Location of the node
625+
626+
`default.get_furnace_active_formspec(fuel_percent, item_percent)`
627+
628+
* Get the active furnace formspec using the defined GUI elements
629+
* fuel_percent: Percent of how much the fuel is used
630+
* item_percent: Percent of how much the item is cooked
631+
632+
`default.get_furnace_inactive_formspec()`
633+
634+
* Get the inactive furnace formspec using the defined GUI elements
635+
636+
595637
Player API
596638
----------
597639

Diff for: ‎mods/default/furnace.lua

+28-28
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
-- Formspecs
44
--
55

6-
local function active_formspec(fuel_percent, item_percent)
7-
local formspec =
8-
"size[8,8.5]"..
6+
function default.get_furnace_active_formspec(fuel_percent, item_percent)
7+
return "size[8,8.5]"..
98
default.gui_bg..
109
default.gui_bg_img..
1110
default.gui_slots..
@@ -25,28 +24,28 @@ local function active_formspec(fuel_percent, item_percent)
2524
"listring[context;fuel]"..
2625
"listring[current_player;main]"..
2726
default.get_hotbar_bg(0, 4.25)
28-
return formspec
2927
end
3028

31-
local inactive_formspec =
32-
"size[8,8.5]"..
33-
default.gui_bg..
34-
default.gui_bg_img..
35-
default.gui_slots..
36-
"list[context;src;2.75,0.5;1,1;]"..
37-
"list[context;fuel;2.75,2.5;1,1;]"..
38-
"image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
39-
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
40-
"list[context;dst;4.75,0.96;2,2;]"..
41-
"list[current_player;main;0,4.25;8,1;]"..
42-
"list[current_player;main;0,5.5;8,3;8]"..
43-
"listring[context;dst]"..
44-
"listring[current_player;main]"..
45-
"listring[context;src]"..
46-
"listring[current_player;main]"..
47-
"listring[context;fuel]"..
48-
"listring[current_player;main]"..
49-
default.get_hotbar_bg(0, 4.25)
29+
function default.get_furnace_inactive_formspec()
30+
return "size[8,8.5]"..
31+
default.gui_bg..
32+
default.gui_bg_img..
33+
default.gui_slots..
34+
"list[context;src;2.75,0.5;1,1;]"..
35+
"list[context;fuel;2.75,2.5;1,1;]"..
36+
"image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
37+
"image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
38+
"list[context;dst;4.75,0.96;2,2;]"..
39+
"list[current_player;main;0,4.25;8,1;]"..
40+
"list[current_player;main;0,5.5;8,3;8]"..
41+
"listring[context;dst]"..
42+
"listring[current_player;main]"..
43+
"listring[context;src]"..
44+
"listring[current_player;main]"..
45+
"listring[context;fuel]"..
46+
"listring[current_player;main]"..
47+
default.get_hotbar_bg(0, 4.25)
48+
end
5049

5150
--
5251
-- Node callback functions that are the same for active and inactive furnace
@@ -190,7 +189,7 @@ local function furnace_node_timer(pos, elapsed)
190189
--
191190
-- Update formspec, infotext and node
192191
--
193-
local formspec = inactive_formspec
192+
local formspec
194193
local item_state
195194
local item_percent = 0
196195
if cookable then
@@ -216,20 +215,22 @@ local function furnace_node_timer(pos, elapsed)
216215
active = "active "
217216
local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
218217
fuel_state = fuel_percent .. "%"
219-
formspec = active_formspec(fuel_percent, item_percent)
218+
formspec = default.get_furnace_active_formspec(fuel_percent, item_percent)
220219
swap_node(pos, "default:furnace_active")
221220
-- make sure timer restarts automatically
222221
result = true
223222
else
224223
if not fuellist[1]:is_empty() then
225224
fuel_state = "0%"
226225
end
226+
formspec = default.get_furnace_inactive_formspec()
227227
swap_node(pos, "default:furnace")
228228
-- stop timer on the inactive furnace
229229
minetest.get_node_timer(pos):stop()
230230
end
231231

232-
local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
232+
local infotext = "Furnace " .. active .. "(Item: " .. item_state ..
233+
"; Fuel: " .. fuel_state .. ")"
233234

234235
--
235236
-- Set meta values
@@ -266,7 +267,7 @@ minetest.register_node("default:furnace", {
266267

267268
on_construct = function(pos)
268269
local meta = minetest.get_meta(pos)
269-
meta:set_string("formspec", inactive_formspec)
270+
meta:set_string("formspec", default.get_furnace_inactive_formspec())
270271
local inv = meta:get_inventory()
271272
inv:set_size('src', 1)
272273
inv:set_size('fuel', 1)
@@ -327,4 +328,3 @@ minetest.register_node("default:furnace_active", {
327328
allow_metadata_inventory_move = allow_metadata_inventory_move,
328329
allow_metadata_inventory_take = allow_metadata_inventory_take,
329330
})
330-

Diff for: ‎mods/default/nodes.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ minetest.register_node("default:lava_flowing", {
17661766
-- Tools / "Advanced" crafting / Non-"natural"
17671767
--
17681768

1769-
local function get_chest_formspec(pos)
1769+
function default.get_chest_formspec(pos)
17701770
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
17711771
local formspec =
17721772
"size[8,9]" ..
@@ -1890,7 +1890,7 @@ function default.register_chest(name, d)
18901890
end
18911891
minetest.after(0.2, minetest.show_formspec,
18921892
clicker:get_player_name(),
1893-
"default:chest", get_chest_formspec(pos))
1893+
"default:chest", default.get_chest_formspec(pos))
18941894
open_chests[clicker:get_player_name()] = { pos = pos,
18951895
sound = def.sound_close, swap = name }
18961896
end
@@ -1912,7 +1912,7 @@ function default.register_chest(name, d)
19121912
minetest.show_formspec(
19131913
player:get_player_name(),
19141914
"default:chest_locked",
1915-
get_chest_formspec(pos)
1915+
default.get_chest_formspec(pos)
19161916
)
19171917
end
19181918
def.on_skeleton_key_use = function(pos, player, newsecret)
@@ -1957,7 +1957,7 @@ function default.register_chest(name, d)
19571957
end
19581958
minetest.after(0.2, minetest.show_formspec,
19591959
clicker:get_player_name(),
1960-
"default:chest", get_chest_formspec(pos))
1960+
"default:chest", default.get_chest_formspec(pos))
19611961
open_chests[clicker:get_player_name()] = { pos = pos,
19621962
sound = def.sound_close, swap = name }
19631963
end

0 commit comments

Comments
 (0)
Please sign in to comment.