From bd5c8e7872568278b678d12fe350c146e8612b1d Mon Sep 17 00:00:00 2001 From: sup39 Date: Mon, 16 Oct 2023 16:47:26 +0900 Subject: [PATCH] Added dependencies information to generated ini/txt --- changelog.md | 3 ++ site/.vuepress/components/CodeList.vue | 2 +- site/.vuepress/components/DownloadButton.vue | 47 +++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 7a0af5b..97719e1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Changelog +## Oct 16, 2023 +Added dependencies information to generated ini/txt + ## Jul 15, 2023 ### Fixed the bug that background color cannot be changed in 'Controller Input Display' ### Ported 'FastForward', 'InstantRestart', 'SpawnYoshi', 'StageIntroSkip' to all versions diff --git a/site/.vuepress/components/CodeList.vue b/site/.vuepress/components/CodeList.vue index 4aed5b2..44b6fc6 100644 --- a/site/.vuepress/components/CodeList.vue +++ b/site/.vuepress/components/CodeList.vue @@ -114,7 +114,7 @@ export default { const selectedCodes = this.availableCodes.filter((c) => c.selected); // add dependencies const deps = new Set(selectedCodes.flatMap(c => c.dependencies)); - selectedCodes.push(...this.codes.filter(c => deps.has(c.id))); + selectedCodes.push(...this.availableCodes.filter(c => !c.selected && deps.has(c.id))); // emit this.onSelectionChanged(selectedCodes); }, diff --git a/site/.vuepress/components/DownloadButton.vue b/site/.vuepress/components/DownloadButton.vue index 5602644..af4eb7f 100644 --- a/site/.vuepress/components/DownloadButton.vue +++ b/site/.vuepress/components/DownloadButton.vue @@ -35,7 +35,39 @@ export default { if ((!this.codes || !this.codes.length) && !this.stageLoaderCode) { return; } - const codeList = this.codes.map((c) => ({ ...c })); + + const codeList = this.codes.map((c) => ({ + ...c, + // for recording previous downloaded code + titleEN: c.title.find(o => o.lang === 'en-US').content, + // for generated txt, ini + title: translateCode(c, this.$lang).title, + })); + + // add dependencies information to title + const id2code = Object.fromEntries(codeList.map(c => [c.id, c])); + const depBys = {}; + /* depends on */ + for (const c of codeList) { + if (c.dependencies.length) { + c.dependencies.forEach(id => { + depBys[id] ??= []; + depBys[id].push(c.title); + }); + const depList = c.dependencies.map(id => id2code[id].title).join(', '); + c.title += ` **(REQUIRES: ${depList})**`; + } + } + /* used by */ + for (const [id, depBy] of Object.entries(depBys)) { + id2code[id].title += ` (Used by: ${depBy.join(', ')})`; + } + + // save downloaded code list + try { + const codeTitles = codeList.map(c => c.titleEN); + localStorage.setItem(lskeyLDC, JSON.stringify(codeTitles)); + } catch {} if (this.stageLoaderCode) codeList.push({ @@ -62,12 +94,6 @@ export default { ]); } catch {} - // save download code list - try { - const codeTitles = codeList.map(c => c.title.find(o => o.lang === 'en-US').content); - localStorage.setItem(lskeyLDC, JSON.stringify(codeTitles)); - } catch {} - const fileName = gameVersions.find((v) => v.identifier === this.versionIdentifier).version; // apply customizable codes @@ -127,10 +153,7 @@ export default { let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]'; codes.forEach((code) => { - const codeTitle = - typeof code.title === 'string' ? code.title : translateCode(code, this.$lang).title; - - data += `\r\n$${codeTitle} (${code.date}) [${code.author}]\r\n`; + data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`; data += code.source .match(/.{8}/g) .join(' ') @@ -146,7 +169,7 @@ export default { const codeTitle = typeof code.title === 'string' ? code.title : translateCode(code, this.$lang).title; - data += `\r\n\r\n${codeTitle} (${code.date}) [${code.author}]\r\n`; + data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`; data += code.source .match(/.{8}/g) .join(' ')