Refactor AgentTracker and related modules to improve agent management and logging

This commit is contained in:
2025-05-18 11:16:13 +02:00
parent eab562b36d
commit e3eefadb75
7 changed files with 166 additions and 144 deletions

View File

@@ -2,13 +2,16 @@ local _, shared = ...
---@cast shared HeimdallShared
local ModuleName = "StinkyTracker"
---@class Stinky
---@field name string
---@field class string
---@field seenAt number
---@field hostile boolean
---@class StinkyTrackerData
---@field stinkies ReactiveValue<table<string, Stinky>>
---@field ignored ReactiveValue<table<string, number>>
---@class StinkyTracker
shared.StinkyTracker = {
---@param stinky Stinky
@@ -68,6 +71,20 @@ shared.StinkyTracker = {
return true
end,
---@param callback fun(stinkies: table<string, Stinky>)
---@return nil
OnChange = function(callback) shared.stinkyTracker.stinkies:onChange(callback) end,
---@param callback fun(name: string, stinky: Stinky)
---@return nil
ForEach = function(callback)
---@type table<string, Stinky>
local stinkies = shared.stinkyTracker.stinkies:get()
for name, stinky in pairs(stinkies) do
callback(name, stinky)
end
end,
Init = function()
shared.stinkyTracker = {
stinkies = ReactiveValue.new({}),
@@ -273,7 +290,7 @@ shared.StinkyTracker = {
end
for name, stinky in pairs(shared.stinkyTracker.stinkies) do
if Heimdall_Data.config.agents[name] then
if shared.AgentTracker.IsAgent(name) then
shared.stinkyTracker.stinkies[name] = nil
if Heimdall_Data.config.stinkyTracker.debug then
print(string.format("[%s] Removed agent from stinkies: %s", ModuleName, name))