Skip to content

Commit

Permalink
Convert start game command to event sourcing
Browse files Browse the repository at this point in the history
  • Loading branch information
dshaneg committed Mar 1, 2018
1 parent 9b3b7f2 commit d9e86d1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/commands/start-game-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Command } from './command';
import { EventPublisher } from '../domain/event-publisher';
import { Voice } from '../domain/voice';
import { GameState } from '../state/game-state';
import { ReadOnlyGameState } from '../state/game-state';
import { CommandFactory } from './command-factory';

import { ItemRepository } from '../item-repository';
Expand Down Expand Up @@ -33,7 +33,7 @@ export class StartGameCommand {
private gameDefinitionRepository: GameDefinitionRepository;
private mapNodeRepository: MapNodeRepository;

execute(gameState: GameState, publisher: EventPublisher): void {
execute(gameState: ReadOnlyGameState, publisher: EventPublisher): void {
if (gameState.isStarted) {
return;
}
Expand All @@ -57,8 +57,6 @@ export class StartGameCommand {
voice: Voice.herald
});

gameState.start();

publisher.publish({
topic: 'game.started',
message: this.gameDefinitionRepository.getGameDefinition().opening,
Expand Down
3 changes: 3 additions & 0 deletions src/domain/game-state-event-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class GameStateEventSubscriber implements EventSubscriber {
case 'player.inventory.item-equipped':
this.gameState.equip(event.item);
break;
case 'game.started':
this.gameState.start();
break;
}
}
}
5 changes: 0 additions & 5 deletions src/test/commands/start-game.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ describe('StartGameCommand', () => {
it('Should execute TeleportCommand.', () => {
mockito.verify(TeleportCommandMock.execute(gameState, publisher)).once();
});

// gameState start
it('Should execute start on gameState.', () => {
mockito.verify(GameStateMock.start()).once();
});
});

describe('Starting an already started game', () => {
Expand Down

0 comments on commit d9e86d1

Please sign in to comment.