Tutoriel
+Tutorial
-
--- a/assets/menu.html 2026-10-30 18:04:00.579159399 -0300 +++ b/assets/menu.html 2026-10-30 18:29:20.899103564 -0300 @@ -1,5 +1,5 @@
--- a/src/game.js 2026-10-30 18:04:00.596774796 -0300 +++ b/src/game.js 2026-10-30 18:29:20.898478717 -0300 @@ -22,9 +22,7 @@ }; async function setup() { - await loadFont( - "https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap" - ); + // FredyGames: the Google Fonts stylesheet that was loaded here is gone; the sketch uses the default font. // console.clear(); const canvasElement = document.getElementById("game"); --- a/src/highscore.js 2026-10-30 18:04:00.597515273 -0300 +++ b/src/highscore.js 2026-10-30 18:29:20.897899954 -0300 @@ -1,55 +1,36 @@ -const privateKeys = { - daily1D: "gH17vCt6G0W2dJC9SzKChAijufOea8ZUiv30ZuN2pqqw", // Replace with your actual private code - daily2D3: "yV7h_o5QzkGYDv1x97LKngLHMFZovBuUaglOTCtoTGFQ", // Replace with your actual private code - daily2D4: "yn-N5KwdOkScT0-dg9c7YA2AA4Zjvx1UCFuiDDg_zCyA", // Replace with your actual private code -}; - -async function sendRequestDreamlo(key, command, user, score, time) { - let url = `https://dreamlo.com/lb/${privateKeys[key]}`; - - switch (command) { - case "add": - url += `/add/${encodeURIComponent(user)}/${score}/${time}`; - break; - case "json": - url += `/json${key === "daily1D" ? "-seconds-asc" : ""}`; - break; - default: - throw new Error(`Unknown command: ${command}`); - } +// FredyGames: the daily leaderboards were online (dreamlo.com). Here they are kept in this browser's +// localStorage, with the same entry shape ({ name, score, seconds }) and the same two functions. +const LOCAL_SCORES_PREFIX = "tilescollector_scores_"; +const LOCAL_SCORES_MAX = 20; +function readLocalScores(mode) { try { - const response = await fetch(url, { mode: "cors" }); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - if (command === "add") { - return await response.text(); - } else if (command === "json") { - const text = await response.json(); - return text; - } + const entries = JSON.parse( + localStorage.getItem(LOCAL_SCORES_PREFIX + mode) || "[]" + ); + return Array.isArray(entries) ? entries : []; } catch (error) { - console.error("Error sending request to Dreamlo:", error); - throw error; + return []; } } async function submitScore(mode, user, score, time) { + const entries = readLocalScores(mode); + entries.push({ name: String(user).slice(0, 40), score: Number(score), seconds: Number(time) }); + // 1D: shortest time first; 2D: highest score first, then shortest time + entries.sort((a, b) => + mode === "daily1D" ? a.seconds - b.seconds : b.score - a.score || a.seconds - b.seconds + ); try { - const response = await sendRequestDreamlo(mode, "add", user, score, time); - console.log("Score submitted successfully:", response); + localStorage.setItem( + LOCAL_SCORES_PREFIX + mode, + JSON.stringify(entries.slice(0, LOCAL_SCORES_MAX)) + ); } catch (error) { - console.error("Failed to submit score:", error); + console.error("Failed to save score:", error); } } -async function getScores(mode) { - try { - const response = await sendRequestDreamlo(mode, "json", "", ""); - return response.dreamlo.leaderboard.entry; - } catch (error) { - console.error("Failed to retrieve scores:", error); - return []; - } +async function getScores(mode) { + return readLocalScores(mode); } --- a/src/MenuHandler.js 2026-10-30 18:04:00.598811847 -0300 +++ b/src/MenuHandler.js 2026-10-30 18:29:20.898795516 -0300 @@ -54,13 +54,11 @@ if (oldMenu) oldMenu.remove(); // Get the modals HTML and append to body - Promise.all([ - fetch("./assets/sandboxModal.html").then((response) => response.text()), - fetch("./assets/settingsModal.html").then((response) => response.text()), - ]).then(([sandboxModalHTML, settingsModalHTML]) => { - document.body.insertAdjacentHTML("beforeend", sandboxModalHTML); - document.body.insertAdjacentHTML("beforeend", settingsModalHTML); - }); + fetch("./assets/sandboxModal.html") + .then((response) => response.text()) + .then((sandboxModalHTML) => { + document.body.insertAdjacentHTML("beforeend", sandboxModalHTML); + }); // Get the static menu HTML and append to #game container fetch("./assets/menu.html") .then((response) => response.text()) @@ -143,30 +141,5 @@ menu.remove(); Game.changeMode(GameState.PLAY); }; - - // Palette select - const paletteSelect = document.getElementById("paletteSelect"); - colorPalettes.forEach((palette, idx) => { - const opt = document.createElement("option"); - opt.value = idx; - opt.innerText = palette.name || `Palette ${idx + 1}`; - paletteSelect.appendChild(opt); - }); - paletteSelect.onchange = () => { - Game.setPalette(parseInt(paletteSelect.value)); - }; - - // Colorblind mode - const cbCheckbox = document.getElementById("cbCheckbox"); - cbCheckbox.checked = Game.colorblindMode || false; - cbCheckbox.onchange = () => { - Game.setColorblindMode(cbCheckbox.checked); - }; - - // Leaderboard button - document.getElementById("leaderboardBtn").onclick = () => { - menu.remove(); - Game.showLeaderboard(); - }; }); }