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

Record "delivered to storage" to analytics history

This commit is contained in:
isaisstillalive 2020-06-28 07:17:14 +09:00
parent 8667739e5e
commit 6d17291f1e
4 changed files with 34 additions and 0 deletions

View File

@ -42,6 +42,11 @@ export class StorageComponent extends Component {
*/ */
this.storedCount = 0; this.storedCount = 0;
/**
* Item to be analyzed
*/
this.itemsToAnalyze = 0;
/** /**
* We compute an opacity to make sure it doesn't flicker * We compute an opacity to make sure it doesn't flicker
*/ */
@ -86,5 +91,6 @@ export class StorageComponent extends Component {
takeItem(item) { takeItem(item) {
this.storedItem = item; this.storedItem = item;
this.storedCount++; this.storedCount++;
this.itemsToAnalyze++;
} }
} }

View File

@ -10,6 +10,7 @@ export const enumAnalyticsDataSource = {
produced: "produced", produced: "produced",
stored: "stored", stored: "stored",
delivered: "delivered", delivered: "delivered",
deliveredToStorage: "deliveredToStorage",
}; };
export class ProductionAnalytics extends BasicSerializableObject { export class ProductionAnalytics extends BasicSerializableObject {
@ -28,6 +29,7 @@ export class ProductionAnalytics extends BasicSerializableObject {
[enumAnalyticsDataSource.produced]: [], [enumAnalyticsDataSource.produced]: [],
[enumAnalyticsDataSource.stored]: [], [enumAnalyticsDataSource.stored]: [],
[enumAnalyticsDataSource.delivered]: [], [enumAnalyticsDataSource.delivered]: [],
[enumAnalyticsDataSource.deliveredToStorage]: [],
}; };
for (let i = 0; i < globalConfig.statisticsGraphSlices; ++i) { for (let i = 0; i < globalConfig.statisticsGraphSlices; ++i) {
@ -36,6 +38,7 @@ export class ProductionAnalytics extends BasicSerializableObject {
this.root.signals.shapeDelivered.add(this.onShapeDelivered, this); this.root.signals.shapeDelivered.add(this.onShapeDelivered, this);
this.root.signals.itemProduced.add(this.onItemProduced, this); this.root.signals.itemProduced.add(this.onItemProduced, this);
this.root.signals.itemDeliveredToStorage.add(this.onItemDeliveredToStorage, this);
this.lastAnalyticsSlice = 0; this.lastAnalyticsSlice = 0;
} }
@ -61,6 +64,20 @@ export class ProductionAnalytics extends BasicSerializableObject {
} }
} }
/**
* @param {number} uid
* @param {BaseItem} item
* @param {number} count
*/
onItemDeliveredToStorage(uid, item, count) {
if (item.getItemType() === enumItemType.shape) {
const definition = /** @type {ShapeItem} */ (item).definition;
const key = uid + "," + definition.getHash();
const entry = this.history[enumAnalyticsDataSource.deliveredToStorage];
entry[entry.length - 1][key] = (entry[entry.length - 1][key] || 0) + count;
}
}
/** /**
* Starts a new time slice * Starts a new time slice
*/ */

View File

@ -165,6 +165,7 @@ export class GameRoot {
shapeDelivered: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()), shapeDelivered: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
itemProduced: /** @type {TypedSignal<[BaseItem]>} */ (new Signal()), itemProduced: /** @type {TypedSignal<[BaseItem]>} */ (new Signal()),
itemDeliveredToStorage: /** @type {TypedSignal<[number, BaseItem, number]>} */ (new Signal()),
bulkOperationFinished: /** @type {TypedSignal<[]>} */ (new Signal()), bulkOperationFinished: /** @type {TypedSignal<[]>} */ (new Signal()),

View File

@ -18,6 +18,16 @@ export class StorageSystem extends GameSystemWithFilter {
const entity = this.allEntities[i]; const entity = this.allEntities[i];
const storageComp = entity.components.Storage; const storageComp = entity.components.Storage;
// Analytics hook
if (storageComp.itemsToAnalyze > 0) {
this.root.signals.itemDeliveredToStorage.dispatch(
entity.uid,
storageComp.storedItem,
storageComp.itemsToAnalyze
);
storageComp.itemsToAnalyze = 0;
}
// Eject from storage // Eject from storage
if (storageComp.storedItem && storageComp.storedCount > 0) { if (storageComp.storedItem && storageComp.storedCount > 0) {
const ejectorComp = entity.components.ItemEjector; const ejectorComp = entity.components.ItemEjector;