can put them back

This commit is contained in:
2025-08-03 22:16:19 -04:00
parent 5f05eb4adf
commit 0dc0a9ce62
7 changed files with 94 additions and 30 deletions

View File

@@ -23,6 +23,10 @@ body::before {
background: radial-gradient(rgb(24, 82, 65), rgb(1, 42, 16));
}
.hand {
background: radial-gradient(rgb(24, 70, 82), rgb(1, 42, 41));
}
.full {
height: 100%;
width: 100%;

View File

@@ -1,5 +1,6 @@
import { Component, createResource, JSX, Suspense } from "solid-js";
import { Card } from "../types/cards";
import { Clickable, Stylable } from "./toolbox";
const cardToSvgFilename = (card: Card) => {
if (card.kind == "joker") {
@@ -30,6 +31,7 @@ export default ((props) => {
return (
<Suspense>
<img
onClick={props.onClick}
draggable={false}
class={props.class}
style={{
@@ -41,9 +43,10 @@ export default ((props) => {
/>
</Suspense>
);
}) satisfies Component<{
class?: string;
style?: JSX.CSSProperties;
}) satisfies Component<
{
card: Card;
face?: "up" | "down";
}>;
} & Stylable &
Clickable
>;

View File

@@ -2,32 +2,35 @@ import { createContext, JSX } from "solid-js";
import Card from "./Card";
import Hand from "./Hand";
import Pile from "./Pile";
import { newDeck, shuffle, Hand as THand } from "../types/cards";
import { createStore, produce } from "solid-js/store";
import { GameState, newDeck, shuffle, Hand as THand } from "../types/cards";
import { createStore, produce, SetStoreFunction, Store } from "solid-js/store";
const GameContext = createContext();
export const GameContext = createContext<{
gameState: Store<GameState>;
setGameState: SetStoreFunction<GameState>;
}>();
export default () => {
const [gameState, setGameState] = createStore({
pile: shuffle(newDeck()),
hand: [] as THand,
const [gameState, setGameState] = createStore<GameState>({
deck: shuffle(newDeck()),
hand: [],
});
return (
<GameContext.Provider value={{ gameState, setGameState }}>
<div
onClick={() => {}}
class="full column"
class="full column center"
style={{ "row-gap": "20px", "font-size": "32px" }}
>
<div class="full center">
<Pile
pile={gameState.pile}
pile={gameState.deck}
style={{ cursor: "pointer" }}
onClick={() =>
setGameState(
produce((state) => {
state.hand.push(state.pile.pop()!);
state.hand.push(state.deck.pop()!);
})
)
}

View File

@@ -1,11 +1,19 @@
import { Component, For } from "solid-js";
import { Component, For, useContext } from "solid-js";
import Card from "./Card";
import { Hand } from "../types/cards";
import { GameContext } from "./Game";
import { produce } from "solid-js/store";
export default ((props) => {
const { setGameState } = useContext(GameContext)!;
return (
<div
class="hand"
style={{
"min-width": "100px",
width: "fit-content",
"max-width": "80%",
border: "2px dashed white",
"border-radius": "12px",
margin: "10px",
@@ -18,7 +26,30 @@ export default ((props) => {
gap: "5px",
}}
>
<For each={props.hand}>{(card) => <Card card={card} />}</For>
<For each={props.hand}>
{(card) => (
<Card
card={card}
style={{
cursor: "pointer",
}}
onClick={() =>
setGameState(
produce((state) => {
const index = state.hand.indexOf(card);
console.log(index);
state.deck.push(
state.hand.splice(
props.hand.indexOf(card),
1
)[0]!
);
})
)
}
/>
)}
</For>
</div>
);
}) satisfies Component<{ hand: Hand }>;

View File

@@ -1,12 +1,19 @@
import { Component, For, JSX } from "solid-js";
import Card from "./Card";
import { Pile } from "../types/cards";
import { type ComponentProps } from "solid-js";
import { Clickable, Stylable } from "./toolbox";
export default ((props) => {
return (
<div
class="center"
style={{ width: "200px", height: "400px", ...props.style }}
{...props}
class={`center ${props.class ?? ""}}`.trim()}
style={{
width: "200px",
height: "400px",
...(props.style as JSX.CSSProperties),
}}
onClick={props.onClick}
>
<For each={props.pile}>
@@ -31,14 +38,9 @@ export default ((props) => {
</For>
</div>
);
}) satisfies Component<{
}) satisfies Component<
{
pile: Pile;
style?: JSX.CSSProperties;
onClick?:
| JSX.EventHandlerUnion<
HTMLDivElement,
MouseEvent,
JSX.EventHandler<HTMLDivElement, MouseEvent>
>
| undefined;
}>;
} & Stylable &
Clickable
>;

View File

@@ -0,0 +1,16 @@
import { JSX } from "solid-js";
export type Stylable = {
class?: string;
style?: JSX.CSSProperties;
};
export type Clickable = {
onClick?:
| JSX.EventHandlerUnion<
HTMLDivElement,
MouseEvent,
JSX.EventHandler<HTMLDivElement, MouseEvent>
>
| undefined;
};

View File

@@ -55,3 +55,8 @@ export const shuffle = (cards: Card[]) => {
}
return cards;
};
export type GameState = {
deck: Pile;
hand: Hand;
};