Skip to main content

Mechanic

Mechanics are YTTT's scripting language commands that are either self contained or call on the game's various modules.

Mechanics in YTTT are split into multiple main functions:

import { Mechanic } from "../components/Mechanic";
class NamedMechanic extends Mechanic {
constructor(game: GameModule) {
super("named", game);
}
trigger(e: string) {
if (e.startsWith(this.name)) return this.parser(e);
return null;
}
parser(e: string) {
return e;
}
action(line?: Line): boolean {
return false;
}
scrub(lineContent: Line): unknown {}
}

The primary functionaltiy of each subcommand in this NamedMechanic are:

trigger() -> "Called in parser.ts to update line_content"
parser() -> "Called by trigger()"
action() -> "Called by game/core.ts to initiate action"
scrub() -> "Called to clean line_content in parser.ts"

Once this named.ts file is created under ./mechanics, the NamedMechcanic class needs to be put in ./config.ts as:

import { NamedMechanic } from "./mechanics/named";
const cMechanics = [NamedMechanic];

As well as Line might need to be updated under typings.d.ts and parser.ts. I'll add that section later, especially because that might need to be cleaned up in the code.