1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-24 04:30:12 +01:00

Increased ttr for UserPlayLog

This commit is contained in:
Galexion 2023-02-18 08:33:40 -05:00
parent 29ffa2adf1
commit 74e99c500f
2 changed files with 91 additions and 65 deletions

View File

@ -73,8 +73,7 @@ function padNumber(num, size) {
return s;
}
async function getSongInformation(id) {
const musicData = await musicMetadata();
async function getSongInformation(musicData,id) {
const songMatch = musicData[id];
if (!songMatch) {
return null;
@ -144,25 +143,39 @@ request.send();
// User Play Log
async function userPlayLogFormatter(div) {
let scoreIncrement = 0;
let errorIncrement = 0;
let displayedScoreCount = 20;
async function userPlayLogFormatter(div, loadMoreButton) {
const UserPlayLogData = await UserPlayLog(aime_card_id);
const musicIds = UserPlayLogData.map(score => score.music_id);
const songs = await Promise.all(musicIds.map(getSongInformation));
let scoresWrapperDiv = document.getElementById("scoreWrapper");
let myDiv = document.getElementById("scoreWrapper");
if (myDiv === null) {
const scoresWrapperDiv = document.createElement('div');
// If the scores wrapper div doesn't exist, create it.
if (scoresWrapperDiv === null) {
scoresWrapperDiv = document.createElement('div');
scoresWrapperDiv.id = "scoreWrapper";
div.appendChild(scoresWrapperDiv);
}
for (let i = UserPlayLogData.length - 1; i >= 0; i--) {
const newDiv = document.createElement('div');
let score = JSON.parse(JSON.stringify(UserPlayLogData[i]));
let song = JSON.parse(JSON.stringify(songs[i]));
// Get the user's play log data and music IDs.
const musicIds = UserPlayLogData.map(score => score.music_id);
const musicData = await musicMetadata();
if (!song || !song.name) {
let errorIncrement = 0;
let scoreIncrement = 0;
const startIndex = scoresWrapperDiv.children.length;
const maxScores = startIndex + 20;
for (let i = startIndex; i < UserPlayLogData.length && scoreIncrement < maxScores; i++) {
const newDiv = document.createElement('div'); // Create a Div
let score = JSON.parse(JSON.stringify(UserPlayLogData[i])); // get score data
let song = await getSongInformation(musicData, score.music_id) // get song data
if (!song || !song.name) { // if a song can't be found, skip it and increment the error counter by 1.
console.log(song)
console.log(score.music_id)
console.log("Song or title is undefined");
errorIncrement++
continue;
}
@ -180,17 +193,30 @@ async function userPlayLogFormatter(div) {
newDiv.setAttribute("id", "score-grid");
newDiv.setAttribute("class", "item");
scoreIncrement++
scoresWrapperDiv.appendChild(newDiv);
}
div.appendChild(scoresWrapperDiv);
// Edit the Score Info Header with the relevant information.
const header = document.querySelector('#score-info-header');
header.textContent = `Showing ${startIndex + scoreIncrement - errorIncrement} out of ${UserPlayLogData.length} scores.`;
if (errorIncrement > 0) {
header.insertAdjacentHTML('afterend', `<p>${errorIncrement} Songs Failed to load properly, most likely due to missing information.</p>`);
}
// If there are no more scores to load, hide the "Load More" button.
if (startIndex + scoreIncrement >= UserPlayLogData.length) {
loadMoreButton.style.display = "none";
}
}
//=====================================================================
// Now Exiting: User Data ////////////// Now Entering: Nested Div Hell
//=====================================================================

View File

@ -37,7 +37,7 @@
</div>
</div><!-- This is just one nested div, Trmazi it's going to get a lot worse from here on. -->
<div data-content="content-2" id="user-play-data" class="hidden"> <!-- User Play-Log is generated at run time when the user clicks the button, so they get up to date data. -->
<h4>Please Wait, Obtaining Scores...</h4>
<h4 id="score-info-header">Please Wait, Obtaining Scores...</h4>
</div>
</div>