Skip to content

Commit 9dd4797

Browse files
authored
4.2.4.6 (MOBILE 4.2! 19/08/2024) localStorage cleanup
1 parent fc66ec7 commit 9dd4797

File tree

6 files changed

+80
-43
lines changed

6 files changed

+80
-43
lines changed

BeatzGame.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Title: Beatz
33
* Author: Victor//GuayabR
44
* Date: 16/05/2024
5-
* Version: MOBILE 4.2.4.7 (release.version.subversion.bugfix)
5+
* Version: MOBILE 4.2.4.6 test (release.version.subversion.bugfix)
66
* GitHub Repository: https://github.com/GuayabR/Beatz
77
**/
88

99
// CONSTANTS
1010

1111
const userDevice = detectDeviceType();
1212

13-
const VERSION = "MOBILE 4.2.4.7 (Codename.Release.Version.Subversion.Bugfix)";
13+
const VERSION = "MOBILE 4.2.4.6 (Codename.Release.Version.Subversion.Bugfix)";
1414
var PUBLICVERSION = `4.2! (${userDevice} Port)`;
1515
console.log("Version: " + VERSION);
1616

@@ -2225,9 +2225,26 @@ function formatTimestampDS(seconds) {
22252225
}
22262226
}
22272227

2228+
function removeLowPointSongs() {
2229+
songList.forEach((song) => {
2230+
let title = getSongTitle(song);
2231+
const songData = localStorage.getItem(title);
2232+
if (songData) {
2233+
const songStats = JSON.parse(songData);
2234+
if (songStats.points <= 10) {
2235+
localStorage.removeItem(title);
2236+
logWarn(`Removed "${title}" from localStorage due to insufficient points.`);
2237+
}
2238+
}
2239+
});
2240+
}
2241+
22282242
function startGame(index, versionPath, setIndex) {
22292243
songMetadataLoaded = false; // Reset flag to false at the start of the game
22302244

2245+
// Check and remove songs with low points from localStorage
2246+
removeLowPointSongs();
2247+
22312248
if (versionPath) {
22322249
currentSongPath = versionPath;
22332250
currentSongIndex = setIndex >= 0 ? setIndex : songList.indexOf(currentSongPath);
@@ -2365,6 +2382,9 @@ function startGame(index, versionPath, setIndex) {
23652382
}
23662383
} else {
23672384
nextSpeedChange = "No more speed changes.";
2385+
setTimeout(() => {
2386+
nextSpeedChange = "";
2387+
}, 5000);
23682388
}
23692389
} else {
23702390
clearInterval(speedUpdater);
@@ -2415,7 +2435,7 @@ function startGame(index, versionPath, setIndex) {
24152435

24162436
// Update the page title
24172437
indexToDisplay = setIndex >= 0 ? setIndex : currentSongIndex;
2418-
document.title = `Song ${indexToDisplay + 1}: ${getSongTitle(currentSongPath)} | Beatz 4.2!`;
2438+
document.title = `Song ${indexToDisplay + 1}: ${getSongTitle(currentSongPath)} | Beatz Testing 4.2!`;
24192439

24202440
console.log(`indexToDisplay converted in startGame: ${indexToDisplay}`);
24212441
};
@@ -2440,7 +2460,7 @@ function saveScore(song, points, perfects, misses, earlylates, maxstreak) {
24402460
} else if (points <= 10) {
24412461
logNotice(`At least 10 points needed to save score. Points: ${points}.`);
24422462
return;
2443-
}
2463+
}
24442464

