Spaces:
Runtime error
Runtime error
skip next button
Browse files- frontend/src/routes/index.svelte +24 -11
- frontend/src/types.ts +9 -0
frontend/src/routes/index.svelte
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
// original code inspired by Evan You https://github.com/yyx990803/vue-wordle/
|
| 3 |
import { LetterState } from '../types';
|
| 4 |
-
import type { Board } from '../types';
|
| 5 |
import { clearTile, fillTile } from '$lib/utils';
|
| 6 |
|
| 7 |
import Keyboard from '$lib/Keyboard.svelte';
|
| 8 |
import Result from '$lib/Result.svelte';
|
| 9 |
import Message from '$lib/Message.svelte';
|
| 10 |
|
| 11 |
-
import { onMount } from 'svelte';
|
| 12 |
|
| 13 |
const totalTime = 1000;
|
| 14 |
const apiUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/data' : 'data';
|
|
@@ -33,12 +33,24 @@
|
|
| 33 |
// Handle keyboard input.
|
| 34 |
let allowInput = true;
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
onMount(async () => {
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
answer = randomPrompt.replace(/_/g, ' ');
|
| 41 |
-
imagePaths =
|
| 42 |
console.log(answer);
|
| 43 |
cols = randomPrompt.length;
|
| 44 |
timePerTile = totalTime / cols;
|
|
@@ -50,11 +62,8 @@
|
|
| 50 |
state: LetterState.INITIAL
|
| 51 |
}))
|
| 52 |
);
|
| 53 |
-
|
| 54 |
-
window.addEventListener('keyup', onKeyup);
|
| 55 |
document.body.style.setProperty('--cols', `${cols}`);
|
| 56 |
-
|
| 57 |
-
});
|
| 58 |
|
| 59 |
const onKeyup = (e: KeyboardEvent) => {
|
| 60 |
onKey(e.key);
|
|
@@ -177,7 +186,11 @@
|
|
| 177 |
<h1 class="text-xl font-bold text-center">π₯ WORDALLE π₯</h1>
|
| 178 |
<span class="sm:block hidden mx-3 flex-1 border-[0.5px] border-opacity-50 border-gray-400" />
|
| 179 |
<span class="font-light flex-1 text-xs sm:text-base">
|
| 180 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
>
|
| 182 |
</header>
|
| 183 |
<div class="grid grid-cols-3 gap-2 max-w-md mx-auto p-3">
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
// original code inspired by Evan You https://github.com/yyx990803/vue-wordle/
|
| 3 |
import { LetterState } from '../types';
|
| 4 |
+
import type { Board, PromptsData, SuccessPrompt } from '../types';
|
| 5 |
import { clearTile, fillTile } from '$lib/utils';
|
| 6 |
|
| 7 |
import Keyboard from '$lib/Keyboard.svelte';
|
| 8 |
import Result from '$lib/Result.svelte';
|
| 9 |
import Message from '$lib/Message.svelte';
|
| 10 |
|
| 11 |
+
import { onMount, setContext } from 'svelte';
|
| 12 |
|
| 13 |
const totalTime = 1000;
|
| 14 |
const apiUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/data' : 'data';
|
|
|
|
| 33 |
// Handle keyboard input.
|
| 34 |
let allowInput = true;
|
| 35 |
|
| 36 |
+
let promptsData: PromptsData;
|
| 37 |
+
let completedPrompts: SuccessPrompt[] = [];
|
| 38 |
+
let currPromptIndex: number;
|
| 39 |
+
|
| 40 |
onMount(async () => {
|
| 41 |
+
promptsData = await fetch(apiUrl).then((d) => d.json());
|
| 42 |
+
restartBoard();
|
| 43 |
+
|
| 44 |
+
window.addEventListener('keyup', onKeyup);
|
| 45 |
+
return () => window.removeEventListener('keyup', onKeyup);
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
function restartBoard() {
|
| 49 |
+
const prompts: string[] = Object.keys(promptsData);
|
| 50 |
+
currPromptIndex = ~~(Math.random() * prompts.length);
|
| 51 |
+
const randomPrompt: string = prompts[currPromptIndex];
|
| 52 |
answer = randomPrompt.replace(/_/g, ' ');
|
| 53 |
+
imagePaths = promptsData[randomPrompt].slice(0, 6);
|
| 54 |
console.log(answer);
|
| 55 |
cols = randomPrompt.length;
|
| 56 |
timePerTile = totalTime / cols;
|
|
|
|
| 62 |
state: LetterState.INITIAL
|
| 63 |
}))
|
| 64 |
);
|
|
|
|
|
|
|
| 65 |
document.body.style.setProperty('--cols', `${cols}`);
|
| 66 |
+
}
|
|
|
|
| 67 |
|
| 68 |
const onKeyup = (e: KeyboardEvent) => {
|
| 69 |
onKey(e.key);
|
|
|
|
| 186 |
<h1 class="text-xl font-bold text-center">π₯ WORDALLE π₯</h1>
|
| 187 |
<span class="sm:block hidden mx-3 flex-1 border-[0.5px] border-opacity-50 border-gray-400" />
|
| 188 |
<span class="font-light flex-1 text-xs sm:text-base">
|
| 189 |
+
<button
|
| 190 |
+
on:click={() => restartBoard()}
|
| 191 |
+
class="hover:no-underline underline underline-offset-2 hover:scale-105 transition-all duration-200 ease-in-out"
|
| 192 |
+
>Skip to next</button
|
| 193 |
+
></span
|
| 194 |
>
|
| 195 |
</header>
|
| 196 |
<div class="grid grid-cols-3 gap-2 max-w-md mx-auto p-3">
|
frontend/src/types.ts
CHANGED
|
@@ -11,3 +11,12 @@ export interface Tile {
|
|
| 11 |
correct: string;
|
| 12 |
}
|
| 13 |
export type Board = Tile[][];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
correct: string;
|
| 12 |
}
|
| 13 |
export type Board = Tile[][];
|
| 14 |
+
|
| 15 |
+
export interface PromptsData {
|
| 16 |
+
[key: string]: string[];
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export interface SuccessPrompt {
|
| 20 |
+
prompt: string;
|
| 21 |
+
idx: number;
|
| 22 |
+
}
|