Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"[tailwindcss]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[xml]": {
"editor.defaultFormatter": "biomejs.biome"
Comment thread
gameroman marked this conversation as resolved.
Resolved
}
}
1 change: 1 addition & 0 deletions apps/bulls-and-cows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@tailwindcss/vite": "catalog:",
"@unplugin-pwa/core": "catalog:",
"@vite-pwa/astro": "catalog:",
"@vite-pwa/workbox-swkit": "catalog:",
"@vite-pwa/workbox-window": "catalog:",
"magicast": "catalog:",
"rolldown": "catalog:",
Expand Down
1 change: 1 addition & 0 deletions apps/bulls-and-cows/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="@unplugin-pwa/core/info" />
/// <reference types="@unplugin-pwa/core/vanillajs" />

/// <reference types="@vite-pwa/workbox-swkit" />
/// <reference types="@vite-pwa/workbox-window" />
/// <reference types="magicast" />
/// <reference types="rolldown" />
Expand Down
2 changes: 1 addition & 1 deletion apps/bulls-and-cows/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Layout from "#layout";

const id = "bulls-and-cows";
const title = "Bulls and Cows";
const canonical = `https://games.rman.dev/${id}`;
const canonical = `https://${id}.rman.dev/`;
const description = `Classic Bulls and Cows game. Play on ${canonical}`;
---

Expand Down
17 changes: 15 additions & 2 deletions apps/wordle/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import solid from "@astrojs/solid-js";
import tailwindcss from "@tailwindcss/vite";
import { AstroPWAIntegration } from "@vite-pwa/astro";
import { defineConfig } from "astro/config";

export default defineConfig({
output: "static",
integrations: [solid()],
integrations: [
solid(),
AstroPWAIntegration({
manifest: {
name: "Wordle",
short_name: "Wordle",
theme_color: "#6AAA64",
icons: [
{ src: "icons/192x192.png", sizes: "192x192", type: "image/png" },
Comment thread
gameroman marked this conversation as resolved.
Resolved
{ src: "icons/512x512.png", sizes: "512x512", type: "image/png" },
],
},
}),
],
vite: { plugins: [tailwindcss()], build: { cssTarget: "safari15" } },
site: "https://wordle.rman.dev",
});
6 changes: 6 additions & 0 deletions apps/wordle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"devDependencies": {
"@astrojs/solid-js": "catalog:",
"@tailwindcss/vite": "catalog:",
"@unplugin-pwa/core": "catalog:",
"@vite-pwa/astro": "catalog:",
"@vite-pwa/workbox-swkit": "catalog:",
"@vite-pwa/workbox-window": "catalog:",
"magicast": "catalog:",
"rolldown": "catalog:",
"wrangler": "catalog:"
}
}
Binary file added apps/wordle/public/favicon.ico
Binary file not shown.
Binary file added apps/wordle/public/icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions apps/wordle/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import answersRaw from "./data/answers.txt?raw";
import guessesRaw from "./data/guesses.txt?raw";

function parseWords(raw: string): string[] {
return raw
.split("\n")
.map((word) => word.trim())
.filter(Boolean);
}

const answers = parseWords(answersRaw);

export const WORDS = {
guesses: [] as string[],
answers: [] as string[],
guesses: new Set(parseWords(guessesRaw).concat(answers)),
answers,

answersRaw,
guessesRaw,
};

export const CONFIG = {
Expand All @@ -14,8 +29,5 @@ export const CONFIG = {
AZERTY: ["AZERTYUIOP", "QSDFGHJKLM", "WXCVBN"],
},

dataUrls: {
guesses: "/data/guesses.txt",
answers: "/data/answers.txt",
},
gameUrl: "https://wordle.rman.dev/",
} as const;
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions apps/wordle/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="@unplugin-pwa/core/info" />
/// <reference types="@unplugin-pwa/core/vanillajs" />

/// <reference types="@vite-pwa/workbox-swkit" />
/// <reference types="@vite-pwa/workbox-window" />
/// <reference types="magicast" />
/// <reference types="rolldown" />

declare module "#styles" {}
23 changes: 2 additions & 21 deletions apps/wordle/src/hooks/useGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function useGame() {
}

