mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-29 13:53:43 +01:00
Minor refactoring
This commit is contained in:
parent
90adfb42c1
commit
e16c23c29c
24
init.lua
24
init.lua
@ -176,26 +176,25 @@ local function table_eq(T1, T2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
avoid_loops[t1] = t2
|
avoid_loops[t1] = t2
|
||||||
local t2keys = {}
|
local t2k, t2kv = {}, {}
|
||||||
local t2tablekeys = {}
|
|
||||||
|
|
||||||
for k in pairs(t2) do
|
for k in pairs(t2) do
|
||||||
if type(k) == "table" then
|
if is_table(k) then
|
||||||
insert(t2tablekeys, k)
|
insert(t2kv, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
t2keys[k] = true
|
t2k[k] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
for k1, v1 in pairs(t1) do
|
for k1, v1 in pairs(t1) do
|
||||||
local v2 = t2[k1]
|
local v2 = t2[k1]
|
||||||
if type(k1) == "table" then
|
if type(k1) == "table" then
|
||||||
local ok
|
local ok
|
||||||
for i = 1, #t2tablekeys do
|
for i = 1, #t2kv do
|
||||||
local tk = t2tablekeys[i]
|
local tk = t2kv[i]
|
||||||
if table_eq(k1, tk) and recurse(v1, t2[tk]) then
|
if table_eq(k1, tk) and recurse(v1, t2[tk]) then
|
||||||
remove(t2tablekeys, i)
|
remove(t2kv, i)
|
||||||
t2keys[tk] = nil
|
t2k[tk] = nil
|
||||||
ok = true
|
ok = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -204,12 +203,12 @@ local function table_eq(T1, T2)
|
|||||||
if not ok then return end
|
if not ok then return end
|
||||||
else
|
else
|
||||||
if v2 == nil then return end
|
if v2 == nil then return end
|
||||||
t2keys[k1] = nil
|
t2k[k1] = nil
|
||||||
if not recurse(v1, v2) then return end
|
if not recurse(v1, v2) then return end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if next(t2keys) then return end
|
if next(t2k) then return end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1174,7 +1173,7 @@ local function handle_drops_table(name, drop)
|
|||||||
local di = drop_items[i]
|
local di = drop_items[i]
|
||||||
|
|
||||||
for j = 1, #di.items do
|
for j = 1, #di.items do
|
||||||
if is_str(di.items[j]) then
|
if not is_str(di.items[j]) then break end
|
||||||
local dname, dcount = match(di.items[j], "(.*)%s*(%d*)")
|
local dname, dcount = match(di.items[j], "(.*)%s*(%d*)")
|
||||||
dcount = dcount and tonumber(dcount) or 1
|
dcount = dcount and tonumber(dcount) or 1
|
||||||
|
|
||||||
@ -1204,7 +1203,6 @@ local function handle_drops_table(name, drop)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
for item, count in pairs(drop_sure) do
|
for item, count in pairs(drop_sure) do
|
||||||
craftguide.register_craft({
|
craftguide.register_craft({
|
||||||
|
Loading…
Reference in New Issue
Block a user