mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Cheat on load
This commit is contained in:
parent
9a790b70db
commit
1af6a45d1d
2 changed files with 29 additions and 3 deletions
|
@ -180,6 +180,19 @@ class EmulatorJS {
|
||||||
|
|
||||||
this.game.classList.add("ejs_game");
|
this.game.classList.add("ejs_game");
|
||||||
|
|
||||||
|
if (Array.isArray(this.config.cheats)) {
|
||||||
|
for (let i=0; i<this.config.cheats.length; i++) {
|
||||||
|
const cheat = this.config.cheats[i];
|
||||||
|
if (Array.isArray(cheat) && cheat[0] && cheat[1]) {
|
||||||
|
this.cheats.push({
|
||||||
|
desc: cheat[0],
|
||||||
|
checked: false,
|
||||||
|
code: cheat[1]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.createStartButton();
|
this.createStartButton();
|
||||||
|
|
||||||
console.log(this)
|
console.log(this)
|
||||||
|
@ -2080,13 +2093,26 @@ class EmulatorJS {
|
||||||
if (coreSpecific) {
|
if (coreSpecific) {
|
||||||
try {
|
try {
|
||||||
coreSpecific = JSON.parse(coreSpecific);
|
coreSpecific = JSON.parse(coreSpecific);
|
||||||
if (!(coreSpecific.controlSettings instanceof Object) || !(coreSpecific.settings instanceof Object) || !(coreSpecific.cheats instanceof Object)) return;
|
if (!(coreSpecific.controlSettings instanceof Object) || !(coreSpecific.settings instanceof Object) || !Array.isArray(coreSpecific.cheats)) return;
|
||||||
this.controls = coreSpecific.controlSettings;
|
this.controls = coreSpecific.controlSettings;
|
||||||
this.checkGamepadInputs();
|
this.checkGamepadInputs();
|
||||||
for (const k in coreSpecific.settings) {
|
for (const k in coreSpecific.settings) {
|
||||||
this.changeSettingOption(k, coreSpecific.settings[k]);
|
this.changeSettingOption(k, coreSpecific.settings[k]);
|
||||||
}
|
}
|
||||||
this.cheats = coreSpecific.cheats;
|
for (let i=0; i<coreSpecific.cheats.length; i++) {
|
||||||
|
const cheat = coreSpecific.cheats[i];
|
||||||
|
let includes = false;
|
||||||
|
for (let j=0; j<this.cheats.length; j++) {
|
||||||
|
if (this.cheats[j].desc === cheat.desc && this.cheats[j].code === cheat.code) {
|
||||||
|
this.cheats[j].checked = cheat.checked;
|
||||||
|
includes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (includes) continue;
|
||||||
|
this.cheats.push(cheat);
|
||||||
|
}
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("Could not load previous settings", e);
|
console.warn("Could not load previous settings", e);
|
||||||
}
|
}
|
||||||
|
@ -2400,7 +2426,6 @@ class EmulatorJS {
|
||||||
this.elements.cheatRows = rows;
|
this.elements.cheatRows = rows;
|
||||||
}
|
}
|
||||||
updateCheatUI() {
|
updateCheatUI() {
|
||||||
if (!this.cheats) this.cheats = [];
|
|
||||||
this.elements.cheatRows.innerHTML = "";
|
this.elements.cheatRows.innerHTML = "";
|
||||||
|
|
||||||
const addToMenu = (desc, checked, code, i) => {
|
const addToMenu = (desc, checked, code, i) => {
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
config.filePaths = window.EJS_paths;
|
config.filePaths = window.EJS_paths;
|
||||||
config.loadState = window.EJS_loadStateURL;
|
config.loadState = window.EJS_loadStateURL;
|
||||||
config.cacheLimit = window.EJS_CacheLimit;
|
config.cacheLimit = window.EJS_CacheLimit;
|
||||||
|
config.cheats = window.EJS_cheats;
|
||||||
|
|
||||||
new EmulatorJS(EJS_player, config);
|
new EmulatorJS(EJS_player, config);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue