Default: Expose the formspec getter functions (#1783)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Sun, 16 Jul 2017 12:31:34 +0000 (14:31 +0200)
committerGitHub <noreply@github.com>
Sun, 16 Jul 2017 12:31:34 +0000 (14:31 +0200)
game_api.txt
mods/default/furnace.lua
mods/default/nodes.lua

index 1864cba4279b6e1b021b20d59f449887f2330a2c..d5d09e92d6af8b1cc4258dca1046ddc7e52ef833 100644 (file)
@@ -592,6 +592,48 @@ Default constants
 
 `default.LIGHT_MAX`  The maximum light level (see [Node definition] light_source)
 
+
+GUI and formspecs
+-----------------
+
+`default.get_hotbar_bg(x, y)`
+
+ * Get the hotbar background as string, containing the formspec elements
+ * x: Horizontal position in the formspec
+ * y: Vertical position in the formspec
+
+`default.gui_bg`
+
+ * Background color formspec element
+
+`default.gui_bg_img`
+
+ * Image overlay formspec element for the background to use in formspecs
+
+`default.gui_slots`
+
+ * `listcolors` formspec element that is used to format the slots in formspecs
+
+`default.gui_survival_form`
+
+ * Entire formspec for the survival inventory
+
+`default.get_chest_formspec(pos)`
+
+ * Get the chest formspec using the defined GUI elements
+ * pos: Location of the node
+
+`default.get_furnace_active_formspec(fuel_percent, item_percent)`
+
+ * Get the active furnace formspec using the defined GUI elements
+ * fuel_percent: Percent of how much the fuel is used
+ * item_percent: Percent of how much the item is cooked
+
+`default.get_furnace_inactive_formspec()`
+
+ * Get the inactive furnace formspec using the defined GUI elements
+
+
 Player API
 ----------
 
index 3c9081dd50c7c8524fe4f755ceb2924272e6488d..1643d427cb8573ffe3fcf6165b826cc1650544ad 100644 (file)
@@ -3,9 +3,8 @@
 -- Formspecs
 --
 
-local function active_formspec(fuel_percent, item_percent)
-       local formspec =
-               "size[8,8.5]"..
+function default.get_furnace_active_formspec(fuel_percent, item_percent)
+       return "size[8,8.5]"..
                default.gui_bg..
                default.gui_bg_img..
                default.gui_slots..
@@ -25,28 +24,28 @@ local function active_formspec(fuel_percent, item_percent)
                "listring[context;fuel]"..
                "listring[current_player;main]"..
                default.get_hotbar_bg(0, 4.25)
-       return formspec
 end
 
-local inactive_formspec =
-       "size[8,8.5]"..
-       default.gui_bg..
-       default.gui_bg_img..
-       default.gui_slots..
-       "list[context;src;2.75,0.5;1,1;]"..
-       "list[context;fuel;2.75,2.5;1,1;]"..
-       "image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
-       "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
-       "list[context;dst;4.75,0.96;2,2;]"..
-       "list[current_player;main;0,4.25;8,1;]"..
-       "list[current_player;main;0,5.5;8,3;8]"..
-       "listring[context;dst]"..
-       "listring[current_player;main]"..
-       "listring[context;src]"..
-       "listring[current_player;main]"..
-       "listring[context;fuel]"..
-       "listring[current_player;main]"..
-       default.get_hotbar_bg(0, 4.25)
+function default.get_furnace_inactive_formspec()
+       return "size[8,8.5]"..
+               default.gui_bg..
+               default.gui_bg_img..
+               default.gui_slots..
+               "list[context;src;2.75,0.5;1,1;]"..
+               "list[context;fuel;2.75,2.5;1,1;]"..
+               "image[2.75,1.5;1,1;default_furnace_fire_bg.png]"..
+               "image[3.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
+               "list[context;dst;4.75,0.96;2,2;]"..
+               "list[current_player;main;0,4.25;8,1;]"..
+               "list[current_player;main;0,5.5;8,3;8]"..
+               "listring[context;dst]"..
+               "listring[current_player;main]"..
+               "listring[context;src]"..
+               "listring[current_player;main]"..
+               "listring[context;fuel]"..
+               "listring[current_player;main]"..
+               default.get_hotbar_bg(0, 4.25)
+end
 
 --
 -- Node callback functions that are the same for active and inactive furnace
@@ -190,7 +189,7 @@ local function furnace_node_timer(pos, elapsed)
        --
        -- Update formspec, infotext and node
        --
-       local formspec = inactive_formspec
+       local formspec
        local item_state
        local item_percent = 0
        if cookable then
@@ -216,7 +215,7 @@ local function furnace_node_timer(pos, elapsed)
                active = "active "
                local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100)
                fuel_state = fuel_percent .. "%"
