Skip to content

Commit ce4b03c

Browse files
committed
code cleanup
1 parent 6ca2aeb commit ce4b03c

File tree

12 files changed

+36
-28
lines changed

12 files changed

+36
-28
lines changed

src/controllers/game/ai/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {InputStateManager} from "../../../services/state/input/service";
99
export class AIController extends BaseController {
1010
constructor(
1111
private _game: Game,
12-
@inject('gameState') private _gameState: GameStateManager,
13-
@inject('inputState') private _inputState: InputStateManager,
12+
private _gameState: GameStateManager,
13+
private _inputState: InputStateManager,
1414
@inject('config') private _config: GameConfig
1515
) {
1616
super();

src/controllers/game/contextmenu/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class ContextMenuController extends BaseController {
1414

1515
constructor(
1616
private _game: Game,
17-
@inject('gameState') private _gameState: GameStateManager,
18-
@inject('inputState') private _inputState: InputStateManager,
17+
private _gameState: GameStateManager,
18+
private _inputState: InputStateManager,
1919
@inject('config') private _config: GameConfig
2020
) {
2121
super();

src/controllers/game/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {GameEvent, GameStateManager} from "../../services/state/game/service";
1111
export class GameController extends BaseController {
1212
constructor(
1313
private _game: Game,
14-
@inject('gameState') private _gameState: GameStateManager,
14+
private _gameState: GameStateManager,
1515
@inject('config') private _config: GameConfig,
1616
@inject('IMapBuilder') private _mapBuilder: IMapBuilder
1717
) {

src/controllers/game/grid/controller.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class GridController extends BaseController {
2020

2121
constructor(
2222
private _game: Game,
23-
@inject('gameState') private _gameState: GameStateManager,
24-
@inject('inputState') private _inputState: InputStateManager,
23+
private _gameState: GameStateManager,
24+
private _inputState: InputStateManager,
2525
@inject('IMapBuilder') private _mapBuilder: IMapBuilder
2626
) {
2727
super();
@@ -36,7 +36,7 @@ export class GridController extends BaseController {
3636
this._gameState.subscribe(GameEvent.UnitMoveCompleted, (): void => {this._canActivateCells = true;});
3737

3838
this.cells = this._mapBuilder.buildGrid();
39-
this._gameState.set('cells', this.cells);
39+
this._gameState.cells = this.cells;
4040

4141
this._game.iso.simpleSort(this._game['isoGridGroup']);
4242
}
@@ -211,9 +211,7 @@ export class GridController extends BaseController {
211211
}
212212

213213
private _getUnitAt(cell: GridCell): BaseUnit {
214-
let units: BaseUnit[] = this._gameState.get('units');
215-
216-
return units.find(unit => unit.x === cell.x && unit.y === cell.y)
214+
return this._gameState.units.find(unit => unit.x === cell.x && unit.y === cell.y)
217215
}
218216

219217
private _getCellAt(unit: BaseUnit): GridCell {

src/controllers/game/unit/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class UnitController extends BaseController {
1616

1717
constructor(
1818
private _game: Game,
19-
@inject('gameState') private _gameState: GameStateManager,
19+
private _gameState: GameStateManager,
2020
@inject('config') private _config: GameConfig,
2121
@inject('IMapBuilder') private _mapBuilder: IMapBuilder
2222
) {
@@ -32,7 +32,7 @@ export class UnitController extends BaseController {
3232
this._gameState.subscribe(GameEvent.UnitAttack, this._onUnitAttack);
3333

3434
this.units = this._mapBuilder.buildUnits();
35-
this._gameState.set('units', this.units);
35+
this._gameState.units = this.units;
3636
}
3737

3838
update() {

src/controllers/input/controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export class InputController extends BaseController {
1313
private _attackKey: Key; //TODO: move all shortcut keys to a map
1414
private _isAttackKeyDown: boolean;
1515

16-
constructor(private _game: Game,
17-
@inject('inputState') private _inputState: InputStateManager){
16+
constructor(
17+
private _game: Game,
18+
private _inputState: InputStateManager
19+
) {
1820
super();
1921
}
2022

src/inversify.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ container.bind<ContextMenuController>(ContextMenuController).toSelf().inSingleto
2929
container.bind<GridController>(GridController).toSelf().inSingletonScope();
3030
container.bind<UnitController>(UnitController).toSelf().inSingletonScope();
3131

32-
container.bind<IStateManager>('gameState').to(GameStateManager).inSingletonScope();
33-
container.bind<IStateManager>('inputState').to(InputStateManager).inSingletonScope();
32+
container.bind<GameStateManager>(GameStateManager).toSelf().inSingletonScope();
33+
container.bind<InputStateManager>(InputStateManager).toSelf().inSingletonScope();
3434

3535
container.bind<IMapBuilder>('IMapBuilder').to(MapBuilder).inSingletonScope();
3636

src/services/army_command_strategy/factory/service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import {IArmyCommandStrategyFactory} from "./interface";
33
import {ArmyCommandStrategy} from "../service";
44
import Game = Phaser.Game;
55
import {IArmyCommandStrategy} from "../interface";
6+
import {GameStateManager} from "../../state/game/service";
67

78
export class ArmyCommandStrategyFactory implements IArmyCommandStrategyFactory {
8-
constructor(private _game: Game) {
9+
constructor(
10+
private _gameState: GameStateManager
11+
) {
912
}
1013

1114
getForPlayer(playerNum: number): IArmyCommandStrategy {
1215
//TODO: configure difficulty, strategy, etc...
13-
return new ArmyCommandStrategy(playerNum, this._game);
16+
return new ArmyCommandStrategy(playerNum, this._gameState);
1417
}
1518
}

src/services/army_command_strategy/service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import * as Phaser from 'phaser';
22
import {IArmyCommandStrategy} from "./interface";
33
import {GameController} from "../../controllers/game/controller";
44
import Game = Phaser.Game;
5+
import {GameStateManager} from "../state/game/service";
56

67
export class ArmyCommandStrategy implements IArmyCommandStrategy {
7-
constructor(private _playerNum: number, private _game: Game) {
8+
constructor(
9+
private _playerNum: number,
10+
private _gameState: GameStateManager
11+
) {
12+
813
}
914

1015
executeTurn() {

src/services/state/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import Signal = Phaser.Signal;
44
import {injectable} from "inversify";
55

66
@injectable()
7-
export abstract class BaseStateManager implements IStateManager {
7+
export abstract class BaseStateManager {
88
private _cache: {[key:string]: any} = {};
99
protected signals: {[key: number]: Signal} = {};
1010

11+
//TODO: localStorage
1112
set(key: string, obj: any):void {
1213
this._cache[key] = obj;
1314
}

0 commit comments

Comments
 (0)