From 9f8c3086e3950849995cb28fc085056941786b6f Mon Sep 17 00:00:00 2001 From: isaisstillalive Date: Sun, 28 Jun 2020 07:17:14 +0900 Subject: [PATCH] Create storage statistics handle --- src/js/game/hud/parts/statistics.js | 27 +++++++++++++------ src/js/game/hud/parts/statistics_handle.js | 30 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/js/game/hud/parts/statistics.js b/src/js/game/hud/parts/statistics.js index 05f5661e..fce3feba 100644 --- a/src/js/game/hud/parts/statistics.js +++ b/src/js/game/hud/parts/statistics.js @@ -4,7 +4,11 @@ import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper"; import { enumAnalyticsDataSource } from "../../production_analytics"; import { BaseHUDPart } from "../base_hud_part"; import { DynamicDomAttach } from "../dynamic_dom_attach"; -import { enumDisplayMode, HUDShapeStatisticsHandle } from "./statistics_handle"; +import { + enumDisplayMode, + HUDShapeStatisticsHandle, + HUDShapeStatisticsStorageHandle, +} from "./statistics_handle"; import { T } from "../../../translations"; export class HUDStatistics extends BaseHUDPart { @@ -183,16 +187,23 @@ export class HUDStatistics extends BaseHUDPart { for (let i = 0; i < Math.min(entries.length, 200); ++i) { const entry = entries[i]; const shapeKey = entry[0]; - const shape = shapeKey.split(",")[1] || shapeKey; let handle = this.activeHandles[shapeKey]; if (!handle) { - const definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape); - handle = this.activeHandles[shapeKey] = new HUDShapeStatisticsHandle( - this.root, - definition, - this.intersectionObserver - ); + if (this.dataSource === enumAnalyticsDataSource.deliveredToStorage) { + const [uid, shape] = shapeKey.split(","); + const definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape); + handle = new HUDShapeStatisticsStorageHandle( + this.root, + Number.parseInt(uid), + definition, + this.intersectionObserver + ); + } else { + const definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shapeKey); + handle = new HUDShapeStatisticsHandle(this.root, definition, this.intersectionObserver); + } + this.activeHandles[shapeKey] = handle; } rendered.add(shapeKey); diff --git a/src/js/game/hud/parts/statistics_handle.js b/src/js/game/hud/parts/statistics_handle.js index 85928081..76d892bc 100644 --- a/src/js/game/hud/parts/statistics_handle.js +++ b/src/js/game/hud/parts/statistics_handle.js @@ -29,9 +29,13 @@ export class HUDShapeStatisticsHandle { this.visible = false; } + get shapeKey() { + return this.definition.getHash(); + } + initElement() { this.element = document.createElement("div"); - this.element.setAttribute("data-shape-key", this.definition.getHash()); + this.element.setAttribute("data-shape-key", this.shapeKey); this.counter = document.createElement("span"); this.counter.classList.add("counter"); @@ -76,9 +80,7 @@ export class HUDShapeStatisticsHandle { switch (dataSource) { case enumAnalyticsDataSource.stored: { - this.counter.innerText = formatBigNumber( - this.root.hubGoals.storedShapes[this.definition.getHash()] || 0 - ); + this.counter.innerText = formatBigNumber(this.root.hubGoals.storedShapes[this.shapeKey] || 0); break; } case enumAnalyticsDataSource.delivered: @@ -111,7 +113,7 @@ export class HUDShapeStatisticsHandle { const [canvas, context] = makeOffscreenBuffer(w * graphDpi, h * graphDpi, { smooth: true, reusable: false, - label: "statgraph-" + this.definition.getHash(), + label: "statgraph-" + this.shapeKey, }); context.scale(graphDpi, graphDpi); canvas.classList.add("graph"); @@ -225,3 +227,21 @@ export class HUDShapeStatisticsHandle { } } } + +export class HUDShapeStatisticsStorageHandle extends HUDShapeStatisticsHandle { + /** + * @param {GameRoot} root + * @param {number} uid + * @param {ShapeDefinition} definition + * @param {IntersectionObserver} intersectionObserver + */ + constructor(root, uid, definition, intersectionObserver) { + super(root, definition, intersectionObserver); + + this.uid = uid; + } + + get shapeKey() { + return this.uid.toString() + "," + this.definition.getHash(); + } +}