Skip to content

Commit 7ab9a27

Browse files
committed
move hotkey to config
1 parent 5fc91c7 commit 7ab9a27

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface GameConfig {
77
units: {[key:string]: Unit};
88
cells: {[key: string]: Cell};
99
maps: MapLayout[];
10+
keyConfig: {[key:string]: string}
1011
}
1112

1213
export abstract class GameStates {
@@ -18,6 +19,11 @@ export abstract class GameStates {
1819

1920
export function getConfig(): GameConfig {
2021
return {
22+
keyConfig: {
23+
KeyAttack: 'A',
24+
KeyCancel: 'C',
25+
KeyWait: 'W'
26+
},
2127
cellSize: 38,
2228
maps: [{
2329
name: 'demo1',

src/controllers/shared/input/controller.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Point3 = Phaser.Plugin.Isometric.Point3;
66
import {BaseController} from "../../base";
77
import Key = Phaser.Key;
88
import {InputEvent, InputSubject} from "../../../services/subject/input";
9+
import {GameConfig} from "../../../config";
910

1011
@injectable()
1112
export class InputController extends BaseController {
@@ -14,21 +15,23 @@ export class InputController extends BaseController {
1415

1516
constructor(
1617
private _game: Game,
17-
private _inputSubject: InputSubject
18+
private _inputSubject: InputSubject,
19+
@inject('config') private _config: GameConfig
1820
) {
1921
super();
2022
}
2123

2224
create() {
23-
// for(let i in [0,1,2,3]) {
24-
// this.subscribe(parseInt(i), _ => console.log(InputEvent[parseInt(i)], _));
25-
// }
2625
this._game.input.mouse.capture = true;
2726

2827
this._keyMap = {};
29-
this._keyMap[InputEvent.KeyAttack] = this._initKey(Phaser.Keyboard.A);
30-
this._keyMap[InputEvent.KeyWait] = this._initKey(Phaser.Keyboard.W);
31-
this._keyMap[InputEvent.KeyCancel] = this._initKey(Phaser.Keyboard.C);
28+
for(let inputEvent in InputEvent) {
29+
let keyEvent = parseInt(inputEvent);
30+
let key = this._config.keyConfig[InputEvent[keyEvent]];
31+
if(!!key) {
32+
this._keyMap[keyEvent] = this._initKey(Phaser.Keyboard[key]);
33+
}
34+
}
3235
}
3336

3437
update() {

0 commit comments

Comments
 (0)