Skip to content

Commit

Permalink
why did I write that like that
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynarus committed Apr 23, 2021
1 parent dd6e290 commit 0aa4c6b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/game-engine/world/action/hooks/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
11 changes: 10 additions & 1 deletion src/game-engine/world/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 4 additions & 10 deletions src/game-engine/world/actor/player/interface-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Widget {

export interface WidgetClosedEvent {
widget: Widget;
widgetId?: number;
data?: number;
}

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 7 additions & 5 deletions src/game-engine/world/actor/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions src/game-engine/world/actor/walking-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dialogue/dialogue-option.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0aa4c6b

Please sign in to comment.