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)