"System mods" vs "Mixins"
Hello there,
Summary: how do people share code across mods?
Here's my example: I'm currently implementing my second mod which has what I call "persistent player attributes"; like "hunger", "mana" or "energy". These should be persisted somewhere when the player logs off / the server is shut down, and restored again as needed. My first mod used a text file in the world directory to save these values. My second mod is using a trick I saw elsewhere: create a new inventory slot, and fill it with up to 65535 units of air. Bingo: persisted numeric attribute (yes, this particular thing also sounds like a core engine request, but that's another topic).
So now I have two mods, maybe more, that share code. I see three approaches to this:
A mixin, in this case, is a separate lua file that gets included in / distributed with each mod, unchanged. Better yet: this file sets up its own global variable, complete with a "version" key, and adds its functionality to the global variable table if the version number is currently lower. In effect, an invisible submodule which can even be updated on the fly by whoever has the most recent version.
My question: does anyone have any thoughts on this? Any experience with this? Any other suggestions? What do other modders do?
Summary: how do people share code across mods?
Here's my example: I'm currently implementing my second mod which has what I call "persistent player attributes"; like "hunger", "mana" or "energy". These should be persisted somewhere when the player logs off / the server is shut down, and restored again as needed. My first mod used a text file in the world directory to save these values. My second mod is using a trick I saw elsewhere: create a new inventory slot, and fill it with up to 65535 units of air. Bingo: persisted numeric attribute (yes, this particular thing also sounds like a core engine request, but that's another topic).
So now I have two mods, maybe more, that share code. I see three approaches to this:
- Copy and paste the code between the two mods.
- Place the shared code in a new "system" mod, and have both mods depend on it.
- Generate what I'm calling a "mixin" (if it already has another name, please let me know).
A mixin, in this case, is a separate lua file that gets included in / distributed with each mod, unchanged. Better yet: this file sets up its own global variable, complete with a "version" key, and adds its functionality to the global variable table if the version number is currently lower. In effect, an invisible submodule which can even be updated on the fly by whoever has the most recent version.
My question: does anyone have any thoughts on this? Any experience with this? Any other suggestions? What do other modders do?