Skip to content

Commit 8e72fb5

Browse files
committed
Enhance data handling and validation in entity and recipe rules
- Updated entity rules to ensure minable results are validated before processing. - Improved recipe rules to handle undefined unit properties and ensure proper ingredient mapping. - Enhanced technology rules to check for prerequisites and unit definitions, improving data integrity. - Updated localization data with new generated timestamps and fixed minor formatting issues in JSON files.
1 parent ab9d036 commit 8e72fb5

6 files changed

Lines changed: 37 additions & 24 deletions

File tree

docs/.vitepress/components/Factoriopedia.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const groupedRecipes = computed(() => {
166166
.map(subgroup => ({
167167
...subgroup,
168168
recipes: subgroup.recipes.filter(recipe =>
169-
recipe.displayName.toLowerCase().includes(query)
169+
recipe.displayName?.toLowerCase()?.includes(query)
170170
)
171171
}))
172172
.filter(subgroup => subgroup.recipes.length > 0)
@@ -194,7 +194,9 @@ const disabledFilters = computed(() => {
194194
const filteredSubgroups = categoryData.subgroups
195195
.map(subgroup => ({
196196
...subgroup,
197-
recipes: subgroup.recipes.filter(recipe => recipe.displayName.toLowerCase().includes(query))
197+
recipes: subgroup.recipes.filter(recipe =>
198+
recipe.displayName?.toLowerCase()?.includes(query)
199+
)
198200
}))
199201
.filter(subgroup => subgroup.recipes.length > 0)
200202

docs/public/data/en-tooltips.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/public/data/rule-failure-report.json

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/composables/useDetailsData/entityRules.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ export const entityRules = [
554554
results = results?.filter(result => result.name !== data.entity.name)
555555
return { items: results, itemsType: 'list' }
556556
},
557-
condition: data => data.entity?.minable,
557+
condition: data => data.entity?.minable && data.entity?.minable?.results?.length > 0,
558558
postCondition: data => data?.items?.length > 0
559559
},
560560
{
@@ -806,9 +806,10 @@ export const entityRules = [
806806
}
807807
},
808808
condition: data =>
809-
data.entity.type != 'inserter' &&
809+
data.entity.type !== 'inserter' &&
810810
data.entity?.energy_source?.type === 'burner' &&
811-
data.entity?.energy_source?.fuel_categories?.includes('chemical')
811+
data.entity?.energy_source?.fuel_categories?.includes('chemical') &&
812+
data.entity?.energy_consumption !== undefined
812813
},
813814
{
814815
name: sectionTypes.generates_steam,

src/composables/useDetailsData/recipeRules.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const recipeRules = [
4949
getValue: data => ({
5050
items: data.recipe?.results?.map(result => {
5151
let amountText = ''
52-
52+
5353
// Handle different amount types
5454
if (result.amount !== undefined) {
5555
// Simple amount
@@ -62,13 +62,13 @@ export const recipeRules = [
6262
amountText = `${result.amount_min}-${result.amount_max}`
6363
}
6464
}
65-
65+
6666
// Add probability if present and not 1
6767
if (result.probability !== undefined && result.probability !== 1) {
6868
const probabilityPercent = Math.round(result.probability * 100)
6969
amountText += ` (${probabilityPercent}%)`
7070
}
71-
71+
7272
return {
7373
name: result.name,
7474
type: result.type,
@@ -120,7 +120,10 @@ export const recipeRules = [
120120
)?.length > 0
121121
)
122122
.map(technology => {
123-
const items = technology.unit?.ingredients?.map(ingredient => ({
123+
// todo deal with unit not being defined
124+
const ingredients =
125+
technology.unit?.ingredients.length > 0 ? technology.unit.ingredients : []
126+
const items = ingredients.map(ingredient => ({
124127
name: ingredient[0],
125128
type: 'item',
126129
amount: ingredient[1]

src/composables/useDetailsData/technologyRules.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const technologyRules = [
3030
]
3131
}
3232
},
33-
condition: data => data.technology.unit !== undefined
33+
condition: data => data.technology.unit !== undefined && data.technology.unit?.length > 0
3434
},
3535
{
3636
name: sectionTypes.technology_effects,
@@ -69,6 +69,7 @@ export const technologyRules = [
6969
.map(technology => ({ name: technology.name, type: 'technology' }))
7070
return { items: prerequisites }
7171
},
72+
condition: data => data.technology.prerequisites?.length > 0,
7273
postCondition: data => data.items?.length > 0
7374
},
7475
{
@@ -80,7 +81,11 @@ export const technologyRules = [
8081
getValue: (data, context) => {
8182
const technologies = Object.values(context.factorioData.technology)
8283
const descendants = technologies
83-
.filter(technology => technology.prerequisites?.includes(data.technology.name))
84+
.filter(
85+
technology =>
86+
technology?.prerequisites?.length > 0 &&
87+
technology.prerequisites?.includes(data.technology.name)
88+
)
8489
.map(technology => ({ name: technology.name, type: 'technology' }))
8590
return { items: descendants, itemsType: 'grid' }
8691
},

0 commit comments

Comments
 (0)