From 0aa4c6b4baf0e778a446863b9352c3ebf038104f Mon Sep 17 00:00:00 2001
From: Tynarus <github@tyn.dev>
Date: Fri, 23 Apr 2021 18:13:03 -0500
Subject: [PATCH] why did I write that like that

---
 src/game-engine/world/action/hooks/task.ts         |  2 +-
 src/game-engine/world/action/index.ts              | 11 ++++++++++-
 .../world/actor/player/interface-state.ts          | 14 ++++----------
 src/game-engine/world/actor/player/player.ts       | 12 +++++++-----
 src/game-engine/world/actor/walking-queue.ts       |  9 ---------
 src/plugins/dialogue/dialogue-option.plugin.ts     |  2 +-
 6 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/src/game-engine/world/action/hooks/task.ts b/src/game-engine/world/action/hooks/task.ts
index 397f4d013..d257f3ac2 100644
--- a/src/game-engine/world/action/hooks/task.ts
+++ b/src/game-engine/world/action/hooks/task.ts
@@ -54,7 +54,7 @@ export class TaskExecutor<T> {
             const intervalMs = this.task.intervalMs !== undefined ? this.task.intervalMs :
                     (this.task.interval * World.TICK_LENGTH);
 
-            await new Promise(resolve => {
+            await new Promise<void>(resolve => {
                 this.intervalSubscription = timer(0, intervalMs).subscribe(
                     async() => {
                         if(!await this.execute()) {
diff --git a/src/game-engine/world/action/index.ts b/src/game-engine/world/action/index.ts
index c2ddd0417..cdbeb186c 100644
--- a/src/game-engine/world/action/index.ts
+++ b/src/game-engine/world/action/index.ts
@@ -44,6 +44,12 @@ export type ActionType =
     | 'equipment_change';
 
 
+export const gentleActions: ActionType[] = [
+    'button', 'widget_interaction', 'player_init', 'npc_init',
+    'move_item', 'item_swap', 'player_command', 'region_change'
+];
+
+
 /**
  * Methods in which action hooks in progress may be cancelled.
  */
@@ -150,7 +156,10 @@ export class ActionPipeline {
                 continue;
             }
 
-            await this.cancelRunningTasks();
+            // Some actions are non-cancelling
+            if(gentleActions.indexOf(hook.type) === -1) {
+                await this.cancelRunningTasks();
+            }
 
             if(runnableHooks.actionPosition) {
                 try {
diff --git a/src/game-engine/world/actor/player/interface-state.ts b/src/game-engine/world/actor/player/interface-state.ts
index 27637258d..7faed6649 100644
--- a/src/game-engine/world/actor/player/interface-state.ts
+++ b/src/game-engine/world/actor/player/interface-state.ts
@@ -66,6 +66,7 @@ export class Widget {
 
 export interface WidgetClosedEvent {
     widget: Widget;
+    widgetId?: number;
     data?: number;
 }
 
@@ -131,21 +132,14 @@ export class InterfaceState {
             filter(event => event.widget.slot === slot)).pipe(take(1)));
     }
 
-    public closeWidget(widgetId: number, data?: number): void;
-    public closeWidget(slot: GameInterfaceSlot, data?: number): void;
-    public closeWidget(i: GameInterfaceSlot | number, data?: number): void {
-        let widget: Widget | null;
-        if(typeof i === 'number') {
-            widget = this.findWidget(i);
-        } else {
-            widget = this.widgetSlots[i] || null;
-        }
+    public closeWidget(slot: GameInterfaceSlot, widgetId?: number, data?: number): void {
+        const widget: Widget | null = (slot ? this.widgetSlots[slot] : this.findWidget(widgetId)) || null;
 
         if(!widget) {
             return;
         }
 
-        this.closed.next({ widget, data });
+        this.closed.next({ widget, widgetId, data });
         this.widgetSlots[widget.slot] = null;
     }
 
diff --git a/src/game-engine/world/actor/player/player.ts b/src/game-engine/world/actor/player/player.ts
index f039a9e54..bc6e6a9e4 100644
--- a/src/game-engine/world/actor/player/player.ts
+++ b/src/game-engine/world/actor/player/player.ts
@@ -598,11 +598,13 @@ export class Player extends Actor {
 
         let showDialogue = false;
         let showInConsole = false;
-        if(options && typeof options === 'boolean') {
-            showDialogue = true;
-        } else if(options) {
-            showDialogue = options.dialogue || false;
-            showInConsole = options.console || false;
+        if(options) {
+            if(typeof options === 'boolean') {
+                showDialogue = true;
+            } else {
+                showDialogue = options.dialogue || false;
+                showInConsole = options.console || false;
+            }
         }
 
         if(!showDialogue) {
diff --git a/src/game-engine/world/actor/walking-queue.ts b/src/game-engine/world/actor/walking-queue.ts
index b2221e85e..db7e43c15 100644
--- a/src/game-engine/world/actor/walking-queue.ts
+++ b/src/game-engine/world/actor/walking-queue.ts
@@ -144,15 +144,6 @@ export class WalkingQueue {
 
         const walkPosition = this.queue.shift();
 
-        if(this.actor instanceof Player) {
-            this.actor.actionsCancelled.next('pathing-movement');
-            // if(activeWidget.disablePlayerMovement) {
-            //     this.resetDirections();
-            //     return;
-            // }
-            //this.actor.interfaceState.closeAllSlots();
-        }
-
         if(this.actor.metadata['faceActorClearedByWalking'] === undefined || this.actor.metadata['faceActorClearedByWalking']) {
             this.actor.clearFaceActor();
         }
diff --git a/src/plugins/dialogue/dialogue-option.plugin.ts b/src/plugins/dialogue/dialogue-option.plugin.ts
index 1db56b250..4fe989d1c 100644
--- a/src/plugins/dialogue/dialogue-option.plugin.ts
+++ b/src/plugins/dialogue/dialogue-option.plugin.ts
@@ -12,7 +12,7 @@ const dialogueIds = [
  */
 export const action: widgetInteractionActionHandler = (details) => {
     const { player, widgetId, childId } = details;
-    player.interfaceState.closeWidget(widgetId, childId);
+    player.interfaceState.closeWidget('chatbox', widgetId, childId);
 };
 
 export default {