]> git.lizzy.rs Git - xdecor.git/commitdiff
Avoid some formspec concatenations
authorjp <jeanpatrick.guerrero@gmail.com>
Wed, 30 Dec 2015 19:08:39 +0000 (20:08 +0100)
committerjp <jeanpatrick.guerrero@gmail.com>
Wed, 30 Dec 2015 20:43:13 +0000 (21:43 +0100)
chess.lua
enchanting.lua
handlers/registration.lua
hive.lua
mailbox.lua
worktable.lua

index 153dced4da66c7d6b79d4f6d2e755ef66e1de803..95a62b1682f248fd2879e5da3ec7f57e51333cd3 100644 (file)
--- a/chess.lua
+++ b/chess.lua
@@ -17,18 +17,17 @@ end
 function realchess.init(pos)
        local meta = minetest.get_meta(pos)
        local inv = meta:get_inventory()
-       local slots = "listcolors[#00000000;#00000000;#00000000;#30434C;#FFF]"
-       local formspec
 
        inv:set_size("board", 64)
-
-       meta:set_string("formspec",
-               "size[8,8.6;]"..
-               "bgcolor[#080808BB;true]"..
-               "background[0,0;8,8;chess_bg.png]"..
-               "button[3.1,7.8;2,2;new;New game]"..
-               "list[context;board;0,0;8,8;]"..
-               slots)
+       
+       local formspec = [[ size[8,8.6;]
+                       bgcolor[#080808BB;true]
+                       background[0,0;8,8;chess_bg.png]
+                       button[3.1,7.8;2,2;new;New game]
+                       list[context;board;0,0;8,8;]
+                       listcolors[#00000000;#00000000;#00000000;#30434C;#FFF] ]]
+
+       meta:set_string("formspec", formspec)
 
        meta:set_string("infotext", "Chess Board")
        meta:set_string("playerBlack", "")
index 4288b2084671b6786fcee7ea45dcbb317965f3e1..c70738d13a32353613b6395aa45ae77d2f362d18 100644 (file)
@@ -15,6 +15,7 @@ function enchanting.formspec(pos, tooltype)
                        tooltip[fast;Your tool digs faster]
                        tooltip[strong;Your armor is more resistant]
                        tooltip[speed;Your speed is increased] ]]
+                       ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
 
        if tooltype == "sword" then
                formspec = formspec.."image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]"
@@ -30,7 +31,7 @@ function enchanting.formspec(pos, tooltype)
                                image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
        end
 
-       meta:set_string("formspec", formspec..default.gui_slots..default.get_hotbar_bg(0.5,4.5))
+       meta:set_string("formspec", formspec)
        return formspec
 end
 
@@ -125,7 +126,7 @@ xdecor.register("enchantment_table", {
        on_receive_fields = enchanting.fields,
        on_metadata_inventory_put = enchanting.on_put,
        allow_metadata_inventory_put = enchanting.put,
-       allow_metadata_inventory_move = function(...) return 0 end,
+       allow_metadata_inventory_move = function() return 0 end,
        on_metadata_inventory_take = function(pos, listname, _, _, _)
                if listname == "tool" then
                        enchanting.formspec(pos, nil)
index efb6608bfa2949b57b48a2329cd4722a35f147d7..b148d356f1f50d2f5d10b11876d2b5fe012792ef 100644 (file)
@@ -9,34 +9,34 @@ local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
 local default_inventory_size = 32
 
 local default_inventory_formspecs = {
-       ["8"] = "size[8,6]"..xbg..
-       "list[context;main;0,0;8,1;]"..
-       "list[current_player;main;0,2;8,4;]"..
-       "listring[current_player;main]"..
-       "listring[context;main]"..
-       default.get_hotbar_bg(0, 2),
-
-       ["16"] = "size[8,7]"..xbg..
-       "list[context;main;0,0;8,2;]"..
-       "list[current_player;main;0,3;8,4;]"..
-       "listring[current_player;main]"..
-       "listring[context;main]"..
-       default.get_hotbar_bg(0, 3),
-
-       ["24"] = "size[8,8]"..xbg..
-       "list[context;main;0,0;8,3;]"..
-       "list[current_player;main;0,4;8,4;]"..
-       "listring[current_player;main]"..
-       "listring[context;main]"..
-       default.get_hotbar_bg(0, 4),
-
-       ["32"] = "size[8,9]"..xbg..
-       "list[context;main;0,0.3;8,4;]"..
-       "list[current_player;main;0,4.85;8,1;]"..
-       "list[current_player;main;0,6.08;8,3;8]"..
-       "listring[current_player;main]"..
-       "listring[context;main]"..
-       default.get_hotbar_bg(0, 4.85)
+       ["8"] = [[ size[8,6]
+               list[context;main;0,0;8,1;]
+               list[current_player;main;0,2;8,4;]
+               listring[current_player;main]
+               listring[context;main] ]] ..
+               xbg..default.get_hotbar_bg(0,2),
+
+       ["16"] = [[ size[8,7]
+               list[context;main;0,0;8,2;]
+               list[current_player;main;0,3;8,4;]
+               listring[current_player;main]
+               listring[context;main] ]] ..
+               xbg..default.get_hotbar_bg(0,3),
+
+       ["24"] = [[ size[8,8]
+               list[context;main;0,0;8,3;]
+               list[current_player;main;0,4;8,4;]
+               listring[current_player;main]
+               listring[context;main]" ]] ..
+               xbg..default.get_hotbar_bg(0,4),
+
+       ["32"] = [[ size[8,9]
+               list[context;main;0,0.3;8,4;]
+               list[current_player;main;0,4.85;8,1;]
+               list[current_player;main;0,6.08;8,3;8]
+               listring[current_player;main]
+               listring[context;main] ]] ..
+               xbg..default.get_hotbar_bg(0,4.85)
 }
 
 local function get_formspec_by_size(size)
@@ -45,7 +45,6 @@ local function get_formspec_by_size(size)
 end
 
 local function drop_stuff() -- thanks to LNJplus for this function
-       local random = math.random
        return function(pos, oldnode, oldmetadata, digger)
                local meta = minetest.get_meta(pos)
                meta:from_table(oldmetadata)
@@ -55,9 +54,10 @@ local function drop_stuff() -- thanks to LNJplus for this function
                        local stack = inv:get_stack("main", i)
                        if not stack:is_empty() then
                                local p = {
-                                       x = pos.x + random(0,5) / 5 - 0.5,
+                                       x = pos.x + math.random(0,5) / 5 - 0.5,
                                        y = pos.y,
-                                       z = pos.z + random(0,5) / 5 - 0.5}
+                                       z = pos.z + math.random(0,5) / 5 - 0.5
+                               }
                                minetest.add_item(p, stack)
                        end
                end
index 2bb12ed7389d0ba29cd5c4f20ddf9d088e156297..b7b374555f1f8f634294473a9c358849a6cac57e 100644 (file)
--- a/hive.lua
+++ b/hive.lua
@@ -5,14 +5,15 @@ function hive.construct(pos)
        local inv = meta:get_inventory()
        local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots..default.get_hotbar_bg(0,1.35)
 
-       local formspec = "size[8,5;]"..xbg..
-                       "label[1.35,0;Bees are making honey\nwith pollen around...]"..
-                       "image[6,0;1,1;hive_bee.png]"..
-                       "image[5,0;1,1;hive_layout.png]"..
-                       "list[context;honey;5,0;1,1;]"..
-                       "list[current_player;main;0,1.35;8,4;]"
-
-       meta:set_string("formspec", formspec)
+       local formspec = [[ size[8,5;]
+                       label[1.35,0;Bees are making honey]
+                       label[1.35,0.5;with pollen around...]
+                       image[6,0;1,1;hive_bee.png]
+                       image[5,0;1,1;hive_layout.png]
+                       list[context;honey;5,0;1,1;]
+                       list[current_player;main;0,1.35;8,4;] ]]
+
+       meta:set_string("formspec", formspec..xbg)
        meta:set_string("infotext", "Artificial Hive")
        inv:set_size("honey", 1)
 end
@@ -40,7 +41,7 @@ xdecor.register("hive", {
                local health = clicker:get_hp()
                clicker:set_hp(health - 1)
        end,
-       allow_metadata_inventory_put = function(...) return 0 end
+       allow_metadata_inventory_put = function() return 0 end
 })
 
 minetest.register_abm({
index 2897bccbb886a3b44fcea8fa91581de15fd90582..fdc63c7bfa7b5f1968a42a011d3ea0807f344f65 100644 (file)
@@ -100,26 +100,26 @@ function mailbox.formspec(pos, owner, num)
                        end
                end
 
-               return "size[9.5,9]"..xbg..
-                       default.get_hotbar_bg(0.75,5.25)..
-                       "label[0,0;Mailbox]"..
-                       "label[6,0;Last donators]"..
-                       "box[6,0.72;3.3,3.5;#555555]"..
+               return [[ size[9.5,9]
+                       label[0,0;Mailbox]
+                       label[6,0;Last donators]
+                       box[6,0.72;3.3,3.5;#555555]
+                       listring[current_player;main]
+                       list[current_player;main;0.75,5.25;8,4;]
+                       tableoptions[background=#00000000;highlight=#00000000;border=false] ]]..
                        "tablecolumns[color;text;image,"..img.."0;color;text]"..
-                       "tableoptions[background=#00000000;highlight=#00000000;border=false]"..
                        "table[6,0.75;3.3,4;givers;"..giver.."]"..
                        "list[nodemeta:"..spos..";mailbox;0,0.75;6,4;]"..
-                       "list[current_player;main;0.75,5.25;8,4;]"..
                        "listring[nodemeta:"..spos..";mailbox]"..
-                       "listring[current_player;main]"
+                       xbg..default.get_hotbar_bg(0.75,5.25)
        else
-               return "size[8,5]"..xbg..
-                       default.get_hotbar_bg(0,1.25)..
-                       "tablecolumns[color;text;color;text]"..
-                       "tableoptions[background=#00000000;highlight=#00000000;border=false]"..
+               return [[ size[8,5]
+                       list[current_player;main;0,1.25;8,4;]
+                       tablecolumns[color;text;color;text]
+                       tableoptions[background=#00000000;highlight=#00000000;border=false] ]]..
                        "table[0,0;3,1;sendform;#FFFFFF,Send your goods to,,,#FFFF00,"..owner.."]"..
                        "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
-                       "list[current_player;main;0,1.25;8,4;]"
+                       xbg..default.get_hotbar_bg(0,1.25)
        end
 end
 
index 61901b601edb20c75bb9296843692b6a9ce23714..0d119190ae1fba48737985a0aae11f5f384f72cf 100644 (file)
@@ -40,22 +40,22 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
        local inventory_size = #meta:to_table().inventory.inv_items_list
        local pagemax = math.floor((inventory_size - 1) / (8*4) + 1)
 
-       local formspec = "size[8,8;]"..xbg..
+       local formspec = [[ size[8,8;]
+                       list[context;item_craft_input;3,6.3;1,1;]
+                       tablecolumns[color;text;color;text]
+                       tableoptions[background=#00000000;highlight=#00000000;border=false]
+                       button[5.5,0;0.7,1;prev;<]
+                       button[7.3,0;0.7,1;next;>]
+                       button[4,0.2;0.7,0.5;search;?]
+                       button[4.6,0.2;0.7,0.5;clearfilter;X]
+                       button[0,0;1.5,1;backcraft;< Back]
+                       tooltip[search;Search]
+                       tooltip[clearfilter;Reset]
+                       label[3,5.8;Input] ]]..
                        "list[context;inv_items_list;0,1;8,4;"..tostring(start_i).."]"..
-                       "list[context;item_craft_input;3,6.3;1,1;]"..
-                       "tablecolumns[color;text;color;text]"..
-                       "tableoptions[background=#00000000;highlight=#00000000;border=false]"..
                        "table[6.1,0.2;1.1,0.5;pagenum;#FFFF00,"..tostring(math.floor(pagenum))..
                        ",#FFFFFF,/ "..tostring(pagemax).."]"..
-                       "button[5.5,0;0.7,1;prev;<]"..
-                       "button[7.3,0;0.7,1;next;>]"..
-                       "button[4,0.2;0.7,0.5;search;?]"..
-                       "button[4.6,0.2;0.7,0.5;clearfilter;X]"..
-                       "button[0,0;1.5,1;backcraft;< Back]"..
-                       "tooltip[search;Search]"..
-                       "tooltip[clearfilter;Reset]"..
-                       "label[3,5.8;Input]"..
-                       "field[1.8,0.32;2.6,1;filter;;"..filter.."]"
+                       "field[1.8,0.32;2.6,1;filter;;"..filter.."]"..xbg
 
        if stackname then
                local items_num = #minetest.get_all_craft_recipes(stackname)
@@ -70,8 +70,7 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                local stack_count = stack_output:match("%s(%d+)")
 
                if items_num > 1 then
-                       formspec = formspec..
-                                       "button[0,5.7;1.6,1;alternate;Alternate]"..
+                       formspec = formspec.."button[0,5.7;1.6,1;alternate;Alternate]"..
                                        "label[0,5.2;Recipe "..recipe_num.." of "..items_num.."]"
                end
 
@@ -112,17 +111,16 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                        end
                elseif stack_width == 3 then
                        if stack_type == "cooking" then
-                               formspec = formspec.."list[context;craft_output_recipe;5,6.3;1,1;]"..
-                                               "image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png]"
+                               formspec = formspec..[[ list[context;craft_output_recipe;5,6.3;1,1;]
+                                                       image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png] ]]
                                inv:set_size("craft_output_recipe", 1)
                        else
                                formspec = formspec.."list[context;craft_output_recipe;5,5.3;3,3;]"
                                inv:set_size("craft_output_recipe", 3*3)
                        end
                elseif stack_type == "cooking" and stack_width > 3 then
-                       formspec = formspec..
-                                       "list[context;craft_output_recipe;5,6.3;1,1;]"..
-                                       "image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png]"
+                       formspec = formspec..[[ list[context;craft_output_recipe;5,6.3;1,1;]
+                                               image[4.25,5.9;0.5,0.5;default_furnace_fire_fg.png] ]]
 
                        inv:set_size("craft_output_recipe", 1)
                end
@@ -160,12 +158,12 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                                                def = def:gsub("group", "default")
                                        else
                                                for node, definition in pairs(minetest.registered_items) do
-                                                       for group in pairs(definition.groups) do
-                                                               if group == def:match("^group:([%w_]+)$") then
-                                                                       inv:set_stack("craft_output_recipe", k, node)
-                                                               end
+                                               for group in pairs(definition.groups) do
+                                                       if def:match("^group:"..group.."$") then
+                                                               inv:set_stack("craft_output_recipe", k, node)
                                                        end
                                                end
+                                               end
                                        end
                                end
                        end
@@ -175,10 +173,9 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
                        end
                end
 
-               formspec = formspec..
-                               "image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
-                               "button[0,6.5;1.6,1;trash;Clear]"..
-                               "label[0,7.5;"..stackname:sub(1,30).."]"
+               formspec = formspec..[[ image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]
+                                       button[0,6.5;1.6,1;trash;Clear] ]]..
+                                       "label[0,7.5;"..stackname:sub(1,30).."]"
        end
 
        meta:set_string("formspec", formspec)
@@ -214,8 +211,9 @@ function worktable.crafting(pos)
                        list[current_player;craftpreview;6,1;1,1;]
                        listring[current_player;main]
                        listring[current_player;craft] ]]
+                       ..xbg..default.get_hotbar_bg(0,3.3)
 
-       meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.3))
+       meta:set_string("formspec", formspec)
 end
 
 function worktable.storage(pos)
@@ -226,8 +224,9 @@ function worktable.storage(pos)
                        listring[context;storage]
                        listring[current_player;main]
                        button[0,0;1.5,1;back;< Back] ]]
+                       ..xbg..default.get_hotbar_bg(0,3.25)
 
-       meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.25))
+       meta:set_string("formspec", formspec)
 end
 
 function worktable.main(pos)
@@ -248,8 +247,9 @@ function worktable.main(pos)
                        list[current_player;main;0,3.25;8,4;]
                        button[0,0;2,1;craft;Crafting]
                        button[2,0;2,1;storage;Storage] ]]
+                       ..xbg..default.get_hotbar_bg(0,3.25)
 
-       meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.25))
+       meta:set_string("formspec", formspec)
 end
 
 function worktable.construct(pos)