minor cleanup

This commit is contained in:
Matteias Collet 2020-07-03 03:53:48 +02:00
parent 27a2774959
commit 137b280c6c
4 changed files with 60 additions and 70 deletions

View file

@ -28,7 +28,5 @@
"dependencies": {
"vuedraggable": "^2.23.2"
},
"pre-commit": [
"codes:clean"
]
"pre-commit": []
}

View file

@ -5,8 +5,6 @@
</template>
<script>
import CodeFormatter from './scripts/codeFormatter';
export default {
props: {
disabled: { type: Boolean },

View file

@ -9,7 +9,6 @@
<script>
// Components
import ButtonComponent from './ButtonComponent';
import CodeFormatter from './scripts/codeFormatter';
// Data
import gameVersions from '../data/gameVersions.json';
@ -58,16 +57,72 @@ export default {
switch (this.format) {
case 'gct':
CodeFormatter.generateGCT(c, fileName);
this.generateGCT(c, fileName);
break;
case 'dolphin':
CodeFormatter.generateDolphinINI(c, fileName);
this.generateDolphinINI(c, fileName);
break;
case 'gcm':
CodeFormatter.generateCheatManagerTXT(c, fileName);
this.generateCheatManagerTXT(c, fileName);
break;
}
},
generateGCT(codes, version) {
let code = '00D0C0DE00D0C0DE';
codes.forEach((c) => (code += c.source));
code += 'FF00000000000000';
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) => {
data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`;
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) => {
data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`;
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);
}
},
},
};
</script>

View file

@ -1,61 +0,0 @@
export default class CodeFormatter {
static generateGCT(codes, version) {
let code = '00D0C0DE00D0C0DE';
codes.forEach((c) => (code += c.source));
code += 'FF00000000000000';
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`);
}
static generateDolphinINI(codes, version) {
let data = 'Paste the following on top of your games .ini file:\r\n[Gecko]';
codes.forEach((code) => {
data += `\r\n$${code.title} (${code.date}) [${code.author}]\r\n`;
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
}
static generateCheatManagerTXT(codes, version) {
let data = `${version}\r\nSuper Mario Sunshine`;
codes.forEach((code) => {
data += `\r\n\r\n${code.title} (${code.date}) [${code.author}]\r\n`;
data += code.source
.match(/.{8}/g)
.join(' ')
.replace(/(.{17})./g, '$1\r\n');
});
this.downloadFile(data, `${version}.txt`);
}
static 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);
}
}
}