Skip to content

Commit

Permalink
修复更改目标物品时由于短暂的物品和配方不匹配造成的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
imsfc committed Sep 22, 2024
1 parent 797a5b9 commit 3a9fdc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/components/ModularFactoryDrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function createColumns({
width: 140,
render: (row) => {
const assemblyLineComputed =
modularFactoryList.assemblyLineComputedList[row.id]
modularFactoryList.assemblyLineComputedRecord[row.id]
if (!assemblyLineComputed) {
return null
}
Expand Down Expand Up @@ -198,7 +198,7 @@ function createColumns({
width: 120,
render: (row) => {
const assemblyLineComputed =
modularFactoryList.assemblyLineComputedList[row.id]
modularFactoryList.assemblyLineComputedRecord[row.id]
if (!assemblyLineComputed?.averageTotalPowerUsage) {
return null
}
Expand Down Expand Up @@ -233,7 +233,7 @@ function createColumns({
width: 160,
render: (row) => {
const assemblyLineComputed =
modularFactoryList.assemblyLineComputedList[row.id]
modularFactoryList.assemblyLineComputedRecord[row.id]
if (!assemblyLineComputed) {
return null
}
Expand All @@ -251,7 +251,7 @@ function createColumns({
width: 160,
render: (row) => {
const assemblyLineComputed =
modularFactoryList.assemblyLineComputedList[row.id]
modularFactoryList.assemblyLineComputedRecord[row.id]
if (!assemblyLineComputed) {
return null
}
Expand Down
27 changes: 18 additions & 9 deletions src/stores/modularFactoryList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => {
direction: 'ltr',
})

const assemblyLineComputedList = computed(() => {
const assemblyLineComputed: Record<Id, AssemblyLineComputed | null> = {}
const assemblyLineComputedRecord = computed(() => {
const _data: Record<Id, AssemblyLineComputed | null> = {}
data.value.forEach(({ data }) => {
data.forEach(
({ id, targetItemId, targetItemSpeed, recipeId, clockSpeed }) => {
if (recipeId && targetItemId && targetItemSpeed && clockSpeed) {
const recipe = getRecipeById(recipeId)
const building = getBuildingById(recipe.producedInId)

// 目标物品每周期生产数量
const targetItemQuantityPerCycle = recipe.outputs.find(
// 配方输出的目标物品对象
const targetOutputItem = recipe.outputs.find(
({ itemId }) => itemId === targetItemId,
)!.quantityPerCycle
)

// 目标物品 和 配方 选择不匹配
if (!targetOutputItem) {
_data[id] = null
return
}

// 目标物品每周期生产数量
const targetItemQuantityPerCycle = targetOutputItem.quantityPerCycle

// 目标物品 100% 频率每分钟生产数量
const targetItemQuantityPerMinutePerBuilding =
Expand Down Expand Up @@ -105,7 +114,7 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => {
},
)

assemblyLineComputed[id] = {
_data[id] = {
buildingId: building.id,
buildingQuantity,
powerUsage,
Expand All @@ -115,12 +124,12 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => {
outputs,
}
} else {
assemblyLineComputed[id] = null
_data[id] = null
}
},
)
})
return assemblyLineComputed
return _data
})

// 自增ID
Expand Down Expand Up @@ -186,7 +195,7 @@ export const useModularFactoryList = defineStore('modularFactoryList', () => {

return {
data,
assemblyLineComputedList,
assemblyLineComputedRecord,
newModularFactory,
deleteModularFactory,
getModularFactory,
Expand Down

0 comments on commit 3a9fdc7

Please sign in to comment.