diff --git a/src/js/game/components/storage.js b/src/js/game/components/storage.js index e7b40a77..b1c9ca62 100644 --- a/src/js/game/components/storage.js +++ b/src/js/game/components/storage.js @@ -42,6 +42,11 @@ export class StorageComponent extends Component { */ this.storedCount = 0; + /** + * Item to be analyzed + */ + this.itemsToAnalyze = 0; + /** * We compute an opacity to make sure it doesn't flicker */ @@ -86,5 +91,6 @@ export class StorageComponent extends Component { takeItem(item) { this.storedItem = item; this.storedCount++; + this.itemsToAnalyze++; } } diff --git a/src/js/game/production_analytics.js b/src/js/game/production_analytics.js index 41ec31ae..ec44978f 100644 --- a/src/js/game/production_analytics.js +++ b/src/js/game/production_analytics.js @@ -10,6 +10,7 @@ export const enumAnalyticsDataSource = { produced: "produced", stored: "stored", delivered: "delivered", + deliveredToStorage: "deliveredToStorage", }; export class ProductionAnalytics extends BasicSerializableObject { @@ -28,6 +29,7 @@ export class ProductionAnalytics extends BasicSerializableObject { [enumAnalyticsDataSource.produced]: [], [enumAnalyticsDataSource.stored]: [], [enumAnalyticsDataSource.delivered]: [], + [enumAnalyticsDataSource.deliveredToStorage]: [], }; 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.itemProduced.add(this.onItemProduced, this); + this.root.signals.itemDeliveredToStorage.add(this.onItemDeliveredToStorage, this); 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 */ diff --git a/src/js/game/root.js b/src/js/game/root.js index 50c87072..9e196f48 100644 --- a/src/js/game/root.js +++ b/src/js/game/root.js @@ -165,6 +165,7 @@ export class GameRoot { shapeDelivered: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()), itemProduced: /** @type {TypedSignal<[BaseItem]>} */ (new Signal()), + itemDeliveredToStorage: /** @type {TypedSignal<[number, BaseItem, number]>} */ (new Signal()), bulkOperationFinished: /** @type {TypedSignal<[]>} */ (new Signal()), diff --git a/src/js/game/systems/storage.js b/src/js/game/systems/storage.js index 7f946e5b..edb49eda 100644 --- a/src/js/game/systems/storage.js +++ b/src/js/game/systems/storage.js @@ -18,6 +18,16 @@ export class StorageSystem extends GameSystemWithFilter { const entity = this.allEntities[i]; 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 if (storageComp.storedItem && storageComp.storedCount > 0) { const ejectorComp = entity.components.ItemEjector;