@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
107 lines (87 loc) • 2.15 kB
JavaScript
import List from "../../../../core/collection/list/List.js";
import { assert } from "../../../../core/assert.js";
import { InputBinding } from "../ism/InputBinding.js";
export class Input {
/**
* @readonly
* @type {List<InputBinding>}
*/
bindings = new List();
/**
*
* @param {Input} other
* @returns {boolean}
*/
equals(other) {
return this.bindings.equals(other.bindings);
}
/**
*
* @return {number}
*/
hash() {
return this.bindings.hash();
}
/**
*
* @param {string} path
* @param {string} event
* @returns {boolean}
*/
exists(path, event) {
assert.isString(path, "path");
assert.isString(event, "event");
const bindings = this.bindings;
const count = bindings.length;
for (let i = 0; i < count; i++) {
const binding = bindings.get(i);
if (binding.path === path && binding.event === event) {
return true;
}
}
return false;
}
/**
*
* @param {string} path
* @param {string} event
* @returns {boolean}
*/
bind(path, event) {
assert.isString(path, "path");
assert.isString(event, "event");
if (this.exists(path, event)) {
//binding exists
return false;
}
const binding = new InputBinding();
binding.set(path, event);
this.bindings.add(binding);
return true;
}
/**
*
* @param {BinaryBuffer} buffer
*/
toBinaryBuffer(buffer) {
this.bindings.toBinaryBuffer(buffer);
}
/**
*
* @param {BinaryBuffer} buffer
*/
fromBinaryBuffer(buffer) {
this.bindings.fromBinaryBuffer(buffer, InputBinding);
}
}
/**
* @readonly
* @type {string}
*/
Input.typeName = "Input";
/**
* @readonly
* @type {boolean}
* TODO make serializable when the rest of the engine is ready for it
*/
Input.serializable = false;