initial commit

This commit is contained in:
achmad
2026-05-29 15:11:31 +07:00
commit 777ee9bad8
1539 changed files with 172449 additions and 0 deletions
@@ -0,0 +1,56 @@
local ____lualib = require("lualib_bundle")
local __TS__ArraySort = ____lualib.__TS__ArraySort
local ____exports = {}
--- Прекеш юнитов по имени (PrecacheUnitByNameAsync) из объединённого npc_units_custom.
-- Вызывать только из GameMode.Precache — иначе движок ругается: «PrecacheResource must be passed a valid precache context».
-- Волны/spawn/event/quest/summons — через #base в npc_units_custom.txt. Герои из npc_heroes_custom сюда не входят.
local LOG_PFX = "[precache_all_npc_units]"
--- Единый источник, как у precache_models_from_kv: движок подмешивает все #base.
local NPC_UNITS_CUSTOM_KV = "scripts/npc/npc_units_custom.txt"
--- Таблица определений юнитов: обычно kv["DOTAUnits"], но LoadKeyValues в части сборок
-- отдаёт те же пары имя→блок сразу в корне (см. admin_menu: перебор верхнего уровня kv).
local function getUnitDefinitionsRoot(self, kv)
local wrapped = kv.DOTAUnits
if wrapped ~= nil and type(wrapped) == "table" then
return wrapped
end
return kv
end
local function collectUnitNamesFromNpcUnitsCustomKv(self, kvPath)
local kv = LoadKeyValues(kvPath)
if kv == nil then
print((LOG_PFX .. " не удалось загрузить ") .. kvPath)
return {}
end
local block = getUnitDefinitionsRoot(nil, kv)
if block == nil then
print((LOG_PFX .. " пустой KV ") .. kvPath)
return {}
end
local names = {}
for key in pairs(block) do
local child = block[key]
if child ~= nil and child ~= nil and type(child) == "table" then
names[#names + 1] = key
end
end
if #names == 0 then
print(((LOG_PFX .. " не найдено ни одного юнита в ") .. kvPath) .. " (ожидан DOTAUnits или плоский корень)")
end
return names
end
--- Имена кастомных юнитов из npc_units_custom.txt (+ #base), без npc_heroes.
function ____exports.getWaveAndSpawnManagerUnitNamesFromKv(self)
local names = collectUnitNamesFromNpcUnitsCustomKv(nil, NPC_UNITS_CUSTOM_KV)
__TS__ArraySort(names)
return names
end
--- Запрашивает прекеш полного набора ресурсов юнита по определению в KV.
function ____exports.precacheAllCustomUnitsByNameAsync(self, context)
local names = ____exports.getWaveAndSpawnManagerUnitNamesFromKv(nil)
print((LOG_PFX .. " PrecacheUnitByNameSync (npc_units_custom + #base) × ") .. tostring(#names))
for ____, name in ipairs(names) do
PrecacheUnitByNameSync(name, context)
end
end
return ____exports