Skip to content
Settlers Journal
Go back

API Calls Based on Player Action

Edit page

TLDR

Frontend work. Created PlayerActionService for handling orchestrating API calls based on the action a user clicks. Implemented this using Observable<T> from RxJS, rather than Promise<T>.

private handleSkipAction(
    gameState: GameState,
    actionState: ActionState,
  ): Observable<ActionState> {
    if (!actionState.selectedPlayerActionUserId) {
      return throwError(
        () =>
          `No player user ID provided for action ${actionState.selectedPlayerAction}.`,
      );
    }

    return this.catanApiService
      .postSkipAction(actionState.selectedPlayerActionUserId!, gameState.gameId)
      .pipe(
        map((_) => {
          actionState.selectedPlayerActionUserId = null;
          actionState.selectedPlayerAction = null;
          return actionState;
        }),
      );
  }

alt text

Main work

Challenges

Learnings


Edit page
Share this post on:

Previous Post
Two-Phase Player Actions and Angular Event Bubbling Through the Component Tree
Next Post
Angular Routing, Login Page, and Wiring Up Player Action Clicks