Skip to content
Permalink
Browse files

Fix display of aetherized and added cards (#703)

* Fix display of aetherized and added cards
  • Loading branch information
Thaoden authored and Manuel-777 committed Nov 10, 2019
1 parent 4568998 commit 14e12665e5b0ee9a88a1c20fbb6ed585e923931e
Showing with 48 additions and 31 deletions.
  1. +48 −31 src/window_main/components/economy/EconomyRow.tsx
@@ -27,7 +27,7 @@ function EconomyRowDate(date: Date) {
}

interface BoosterDeltaProps {
booster: { collationId: string, count: number};
booster: { collationId: string, count: number };
}

function BoosterDelta(props: BoosterDeltaProps) {
@@ -78,24 +78,24 @@ function getThingsToCheck(fullContext: string, change: any): PossibleModifiedEco
fullContext.includes("Store") ||
fullContext.includes("Purchase")
) ? {
checkGemsEarnt: (change.delta.gemsDelta > 0),
checkGemsPaid: (change.delta.gemsDelta < 0),
checkGoldEarnt: (change.delta.goldDelta > 0),
checkGoldPaid: (change.delta.goldDelta < 0),
checkBoosterAdded: true,
checkCardsAdded: true,
checkAetherized: true,
checkWildcardsAdded: true,
checkSkinsAdded: true,
} : {
checkGemsEarnt: true,
checkGoldEarnt: true,
checkBoosterAdded: true,
checkCardsAdded: true,
checkAetherized: true,
checkWildcardsAdded: true,
checkSkinsAdded: true,
}
checkGemsEarnt: (change.delta.gemsDelta > 0),
checkGemsPaid: (change.delta.gemsDelta < 0),
checkGoldEarnt: (change.delta.goldDelta > 0),
checkGoldPaid: (change.delta.goldDelta < 0),
checkBoosterAdded: true,
checkCardsAdded: true,
checkAetherized: true,
checkWildcardsAdded: true,
checkSkinsAdded: true,
} : {
checkGemsEarnt: true,
checkGoldEarnt: true,
checkBoosterAdded: true,
checkCardsAdded: true,
checkAetherized: true,
checkWildcardsAdded: true,
checkSkinsAdded: true,
}
}
}

@@ -161,26 +161,43 @@ interface CardPoolAddedEconomyValueRecordProps {
aetherizedCardIds: string[];
}

function countDupesArray(array: string[]): Record<string, number> {
const counted: Record<string, number> = {};
function countDupesArray(array: string[] | undefined): Record<string, number> {
if (!array) {
return {};
}
const counted: Record<string, number> = {};
array.forEach((value) => {
counted[value] = counted[value] ? counted[value] + 1 : 1;
});
return counted;
}

interface InventoryCardListProps {
cardsList: string[];
isAetherized: boolean;
}

function CardPoolAddedEconomyValueRecord(props: CardPoolAddedEconomyValueRecordProps) {
const { addedCardIds, aetherizedCardIds } = props;
const addedUniques = (addedCardIds.length > 0) ? countDupesArray(addedCardIds) : undefined;
const aetherUniques = (aetherizedCardIds.length > 0) ? countDupesArray(aetherizedCardIds) : undefined;

return (<>
<InventoryCardList cardsList={addedCardIds} isAetherized={false} />
<InventoryCardList cardsList={aetherizedCardIds} isAetherized={true} />
</>);
}

function InventoryCardList(props: InventoryCardListProps) {
const { cardsList, isAetherized } = props;
const uniqueCardList = countDupesArray(cardsList);

return (
<>
{addedUniques && Object.entries(addedUniques).map((entry: [string, number]) => <InventoryCard key={entry[0]} card={db.card(entry[0])} quantity={entry[1]} />)}
{aetherUniques && Object.entries(aetherUniques).map((entry: [string, number]) => <InventoryCard key={entry[0]} card={db.card(entry[0])} quantity={entry[1]} isAetherized={true}/>)}
{Object.entries(uniqueCardList).map((entry: [string, number]) => <InventoryCard key={entry[0]} card={db.card(entry[0])} quantity={entry[1]} isAetherized={isAetherized} />)}
</>
)
}


interface FlexRightProps {
fullContext: string;
change: any;
@@ -198,7 +215,7 @@ function FlexRight(props: FlexRightProps) {

const orbDelta = change.orbCountDiff && Math.abs(
(change.orbCountDiff.currentOrbCount || 0) -
(change.orbCountDiff.oldOrbCount || 0)
(change.orbCountDiff.oldOrbCount || 0)
);

const checkCards = checkCardsAdded && change.delta.cardsAdded && change.delta.cardsAdded.length > 0;
@@ -221,7 +238,7 @@ function FlexRight(props: FlexRightProps) {
}
return aggregator;
}
, []) : [];
, []) : [];

const checkSkins = checkSkinsAdded && change.delta.artSkinsAdded !== undefined;
const skinsToCards = checkSkins ? change.delta.artSkinsAdded.map((obj: { artId: string }) => db.cardFromArt(obj.artId)) : undefined;
@@ -237,7 +254,7 @@ function FlexRight(props: FlexRightProps) {
{!!xpGainedNumber && <EconomyValueRecord iconClassName={"economy_exp"} title={"Experience"} deltaContent={formatNumber(xpGainedNumber)} />}
{checkBoosterAdded && change.delta.boosterDelta && change.delta.boosterDelta.map((booster: any) => <BoosterDelta booster={booster} key={booster.collationId} />)}
{checkWildcardsAdded && <AllWildcardsEconomyValueRecord delta={change.delta} />}
{(checkCards || checkAether) && <CardPoolAddedEconomyValueRecord addedCardIds={change.delta.cardsAdded} aetherizedCardIds={aetherCards}/>}
{(checkCards || checkAether) && <CardPoolAddedEconomyValueRecord addedCardIds={change.delta.cardsAdded} aetherizedCardIds={aetherCards} />}
{skinsToCards && skinsToCards.map((card: any) => <EconomyIcon key={card.name} title={card.name + " Skin"} className={"economy_skin_art"} url={`url("${getCardArtCrop(card)}")`} />)}
</div>
)
@@ -267,7 +284,7 @@ function InventoryCard(props: InventoryCardProps) {
const tooltip = isAetherized ? computeAetherizedTooltip(card, quantity) : card.name;
return (
<div ref={inventoryCardRef} className={"inventory_card small"} onClick={onCardClick}>
<img className={"inventory_card_img 39px" + (isAetherized ? " inventory_card_aetherized" : "")} src={getCardImage(card)} title={tooltip}/>
<img className={"inventory_card_img 39px" + (isAetherized ? " inventory_card_aetherized" : "")} src={getCardImage(card)} title={tooltip} />
{(quantity && quantity > 1) && <div className={"inventory_card_quantity_container"}>
<span className={"inventory_card_quantity"}>{"x" + quantity}</span>
</div>}
@@ -328,7 +345,7 @@ function DeleteButton(props: DeleteButtonProps) {
const title = change.archived
? "restore"
: "archive (will not delete data)";

const archiveCallback = React.useCallback((e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
if (!change.archived) {
@@ -380,7 +397,7 @@ function ChangeRow(props: ChangeRowProps) {
<FlexBottom {...flexBottomProps} />
</div>
<FlexRight {...flexRightProps} />
<DeleteButton change={change} economyId={economyId} hideRowCallback={hideRowCallback}/>
<DeleteButton change={change} economyId={economyId} hideRowCallback={hideRowCallback} />
</div>
)
}

0 comments on commit 14e1266

Please sign in to comment.
You can’t perform that action at this time.