Actions
Overview
Creating a Custom Action
class MyAction extends Monogatari.Action {
// Unique identifier for this action
static id = 'MyAction';
// Match statements starting with 'myaction'
static matchString([action]) {
return action === 'myaction';
}
constructor([myaction, ...args]) {
super();
this.args = args;
}
apply() {
// Do something when the action is executed
console.log('Action applied with args:', this.args);
return Promise.resolve();
}
didApply() {
// Return whether to advance automatically
return Promise.resolve({ advance: true });
}
revert() {
// Undo the action when rolling back
console.log('Action reverted');
return Promise.resolve();
}
didRevert() {
return Promise.resolve({ advance: true, step: true });
}
}Registering an Action
Static Properties
Property
Type
Description
Instance Properties
Property
Type
Description
Matching Methods
matchString
matchObject
Configuration
Complete Example
Related
Last updated
Was this helpful?