-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GameStateEventSubscriber to use individual handlers
Still need to figure out injection and write tests
- Loading branch information
Showing
9 changed files
with
96 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StateChangeHandler } from './state-change-handler'; | ||
import { GameState } from '../../state/game-state'; | ||
|
||
export class GameStartedHandler implements StateChangeHandler { | ||
public handles(event: any): boolean { | ||
return event.topic === 'game.started'; | ||
} | ||
|
||
public handle(event: any, gameState: GameState): void { | ||
gameState.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StateChangeHandler } from './state-change-handler'; | ||
import { GameState } from '../../state/game-state'; | ||
|
||
export class GameStoppedHandler implements StateChangeHandler { | ||
public handles(event: any): boolean { | ||
return event.topic === 'game.stopped'; | ||
} | ||
|
||
public handle(event: any, gameState: GameState): void { | ||
gameState.stop(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/domain/state-change-handler/player-inventory-added-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StateChangeHandler } from './state-change-handler'; | ||
import { GameState } from '../../state/game-state'; | ||
|
||
export class PlayerInventoryAddedHandler implements StateChangeHandler { | ||
public handles(event: any): boolean { | ||
return event.topic === 'player.inventory.added'; | ||
} | ||
|
||
public handle(event: any, gameState: GameState): void { | ||
gameState.addInventory(event.item, event.count); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/domain/state-change-handler/player-inventory-equipped-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StateChangeHandler } from './state-change-handler'; | ||
import { GameState } from '../../state/game-state'; | ||
|
||
export class PlayerInventoryEquippedHandler implements StateChangeHandler { | ||
public handles(event: any): boolean { | ||
return event.topic === 'player.inventory.equipped'; | ||
} | ||
|
||
public handle(event: any, gameState: GameState): void { | ||
gameState.equip(event.item); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/domain/state-change-handler/player-location-moved-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { StateChangeHandler } from './state-change-handler'; | ||
import { GameState } from '../../state/game-state'; | ||
import { MapNodeRepository } from '../../map-node-repository'; | ||
|
||
export class PlayerLocationMovedHandler implements StateChangeHandler { | ||
constructor(private mapNodeRepository: MapNodeRepository) {} | ||
|
||
public handles(event: any): boolean { | ||
return event.topic === 'player.location.moved'; | ||
} | ||
|
||
public handle(event: any, gameState: GameState): void { | ||
const targetNode = this.mapNodeRepository.getMap().get(event.currentNode.id); | ||
gameState.setCurrentLocation(targetNode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { GameState } from '../../state/game-state'; | ||
|
||
export interface StateChangeHandler { | ||
handles(event: any): boolean; | ||
handle(event: any, gameState: GameState): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters