Mod Structure and Loading - Skirlez/nubbys-forgery GitHub Wiki

Nubby's Forgery has a modular structure. The only two files you really need are mod.json, and a *.meow file called the entrypoint, which is specified in mod.json.

mod.json

{
    "mod_id" : (string),
    
    "display_name" : (string),
    
    "description" : (string),
    "credits" : (array of strings),
    
    // This is an arbitrary version string decided by you
    "version" : (string),

    // This is the target modloader version.
    // The modloader will check this to prevent the case
    // where an older version of the modloader tries to load a newer mod.
    // if this number is higher than the modloader's version, it will refuse to load the mod.
    "target_modloader_version" : (number),

    // Path to the entrypoint code file. This will be the first thing your mod runs.
    "entrypoint_path" : (string path),
    
    // Path to the languages folder
    // These translations will be read from before the entrypoint file is executed
    "translations_path" : (string path),
    
    // Should all code files be compiled when the mod is loaded?
    // If true, the mod will only load if all of them compile without error
    "compile_all_code_on_load" : (boolean)
}

For an example of a filled mod.json, see the example mod.

To avoid having everything in one file, you can execute more of your own files from the entrypoint. See this page.

The loading process

  • Modloader reads mods folder and starts iterating through every mod. For every mod:
  1. mod.json is read
  2. Translations folder is read and loaded into the game
  3. Entrypoint code file is initialized and on_load is called (You then register your items, perks, supervisors, and so on)
  4. If no errors occurred, the mod is now loaded

Gameplay loading/Indexing

Nubby's Number Factory keeps most of its resource data in several large arrays, with each index in each array corresponding to some property of a resource.

For example, the Pants item takes index 0. In the array responding to item descriptions (obj_ItemMGMT.ItemDesc), you will find the Pants description inside index 0 there. (obj_ItemMGMT.ItemDesc[0])

So, when the modloader indexes some resource, it means those arrays are resized to fit a new index, and all the arrays are filled with the resource's data at that new index. Thus, your resource gets integrated into some base game system.

You reach the supervisor screen ->

  • Supervisors are indexed (only data relevant to the selection screen, such as the preview sprite, cost, etc...)

You press GO ->

In an arbitrary and unknown order:

  • Items are indexed
  • Perks are indexed
  • Your supervisor's create event, if it is selected, is ran
  • Your supervisor's gameplay sprites, if it is selected, are indexed

There is no manual "de-indexing" process, as the objects holding these arrays gets destroyed once you abandon/win a game, and in fact only starts existing when you start a game.

Mod unloading

  1. Entrypoint code file's on_unload function is called
  2. All resources belonging to the mod are cleaned up
  3. The mod is no longer loaded