Merge util with ikea, update .luacheckrc, decruft

master
benrob0329 2022-01-11 17:27:27 -05:00
parent 70e9cb027c
commit c974875a6a
14 changed files with 133 additions and 147 deletions

View File

@ -7,12 +7,12 @@ read_globals = {
"ItemStack",
"PerlinNoise",
"dump",
"mobkit",
"l",
"DEBUG",
"ikea",
"music",
"util",
"schematic",
"mobkit",
"ikea_mapgen",
"ikea_facsimile",
}
read_globals.table = {
@ -26,7 +26,6 @@ read_globals.table = {
read_globals.string = {
fields = {
"insert",
"split",
}
}
@ -37,15 +36,9 @@ read_globals.vector = {
}
}
exclude_files = {"mods/mobkit", "mods/ikea_staff/behaviors2override.lua"}
exclude_files = {"mods/mobkit", "mods/lambda", "mods/ikea_staff/behaviors2override.lua"}
files["mods/util/init.lua"] = {globals = {"util", "schematic"}}
files["mods/util/overrides/table.lua"] = {globals = {"table"}}
files["mods/util/overrides/string.lua"] = {globals = {"string"}}
files["mods/util/overrides/vector.lua"] = {globals = {"vector"}}
files["mods/ikea/init.lua"] = {globals = {"DEBUG", "ikea", "table"}}
files["mods/ikea_mapgen/init.lua"] = {globals = {"ikea_mapgen"}}
files["mods/ikea_facsimile/init.lua"] = {globals = {"ikea_facsimile"}}
files["mods/ikea/init.lua"] = {globals = {"DEBUG"}}
files["mods/ikea/api"] = {globals = {"ikea"}}
files["mods/ikea_staff"] = {globals = {"staff"}}
files["mods/music"] = {globals = {"music"}}

View File

@ -1,29 +1,122 @@
DEBUG = minetest.settings:get_bool("DEBUG") or false
ikea = {}
ikea.opening_time = 7
ikea.closing_time = 23
do -- Misc Utility Stuff --
ikea = {}
ikea.opening_time = 7
ikea.closing_time = 23
function ikea.is_open()
local tod = minetest.get_timeofday()
return tod >= (ikea.opening_time / 24) and tod <= (ikea.closing_time / 24)
function ikea.is_open()
local tod = minetest.get_timeofday()
return tod >= (ikea.opening_time / 24) and tod <= (ikea.closing_time / 24)
end
local registered_on_tod = {}
function ikea.register_on_tod(tod, func)
if (type(tod) == "number") and (type(func) == "function") then
registered_on_tod[tod] = registered_on_tod[tod] or {}
table.insert(registered_on_tod[tod], func)
end
end
local old_tod = 0
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 1 then
local tod = math.floor(minetest.get_timeofday() * 24)
if (tod ~= old_tod) and registered_on_tod[tod] then
for _, v in ipairs(registered_on_tod[tod]) do
v()
end
old_tod = tod
end
timer = 0
end
end)
-- Returns A List Of Nodestrings Filtered By Group
function ikea.get_nodes_by_groups(groups)
groups = groups or {}
local results = {}
for node_name, _ in pairs(minetest.registered_nodes) do
local should_include = true
for group, value in pairs(groups) do
if minetest.get_item_group(node_name, group) ~= value then
should_include = false
end
end
if should_include then
table.insert(results, node_name)
end
end
return results
end
end
minetest.register_node("ikea:error", {
drawtype = "mesh",
mesh = "error.obj",
tiles = {"unknown_node.png^[colorize:#ff0000:255"},
pointable = false,
walkable = false,
})
do -- Nodes --
minetest.register_node("ikea:error", {
drawtype = "mesh",
mesh = "error.obj",
tiles = {"unknown_node.png^[colorize:#ff0000:255"},
pointable = false,
walkable = false,
})
minetest.register_node("ikea:invisible_wall", {
description = "Invisible Node For Collisions (You Hacker!)",
paramtype = "light",
drawtype = "airlike",
walkable = true,
pointable = false,
is_ground_content = true,
sunlight_propagates = true,
})
minetest.register_node("ikea:invisible_wall", {
description = "Invisible Node For Collisions (You Hacker!)",
paramtype = "light",
drawtype = "airlike",
walkable = true,
pointable = false,
is_ground_content = true,
sunlight_propagates = true,
})
end
do -- Extra stdlib functions --
local function half_equals(t1, t2)
for k, v in pairs(t1) do
if t2[k] == nil then
return false
elseif type(v) == "table" then
if (v ~= t1) and (not half_equals(t2[k], v)) then
return false
end
elseif not (t2[k] == v) then
return false
end
end
return true
end
function table.equals(t1, t2)
return half_equals(t1, t2) and half_equals(t2, t1)
end
function table.merge(t1, t2)
for k, v in pairs(t2) do
t1[k] = v
end
end
end
do -- Test table.equals --
local error_message = [[
Function %s does not pass self-test!
Expected results: %s
Test Results: %s
]]
local test_table = {"a", "b", c = false, e = {"f", "g", "h", {"h"}}}
table.insert(test_table, test_table)
local results = table.equals(test_table, test_table)
local error = error_message:format("table.equals", "true", tostring(results))
assert(results, error)
local results2 = not table.equals({a = 1}, {a = 2})
local error2 = error_message:format("table.equals", "false", tostring(results2))
assert(results2, error2)
end