24452465
const score = {
24462466
points: points,
@@ -2463,10 +2483,10 @@ function saveScore(song, points, perfects, misses, earlylates, maxstreak) {
24632483
} else {
24642484
logNotice(`Score for ${song} is not higher than existing best score, score has not been saved.`);
24652485
}
2466-
} else {
2486+
} else if (!existingScoreStr) {
24672487
// If no existing score, save the new score
24682488
localStorage.setItem(song, JSON.stringify(score));
2469-
logNotice(`Score for ${song} saved to localStorage as the first best score. Nice!`);
2489+
logNotice(`Score for ${song} saved to localStorage as your first new best score with ${points} points. Nice!`);
24702490
}
24712491
} catch (error) {
24722492
console.error(`Error saving score for ${song} to localStorage:`, error);
@@ -2550,6 +2570,16 @@ function drawEndScreen() {
25502570
ctx.drawImage(BGbright, 0, 0, 1280, 720);
25512571
}
25522572

2573+
noteYPositions.left = [];
2574+
noteYPositions.up = [];
2575+
noteYPositions.down = [];
2576+
noteYPositions.right = [];
2577+
2578+
console.log(noteYPositions.left);
2579+
console.log(noteYPositions.down);
2580+
console.log(noteYPositions.up);
2581+
console.log(noteYPositions.right);
2582+
25532583
// Draw "Song completed!" text
25542584
ctx.fillStyle = "white";
25552585
ctx.font = "60px Arial";
@@ -2589,7 +2619,7 @@ function drawEndScreen() {
25892619
ctx.fillText("Maximum streak: " + maxStreak, WIDTH / 2, HEIGHT / 2 + 200);
25902620
}
25912621

2592-
console.log("Functions saveScore, getBestScore, displayBestScore, and onSongEnd loaded.");
2622+
console.log("Saving logic loaded.");
25932623

25942624
console.log("Ready to start Beatz.");
25952625

BeatzGameTesting.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,9 +2225,26 @@ function formatTimestampDS(seconds) {
22252225
}
22262226
}
22272227

