diff --git a/src/components/ModularFactoryDrawerContent.tsx b/src/components/ModularFactoryDrawerContent.tsx index bf3a675..5667b6a 100644 --- a/src/components/ModularFactoryDrawerContent.tsx +++ b/src/components/ModularFactoryDrawerContent.tsx @@ -306,8 +306,14 @@ export default defineComponent({ return modularFactoryList.getModularFactory(props.modularFactoryId) }) + const modularFactoryComputed = computed(() => { + return modularFactoryList.modularFactoryComputedRecord[ + props.modularFactoryId + ] + }) + return () => ( - + id} columns={createColumns({ onDelete: (id) => { modularFactoryList.deleteAssemblyLine(modularFactory.value.id, id) @@ -350,6 +357,21 @@ export default defineComponent({ })} data={modularFactory.value.data} /> + + + +
{t('totalInputs')}
+ {modularFactoryComputed.value?.inputs.map( + renderItemQuantityPerMinute, + )} +
+ +
{t('totalOutputs')}
+ {modularFactoryComputed.value?.outputs.map( + renderItemQuantityPerMinute, + )} +
+
) }, diff --git a/src/locales/en.yml b/src/locales/en.yml index 5c3bb2d..f233945 100644 --- a/src/locales/en.yml +++ b/src/locales/en.yml @@ -18,6 +18,8 @@ remark: Remark power: Power inputs: Inputs outputs: Outputs +totalInputs: Total Inputs +totalOutputs: Total Outputs action: Action delete: Delete diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml index a148b98..f78eb3c 100644 --- a/src/locales/zh-CN.yml +++ b/src/locales/zh-CN.yml @@ -18,6 +18,8 @@ remark: 备注 power: 功率 inputs: 输入 outputs: 输出 +totalInputs: 总输入 +totalOutputs: 总输出 action: 操作 delete: 删除 diff --git a/src/stores/modularFactoryList.ts b/src/stores/modularFactoryList.ts index 5eb7b6e..7e6356c 100644 --- a/src/stores/modularFactoryList.ts +++ b/src/stores/modularFactoryList.ts @@ -7,7 +7,9 @@ import type { AssemblyLine, AssemblyLineComputed, Id, + ItemQuantityPerMinute, ModularFactory, + ModularFactoryComputed, } from '@/types' import { getBuildingById, getRecipeById } from '@/data' import { @@ -132,6 +134,75 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => { return _data }) + const modularFactoryComputedRecord = computed(() => { + const _data: Record = {} + data.value.forEach(({ id, data }) => { + const inputAndOutputs: { + itemId: Id + input: number + output: number + }[] = [] + const inputAndOutputsAdd = ( + type: 'input' | 'output', + itemId: Id, + quantityPerMinute: number, + ) => { + let inputAndOutput = inputAndOutputs.find( + (item) => item.itemId === itemId, + ) + if (!inputAndOutput) { + inputAndOutput = { + itemId, + input: 0, + output: 0, + } + inputAndOutputs.push(inputAndOutput) + } + inputAndOutput[type] += quantityPerMinute + } + data.forEach(({ id }) => { + const assemblyLineComputed = assemblyLineComputedRecord.value[id] + if (!assemblyLineComputed) { + return + } + assemblyLineComputed.inputs.forEach(({ itemId, quantityPerMinute }) => { + inputAndOutputsAdd('input', itemId, quantityPerMinute) + }) + assemblyLineComputed.outputs.forEach( + ({ itemId, quantityPerMinute }) => { + inputAndOutputsAdd('output', itemId, quantityPerMinute) + }, + ) + }) + const inputAndOutputsAbs = inputAndOutputs.map( + ({ itemId, input, output }): ItemQuantityPerMinute => { + return { + itemId, + quantityPerMinute: new Decimal(output).sub(input).toNumber(), + } + }, + ) + _data[id] = { + modularFactoryId: id, + inputs: inputAndOutputsAbs + .filter(({ quantityPerMinute }) => quantityPerMinute < 0) + .map(({ itemId, quantityPerMinute }) => { + return { + itemId, + quantityPerMinute: new Decimal(quantityPerMinute) + .abs() + .toNumber(), + } + }) + .sort((a, b) => b.quantityPerMinute - a.quantityPerMinute), + outputs: inputAndOutputsAbs + .filter(({ quantityPerMinute }) => quantityPerMinute > 0.0001) + .sort((a, b) => b.quantityPerMinute - a.quantityPerMinute), + } + }) + return _data + }) + // 自增ID let currentId: Id = Math.max( 0, @@ -196,6 +267,7 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => { return { data, assemblyLineComputedRecord, + modularFactoryComputedRecord, newModularFactory, deleteModularFactory, getModularFactory, diff --git a/src/types.ts b/src/types.ts index a419063..cf74fe8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,6 +41,12 @@ export interface ModularFactory { data: AssemblyLine[] } +export interface ModularFactoryComputed { + modularFactoryId: Id + inputs: ItemQuantityPerMinute[] + outputs: ItemQuantityPerMinute[] +} + export interface AssemblyLine { id: Id targetItemId: Id | null