]> git.lizzy.rs Git - xdecor.git/commitdiff
Small simplifications
authorkilbith <jeanpatrick.guerrero@gmail.com>
Tue, 12 Jan 2016 13:27:13 +0000 (14:27 +0100)
committerkilbith <jeanpatrick.guerrero@gmail.com>
Wed, 13 Jan 2016 17:15:16 +0000 (18:15 +0100)
chess.lua
enchanting.lua
mailbox.lua
worktable.lua

index 2b020948b9a1b558261d0a3ce373e9a8777c9276..5d08f86daebbda0f074c7ef61d2b76fa8f225b5b 100644 (file)
--- a/chess.lua
+++ b/chess.lua
@@ -528,10 +528,10 @@ function realchess.move(pos, from_list, from_index, to_list, to_index, count, pl
 
        if meta:get_string("lastMove") == "black" then
                minetest.chat_send_player(playerWhite, "["..os.date("%H:%M:%S").."] "..
-                               playerName.." has moved a "..pieceFrom:match("%a+:(%a+)")..", it's now your turn.")
+                               playerName.." has moved a "..pieceFrom:match(":(.-)%_")..", it's now your turn.")
        elseif meta:get_string("lastMove") == "white" then
                minetest.chat_send_player(playerBlack, "["..os.date("%H:%M:%S").."] "..
-                               playerName.." has moved a "..pieceFrom:match("%a+:(%a+)")..", it's now your turn.")
+                               playerName.." has moved a "..pieceFrom:match(":(.-)%_")..", it's now your turn.")
        end
 
        if pieceTo:find("king") then
index b6c10a5ff387c82a7c896adc42f1c88221f071c7..3aad80aeddfcf53140cb6d7ed2cc8d3b3e8c6025 100644 (file)
@@ -56,7 +56,7 @@ function enchanting.fields(pos, _, fields)
        local tool = inv:get_stack("tool", 1)
        local mese = inv:get_stack("mese", 1)
        local orig_wear = tool:get_wear()
-       local mod, name = tool:get_name():match("([%w_]+):([%w_]+)")
+       local mod, name = tool:get_name():match("(.*):(.*)")
        local enchanted_tool = mod..":enchanted_"..name.."_"..next(fields)
 
        if mese:get_count() > 0 and minetest.registered_tools[enchanted_tool] then
index 28c459558c73950af3cc8fa75ac9f9c438418c4c..1f99e14b12c2003006f7629743a060c00c541c67 100644 (file)
@@ -77,9 +77,9 @@ xdecor.register("mailbox", {
 local function img_col(stack)
        if not stack then return "" end
        if stack.inventory_image ~= "" then
-               return stack.inventory_image:match("([%w_]+)%.png")..".png"
+               return stack.inventory_image:match("(.*)%.png")..".png"
        else
-               return stack.tiles[1]:match("([%w_]+)%.png")..".png"
+               return stack.tiles[1]:match("(.*)%.png")..".png"
        end
 end
 
@@ -95,7 +95,7 @@ function mailbox.formspec(pos, owner, num)
                                        ","..i..",#FFFFFF,x "..meta:get_string("stack"..i):match("%s(%d+)")..","
 
                                img = img..i.."="..img_col(minetest.registered_items[
-                                       meta:get_string("stack"..i):match("([%w_:]+)")])..","
+                                       meta:get_string("stack"..i):match("(.*)%s")])..","
                        end
                end
 
index 820932f322c5221a70d957ab98a2365049e2a697..10d5aaf21e1fad6d5a99f630a6cc16789acd680d 100644 (file)
@@ -34,8 +34,8 @@ local def = { -- Nodebox name, yield, definition.
 function worktable.get_recipe(item)
        if item:find("^group:") then
                if item:find("wool$") or item:find("dye$") then
-                       item = item:match("[^,:]+$")..":white"
-               elseif minetest.registered_items["default:"..item:match("[^,:]+$")] then
+                       item = item:sub(7)..":white"
+               elseif minetest.registered_items["default:"..item:sub(7)] then
                        item = item:gsub("group:", "default:")
                else
                        for node, definition in pairs(minetest.registered_items) do
@@ -217,7 +217,7 @@ function worktable.fields(pos, _, fields)
        local formspec = meta:to_table().fields.formspec
        local filter = formspec:match("filter;;([%w_:]+)") or ""
        local pagenum = tonumber(formspec:match("#FFFF00,(%d+)")) or 1
-       local tab_id = tonumber(formspec:match("tabheader%[.*;(%d+)%;.*]")) or 1
+       local tab_id = tonumber(formspec:match("tabheader%[.*;(%d+)%;.*%]")) or 1
 
        if fields.back then
                worktable.formspecs.main(meta)
@@ -248,8 +248,7 @@ function worktable.fields(pos, _, fields)
                worktable.craftguide_formspec(meta, pagenum, nil, 1, filter, tab_id)
        else
                for item in pairs(fields) do
-                       if item:match("[%w_]+:[%w_]+") and
-                                       minetest.get_craft_recipe(item).items then
+                       if item:match(".-:") and minetest.get_craft_recipe(item).items then
                                worktable.craftguide_formspec(meta, pagenum, item, 1, filter, tab_id)
                        end
                end
@@ -262,7 +261,7 @@ function worktable.dig(pos)
                inv:is_empty("tool") and inv:is_empty("storage")
 end
 
-function worktable.contains(table, element)
+function worktable.allowed(table, element)
        if table then
                for _, value in pairs(table) do
                        if value == element then
@@ -282,10 +281,10 @@ end
 
 function worktable.put(pos, listname, _, stack)
        local stackname = stack:get_name()
-       local mod, node = stackname:match("([%w_]+):([%w_]+)")
+       local mod, node = stackname:match("(.*):(.*)")
 
        if (listname == "tool" and stack:get_wear() > 0 and stackname ~= "xdecor:hammer") or
-                       (listname == "input" and worktable.contains(nodes[mod], node)) or
+                       (listname == "input" and worktable.allowed(nodes[mod], node)) or
                        (listname == "hammer" and stackname == "xdecor:hammer") or
                        listname == "storage" or listname == "trash" then
                if listname == "trash" then trash_delete(pos) end
@@ -306,9 +305,11 @@ function worktable.take(pos, listname, _, stack, player)
        return stack:get_count()
 end
 
-function worktable.move(pos, from_list, _, to_list, _, count)
-       if (from_list == "storage" and to_list == "storage") or to_list == "trash" then
-               if to_list == "trash" then trash_delete(pos) end
+function worktable.move(pos, _, _, to_list, _, count)
+       if to_list == "storage" then
+               return count
+       elseif to_list == "trash" then
+               trash_delete(pos)
                return count
        end
        return 0