Skip to content

Commit cb35a2a

Browse files
committed
Enhance DetailsPaneSection and entity rules for improved data representation
- Added a new section type 'crafting_time' in DetailsPaneSection to display crafting time statistics. - Updated entityRules to enhance the getValue functions, providing more detailed statistics and item handling for various entity types. - Refactored conditions to ensure accurate validation of entity types and improve data clarity.
1 parent a6ff248 commit cb35a2a

3 files changed

Lines changed: 149 additions & 30 deletions

File tree

docs/.vitepress/components/DetailsPaneSection.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
</div>
2727
</div>
2828
</template>
29+
<template v-else-if="section.type === 'crafting_time'">
30+
<div :class="$style.section">🕛{{ section.statistics[0]?.value }} s Crafting time</div>
31+
</template>
2932
<template v-else>
3033
<div :class="$style.section">
3134
<h4 :class="$style.sectionTitle">{{ section.label }}</h4>
@@ -34,6 +37,7 @@
3437
<Statistics v-if="section.statistics?.length > 0" :statistics="section.statistics" />
3538

3639
<!-- Items for this section -->
40+
{{ section.items?.length > 0 && section.itemsLabel ? section.itemsLabel + ':' : null }}
3741
<div v-if="section.items?.length > 0" :class="getItemsContainerClass()">
3842
<div
3943
v-for="item in section.items"

src/composables/useDetailsData/entityRules.js

