blob: ba6fac52f387d78ab0ad66f84c4c1c1bb0207635 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
local GameMod = require "necro.game.data.resource.GameMod"
local FileIO = require "system.game.FileIO"
local JSON = require "system.utils.serial.JSON"
local Utilities = require "system.utils.Utilities"
event.entitySchemaLoadEntity.add("useModData", { order = "overrides", sequence = 1 }, function(ev)
for _, mod in pairs(GameMod.listLoadedAssetMods()) do
local modPath = GameMod.getAssetModPath(mod)
-- only files with certain extensions are loaded as resources, and only
-- files loaded as resources can be accessed with FileIO
local schemaFile = modPath .. "/schema/" .. ev.entity.name .. ".txt"
if FileIO.exists(schemaFile) then
local data = JSON.decode(FileIO.readFileToString(schemaFile))
-- Most EntitySchema events define ev.merge, but apparently entitySchemaLoadEntity
-- does not.
--
-- TODO: Sometimes one may want to merge recursively, such as to edit just some
-- fields of a component, but other times, like when editing animations, it may
-- be desired to overwrite values (the regular mergeTables may be sufficient).
-- Introducing more complex syntax (possibly but not necessarily expressed in
-- JSON) could enable dictating these differing needs.
Utilities.mergeTables(ev.entity, data)
end
end
end)
|