mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Fix bug with duplicate control inputs
This commit is contained in:
parent
88ec215493
commit
7cf0c2d484
3 changed files with 36 additions and 101 deletions
BIN
BtnTest.gba
Normal file
BIN
BtnTest.gba
Normal file
Binary file not shown.
|
@ -2390,6 +2390,23 @@ class EmulatorJS {
|
|||
{id: 29, label: this.localization('SLOW MOTION')},
|
||||
{id: 28, label: this.localization('REWIND')}
|
||||
);
|
||||
let nums = [];
|
||||
for (let i=0; i<buttons.length; i++) {
|
||||
nums.push(buttons[i].id);
|
||||
}
|
||||
for (let i=0; i<30; i++) {
|
||||
if (!nums.includes(i)) {
|
||||
delete this.defaultControllers[0][i];
|
||||
delete this.defaultControllers[1][i];
|
||||
delete this.defaultControllers[2][i];
|
||||
delete this.defaultControllers[3][i];
|
||||
delete this.controls[0][i];
|
||||
delete this.controls[1][i];
|
||||
delete this.controls[2][i];
|
||||
delete this.controls[3][i];
|
||||
}
|
||||
}
|
||||
|
||||
//if (_this.statesSupported === false) {
|
||||
// delete buttons[24];
|
||||
// delete buttons[25];
|
||||
|
@ -2872,22 +2889,24 @@ class EmulatorJS {
|
|||
setupKeys() {
|
||||
for (let i=0; i<4; i++) {
|
||||
for (let j=0; j<30; j++) {
|
||||
if (this.controls[i][j] && this.keyMap) {
|
||||
this.controls[i][j].value = Number(this.keyLookup(this.controls[i][j]));
|
||||
if(this.controls[i][j].value === -1){
|
||||
console.warn("Invalid key for control "+j+" player "+i+" with value "+this.keyMap[this.keyLookup(this.defaultControllers[i][j])]);
|
||||
if (this.controls[i][j]) {
|
||||
this.controls[i][j].value = parseInt(this.keyLookup(this.controls[i][j].value));
|
||||
if (this.controls[i][j].value === -1 && this.debug) {
|
||||
delete this.controls[i][j].value;
|
||||
console.warn("Invalid key for control "+j+" player "+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
keyLookup(controllerkey) {
|
||||
for (var key in this.keyMap) {
|
||||
if (this.keyMap[key] === controllerkey.value || key === controllerkey.value) {
|
||||
return key;
|
||||
} else if (controllerkey.value === undefined) {
|
||||
return 0;
|
||||
}
|
||||
if (controllerkey === undefined) return 0;
|
||||
if (typeof controllerkey === "number") return controllerkey;
|
||||
controllerkey = controllerkey.toString().toLowerCase()
|
||||
const values = Object.values(this.keyMap);
|
||||
if (values.includes(controllerkey)) {
|
||||
const index = values.indexOf(controllerkey);
|
||||
return Object.keys(this.keyMap)[index];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
94
index.html
94
index.html
|
@ -104,88 +104,7 @@
|
|||
<input type = file id = input>
|
||||
Drag ROM file or click here
|
||||
</div>
|
||||
|
||||
<script>
|
||||
input.onchange = async () => {
|
||||
const url = new Blob([input.files[0]])
|
||||
const parts = input.files[0].name.split(".")
|
||||
|
||||
const core = await (async (ext) => {
|
||||
if (["fds", "nes", "unif", "unf"].includes(ext))
|
||||
return "nes"
|
||||
|
||||
if (["smc", "fig", "sfc", "gd3", "gd7", "dx2", "bsx", "swc"].includes(ext))
|
||||
return "snes"
|
||||
|
||||
if (["z64", "n64"].includes(ext))
|
||||
return "n64"
|
||||
|
||||
if (["pce"].includes(ext))
|
||||
return "pce"
|
||||
|
||||
if (["ngp", "ngc"].includes(ext))
|
||||
return "ngp"
|
||||
|
||||
if (["ws", "wsc"].includes(ext))
|
||||
return "ws"
|
||||
|
||||
if (["col", "cv"].includes(ext))
|
||||
return "coleco"
|
||||
|
||||
if (["d64"].includes(ext))
|
||||
return "vice_x64"
|
||||
|
||||
if (["nds", "gba", "gb", "z64", "n64"].includes(ext))
|
||||
return ext
|
||||
|
||||
return await new Promise(resolve => {
|
||||
const cores = {
|
||||
"Nintendo 64": "n64",
|
||||
"Nintendo Game Boy": "gb",
|
||||
"Nintendo Game Boy Advance": "gba",
|
||||
"Nintendo DS": "nds",
|
||||
"Nintendo Entertainment System": "nes",
|
||||
"Super Nintendo Entertainment System": "snes",
|
||||
"PlayStation": "psx",
|
||||
"Virtual Boy": "vb",
|
||||
"Sega Mega Drive": "segaMD",
|
||||
"Sega Master System": "segaMS",
|
||||
"Sega CD": "segaCD",
|
||||
"Atari Lynx": "lynx",
|
||||
"Sega 32X": "sega32x",
|
||||
"Atari Jaguar": "jaguar",
|
||||
"Sega Game Gear": "segaGG",
|
||||
"Sega Saturn": "segaSaturn",
|
||||
"Atari 7800": "atari7800",
|
||||
"Atari 2600": "atari2600",
|
||||
"NEC TurboGrafx-16/SuperGrafx/PC Engine": "pce",
|
||||
"NEC PC-FX": "pcfx",
|
||||
"SNK NeoGeo Pocket (Color)": "ngp",
|
||||
"Bandai WonderSwan (Color)": "ws",
|
||||
"ColecoVision": "coleco",
|
||||
"Commodore 64": "vice_x64"
|
||||
}
|
||||
|
||||
const button = document.createElement("button")
|
||||
const select = document.createElement("select")
|
||||
|
||||
for (const type in cores) {
|
||||
const option = document.createElement("option")
|
||||
|
||||
option.value = cores[type]
|
||||
option.textContent = type
|
||||
select.appendChild(option)
|
||||
}
|
||||
|
||||
button.onclick = () => resolve(select[select.selectedIndex].value)
|
||||
button.textContent = "Load game"
|
||||
box.innerHTML = ""
|
||||
|
||||
box.appendChild(select)
|
||||
box.appendChild(button)
|
||||
})
|
||||
})(parts.pop())
|
||||
|
||||
const div = document.createElement("div")
|
||||
const sub = document.createElement("div")
|
||||
const script = document.createElement("script")
|
||||
|
@ -193,25 +112,22 @@
|
|||
sub.id = "game"
|
||||
div.id = "display"
|
||||
|
||||
const top = document.getElementById("top");
|
||||
top.remove();
|
||||
const topp = document.getElementById("top");
|
||||
topp.remove();
|
||||
box.remove()
|
||||
div.appendChild(sub)
|
||||
document.body.appendChild(div)
|
||||
|
||||
window.EJS_player = "#game";
|
||||
window.EJS_gameName = parts.shift();
|
||||
window.EJS_biosUrl = "";
|
||||
window.EJS_gameUrl = url;
|
||||
window.EJS_core = core;
|
||||
window.EJS_gameUrl = "BtnTest.gba";
|
||||
window.EJS_core = "gba";
|
||||
window.EJS_pathtodata = "data/";
|
||||
window.EJS_startOnLoaded = true;
|
||||
window.EJS_DEBUG_XX = true;
|
||||
|
||||
script.src = "data/loader.js";
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
box.ondragover = () => box.setAttribute("drag", true);
|
||||
box.ondragleave = () => box.removeAttribute("drag");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue