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

74 lines
1.8 KiB
Vue
Raw Normal View History

2020-06-28 06:33:20 +09:00
<template>
2020-06-28 10:45:44 +09:00
<ButtonComponent
label="Download"
:onClick="onClick"
:disabled="(!codes || codes.length === 0) && !stageLoaderCode"
/>
2020-06-28 06:33:20 +09:00
</template>
<script>
2020-06-30 05:30:29 +09:00
// Components
2020-06-29 00:35:18 +09:00
import ButtonComponent from './ButtonComponent';
import CodeFormatter from './scripts/codeFormatter';
2020-06-28 06:33:20 +09:00
2020-06-30 05:30:29 +09:00
// Data
import gameVersions from '../data/gameVersions.json';
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
},
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-06-28 06:33:20 +09:00
console.log(`Preparing download for ${this.format}`);
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-06-30 05:30:29 +09:00
CodeFormatter.generateGCT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'dolphin':
2020-06-30 05:30:29 +09:00
CodeFormatter.generateDolphinINI(c, fileName);
2020-06-28 06:33:20 +09:00
break;
2020-06-29 00:35:18 +09:00
case 'gcm':
2020-06-30 05:30:29 +09:00
CodeFormatter.generateCheatManagerTXT(c, fileName);
2020-06-28 06:33:20 +09:00
break;
}
2020-06-28 10:45:44 +09:00
},
},
2020-06-28 06:33:20 +09:00
};
</script>