2228+
function removeLowPointSongs() {
2229+
songList.forEach((song) => {
2230+
let title = getSongTitle(song);
2231+
const songData = localStorage.getItem(title);
2232+
if (songData) {
2233+
const songStats = JSON.parse(songData);
2234+
if (songStats.points <= 10) {
2235+
localStorage.removeItem(title);
2236+
logWarn(`Removed "${title}" from localStorage due to insufficient points.`);
2237+
}
2238+
}
2239+
});
2240+
}
2241+
22282242
function startGame(index, versionPath, setIndex) {
22292243
songMetadataLoaded = false; // Reset flag to false at the start of the game
22302244

2245+
// Check and remove songs with low points from localStorage
2246+
removeLowPointSongs();
2247+
22312248
if (versionPath) {
22322249
currentSongPath = versionPath;
22332250
currentSongIndex = setIndex >= 0 ? setIndex : songList.indexOf(currentSongPath);
@@ -2365,6 +2382,9 @@ function startGame(index, versionPath, setIndex) {
23652382
}
23662383
} else {
23672384
nextSpeedChange = "No more speed changes.";
2385+
setTimeout(() => {
2386+
nextSpeedChange = "";
2387+
}, 5000);
23682388
}
23692389
} else {
23702390
clearInterval(speedUpdater);
@@ -2434,6 +2454,12 @@ function saveScore(song, points, perfects, misses, earlylates, maxstreak) {
24342454
if (autoHitDisableSaving) {
24352455
logNotice(`Score for ${song} not saved because Auto Hit was enabled during gameplay. Don't cheat!`, "rgb(190, 50, 0)");
24362456
return;
2457+
} else if (maxstreak === 0) {
2458+
logNotice(`You went AFK for the whole song. Score has not been saved.`);
2459+
return;
2460+
} else if (points <= 10) {
2461+
logNotice(`At least 10 points needed to save score. Points: ${points}.`);
2462+
return;
24372463
}
24382464

24392465
const score = {
@@ -2454,17 +2480,13 @@ function saveScore(song, points, perfects, misses, earlylates, maxstreak) {
24542480
// Update localStorage with new score
24552481
localStorage.setItem(song, JSON.stringify(score));
24562482
logNotice(`New best score for ${song} with ${points} points. Amazing!`);
2457-
} else if (maxstreak === 0) {
2458-
logNotice(`You went AFK for the whole song. Score has not been saved.`);
2459-
} else if (points <= 10) {
2460-
logNotice(`At least 10 points needed to save score. Points: ${points}.`);
24612483
} else {
24622484
logNotice(`Score for ${song} is not higher than existing best score, score has not been saved.`);
24632485
}
2464-
} else {
2486+
} else if (!existingScoreStr) {
24652487
// If no existing score, save the new score
24662488
localStorage.setItem(song, JSON.stringify(score));
2467-
logNotice(`Score for ${song} saved to localStorage as the first best score. Nice!`);
2489+
logNotice(`Score for ${song} saved to localStorage as your first new best score with ${points} points. Nice!`);
24682490
}
24692491
} catch (error) {
24702492
console.error(`Error saving score for ${song} to localStorage:`, error);
@@ -2548,6 +2570,16 @@ function drawEndScreen() {
25482570
ctx.drawImage(BGbright, 0, 0, 1280, 720);
25492571
}
25502572

2573+
noteYPositions.left = [];
2574+
noteYPositions.up = [];
2575+
noteYPositions.down = [];
2576+
noteYPositions.right = [];
2577+
2578+
console.log(noteYPositions.left);
2579+
console.log(noteYPositions.down);
2580+
console.log(noteYPositions.up);
2581+
console.log(noteYPositions.right);
2582+
25512583
// Draw "Song completed!" text
25522584
ctx.fillStyle = "white";
25532585
ctx.font = "60px Arial";
@@ -2587,7 +2619,7 @@ function drawEndScreen() {
25872619
ctx.fillText("Maximum streak: " + maxStreak, WIDTH / 2, HEIGHT / 2 + 200);
25882620
}
25892621

2590-
console.log("Functions saveScore, getBestScore, displayBestScore, and onSongEnd loaded.");
2622+
console.log("Saving logic loaded.");
25912623

25922624
console.log("Ready to start Beatz.");
25932625

index.html

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,35 +184,11 @@ <h4><span id="presetSaved" style="color: white; display: none">Preset has been s
184184
</div>
185185
<br /><br />
186186

187-
<!-- Button to Open the Modal -->
188-
<button id="openCustomSongModal">Add your Custom Song!</button>
189-
190-
<!-- Modal Structure -->
191-
<div id="customSongModal" class="modal">
192-
<div class="modal-content">
193-
<span id="closeCustomSongModal" class="close"><i class="fa-solid fa-xmark"></i></span>
194-
<h1>Add Custom Song</h1>
195-
<label for="customSongTitle">Title:</label>
196-
<input type="text" id="customSongTitle" placeholder="Enter song title" /><br /><br />
197-
198-
<label for="songFile">Upload MP3:</label>
199-
<input type="file" id="songFile" accept=".mp3" /><br /><br />
200-
201-
<label for="noteSpeed">Note Speed:</label>
202-
<input type="number" id="noteSpeed" min="1" max="50" placeholder="Enter note speed" /><br /><br />
203-
204-
<label for="bpm">BPM:</label>
205-
<input type="number" id="bpm" min="1" max="1000" placeholder="Enter BPM" /><br /><br />
206-
207-
<button id="createCustomSong">Create Custom Song!</button>
208-
</div>
209-
</div>
210-
211187
<div id="contactBtn">
212188
<button id="contactbtn" onclick="email()"><i class="fa-solid fa-envelope"></i> Contact</button>
213189
</div>
214190

215-
<div id="publicToTestToggle"><button id="publicbtn" onclick="toVersion()">Open public game</button><br /><br /></div>
191+
<div id="publicToTestToggle"><button id="publicbtn" onclick="toVersion()">Open testing game</button><br /><br /></div>
216192

217193
<h2>
218194
Background image from:

mobileStyles.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ body {
3737
bottom: 5;
3838
left: 5;
3939
border-radius: 4px;
40-
z-index: 1000;
4140
font-size: 14px;
4241
font-family: Arial, sans-serif;
4342
opacity: 1;
@@ -188,7 +187,7 @@ canvas {
188187
.modal {
189188
display: none;
190189
position: fixed;
191-
z-index: 1;
190+
z-index: 1000;
192191
left: 0;
193192
top: 2vh;
194193
width: 100%;

styles.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ html {
2626
bottom: 5;
2727
left: 5;
2828
border-radius: 4px;
29-
z-index: 1000;
3029
font-size: 14px;
3130
font-family: Arial, sans-serif;
3231
opacity: 1;
@@ -152,7 +151,7 @@ canvas:-ms-fullscreen {
152151
.modal {
153152
display: none;
154153
position: fixed;
155-
z-index: 1;
154+
z-index: 1000;
156155
left: 0;
157156
top: 2vh;
158157
width: 100%;

versions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,4 @@ Fixes or tweaks:
510510
4.2.4.7 (MOBILE 4.2! 18/08/2024)
511511
Added logging notices and warnings and styled them.
512512
Fixed default backgrounds being fixed to the canvas' viewport, noticeable in fullscreen mode.
513+
Added a localStorage cleanup system where every time you start up a new song, it checks for all saved song's scores and deletes all that are below 10 points.

0 commit comments

Comments
 (0)