Skip to content

Commit

Permalink
Merge pull request #421 from scottbenton/feat/truths-update
Browse files Browse the repository at this point in the history
Feat/truths update
  • Loading branch information
scottbenton authored May 14, 2024
2 parents ccd7736 + 9e5c6d5 commit 97babcb
Show file tree
Hide file tree
Showing 24 changed files with 782 additions and 75 deletions.
23 changes: 23 additions & 0 deletions src/api-calls/world/updateWorldTruthNew.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { updateDoc } from "firebase/firestore";
import { getWorldDoc } from "./_getRef";
import { createApiFunction } from "api-calls/createApiFunction";
import { NewTruth } from "types/World.type";

export const updateWorldTruthNew = createApiFunction<
{ worldId: string; truthKey: string; truth: NewTruth },
void
>((params) => {
const { worldId, truthKey, truth } = params;

return new Promise((resolve, reject) => {
updateDoc(getWorldDoc(worldId), {
[`newTruths.${truthKey}`]: truth,
})
.then(() => {
resolve();
})
.catch((e) => {
reject(e);
});
});
}, "Failed to update world truth.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useStore } from "stores/store";
import { LinkedDialogContentTitle } from "./LinkedDialogContentTitle";
import { Box, DialogContent } from "@mui/material";
import { AssetCard } from "components/features/assets/NewAssetCard";

export interface AssetDialogContentProps {
id: string;
handleBack: () => void;
handleClose: () => void;
isLastItem: boolean;
}

export function AssetDialogContent(props: AssetDialogContentProps) {
const { id, handleBack, handleClose, isLastItem } = props;

const assets = useStore((store) => store.rules.assetMaps.assetMap);

const asset = assets[id];

if (!asset) {
return (
<>
<LinkedDialogContentTitle
id={id}
handleBack={handleBack}
handleClose={handleClose}
isLastItem={isLastItem}
>
Asset Not Found
</LinkedDialogContentTitle>
<DialogContent>Sorry, we could not find that asset.</DialogContent>
</>
);
}

return (
<>
<LinkedDialogContentTitle
id={id}
handleBack={handleBack}
handleClose={handleClose}
isLastItem={isLastItem}
>
{asset.name}
</LinkedDialogContentTitle>
<DialogContent>
<Box maxWidth={(theme) => theme.spacing(48)} mx={"auto"}>
<AssetCard assetId={id} />
</Box>
</DialogContent>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MoveDialogContent } from "./MoveDialogContent";
import { OracleDialogContent } from "./OracleDialogContent";
import { NewOracleDialogContent } from "./NewOracleDialogContent";
import { NewMoveDialogContent } from "./NewMoveDialogContent";
import { AssetDialogContent } from "./AssetDialogContent";

export interface LinkedDialogContentProps {
id?: string;
Expand Down Expand Up @@ -67,6 +68,17 @@ export function LinkedDialogContent(props: LinkedDialogContentProps) {
);
}

if (id?.match(/^[^/]*\/assets/)) {
return (
<AssetDialogContent
id={id}
handleBack={handleBack}
handleClose={handleClose}
isLastItem={isLastItem}
/>
);
}

return (
<>
<LinkedDialogContentTitle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
ButtonBase,
IconButton,
ListItemIcon,
ListItemText,
Menu,
Expand All @@ -9,7 +9,7 @@ import { useRef, useState } from "react";
import MoreIcon from "@mui/icons-material/MoreHoriz";
import CopyIcon from "@mui/icons-material/CopyAll";
import RerollIcon from "@mui/icons-material/Casino";
import BackspaceIcon from '@mui/icons-material/Backspace';
import BackspaceIcon from "@mui/icons-material/Backspace";
import MomentumIcon from "@mui/icons-material/Whatshot";
import { useSnackbar } from "providers/SnackbarProvider";
import { convertRollToClipboard } from "./clipboardFormatter";
Expand Down Expand Up @@ -51,7 +51,9 @@ export function NormalRollActions(props: NormalRollActionsProps) {
const characterId = useStore(
(store) => store.characters.currentCharacter.currentCharacterId
);
const campaignId = useStore((store) => store.campaigns.currentCampaign.currentCampaignId);
const campaignId = useStore(
(store) => store.campaigns.currentCampaign.currentCampaignId
);
const momentum = useStore(
(store) => store.characters.currentCharacter.currentCharacter?.momentum ?? 0
);
Expand All @@ -64,9 +66,7 @@ export function NormalRollActions(props: NormalRollActionsProps) {
store.auth.uid
) ?? false
);
const removeLog = useStore(
(store) => store.gameLog.removeRoll
);
const removeLog = useStore((store) => store.gameLog.removeRoll);

const updateRoll = useStore((store) => store.gameLog.updateRoll);
const updateCharacter = useStore(
Expand Down Expand Up @@ -145,16 +145,25 @@ export function NormalRollActions(props: NormalRollActionsProps) {

return (
<>
<ButtonBase
<IconButton
aria-label={"Copy Roll Result"}
color={"inherit"}
onClick={() => {
handleCopyRoll();
}}
>
<CopyIcon />
</IconButton>
<IconButton
aria-label={"Roll Menu"}
color={"inherit"}
ref={menuParent}
onClick={(evt) => {
evt.stopPropagation();
onClick={() => {
setIsMenuOpen(true);
}}
>
<MoreIcon />
</ButtonBase>
</IconButton>
{isMenuOpen && (
<Menu
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function RollDisplay(props: RollDisplayProps) {
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
position: "relative",
})}
>
<Box
Expand All @@ -39,7 +40,6 @@ export function RollDisplay(props: RollDisplayProps) {
title={roll.moveName ? roll.moveName : roll.rollLabel}
overline={roll.moveName ? roll.rollLabel : undefined}
isExpanded={isExpanded}
actions={actions}
/>
<RollContainer>
<RollValues
Expand Down Expand Up @@ -71,11 +71,7 @@ export function RollDisplay(props: RollDisplayProps) {
)}
{roll.type === ROLL_TYPE.TRACK_PROGRESS && (
<>
<RollTitle
title={roll.rollLabel}
isExpanded={isExpanded}
actions={actions}
/>
<RollTitle title={roll.rollLabel} isExpanded={isExpanded} />
<RollContainer>
<RollValues
fixedResult={{
Expand All @@ -100,7 +96,6 @@ export function RollDisplay(props: RollDisplayProps) {
overline={roll.oracleCategoryName}
title={roll.rollLabel}
isExpanded={isExpanded}
actions={actions}
/>
<RollContainer>
<RollValues d10Results={roll.roll} isExpanded={isExpanded} />
Expand All @@ -114,7 +109,6 @@ export function RollDisplay(props: RollDisplayProps) {
overline={roll.oracleTitle}
title={roll.rollLabel}
isExpanded={isExpanded}
actions={actions}
/>
<RollContainer>
<RollValues d10Results={roll.roll} isExpanded={isExpanded} />
Expand All @@ -123,6 +117,9 @@ export function RollDisplay(props: RollDisplayProps) {
</>
)}
</Box>
<Box position={"absolute"} top={0} right={0}>
{isExpanded && actions}
</Box>
</Card>
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Box, Stack, Typography } from "@mui/material";
import { ReactNode } from "react";
import { Box, Typography } from "@mui/material";

export interface RollTitleProps {
overline?: string;
title: string;
isExpanded: boolean;
actions?: ReactNode;
}

export function RollTitle(props: RollTitleProps) {
const { isExpanded, title, overline, actions } = props;
const { isExpanded, title, overline } = props;

return (
<Box
Expand Down Expand Up @@ -37,10 +35,9 @@ export function RollTitle(props: RollTitleProps) {
{title}
</Typography>
</div>
{actions && isExpanded && (
<Stack direction={"row"} spacing={1} sx={{ mr: -1 }}>
{actions}
</Stack>
{isExpanded && (
// Holds action space
<Box height={40 - 16} width={80 - 16} />
)}
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function extractOracleRollContents(
roll: OracleTableRoll
): OracleRollContents {
const title = roll.oracleCategoryName
? `${roll.oracleCategoryName} ${roll.rollLabel}`
? `${roll.oracleCategoryName} / ${roll.rollLabel}`
: roll.rollLabel;
const rollSection = roll.roll + "";
const result = roll.result;
Expand Down
16 changes: 2 additions & 14 deletions src/components/features/worlds/WorldSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@ import { WorldNameSection } from "pages/World/WorldSheetPage/components/WorldNam
import { useStore } from "stores/store";
import { RtcRichTextEditor } from "components/shared/RichTextEditor/RtcRichTextEditor";
import { useCallback } from "react";
import { GAME_SYSTEMS, GameSystemChooser } from "types/GameSystems.type";
import { IronswornWorldTruthsSection } from "components/features/worlds/IronswornWorldTruthsSection";
import { useGameSystemValue } from "hooks/useGameSystemValue";
import { StarforgedWorldTruthsSection } from "components/features/worlds/StarforgedWorldTruthsSection";
import { WorldTruths } from "./WorldTruths";

export interface WorldSheetProps {
canEdit: boolean;
hideCampaignHints?: boolean;
}

const truthSection: GameSystemChooser<
(props: { canEdit: boolean; hideCampaignHints?: boolean }) => JSX.Element
> = {
[GAME_SYSTEMS.IRONSWORN]: IronswornWorldTruthsSection,
[GAME_SYSTEMS.STARFORGED]: StarforgedWorldTruthsSection,
};

export function WorldSheet(props: WorldSheetProps) {
const { canEdit, hideCampaignHints } = props;

Expand All @@ -39,8 +29,6 @@ export function WorldSheet(props: WorldSheetProps) {
[updateWorldDescription, worldId]
);

const TruthSection = useGameSystemValue(truthSection);

if (!world || !worldId) return null;

return (
Expand Down Expand Up @@ -77,7 +65,7 @@ export function WorldSheet(props: WorldSheetProps) {
/>
</>
)}
<TruthSection canEdit={canEdit} hideCampaignHints={hideCampaignHints} />
<WorldTruths canEdit={canEdit} hideCampaignHints={hideCampaignHints} />
</>
);
}
Loading

0 comments on commit 97babcb

Please sign in to comment.