@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
108 lines (85 loc) • 1.94 kB
JavaScript
import List from "../../../../core/collection/list/List.js";
import { HighlightDefinition } from "./HighlightDefinition.js";
class Highlight {
/**
*
* @type {List<HighlightDefinition>}
*/
elements = new List();
/**
*
* @param {HighlightDefinition} def
*/
add(def) {
this.elements.add(def);
}
/**
*
* @param {HighlightDefinition} def
* @returns {boolean}
*/
remove(def) {
return this.elements.removeOneOf(def);
}
/**
*
* @returns {HighlightDefinition}
*/
createElement() {
const el = new HighlightDefinition();
this.add(el);
return el;
}
/**
*
* @param {Highlight} other
* @return {boolean}
*/
equals(other) {
if(other === null || other === undefined){
return false;
}
return this.elements.equals(other.elements);
}
/**
*
* @return {number}
*/
hash() {
return this.elements.hash();
}
toJSON() {
return {
elements: this.elements.toJSON()
};
}
fromJSON({ elements = [] }) {
this.elements.fromJSON(elements, HighlightDefinition);
}
/**
*
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} a
*/
static fromOne(r, g, b, a = 1) {
const result = new Highlight();
const el = result.createElement();
el.color.setRGB(r, g, b);
el.opacity = a;
return result;
}
/**
*
* @param json
* @returns {Highlight}
*/
static fromJSON(json) {
const r = new Highlight();
r.fromJSON(json);
return r;
}
}
Highlight.typeName = "Highlight";
export default Highlight;