|
| 1 | +# Construct Addon Wizard (CAW) Framework |
| 2 | + |
| 3 | +This is a build framework for creating Construct 3 addons (plugins and behaviors). It handles code bundling, ACE (Actions, Conditions, Expressions) generation, localization, and packaging. |
| 4 | + |
| 5 | +## Critical Rules |
| 6 | + |
| 7 | +**DO NOT MODIFY FILES IN THE `build/` OR `template/` FOLDERS** - These contain the build system internals and modifying them will likely break the addon build process. |
| 8 | + |
| 9 | +**CHECK FOR DEV SERVER BEFORE BUILDING** - If the file `.dev-server-running` exists in the project root, the dev server is already running and will automatically rebuild when files change. You don't need to run `npm run build` to verify changes - just save the file and the dev server will rebuild and show any errors in its terminal output. |
| 10 | + |
| 11 | +## Quick Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +npm run build # Build the addon for production |
| 15 | +npm run dev # Start dev server with hot reload |
| 16 | +``` |
| 17 | + |
| 18 | +## Project Structure |
| 19 | + |
| 20 | +``` |
| 21 | +config.caw.js # Main addon configuration (ID, name, type, properties) |
| 22 | +buildconfig.js # Build system settings (cleanup, warnings, terser validation) |
| 23 | +devConfig.js # Dev server settings (port) |
| 24 | +version.js # Addon version number |
| 25 | +
|
| 26 | +src/ |
| 27 | +├── aces.js # Alternative: Define ACEs in a single file |
| 28 | +├── aces/ # ACE definitions (Actions, Conditions, Expressions) |
| 29 | +│ └── [CategoryName]/ |
| 30 | +│ ├── a.ActionName.js # Action (prefix: a. or act.) |
| 31 | +│ ├── c.ConditionName.js # Condition (prefix: c. or cnd.) |
| 32 | +│ └── e.ExpressionName.js # Expression (prefix: e. or exp.) |
| 33 | +├── runtime/ |
| 34 | +│ ├── instance.js # Runtime instance class |
| 35 | +│ ├── plugin.js # Runtime plugin class |
| 36 | +│ └── type.js # Runtime type class |
| 37 | +├── editor/ |
| 38 | +│ ├── instance.js # Editor instance class |
| 39 | +│ └── type.js # Editor type class |
| 40 | +└── domside/ |
| 41 | + └── index.js # DOM-side script (if hasDomside: true) |
| 42 | +
|
| 43 | +build/ # DO NOT MODIFY - Build system internals |
| 44 | +template/ # DO NOT MODIFY - Template files |
| 45 | +``` |
| 46 | + |
| 47 | +## Key Files to Edit |
| 48 | + |
| 49 | +### config.caw.js - Main Addon Configuration |
| 50 | + |
| 51 | +```javascript |
| 52 | +import { |
| 53 | + ADDON_TYPE, |
| 54 | + PLUGIN_TYPE, |
| 55 | + PROPERTY_TYPE, |
| 56 | + ADDON_CATEGORY, |
| 57 | +} from "./template/enums.js"; |
| 58 | + |
| 59 | +export const addonType = ADDON_TYPE.PLUGIN; // or ADDON_TYPE.BEHAVIOR |
| 60 | +export const type = PLUGIN_TYPE.OBJECT; // OBJECT, WORLD, or DOM |
| 61 | +export const id = "my_addon"; // Unique addon ID (lowercase, underscores) |
| 62 | +export const name = "My Addon"; // Display name |
| 63 | +export const author = "Your Name"; |
| 64 | +export const description = "Addon description"; |
| 65 | +export const category = ADDON_CATEGORY.GENERAL; |
| 66 | + |
| 67 | +export const properties = [ |
| 68 | + { |
| 69 | + type: PROPERTY_TYPE.INTEGER, |
| 70 | + id: "myProperty", |
| 71 | + name: "My Property", |
| 72 | + desc: "Property description", |
| 73 | + options: { |
| 74 | + initialValue: 0, |
| 75 | + }, |
| 76 | + }, |
| 77 | +]; |
| 78 | +``` |
| 79 | + |
| 80 | +### ACE File Structure |
| 81 | + |
| 82 | +There are **three ways** to organize ACEs: |
| 83 | + |
| 84 | +#### Method 1: Files in Category Folders (Recommended) |
| 85 | + |
| 86 | +``` |
| 87 | +src/aces/ |
| 88 | +└── MyCategoryName/ |
| 89 | + ├── a.MyAction.js # Action |
| 90 | + ├── c.MyCondition.js # Condition |
| 91 | + └── e.MyExpression.js # Expression |
| 92 | +``` |
| 93 | + |
| 94 | +File prefixes: |
| 95 | + |
| 96 | +- Actions: `a.` or `act.` |
| 97 | +- Conditions: `c.` or `cnd.` |
| 98 | +- Expressions: `e.` or `exp.` |
| 99 | + |
| 100 | +#### Method 2: Subfolders for Each Type |
| 101 | + |
| 102 | +``` |
| 103 | +src/aces/ |
| 104 | +└── MyCategoryName/ |
| 105 | + ├── actions/ |
| 106 | + │ └── MyAction.js |
| 107 | + ├── conditions/ |
| 108 | + │ └── MyCondition.js |
| 109 | + └── expressions/ |
| 110 | + └── MyExpression.js |
| 111 | +``` |
| 112 | + |
| 113 | +#### Method 3: Single File (src/aces.js) |
| 114 | + |
| 115 | +```javascript |
| 116 | +import { action, condition, expression } from "../template/aceDefine.js"; |
| 117 | + |
| 118 | +action( |
| 119 | + "CategoryName", |
| 120 | + "ActionId", |
| 121 | + { |
| 122 | + /* config */ |
| 123 | + }, |
| 124 | + function () { |
| 125 | + /* code */ |
| 126 | + } |
| 127 | +); |
| 128 | +condition( |
| 129 | + "CategoryName", |
| 130 | + "ConditionId", |
| 131 | + { |
| 132 | + /* config */ |
| 133 | + }, |
| 134 | + function () { |
| 135 | + /* code */ |
| 136 | + } |
| 137 | +); |
| 138 | +expression( |
| 139 | + "CategoryName", |
| 140 | + "ExpressionId", |
| 141 | + { |
| 142 | + /* config */ |
| 143 | + }, |
| 144 | + function () { |
| 145 | + /* code */ |
| 146 | + } |
| 147 | +); |
| 148 | +``` |
| 149 | + |
| 150 | +## ACE Configuration Examples |
| 151 | + |
| 152 | +### Action |
| 153 | + |
| 154 | +```javascript |
| 155 | +export const config = { |
| 156 | + listName: "Do Something", // Name in action list |
| 157 | + displayText: "Do something with {0}", // Text shown in event sheet ({0} = param) |
| 158 | + description: "Action description", |
| 159 | + isAsync: false, // Set true for async actions |
| 160 | + highlight: false, |
| 161 | + deprecated: false, |
| 162 | + params: [ |
| 163 | + { |
| 164 | + id: "param1", |
| 165 | + name: "Parameter", |
| 166 | + desc: "Parameter description", |
| 167 | + type: "string", // string, number, combo, object, etc. |
| 168 | + initialValue: '"default"', |
| 169 | + }, |
| 170 | + ], |
| 171 | +}; |
| 172 | + |
| 173 | +export const expose = true; // Expose to runtime instance |
| 174 | + |
| 175 | +export default function (param1) { |
| 176 | + // 'this' is the runtime instance |
| 177 | + console.log(param1); |
| 178 | +} |
| 179 | +``` |
| 180 | + |
| 181 | +### Condition |
| 182 | + |
| 183 | +```javascript |
| 184 | +export const config = { |
| 185 | + listName: "Is Something", |
| 186 | + displayText: "Is something {0}", |
| 187 | + description: "Condition description", |
| 188 | + isTrigger: false, // Set true for trigger conditions |
| 189 | + isInvertible: true, |
| 190 | + params: [], |
| 191 | +}; |
| 192 | + |
| 193 | +export const expose = true; |
| 194 | + |
| 195 | +export default function () { |
| 196 | + return true; // Must return boolean |
| 197 | +} |
| 198 | +``` |
| 199 | + |
| 200 | +### Expression |
| 201 | + |
| 202 | +```javascript |
| 203 | +export const config = { |
| 204 | + returnType: "number", // number, string, or any |
| 205 | + description: "Expression description", |
| 206 | + highlight: false, |
| 207 | + deprecated: false, |
| 208 | + params: [], |
| 209 | +}; |
| 210 | + |
| 211 | +export const expose = false; |
| 212 | + |
| 213 | +export default function () { |
| 214 | + return 42; |
| 215 | +} |
| 216 | +``` |
| 217 | + |
| 218 | +## Parameter Types |
| 219 | + |
| 220 | +For actions/conditions: |
| 221 | + |
| 222 | +- `string` - Text input |
| 223 | +- `number` - Numeric input |
| 224 | +- `combo` - Dropdown (requires `items` array) |
| 225 | +- `object` - Object picker |
| 226 | +- `layer` - Layer picker |
| 227 | +- `layout` - Layout picker |
| 228 | +- `keyb` - Keyboard key picker |
| 229 | +- `boolean` - Checkbox |
| 230 | +- `any` - Any expression |
| 231 | + |
| 232 | +For expressions: |
| 233 | + |
| 234 | +- `string`, `number`, `any` |
| 235 | + |
| 236 | +### Combo Parameter Example |
| 237 | + |
| 238 | +```javascript |
| 239 | +{ |
| 240 | + id: "myCombo", |
| 241 | + name: "Option", |
| 242 | + desc: "Select an option", |
| 243 | + type: "combo", |
| 244 | + initialValue: "option1", |
| 245 | + items: [ |
| 246 | + { option1: "First Option" }, |
| 247 | + { option2: "Second Option" }, |
| 248 | + ], |
| 249 | +} |
| 250 | +``` |
| 251 | + |
| 252 | +## Runtime Instance Methods |
| 253 | + |
| 254 | +In `src/runtime/instance.js`, you can: |
| 255 | + |
| 256 | +```javascript |
| 257 | +export default function (parentClass) { |
| 258 | + return class extends parentClass { |
| 259 | + constructor() { |
| 260 | + super(); |
| 261 | + const properties = this._getInitProperties(); |
| 262 | + // Access properties: properties[0], properties[1], etc. |
| 263 | + } |
| 264 | + |
| 265 | + // Trigger a condition |
| 266 | + _trigger(method) { |
| 267 | + super._trigger(self.C3.Plugins[id].Cnds[method]); |
| 268 | + } |
| 269 | + |
| 270 | + // Save/load for savegames |
| 271 | + _saveToJson() { |
| 272 | + return { myData: this.myData }; |
| 273 | + } |
| 274 | + |
| 275 | + _loadFromJson(o) { |
| 276 | + this.myData = o.myData; |
| 277 | + } |
| 278 | + }; |
| 279 | +} |
| 280 | +``` |
| 281 | + |
| 282 | +## Property Types |
| 283 | + |
| 284 | +```javascript |
| 285 | +PROPERTY_TYPE.INTEGER; // Whole number |
| 286 | +PROPERTY_TYPE.FLOAT; // Decimal number |
| 287 | +PROPERTY_TYPE.PERCENT; // 0-1 range shown as 0-100% |
| 288 | +PROPERTY_TYPE.TEXT; // Single line text |
| 289 | +PROPERTY_TYPE.LONGTEXT; // Multi-line text |
| 290 | +PROPERTY_TYPE.CHECK; // Boolean checkbox |
| 291 | +PROPERTY_TYPE.COMBO; // Dropdown |
| 292 | +PROPERTY_TYPE.COLOR; // Color picker [r, g, b] (0-1 range) |
| 293 | +PROPERTY_TYPE.OBJECT; // Object reference |
| 294 | +PROPERTY_TYPE.GROUP; // Property group header |
| 295 | +PROPERTY_TYPE.FONT; // Font picker |
| 296 | +PROPERTY_TYPE.LINK; // Clickable link |
| 297 | +PROPERTY_TYPE.INFO; // Info display |
| 298 | +``` |
| 299 | + |
| 300 | +## Build Configuration (buildconfig.js) |
| 301 | + |
| 302 | +```javascript |
| 303 | +export const cleanup = { |
| 304 | + keepExport: false, // Keep dist/export after build |
| 305 | + keepExportStep: false, // Keep intermediate files |
| 306 | + keepGenerated: false, // Keep generated folder |
| 307 | +}; |
| 308 | + |
| 309 | +export const terserValidation = "error"; // "error", "warning", or "skip" |
| 310 | +export const disableTips = false; |
| 311 | +export const disableWarnings = false; |
| 312 | +``` |
| 313 | + |
| 314 | +## Workflow |
| 315 | + |
| 316 | +1. **Configure addon** in `config.caw.js` |
| 317 | +2. **Create ACEs** in `src/aces/` folders |
| 318 | +3. **Implement runtime logic** in `src/runtime/instance.js` |
| 319 | +4. **Run dev server**: `npm run dev` |
| 320 | +5. **Test in Construct 3** using the localhost URL shown |
| 321 | +6. **Build for release**: `npm run build` |
| 322 | +7. **Find output** at project root: `{id}-{version}.c3addon` |
| 323 | + |
| 324 | +## Common Patterns |
| 325 | + |
| 326 | +### Async Action |
| 327 | + |
| 328 | +```javascript |
| 329 | +export const config = { |
| 330 | + isAsync: true, |
| 331 | + // ... |
| 332 | +}; |
| 333 | + |
| 334 | +export default async function () { |
| 335 | + await someAsyncOperation(); |
| 336 | +} |
| 337 | +``` |
| 338 | + |
| 339 | +### Trigger Condition |
| 340 | + |
| 341 | +```javascript |
| 342 | +export const config = { |
| 343 | + isTrigger: true, |
| 344 | + // ... |
| 345 | +}; |
| 346 | + |
| 347 | +export default function () { |
| 348 | + return true; |
| 349 | +} |
| 350 | + |
| 351 | +// In instance.js, call: this._trigger("ConditionMethodName"); |
| 352 | +``` |
| 353 | + |
| 354 | +### Accessing Other Instances |
| 355 | + |
| 356 | +```javascript |
| 357 | +export default function () { |
| 358 | + const runtime = this._runtime; |
| 359 | + const allInstances = runtime.objects.Sprite.getAllInstances(); |
| 360 | +} |
| 361 | +``` |
| 362 | + |
| 363 | +## Gotchas |
| 364 | + |
| 365 | +1. **Property access in ACEs**: Use `this` to access the runtime instance, not `self` |
| 366 | +2. **Expression returns**: Must match the declared `returnType` |
| 367 | +3. **Combo initial values**: Must match one of the item keys, not display names |
| 368 | +4. **File naming**: Use correct prefixes (`a.`, `c.`, `e.`) or folder structure |
| 369 | +5. **Category names**: Folder names become category IDs (use underscores, not spaces) |
| 370 | +6. **Version**: Edit `version.js` to update addon version |
0 commit comments