From 89f615a2192175ee0b49941db9c899d067a33fc0 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 11 May 2024 14:41:30 +0200 Subject: [PATCH] chore: in calculation details, show better when an effect isn't applied (#107) --- .../CalculationDetail.module.css | 4 + src/CalculationDetail/CalculationDetail.tsx | 111 ++++++++++++------ 2 files changed, 80 insertions(+), 35 deletions(-) diff --git a/src/CalculationDetail/CalculationDetail.module.css b/src/CalculationDetail/CalculationDetail.module.css index 0c68bc6..14c57d8 100644 --- a/src/CalculationDetail/CalculationDetail.module.css +++ b/src/CalculationDetail/CalculationDetail.module.css @@ -53,3 +53,7 @@ .line:nth-child(odd) { background-color: #f2f2f2; } + +.notApplied { + background-color: #ffcccc; +} diff --git a/src/CalculationDetail/CalculationDetail.tsx b/src/CalculationDetail/CalculationDetail.tsx index 0ca4f9c..ffc3d18 100644 --- a/src/CalculationDetail/CalculationDetail.tsx +++ b/src/CalculationDetail/CalculationDetail.tsx @@ -23,6 +23,29 @@ const EffectOperatorOrder: Record = { PostAssignment: "=", }; +function stateToInteger(state: string): number { + switch (state) { + case "Passive": + return 0; + case "Online": + return 1; + case "Active": + return 2; + case "Overload": + return 3; + case "Target": + return 4; + case "Area": + return 5; + case "Dungeon": + return 6; + case "System": + return 7; + default: + return 8; + } +} + const Effect = (props: { effect: ShipSnapshotItemAttributeEffect }) => { const eveData = React.useContext(EveDataContext); const shipSnapshot = React.useContext(ShipSnapshotContext); @@ -31,54 +54,72 @@ const Effect = (props: { effect: ShipSnapshotItemAttributeEffect }) => { let sourceName = "Unknown"; let attribute = undefined; + let applied = true; - if (props.effect.source === "Ship") { - sourceName = "Ship"; - attribute = shipSnapshot.hull?.attributes.get(props.effect.source_attribute_id); - } else if (props.effect.source === "Char") { - sourceName = "Char"; - attribute = shipSnapshot.char?.attributes.get(props.effect.source_attribute_id); - } else if (props.effect.source === "Structure") { - sourceName = "Structure"; - attribute = shipSnapshot.structure?.attributes.get(props.effect.source_attribute_id); - } else if (props.effect.source === "Target") { - sourceName = "Target"; - attribute = shipSnapshot.target?.attributes.get(props.effect.source_attribute_id); - } else { - let item = undefined; - let sourceType = undefined; + switch (props.effect.source) { + case "Ship": + sourceName = "Ship"; + attribute = shipSnapshot.hull?.attributes.get(props.effect.source_attribute_id); + break; - /* Lookup the source of the effect. */ - if (props.effect.source.Item !== undefined) { - item = shipSnapshot.items?.[props.effect.source.Item]; - sourceType = "Item"; - } else if (props.effect.source.Skill !== undefined) { - item = shipSnapshot.skills?.[props.effect.source.Skill]; - sourceType = "Skill"; - } else if (props.effect.source.Charge !== undefined) { - item = shipSnapshot.items?.[props.effect.source.Charge].charge; - sourceType = "Charge"; - } + case "Char": + sourceName = "Character"; + attribute = shipSnapshot.char?.attributes.get(props.effect.source_attribute_id); + break; - /* Find the attribute on the source. */ - if (item === undefined) { - sourceName = `Unknown ${sourceType}`; - } else { - sourceName = `${sourceType} - ` + (eveData.typeIDs?.[item?.type_id]?.name ?? sourceName); - attribute = item?.attributes.get(props.effect.source_attribute_id); - } + case "Structure": + sourceName = "Structure"; + attribute = shipSnapshot.structure?.attributes.get(props.effect.source_attribute_id); + break; + + case "Target": + sourceName = "Target"; + attribute = shipSnapshot.target?.attributes.get(props.effect.source_attribute_id); + break; + + default: + let item = undefined; + let sourceType = undefined; + + /* Lookup the source of the effect. */ + if (props.effect.source.Item !== undefined) { + item = shipSnapshot.items?.[props.effect.source.Item]; + sourceType = "Item"; + } else if (props.effect.source.Skill !== undefined) { + item = shipSnapshot.skills?.[props.effect.source.Skill]; + sourceType = "Skill"; + } else if (props.effect.source.Charge !== undefined) { + item = shipSnapshot.items?.[props.effect.source.Charge].charge; + sourceType = "Charge"; + } + + /* Find the attribute on the source. */ + if (item === undefined) { + sourceName = `Unknown ${sourceType}`; + } else { + sourceName = `${sourceType}: ` + (eveData.typeIDs?.[item?.type_id]?.name ?? sourceName); + attribute = item?.attributes.get(props.effect.source_attribute_id); + + const itemState = stateToInteger(item.state); + const sourceState = stateToInteger(props.effect.source_category); + if (itemState < sourceState) { + applied = false; + } + } + break; } return ( -
+
{EffectOperatorOrder[props.effect.operator]} - {attribute?.value || eveAttribute?.defaultValue} + {attribute?.value ?? eveAttribute?.defaultValue} {props.effect.penalty ? " (penalized)" : ""} {attribute?.value === undefined ? " (default)" : ""} {sourceName} - {eveAttribute?.name} + {!applied && " (not applied)"}
);