Skip to main content

Making your own ct.js modules: directory structure and manifest

July 30, 2020

Making your own ct.js modules: directory structure and manifest

Ct.js is moddable, and the process of making new modules is pretty easy! Modules, or catmods, can put new code into ct.js framework, hack on built-in events and procedures, add new project settings and editable fields for game assets.

Any module is a directory with module.json file inside and any additional files needed for your module to work.

Warning

The name of the directory itself is the codename of your module. For example, if you look into ct.js folder/data/ct.libs, you will see that the codename of ct.place library is just place.

The name should be unique, should have lowercase latin letters and (optionally) dots in it, and must not contain underscores and other special characters, like quotes and commas.

There is also a list of reserved names:

  • core
  • names of the core ct.js library's objects: templates, actions, rooms, inputs, etc.

Ct.js detects a following module structure, placed at ct.js/data/ct.libs:

mycatmod
  |
  |  (Core files)
  |-- index.js
  |-- module.json (required)
  |
  |  (Docs shown in the expanding panel on the right)
  |-- README.md
  |-- docs
      \-- (any number of .md docs)
  |-- CHANGELOG.md
  |-- LICENSE (plain text, strongly recommended)
  |-- types.d.ts (TypeScript declarations for in-editor code completions and type checks)
  |
  |-- includes
  |   \-- (files to be copied to a resulting game)
  |
  \-- injections
      \-- (injections go here)

(more about injections here)

Structure of module.json

module.json is the only required file for your modules. Its minimal version has the following format:

{
    "main": {
        "name": "Module's name",
        "tagline": "A short description of a module",
        "version": "1.0.0",
        "authors": [{
            "name": "Cosmo Myzrail Gorynych",
            "mail": "admin@nersta.ru"
        }, {
            ...
        }]
    }
}

Listing dependencies

Currently, catmods may express their dependency in other module with fields dependencies and optionalDependencies inside module.json. It allows ct.IDE to warn users about missing (disabled) modules. Please write info about getting custom modules in the "readme" section.

{
    "main": {
        "name": "An example module json with dependencies",
        "tagline": "Add dependencies to your modules!",
        "version": "1.0.0",
        "authors": [
            ...
        ]
    },
    "dependencies": ["tween"],
    "optionalDependencies": ["place"]
}

Specifying a category

Modules can specify one or two categories in module.json so that they can be filtered on the project's settings page. Categories are written in an array under the main.categories key, and can be one of these strings:

The first category is also used to create an icon in the bottom-right corner of a module's card:

An example from ct.flow module:

{
    "main": {
        "name": "Flow control and timing",
        "tagline": "Add high-level methods for asynchronous events, e.g. gate, cumulative delay, retriggerable delay.",
        "version": "0.0.0",
        "authors": [{
            "name": "Cosmo Myzrail Gorynych",
            "mail": "admin@nersta.ru"
        }],
        "categories": [
            "utilities"
        ]
    }
}

Writing a mod

Depending on your needs, you will probably need to:

Follow the links to find the examples and references on further implementation.