From f3760e3e0fdeb4dbb091ec220c580a0cee8f298f Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Wed, 1 Jul 2020 22:13:53 +0900 Subject: [PATCH] Display throughput in storage --- src/js/game/components/storage.js | 16 ++++++++++++++++ src/js/game/systems/storage.js | 29 ++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/js/game/components/storage.js b/src/js/game/components/storage.js index b1c9ca62..cc6d11e2 100644 --- a/src/js/game/components/storage.js +++ b/src/js/game/components/storage.js @@ -5,6 +5,12 @@ import { BaseItem, enumItemType } from "../base_item"; import { ColorItem } from "../items/color_item"; import { ShapeItem } from "../items/shape_item"; +/** @enum {string} */ +export const enumStorageDisplayType = { + count: "count", + rate: "rate", +}; + export class StorageComponent extends Component { static getId() { return "Storage"; @@ -51,6 +57,8 @@ export class StorageComponent extends Component { * We compute an opacity to make sure it doesn't flicker */ this.overlayOpacity = 0; + + this.displayType = enumStorageDisplayType.count; } /** @@ -93,4 +101,12 @@ export class StorageComponent extends Component { this.storedCount++; this.itemsToAnalyze++; } + + cycleDisplayType() { + if (this.displayType === enumStorageDisplayType.count) { + this.displayType = enumStorageDisplayType.rate; + } else { + this.displayType = enumStorageDisplayType.count; + } + } } diff --git a/src/js/game/systems/storage.js b/src/js/game/systems/storage.js index edb49eda..8e85a1e5 100644 --- a/src/js/game/systems/storage.js +++ b/src/js/game/systems/storage.js @@ -1,10 +1,14 @@ import { GameSystemWithFilter } from "../game_system_with_filter"; -import { StorageComponent } from "../components/storage"; +import { StorageComponent, enumStorageDisplayType } from "../components/storage"; import { Entity } from "../entity"; import { DrawParameters } from "../../core/draw_parameters"; import { formatBigNumber, lerp } from "../../core/utils"; import { Loader } from "../../core/loader"; import { enumLayer } from "../root"; +import { enumAnalyticsDataSource } from "../production_analytics"; +import { globalConfig } from "../../core/config"; +import { enumItemType } from "../base_item"; +import { ShapeItem } from "../items/shape_item"; export class StorageSystem extends GameSystemWithFilter { constructor(root) { @@ -76,10 +80,25 @@ export class StorageSystem extends GameSystemWithFilter { this.storageOverlaySprite.drawCached(parameters, center.x - 15, center.y + 15, 30, 15); - context.font = "bold 10px GameFont"; - context.textAlign = "center"; - context.fillStyle = "#64666e"; - context.fillText(formatBigNumber(storageComp.storedCount), center.x, center.y + 25.5); + if (storageComp.displayType === enumStorageDisplayType.count) { + context.font = "bold 10px GameFont"; + context.textAlign = "center"; + context.fillStyle = "#64666e"; + context.fillText(formatBigNumber(storageComp.storedCount), center.x, center.y + 25.5); + } else if (storageComp.displayType === enumStorageDisplayType.rate) { + const shapeKey = entity.uid.toString() + "," + storageComp.storedItem.serialize(); + let rate = + (this.root.productionAnalytics.getCurrentShapeRate( + enumAnalyticsDataSource.deliveredToStorage, + shapeKey + ) / + globalConfig.analyticsSliceDurationSeconds) * + 60; + context.font = "bold 7px GameFont"; + context.textAlign = "center"; + context.fillStyle = "#64666e"; + context.fillText("" + formatBigNumber(rate) + " /s", center.x, center.y + 24.5); + } context.textAlign = "left"; context.globalAlpha = 1;