diff --git a/src/js/core/config.js b/src/js/core/config.js index bc2e2460..abb25402 100644 --- a/src/js/core/config.js +++ b/src/js/core/config.js @@ -83,17 +83,14 @@ export const globalConfig = { puzzleMaxBoundsSize: 20, puzzleValidationDurationSeconds: 30, - buildingSpeeds: { - cutter: 1 / 4, - cutterQuad: 1 / 4, - rotater: 1 / 1, - rotaterCCW: 1 / 1, - rotater180: 1 / 1, - painter: 1 / 6, - painterDouble: 1 / 8, - painterQuad: 1 / 2, - mixer: 1 / 5, - stacker: 1 / 8, + buildingAmountsToBelt: { + cutter: 4, + cutterQuad: 4, + painter: 6, + painterDouble: 8, + painterQuad: 2, + mixer: 5, + stacker: 8, }, // Zooming diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index 0126349d..e1326693 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -132,12 +132,6 @@ export class BeltPath extends BasicSerializableObject { */ tryAcceptItem(item, startProgress = 0) { if (this.spacingToFirstItem >= globalConfig.itemSpacingOnBelts) { - // So, since we already need one tick to accept this item we will add this directly. - const progressGrowth = - this.root.hubGoals.getBeltBaseSpeed() * - this.root.dynamicTickrate.deltaSeconds * - globalConfig.itemSpacingOnBelts; - // First, compute how much progress we can make *at max* const maxProgress = Math.max(0, this.spacingToFirstItem - globalConfig.itemSpacingOnBelts); const initialProgress = Math.min(maxProgress, startProgress); @@ -283,64 +277,6 @@ export class BeltPath extends BasicSerializableObject { }; } - /** - * Computes a method to pass over the item to the entity - * @param {Entity} entity - * @param {number} matchingSlotIndex - * @returns {(item: BaseItem, slotIndex: number) => boolean | void} - */ - computePassOverFunctionWithoutBelts(entity, matchingSlotIndex) { - const systems = this.root.systemMgr.systems; - const hubGoals = this.root.hubGoals; - - // NOTICE: THIS IS COPIED FROM THE ITEM EJECTOR SYSTEM FOR PERFORMANCE REASONS - - const itemProcessorComp = entity.components.ItemProcessor; - if (itemProcessorComp) { - // Its an item processor .. - return function (item) { - // Check for potential filters - if (!systems.itemProcessor.checkRequirements(entity, item, matchingSlotIndex)) { - return; - } - //return itemProcessorComp.tryTakeItem(item, matchingSlotIndex); - }; - } - - const undergroundBeltComp = entity.components.UndergroundBelt; - if (undergroundBeltComp) { - // Its an underground belt. yay. - return function (item) { - return undergroundBeltComp.tryAcceptExternalItem( - item, - hubGoals.getUndergroundBeltBaseSpeed() - ); - }; - } - - const storageComp = entity.components.Storage; - if (storageComp) { - // It's a storage - return function (item) { - if (storageComp.canAcceptItem(item)) { - storageComp.takeItem(item); - return true; - } - }; - } - - const filterComp = entity.components.Filter; - if (filterComp) { - // It's a filter! Unfortunately the filter has to know a lot about it's - // surrounding state and components, so it can't be within the component itself. - return function (item) { - if (systems.filter.tryAcceptItem(entity, matchingSlotIndex, item)) { - return true; - } - }; - } - } - // Following code will be compiled out outside of dev versions /* dev:start */ diff --git a/src/js/game/buildings/balancer.js b/src/js/game/buildings/balancer.js index ce685a9a..3af03e16 100644 --- a/src/js/game/buildings/balancer.js +++ b/src/js/game/buildings/balancer.js @@ -104,8 +104,7 @@ export class MetaBalancerBuilding extends MetaBuilding { speedMultiplier = 1; } - const speed = - (root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.balancer) / 2) * speedMultiplier; + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.balancer) * speedMultiplier; return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } diff --git a/src/js/game/buildings/cutter.js b/src/js/game/buildings/cutter.js index 21acdaa0..5717b702 100644 --- a/src/js/game/buildings/cutter.js +++ b/src/js/game/buildings/cutter.js @@ -54,7 +54,7 @@ export class MetaCutterBuilding extends MetaBuilding { if (root.gameMode.throughputDoesNotMatter()) { return []; } - const speed = root.hubGoals.getProcessorBaseSpeed( + const speed = root.hubGoals.getProcessingSpeed( variant === enumCutterVariants.quad ? enumItemProcessorTypes.cutterQuad : enumItemProcessorTypes.cutter diff --git a/src/js/game/buildings/hub.js b/src/js/game/buildings/hub.js index f8ba4b82..7ea336f1 100644 --- a/src/js/game/buildings/hub.js +++ b/src/js/game/buildings/hub.js @@ -164,7 +164,6 @@ export class MetaHubBuilding extends MetaBuilding { filter: "shape", }, ], - type: enumItemAcceptorTypes.hub, }) ); } diff --git a/src/js/game/buildings/mixer.js b/src/js/game/buildings/mixer.js index de1665c4..527de3ea 100644 --- a/src/js/game/buildings/mixer.js +++ b/src/js/game/buildings/mixer.js @@ -47,7 +47,7 @@ export class MetaMixerBuilding extends MetaBuilding { if (root.gameMode.throughputDoesNotMatter()) { return []; } - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.mixer); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.mixer); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } diff --git a/src/js/game/buildings/painter.js b/src/js/game/buildings/painter.js index 432973d0..a0839ef4 100644 --- a/src/js/game/buildings/painter.js +++ b/src/js/game/buildings/painter.js @@ -73,15 +73,15 @@ export class MetaPainterBuilding extends MetaBuilding { switch (variant) { case defaultBuildingVariant: case enumPainterVariants.mirrored: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.painter); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.painter); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } case enumPainterVariants.double: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.painterDouble); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.painterDouble); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed, true)]]; } case enumPainterVariants.quad: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.painterQuad); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.painterQuad); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } } diff --git a/src/js/game/buildings/rotater.js b/src/js/game/buildings/rotater.js index e1080767..c8a28748 100644 --- a/src/js/game/buildings/rotater.js +++ b/src/js/game/buildings/rotater.js @@ -70,15 +70,15 @@ export class MetaRotaterBuilding extends MetaBuilding { } switch (variant) { case defaultBuildingVariant: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotater); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.rotater); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } case enumRotaterVariants.ccw: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotaterCCW); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.rotaterCCW); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } case enumRotaterVariants.rotate180: { - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.rotater180); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.rotater180); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } } diff --git a/src/js/game/buildings/stacker.js b/src/js/game/buildings/stacker.js index f36ef248..fdd6f5fb 100644 --- a/src/js/game/buildings/stacker.js +++ b/src/js/game/buildings/stacker.js @@ -40,7 +40,7 @@ export class MetaStackerBuilding extends MetaBuilding { if (root.gameMode.throughputDoesNotMatter()) { return []; } - const speed = root.hubGoals.getProcessorBaseSpeed(enumItemProcessorTypes.stacker); + const speed = root.hubGoals.getProcessingSpeed(enumItemProcessorTypes.stacker); return [[T.ingame.buildingPlacement.infoTexts.speed, formatItemsPerSecond(speed)]]; } diff --git a/src/js/game/buildings/storage.js b/src/js/game/buildings/storage.js index 69e03608..78f398be 100644 --- a/src/js/game/buildings/storage.js +++ b/src/js/game/buildings/storage.js @@ -1,7 +1,7 @@ import { formatBigNumber } from "../../core/utils"; import { enumDirection, Vector } from "../../core/vector"; import { T } from "../../translations"; -import { enumItemAcceptorTypes, ItemAcceptorComponent } from "../components/item_acceptor"; +import { ItemAcceptorComponent } from "../components/item_acceptor"; import { ItemEjectorComponent } from "../components/item_ejector"; import { StorageComponent } from "../components/storage"; import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins"; @@ -81,7 +81,6 @@ export class MetaStorageBuilding extends MetaBuilding { direction: enumDirection.bottom, }, ], - type: enumItemAcceptorTypes.storage, }) ); diff --git a/src/js/game/buildings/underground_belt.js b/src/js/game/buildings/underground_belt.js index 182ee9a8..4dbce634 100644 --- a/src/js/game/buildings/underground_belt.js +++ b/src/js/game/buildings/underground_belt.js @@ -1,6 +1,6 @@ import { Loader } from "../../core/loader"; import { enumDirection, Vector, enumAngleToDirection, enumDirectionToVector } from "../../core/vector"; -import { enumItemAcceptorTypes, ItemAcceptorComponent } from "../components/item_acceptor"; +import { ItemAcceptorComponent } from "../components/item_acceptor"; import { ItemEjectorComponent } from "../components/item_ejector"; import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt"; import { Entity } from "../entity"; @@ -184,7 +184,6 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding { * @param {Entity} entity */ setupEntityComponents(entity) { - // Required, since the item processor needs this. entity.addComponent( new ItemEjectorComponent({ slots: [], @@ -195,7 +194,6 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding { entity.addComponent( new ItemAcceptorComponent({ slots: [], - type: enumItemAcceptorTypes.undergroundBelt, }) ); } diff --git a/src/js/game/components/item_acceptor.js b/src/js/game/components/item_acceptor.js index 9d3f2894..6ad136eb 100644 --- a/src/js/game/components/item_acceptor.js +++ b/src/js/game/components/item_acceptor.js @@ -45,8 +45,7 @@ import { GameRoot } from "../root"; */ /** @enum {string} */ -export const enumItemAcceptorTypes = { - itemProcessor: "itemProcessor", +const enumItemAcceptorTypes = { hub: "hub", storage: "storage", trash: "trash", @@ -64,14 +63,13 @@ export class ItemAcceptorComponent extends Component { * @param {Array} param0.slots The slots from which we accept items * @param {enumItemAcceptorTypes=} param0.type Function that gets called when the input of an item is completed */ - constructor({ slots = [], type = enumItemAcceptorTypes.itemProcessor }) { + constructor({ slots = [] }) { super(); /** @type {ItemAcceptorInputs} */ this.inputs = new Map(); /** @type {ItemAcceptorCompletedInputs} */ this.completedInputs = new Map(); // @SENSETODO does this need to be saved? - this.type = type; this.setSlots(slots); } diff --git a/src/js/game/components/item_ejector.js b/src/js/game/components/item_ejector.js index dbf88139..5c1cdb2a 100644 --- a/src/js/game/components/item_ejector.js +++ b/src/js/game/components/item_ejector.js @@ -70,7 +70,7 @@ export class ItemEjectorComponent extends Component { direction: slot.direction, item: null, lastItem: null, - progress: 0, //@SENSETODO needs to be started off with extra time + progress: 0, cachedDestSlot: null, cachedTargetEntity: null, }); @@ -134,7 +134,6 @@ export class ItemEjectorComponent extends Component { if (!this.canEjectOnSlot(slotIndex)) { return false; } - if (startingProgress > 0) console.log("starting with progress: " + startingProgress); this.slots[slotIndex].item = item; this.slots[slotIndex].lastItem = item; this.slots[slotIndex].progress = startingProgress; diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 854ef2ae..45e56a1b 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -507,55 +507,39 @@ export class HubGoals extends BasicSerializableObject { } /** - * Processor speed + * Processor time to process * @param {enumItemProcessorTypes} processorType - * @returns {number} items / sec + * @returns {number} process time in seconds */ - getProcessorBaseSpeed(processorType) { + getProcessingTime(processorType) { if (this.root.gameMode.throughputDoesNotMatter()) { - return globalConfig.beltSpeedItemsPerSecond * globalConfig.puzzleModeSpeed * 10; + return 0; } switch (processorType) { case enumItemProcessorTypes.trash: case enumItemProcessorTypes.hub: case enumItemProcessorTypes.goal: - return 1e30; case enumItemProcessorTypes.balancer: - return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt * 2; case enumItemProcessorTypes.reader: - return globalConfig.beltSpeedItemsPerSecond * this.upgradeImprovements.belt; + case enumItemProcessorTypes.rotater: + case enumItemProcessorTypes.rotaterCCW: + case enumItemProcessorTypes.rotater180: + return 0; case enumItemProcessorTypes.mixer: case enumItemProcessorTypes.painter: case enumItemProcessorTypes.painterDouble: case enumItemProcessorTypes.painterQuad: { - assert( - globalConfig.buildingSpeeds[processorType], - "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType - ); - return ( - globalConfig.beltSpeedItemsPerSecond * - this.upgradeImprovements.painting * - globalConfig.buildingSpeeds[processorType] - ); + return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.painting, processorType); + // b2 + 4 = 4 + // b2 + 8 = 8 } case enumItemProcessorTypes.cutter: case enumItemProcessorTypes.cutterQuad: - case enumItemProcessorTypes.rotater: - case enumItemProcessorTypes.rotaterCCW: - case enumItemProcessorTypes.rotater180: case enumItemProcessorTypes.stacker: { - assert( - globalConfig.buildingSpeeds[processorType], - "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType - ); - return ( - globalConfig.beltSpeedItemsPerSecond * - this.upgradeImprovements.processors * - globalConfig.buildingSpeeds[processorType] - ); + return this.getProcessorTimeWithUpgrades(this.upgradeImprovements.processors, processorType); } default: if (MOD_ITEM_PROCESSOR_SPEEDS[processorType]) { @@ -564,6 +548,33 @@ export class HubGoals extends BasicSerializableObject { assertAlways(false, "invalid processor type: " + processorType); } - return 1 / globalConfig.beltSpeedItemsPerSecond; + return 0; + } + + /** + * @param {number} upgrade + * @param {number} upgrade + */ + getProcessorTimeWithUpgrades(upgrade, processorType) { + assert( + globalConfig.buildingAmountsToBelt[processorType], + "Processor type has no speed set in globalConfig.buildingSpeeds: " + processorType + ); + + const processorTime = + globalConfig.buildingAmountsToBelt[processorType] / globalConfig.beltSpeedItemsPerSecond; + return processorTime / upgrade; + } + /** + * Processor speed + * @param {enumItemProcessorTypes} processorType + * @returns {number} process time in seconds + */ + getProcessingSpeed(processorType) { + const time = this.getProcessingTime(processorType); + if (time == 0) { + return time; + } + return 1 / time; } } diff --git a/src/js/game/systems/item_acceptor.js b/src/js/game/systems/item_acceptor.js index a0ba70cf..34b3b12f 100644 --- a/src/js/game/systems/item_acceptor.js +++ b/src/js/game/systems/item_acceptor.js @@ -2,11 +2,7 @@ import { globalConfig } from "../../core/config"; import { DrawParameters } from "../../core/draw_parameters"; import { enumDirectionToVector } from "../../core/vector"; import { ACHIEVEMENTS } from "../../platform/achievement_provider"; -import { - enumItemAcceptorTypes, - ItemAcceptorComponent, - InputCompletedArgs, -} from "../components/item_acceptor"; +import { ItemAcceptorComponent, InputCompletedArgs } from "../components/item_acceptor"; import { GameSystemWithFilter } from "../game_system_with_filter"; import { ShapeItem } from "../items/shape_item"; import { MapChunkView } from "../map_chunk_view"; @@ -14,29 +10,16 @@ import { MapChunkView } from "../map_chunk_view"; export class ItemAcceptorSystem extends GameSystemWithFilter { constructor(root) { super(root, [ItemAcceptorComponent]); - - /** - * @type {Object} - */ - this.handlers = { - [enumItemAcceptorTypes.itemProcessor]: this.input_ITEMPROCESSOR, - [enumItemAcceptorTypes.hub]: this.input_HUB, - [enumItemAcceptorTypes.trash]: this.input_TRASH, - }; - - // Bind all handlers - for (const key in this.handlers) { - this.handlers[key] = this.handlers[key].bind(this); - } } update() { - // * 2 because its only a half tile - (same code as ejector) + // same code for belts, acceptors and ejectors - add helper method??? const progressGrowth = - 2 * this.root.dynamicTickrate.deltaSeconds * this.root.hubGoals.getBeltBaseSpeed() * globalConfig.itemSpacingOnBelts; + // it's only half a belt + const maxProgress = 0.5; for (let i = 0; i < this.allEntities.length; ++i) { const entity = this.allEntities[i]; @@ -46,26 +29,13 @@ export class ItemAcceptorSystem extends GameSystemWithFilter { inputs.forEach((values, index) => { values.animProgress += progressGrowth; - if (values.animProgress < 1) return; + if (values.animProgress < maxProgress) return; inputs.delete(index); acceptorComp.completedInputs.set(index, { item: values.item, - extraProgress: values.animProgress - 1, - }); // will be handled on the SAME frame due to processor being afterwards - - /** @type {function(InputCompletedArgs) : string} */ - const handler = this.handlers[acceptorComp.type]; - assert(handler, "No handler for acceptor type defined: " + acceptorComp.type); - - // Call implementation - handler({ - root: this.root, - entity, - item: values.item, - slotIndex: index, - extraProgress: values.animProgress - 1, - }); + extraProgress: values.animProgress - maxProgress, + }); // will be handled on the SAME frame due to processor system being afterwards }); } } @@ -102,8 +72,8 @@ export class ItemAcceptorSystem extends GameSystemWithFilter { const fadeOutDirection = enumDirectionToVector[staticComp.localDirectionToWorld(direction)]; const finalTile = realSlotPos.subScalars( - fadeOutDirection.x * (animProgress / 2 - 0.5), - fadeOutDirection.y * (animProgress / 2 - 0.5) + fadeOutDirection.x * (animProgress - 0.5), + fadeOutDirection.y * (animProgress - 0.5) ); item.drawItemCenteredClipped( diff --git a/src/js/game/systems/item_ejector.js b/src/js/game/systems/item_ejector.js index 96c90951..4dfc31b3 100644 --- a/src/js/game/systems/item_ejector.js +++ b/src/js/game/systems/item_ejector.js @@ -139,12 +139,13 @@ export class ItemEjectorSystem extends GameSystemWithFilter { update() { this.staleAreaDetector.update(); - // * 2 because its only a half tile - (same code as acceptor) + // same code for belts, acceptors and ejectors - add helper method??? const progressGrowth = - 2 * this.root.dynamicTickrate.deltaSeconds * this.root.hubGoals.getBeltBaseSpeed() * globalConfig.itemSpacingOnBelts; + // it's only half a belt + const maxProgress = 0.5; // Go over all cache entries for (let i = 0; i < this.allEntities.length; ++i) { @@ -160,25 +161,25 @@ export class ItemEjectorSystem extends GameSystemWithFilter { continue; } - if (slot.progress < 1) { + if (slot.progress < maxProgress) { // Advance items on the slot slot.progress += progressGrowth; if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) { - slot.progress = 1; + slot.progress = maxProgress; } } // Check if we are still in the process of ejecting, can't proceed then - if (slot.progress < 1) continue; + if (slot.progress < maxProgress) continue; - const extraProgress = slot.progress - 1; + const extraProgress = slot.progress - maxProgress; // Check if we are ejecting to a belt path const destPath = slot.cachedBeltPath; if (destPath) { - // Try passing the item over - extraProgress / 2 because the progress there is for double the distance - if (destPath.tryAcceptItem(item, extraProgress / 2)) { + // Try passing the item over + if (destPath.tryAcceptItem(item, extraProgress)) { slot.item = null; } @@ -203,8 +204,6 @@ export class ItemEjectorSystem extends GameSystemWithFilter { slot.item = null; } } - - //@SENSETODO deal with other buildings - acceptor code on them needs to be different! } } } @@ -244,8 +243,13 @@ export class ItemEjectorSystem extends GameSystemWithFilter { continue; } + // don't render items at the start of output + if (slot.progress < 0.05) { + continue; + } + // Limit the progress to the maximum available space on the next belt (also see #1000) - let progress = Math.min(1, slot.progress); + let progress = Math.min(0.5, slot.progress); const nextBeltPath = slot.cachedBeltPath; if (nextBeltPath) { /* @@ -281,7 +285,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter { ^ max progress = 0.3 Because now our range actually only goes to the end of the building, and not towards the center of the building, we need to multiply - all values by 2: + all values by 2: <--------- except max progress is now 0.5 rather than 1, so this isn't needed anymore Building Belt | X | X | @@ -293,7 +297,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter { */ const maxProgress = - (0.5 + nextBeltPath.spacingToFirstItem - globalConfig.itemSpacingOnBelts) * 2; + 0.5 + nextBeltPath.spacingToFirstItem - globalConfig.itemSpacingOnBelts; progress = Math.min(maxProgress, progress); } @@ -306,8 +310,8 @@ export class ItemEjectorSystem extends GameSystemWithFilter { const realDirection = staticComp.localDirectionToWorld(slot.direction); const realDirectionVector = enumDirectionToVector[realDirection]; - const tileX = realPosition.x + 0.5 + realDirectionVector.x * 0.5 * progress; - const tileY = realPosition.y + 0.5 + realDirectionVector.y * 0.5 * progress; + const tileX = realPosition.x + 0.5 + realDirectionVector.x * progress; + const tileY = realPosition.y + 0.5 + realDirectionVector.y * progress; const worldX = tileX * globalConfig.tileSize; const worldY = tileY * globalConfig.tileSize; diff --git a/src/js/game/systems/item_processor.js b/src/js/game/systems/item_processor.js index 2119a721..20bfbdab 100644 --- a/src/js/game/systems/item_processor.js +++ b/src/js/game/systems/item_processor.js @@ -1,4 +1,5 @@ import { globalConfig } from "../../core/config"; +import { ACHIEVEMENTS } from "../../platform/achievement_provider"; import { BaseItem } from "../base_item"; import { enumColorMixingResults, enumColors } from "../colors"; import { @@ -13,10 +14,10 @@ import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item"; import { ShapeItem } from "../items/shape_item"; /** - * We need to allow queuing charges, otherwise the throughput will stall + * We need to allow queuing charges, otherwise the throughput will stalls */ //@SENSETODO not sure if this is true anymore -const MAX_QUEUED_CHARGES = 2; +const MAX_QUEUED_CHARGES = 1; /** * Whole data for a produced item @@ -266,7 +267,6 @@ export class ItemProcessorSystem extends GameSystemWithFilter { // First, take inputs - but only ones that are completed const inputs = acceptorComp.completedInputs; - console.log("processor added charge"); const outItems = []; @@ -289,8 +289,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } // Queue Charge - const baseSpeed = this.root.hubGoals.getProcessorBaseSpeed(processorComp.type); - const originalTime = 0; + const originalTime = this.root.hubGoals.getProcessingTime(processorComp.type); const bonusTimeToApply = Math.min(originalTime, processorComp.bonusTime); const timeToProcess = originalTime - bonusTimeToApply; @@ -414,6 +413,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateCCW(inputDefinition); payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(rotatedDefinition), + extraProgress: input.extraProgress, }); } @@ -429,6 +429,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotate180(inputDefinition); payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(rotatedDefinition), + extraProgress: input.extraProgress, }); } @@ -437,7 +438,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { */ process_STACKER(payload) { const lowerInput = payload.inputs.get(0); - const upperInput = payload.inputs.get(0); + const upperInput = payload.inputs.get(1); const lowerItem = /** @type {ShapeItem} */ (lowerInput.item); const upperItem = /** @type {ShapeItem} */ (upperInput.item); @@ -450,6 +451,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { ); payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(stackedDefinition), + extraProgress: lowerInput.extraProgress, }); } @@ -457,7 +459,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { * @param {ProcessorImplementationPayload} payload */ process_TRASH(payload) { - // Do nothing .. + payload.entity.root.signals.achievementCheck.dispatch(ACHIEVEMENTS.trash1000, 1); } /** @@ -483,6 +485,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { } payload.outItems.push({ item: COLOR_ITEM_SINGLETONS[resultColor], + extraProgress: input1.extraProgress, }); } @@ -502,6 +505,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition), + extraProgress: input1.extraProgress, }); } @@ -509,8 +513,11 @@ export class ItemProcessorSystem extends GameSystemWithFilter { * @param {ProcessorImplementationPayload} payload */ process_PAINTER_DOUBLE(payload) { - const shapeItem1 = /** @type {ShapeItem} */ (payload.inputs.get(0).item); - const shapeItem2 = /** @type {ShapeItem} */ (payload.inputs.get(1).item); + const input1 = payload.inputs.get(0); + const input2 = payload.inputs.get(1); + + const shapeItem1 = /** @type {ShapeItem} */ (input1.item); + const shapeItem2 = /** @type {ShapeItem} */ (input2.item); const colorItem = /** @type {ColorItem} */ (payload.inputs.get(2).item); assert(shapeItem1 instanceof ShapeItem, "Input for painter is not a shape"); @@ -528,10 +535,12 @@ export class ItemProcessorSystem extends GameSystemWithFilter { ); payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition1), + extraProgress: input1.extraProgress, }); payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition2), + extraProgress: input2.extraProgress, }); } @@ -559,6 +568,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter { payload.outItems.push({ item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition), + extraProgress: input.extraProgress, }); } @@ -567,33 +577,34 @@ export class ItemProcessorSystem extends GameSystemWithFilter { */ process_READER(payload) { // Pass through the item - const item = payload.inputs.get(0).item; + const input = payload.inputs.get(0); payload.outItems.push({ - item, + item: input.item, doNotTrack: true, + extraProgress: input.extraProgress, }); // Track the item const readerComp = payload.entity.components.BeltReader; readerComp.lastItemTimes.push(this.root.time.now()); - readerComp.lastItem = item; + readerComp.lastItem = input.item; } /** * @param {ProcessorImplementationPayload} payload */ process_HUB(payload) { - //const input = payload.inputs.get(i); - //const hubComponent = payload.entity.components.Hub; - //assert(hubComponent, "Hub item processor has no hub component"); - //// Hardcoded - //for (let i = 0; i < payload.inputCount; ++i) { - // const item = /** @type {ShapeItem} */ (payload.inputs.get(i)); - // if (!item) { - // continue; - // } - // this.root.hubGoals.handleDefinitionDelivered(item.definition); - //} + const hubComponent = payload.entity.components.Hub; + assert(hubComponent, "Hub item processor has no hub component"); + // Hardcoded + for (let i = 0; i < payload.inputs.size; ++i) { + const input = payload.inputs.get(i); + if (!input) continue; + const item = /** @type {ShapeItem} */ (input.item); + if (!item) continue; + + this.root.hubGoals.handleDefinitionDelivered(item.definition); + } } /** diff --git a/src/js/game/systems/underground_belt.js b/src/js/game/systems/underground_belt.js index 9b31eec1..84f71abd 100644 --- a/src/js/game/systems/underground_belt.js +++ b/src/js/game/systems/underground_belt.js @@ -294,6 +294,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter { */ handleSender(entity) { const undergroundComp = entity.components.UndergroundBelt; + const acceptorComp = entity.components.ItemAcceptor; // Find the current receiver let cacheEntry = undergroundComp.cachedLinkedEntity;