mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add CCW rotater
This commit is contained in:
@@ -47,6 +47,7 @@ export const globalConfig = {
|
||||
buildingSpeeds: {
|
||||
cutter: 1 / 4,
|
||||
rotater: 1 / 1,
|
||||
rotaterCCW: 1 / 1,
|
||||
painter: 1 / 3,
|
||||
painterDouble: 1 / 3,
|
||||
mixer: 1 / 2,
|
||||
|
||||
@@ -4,10 +4,13 @@ import { ItemAcceptorComponent, enumItemAcceptorItemFilter } from "../components
|
||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||
import { GameRoot } from "../root";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumRotaterVariants = { ccw: "ccw" };
|
||||
|
||||
export class MetaRotaterBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
super("rotater");
|
||||
@@ -25,6 +28,10 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
||||
return "#7dc6cd";
|
||||
}
|
||||
|
||||
getAvailableVariants(root) {
|
||||
return [defaultBuildingVariant, enumRotaterVariants.ccw];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GameRoot} root
|
||||
*/
|
||||
@@ -61,4 +68,24 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariant(entity, variant) {
|
||||
switch (variant) {
|
||||
case defaultBuildingVariant: {
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.rotater;
|
||||
break;
|
||||
}
|
||||
case enumRotaterVariants.ccw: {
|
||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.rotaterCCW;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assertAlways(false, "Unknown rotater variant: " + variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ export const enumItemProcessorTypes = {
|
||||
splitter: "splitter",
|
||||
cutter: "cutter",
|
||||
rotater: "rotater",
|
||||
rotaterCCW: "rotaterCCW",
|
||||
stacker: "stacker",
|
||||
trash: "trash",
|
||||
mixer: "mixer",
|
||||
|
||||
@@ -384,6 +384,7 @@ export class HubGoals extends BasicSerializableObject {
|
||||
return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt * 2;
|
||||
case enumItemProcessorTypes.cutter:
|
||||
case enumItemProcessorTypes.rotater:
|
||||
case enumItemProcessorTypes.rotaterCCW:
|
||||
case enumItemProcessorTypes.stacker:
|
||||
case enumItemProcessorTypes.mixer:
|
||||
case enumItemProcessorTypes.painter:
|
||||
|
||||
@@ -393,6 +393,20 @@ export class ShapeDefinition extends BasicSerializableObject {
|
||||
return new ShapeDefinition({ layers: newLayers });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a definition which was rotated counter clockwise
|
||||
* @returns {ShapeDefinition}
|
||||
*/
|
||||
cloneRotateCCW() {
|
||||
const newLayers = this.internalCloneLayers();
|
||||
for (let layerIndex = 0; layerIndex < newLayers.length; ++layerIndex) {
|
||||
const quadrants = newLayers[layerIndex];
|
||||
quadrants.push(quadrants[0]);
|
||||
quadrants.shift();
|
||||
}
|
||||
return new ShapeDefinition({ layers: newLayers });
|
||||
}
|
||||
|
||||
/**
|
||||
* Stacks the given shape definition on top.
|
||||
* @param {ShapeDefinition} definition
|
||||
|
||||
@@ -75,7 +75,7 @@ export class ShapeDefinitionManager extends BasicSerializableObject {
|
||||
* @returns {ShapeDefinition}
|
||||
*/
|
||||
shapeActionRotateCW(definition) {
|
||||
const key = "rotate:" + definition.getHash();
|
||||
const key = "rotate-cw:" + definition.getHash();
|
||||
if (this.operationCache[key]) {
|
||||
return /** @type {ShapeDefinition} */ (this.operationCache[key]);
|
||||
}
|
||||
@@ -87,6 +87,24 @@ export class ShapeDefinitionManager extends BasicSerializableObject {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a definition for rotating a shape counter clockwise
|
||||
* @param {ShapeDefinition} definition
|
||||
* @returns {ShapeDefinition}
|
||||
*/
|
||||
shapeActionRotateCCW(definition) {
|
||||
const key = "rotate-ccw:" + definition.getHash();
|
||||
if (this.operationCache[key]) {
|
||||
return /** @type {ShapeDefinition} */ (this.operationCache[key]);
|
||||
}
|
||||
|
||||
const rotated = definition.cloneRotateCCW();
|
||||
|
||||
return /** @type {ShapeDefinition} */ (this.operationCache[key] = this.registerOrReturnHandle(
|
||||
rotated
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a definition for stacking the upper definition onto the lower one
|
||||
* @param {ShapeDefinition} lowerDefinition
|
||||
|
||||
@@ -175,7 +175,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
// ROTATER
|
||||
case enumItemProcessorTypes.rotater: {
|
||||
const inputItem = /** @type {ShapeItem} */ (items[0].item);
|
||||
assert(inputItem instanceof ShapeItem, "Input for cut is not a shape");
|
||||
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
||||
const inputDefinition = inputItem.definition;
|
||||
|
||||
const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateCW(inputDefinition);
|
||||
@@ -185,6 +185,19 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
break;
|
||||
}
|
||||
|
||||
// ROTATER ( CCW)
|
||||
case enumItemProcessorTypes.rotaterCCW: {
|
||||
const inputItem = /** @type {ShapeItem} */ (items[0].item);
|
||||
assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape");
|
||||
const inputDefinition = inputItem.definition;
|
||||
|
||||
const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateCCW(inputDefinition);
|
||||
outItems.push({
|
||||
item: new ShapeItem(rotatedDefinition),
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// STACKER
|
||||
|
||||
case enumItemProcessorTypes.stacker: {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { MinerComponent } from "../components/miner";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { enumDirectionToVector } from "../../core/vector";
|
||||
import { Entity } from "../entity";
|
||||
import { BaseItem } from "../base_item";
|
||||
@@ -20,7 +19,6 @@ export class MinerSystem extends GameSystemWithFilter {
|
||||
|
||||
const minerComp = entity.components.Miner;
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const ejectComp = entity.components.ItemEjector;
|
||||
|
||||
// First, try to get rid of chained items
|
||||
if (minerComp.itemChainBuffer.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user