File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff 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
1213export abstract class GameStates {
@@ -18,6 +19,11 @@ export abstract class GameStates {
1819
1920export 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' ,
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Point3 = Phaser.Plugin.Isometric.Point3;
66import { BaseController } from "../../base" ;
77import Key = Phaser . Key ;
88import { InputEvent , InputSubject } from "../../../services/subject/input" ;
9+ import { GameConfig } from "../../../config" ;
910
1011@injectable ( )
1112export 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 ( ) {
You can’t perform that action at this time.
0 commit comments