This commit is contained in:
Niklas Kapelle 2024-05-24 17:43:35 +02:00
parent e517bed681
commit b47325a0dc
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
38 changed files with 3110 additions and 1 deletions

View File

View File

View File

@ -32,6 +32,7 @@ struct MyState {
} }
#[derive(Serialize)] #[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct GamestateJson { struct GamestateJson {
state: GameState, state: GameState,
dealer_upcard: Option<Card>, dealer_upcard: Option<Card>,
@ -60,5 +61,5 @@ pub fn build() -> Rocket<Build> {
rocket::build() rocket::build()
.manage(state) .manage(state)
.mount("/", routes![get_state, post_move]) .mount("/api", routes![get_state, post_move])
} }

24
frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

12
frontend/index.html Normal file
View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Blackjack</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

2898
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

24
frontend/package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.2",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"svelte": "^4.2.12",
"svelte-check": "^3.6.7",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}

View File

@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

22
frontend/src/App.svelte Normal file
View File

@ -0,0 +1,22 @@
<script lang="ts">
import {fetchState} from "./functions/fetchState";
import { CardSuit } from "./types/CardSuit";
async function getState() {
let state = await fetchState();
console.debug(state);
if (state.dealerUpcard.suit == CardSuit.Spades){
console.debug("Heureka");
}else{
console.debug("FUCK");
}
}
</script>
<main>
<div>Hello world</div>
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" on:click={getState}>Get state</button>
</main>

View File

@ -0,0 +1,6 @@
import type { Gamestate } from "../types/Gamestate";
export async function fetchState(): Promise<Gamestate>{
let res = await fetch("/api/state");
return await res.json();
}

3
frontend/src/index.css Normal file
View File

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@ -0,0 +1,9 @@
<script lang="ts">
import type { Card } from "../types/Card";
export let card: Card;
</script>
<div class="w-2 h-5">
I am a {card.index} of {card.suit}!
</div>

8
frontend/src/main.ts Normal file
View File

@ -0,0 +1,8 @@
import "./index.css"
import App from './App.svelte'
const app = new App({
target: document.getElementById('app')!,
})
export default app

View File

@ -0,0 +1,7 @@
import type { CardIndex } from "./CardIndex";
import type { CardSuit } from "./CardSuit";
export interface Card {
suit: CardSuit,
index: CardIndex,
}

View File

@ -0,0 +1,15 @@
export enum CardIndex {
A = "A",
K = "K",
Q = "Q",
J = "J",
N10 = "N10",
N9 = "N9",
N8 = "N8",
N7 = "N7",
N6 = "N6",
N5 = "N5",
N4 = "N4",
N3 = "N3",
N2 = "N2",
}

View File

@ -0,0 +1,6 @@
export enum CardSuit {
Spades = "Spades",
Clubs = "Clubs",
Hearts = "Hearts",
Diamonds = "Diamonds",
}

View File

@ -0,0 +1,5 @@
import type { Card } from "./Card";
export interface Gamestate{
dealerUpcard: Card,
}

2
frontend/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />

View File

@ -0,0 +1,7 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
export default {
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
}

View File

@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx,svelte}",
],
theme: {
extend: {},
},
plugins: [],
}

20
frontend/tsconfig.json Normal file
View File

@ -0,0 +1,20 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": true,
"isolatedModules": true
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true
},
"include": ["vite.config.ts"]
}

12
frontend/vite.config.ts Normal file
View File

@ -0,0 +1,12 @@
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/api" : "http://127.0.0.1:8000"
}
}
})