Skip to content

Commit

Permalink
Fix oz choosing decks (#649)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Salinas <[email protected]>
  • Loading branch information
zzorba and Daniel Salinas authored Feb 22, 2025
1 parent b36e17b commit 0c3dc82
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/campaign/CampaignDetailView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type AsyncDispatch = ThunkDispatch<AppState, unknown, Action>;

function CampaignDetailView(props: Props) {
const { componentId, upload } = props;

const [textEditDialog, showTextEditDialog] = useTextEditDialog();
const [countDialog, showCountDialog] = useCountDialog();
const [campaignId, setCampaignServerId, uploadingCampaign] = useCampaignId(props.campaignId);
Expand Down Expand Up @@ -172,7 +173,6 @@ function CampaignDetailView(props: Props) {
if (!campaign) {
return;
}
console.log(`Show choose deck: `, singleInvestigator?.code);
const passProps: MyDecksSelectorProps = singleInvestigator ? {
campaignId: campaign.id,
singleInvestigator: singleInvestigator.alternate_of_code ?? singleInvestigator.code,
Expand Down
3 changes: 2 additions & 1 deletion src/components/campaign/CampaignDrawWeaknessDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Navigation, OptionsModalPresentationStyle } from 'react-native-navigati
import { ThunkDispatch } from 'redux-thunk';
import { t } from 'ttag';

import { CampaignId, Deck, getDeckId, Slots } from '@actions/types';
import { CampaignId, Deck, getDeckId, OZ, Slots } from '@actions/types';
import { updateCampaignWeaknessSet } from './actions';
import { NavigationProps } from '@components/nav/types';
import BasicButton from '@components/core/BasicButton';
Expand Down Expand Up @@ -140,6 +140,7 @@ export default function CampaignDrawWeaknessDialog(props: Props) {
onDeckSelect: selectDeck,
selectedDecks: latestDecks,
onlyShowSelected: true,
includeParallel: campaign?.cycleCode === OZ,
};
Navigation.showModal({
stack: {
Expand Down
1 change: 1 addition & 0 deletions src/components/campaign/InvestigatorCampaignRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export default function InvestigatorCampaignRow({
open={open}
badge={badge || (upgradeBadge ? 'upgrade' : undefined)}
width={width - s * 2}
showParallel={campaignGuide?.includeParallelInvestigators()}
headerContent={!open && (
<View style={styles.trauma}>
<TraumaSummary trauma={traumaAndCardData} investigator={investigator} whiteText />
Expand Down
2 changes: 1 addition & 1 deletion src/components/campaign/UpgradeDecksView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function UpgradeDecksView({ componentId, id }: UpgradeDecksProps & NavigationPro
const dispatch = useAppDispatch();
const campaign = useCampaign(id);
const [allInvestigators] = useCampaignInvestigators(campaign);
const latestDecks = campaign?.latestDecks() || EMPTY_DECKS;
const latestDecks = campaign?.latestDecks() ?? EMPTY_DECKS;
const lang = useSelector(getLangPreference);
const updateCampaignActions = useUpdateCampaignActions();
const originalDeckUuids = useRef(new Set(map(latestDecks, deck => deck.id.uuid)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function AliveInvestigatorRow({
campaign={campaign}
campaignGuide={campaignGuide}
badge={nextDeckUpgradeStepId ? 'deck' : undefined}
spentXp={spentXp[investigator.code] || 0}
spentXp={spentXp[investigator.code] ?? 0}
totalXp={processedCampaign.campaignLog.totalXp(investigator.code)}
unspentXp={processedCampaign.campaignLog.specialXp(investigator.code, 'unspect_xp')}
deck={deck}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
CampaignId,
DelayedDeckEdits,
EmbarkData,
OZ,
} from '@actions/types';
import Card, { CardsMap } from '@data/types/Card';
import useChooseDeck from './useChooseDeck';
Expand All @@ -45,6 +46,8 @@ export default function useCampaignGuideContextFromActions(
const dispatch: AsyncDispatch = useDispatch();
const [campaignChooseDeck, campaignAddInvestigator] = useChooseDeck(createDeckActions, updateCampaignActions);
const cycleCode = campaignData?.campaign?.cycleCode;
const includeParallel = cycleCode === OZ;

const showChooseDeck = useCallback((singleInvestigator?: Card, callback?: (code: string) => Promise<void>) => {
if (campaignInvestigators !== undefined) {
campaignChooseDeck(campaignId, cycleCode, campaignInvestigators, singleInvestigator, callback);
Expand Down Expand Up @@ -209,8 +212,9 @@ export default function useCampaignGuideContextFromActions(
[code: string]: LatestDeckT | undefined;
} = {};
forEach(latestDecks, deck => {
if (deck && deck.investigator) {
decksByInvestigator[deck.investigator] = deck;
const investigatorCode = includeParallel ? deck.deck.meta?.alternate_front ?? deck.investigator : deck.investigator;
if (deck && investigatorCode) {
decksByInvestigator[investigatorCode] = deck;
}
});
return decksByInvestigator;
Expand Down
8 changes: 5 additions & 3 deletions src/components/campaignguide/useChooseDeck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export default function useChooseDeck(createDeckActions: DeckActions, updateActi
singleInvestigator?: Card,
callback?: (code: string) => Promise<void>
) => {
const includeParallel = cycleCode === OZ;
const onDeckSelect = async(deck: Deck) => {
await doAddInvestigator(campaignId, singleInvestigator?.code ?? deck.investigator_code, getDeckId(deck));
const investigatorCode = includeParallel ? deck.meta?.alternate_front ?? deck.investigator_code : singleInvestigator?.code ?? deck.investigator_code;
await doAddInvestigator(campaignId, investigatorCode, getDeckId(deck));
if (callback) {
await callback(singleInvestigator?.code ?? deck.investigator_code);
await callback(investigatorCode);
}
};
const onInvestigatorSelect = async(card: Card) => {
Expand All @@ -69,7 +71,7 @@ export default function useChooseDeck(createDeckActions: DeckActions, updateActi
onDeckSelect,
onInvestigatorSelect,
simpleOptions: true,
includeParallel: cycleCode === OZ,
includeParallel,
};
Navigation.showModal({
stack: {
Expand Down
5 changes: 2 additions & 3 deletions src/components/cardlist/InvestigatorsListComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext, useMemo, useState } from 'react';
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { filter, forEach } from 'lodash';
import {
Keyboard,
Expand All @@ -19,7 +19,7 @@ import { getPacksInCollection } from '@reducers';
import space, { s } from '@styles/space';
import StyleContext from '@styles/StyleContext';
import ArkhamButton from '@components/core/ArkhamButton';
import { useAllInvestigators, useSettingValue, useToggles } from '@components/core/hooks';
import { useAllInvestigators, useParallelInvestigators, useSettingValue, useToggles } from '@components/core/hooks';
import CompactInvestigatorRow, { AnimatedCompactInvestigatorRow } from '@components/core/CompactInvestigatorRow';
import { TouchableShrink } from '@components/core/Touchables';
import CardDetailSectionHeader from '@components/card/CardDetailView/CardDetailSectionHeader';
Expand Down Expand Up @@ -195,7 +195,6 @@ export default function InvestigatorsListComponent({
[i.name, i.faction_name || '', i.traits || '']
);
});

const results: Item[] = [];
let nonCollectionCards: Card[] = [];
let currentBucket: Section | undefined = undefined;
Expand Down
1 change: 0 additions & 1 deletion src/components/chaos/GuideOddsCalculatorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default function GuideOddsCalculatorView({ campaignId, investigatorIds, c
const allInvestigators: Card[] = useMemo(() => {
return flatMap(investigatorIds, code => (investigators && investigators[code]) || []);
}, [investigators, investigatorIds]);
console.log(`ScenarioCode: ${scenarioIcon}`);
if (!campaign || loading) {
return <LoadingSpinner />
}
Expand Down
23 changes: 15 additions & 8 deletions src/components/core/CompactInvestigatorRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import RoundedFactionHeader from '@components/core/RoundedFactionHeader';
import InvestigatorImage from '@components/core/InvestigatorImage';
import space from '@styles/space';
import CollapsibleFactionBlock from './CollapsibleFactionBlock';
import AppIcon from '@icons/AppIcon';

interface Props {
investigator?: Card;
Expand All @@ -26,6 +27,7 @@ interface Props {
hideImage?: boolean;
arkhamCardsImg?: string;
imageOffset?: 'right' | 'left';
showParallel?: boolean;
}
export default function CompactInvestigatorRow({
hideImage,
Expand All @@ -34,14 +36,16 @@ export default function CompactInvestigatorRow({
eliminated, name, description, investigator,
transparent, yithian, open, detail, badge,
leftContent, imageOffset, children, width, arkhamCardsImg,
showParallel,
}: Props) {
const { colors, typography } = useContext(StyleContext);
const isParallel = investigator?.cycle_code === 'parallel'
return (
<RoundedFactionHeader
transparent={transparent}
eliminated={eliminated}
faction={investigator?.factionCode() || 'neutral'}
parallel={!!investigator?.alternate_of_code}
parallel={isParallel}
fullRound={!open}
width={width}
color={color}
Expand Down Expand Up @@ -72,13 +76,16 @@ export default function CompactInvestigatorRow({
{ name || investigator?.name }
</Text>
{ detail ?? (
<Text
style={[typography.cardTraits, !transparent ? typography.white : { color: colors.D20 }, eliminated ? typography.strike : undefined]}
numberOfLines={1}
ellipsizeMode="tail"
>
{ description !== undefined ? description : investigator?.subname }
</Text>
<View style={styles.row}>
<Text
style={[typography.cardTraits, !transparent ? typography.white : { color: colors.D20 }, eliminated ? typography.strike : undefined]}
numberOfLines={1}
ellipsizeMode="tail"
>
{ description !== undefined ? description : investigator?.subname }
</Text>
{ !!showParallel && isParallel && <AppIcon color="#FFFFFF" name="parallel" size={18} /> }
</View>
) }
</View>
{ !!children && <View style={[styles.rightRow, space.paddingLeftS]}>{ children }</View> }
Expand Down
2 changes: 1 addition & 1 deletion src/data/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function useCampaignInvestigators(
campaign: undefined | SingleCampaignT
): [Card[] | undefined, boolean] {
const [allInvestigators] = usePlayerCards(
campaign?.investigators || NO_INVESTIGATOR_CODES,
campaign?.investigators ?? NO_INVESTIGATOR_CODES,
false
);
const campaignInvestigators = campaign?.investigators;
Expand Down
5 changes: 3 additions & 2 deletions src/data/remote/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CampaignCycleCode, ScenarioResult, StandaloneId, CampaignDifficulty, TraumaAndCardData, InvestigatorData, CampaignId, Deck, WeaknessSet, GuideInput, CampaignNotes, DeckId, SYSTEM_BASED_GUIDE_INPUT_TYPES, SYSTEM_BASED_GUIDE_INPUT_IDS, SealedToken, TarotReading, ChaosBagHistory } from '@actions/types';
import { CampaignCycleCode, ScenarioResult, StandaloneId, CampaignDifficulty, TraumaAndCardData, InvestigatorData, CampaignId, Deck, WeaknessSet, GuideInput, CampaignNotes, DeckId, SYSTEM_BASED_GUIDE_INPUT_TYPES, SYSTEM_BASED_GUIDE_INPUT_IDS, SealedToken, TarotReading, ChaosBagHistory, OZ } from '@actions/types';
import { uniq, concat, flatMap, sumBy, trim, find, findLast, maxBy, map, last, forEach, findLastIndex, filter, isArray } from 'lodash';

import MiniCampaignT, { CampaignLink } from '@data/interfaces/MiniCampaignT';
Expand Down Expand Up @@ -48,10 +48,11 @@ function fragmentToFullInvestigatorData(campaign: FullCampaignFragment): Investi
}

function fragmentToInvestigators(campaign: MiniCampaignFragment): string[] {
const includeParallel = campaign.cycleCode === OZ;
return uniq(
concat(
flatMap(campaign.investigators, i => i.investigator),
flatMap(campaign.latest_decks, d => d.deck?.investigator || []),
includeParallel ? [] : flatMap(campaign.latest_decks, d => d.deck?.investigator || []),
)
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/data/scenario/CampaignGuide.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { find, findIndex, filter, flatMap, forEach, reverse, slice } from 'lodash';
import { ngettext, msgid, t } from 'ttag';

import { GuideStartCustomSideScenarioInput } from '@actions/types';
import { GuideStartCustomSideScenarioInput, OZ } from '@actions/types';
import { PlayedScenario, ProcessedCampaign, ProcessedScenario, ScenarioId } from '@data/scenario';
import { createInvestigatorStatusStep, PLAY_SCENARIO_STEP_ID, PROCEED_STEP_ID, UPGRADE_DECKS_STEP_ID } from './fixedSteps';
import GuidedCampaignLog from './GuidedCampaignLog';
Expand Down Expand Up @@ -116,6 +116,10 @@ export default class CampaignGuide {
});
}

includeParallelInvestigators() {
return this.campaignCycleCode() === OZ;
}

scenarioSetupStepIds(): string[] {
return this.campaign.campaign.scenario_setup || [];
}
Expand Down

0 comments on commit 0c3dc82

Please sign in to comment.