Skip to content

Commit

Permalink
feat(actions): better, more robust action handling. closes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 20, 2023
1 parent 2d028e1 commit 2b9b497
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
19 changes: 6 additions & 13 deletions client/src/app/services/actions.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { environment } from '@environment';
import { INotification, INotificationAction } from '@interfaces';
import { Store } from '@ngxs/store';
import { GameplayService } from '@services/gameplay.service';
import { NotificationsService } from '@services/notifications.service';
import { ClearNotificationActions } from '@stores/notifications/notifications.actions';

Expand All @@ -13,8 +14,8 @@ export class ActionsService {
constructor(
private store: Store,
private router: Router,
private http: HttpClient,
private notificationService: NotificationsService,
private gameplayService: GameplayService,
) {}

doAction(action: INotificationAction, notification?: INotification) {
Expand All @@ -27,18 +28,10 @@ export class ActionsService {
this.router.navigate([action.actionData.url]);
}

if (action.action === 'wave') {
this.gameplayService.wave(action.actionData.player.userId).subscribe();
}

if (action.action === 'waveback') {
this.gameplayService
.wave(action.actionData.player.userId, true)
if (action.url) {
this.http
.post(`${environment.apiUrl}/${action.url}`, action.urlData || {})
.subscribe();
}

if (action.action === 'collectible' || action.action === 'item') {
this.gameplayService.takeitem().subscribe();
}
}
}
4 changes: 0 additions & 4 deletions client/src/app/services/gameplay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ export class GameplayService {
isWaveBack,
});
}

takeitem() {
return this.http.post(`${environment.apiUrl}/gameplay/takeitem`, {});
}
}
5 changes: 5 additions & 0 deletions server/src/modules/player/gameplay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ export class GameplayService {
actionData: {
player,
},
url: 'gameplay/wave',
urlData: {
targetUserId: userId,
isWaveBack: true,
},
},
],
},
Expand Down
6 changes: 6 additions & 0 deletions server/src/modules/player/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ export class PlayerService {
actionData: {
player: randomPlayer,
},
url: 'gameplay/wave',
urlData: {},
});
}

Expand Down Expand Up @@ -258,6 +260,8 @@ export class PlayerService {
actionData: {
item: randomCollectibleForLocation,
},
url: 'gameplay/takeitem',
urlData: {},
});
}

Expand All @@ -280,6 +284,8 @@ export class PlayerService {
actionData: {
item: randomItemForLocation,
},
url: 'gameplay/takeitem',
urlData: {},
});
}
}
2 changes: 2 additions & 0 deletions shared/interfaces/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export interface INotificationAction {
text: string;
action: string;
actionData: any;
url?: string;
urlData?: any;
}

export interface INotification {
Expand Down

0 comments on commit 2b9b497

Please sign in to comment.