Skip to content
Snippets Groups Projects
Commit 95964be4 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe accept case sensitive input

parent c60af637
No related branches found
No related tags found
No related merge requests found
Pipeline #23750 failed
...@@ -31,14 +31,13 @@ $key-width: 8vw; // 100/12 ~ 8.3 ...@@ -31,14 +31,13 @@ $key-width: 8vw; // 100/12 ~ 8.3
grid-auto-flow: column; grid-auto-flow: column;
// grid-column-gap: $kbd-gutter; // grid-column-gap: $kbd-gutter;
&:nth-child(1) { &:nth-child(1) {
grid-auto-columns: 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 1fr; grid-template-columns: repeat(11, $key-width) 1fr;
} }
&:nth-child(2) { &:nth-child(2) {
padding-left: 0.5 * $key-width; grid-template-columns: 0.666 * $key-width repeat(11, $key-width) 1fr;
grid-auto-columns: 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw;
} }
&:nth-child(3) { &:nth-child(3) {
grid-auto-columns: 1fr 8vw 8vw 8vw 8vw 8vw 8vw 8vw 8vw 1fr; grid-template-columns: 2.333 * $key-width repeat(8, $key-width) 1fr;
} }
} }
......
...@@ -329,7 +329,13 @@ export default class FightScene extends Phaser.Scene { ...@@ -329,7 +329,13 @@ export default class FightScene extends Phaser.Scene {
createAndBindTypewriter() { createAndBindTypewriter() {
this.typewriter ??= new Typewriter(); this.typewriter ??= new Typewriter();
this.typewriter.setHidden(this.game.device.os.desktop); if (this.game.device.os.desktop) {
this.typewriter.setHidden(true);
this.typewriter.setShiftModeHoldable();
} else {
this.typewriter.setHidden(false);
this.typewriter.setShiftModeOneShot();
}
this.typewriter.onSubmit = async (inputStatus) => { this.typewriter.onSubmit = async (inputStatus) => {
if (inputStatus.began_at === null) return; if (inputStatus.began_at === null) return;
if (inputStatus.ended_at === null) return; if (inputStatus.ended_at === null) return;
......
...@@ -12,36 +12,69 @@ enum Key { ...@@ -12,36 +12,69 @@ enum Key {
Space = "{space}", Space = "{space}",
Enter = "{enter}", Enter = "{enter}",
Backspace = "{backspace}", Backspace = "{backspace}",
A = "a", ShiftLeft = "{shiftleft}",
B = "b", ShiftRight = "{shiftright}",
C = "c", a = "a",
D = "d", b = "b",
E = "e", c = "c",
F = "f", d = "d",
G = "g", e = "e",
H = "h", f = "f",
I = "i", g = "g",
J = "j", h = "h",
K = "k", i = "i",
L = "l", j = "j",
M = "m", k = "k",
N = "n", l = "l",
O = "o", m = "m",
P = "p", n = "n",
Q = "q", o = "o",
R = "r", p = "p",
S = "s", q = "q",
T = "t", r = "r",
U = "u", s = "s",
V = "v", t = "t",
W = "w", u = "u",
X = "x", v = "v",
Y = "y", w = "w",
Z = "z", x = "x",
Ä = "ä", y = "y",
Ö = "ö", z = "z",
Ü = "ü", ä = "ä",
ö = "ö",
ü = "ü",
ß = "ß", ß = "ß",
A = "A",
B = "B",
C = "C",
D = "D",
E = "E",
F = "F",
G = "G",
H = "H",
I = "I",
J = "J",
K = "K",
L = "L",
M = "M",
N = "N",
O = "O",
P = "P",
Q = "Q",
R = "R",
S = "S",
T = "T",
U = "U",
V = "V",
W = "W",
X = "X",
Y = "Y",
Z = "Z",
Ä = "Ä",
Ö = "Ö",
Ü = "Ü",
= "", // TODO: is this even typeable on a physical keyboard?
}
// NOTE: this is a hack to get onKeyReleased to work with physical keyboards, stealing from the following points // NOTE: this is a hack to get onKeyReleased to work with physical keyboards, stealing from the following points
// https://github.com/hodgef/simple-keyboard/blob/ed2c5ce81d7149b07cb3b11f4b629a63034be8ce/src/lib/services/PhysicalKeyboard.ts#L27-L64 // https://github.com/hodgef/simple-keyboard/blob/ed2c5ce81d7149b07cb3b11f4b629a63034be8ce/src/lib/services/PhysicalKeyboard.ts#L27-L64
...@@ -71,7 +104,7 @@ const hackPhysicalKeyboardKeyUp = function (event: KeyboardEvent) { ...@@ -71,7 +104,7 @@ const hackPhysicalKeyboardKeyUp = function (event: KeyboardEvent) {
buttonDOM.removeAttribute("style"); buttonDOM.removeAttribute("style");
instance.handleButtonMouseUp(buttonName, event); instance.handleButtonMouseUp(buttonName, event);
} }
}); });
}; };
...@@ -103,14 +136,21 @@ class Typewriter { ...@@ -103,14 +136,21 @@ class Typewriter {
layout: { layout: {
default: [ default: [
`q w e r t z u i o p ü ${Key.Backspace}`, `q w e r t z u i o p ü ${Key.Backspace}`,
`a s d f g h j k l ö ä`, `${Key.ShiftLeft} a s d f g h j k l ö ä ${Key.ShiftRight}`,
`${Key.Space} y x c v b n m ß ${Key.Enter}`, `${Key.Space} y x c v b n m ß ${Key.Enter}`,
], ],
shifted: [
`Q W E R T Z U I O P Ü ${Key.Backspace}`,
`${Key.ShiftLeft} A S D F G H J K L Ö Ä ${Key.ShiftRight}`,
`${Key.Space} Y X C V B N M ẞ ${Key.Enter}`,
],
}, },
display: { display: {
[Key.Backspace]: "", // "⌫⟵", [Key.Backspace]: "", // "⌫⟵",
[Key.Enter]: "", // "⏎↩↵⏎", [Key.Enter]: "", // "⏎↩↵⏎",
[Key.Space]: " ", // "␣", [Key.Space]: " ", // "␣",
[Key.ShiftLeft]: "",
[Key.ShiftRight]: "",
}, },
onChange: this.keyboardOnChangeHandler.bind(this), onChange: this.keyboardOnChangeHandler.bind(this),
} as KeyboardOptions); } as KeyboardOptions);
...@@ -176,6 +216,36 @@ class Typewriter { ...@@ -176,6 +216,36 @@ class Typewriter {
setHidden(hidden: boolean) { setHidden(hidden: boolean) {
this.keyboard.keyboardDOM.hidden = hidden; this.keyboard.keyboardDOM.hidden = hidden;
} }
setShiftModeHoldable() {
this.keyboard.setOptions({
onKeyPress: (key: string) => {
if (Key.ShiftLeft == key || Key.ShiftRight == key) {
this.keyboard.setOptions({ layoutName: "shifted" });
}
},
onKeyReleased: (key: string) => {
if (Key.ShiftLeft == key || Key.ShiftRight == key) {
this.keyboard.setOptions({ layoutName: "default" });
}
},
});
}
setShiftModeOneShot() {
this.keyboard.setOptions({
onKeyPress: undefined,
onKeyReleased: (key: string) => {
if (this.keyboard.options.layoutName == "shifted") {
this.keyboard.setOptions({ layoutName: "default" });
} else if (Key.ShiftLeft == key || Key.ShiftRight == key) {
this.keyboard.setOptions({
layoutName: "shifted",
});
}
},
});
}
} }
export default Typewriter; export default Typewriter;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment