Skip to content

Commit

Permalink
build: add shared folder to build config
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpixels committed Oct 2, 2023
1 parent a7cdf56 commit d8cec50
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { Meta, StoryObj } from "@storybook/react";

import { AssetCardForm } from "./AssetCardForm";
import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";
import { useState } from "react";

const meta: Meta<typeof AssetCardForm> = {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/AssetCardForm/AssetCardForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
beforeEach,
MockedFunction,
} from "vitest";
import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";

const getMockCard = (): AssetCard => {
return {
Expand Down
38 changes: 34 additions & 4 deletions client/src/components/AssetCardForm/AssetCardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import { Button, Card, Divider, Input, Radio, Select } from "antd";
import TextArea from "antd/es/input/TextArea";
import {
AssetCard,
AssetCardProperty,
} from "../../../../shared/types/AssetCard";
import { AssetCard, AssetCardProperty } from "@shared/types/AssetCard";
import CaretUpOutlined from "@ant-design/icons/lib/icons/CaretUpOutlined";
import CaretDownOutlined from "@ant-design/icons/lib/icons/CaretDownOutlined";

export interface AssetCardFormProps {
card: AssetCard;
Expand Down Expand Up @@ -171,6 +170,18 @@ function renderProperty(
>
Remove
</Button>
<Radio.Group data-testid={"asset-card-form-move-property"}>
<Radio.Button
onClick={() => moveProperty("up", propertyIndex, card, setCard)}
>
<CaretUpOutlined />
</Radio.Button>
<Radio.Button
onClick={() => moveProperty("down", propertyIndex, card, setCard)}
>
<CaretDownOutlined />
</Radio.Button>
</Radio.Group>
<Select
data-testid={"asset-card-form-property-indents"}
placeholder={"Indents"}
Expand Down Expand Up @@ -242,3 +253,22 @@ function editProperty(
(cardProperty[key] as AssetCardProperty[typeof key]) = value;
setCard(cardCopy);
}

function moveProperty(
direction: "up" | "down",
current: number,
card: AssetCard,
setCard: (card: AssetCard) => void
) {
if (
(current === 0 && direction === "up") ||
(current === card.properties.length - 1 && direction === "down")
)
return;
const cardCopy = { ...card };
const properties = cardCopy.properties;
const element = properties[current];
properties.splice(current, 1);
properties.splice(current + (direction === "up" ? -1 : 1), 0, element);
setCard({ ...cardCopy, properties: [...properties] });
}
26 changes: 22 additions & 4 deletions client/src/components/AssetCardViewer/AssetCardViewer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import type { Meta, StoryObj } from "@storybook/react";

import { AssetCardViewer } from "./AssetCardViewer";
import { HawkMockAssetCard } from "./Mocks";
import {
FletcherMockAssetCard,
HawkMockAssetCard,
IroncladMockAssetCard,
} from "./Mocks";

const meta: Meta<typeof AssetCardViewer> = {
component: AssetCardViewer,
Expand All @@ -12,17 +16,31 @@ const meta: Meta<typeof AssetCardViewer> = {
export default meta;
type Story = StoryObj<typeof AssetCardViewer>;

export const Default: Story = {
export const Original: Story = {
args: {
card: HawkMockAssetCard,
scale: 1,
isOriginal: true,
},
};

export const Original: Story = {
export const Hawk: Story = {
args: {
card: HawkMockAssetCard,
scale: 1,
isOriginal: true,
},
};

export const Ironclad: Story = {
args: {
card: IroncladMockAssetCard,
scale: 1,
},
};

export const Fletcher: Story = {
args: {
card: FletcherMockAssetCard,
scale: 1,
},
};
2 changes: 1 addition & 1 deletion client/src/components/AssetCardViewer/AssetCardViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Alert, Button, Spin } from "antd";
import { useInView } from "../../helpers/hooks/useInView";
import { generatePngDataFromAssetCard } from "../../helpers/Converters";
import OriginalContentWarning from "../OriginalContentWarning/OriginalContentWarning";
import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";

type AssetCardViewerProps = {
card: AssetCard;
Expand Down
13 changes: 8 additions & 5 deletions client/src/components/AssetCardViewer/CardTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */

import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";

export function CardTemplate(card: AssetCard, width: number, height: number) {
return (
Expand All @@ -13,7 +13,7 @@ export function CardTemplate(card: AssetCard, width: number, height: number) {
display: "flex",
flexDirection: "column",
boxSizing: "border-box",
fontSize: "1.1em",
fontSize: "1.05em",
fontFamily: "Georgia",
}}
>
Expand Down Expand Up @@ -55,7 +55,7 @@ export function CardTemplate(card: AssetCard, width: number, height: number) {
<div
style={{
paddingLeft: "1em",
paddingRight: "1em",
paddingRight: "2em",
display: "flex",
flexDirection: "column",
fontSize: "2em",
Expand All @@ -79,21 +79,24 @@ export function CardTemplate(card: AssetCard, width: number, height: number) {
<div
key={"property-" + index}
style={{
position: "relative",
display: "flex",
marginBottom: "0.1em",
columnGap: "1em",
paddingLeft: property.indents * 2 + "em",
}}
>
<span
style={{
marginTop: "0.2em",
position: "absolute",
top: "0.2em",
fontSize: "0.66em",
scale: property.indents > 0 ? "50%" : "100%",
}}
>
{property.is_upgradeable ? "⚪" : "⚫"}
</span>
<span>
<span style={{ marginLeft: "1.5em" }}>
{property.title && <b>{property.title}: </b>}
{property.description}
</span>
Expand Down
92 changes: 91 additions & 1 deletion client/src/components/AssetCardViewer/Mocks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */

import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";

export const HawkMockAssetCard = {
category: "companion",
Expand Down Expand Up @@ -33,3 +33,93 @@ export const HawkMockAssetCard = {
title: "Hawk",
custom_fields: [],
} satisfies AssetCard;

export const IroncladMockAssetCard = {
category: "combat talent",
description: "If you wear armor...",
has_name_field: false,
properties: [
{
description: "When you equip or adjust your armor, choose one.",
indents: 0,
is_upgradeable: false,
title: "",
},
{
description:
"When you Endure Harm in a fight, add +1 and take +1 momentum on a hit.",
indents: 1,
is_upgradeable: false,
title: "Lightly armored",
},
{
description:
"Mark encumbered. When you Endure Harm in a fight, add +2 and take +1 momentum on a hit.",
indents: 1,
is_upgradeable: false,
title: "Geared for war",
},
{
description: "When you Clash while you are geared for war, add +1.",
indents: 0,
is_upgradeable: true,
title: "",
},
{
description:
"When you Compel in a situation where strength of arms is a factor, add +2.",
indents: 0,
is_upgradeable: true,
title: "",
},
],
health: 0,
title: "Ironclad",
custom_fields: ["LIGHTLY ARMORED", "GEARED FOR WAR"],
} satisfies AssetCard;

export const FletcherMockAssetCard = {
category: "combat talent",
description: "",
has_name_field: false,
properties: [
{
description:
"When you Secure an Advantage by crafting arrows of fine quality, add +1. Then, take +1 supply or +1 momentum on a hit.",
indents: 0,
is_upgradeable: false,
title: "",
},
{
description:
"When you Resupply by recovering or gathering arrows after a battle, add +2.",
indents: 0,
is_upgradeable: true,
title: "",
},
{
description:
"When you craft a single arrow designated for a specific foe, envision the process and materials, and roll +wits. On a strong hit, take both. On a weak hit, choose one.",
indents: 0,
is_upgradeable: true,
title: "",
},
{
description:
"When a shooter uses the arrow to Strike or Clash against this foe, reroll any dice (one time only).",
indents: 1,
is_upgradeable: false,
title: "Seeker",
},
{
description:
"When a shooter uses the arrow to inflict harm against this foe, inflict +1d6 harm (one time only).",
indents: 1,
is_upgradeable: false,
title: "Ravager",
},
],
health: 0,
title: "Fletcher",
custom_fields: [],
} satisfies AssetCard;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { Meta, StoryObj } from "@storybook/react";
import { RessourceList, RessourceType } from "./RessourceList";
import { HawkMockAssetCard } from "../AssetCardViewer/Mocks";
import { RessourceMetadata } from "../../types/Metadata";
import { RessourceMetadata } from "@shared/types/Metadata";

const meta: Meta<typeof RessourceList> = {
component: RessourceList,
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/RessourceList/RessourceList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @format */

import Search from "antd/es/input/Search";
import { AssetCard } from "../../types/AssetCard";
import { RessourceMetadata } from "../../types/Metadata";
import { AssetCard } from "@shared/types/AssetCard";
import { RessourceMetadata } from "@shared/types/Metadata";
import { AssetCardViewer } from "../AssetCardViewer/AssetCardViewer";
import { Card, Empty, Tooltip } from "antd";
import HeartOutlined from "@ant-design/icons/lib/icons/HeartOutlined";
Expand Down
2 changes: 1 addition & 1 deletion client/src/helpers/Converters.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @format */

import ReactDOMServer from "react-dom/server";
import { AssetCard } from "../types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";
import { CardTemplate } from "../components/AssetCardViewer/CardTemplate";

export function convertJsxToHtmlString(jsx: JSX.Element) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/widgets/AssetCardEditor/AssetCardEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useEffect, useState } from "react";
import { AssetCardViewer } from "../../components/AssetCardViewer/AssetCardViewer";
import { AssetCardForm } from "../../components/AssetCardForm/AssetCardForm";
import { AssetCard } from "../../../../shared/types/AssetCard";
import { AssetCard } from "@shared/types/AssetCard";

type AssetCardEditorProps = {
initial?: AssetCard;
Expand Down
3 changes: 3 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"paths": {
"@shared/*": ["../shared/*"]
},

/* Bundler mode */
"moduleResolution": "bundler",
Expand Down
5 changes: 5 additions & 0 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export default defineConfig({
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
resolve: {
alias: {
"@shared": "../shared", // Adjust the path as needed
},
},
test: {
environment: "happy-dom",
coverage: {
Expand Down

0 comments on commit d8cec50

Please sign in to comment.