From b2037776fee69acb9ece0fe5c4d7ffce76224b66 Mon Sep 17 00:00:00 2001 From: Petr Vecera Date: Tue, 1 Oct 2024 15:23:23 +0200 Subject: [PATCH] Small UI tweaks on the units page (#600) * Small ui tweaks * De-duplicate abilities --- .../unit-cards/unit-description-card.tsx | 14 +++++-- .../races/[raceId]/units/[unitId].tsx | 41 ++++++++++++------- pages/explorer/races/[raceId]/units/index.tsx | 3 +- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/components/unit-cards/unit-description-card.tsx b/components/unit-cards/unit-description-card.tsx index cee8c5fc..0e096f83 100644 --- a/components/unit-cards/unit-description-card.tsx +++ b/components/unit-cards/unit-description-card.tsx @@ -32,20 +32,26 @@ export type UnitDescription = { export const UnitDescriptionCard = ({ desc, faction, + list, }: { desc: UnitDescription; faction: raceType; + list?: boolean; // Specifies if the description card is used in the list of all units or in unit details }) => { const factionBackgroundSrc = BattlegroupBackgrounds[faction]; const spaceRegex = /\\r?\\n|\\r|\\n/g; const specialRegex = /\*/g; + const regexDot = /•/g; - const briefText = desc.brief_text?.replace(spaceRegex, "\n")?.replace(specialRegex, ""); + const briefText = desc.brief_text + ?.replace(spaceRegex, "\n") + ?.replace(specialRegex, "") + .replace(regexDot, "• "); return ( <> - + - - + + {briefText} diff --git a/pages/explorer/races/[raceId]/units/[unitId].tsx b/pages/explorer/races/[raceId]/units/[unitId].tsx index aef82587..f3444a65 100644 --- a/pages/explorer/races/[raceId]/units/[unitId].tsx +++ b/pages/explorer/races/[raceId]/units/[unitId].tsx @@ -159,7 +159,6 @@ const UnitDetail: NextPage = ({ calculatedData }) => { /> - @@ -167,10 +166,10 @@ const UnitDetail: NextPage = ({ calculatedData }) => { {descriptionRace} - + - + = ({ calculatedData }) => { Stats - + {UnitSquadCard({ id: resolvedSquad.id, type: resolvedSquad.unitType, @@ -210,7 +209,7 @@ const UnitDetail: NextPage = ({ calculatedData }) => { Stats - + {UnitCostCard(totalCost)} {defaultSquadMember.unitType !== "vehicles" && defaultSquadMember.unitType !== "emplacements" ? ( @@ -219,18 +218,18 @@ const UnitDetail: NextPage = ({ calculatedData }) => { <> )} - + {HitpointCard({ squad: resolvedSquad, entities: resolvedEntities })} - + {UnitCostCard(totalUpkeepCost, "Upkeep per minute")} - + + /> @@ -286,7 +285,7 @@ const UnitBuildingSection = (buildings: EbpsType[]) => { // If we are missing the name of the ability --> it's most likely broken if (ui.screenName) { return ( - + {ConstructableCard({ id, desc: { @@ -314,6 +313,7 @@ const UnitBuildingSection = (buildings: EbpsType[]) => { const UnitAbilitySection = (abilities: AbilitiesType[]) => { // Resolve unit abilities. if (!abilities || !abilities.length) return <>; + return ( Abilities @@ -322,7 +322,7 @@ const UnitAbilitySection = (abilities: AbilitiesType[]) => { // If we are missing the name of the ability --> it's most likely broken if (ui.screenName) { return ( - + {UnitUpgradeCard({ id, desc: { @@ -408,12 +408,12 @@ const createdCalculateValuesForUnits = ( const upgrades = Object.values(getResolvedUpgrades(resolvedSquad.upgrades, upgradesData)); - const abilities = Object.values(getResolvedAbilities(resolvedSquad.abilities, abilitiesData)); + const rawAbilities = Object.values( + getResolvedAbilities(resolvedSquad.abilities, abilitiesData), + ); const buildables = Object.values(getResolvedConstruction(resolvedSquad.construction, ebpsData)); - // console.log('Calculated abilities', resolvedSquad); - const resolvedEntities: EbpsType[] = []; for (const loadout of resolvedSquad.loadout || []) { @@ -424,6 +424,19 @@ const createdCalculateValuesForUnits = ( } } + // Some abilities are duplicated, they have different IDs but the name and description is the same. + // IF the UI is completely the same, we can remove the duplicates. + // This might lead to some bugs in case other parts would be different. + const abilities: AbilitiesType[] = []; + for (const ability of rawAbilities) { + // If we are missing the name of the ability --> it's most likely broken // remove it here so we save the data + if (ability.ui.screenName) { + if (!abilities.find((x) => JSON.stringify(x.ui) === JSON.stringify(ability.ui))) { + abilities.push(ability); + } + } + } + return { resolvedSquad, totalCost, diff --git a/pages/explorer/races/[raceId]/units/index.tsx b/pages/explorer/races/[raceId]/units/index.tsx index b6a719b1..8f8acf6c 100644 --- a/pages/explorer/races/[raceId]/units/index.tsx +++ b/pages/explorer/races/[raceId]/units/index.tsx @@ -77,7 +77,7 @@ const ExplorerUnits: NextPage = ({ units, raceToFetch }) => { component={LinkWithOutPrefetch} href={getExplorerUnitRoute(raceToFetch, id)} > - + = ({ units, raceToFetch }) => { symbol_icon_name: ui.symbolIconName, icon_name: ui.iconName, }} + list />