Files
darktide-AutoMark/AutoMark/scripts/mods/AutoMark/utils/utils.lua
T

97 lines
3.3 KiB
Lua

---@class AutoMarkMod:DMFMod
local mod = get_mod("AutoMark")
local mod_settings = mod.settings
local FixedFrame = require("scripts/utilities/fixed_frame")
-- Global Cache
local Managers = Managers
-- Debug Print
function mod:print_debug(...)
if mod_settings.debug_mode then
local n = select("#", ...)
if n == 0 then
return
end
local result = tostring(select(1, ...))
for i = 2, n do
local value = select(i, ...)
result = result .. " " .. tostring(value)
end
mod:echo(result)
end
end
-- Time for Now
function mod:get_main_time()
return Managers.time:time("main")
end
function mod:get_gameplay_time()
return Managers.time:time("gameplay")
end
function mod:get_latest_fixed_time()
return FixedFrame.get_latest_fixed_time()
end
-- Dev utility: dump all current game breeds to a file so mod hard-coded breed tables
-- can be diffed against the live game after updates. Runs once on mod load.
function mod:dump_breeds()
local Breed = require("scripts/utilities/breed")
local Breeds = require("scripts/settings/breed/breeds")
local names = {}
for breed_name, breed_data in pairs(Breeds) do
if type(breed_data) == "table" and (Breed.is_minion(breed_data) or breed_data.is_boss) then
names[#names + 1] = breed_name
end
end
table.sort(names)
local lines = {}
lines[#lines + 1] = "breed dump v1"
for _, breed_name in ipairs(names) do
local breed_data = Breeds[breed_name]
local tags = {}
for tag_name, value in pairs(breed_data.tags or {}) do
if value then
tags[#tags + 1] = tag_name
end
end
table.sort(tags)
local pounce_setting = breed_data.companion_pounce_setting
local pounce_action = pounce_setting and pounce_setting.companion_pounce_action or ""
local passes_filter = Breed.is_minion(breed_data) and breed_data.unit_template_name == "minion" and
breed_data.smart_tag_target_type == "breed" and breed_data.faction_name ~= "imperium"
lines[#lines + 1] = string.format("%s|tpl=%s|tag_type=%s|faction=%s|boss=%s|filter=%s|her=%s|hef=%s|pounce=%s|tags=%s",
breed_name,
tostring(breed_data.unit_template_name),
tostring(breed_data.smart_tag_target_type),
tostring(breed_data.faction_name),
tostring(breed_data.is_boss == true),
tostring(passes_filter),
tostring(breed_data.half_extent_right),
tostring(breed_data.half_extent_forward),
pounce_action,
table.concat(tags, ","))
end
-- the mod sandbox strips the standard io library, go through DMF's engine backup
local path = "./../mods/AutoMark/breed_dump.txt"
local file, err = Mods.lua.io.open(path, "w")
if file then
file:write(table.concat(lines, "\n"))
file:close()
mod:echo("breed dump written:", path)
else
mod:echo("breed dump FAILED:", tostring(err))
end
end
-- never let the dev dump break mod load
local ok, err = pcall(mod.dump_breeds, mod)
if not ok then
mod:echo("breed dump error:", tostring(err))
end