non-functional thing

This commit is contained in:
Emma 2023-07-27 05:12:30 -06:00
parent f300ddc1a1
commit 7e6a0036e4
6 changed files with 1164 additions and 110 deletions

48
Deck.ts Normal file
View File

@ -0,0 +1,48 @@
export type Card<T> = {
id: string;
} & T
export class Deck<T> {
private cards: Card<T>[];
private discard: Card<T>[];
public hands: Card<T>[][] = []
constructor(cards?: Card<T>[]) {
this.cards = cards || [];
this.discard = [];
}
public shuffle() {
this.cards.sort(Math.random);
}
public reshuffle() {
this.cards = this.cards.concat(this.discard).sort(Math.random);
this.discard = [];
}
public createHand() {
return this.hands.push([]) - 1;
}
public drawToHand(handIndex: number, count = 1, reshuffle = true) {
const hand = this.hands.at(handIndex);
if (!hand) throw 'No hand at index ' + handIndex;
for (let i = 0; i < count; i++) {
if (!this.cards.length && reshuffle) this.reshuffle();
const card = this.cards.pop();
if (!card) break;
hand.push(card);
}
}
public addCard(...cards: Card<T>[]) {
this.cards.push(...cards);
}
public getDeck() {
return [...this.cards];
}
public getDiscard() {
return [...this.discard];
}
}

View File

@ -1,113 +1,66 @@
'use client'
import { Card } from '@/Deck';
import { useDeck } from '@/hooks/useDeck'
import { camelToSpace } from '@/utils/camelToSpace';
import Image from 'next/image'
import { useCallback, useEffect, useState } from 'react';
type planeCard = {
maneuvers: [
{
name: string,
complexity: 'simple' | 'complex',
length: number
}
],
attacks: ('airToGround' | 'groundToAir' | 'airToAir')[],
penalties: ('Stall' | 'Damage' | 'Ground Battle')[],
type: 'action' | 'win condition' | 'wild card' | 'sudden death'
};
export default function Home() {
const { addCard, createHand, deck, discard, drawToHand, hands, reshuffle, shuffle, createDeck } = useDeck<planeCard>();
const series = 1;
const fetchDeckJson = useCallback(async () => {
const res = await fetch('./json/deck.json');
const json: Card<planeCard>[] = await res.json();
json.forEach(c => c.id = crypto.randomUUID());
createDeck(json);
}, [])
useEffect(() => {
fetchDeckJson().then(() => {
shuffle()
// setRender(!render)
})
}, [])
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
<div className="grid grid-cols-4 gap-6">
{deck.map((c,i) => (<div className="rounded-lg aspect-card p-8 shadow-lg flex flex-wrap dark:bg-green-700">
<div className="basis-full">
<p className="mb-4 font-extrabold uppercase text-xl">{c.type}</p>
{c.attacks.length || c.maneuvers.length ?
<p className="mb-8 text-sm">Select either one maneuver or one attack to make. If you can't complete one action from this card, you must take one penalty listed. If there are no penalties listed, discard this card.</p> :
<p className="mb-8 text-sm">Bad luck! You must take one of the following penalties</p>
}
{c.maneuvers.length > 0 ? <p className="capitalize my-8"><span className="font-bold">Maneuvers</span>: {c.maneuvers.map(a => camelToSpace(a.name)).join(', ')}</p> : ''}
{c.attacks.length > 0 ? <p className="capitalize my-8"><span className="font-bold">Attacks</span>: {c.attacks.map(a => camelToSpace(a)).join(', ')}</p> : ''}
{c.penalties.length > 0 ? <><hr /><p className="capitalize my-8"><span className="font-bold">Penalties</span>: {c.penalties.join(', ')}</p></> : ''}
</div>
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
<div className="text-xs self-end flex justify-between w-full text-white/50">
<p className="dark:text-white/50 text-black/50">Series {series}</p>
<p className="dark:text-white/50 text-black/50">{i + 1}/{deck.length}</p>
<p className="dark:text-white/50 text-black/50">&copy; {new Date().getFullYear()} Cyborg Grizzly Games</p>
</div>
<div className="mb-32 grid text-center lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore the Next.js 13 playground.
</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{' '}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>))}
</div>
</main>
)
}

44
hooks/useDeck.ts Normal file
View File

@ -0,0 +1,44 @@
import { Card, Deck } from "@/Deck";
import { useCallback, useRef, useState } from "react"
export const useDeck = <T>() => {
const deck = useRef(new Deck<T>());
const shuffle = useCallback(() => {
deck.current.shuffle();
}, [])
const reshuffle = useCallback(() => {
deck.current.reshuffle();
}, [])
const createHand = useCallback(() => deck.current.createHand(), [])
const drawToHand = useCallback((index: number, count?: number, reshuffle?: boolean) => {
deck.current.drawToHand(index, count, reshuffle);
}, [])
const addCard = useCallback((...cards: Card<T>[]) => {
deck.current.addCard(...cards)
}, [])
const getDeck = useCallback(() => deck.current.getDeck(), []);
const getDiscard = useCallback(() => deck.current.getDiscard(), []);
const getHands = useCallback(() => deck.current.hands, []);
const createDeck = useCallback((cards: Card<T>[]) => {
deck.current = new Deck(cards);
}, [])
return {
deck: getDeck(),
discard: getDiscard(),
hands: getHands(),
shuffle,
reshuffle,
createHand,
drawToHand,
addCard,
createDeck
}
}

1007
public/json/deck.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,13 @@ module.exports = {
],
theme: {
extend: {
backgroundImage: {
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
'gradient-conic':
'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
container: {
center: true
},
aspectRatio: {
card: '2.5 / 3.5'
},
}
},
plugins: [],
}

1
utils/camelToSpace.ts Normal file
View File

@ -0,0 +1 @@
export const camelToSpace = (value: string) => value.replace(/[A-Z0-9]/g, e => ` ${e.toLowerCase()}`);