mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add underground belt tier 2
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
@include S(border-radius, 2px);
|
||||
@include S(margin-top, 3px);
|
||||
color: #fff;
|
||||
@include PlainText;
|
||||
@include SuperSmallText;
|
||||
@include S(padding, 7px, 10px);
|
||||
@include S(width, 200px);
|
||||
@include S(width, 150px);
|
||||
|
||||
&[data-icon] {
|
||||
@include S(background-position-x, 8px);
|
||||
|
||||
@@ -42,7 +42,7 @@ export const globalConfig = {
|
||||
itemSpacingOnBelts: 0.63,
|
||||
minerSpeedItemsPerSecond: 0, // COMPUTED
|
||||
|
||||
undergroundBeltMaxTiles: 5,
|
||||
undergroundBeltMaxTilesByTier: [5, 8],
|
||||
|
||||
buildingSpeeds: {
|
||||
cutter: 1 / 4,
|
||||
|
||||
@@ -116,7 +116,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
*/
|
||||
updateRotationVariant(entity, rotationVariant) {
|
||||
updateVariants(entity, rotationVariant) {
|
||||
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
|
||||
entity.components.ItemEjector.slots[0].direction = arrayBeltVariantToRotation[rotationVariant];
|
||||
|
||||
@@ -128,9 +128,10 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||
* @param {GameRoot} root
|
||||
* @param {Vector} tile
|
||||
* @param {number} rotation
|
||||
* @param {string} variant
|
||||
* @return {{ rotation: number, rotationVariant: number }}
|
||||
*/
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation) {
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation, variant) {
|
||||
const topDirection = enumAngleToDirection[rotation];
|
||||
const rightDirection = enumAngleToDirection[(rotation + 90) % 360];
|
||||
const bottomDirection = enumAngleToDirection[(rotation + 180) % 360];
|
||||
|
||||
@@ -62,9 +62,10 @@ export class MetaMinerBuilding extends MetaBuilding {
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {*} variant
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
entity.components.Miner.chainable = variant === enumMinerVariants.chainable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,10 @@ export class MetaPainterBuilding extends MetaBuilding {
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
switch (variant) {
|
||||
case defaultBuildingVariant: {
|
||||
entity.components.ItemAcceptor.setSlots([
|
||||
|
||||
@@ -72,9 +72,10 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
switch (variant) {
|
||||
case defaultBuildingVariant: {
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.rotater;
|
||||
|
||||
@@ -90,9 +90,10 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
switch (variant) {
|
||||
case defaultBuildingVariant: {
|
||||
entity.components.ItemAcceptor.setSlots([
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { GameRoot } from "../root";
|
||||
import { globalConfig } from "../../core/config";
|
||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||
@@ -15,6 +15,14 @@ export const arrayUndergroundRotationVariantToMode = [
|
||||
enumUndergroundBeltMode.receiver,
|
||||
];
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumUndergroundBeltVariants = { tier2: "tier2" };
|
||||
|
||||
export const enumUndergroundBeltVariantToTier = {
|
||||
[defaultBuildingVariant]: 0,
|
||||
[enumUndergroundBeltVariants.tier2]: 1,
|
||||
};
|
||||
|
||||
export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
super("underground_belt");
|
||||
@@ -40,23 +48,37 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
||||
return true;
|
||||
}
|
||||
|
||||
getPreviewSprite(rotationVariant) {
|
||||
getAvailableVariants(root) {
|
||||
return [defaultBuildingVariant, enumUndergroundBeltVariants.tier2];
|
||||
}
|
||||
|
||||
getPreviewSprite(rotationVariant, variant) {
|
||||
let suffix = "";
|
||||
if (variant !== defaultBuildingVariant) {
|
||||
suffix = "-" + variant;
|
||||
}
|
||||
|
||||
switch (arrayUndergroundRotationVariantToMode[rotationVariant]) {
|
||||
case enumUndergroundBeltMode.sender:
|
||||
return Loader.getSprite("sprites/buildings/underground_belt_entry.png");
|
||||
return Loader.getSprite("sprites/buildings/underground_belt_entry" + suffix + ".png");
|
||||
case enumUndergroundBeltMode.receiver:
|
||||
return Loader.getSprite("sprites/buildings/underground_belt_exit.png");
|
||||
return Loader.getSprite("sprites/buildings/underground_belt_exit" + suffix + ".png");
|
||||
default:
|
||||
assertAlways(false, "Invalid rotation variant");
|
||||
}
|
||||
}
|
||||
|
||||
getBlueprintSprite(rotationVariant) {
|
||||
getBlueprintSprite(rotationVariant, variant) {
|
||||
let suffix = "";
|
||||
if (variant !== defaultBuildingVariant) {
|
||||
suffix = "-" + variant;
|
||||
}
|
||||
|
||||
switch (arrayUndergroundRotationVariantToMode[rotationVariant]) {
|
||||
case enumUndergroundBeltMode.sender:
|
||||
return Loader.getSprite("sprites/blueprints/underground_belt_entry.png");
|
||||
return Loader.getSprite("sprites/blueprints/underground_belt_entry" + suffix + ".png");
|
||||
case enumUndergroundBeltMode.receiver:
|
||||
return Loader.getSprite("sprites/blueprints/underground_belt_exit.png");
|
||||
return Loader.getSprite("sprites/blueprints/underground_belt_exit" + suffix + ".png");
|
||||
default:
|
||||
assertAlways(false, "Invalid rotation variant");
|
||||
}
|
||||
@@ -93,21 +115,27 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
||||
* @param {GameRoot} root
|
||||
* @param {Vector} tile
|
||||
* @param {number} rotation
|
||||
* @param {string} variant
|
||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
||||
*/
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation) {
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation, variant) {
|
||||
const searchDirection = enumAngleToDirection[rotation];
|
||||
const searchVector = enumDirectionToVector[searchDirection];
|
||||
const tier = enumUndergroundBeltVariantToTier[variant];
|
||||
|
||||
const targetRotation = (rotation + 180) % 360;
|
||||
|
||||
for (let searchOffset = 1; searchOffset <= globalConfig.undergroundBeltMaxTiles; ++searchOffset) {
|
||||
for (
|
||||
let searchOffset = 1;
|
||||
searchOffset <= globalConfig.undergroundBeltMaxTilesByTier[tier];
|
||||
++searchOffset
|
||||
) {
|
||||
tile = tile.addScalars(searchVector.x, searchVector.y);
|
||||
|
||||
const contents = root.map.getTileContent(tile);
|
||||
if (contents) {
|
||||
const undergroundComp = contents.components.UndergroundBelt;
|
||||
if (undergroundComp) {
|
||||
if (undergroundComp && undergroundComp.tier === tier) {
|
||||
const staticComp = contents.components.StaticMapEntity;
|
||||
if (staticComp.rotation === targetRotation) {
|
||||
if (undergroundComp.mode !== enumUndergroundBeltMode.sender) {
|
||||
@@ -132,11 +160,17 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateRotationVariant(entity, rotationVariant) {
|
||||
entity.components.StaticMapEntity.spriteKey = this.getPreviewSprite(rotationVariant).spriteName;
|
||||
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: {
|
||||
|
||||
@@ -26,11 +26,13 @@ export class UndergroundBeltComponent extends Component {
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {enumUndergroundBeltMode=} param0.mode As which type of belt the entity acts
|
||||
* @param {number=} param0.tier
|
||||
*/
|
||||
constructor({ mode = enumUndergroundBeltMode.sender }) {
|
||||
constructor({ mode = enumUndergroundBeltMode.sender, tier = 0 }) {
|
||||
super();
|
||||
|
||||
this.mode = mode;
|
||||
this.tier = tier;
|
||||
|
||||
/**
|
||||
* Used on both receiver and sender.
|
||||
@@ -57,7 +59,7 @@ export class UndergroundBeltComponent extends Component {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.pendingItems.push([item, 1 / beltSpeed]);
|
||||
this.pendingItems.push([item, 0.5 / beltSpeed]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +370,8 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
||||
const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
|
||||
this.root,
|
||||
tile,
|
||||
this.currentBaseRotation
|
||||
this.currentBaseRotation,
|
||||
this.currentVariant.get()
|
||||
);
|
||||
|
||||
if (
|
||||
@@ -437,7 +438,8 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
||||
} = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
|
||||
this.root,
|
||||
tile,
|
||||
this.currentBaseRotation
|
||||
this.currentBaseRotation,
|
||||
this.currentVariant.get()
|
||||
);
|
||||
|
||||
// Check if there are connected entities
|
||||
@@ -476,8 +478,7 @@ export class HUDBuildingPlacer extends BaseHUDPart {
|
||||
staticComp.origin = tile;
|
||||
staticComp.rotation = rotation;
|
||||
staticComp.tileSize = metaBuilding.getDimensions(this.currentVariant.get());
|
||||
metaBuilding.updateRotationVariant(this.fakeEntity, rotationVariant);
|
||||
metaBuilding.updateVariant(this.fakeEntity, this.currentVariant.get());
|
||||
metaBuilding.updateVariants(this.fakeEntity, rotationVariant, this.currentVariant.get());
|
||||
|
||||
// Check if we could place the buildnig
|
||||
const canBuild = this.root.logic.checkCanPlaceBuilding({
|
||||
|
||||
@@ -173,8 +173,7 @@ export class MetaBuilding {
|
||||
);
|
||||
|
||||
this.setupEntityComponents(entity, root);
|
||||
this.updateRotationVariant(entity, rotationVariant);
|
||||
this.updateVariant(entity, variant);
|
||||
this.updateVariants(entity, rotationVariant, variant);
|
||||
|
||||
root.map.placeStaticEntity(entity);
|
||||
root.entityMgr.registerEntity(entity);
|
||||
@@ -186,9 +185,10 @@ export class MetaBuilding {
|
||||
* @param {GameRoot} root
|
||||
* @param {Vector} tile
|
||||
* @param {number} rotation
|
||||
* @param {string} variant
|
||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
||||
*/
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation) {
|
||||
computeOptimalDirectionAndRotationVariantAtTile(root, tile, rotation, variant) {
|
||||
if (!this.isRotateable()) {
|
||||
return {
|
||||
rotation: 0,
|
||||
@@ -202,18 +202,12 @@ export class MetaBuilding {
|
||||
}
|
||||
|
||||
/**
|
||||
* Should update the entity to match the given rotation variant
|
||||
* Should update the entity to match the given variants
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
*/
|
||||
updateRotationVariant(entity, rotationVariant) {}
|
||||
|
||||
/**
|
||||
* Should update the entity to match the given variant
|
||||
* @param {Entity} entity
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {}
|
||||
updateVariants(entity, rotationVariant, variant) {}
|
||||
|
||||
// PRIVATE INTERFACE
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { enumDirection, enumDirectionToVector, Vector } from "../../core/vector"
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { gMetaBuildingRegistry } from "../../core/global_registries";
|
||||
import { MetaBeltBaseBuilding } from "../buildings/belt_base";
|
||||
import { defaultBuildingVariant } from "../meta_building";
|
||||
|
||||
const BELT_ANIM_COUNT = 6;
|
||||
|
||||
@@ -91,10 +92,11 @@ export class BeltSystem extends GameSystemWithFilter {
|
||||
} = metaBelt.computeOptimalDirectionAndRotationVariantAtTile(
|
||||
this.root,
|
||||
new Vector(x, y),
|
||||
targetStaticComp.originalRotation
|
||||
targetStaticComp.originalRotation,
|
||||
defaultBuildingVariant
|
||||
);
|
||||
targetStaticComp.rotation = rotation;
|
||||
metaBelt.updateRotationVariant(targetEntity, rotationVariant);
|
||||
metaBelt.updateVariants(targetEntity, rotationVariant, defaultBuildingVariant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
for (
|
||||
let searchOffset = 0;
|
||||
searchOffset < globalConfig.undergroundBeltMaxTiles;
|
||||
searchOffset < globalConfig.undergroundBeltMaxTilesByTier[undergroundComp.tier];
|
||||
++searchOffset
|
||||
) {
|
||||
currentTile = currentTile.add(searchVector);
|
||||
@@ -75,7 +75,10 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
||||
const contents = this.root.map.getTileContent(currentTile);
|
||||
if (contents) {
|
||||
const receiverUndergroundComp = contents.components.UndergroundBelt;
|
||||
if (receiverUndergroundComp) {
|
||||
if (
|
||||
receiverUndergroundComp &&
|
||||
receiverUndergroundComp.tier === undergroundComp.tier
|
||||
) {
|
||||
const receiverStaticComp = contents.components.StaticMapEntity;
|
||||
if (receiverStaticComp.rotation === targetRotation) {
|
||||
if (receiverUndergroundComp.mode === enumUndergroundBeltMode.receiver) {
|
||||
|
||||
Reference in New Issue
Block a user