summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.stylua.toml1
-rw-r--r--BehaviorPacks.lua26
-rw-r--r--BehaviorPacksBanner.pngbin0 -> 1040 bytes
-rw-r--r--BehaviorPacksIcon.pngbin0 -> 268 bytes
-rw-r--r--mod.json20
5 files changed, 47 insertions, 0 deletions
diff --git a/.stylua.toml b/.stylua.toml
new file mode 100644
index 0000000..eb6f5ec
--- /dev/null
+++ b/.stylua.toml
@@ -0,0 +1 @@
+call_parentheses = "NoSingleString"
diff --git a/BehaviorPacks.lua b/BehaviorPacks.lua
new file mode 100644
index 0000000..ba6fac5
--- /dev/null
+++ b/BehaviorPacks.lua
@@ -0,0 +1,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)
diff --git a/BehaviorPacksBanner.png b/BehaviorPacksBanner.png
new file mode 100644
index 0000000..596b86a
--- /dev/null
+++ b/BehaviorPacksBanner.png
Binary files differ
diff --git a/BehaviorPacksIcon.png b/BehaviorPacksIcon.png
new file mode 100644
index 0000000..4421ef6
--- /dev/null
+++ b/BehaviorPacksIcon.png
Binary files differ
diff --git a/mod.json b/mod.json
new file mode 100644
index 0000000..caeb7a9
--- /dev/null
+++ b/mod.json
@@ -0,0 +1,20 @@
+{
+ "namespace": "BehaviorPacks",
+ "displayName": "Behavior Packs",
+ "version": "1.0.0",
+ "synchronyVersion": "4.1.1",
+ "description": "Enables asset mods (also known as legacy mods or resource packs) to alter entity schemas, thus allowing them to alter their behavior. Modifications do not hotload; it will be necessary to trigger an entity schema reload (reloading this mod will suffice).",
+ "author": "TheLegendaryOrb",
+ "dependencies": {},
+ "api": {"scriptPath":""},
+ "icon": "BehaviorPacksIcon.png",
+ "banner": "BehaviorPacksBanner.png",
+ "tags": [],
+ "name": "BehaviorPacks_io_5189325",
+ "changelog": "",
+ "homepageURL": "https://mod.io/g/crypt/m/behaviorpacks",
+ "modioID": "5189325",
+ "modioUserID": 24922981,
+ "pendingVersion": "1.0.0",
+ "visibility": 0
+} \ No newline at end of file