gctGenerator/site/.vuepress/components/DownloadButton.vue

139 lines
3.6 KiB
Vue
Raw Normal View History

2020-06-28 06:33:20 +09:00
<template>
2021-06-11 07:48:15 +09:00
<div>
<ButtonComponent
label="Download"
:onClick="onClick"
:disabled="(!codes || codes.length === 0) && !stageLoaderCode"
2022-01-17 03:17:07 +09:00
/>
2021-06-11 07:48:15 +09:00
</div>
2020-06-28 06:33:20 +09:00
</template>
<script>
2020-06-30 05:30:29 +09:00
// Data
import gameVersions from '../data/gameVersions.json';
2020-07-10 12:21:13 +09:00
// Util
import { translateCode } from '../i18n/localeHelper';
2020-06-28 06:33:20 +09:00
export default {
props: {
codes: { type: Array },
2020-06-28 10:45:44 +09:00
stageLoaderCode: { type: String },
2020-06-28 06:33:20 +09:00
format: { type: String },
2020-06-28 10:45:44 +09:00
versionIdentifier: { type: String },
2020-06-28 06:33:20 +09:00
},
2021-06-11 07:48:15 +09:00
data() {
2022-01-17 03:17:07 +09:00
return {};
2021-06-11 07:48:15 +09:00
},
2020-06-28 06:33:20 +09:00
methods: {
onClick() {
2020-06-28 10:45:44 +09:00
if (!(this.codes || this.codes.length === 0) && !this.stageLoaderCode) {
2020-06-28 06:33:20 +09:00
return;
}
2020-06-28 10:45:44 +09:00
const c = [...(this.codes ?? [])];
if (this.stageLoaderCode)
c.push({
2020-06-29 00:35:18 +09:00
title: 'Stage List Loader',
author: 'Noki Doki',
date: '-',
version: '',
2020-06-28 10:45:44 +09:00
source: this.stageLoaderCode,
});
2020-06-28 06:33:20 +09:00
try {
2020-07-01 13:19:15 +09:00
window._paq.push([
'trackEvent',
'GCT Generator',
'Code Download',
JSON.stringify({
gameVersion: this.versionIdentifier,
format: this.format,
2020-07-01 14:26:48 +09:00
codes: c.map((code) => ({
title: code.title,
version: code.version,
})),
}),
]);
} catch {}
2020-07-01 14:26:48 +09:00
const fileName = gameVersions.find((v) => v.identifier === this.versionIdentifier).version;
2020-06-30 05:30:29 +09:00
2020-06-28 06:33:20 +09:00
switch (this.format) {
2020-06-29 00:35:18 +09:00
case 'gct':
2020-07-03 10:53:48 +09:00
this.generateGCT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'dolphin':
2020-07-03 10:53:48 +09:00
this.generateDolphinINI(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'gcm':
2020-07-03 10:53:48 +09:00
this.generateCheatManagerTXT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
}
2020-06-28 10:45:44 +09:00
},
2020-07-03 10:53:48 +09:00
generateGCT(codes, version) {
let code = '00D0C0DE00D0C0DE';
codes.forEach((c) => (code += c.source));
2021-01-15 08:39:49 +09:00
code += 'F000000000000000';
2020-07-03 10:53:48 +09:00
let rawData = new Uint8Array(code.length / 2);
for (let x = 0; x < rawData.length; x++) {
rawData[x] = parseInt(code.substr(x * 2, 2), 16);
}
this.downloadFile(rawData, `${version}.gct`);
},
generateDolphinINI(codes, version) {
let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]';
codes.forEach((code) => {
2020-07-10 12:21:13 +09:00
const codeTitle =
typeof code.title === 'string' ? code.title : translateCode(code, this.$lang).title;
data += `\r\n$${codeTitle} (${code.date}) [${code.author}]\r\n`;
2020-07-03 10:53:48 +09:00
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
},
generateCheatManagerTXT(codes, version) {
let data = `${version}\r\nSuper Mario Sunshine`;
codes.forEach((code) => {
2020-07-10 12:21:13 +09:00
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`;
2020-07-03 10:53:48 +09:00
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
},
downloadFile(data, filename) {
var file = new Blob([data], {
type: 'application/octet-stream',
});
if (window.navigator.msSaveOrOpenBlob) window.navigator.msSaveOrOpenBlob(file, filename);
else {
var a = document.createElement('a'),
url = window.URL.createObjectURL(file);
a.href = url;
a.download = filename;
a.click();
setTimeout(function () {
window.URL.revokeObjectURL(url);
}, 500);
}
},
2020-06-28 10:45:44 +09:00
},
2020-06-28 06:33:20 +09:00
};
</script>