async function submitGuess(guess: string) {
if (!WORDS.guesses.includes(guess)) {
if (!WORDS.guesses.has(guess)) {
await shakeCurrentRow();
showNotification(`Word ${guess.toUpperCase()} does not exist`);
return;
Expand Down Expand Up @@ -144,25 +144,6 @@ export function useGame() {
});
}

async function fetchWords() {
try {
const [guessesString, answersString] = await Promise.all([
fetch(CONFIG.dataUrls.guesses).then((r) => r.text()),
fetch(CONFIG.dataUrls.answers).then((r) => r.text()),
]);

const guesses = guessesString.split("\n").map((word) => word.trim());
const answers = answersString.split("\n").map((word) => word.trim());

WORDS.guesses = guesses.concat(answers);
WORDS.answers = answers;
} catch (error) {
console.error("Error fetching words:", error);
}

return WORDS;
}

function handleBoardAction(action: BoardAction) {
if (getState() !== "playing") return;

Expand Down Expand Up @@ -231,7 +212,7 @@ export function useGame() {
}

function init() {
fetchWords().then(() => startNewGame("daily"));
startNewGame("daily");
document.addEventListener("keydown", (event) => {
const action = getBoardAction(event);
if (!action) return;
Expand Down
23 changes: 19 additions & 4 deletions apps/wordle/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
---
import "#styles";

import { pwaInfo } from "virtual:pwa-info";

import type { JSXElement } from "solid-js";

interface Props {
title: string;
description: string;
canonical: string;
thumbnail: string;
children: unknown;
children: () => JSXElement;
}

const { title, description, canonical, thumbnail } = Astro.props;
const { title, description, canonical } = Astro.props;

const thumbnail = "/icons/512x512.png";
---

<html lang="en" class="h-screen">
Expand All @@ -33,7 +38,17 @@ const { title, description, canonical, thumbnail } = Astro.props;
<meta name="twitter:image" content={thumbnail} />

<link rel="canonical" href={canonical} />
<link rel="shortcut icon" href={thumbnail} type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />

<link rel="apple-touch-icon" href="/icons/192x192.png" />

{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}

<script>
import { registerSW } from "virtual:pwa-register";

registerSW({ immediate: true });
</script>
</head>

<body class="bg-light dark:bg-dark text-dark dark:text-light font-app">
Expand Down
12 changes: 6 additions & 6 deletions apps/wordle/src/lib/get-guess-patern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { getTileColors } from "./get-tile-colors";

type PatternSymbol = "🟩" | "🟨" | "⬛";

const colorMap = {
absent: "⬛",
present: "🟨",
correct: "🟩",
} as const satisfies Record<TileColor, PatternSymbol>;

function getGuessPattern(
guesses: readonly string[],
secretWord: string,
): string {
const pattern: string[] = [];

const colorMap = {
absent: "⬛",
present: "🟨",
correct: "🟩",
} as const satisfies Record<TileColor, PatternSymbol>;

for (const guess of guesses) {
const colors = getTileColors(guess, secretWord);
const rowPattern: PatternSymbol[] = colors.map((color) => colorMap[color]);
Expand Down
3 changes: 2 additions & 1 deletion apps/wordle/src/lib/show-share-popup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CONFIG } from "#config";
import { getGuessPattern } from "./get-guess-patern";

export function getSharePopupData({
Expand All @@ -19,7 +20,7 @@ export function getSharePopupData({
const topText = isWin
? `I guessed a word in Wordle in ${attempts} attempts`
: `I did not guess a word in Wordle`;
const shareText = `${topText}\n\n${pattern}\n\nPlay on ${window.location.href}`;
const shareText = `${topText}\n\n${pattern}\n\nPlay on ${CONFIG.gameUrl}`;

return { isWin, title, pattern, shareText };
}
7 changes: 7 additions & 0 deletions apps/wordle/src/pages/data/answers.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { APIRoute } from "astro";
import { WORDS } from "#config";

// biome-ignore lint/nursery/useReactFunctionComponentDefinition: false positive
export const GET: APIRoute = () => {
return new Response(WORDS.answersRaw);
};
7 changes: 7 additions & 0 deletions apps/wordle/src/pages/data/guesses.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { APIRoute } from "astro";
import { WORDS } from "#config";

// biome-ignore lint/nursery/useReactFunctionComponentDefinition: false positive
export const GET: APIRoute = () => {
return new Response(WORDS.guessesRaw);
};
7 changes: 3 additions & 4 deletions apps/wordle/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
import Game from "#components/Game";
import { CONFIG } from "#config";
import Layout from "#layout";

const id = "wordle";
const title = "Wordle - Daily and Unlimited Word Puzzle Game";
const canonical = `https://games.rman.dev/${id}`;
const canonical = CONFIG.gameUrl;
const description = `Challenge yourself with Wordle, the addictive daily word puzzle. Enjoy unlimited games or a new daily challenge. Play now on ${canonical}`;
const thumbnail = `/images/${id}.png`;
---

<Layout {title} {description} {canonical} {thumbnail}>
<Layout {title} {description} {canonical}>
<Game client:only="solid-js" />
</Layout>
8 changes: 8 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@tailwindcss/vite": "4.3.5",
"@unplugin-pwa/core": "0.0.3",
"@vite-pwa/astro": "2.0.0",
"@vite-pwa/workbox-swkit": "8.0.14",
"@vite-pwa/workbox-window": "8.0.14",
"astro": "7.4.2",
"magicast": "0.5.5",
Expand Down
Loading