Add command enable/disable
parent
a745ff299e
commit
a968f89bb3
|
@ -5,21 +5,42 @@ const defaultCommands = [
|
|||
[["use", "interact"], UseCommand]
|
||||
];
|
||||
|
||||
const directionMap = [
|
||||
["n", "north"],
|
||||
["ne", "northeast"],
|
||||
["e", "east"],
|
||||
["se", "southeast"],
|
||||
["s", "south"],
|
||||
["sw", "southwest"],
|
||||
["w", "west"],
|
||||
["nw", "northwest"],
|
||||
["u", "up"],
|
||||
["d", "down"]
|
||||
];
|
||||
|
||||
export default class Commands {
|
||||
constructor(context, commands) {
|
||||
this.context = context;
|
||||
this.commands = commands || new Map();
|
||||
this.enabled = true;
|
||||
this.addDefaultCommands();
|
||||
}
|
||||
|
||||
doCommand(str) {
|
||||
if (!this.enabled) {
|
||||
this.context.print(`You can't seem to do anything at the moment.`);
|
||||
return;
|
||||
}
|
||||
const room = this.context.getRoom(this.context.player.currentRoom);
|
||||
const split = str.split(" ");
|
||||
if (this.commands.get(split[0])) {
|
||||
this.commands.get(split[0])(split, this.context);
|
||||
}
|
||||
if (room.getExit(split[0])) {
|
||||
this.context.move(room.getExit(split[0]));
|
||||
|
||||
const direction = this.matchDirection(split[0]);
|
||||
|
||||
if (room.getExit(direction)) {
|
||||
this.context.move(room.getExit(direction));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,4 +61,10 @@ export default class Commands {
|
|||
addDefaultCommands() {
|
||||
this.addCommands(defaultCommands);
|
||||
}
|
||||
|
||||
matchDirection(str) {
|
||||
for (let dir of directionMap) {
|
||||
if (dir[0] == str) return dir[1];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
export default function LookCommand(args, context) {
|
||||
if (args.length == 0) {
|
||||
if (args.length == 1) {
|
||||
context.examineRoom();
|
||||
} else {
|
||||
const room = context.getRoom(context.player.currentRoom);
|
||||
|
|
|
@ -89,4 +89,8 @@ export default class Game {
|
|||
this.visitedRooms.set(roomID, true);
|
||||
}
|
||||
}
|
||||
|
||||
enableCommandInput(value) {
|
||||
this.commandHandler.enabled = value;
|
||||
}
|
||||
}
|
|
@ -8,11 +8,13 @@ export default new RoomBuilder()
|
|||
.withExit("north", "tunnel_1")
|
||||
.withEnterCallback(async function(context) {
|
||||
const { output, wait } = context;
|
||||
context.enableCommandInput(false);
|
||||
output.say("You slowly wake up");
|
||||
await wait(5000);
|
||||
output.say("It's strange. You never used to be able to be conscious about the fact that you were waking up.");
|
||||
await wait(5000);
|
||||
output.say("Yet here we are.");
|
||||
context.enableCommandInput(true);
|
||||
})
|
||||
.withItem("stone")
|
||||
.create();
|
Loading…
Reference in New Issue