mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Add 2nd keybinding
This commit is contained in:
parent
d6c1cb15f6
commit
d714af7d64
@ -245,14 +245,16 @@ export class Keybinding {
|
||||
* @param {Application} app
|
||||
* @param {object} param0
|
||||
* @param {number} param0.keyCode
|
||||
* @param {number} param0.keyCode2
|
||||
* @param {boolean=} param0.builtin
|
||||
* @param {boolean=} param0.repeated
|
||||
*/
|
||||
constructor(keyMapper, app, { keyCode, builtin = false, repeated = false }) {
|
||||
constructor(keyMapper, app, { keyCode, keyCode2 = 0, builtin = false, repeated = false }) {
|
||||
assert(keyCode && Number.isInteger(keyCode), "Invalid key code: " + keyCode);
|
||||
this.keyMapper = keyMapper;
|
||||
this.app = app;
|
||||
this.keyCode = keyCode;
|
||||
this.keyCode2 = keyCode2;
|
||||
this.builtin = builtin;
|
||||
this.repeated = repeated;
|
||||
|
||||
@ -266,7 +268,7 @@ export class Keybinding {
|
||||
*/
|
||||
get pressed() {
|
||||
// Check if the key is down
|
||||
if (this.app.inputMgr.keysDown.has(this.keyCode)) {
|
||||
if (this.app.inputMgr.keysDown.has(this.keyCode) || this.app.inputMgr.keysDown.has(this.keyCode2)) {
|
||||
// Check if it is the top reciever
|
||||
const reciever = this.keyMapper.inputReceiver;
|
||||
return this.app.inputMgr.getTopReciever() === reciever;
|
||||
@ -304,6 +306,9 @@ export class Keybinding {
|
||||
getKeyCodeString() {
|
||||
return getStringForKeyCode(this.keyCode);
|
||||
}
|
||||
getKeyCodeString2() {
|
||||
return getStringForKeyCode(this.keyCode2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remvoes all signal receivers
|
||||
@ -337,6 +342,9 @@ export class KeyActionMapper {
|
||||
if (overrides[key]) {
|
||||
payload.keyCode = overrides[key];
|
||||
}
|
||||
if (overrides[key + "_2"]) {
|
||||
payload.keyCode2 = overrides[key + "_2"];
|
||||
}
|
||||
|
||||
this.keybindings[key] = new Keybinding(this, this.root.app, payload);
|
||||
}
|
||||
@ -403,7 +411,10 @@ export class KeyActionMapper {
|
||||
for (const key in this.keybindings) {
|
||||
/** @type {Keybinding} */
|
||||
const binding = this.keybindings[key];
|
||||
if (binding.keyCode === keyCode && (initial || binding.repeated)) {
|
||||
if (
|
||||
(binding.keyCode === keyCode || binding.keyCode2 == keyCode) &&
|
||||
(initial || binding.repeated)
|
||||
) {
|
||||
/** @type {Signal} */
|
||||
const signal = this.keybindings[key].signal;
|
||||
if (signal.dispatch() === STOP_PROPAGATION) {
|
||||
|
||||
@ -64,18 +64,36 @@ export class KeybindingsState extends TextualGameState {
|
||||
const editBtn = document.createElement("button");
|
||||
editBtn.classList.add("styledButton", "editKeybinding");
|
||||
|
||||
const mappingDiv2 = document.createElement("span");
|
||||
mappingDiv2.classList.add("mapping");
|
||||
mappingDiv2.classList.add("mapping_2");
|
||||
|
||||
const editBtn2 = document.createElement("button");
|
||||
editBtn2.classList.add("styledButton", "editKeybinding");
|
||||
editBtn2.classList.add("styledButton", "editKeybinding_2");
|
||||
|
||||
const resetBtn = document.createElement("button");
|
||||
resetBtn.classList.add("styledButton", "resetKeybinding");
|
||||
const resetBtn2 = document.createElement("button");
|
||||
resetBtn2.classList.add("styledButton", "resetKeybinding");
|
||||
resetBtn2.classList.add("styledButton", "resetKeybinding_2");
|
||||
|
||||
if (mapped.builtin) {
|
||||
editBtn.classList.add("disabled");
|
||||
resetBtn.classList.add("disabled");
|
||||
editBtn2.classList.add("disabled");
|
||||
resetBtn2.classList.add("disabled");
|
||||
} else {
|
||||
this.trackClicks(editBtn, () => this.editKeybinding(keybindingId));
|
||||
this.trackClicks(resetBtn, () => this.resetKeybinding(keybindingId));
|
||||
this.trackClicks(editBtn2, () => this.editKeybinding(keybindingId + "_2"));
|
||||
this.trackClicks(resetBtn2, () => this.resetKeybinding(keybindingId + "_2"));
|
||||
}
|
||||
elem.appendChild(editBtn);
|
||||
elem.appendChild(resetBtn);
|
||||
elem.appendChild(mappingDiv2);
|
||||
elem.appendChild(editBtn2);
|
||||
elem.appendChild(resetBtn2);
|
||||
}
|
||||
}
|
||||
this.updateKeybindings();
|
||||
@ -144,13 +162,24 @@ export class KeybindingsState extends TextualGameState {
|
||||
if (overrides[keybindingId]) {
|
||||
keyCode = overrides[keybindingId];
|
||||
}
|
||||
let keyCode2 = mapped.keyCode2;
|
||||
if (overrides[keybindingId + "_2"]) {
|
||||
keyCode2 = overrides[keybindingId + "_2"];
|
||||
}
|
||||
|
||||
const mappingDiv = container.querySelector(".mapping");
|
||||
mappingDiv.innerHTML = getStringForKeyCode(keyCode);
|
||||
mappingDiv.classList.toggle("changed", !!overrides[keybindingId]);
|
||||
|
||||
const mappingDiv2 = container.querySelector(".mapping_2");
|
||||
mappingDiv2.innerHTML = getStringForKeyCode(keyCode2);
|
||||
mappingDiv2.classList.toggle("changed", !!overrides[keybindingId + "_2"]);
|
||||
|
||||
const resetBtn = container.querySelector("button.resetKeybinding");
|
||||
resetBtn.classList.toggle("disabled", mapped.builtin || !overrides[keybindingId]);
|
||||
|
||||
const resetBtn2 = container.querySelector("button.resetKeybinding_2");
|
||||
resetBtn2.classList.toggle("disabled", mapped.builtin || !overrides[keybindingId + "_2"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user