Skip to content

Commit

Permalink
feat(condition meters): Combined condition meters into a new database…
Browse files Browse the repository at this point in the history
… section
  • Loading branch information
scottbenton committed Mar 9, 2024
1 parent 6d91832 commit cecbb1d
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/api-calls/campaign/updateCampaign.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { updateDoc } from "firebase/firestore";
import { UpdateData, updateDoc } from "firebase/firestore";
import { getCampaignDoc } from "./_getRef";
import { createApiFunction } from "api-calls/createApiFunction";
import { StoredCampaign } from "types/Campaign.type";

export const updateCampaign = createApiFunction<
{
campaignId: string;
campaign: Partial<StoredCampaign>;
campaign: UpdateData<StoredCampaign>;
},
void
>((params) => {
Expand Down
2 changes: 2 additions & 0 deletions src/api-calls/character/createCharacter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const createCharacter = createApiFunction<
uid: uid,
name: name,
stats: stats,
conditionMeters: {},
specialTracks: {},
health: healthTrack.startingValue,
spirit: spiritTrack.startingValue,
supply: supplyTrack.startingValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export function IronswornTracks() {
);

const updateBonds = (bonds: number) => {
return updateCharacter({ bonds });
const trackName = "bonds";
return updateCharacter({
[`legacyTracks.${trackName}.value`]: bonds,
bonds,
});
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export function TracksSection() {
if (track === "supply" && isInCampaign) {
return updateCampaignSupply(newValue);
} else {
return updateCharacter({ [track]: newValue });
return updateCharacter({
[track]: newValue,
[`conditionMeters.${track}`]: newValue,
});
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/stores/campaign/currentCampaign/currentCampaign.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ export const createCurrentCampaignSlice: CreateSliceType<
if (!campaignId) {
return new Promise((res, reject) => reject("No campaign found."));
}
return updateCampaign({ campaignId, campaign: { supply } });
return updateCampaign({
campaignId,
campaign: { supply, [`conditionMeters.supply`]: supply },
});
},
updateCampaign: (campaign) => {
const campaignId = getState().campaigns.currentCampaign.currentCampaignId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CharacterDocument } from "types/Character.type";
import { AssetSlice } from "./assets/assets.slice.type";
import { CharacterTracksSlice } from "./tracks/characterTracks.slice.type";
import { UpdateData } from "firebase/firestore";

export interface CurrentCharacterSliceData {
currentCharacterId?: string;
Expand All @@ -11,7 +12,7 @@ export interface CurrentCharacterSliceActions {
setCurrentCharacterId: (characterId?: string) => void;

updateCurrentCharacter: (
character: Partial<CharacterDocument>
character: UpdateData<CharacterDocument>
) => Promise<void>;
updateCurrentCharacterPortrait: (
portrait: File | undefined,
Expand Down
4 changes: 3 additions & 1 deletion src/types/Campaign.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export interface StoredCampaign {
name: string;
users: string[];
characters: { uid: string; characterId: string }[];
supply: number;
gmIds?: string[];
worldId?: string;
conditionMeters: Record<string, number>;
// TODO - Remove once expansions are in
supply: number;
}
19 changes: 9 additions & 10 deletions src/types/Character.type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StoredAsset } from "./Asset.type";
import { LEGACY_TRACK_TYPES, LegacyTrack } from "./LegacyTrack.type";
import { LegacyTrack } from "./LegacyTrack.type";

export type StatsMap = {
[key: string]: number;
Expand All @@ -15,22 +15,13 @@ export interface CharacterDocument {
uid: string;
name: string;
stats: StatsMap;
health: number;
spirit: number;
supply: number;
adds?: number;
momentum: number;
campaignId?: string;
experience?: {
earned?: number;
spent?: number;
};
legacyTracks?: {
[LEGACY_TRACK_TYPES.QUESTS]?: LegacyTrack;
[LEGACY_TRACK_TYPES.BONDS]?: LegacyTrack;
[LEGACY_TRACK_TYPES.DISCOVERIES]?: LegacyTrack;
};
bonds?: number;
debilities?: {
[key: string]: boolean;
};
Expand All @@ -46,6 +37,14 @@ export interface CharacterDocument {
};
worldId?: string | null;

conditionMeters: Record<string, number>;
legacyTracks: Record<string, LegacyTrack>;

// TODO - remove once new expansion is complete
health: number;
spirit: number;
supply: number;
bonds?: number;
customTracks?: {
[trackName: string]: number;
};
Expand Down
4 changes: 2 additions & 2 deletions src/types/LegacyTrack.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export enum LEGACY_TRACK_TYPES {
}
export interface LegacyTrack {
value: number;
spentExperience: { [index: number]: boolean };
isLegacy: boolean;
spentExperience?: { [index: number]: boolean };
isLegacy?: boolean;
}

0 comments on commit cecbb1d

Please sign in to comment.