2020-08-15 22:32:55 +02:00
|
|
|
import { globalConfig } from "../core/config";
|
2020-05-09 16:45:23 +02:00
|
|
|
import { DrawParameters } from "../core/draw_parameters";
|
2020-06-27 10:38:11 +02:00
|
|
|
import { BasicSerializableObject } from "../savegame/serialization";
|
|
|
|
|
2020-08-15 18:39:08 +02:00
|
|
|
/** @type {ItemType[]} **/
|
|
|
|
export const itemTypes = ["shape", "color", "boolean"];
|
2020-05-09 16:45:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for items on belts etc. Not an entity for performance reasons
|
|
|
|
*/
|
|
|
|
export class BaseItem extends BasicSerializableObject {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
static getId() {
|
|
|
|
return "base_item";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @returns {object} */
|
|
|
|
static getSchema() {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-08-15 18:39:08 +02:00
|
|
|
/** @returns {ItemType} **/
|
2020-06-27 10:38:11 +02:00
|
|
|
getItemType() {
|
|
|
|
abstract;
|
2020-08-15 18:39:08 +02:00
|
|
|
return "shape";
|
2020-06-27 10:38:11 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 19:23:00 +02:00
|
|
|
/**
|
|
|
|
* Returns if the item equals the other itme
|
|
|
|
* @param {BaseItem} other
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
equals(other) {
|
|
|
|
if (this.getItemType() !== other.getItemType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.equalsImpl(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override for custom comparison
|
|
|
|
* @abstract
|
|
|
|
* @param {BaseItem} other
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
equalsImpl(other) {
|
|
|
|
abstract;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-09 16:45:23 +02:00
|
|
|
/**
|
|
|
|
* Draws the item at the given position
|
|
|
|
* @param {number} x
|
|
|
|
* @param {number} y
|
|
|
|
* @param {DrawParameters} parameters
|
2020-08-15 19:43:03 +02:00
|
|
|
* @param {number=} diameter
|
2020-05-09 16:45:23 +02:00
|
|
|
*/
|
2020-08-15 22:32:55 +02:00
|
|
|
drawItemCenteredClipped(x, y, parameters, diameter = globalConfig.defaultItemDiameter) {
|
|
|
|
if (parameters.visibleRect.containsCircle(x, y, diameter / 2)) {
|
|
|
|
this.drawItemCenteredImpl(x, y, parameters, diameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INTERNAL
|
|
|
|
* @param {number} x
|
|
|
|
* @param {number} y
|
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
* @param {number=} diameter
|
|
|
|
*/
|
|
|
|
drawItemCenteredImpl(x, y, parameters, diameter = globalConfig.defaultItemDiameter) {
|
|
|
|
abstract;
|
|
|
|
}
|
2020-05-09 16:45:23 +02:00
|
|
|
|
|
|
|
getBackgroundColorAsResource() {
|
2020-05-16 09:49:00 +02:00
|
|
|
abstract;
|
2020-05-16 22:45:40 +02:00
|
|
|
return "";
|
2020-05-09 16:45:23 +02:00
|
|
|
}
|
|
|
|
}
|