@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
51 lines (43 loc) • 1.1 kB
JavaScript
import { array_pick_best_element } from "../../../core/collection/array/array_pick_best_element.js";
import { CursorType } from "./CursorType.js";
export class CursorCoalescence {
constructor() {
/**
*
* @type {CursorType[]}
*/
this.cursorPriorities = [
CursorType.Normal,
CursorType.Move,
CursorType.Pointer,
CursorType.Attack
];
this.cursors = [];
}
/**
*
* @param {CursorType[]} priorities
*/
setPriorities(priorities) {
this.cursorPriorities = priorities;
}
reset() {
this.cursors.splice(0, this.cursors.length);
}
/**
*
* @param {CursorType} cursor
*/
add(cursor) {
if (this.cursors.indexOf(cursor) === -1) {
this.cursors.push(cursor);
}
}
/**
* @returns {CursorType}
*/
get() {
//pick best
return array_pick_best_element(this.cursors, c => this.cursorPriorities.indexOf(c));
}
}