1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Refactor static map entity component to store building metaclass

This commit is contained in:
tobspr
2020-07-27 17:14:29 +02:00
parent 567db72538
commit bf2eee908f
17 changed files with 307 additions and 166 deletions

View File

@@ -1,4 +1,3 @@
import { Loader } from "../../core/loader";
import { formatItemsPerSecond } from "../../core/utils";
import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
import { SOUNDS } from "../../platform/sound";
@@ -40,6 +39,10 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
return SOUNDS.placeBelt;
}
getSprite() {
return null;
}
/**
* Creates the entity at the given location
* @param {Entity} entity
@@ -88,7 +91,6 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
updateVariants(entity, rotationVariant) {
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
entity.components.ItemEjector.slots[0].direction = arrayBeltVariantToRotation[rotationVariant];
entity.components.StaticMapEntity.spriteKey = null;
}
/**

View File

@@ -28,6 +28,11 @@ export class MetaHubBuilding extends MetaBuilding {
return null;
}
getSprite() {
// We render it ourself
return null;
}
/**
* Creates the entity at the given location
* @param {Entity} entity
@@ -41,9 +46,6 @@ export class MetaHubBuilding extends MetaBuilding {
})
);
// We render the sprite ourself
entity.components.StaticMapEntity.spriteKey = null;
entity.addComponent(new UnremovableComponent());
entity.addComponent(
new ItemAcceptorComponent({

View File

@@ -71,6 +71,10 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
return super.getAvailableVariants(root);
}
/**
* @param {number} rotationVariant
* @param {string} variant
*/
getPreviewSprite(rotationVariant, variant) {
let suffix = "";
if (variant !== defaultBuildingVariant) {
@@ -87,6 +91,10 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
}
}
/**
* @param {number} rotationVariant
* @param {string} variant
*/
getBlueprintSprite(rotationVariant, variant) {
let suffix = "";
if (variant !== defaultBuildingVariant) {
@@ -103,6 +111,14 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
}
}
/**
* @param {number} rotationVariant
* @param {string} variant
*/
getSprite(rotationVariant, variant) {
return this.getPreviewSprite(rotationVariant, variant);
}
/**
* @param {GameRoot} root
*/
@@ -201,10 +217,6 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
*/
updateVariants(entity, rotationVariant, variant) {
entity.components.UndergroundBelt.tier = enumUndergroundBeltVariantToTier[variant];
entity.components.StaticMapEntity.spriteKey = this.getPreviewSprite(
rotationVariant,
variant
).spriteName;
switch (arrayUndergroundRotationVariantToMode[rotationVariant]) {
case enumUndergroundBeltMode.sender: {