View File

@ -1,2 +1 @@
name = ikea
depends = util, ikea_fx

View File

@ -1 +0,0 @@

View File

@ -1,5 +1,5 @@
-- Power Down Sound --
util.register_on_tod(ikea.closing_time, function()
ikea.register_on_tod(ikea.closing_time, function()
minetest.sound_play({name = "ikea_power_down", gain = 0.15, pitch = 1.0})
end)
@ -97,15 +97,15 @@ do -- Music --
end,
})
util.register_on_tod(ikea.opening_time, function()
ikea.register_on_tod(ikea.opening_time, function()
stop()
play_random_to_all()
end)
util.register_on_tod(12, play_random_to_all)
util.register_on_tod(ikea.closing_time - 2, play_random_to_all)
ikea.register_on_tod(12, play_random_to_all)
ikea.register_on_tod(ikea.closing_time - 2, play_random_to_all)
util.register_on_tod(ikea.closing_time, function()
ikea.register_on_tod(ikea.closing_time, function()
stop()
end)
end

View File

@ -26,7 +26,7 @@ minetest.register_node("ikea_facsimile:container", {
})
minetest.register_on_mods_loaded(function()
for _, name in ipairs(util.get_nodes_by_groups({facsimile = 1})) do
for _, name in ipairs(ikea.get_nodes_by_groups({facsimile = 1})) do
local def = minetest.registered_nodes[name]
local fax_name = string.format("ikea_facsimile:%s__%s", name:match("([A-z_]+):([A-z_]+)"))
ikea_facsimile.facsimiles[name] = fax_name

View File

@ -64,7 +64,7 @@ minetest.register_globalstep(function(dtime)
-- Satus Vignette --
if (not data.hp_last) or (hp ~= data.hp_last) then
vign_texture = "(ikea_player_vignette.png^[multiply:#5c3d41)^[opacity:" .. tostring((1 - (hp / props.hp_max)) * 255)
local vign_texture = "(ikea_player_vignette.png^[multiply:#5c3d41)^[opacity:" .. tostring((1 - (hp / props.hp_max)) * 255)
if not data.vign_id then
error("Player Vignette ID Not Set!")

View File

@ -110,7 +110,7 @@ ikea_mapgen.register_department({
local groups = {ikea_furniture = 1}
groups[v.type] = 1
groups[room_name] = 1
local applicable_furniture = util.get_nodes_by_groups(groups)
local applicable_furniture = ikea.get_nodes_by_groups(groups)
local id = bound_perlin(Perlin, #applicable_furniture, x + x2, 2, z + z2)
local index = va:indexp(vector.add(v.pos, v_new(x2, 1, z2)))

View File

@ -43,7 +43,7 @@ local function do_on_trolley_container_positions(pos, param2, func)
end
end
trolley_box = {
local trolley_box = {
type = "fixed",
fixed = {
{-0.5, -0.250543, -0.5, 1.5, -0.500882, 3.5},

View File

@ -22,7 +22,6 @@ local Perlin = PerlinNoise({
})
-- Content IDs
local c_air = get_content_id("air")
local c_iw = get_content_id("ikea:invisible_wall")
local c_floor = get_content_id("ikea_warehouse:floor")
local c_rack = get_content_id("ikea_warehouse:rack")
@ -33,7 +32,7 @@ local c_sign = get_content_id("ikea_warehouse:row_sign")
-- We need to find these after everything else has been registered
local applicable_furniture, c_box
minetest.after(0, function()
applicable_furniture = util.get_nodes_by_groups({spawn_on_rack = 1})
applicable_furniture = ikea.get_nodes_by_groups({spawn_on_rack = 1})
c_box = get_content_id(ikea_facsimile.facsimiles["ikea_warehouse:box"])
end)

View File

@ -1,53 +0,0 @@
util = {}
local modpath = minetest.get_modpath("util") .. "/"
dofile(modpath .. "overrides/table.lua")
dofile(modpath .. "overrides/string.lua")
dofile(modpath .. "tests.lua")
-- Returns A List Of Nodestrings Filtered By Group
function util.get_nodes_by_groups(groups)
groups = groups or {}
local results = {}
for node_name, _ in pairs(minetest.registered_nodes) do
local should_include = true
for group, value in pairs(groups) do
if minetest.get_item_group(node_name, group) ~= value then
should_include = false
end
end
if should_include then
table.insert(results, node_name)
end
end
return results
end
do
local registered_on_tod = {}
function util.register_on_tod(tod, func)
if (type(tod) == "number") and (type(func) == "function") then
registered_on_tod[tod] = registered_on_tod[tod] or {}
table.insert(registered_on_tod[tod], func)
end
end
local old_tod = 0
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer >= 1 then
local tod = math.floor(minetest.get_timeofday() * 24)
if (tod ~= old_tod) and registered_on_tod[tod] then
for _, v in ipairs(registered_on_tod[tod]) do
v()
end
old_tod = tod
end
timer = 0
end
end)
end

View File

@ -1,3 +0,0 @@
function string:insert(pos, str)
return self:sub(1, pos) .. str .. self:sub(pos + 1)
end

View File

@ -1,24 +0,0 @@
local function half_equals(t1, t2)
for k, v in pairs(t1) do
if t2[k] == nil then
return false
elseif type(v) == "table" then
if (v ~= t1) and (not half_equals(t2[k], v)) then
return false
end
elseif not (t2[k] == v) then
return false
end
end
return true
end
function table.equals(t1, t2)
return half_equals(t1, t2) and half_equals(t2, t1)
end
function table.merge(t1, t2)
for k, v in pairs(t2) do
t1[k] = v
end
end

View File

@ -1,17 +0,0 @@
local error_message = [[
Function %s does not pass self-test!
Expected results: %s
Test Results: %s
]]
do -- table.equals
local test_table = {"a", "b", c = false, e = {"f", "g", "h", {"h"}}}
table.insert(test_table, test_table)
local results = table.equals(test_table, test_table)
local error = error_message:format("table.equals", "true", tostring(results))
assert(results, error)
local results2 = not table.equals({a = 1}, {a = 2})
local error2 = error_message:format("table.equals", "false", tostring(results2))
assert(results2, error2)
end