mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Create storage statistics handle
This commit is contained in:
parent
17059f600e
commit
9f8c3086e3
@ -4,7 +4,11 @@ import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper";
|
|||||||
import { enumAnalyticsDataSource } from "../../production_analytics";
|
import { enumAnalyticsDataSource } from "../../production_analytics";
|
||||||
import { BaseHUDPart } from "../base_hud_part";
|
import { BaseHUDPart } from "../base_hud_part";
|
||||||
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
import { DynamicDomAttach } from "../dynamic_dom_attach";
|
||||||
import { enumDisplayMode, HUDShapeStatisticsHandle } from "./statistics_handle";
|
import {
|
||||||
|
enumDisplayMode,
|
||||||
|
HUDShapeStatisticsHandle,
|
||||||
|
HUDShapeStatisticsStorageHandle,
|
||||||
|
} from "./statistics_handle";
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
|
|
||||||
export class HUDStatistics extends BaseHUDPart {
|
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) {
|
for (let i = 0; i < Math.min(entries.length, 200); ++i) {
|
||||||
const entry = entries[i];
|
const entry = entries[i];
|
||||||
const shapeKey = entry[0];
|
const shapeKey = entry[0];
|
||||||
const shape = shapeKey.split(",")[1] || shapeKey;
|
|
||||||
|
|
||||||
let handle = this.activeHandles[shapeKey];
|
let handle = this.activeHandles[shapeKey];
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
|
if (this.dataSource === enumAnalyticsDataSource.deliveredToStorage) {
|
||||||
|
const [uid, shape] = shapeKey.split(",");
|
||||||
const definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape);
|
const definition = this.root.shapeDefinitionMgr.getShapeFromShortKey(shape);
|
||||||
handle = this.activeHandles[shapeKey] = new HUDShapeStatisticsHandle(
|
handle = new HUDShapeStatisticsStorageHandle(
|
||||||
this.root,
|
this.root,
|
||||||
|
Number.parseInt(uid),
|
||||||
definition,
|
definition,
|
||||||
this.intersectionObserver
|
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);
|
rendered.add(shapeKey);
|
||||||
|
@ -29,9 +29,13 @@ export class HUDShapeStatisticsHandle {
|
|||||||
this.visible = false;
|
this.visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get shapeKey() {
|
||||||
|
return this.definition.getHash();
|
||||||
|
}
|
||||||
|
|
||||||
initElement() {
|
initElement() {
|
||||||
this.element = document.createElement("div");
|
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 = document.createElement("span");
|
||||||
this.counter.classList.add("counter");
|
this.counter.classList.add("counter");
|
||||||
@ -76,9 +80,7 @@ export class HUDShapeStatisticsHandle {
|
|||||||
|
|
||||||
switch (dataSource) {
|
switch (dataSource) {
|
||||||
case enumAnalyticsDataSource.stored: {
|
case enumAnalyticsDataSource.stored: {
|
||||||
this.counter.innerText = formatBigNumber(
|
this.counter.innerText = formatBigNumber(this.root.hubGoals.storedShapes[this.shapeKey] || 0);
|
||||||
this.root.hubGoals.storedShapes[this.definition.getHash()] || 0
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case enumAnalyticsDataSource.delivered:
|
case enumAnalyticsDataSource.delivered:
|
||||||
@ -111,7 +113,7 @@ export class HUDShapeStatisticsHandle {
|
|||||||
const [canvas, context] = makeOffscreenBuffer(w * graphDpi, h * graphDpi, {
|
const [canvas, context] = makeOffscreenBuffer(w * graphDpi, h * graphDpi, {
|
||||||
smooth: true,
|
smooth: true,
|
||||||
reusable: false,
|
reusable: false,
|
||||||
label: "statgraph-" + this.definition.getHash(),
|
label: "statgraph-" + this.shapeKey,
|
||||||
});
|
});
|
||||||
context.scale(graphDpi, graphDpi);
|
context.scale(graphDpi, graphDpi);
|
||||||
canvas.classList.add("graph");
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user