This commit is contained in:
2025-09-03 21:11:43 -04:00
parent d203fe4141
commit ce29ab72ae
10 changed files with 55 additions and 27 deletions

2
.gitignore vendored
View File

@@ -2,6 +2,8 @@
.vinxi .vinxi
*.db *.db
.DS_STORE
# ---> Node # ---> Node
# Logs # Logs
logs logs

7
deploy Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
branch=$(git branch --show-current)
git switch prod
git merge $branch
git push
git switch $brnach

View File

@@ -1,7 +1,7 @@
{ {
"name": "games", "name": "games",
"type": "module", "type": "module",
"version": "0.0.8", "version": "0.0.9",
"scripts": { "scripts": {
"dev": "pnpm --parallel dev", "dev": "pnpm --parallel dev",
"build": "pnpm run -F client build", "build": "pnpm run -F client build",

View File

@@ -1,7 +1,7 @@
import { Component, Suspense } from "solid-js"; import { Component, Suspense } from "solid-js";
import type { Card } from "@games/shared/cards"; import type { Card } from "@games/shared/cards";
import { Clickable, Sizable, Stylable } from "./toolbox"; import { Clickable, Scalable, Stylable } from "./toolbox";
const cardToSvgFilename = (card: Card) => { const cardToSvgFilename = (card: Card) => {
if (card.kind == "joker") { if (card.kind == "joker") {
@@ -17,7 +17,12 @@ const cardToSvgFilename = (card: Card) => {
}`; }`;
}; };
export const CARD_RATIO = 1.456730769;
export const BASE_CARD_WIDTH = 100;
export default ((props) => { export default ((props) => {
const width = () => BASE_CARD_WIDTH * (props.scale ?? 1);
const height = () => width() * CARD_RATIO;
return ( return (
<Suspense> <Suspense>
<img <img
@@ -25,8 +30,8 @@ export default ((props) => {
draggable={false} draggable={false}
class={props.class} class={props.class}
style={props.style} style={props.style}
width={props.width ?? "100px"} width={`${width()}px`}
height={props.height} height={`${height()}px`}
src={ src={
props.face == "down" props.face == "down"
? "/views/back.svg" ? "/views/back.svg"
@@ -45,5 +50,5 @@ export default ((props) => {
) & ) &
Stylable & Stylable &
Clickable & Clickable &
Sizable Scalable
>; >;

View File

@@ -10,7 +10,7 @@ export default (props: { handCount: number }) => {
return ( return (
<Card <Card
face="down" face="down"
width="40px" scale={0.4}
style={{ style={{
"margin-left": "-12px", "margin-left": "-12px",
"margin-right": "-12px", "margin-right": "-12px",

View File

@@ -25,6 +25,7 @@ export default () => {
<GameContext.Provider value={{ view, submitAction }}> <GameContext.Provider value={{ view, submitAction }}>
<Pile <Pile
count={view().deckCount} count={view().deckCount}
scale={0.8}
class="cursor-pointer fixed center" class="cursor-pointer fixed center"
onClick={() => submitAction({ type: "draw" })} onClick={() => submitAction({ type: "draw" })}
/> />
@@ -58,11 +59,16 @@ export default () => {
> >
Quit Quit
</button> </button>
<For each={Object.entries(view().playerHandCounts)}> <For
each={Object.entries(view().playerHandCounts).filter(([key, _]) =>
table.players().includes(key)
)}
>
{([playerKey, handCount], i) => ( {([playerKey, handCount], i) => (
<Portal <Portal
mount={document.getElementById(`player-${playerKey}`)!} mount={document.getElementById(`player-${playerKey}`)!}
ref={(ref) => { ref={(ref) => {
console.log("Setting hand ref");
const midOffset = const midOffset =
i() + 0.5 - Object.values(view().playerHandCounts).length / 2; i() + 0.5 - Object.values(view().playerHandCounts).length / 2;

View File

@@ -1,17 +1,19 @@
import { Component, createMemo, For, JSX, Show } from "solid-js"; import { Component, createMemo, For, JSX, Show } from "solid-js";
import Card from "./Card"; import Card, { BASE_CARD_WIDTH, CARD_RATIO } from "./Card";
import { desaturate } from "color2k"; import { desaturate } from "color2k";
import { Clickable, hashColor, Stylable } from "./toolbox"; import { Clickable, hashColor, Scalable, Stylable } from "./toolbox";
const cardWidth = 100;
const cardHeight = 145; const cardOffset = 0.35; // Small offset for the stack effect
const cardOffset = 0.3; // Small offset for the stack effect
export default ((props) => { export default ((props) => {
const cards = createMemo(() => { const cards = createMemo(() => {
const numCards = Math.max(0, props.count - 1); // Subtract 1 for the top card const numCards = Math.max(0, props.count - 1); // Subtract 1 for the top card
return Array.from({ length: numCards }, (_, i) => i).toReversed(); return Array.from({ length: numCards }, (_, i) => i).toReversed();
}); });
const width = () => BASE_CARD_WIDTH * (props.scale ?? 1);
const height = () => width() * CARD_RATIO;
const offset = () => cardOffset * (props.scale ?? 1);
return ( return (
<Show when={props.count > 0}> <Show when={props.count > 0}>
<div <div
@@ -22,24 +24,24 @@ export default ((props) => {
> >
<svg <svg
class="absolute z-[-1]" class="absolute z-[-1]"
width={cardWidth + cards().length * cardOffset} width={width() + cards().length * offset()}
height={cardHeight + cards().length * cardOffset} height={height() + cards().length * offset()}
viewBox={`0 0 ${cardWidth + cards().length * cardOffset} ${ viewBox={`0 0 ${width() + cards().length * offset()} ${
cardHeight + cards().length * cardOffset height() + cards().length * offset()
}`} }`}
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
> >
<For each={cards()}> <For each={cards()}>
{(i) => { {(i) => {
const xOffset = (i * cardOffset) / 2; const xOffset = (i * offset()) / 2;
const yOffset = i * cardOffset; const yOffset = i * offset();
const color = desaturate(hashColor(i), 0.9); const color = desaturate(hashColor(i), 0.9);
return ( return (
<rect <rect
x={xOffset} x={xOffset}
y={yOffset} y={yOffset}
width={cardWidth} width={width()}
height={cardHeight} height={height()}
rx="5" // Rounded corners rx="5" // Rounded corners
ry="5" ry="5"
fill={color} fill={color}
@@ -48,7 +50,7 @@ export default ((props) => {
}} }}
</For> </For>
</svg> </svg>
<Card onClick={props.onClick} face="down" /> <Card onClick={props.onClick} face="down" scale={props.scale} />
</div> </div>
</Show> </Show>
); );
@@ -56,5 +58,6 @@ export default ((props) => {
{ {
count: number; count: number;
} & Stylable & } & Stylable &
Clickable Clickable &
Scalable
>; >;

View File

@@ -1,4 +1,4 @@
import { createSignal, useContext } from "solid-js"; import { createSignal, onMount, useContext } from "solid-js";
import { playerColor } from "~/profile"; import { playerColor } from "~/profile";
import { TableContext } from "./Table"; import { TableContext } from "./Table";
import { Stylable } from "./toolbox"; import { Stylable } from "./toolbox";
@@ -16,6 +16,8 @@ export default (props: { playerKey: string } & Stylable) => {
const game = useContext(GameContext); const game = useContext(GameContext);
onMount(() => console.log("Player mounted"));
return ( return (
<div <div
id={`player-${props.playerKey}`} id={`player-${props.playerKey}`}

View File

@@ -28,6 +28,7 @@ export const TableContext = createContext<{
sendWs: (msg: TWsIn) => void; sendWs: (msg: TWsIn) => void;
wsEvents: Stream<TWsOut, any>; wsEvents: Stream<TWsOut, any>;
playerNames: Store<{ [key: string]: string }>; playerNames: Store<{ [key: string]: string }>;
players: Accessor<string[]>;
}>(); }>();
export default (props: { tableKey: string }) => { export default (props: { tableKey: string }) => {
@@ -75,7 +76,9 @@ export default (props: { tableKey: string }) => {
createEffect(() => sendWs({ ready: ready() })); createEffect(() => sendWs({ ready: ready() }));
createEffect(() => sendWs({ name: name() })); createEffect(() => sendWs({ name: name() }));
const view = createObservable(gameEvents.map((evt) => evt.view)); const viewProp = gameEvents.map((evt) => evt.view).toProperty();
viewProp.log();
const view = createObservable(viewProp);
const results = createObservable<string>( const results = createObservable<string>(
merge([ merge([
gameEvents gameEvents
@@ -92,6 +95,7 @@ export default (props: { tableKey: string }) => {
wsEvents, wsEvents,
view, view,
playerNames, playerNames,
players,
}} }}
> >
<div class="flex justify-around p-t-14"> <div class="flex justify-around p-t-14">

View File

@@ -16,9 +16,8 @@ export type Clickable = {
| undefined; | undefined;
}; };
export type Sizable = { export type Scalable = {
width?: string; scale?: number;
height?: string;
}; };
export const hashColor = (obj: NotUndefined) => `#${hash(obj).substring(0, 6)}`; export const hashColor = (obj: NotUndefined) => `#${hash(obj).substring(0, 6)}`;