diff --git a/package.json b/package.json index 81ed333..f469736 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "donder-hiroba-plus", "private": true, - "version": "0.2.8.5", + "version": "0.2.8.6", "type": "module", "scripts": { "dev": "vite dev", diff --git a/src/components/Rating/RatingApp.svelte b/src/components/Rating/RatingApp.svelte index 8ee5e10..c3e01f8 100644 --- a/src/components/Rating/RatingApp.svelte +++ b/src/components/Rating/RatingApp.svelte @@ -26,12 +26,14 @@ let scoreDataSorted: Array<{ songName: string, difficulty: string, score: DifficultyScoreData, songNo: string }> = [] let totalPlayCount: string = '0 / 0 / 0 / 0' let openPlayCount: boolean = false + let disabledRecent: boolean = true onMount(async () => { await storage.loadFromChromeStorage() storageLoaded = true lastUpdated = storage.getLastUpdated() updateScoreDataSorted() + disabledRecent = storage.getCount() === 0 }) const updateScoreDataSorted = (): void => { @@ -68,11 +70,11 @@ return wikiUser.logined === true } + let waitTime = 3000 async function fetchScoreForSong (songNo: string, clearData: ClearData): Promise { const response: { songNo: string, body: { oni?: string, ura?: string } } = { songNo, body: {} } - let waitTime = 3000 while (true) { try { if (clearData.difficulty.oni === undefined) break @@ -107,10 +109,12 @@ } async function uploadToWiki (donderData: CardData, clearData: ClearData[], scoreDataMap: Record): Promise { + await storage.mergeMap(scoreDataMap) + const data = JSON.stringify({ donderData, clearData, - scoreData: scoreDataMap + scoreData: storage.getMap() }) const compressedBody = lzutf8.compress(data, { @@ -126,7 +130,6 @@ } }) - await storage.mergeMap(scoreDataMap) updateScoreDataSorted() } @@ -154,15 +157,21 @@ await hiroba.updateScore(null) const clearData = await hiroba.getClearData(null) + const songNameToSongNos = new Map() + for (const song of clearData) { + if (songNameToSongNos.has(song.title)) { + songNameToSongNos.get(song.title)?.push(song.songNo) + console.log(song.title, songNameToSongNos.get(song.title)) + } else { + songNameToSongNos.set(song.title, [song.songNo]) + } + } + if (sendType === 'clear') { uploadMessage = 'Uploading clear data...' await uploadToWiki(cardData, clearData, {}) } else if (sendType === 'recent') { uploadMessage = 'Fetching recent score data...' - const songNameToSongNo = new Map() - for (const song of clearData) { - songNameToSongNo.set(song.title, song.songNo) - } counts = nRecentPageToFetch complete = 0 @@ -179,11 +188,13 @@ const scoreDataMap: Record = {} for (const recentScore of recentScoreData) { - const songNo = songNameToSongNo.get(recentScore.songName) - if (songNo === undefined) { - console.warn(`songNo not found for ${recentScore.songName}`) + const songNos = songNameToSongNos.get(recentScore.songName) + if (songNos === undefined || songNos.length > 1) { + console.warn(`multiple or undefined songNos found for ${recentScore.songName}`) continue } + const songNo = songNos[0] + const score = recentScore.scoreData if (scoreDataMap[songNo] === undefined) { scoreDataMap[songNo] = { @@ -195,10 +206,18 @@ scoreDataMap[songNo].difficulty[recentScore.difficulty] = score } - console.log(nRecentPageToFetch) - console.log(recentScoreData) - console.log(songNameToSongNo) - console.log(scoreDataMap) + for (const songNos of songNameToSongNos.values()) { + if (songNos !== undefined && songNos.length > 1) { + for (const songNo of songNos) { + const score = await fetchScoreForSong( + songNo, clearData.find(song => song.songNo === songNo) + ) + if (score !== null) { + scoreDataMap[songNo] = score + } + } + } + } await uploadToWiki(cardData, clearData, scoreDataMap) @@ -206,10 +225,6 @@ scene = 'ready' } else if (sendType === 'all') { uploadMessage = 'Fetching recent score data...' - const songNameToSongNo = new Map() - for (const song of clearData) { - songNameToSongNo.set(song.title, song.songNo) - } complete = 0 uploadMessage = 'Fetch score data... (0/?)' @@ -233,11 +248,13 @@ const scoreDataMap: Record = {} for (const recentScore of recentScoreData) { - const songNo = songNameToSongNo.get(recentScore.songName) - if (songNo === undefined) { - console.warn(`songNo not found for ${recentScore.songName}`) + const songNos = songNameToSongNos.get(recentScore.songName) + if (songNos === undefined || songNos.length > 1) { + console.warn(`multiple or undefined songNos found for ${recentScore.songName}`) continue } + const songNo = songNos[0] + const score = recentScore.scoreData if (scoreDataMap[songNo] === undefined) { scoreDataMap[songNo] = { @@ -249,10 +266,16 @@ scoreDataMap[songNo].difficulty[recentScore.difficulty] = score } - console.log(nRecentPageToFetch) - console.log(recentScoreData) - console.log(songNameToSongNo) - console.log(scoreDataMap) + for (const songNos of songNameToSongNos.values()) { + if (songNos !== undefined && songNos.length > 1) { + for (const songNo of songNos) { + const score = await fetchScoreForSong(songNo, clearData.find(song => song.songNo === songNo)) + if (score !== null) { + scoreDataMap[songNo] = score + } + } + } + } await uploadToWiki(cardData, clearData, scoreDataMap) @@ -287,8 +310,6 @@ } } - console.log(scoreDataMap, clearData) - await uploadToWiki(cardData, clearData, scoreDataMap) } @@ -313,32 +334,36 @@ + -