Skip to content

Commit

Permalink
registered item list with unknown node marker
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jan 16, 2024
1 parent ae8f855 commit af9973f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
3 changes: 3 additions & 0 deletions handlers/items.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mtui.register_on_command("get_item_list", function()
return mtui.items
end)
8 changes: 7 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ end

print("[mtui] initializing")
mtui = {
mod_storage = minetest.get_mod_storage(),
url = minetest.settings:get("mtui.url") or "http://127.0.0.1:8080",
key = minetest.settings:get("mtui.key")
key = minetest.settings:get("mtui.key"),
-- map of name to bool (known node)
items = {}
}
assert(mtui.key, "no key found")

Expand All @@ -18,6 +21,7 @@ loadfile(MP.."/bridge_tx.lua")(http)
dofile(MP.."/common.lua")
dofile(MP.."/tan.lua")
dofile(MP.."/stats.lua")
dofile(MP.."/items.lua")
dofile(MP.."/log.lua")
dofile(MP.."/log_file.lua")
dofile(MP.."/log_technic.lua")
Expand All @@ -27,6 +31,7 @@ dofile(MP.."/controls/builtin.lua")
dofile(MP.."/controls/restart_if_empty.lua")

dofile(MP.."/handlers/ping.lua")
dofile(MP.."/handlers/items.lua")
dofile(MP.."/handlers/chat.lua")
dofile(MP.."/handlers/execute_command.lua")
dofile(MP.."/handlers/lua.lua")
Expand Down Expand Up @@ -61,6 +66,7 @@ end
if minetest.get_modpath("mtt") and mtt.enabled then
dofile(MP.."/mtt.lua")
dofile(MP.."/common.spec.lua")
dofile(MP.."/items.spec.lua")
end

if minetest.get_modpath("monitoring") then
Expand Down
42 changes: 42 additions & 0 deletions items.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

local function check_registered_items()
mtui.items = minetest.deserialize(mtui.mod_storage:get_string("registered_items")) or {}

-- assemble node-list from registered lbm's
local lbm_nodes = {}
for _, lbm in ipairs(minetest.registered_lbms) do
if type(lbm.nodenames) == "string" then
-- duh, list as string
lbm_nodes[lbm.nodenames] = true
else
-- proper list, add all regardless if they are a "group:*"
for _, nodename in ipairs(lbm.nodenames) do
lbm_nodes[nodename] = true
end
end
end

-- mark all currently registered items
for name in pairs(minetest.registered_items) do
mtui.items[name] = true
end

-- check for items that don't exist anymore
for name in pairs(mtui.items) do
if not minetest.registered_items[name] and
not minetest.registered_aliases[name] and
not lbm_nodes[name] then
-- item does not exist anymore, mark it as such
mtui.items[name] = false
end
end

-- save current list back
mtui.mod_storage:set_string("registered_items", minetest.serialize(mtui.items))
end

-- execute check after mods loaded and other things are set up
minetest.register_on_mods_loaded(function()
minetest.after(0, check_registered_items)
end)

12 changes: 12 additions & 0 deletions items.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

mtt.register("items", function(callback)
assert(mtui.items)

local count = 0
for _ in pairs(mtui.items) do
count = count + 1
end

assert(count > 0)
callback()
end)

0 comments on commit af9973f

Please sign in to comment.