UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

103 lines (85 loc) 1.91 kB
import ObservedString from "../../../src/core/model/ObservedString.js"; import ObservedValue from '../../../src/core/model/ObservedValue.js'; import { ToolState } from "./ToolState.js"; class Tool { #state = ToolState.Initial; /** * * @constructor * @property {ObservedValue.<String>} mode */ constructor() { this.name = null; this.mode = new ObservedValue(); this.settings = {}; this.modifiers = { shift: false, alternative: false }; /** * * @type {Engine|null} */ this.engine = null; /** * * @type {Editor|null} */ this.editor = null; /** * * @type {ObservedString} */ this.icon = new ObservedString(""); } /** * * @param {Editor} editor */ updateIcon(editor) { } /** * * @returns {ToolState|number} */ getState() { return this.#state; } isRunning() { return this.#state === ToolState.Running; } /** * Activate the tool and prepare it for usage */ initialize() { this.#state = ToolState.Ready; } /** * Deactivate the tool and remove and influence it may have */ finalize() { this.#state = ToolState.Ready; } /** * Update loop */ update() { } /** * Start usage of the tool. * @example Start painting with a brush */ start() { this.#state = ToolState.Running; } /** * Finish usage of the tool * @example Finish brush stroke */ stop() { this.#state = ToolState.Ready; } handleKeyboardEvent(e) { } } export default Tool;