1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Display throughput in storage

This commit is contained in:
isaisstillalive 2020-07-01 22:13:53 +09:00
parent fc0fd2eb49
commit f3760e3e0f
2 changed files with 40 additions and 5 deletions

View File

@ -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;
}
}
}

View File

@ -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;