forked from hunterlord/phaser-input
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.ts
50 lines (40 loc) · 2.2 KB
/
Plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Fabrique {
export module Plugins {
export interface InputFieldObjectFactory extends Phaser.GameObjectFactory {
inputField: (x:number, y:number, inputOptions?: Fabrique.InputOptions, group?:Phaser.Group) => Fabrique.InputField;
}
export interface InputFieldObjectCreator extends Phaser.GameObjectCreator {
inputField: (x:number, y:number, inputOptions?: Fabrique.InputOptions) => Fabrique.InputField;
}
export interface InputFieldGame extends Phaser.Game {
add: InputFieldObjectFactory;
make: InputFieldObjectCreator;
}
export class InputField extends Phaser.Plugin {
public static Zoomed: boolean = false;
public static KeyboardOpen: boolean = false;
public static onKeyboardOpen: Phaser.Signal = new Phaser.Signal();
public static onKeyboardClose: Phaser.Signal = new Phaser.Signal();
constructor(game:Phaser.Game, parent:PIXI.DisplayObject) {
super(game, parent);
this.addInputFieldFactory();
}
/**
* Extends the GameObjectFactory prototype with the support of adding InputField. this allows us to add InputField methods to the game just like any other object:
* game.add.InputField();
*/
private addInputFieldFactory() {
(<Fabrique.Plugins.InputFieldObjectFactory>Phaser.GameObjectFactory.prototype).inputField = function (x:number, y:number, inputOptions: Fabrique.InputOptions, group?:Phaser.Group):Fabrique.InputField {
if (group === undefined) {
group = this.world;
}
var nineSliceObject = new Fabrique.InputField(this.game, x, y, inputOptions);
return group.add(nineSliceObject);
};
(<Fabrique.Plugins.InputFieldObjectCreator>Phaser.GameObjectCreator.prototype).inputField = function (x:number, y:number, inputOptions: Fabrique.InputOptions):Fabrique.InputField {
return new Fabrique.InputField(this.game, x, y, inputOptions);
};
}
}
}
}