UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

56 lines (37 loc) 1.4 kB
import { assert } from "../../../../../core/assert.js"; import { compileReactiveExpression } from "../../../../../core/lang/reactive/compileReactiveExpression.js"; import { ActionBehavior } from "../../../../intelligence/behavior/primitive/ActionBehavior.js"; import { Blackboard } from "../../../../intelligence/blackboard/Blackboard.js"; import { AbstractActionDescription } from "./AbstractActionDescription.js"; export class WriteToBlackboardActionDescription extends AbstractActionDescription { /** * * @type {ReactiveExpression} */ expression = null; /** * * @type {string} */ name = ""; execute(actor, dataset, context, system) { const expression = this.expression; const name = this.name; return new ActionBehavior(() => { const blackboard = dataset.getComponent(actor, Blackboard); const value = blackboard.acquire(name, expression.dataType); value.set(expression.evaluate(context)); }); } /** * * @param {string} name * @param {string} value */ fromJSON({ name, value }) { assert.isString(name, 'name'); this.name = name; this.expression = compileReactiveExpression(value); } } WriteToBlackboardActionDescription.prototype.type = "Write";