Lines changed: 143 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function parseEnergyString(energyString) {
2020

2121
const unitMultipliers = {
2222
K: 1, // Kilowatts to MW
23-
M: 0.001, // Megawatts (base unit)
24-
G: 0.000001 // Gigawatts to MW
23+
M: 1000, // Megawatts (base unit)
24+
G: 1000000 // Gigawatts to MW
2525
}
2626

2727
const multiplier = unitMultipliers[unit[0]] || 1
@@ -344,7 +344,11 @@ export const entityRules = [
344344
order: 29,
345345
type: 'statistics',
346346
shownInTooltip: false,
347-
getValue: data => data.entity?.resistances,
347+
getValue: data => {
348+
return {
349+
children: data.entity?.resistances.map(a => ({ label: a.type, value: `${a.percent}%` }))
350+
}
351+
},
348352
condition: data => data.entity?.resistances !== undefined
349353
},
350354
{
@@ -386,20 +390,53 @@ export const entityRules = [
386390
type: 'section',
387391
forType: 'entity',
388392
shownInTooltip: true,
389-
getValue: data => {
390-
return { items: [data.entity?.consumes_water] }
391-
data.entity?.consumes_water
393+
getValue: (data, context) => {
394+
//fluid usage = ratio of output to input heat capacity * different between input and output temperature
395+
const fluidName = data.entity?.fluid_box?.filter
396+
const inputFluid = context.factorioData.fluid[fluidName]
397+
398+
const inputHeatCapacity = parseEnergyString(inputFluid?.heat_capacity)
399+
const temperatureDifference = data.entity?.target_temperature - 15 //might be min temperature of the input
400+
const power = parseEnergyString(data.entity?.energy_consumption)
401+
const fluidUsage =
402+
power.normalizedValue / (inputHeatCapacity.normalizedValue * temperatureDifference)
403+
return {
404+
statistics: [{ label: labels.fluid_consumption, value: fluidUsage }],
405+
items: [{ name: fluidName, type: 'fluid' }],
406+
itemsLabel: 'Accepted fluid',
407+
itemsType: 'grid'
408+
}
392409
},
393-
condition: data => data.entity?.consumes_water !== undefined
410+
condition: data => data.entity?.type === 'boiler'
394411
},
395412
{
396413
name: sectionTypes.equipment_grid,
397414
order: 4,
398415
type: 'section',
399416
forType: 'entity',
400417
shownInTooltip: true,
401-
getValue: data => {
402-
return { items: [data.entity?.equipment_grid] }
418+
getValue: (data, context) => {
419+
const equipmentGridName = data.entity?.equipment_grid
420+
const equipmentGrid = context.factorioData['equipment-grid'][equipmentGridName]
421+
//is array
422+
const equipment_categories = equipmentGrid?.equipment_categories
423+
424+
const equipmentItems = Object.values(context.factorioData.equipment)
425+
const equipmentGridItems = equipmentItems
426+
.filter(equipment =>
427+
equipment?.categories?.some(category => equipment_categories.includes(category))
428+
)
429+
.map(equipment => ({ name: equipment.name, type: 'equipment' }))
430+
return {
431+
statistics: [
432+
{
433+
label: labels.equipment_grid_size,
434+
value: `${equipmentGrid.width}x${equipmentGrid.height}`
435+
}
436+
],
437+
items: equipmentGridItems,
438+
itemsType: 'grid'
439+
}
403440
},
404441
condition: data => data.entity?.equipment_grid !== undefined
405442
},
@@ -431,21 +468,50 @@ export const entityRules = [
431468
type: 'section',
432469
forType: 'entity',
433470
shownInTooltip: true,
434-
getValue: data => {
435-
return { items: [data.entity?.burnable_fuel] }
471+
getValue: (data, context) => {
472+
const chemicalFuels = Object.values(context.factorioData.item)
473+
.filter(item => item.fuel_category === 'chemical')
474+
.map(item => ({ name: item.name, type: 'item' }))
475+
return {
476+
statistics: [
477+
{
478+
label: labels.max_consumption,
479+
value: data.entity?.energy_consumption || data.entity?.consumption
480+
}
481+
],
482+
items: chemicalFuels,
483+
itemsLabel: 'Accepted fuel',
484+
itemsType: 'grid'
485+
}
436486
},
437-
condition: data => data.entity?.burnable_fuel !== undefined
487+
condition: data =>
488+
data.entity?.energy_source?.type === 'burner' &&
489+
data.entity?.energy_source?.fuel_categories?.includes('chemical')
438490
},
439491
{
440492
name: sectionTypes.generates_steam,
441493
order: 8,
442494
type: 'section',
443495
forType: 'entity',
444496
shownInTooltip: true,
445-
getValue: data => {
446-
return { items: [data.entity?.generates_steam] }
497+
getValue: (data, context) => {
498+
//fluid usage = ratio of output to input heat capacity * different between input and output temperature
499+
const fluidName = data.entity?.output_fluid_box?.filter
500+
const outputFluid = context.factorioData.fluid[fluidName]
501+
502+
const outputHeatCapacity = parseEnergyString(outputFluid?.heat_capacity)
503+
const temperatureDifference = data.entity?.target_temperature - 15 //15 might be min temperature of the input
504+
const power = parseEnergyString(data.entity?.energy_consumption)
505+
const fluidUsage =
506+
power.normalizedValue / (outputHeatCapacity.normalizedValue * temperatureDifference)
507+
return {
508+
statistics: [{ label: labels.fluid_output, value: fluidUsage }],
509+
items: [{ name: fluidName, type: 'fluid' }],
510+
itemsLabel: 'Result fluid',
511+
itemsType: 'grid'
512+
}
447513
},
448-
condition: data => data.entity?.generates_steam !== undefined
514+
condition: data => data.entity?.type === 'boiler'
449515
},
450516
{
451517
name: sectionTypes.consumes_steam,
@@ -470,7 +536,8 @@ export const entityRules = [
470536
{ label: labels.fluid_consumption, value: data.entity?.fluid_usage_per_tick * 60 },
471537
{ label: labels.fluid_max_temperature, value: data.entity?.maximum_temperature }
472538
],
473-
items: [workingFluid]
539+
items: [workingFluid],
540+
itemsLabel: 'Accepted fluid'
474541
}
475542
},
476543
condition: data => data.entity?.fluid_usage_per_tick !== undefined
@@ -482,9 +549,15 @@ export const entityRules = [
482549
forType: 'entity',
483550
shownInTooltip: true,
484551
getValue: data => {
485-
return { items: [data.entity?.stores_electricity] }
552+
return {
553+
statistics: [
554+
{ label: labels.energy_capacity, value: data.entity?.energy_source?.buffer_capacity },
555+
{ label: labels.max_input, value: data.entity?.energy_source?.input_flow_limit },
556+
{ label: labels.max_output, value: data.entity?.energy_source?.output_flow_limit }
557+
]
558+
}
486559
},
487-
condition: data => data.entity?.stores_electricity !== undefined
560+
condition: data => data.entity?.type === 'accumulator'
488561
},
489562
{
490563
name: sectionTypes.consumes_nuclear_fuel,
@@ -493,9 +566,18 @@ export const entityRules = [
493566
forType: 'entity',
494567
shownInTooltip: true,
495568
getValue: data => {
496-
return { items: [data.entity?.consumes_nuclear_fuel] }
569+
return {
570+
statistics: [
571+
{
572+
label: labels.nuclear_fuel_consumption,
573+
value: data.entity?.consumption
574+
}
575+
]
576+
}
497577
},
498-
condition: data => data.entity?.consumes_nuclear_fuel !== undefined
578+
condition: data =>
579+
data.entity?.energy_source?.type === 'burner' &&
580+
data.entity?.energy_source?.fuel_categories?.includes('nuclear')
499581
},
500582
{
501583
name: sectionTypes.generates_heat,
@@ -504,9 +586,14 @@ export const entityRules = [
504586
forType: 'entity',
505587
shownInTooltip: true,
506588
getValue: data => {
507-
return { items: [data.entity?.generates_heat] }
589+
return {
590+
statistics: [
591+
{ label: labels.heat_generation, value: data.entity?.consumption },
592+
{ label: labels.neighbour_bonus, value: data.entity?.neighbour_bonus }
593+
]
594+
}
508595
},
509-
condition: data => data.entity?.generates_heat !== undefined
596+
condition: data => data.entity.type === 'reactor'
510597
},
511598
{
512599
name: sectionTypes.consumes_heat,
@@ -515,9 +602,14 @@ export const entityRules = [
515602
forType: 'entity',
516603
shownInTooltip: true,
517604
getValue: data => {
518-
return { items: [data.entity?.consumes_heat] }
605+
return {
606+
statistics: [
607+
{ label: labels.energy_consumption, value: data.entity?.energy_consumption },
608+
{ label: labels.min_temperature, value: data.entity?.energy_source?.min_temperature }
609+
]
610+
}
519611
},
520-
condition: data => data.entity?.consumes_heat !== undefined
612+
condition: data => data.entity?.energy_source && data.entity?.energy_source.type === 'heat'
521613
},
522614
{
523615
name: sectionTypes.consumes_electricity,
@@ -526,20 +618,42 @@ export const entityRules = [
526618
forType: 'entity',
527619
shownInTooltip: true,
528620
getValue: data => {
529-
return { items: [data.entity?.consumes_electricity] }
621+
const energyUsage = parseEnergyString(data.entity?.energy_usage)
622+
const minConsumption = Math.ceil(energyUsage.normalizedValue * 0.03) //afaik 3% is min consumption
623+
const maxConsumption = Math.ceil(energyUsage.normalizedValue * 1.03)
624+
return {
625+
statistics: [
626+
{ label: labels.max_consumption, value: maxConsumption },
627+
{ label: labels.min_consumption, value: minConsumption }
628+
]
629+
}
530630
},
531-
condition: data => data.entity?.consumes_electricity !== undefined
631+
condition: data =>
632+
data.entity?.energy_source &&
633+
data.entity?.energy_source.type === 'electric' &&
634+
data.entity.energy_usage
532635
},
533636
{
534637
name: sectionTypes.generates_electricity,
535638
order: 15,
536639
type: 'section',
537640
forType: 'entity',
538641
shownInTooltip: true,
539-
getValue: data => {
540-
return { items: [data.entity?.generates_electricity] }
642+
getValue: (data, context) => {
643+
if (data.entity?.type === 'solar-panel')
644+
return { statistics: [{ label: labels.max_output, value: data.entity?.production }] }
645+
else {
646+
const fluidName = data.entity?.fluid_box?.filter
647+
const fluid = context.factorioData.fluid[fluidName]
648+
const fluidAmount = data.entity?.fluid_usage_per_tick
649+
const fluidTemperature = data.entity?.maximum_temperature
650+
const fluidHeatCapacity = parseEnergyString(fluid?.heat_capacity)
651+
652+
const power = fluidAmount * (fluidTemperature - 15) * fluidHeatCapacity.normalizedValue * 60
653+
return { statistics: [{ label: labels.max_output, value: power }] }
654+
}
541655
},
542-
condition: data => data.entity?.generates_electricity !== undefined
656+
condition: data => data.entity?.energy_source && data.entity?.energy_source.type === 'electric'
543657
}
544658
]
545659

src/composables/useDetailsData/recipeRules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export const recipeRules = [
3232
forType: 'recipe',
3333
shownInTooltip: true,
3434
getValue: data => ({
35-
statistics: [{ label: labels.crafting_time, value: data.recipe?.energy_required }]
35+
statistics: [{ label: labels.crafting_time, value: data.recipe?.energy_required }],
36+
type: 'crafting_time'
3637
}),
3738
condition: data => data.recipe?.energy_required !== undefined
3839
},

0 commit comments

Comments
 (0)