]> git.lizzy.rs Git - xdecor.git/blobdiff - src/mailbox.lua
Global code style cleaning
[xdecor.git] / src / mailbox.lua
index 5c2dcd291df015ab50c0f28f3fbda65ec4ae148d..a3f54245f720c46e6407fde517b0213e92480850 100644 (file)
@@ -2,17 +2,25 @@ local mailbox = {}
 screwdriver = screwdriver or {}
 
 local function get_img(img)
+       if not img then return end
        local img_name = img:match("(.*)%.png")
-       if img_name then return img_name..".png" end
+
+       if img_name then
+               return img_name .. ".png"
+       end
 end
 
 local function img_col(stack)
        local def = minetest.registered_items[stack]
-       if not def then return "" end
+       if not def then
+               return ""
+       end
 
        if def.inventory_image ~= "" then
                local img = get_img(def.inventory_image)
-               if img then return img end
+               if img then
+                       return img
+               end
        end
 
        if def.tiles then
@@ -22,30 +30,34 @@ local function img_col(stack)
                elseif type(tile) == "string" then
                        img = get_img(tile)
                end
-               if img then return img end
+
+               if img then
+                       return img
+               end
        end
 
        return ""
 end
 
 function mailbox:formspec(pos, owner, is_owner)
-       local spos = pos.x..","..pos.y..","..pos.z
+       local spos = pos.x .. "," .. pos.y .. "," .. pos.z
        local meta = minetest.get_meta(pos)
        local giver, img = "", ""
 
        if is_owner then
                for i = 1, 7 do
-                       local giving = meta:get_string("giver"..i)
+                       local giving = meta:get_string("giver" .. i)
                        if giving ~= "" then
-                               local stack = meta:get_string("stack"..i)
+                               local stack = meta:get_string("stack" .. i)
                                local giver_name = giving:sub(1,12)
                                local stack_name = stack:match("[%w_:]+")
                                local stack_count = stack:match("%s(%d+)") or 1
 
-                               giver = giver.."#FFFF00,"..giver_name..","..i..
-                                       ",#FFFFFF,x "..stack_count..","
-                               img = img..i.."="..
-                                       img_col(stack_name).."^\\[resize:16x16,"
+                               giver = giver .. "#FFFF00," .. giver_name .. "," .. i ..
+                                       ",#FFFFFF,x " .. stack_count .. ","
+
+                               img = img .. i .. "=" ..
+                                       img_col(stack_name) .. "^\\[resize:16x16,"
                        end
                end
 
@@ -55,20 +67,21 @@ function mailbox:formspec(pos, owner, is_owner)
                        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]"..
-                       "table[6,0.75;3.3,4;givers;"..giver.."]"..
-                       "list[nodemeta:"..spos..";mailbox;0,0.75;6,4;]"..
-                       "listring[nodemeta:"..spos..";mailbox]"..
-                       xbg..default.get_hotbar_bg(0.75,5.25)
+                       tableoptions[background=#00000000;highlight=#00000000;border=false] ]] ..
+                       "tablecolumns[color;text;image," .. img .. "0;color;text]" ..
+                       "table[6,0.75;3.3,4;givers;" .. giver .. "]" ..
+                       "list[nodemeta:" .. spos .. ";mailbox;0,0.75;6,4;]" ..
+                       "listring[nodemeta:" .. spos .. ";mailbox]" ..
+                       xbg .. default.get_hotbar_bg(0.75, 5.25)
        end
-       return [[ size[8,5]
-               list[current_player;main;0,1.25;8,4;] ]]..
-               "label[0,0;Send your goods to\n"..
+
+       return  "size[8,5]" ..
+               "list[current_player;main;0,1.25;8,4;]" ..
+               "label[0,0;Send your goods to\n" ..
                (minetest.colorize and
-                       minetest.colorize("#FFFF00", owner) or owner).."]"..
-               "list[nodemeta:"..spos..";drop;3.5,0;1,1;]"..
-               xbg..default.get_hotbar_bg(0,1.25)
+                       minetest.colorize("#FFFF00", owner) or owner) .. "]" ..
+               "list[nodemeta:" .. spos .. ";drop;3.5,0;1,1;]" ..
+               xbg .. default.get_hotbar_bg(0, 1.25)
 end
 
 function mailbox.dig(pos, player)
@@ -85,10 +98,10 @@ function mailbox.after_place_node(pos, placer)
        local player_name = placer:get_player_name()
 
        meta:set_string("owner", player_name)
-       meta:set_string("infotext", player_name.."'s Mailbox")
+       meta:set_string("infotext", player_name .. "'s Mailbox")
 
        local inv = meta:get_inventory()
-       inv:set_size("mailbox", 6*4)
+       inv:set_size("mailbox", 6 * 4)
        inv:set_size("drop", 1)
 end
 
@@ -97,8 +110,9 @@ function mailbox.rightclick(pos, node, clicker, itemstack, pointed_thing)
        local player = clicker:get_player_name()
        local owner = meta:get_string("owner")
 
-       minetest.show_formspec(player, "xdecor:mailbox", mailbox:formspec(pos,
-                              owner, (player == owner)))
+       minetest.show_formspec(player, "xdecor:mailbox",
+               mailbox:formspec(pos, owner, (player == owner)))
+
        return itemstack
 end
 
@@ -109,9 +123,10 @@ function mailbox.put(pos, listname, _, stack, player)
                        return -1
                else
                        minetest.chat_send_player(player:get_player_name(),
-                                                 "The mailbox is full")
+                               "The mailbox is full")
                end
        end
+
        return 0
 end
 
@@ -124,8 +139,8 @@ function mailbox.on_put(pos, listname, _, stack, player)
                inv:add_item("mailbox", stack)
 
                for i = 7, 2, -1 do
-                       meta:set_string("giver"..i, meta:get_string("giver"..(i-1)))
-                       meta:set_string("stack"..i, meta:get_string("stack"..(i-1)))
+                       meta:set_string("giver" .. i, meta:get_string("giver" .. (i - 1)))
+                       meta:set_string("stack" .. i, meta:get_string("stack" .. (i - 1)))
                end
 
                meta:set_string("giver1", player:get_player_name())
@@ -139,6 +154,7 @@ function mailbox.allow_take(pos, listname, index, stack, player)
        if player:get_player_name() ~= meta:get_string("owner") then
                return 0
        end
+
        return stack:get_count()
 end
 
@@ -151,7 +167,7 @@ xdecor.register("mailbox", {
        tiles = {"xdecor_mailbox_top.png", "xdecor_mailbox_bottom.png",
                 "xdecor_mailbox_side.png", "xdecor_mailbox_side.png",
                 "xdecor_mailbox.png", "xdecor_mailbox.png"},
-       groups = {cracky=3, oddly_breakable_by_hand=1},
+       groups = {cracky = 3, oddly_breakable_by_hand = 1},
        on_rotate = screwdriver.rotate_simple,
        can_dig = mailbox.dig,
        on_rightclick = mailbox.rightclick,