Some cleaning

This commit is contained in:
Jean-Patrick Guerrero
2022-09-04 19:12:57 +02:00
parent 734b09b69f
commit 8afb51dae8
3 changed files with 70 additions and 63 deletions

View File

@ -2,7 +2,7 @@ local replacements = {fuel = {}}
local http = ...
IMPORT("maxn", "copy", "insert", "sort", "match", "sub")
IMPORT("true_str", "is_table", "valid_item", "table_merge", "table_replace", "rcp_eq")
IMPORT("true_str", "is_table", "valid_item", "table_merge", "table_replace", "table_eq")
IMPORT("fmt", "reg_items", "reg_aliases", "reg_nodes", "is_cube", "get_cube", "ItemStack")
IMPORT("is_group", "extract_groups", "item_has_groups", "groups_to_items", "get_group_stereotype")
@ -248,11 +248,7 @@ local old_clear_craft = core.clear_craft
core.clear_craft = function(def)
old_clear_craft(def)
if true_str(def) then
return -- TODO
elseif is_table(def) then
return -- TODO
end
-- TODO: hide in crafting guide
end
local function resolve_aliases(hash)
@ -274,7 +270,7 @@ local function resolve_aliases(hash)
local rcp_new = copy(i3.recipes_cache[newname][j])
rcp_new.output = oldname
if rcp_eq(rcp_old, rcp_new) then
if table_eq(rcp_old, rcp_new) then
similar = true
break
end

View File

@ -216,18 +216,22 @@ local function array_diff(t1, t2)
return diff
end
local function rcp_eq(rcp, rcp2)
if rcp.type ~= rcp2.type then return end
if rcp.width ~= rcp2.width then return end
if #rcp.items ~= #rcp2.items then return end
if rcp.output ~= rcp2.output then return end
local function table_eq(t1, t2)
local ty1, ty2 = type(t1), type(t2)
if ty1 ~= ty2 then return end
for i, item in pairs(rcp.items) do
if item ~= rcp2.items[i] then return end
if ty1 ~= "table" and ty2 ~= "table" then
return t1 == t2
end
for i, item in pairs(rcp2.items) do
if item ~= rcp.items[i] then return end
for k, v in pairs(t1) do
local v2 = t2[k]
if v2 == nil or not table_eq(v, v2) then return end
end
for k, v in pairs(t2) do
local v1 = t1[k]
if v1 == nil or not table_eq(v1, v) then return end
end
return true
@ -764,7 +768,7 @@ local _ = {
is_table = is_table,
table_merge = table_merge,
table_replace = table_replace,
rcp_eq = rcp_eq,
table_eq = table_eq,
array_diff = array_diff,
-- Math