2022-06-14 01:11:20 +02:00
|
|
|
stairsplus.util = {
|
|
|
|
table_set_all = function(t, other_table)
|
|
|
|
for key, value in pairs(other_table) do
|
|
|
|
t[key] = value
|
|
|
|
end
|
|
|
|
return t
|
2022-06-14 20:17:06 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
table_is_empty = function(t)
|
2022-09-22 21:55:29 +02:00
|
|
|
return next(t) == nil
|
2022-06-14 20:17:06 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
table_sort_keys = function(t, sort_function)
|
|
|
|
local sorted = {}
|
|
|
|
for key in pairs(t) do
|
|
|
|
table.insert(sorted, key)
|
|
|
|
end
|
|
|
|
if sort_function then
|
|
|
|
table.sort(sorted, sort_function)
|
|
|
|
else
|
|
|
|
table.sort(sorted)
|
|
|
|
end
|
|
|
|
return sorted
|
2022-06-17 21:22:47 +02:00
|
|
|
end,
|
|
|
|
|
2022-06-19 01:23:11 +02:00
|
|
|
table_equals = function(t1, t2)
|
|
|
|
if t1 == t2 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local tt1 = type(t1)
|
|
|
|
local tt2 = type(t2)
|
|
|
|
|
|
|
|
if tt1 ~= tt2 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if tt1 ~= "table" or tt2 ~= "table" then
|
|
|
|
return t1 == t2
|
|
|
|
end
|
|
|
|
|
|
|
|
for k1, v1 in pairs(t1) do
|
2022-06-19 01:25:47 +02:00
|
|
|
if v1 ~= t2[k1] then
|
2022-06-19 01:23:11 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for k2, v2 in pairs(t2) do
|
2022-06-19 01:25:47 +02:00
|
|
|
if t1[k2] ~= v2 then
|
2022-06-19 01:23:11 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
2022-06-20 00:26:05 +02:00
|
|
|
get_location_string = function(inv)
|
|
|
|
local location = inv:get_location()
|
|
|
|
if location.type == "node" then
|
|
|
|
return ("nodemeta:%i,%i,%i"):format(location.pos.x, location.pos.y, location.pos.z)
|
|
|
|
elseif location.type == "player" then
|
|
|
|
return ("player:%s"):format(location.name)
|
|
|
|
elseif location.type == "detached" then
|
|
|
|
return ("detached:%s"):format(location.name)
|
|
|
|
else
|
|
|
|
error(("unexpected location? %s"):format(dump(location)))
|
|
|
|
end
|
|
|
|
end,
|
2022-06-21 21:22:26 +02:00
|
|
|
|
|
|
|
resolve_aliases = function(node, seen)
|
|
|
|
seen = seen or {}
|
|
|
|
if seen[node] then
|
|
|
|
error(("alias loop on %s"):format(node))
|
|
|
|
end
|
|
|
|
local aliased_to = minetest.registered_aliases[node]
|
|
|
|
if aliased_to then
|
|
|
|
seen[node] = true
|
|
|
|
return stairsplus.util.resolve_aliases(aliased_to, seen)
|
|
|
|
end
|
|
|
|
return node
|
|
|
|
end,
|
2022-06-14 01:11:20 +02:00
|
|
|
}
|