feat: add settings and browser input
This commit is contained in:
+49
-5
@@ -1,5 +1,6 @@
|
||||
const InputModule = {
|
||||
currentLine: "",
|
||||
localBuffer: "",
|
||||
|
||||
submitLine(text, username) {
|
||||
const line = text.trim().toLowerCase();
|
||||
@@ -16,22 +17,54 @@ const InputModule = {
|
||||
if (gameState !== "playing") return;
|
||||
|
||||
this.currentLine = line;
|
||||
this.updateDisplay(line);
|
||||
this.updateChatDisplay(line, username);
|
||||
|
||||
const enemy = this.findEnemy(line);
|
||||
|
||||
this.animateShoot(line, enemy, username);
|
||||
},
|
||||
|
||||
submitLocal(text) {
|
||||
const line = text.trim().toLowerCase();
|
||||
if (!line) return;
|
||||
if (introPlaying) return;
|
||||
|
||||
if (line === CONFIG.commands.play) {
|
||||
if (gameState === "start" || gameState === "gameover") {
|
||||
startGame();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameState !== "playing") return;
|
||||
|
||||
this.currentLine = line;
|
||||
this.updateLocalDisplay(line);
|
||||
|
||||
const enemy = this.findEnemy(line);
|
||||
const username = channelName;
|
||||
|
||||
this.animateShoot(line, enemy, username);
|
||||
},
|
||||
|
||||
animateShoot(line, enemy, username) {
|
||||
const el = document.getElementById("typed-text");
|
||||
const localEl = document.getElementById("typed-text");
|
||||
const chatEl = document.getElementById("chat-text");
|
||||
|
||||
const isLocal = username === channelName;
|
||||
const el = isLocal ? localEl : chatEl;
|
||||
|
||||
el.classList.add("shooting");
|
||||
|
||||
setTimeout(() => {
|
||||
el.classList.remove("shooting");
|
||||
this.currentLine = "";
|
||||
this.updateDisplay("");
|
||||
if (isLocal) {
|
||||
this.updateLocalDisplay("");
|
||||
this.localBuffer = "";
|
||||
} else {
|
||||
this.updateChatDisplay("", "");
|
||||
}
|
||||
|
||||
if (enemy) {
|
||||
game.launchProjectile(line, enemy, true, username);
|
||||
@@ -50,13 +83,24 @@ const InputModule = {
|
||||
return null;
|
||||
},
|
||||
|
||||
updateDisplay(text) {
|
||||
updateLocalDisplay(text) {
|
||||
const el = document.getElementById("typed-text");
|
||||
el.innerHTML = text;
|
||||
},
|
||||
|
||||
updateChatDisplay(text, username) {
|
||||
const el = document.getElementById("chat-text");
|
||||
if (text) {
|
||||
el.innerHTML = `<span style="opacity:0.6">${username}:</span> ${text}`;
|
||||
} else {
|
||||
el.innerHTML = "";
|
||||
}
|
||||
},
|
||||
|
||||
clear() {
|
||||
this.currentLine = "";
|
||||
this.updateDisplay("");
|
||||
this.localBuffer = "";
|
||||
this.updateLocalDisplay("");
|
||||
this.updateChatDisplay("", "");
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user