-               formspec = active_formspec(fuel_percent, item_percent)
+               formspec = default.get_furnace_active_formspec(fuel_percent, item_percent)
                swap_node(pos, "default:furnace_active")
                -- make sure timer restarts automatically
                result = true
@@ -224,12 +223,14 @@ local function furnace_node_timer(pos, elapsed)
                if not fuellist[1]:is_empty() then
                        fuel_state = "0%"
                end
+               formspec = default.get_furnace_inactive_formspec()
                swap_node(pos, "default:furnace")
                -- stop timer on the inactive furnace
                minetest.get_node_timer(pos):stop()
        end
 
-       local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")"
+       local infotext = "Furnace " .. active .. "(Item: " .. item_state ..
+               "; Fuel: " .. fuel_state .. ")"
 
        --
        -- Set meta values
@@ -266,7 +267,7 @@ minetest.register_node("default:furnace", {
 
        on_construct = function(pos)
                local meta = minetest.get_meta(pos)
-               meta:set_string("formspec", inactive_formspec)
+               meta:set_string("formspec", default.get_furnace_inactive_formspec())
                local inv = meta:get_inventory()
                inv:set_size('src', 1)
                inv:set_size('fuel', 1)
@@ -327,4 +328,3 @@ minetest.register_node("default:furnace_active", {
        allow_metadata_inventory_move = allow_metadata_inventory_move,
        allow_metadata_inventory_take = allow_metadata_inventory_take,
 })
-
index f7826e3f100b73f7fed3bfc3ccf866beafdaf6f3..c90c8dc42c8b3227d3d8e20f98fe17e1ea9b450f 100644 (file)
@@ -1766,7 +1766,7 @@ minetest.register_node("default:lava_flowing", {
 -- Tools / "Advanced" crafting / Non-"natural"
 --
 
-local function get_chest_formspec(pos)
+function default.get_chest_formspec(pos)
        local spos = pos.x .. "," .. pos.y .. "," .. pos.z
        local formspec =
                "size[8,9]" ..
@@ -1890,7 +1890,7 @@ function default.register_chest(name, d)
                        end
                        minetest.after(0.2, minetest.show_formspec,
                                        clicker:get_player_name(),
-                                       "default:chest", get_chest_formspec(pos))
+                                       "default:chest", default.get_chest_formspec(pos))
                        open_chests[clicker:get_player_name()] = { pos = pos,
                                        sound = def.sound_close, swap = name }
                end
@@ -1912,7 +1912,7 @@ function default.register_chest(name, d)
                        minetest.show_formspec(
                                player:get_player_name(),
                                "default:chest_locked",
-                               get_chest_formspec(pos)
+                               default.get_chest_formspec(pos)
                        )
                end
                def.on_skeleton_key_use = function(pos, player, newsecret)
@@ -1957,7 +1957,7 @@ function default.register_chest(name, d)
                        end
                        minetest.after(0.2, minetest.show_formspec,
                                        clicker:get_player_name(),
-                                       "default:chest", get_chest_formspec(pos))
+                                       "default:chest", default.get_chest_formspec(pos))
                        open_chests[clicker:get_player_name()] = { pos = pos,
                                        sound = def.sound_close, swap = name }
                end