input echo

master
Talon 2021-11-04 22:51:50 +01:00
parent 37759d7b9f
commit b257784553
4 changed files with 21 additions and 2 deletions

View File

@ -2,12 +2,14 @@ import LookCommand from "./commands/look";
import UseCommand from "./commands/use";
import TakeCommand from "./commands/take";
import DropCommand from "./commands/drop";
import EchoCommand from "./commands/echo";
const defaultCommands = [
[["look", "l"], LookCommand],
[["use", "interact"], UseCommand],
[["take", "get"], TakeCommand],
[["drop", "put"], DropCommand]
[["drop", "put"], DropCommand],
["echo", EchoCommand]
];
const directionMap = [

View File

@ -0,0 +1,8 @@
export default function EchoCommand(args, context) {
if (args[1] != "on" && args[1] != "off") {
context.print(`Usage: echo <on/off>`);
} else {
context.setInputEcho(args[1] == "on" ? true : false);
context.print(`Command echo is now ${args[1]}`);
}
}

View File

@ -94,4 +94,8 @@ export default class Game {
enableCommandInput(value) {
this.commandHandler.enabled = value;
}
setInputEcho(value) {
this.input.setEcho(value);
}
}

View File

@ -2,16 +2,21 @@ export default class Input {
constructor(commandHandler, outputHandler) {
this.handler = commandHandler;
this.output = outputHandler;
this.echoInput = true;
this.inputField = document.getElementById("input-area");
this.init();
}
setEcho(value) {
this.echoInput = value;
}
init() {
this.inputField.addEventListener("keydown", (e) => {
if (e.which == 13) {
const val = this.inputField.value;
this.inputField.value = "";
this.output.say(`> ${val}`);
if (this.echoInput) this.output.say(`> ${val}`);
this.handler.doCommand(val);
}
})