From f77d47d9f7dce6db8f945e8f79f86966017623aa Mon Sep 17 00:00:00 2001 From: RogiJAG Date: Mon, 13 Jul 2020 19:57:09 -0500 Subject: [PATCH] Add fl rotater variant --- src/js/core/config.js | 1 + src/js/game/buildings/rotater.js | 34 +++++++++++++++++------- src/js/game/components/item_processor.js | 1 + src/js/game/hub_goals.js | 1 + src/js/game/shape_definition.js | 14 ++++++++++ src/js/game/shape_definition_manager.js | 18 +++++++++++++ src/js/game/systems/item_processor.js | 15 ++++++++++- src/js/game/tutorial_goals.js | 1 + 8 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/js/core/config.js b/src/js/core/config.js index e06f9422..235904d9 100644 --- a/src/js/core/config.js +++ b/src/js/core/config.js @@ -67,6 +67,7 @@ export const globalConfig = { cutterQuad: 1 / 4, rotater: 1 / 1, rotaterCCW: 1 / 1, + rotaterFL: 1 / 1, painter: 1 / 6, painterDouble: 1 / 8, painterQuad: 1 / 8, diff --git a/src/js/game/buildings/rotater.js b/src/js/game/buildings/rotater.js index 56c0c87d..45bb97b9 100644 --- a/src/js/game/buildings/rotater.js +++ b/src/js/game/buildings/rotater.js @@ -11,7 +11,7 @@ import { enumHubGoalRewards } from "../tutorial_goals"; import { enumItemType } from "../base_item"; /** @enum {string} */ -export const enumRotaterVariants = { ccw: "ccw" }; +export const enumRotaterVariants = { ccw: "ccw", fl: "fl" }; export class MetaRotaterBuilding extends MetaBuilding { constructor() { @@ -28,12 +28,20 @@ export class MetaRotaterBuilding extends MetaBuilding { * @returns {Array<[string, string]>} */ getAdditionalStatistics(root, variant) { - const speed = root.hubGoals.getProcessorBaseSpeed( - variant === enumRotaterVariants.ccw - ? enumItemProcessorTypes.rotaterCCW - : enumItemProcessorTypes.rotater - ); - return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; + switch (variant) { + case defaultBuildingVariant: { + const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotater); + return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; + } + case enumRotaterVariants.ccw: { + const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotaterCCW); + return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; + } + case enumRotaterVariants.fl: { + const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotaterFL); + return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; + } + } } /** @@ -41,10 +49,14 @@ export class MetaRotaterBuilding extends MetaBuilding { * @param {GameRoot} root */ getAvailableVariants(root) { + let variants = [defaultBuildingVariant]; if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_rotater_ccw)) { - return [defaultBuildingVariant, enumRotaterVariants.ccw]; + variants.push(enumRotaterVariants.ccw); + } + if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_rotater_fl)) { + variants.push(enumRotaterVariants.fl); } - return super.getAvailableVariants(root); + return variants; } /** @@ -100,6 +112,10 @@ export class MetaRotaterBuilding extends MetaBuilding { entity.components.ItemProcessor.type = enumItemProcessorTypes.rotaterCCW; break; } + case enumRotaterVariants.fl: { + entity.components.ItemProcessor.type = enumItemProcessorTypes.rotaterFL; + break; + } default: assertAlways(false, "Unknown rotater variant: " + variant); } diff --git a/src/js/game/components/item_processor.js b/src/js/game/components/item_processor.js index 72422faf..806ec7c8 100644 --- a/src/js/game/components/item_processor.js +++ b/src/js/game/components/item_processor.js @@ -11,6 +11,7 @@ export const enumItemProcessorTypes = { cutterQuad: "cutterQuad", rotater: "rotater", rotaterCCW: "rotaterCCW", + rotaterFL: "rotaterFL", stacker: "stacker", trash: "trash", mixer: "mixer", diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 612bc124..36f8f107 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -431,6 +431,7 @@ export class HubGoals extends BasicSerializableObject { case enumItemProcessorTypes.cutterQuad: case enumItemProcessorTypes.rotater: case enumItemProcessorTypes.rotaterCCW: + case enumItemProcessorTypes.rotaterFL: case enumItemProcessorTypes.stacker: { assert( globalConfig.buildingSpeeds[processorType], diff --git a/src/js/game/shape_definition.js b/src/js/game/shape_definition.js index af2214e3..4e63c54b 100644 --- a/src/js/game/shape_definition.js +++ b/src/js/game/shape_definition.js @@ -13,6 +13,7 @@ import { enumInvertedColors, } from "./colors"; import { THEME } from "./theme"; +import { StaticMapEntitySystem } from "./systems/static_map_entity"; const rusha = require("rusha"); @@ -495,6 +496,19 @@ export class ShapeDefinition extends BasicSerializableObject { return new ShapeDefinition({ layers: newLayers }); } + /** + * Returns a definition which was rotated 180 degrees (flipped) + * @returns {ShapeDefinition} + */ + cloneRotateFL() { + const newLayers = this.internalCloneLayers(); + for (let layerIndex = 0; layerIndex < newLayers.length; ++layerIndex) { + const quadrants = newLayers[layerIndex]; + quadrants.push(quadrants.shift(), quadrants.shift()); + } + return new ShapeDefinition({ layers: newLayers }); + } + /** * Stacks the given shape definition on top. * @param {ShapeDefinition} definition diff --git a/src/js/game/shape_definition_manager.js b/src/js/game/shape_definition_manager.js index bebb4592..a3b8c841 100644 --- a/src/js/game/shape_definition_manager.js +++ b/src/js/game/shape_definition_manager.js @@ -127,6 +127,24 @@ export class ShapeDefinitionManager extends BasicSerializableObject { )); } + /** + * Generates a definition for rotating a shape counter clockwise + * @param {ShapeDefinition} definition + * @returns {ShapeDefinition} + */ + shapeActionRotateFL(definition) { + const key = "rotate-fl:" + definition.getHash(); + if (this.operationCache[key]) { + return /** @type {ShapeDefinition} */ (this.operationCache[key]); + } + + const rotated = definition.cloneRotateFL(); + + return /** @type {ShapeDefinition} */ (this.operationCache[key] = this.registerOrReturnHandle( + rotated + )); + } + /** * Generates a definition for stacking the upper definition onto the lower one * @param {ShapeDefinition} lowerDefinition diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 8713f599..5bebfed7 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -185,7 +185,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { break; } - // ROTATER ( CCW) + // ROTATER (CCW) case enumItemProcessorTypes.rotaterCCW: { const inputItem = /** @type {ShapeItem} */ (items[0].item); assert(inputItem instanceof ShapeItem, "Input for rotation is not a shape"); @@ -198,6 +198,19 @@ export class ItemProcessorSystem extends GameSystemWithFilter { break; } + // ROTATER (FL) + case enumItemProcessorTypes.rotaterFL: { + 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.shapeActionRotateFL(inputDefinition); + outItems.push({ + item: new ShapeItem(rotatedDefinition), + }); + break; + } + // STACKER case enumItemProcessorTypes.stacker: { diff --git a/src/js/game/tutorial_goals.js b/src/js/game/tutorial_goals.js index 366877ee..72fd093f 100644 --- a/src/js/game/tutorial_goals.js +++ b/src/js/game/tutorial_goals.js @@ -15,6 +15,7 @@ export const enumHubGoalRewards = { reward_tunnel: "reward_tunnel", reward_rotater_ccw: "reward_rotater_ccw", + reward_rotater_fl: "reward_rotater_fl", reward_miner_chainable: "reward_miner_chainable", reward_underground_belt_tier_2: "reward_underground_belt_tier_2", reward_splitter_compact: "reward_splitter_compact",