fix: daily reset

This commit is contained in:
Maxwell Paradis 2025-04-07 22:24:28 -05:00
parent 37323c4fda
commit 846b934ed2
2 changed files with 11 additions and 4 deletions

View File

@ -146,7 +146,8 @@ app.get("/", (req, res) => {
app.get("/api/blocks", (req, res) => { app.get("/api/blocks", (req, res) => {
console.log(dailyBlocks[0]); console.log(dailyBlocks[0]);
res.send(dailyBlocks); let data = {blocks: dailyBlocks, day: getDay(0)}
res.send(data);
}); });
app.get("/api/scoreboard", async (req, res) => { app.get("/api/scoreboard", async (req, res) => {

View File

@ -19,6 +19,7 @@
let score: number = 0; let score: number = 0;
let gameEnding: boolean = false; let gameEnding: boolean = false;
let gameOver: boolean = false; let gameOver: boolean = false;
let day: number = 100000;
let fdef: any[] = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]; let fdef: any[] = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
let cdef: any[] = [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3]; let cdef: any[] = [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3];
@ -110,8 +111,9 @@
async function gameSetup() { async function gameSetup() {
await axios.get('/api/blocks').then((res) => { await axios.get('/api/blocks').then((res) => {
blocks = res.data; blocks = res.data.blocks;
//console.log(blocks); day = res.data.day;
//console.log(day);
}) })
.catch((error) => { .catch((error) => {
if(error.code != 'ERR_INVALID_URL') console.error('Error fetching data:', error); if(error.code != 'ERR_INVALID_URL') console.error('Error fetching data:', error);
@ -122,8 +124,9 @@
? JSON.parse(cacheData) ? JSON.parse(cacheData)
: { : {
daily: Array.from({ length: 25 }, (_, index) => index), daily: Array.from({ length: 25 }, (_, index) => index),
day: 100000,
}; };
if (cacheGame.daily.join("") == daily.join("")) { if (cacheGame.day == day) {
//playing = cacheGame.playing; gameOver instead of playing //playing = cacheGame.playing; gameOver instead of playing
cube = cacheGame.cube || cube; cube = cacheGame.cube || cube;
current = cacheGame.current || 0; current = cacheGame.current || 0;
@ -215,6 +218,7 @@
gameOver: gameOver, gameOver: gameOver,
daily: daily, daily: daily,
score: score, score: score,
day: day,
}; };
localStorage.setItem("gameState", JSON.stringify(gameState)); localStorage.setItem("gameState", JSON.stringify(gameState));
}; };
@ -230,6 +234,7 @@
gameOver: gameOver, gameOver: gameOver,
daily: daily, daily: daily,
score: score, score: score,
day: day,
}; };
localStorage.setItem("gameState", JSON.stringify(gameState)); localStorage.setItem("gameState", JSON.stringify(gameState));
let data = { let data = {
@ -259,6 +264,7 @@
gameOver: gameOver, gameOver: gameOver,
daily: daily, daily: daily,
score: score, score: score,
day: day,
}; };
localStorage.setItem("gameState", JSON.stringify(gameState)); localStorage.setItem("gameState", JSON.stringify(gameState));
gameSetup(); gameSetup();