37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { DIFFICULTIES, getPuzzleNumber, MAX_ATTEMPTS, POSITIONS } from "./game-engine";
|
|
import type { Dictionary } from "./i18n";
|
|
import { formatElapsed } from "./time";
|
|
import type { DailyProgress, Difficulty } from "./types";
|
|
|
|
const emoji = {
|
|
correct: "🟩",
|
|
partial: "🟨",
|
|
wrong: "⬛",
|
|
empty: "⬛",
|
|
};
|
|
|
|
export function buildShareText(dateKey: string, progress: DailyProgress, t: Dictionary): string {
|
|
const rows = DIFFICULTIES.map((difficulty) => {
|
|
const item = progress[difficulty];
|
|
const label = t.difficulty[difficulty];
|
|
if (item.locked) return `${label.padEnd(8)} 🔒`;
|
|
|
|
const result = item.solved ? `${item.attempts.length}/${MAX_ATTEMPTS}` : `X/${MAX_ATTEMPTS}`;
|
|
const time = formatElapsed(item.elapsedSeconds);
|
|
const grids = item.attempts.length
|
|
? item.attempts
|
|
.map((attempt) =>
|
|
POSITIONS.map((position) => {
|
|
const slot = attempt.slots.find((candidate) => candidate.position === position);
|
|
return emoji[slot?.feedback ?? "empty"];
|
|
}).join(""),
|
|
)
|
|
.join("\n")
|
|
: "⬛⬛⬛⬛⬛";
|
|
|
|
return `${label} ${result} · ${time}\n${grids}`;
|
|
});
|
|
|
|
return [`hidden11 #${getPuzzleNumber(dateKey)}`, "", ...rows, "", "https://hidden11.app"].join("\n");
|
|
}
|