Fix async logging bugs.

This commit is contained in:
2021-05-05 21:09:51 -07:00
parent 8d854945e1
commit 09e10e94b5
3 changed files with 16 additions and 7 deletions

View File

@ -14,9 +14,9 @@ export default class Player extends Container {
this.items.push(item);
}
look(): void {
async look(): Promise<void> {
const description = super.description(this.items);
this.#user.tell(`You have ${description}`);
await this.#user.tell(`You have ${description}`);
}
}

View File

@ -10,7 +10,7 @@ export default class Scene extends Container {
this.#user = new User();
}
async look() {
async look(): Promise<void> {
const description = super.description(this.items);
await this.#user.tell(`There is ${description}`);

17
main.ts
View File

@ -30,7 +30,7 @@ async function main() {
break;
case "take":
await pickUpItem(scene, player, target);
await pickUpItem(user, scene, player, target);
break;
case "inventory":
@ -38,8 +38,7 @@ async function main() {
break;
default:
statement = "I didn't understand that.\n";
statement = "\nI didn't understand that.\n";
break;
}
}
@ -55,7 +54,17 @@ function quit(user: User): boolean {
return true;
}
async function pickUpItem(scene: Scene, player: Player, target: string) {
async function pickUpItem(
user: User,
scene: Scene,
player: Player,
target?: string
) {
if (!target) {
await user.tell("What do you want me to take?");
return;
}
const item = await scene.take(target);
if (item !== null) {