This repository has been archived on 2021-02-20. You can view files and clone it, but cannot push or open issues or pull requests.
shapez.io/src/js/game/base_item.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-05-09 16:45:23 +02:00
import { DrawParameters } from "../core/draw_parameters";
import { BasicSerializableObject } from "../savegame/serialization";
/** @enum {string} */
export const enumItemType = {
shape: "shape",
color: "color",
2020-08-12 21:05:32 +02:00
boolean: "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 {};
}
/** @returns {enumItemType} */
getItemType() {
abstract;
return "";
}
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 19:43:03 +02:00
drawCentered(x, y, parameters, diameter) {}
2020-05-09 16:45:23 +02:00
getBackgroundColorAsResource() {
abstract;
return "";
2020-05-09 16:45:23 +02:00
}
}