Skip to main content

Extending ct.js' gameplay loop with injections

July 30, 2020

Extending ct.js' gameplay loop with injections

Injections are a powerful instrument to extend functionality of ct.js framework beyond adding methods or properties. It allows you to add logic to a game loop, load resources, create bundled Templates, etc.

The injections folder inside your module's directory accepts files with code that will be injected while exporting a game. All of them are optional, and here is a list of all the possible injections:

General events:

Room-specific events:

Copy-specific events:

Templating and utilities:

Also see Call order with mod's injections for a more complete picture of call order.

Templating

Each injection can substitute a special label with a value from your settings. If you defined a setting field with a key enableSockets, then all matches with /*%enableSockets%*/ in js, css, and html files will be replaced with user's chosen value.

Be wary, as a field may return an empty value. In JavaScript, you may use this wrapper to safely read a variable without breaking syntax: [/*%enableSockets%*/][0]. This will return either the defined value or undefined.

Tips

Templating is also supported in your index.js file.