input echo
parent
37759d7b9f
commit
b257784553
|
@ -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 = [
|
||||
|
|
|
@ -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]}`);
|
||||
}
|
||||
}
|
|
@ -94,4 +94,8 @@ export default class Game {
|
|||
enableCommandInput(value) {
|
||||
this.commandHandler.enabled = value;
|
||||
}
|
||||
|
||||
setInputEcho(value) {
|
||||
this.input.setEcho(value);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue