Skip to content

Commit 51f7541

Browse files
committed
Added new State Input Manager and updated the Injection Map.
1 parent 26ef04c commit 51f7541

4 files changed

Lines changed: 104 additions & 4 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'eaf36990-6768-11e7-b615-6ddbba39daf4'
2+
build: '3d091d10-67d2-11e7-977c-8588186fe9f9'
33
};
44
module.exports = CHECKSUM;

v3/src/plugins/InputManager.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
var Class = require('../utils/Class');
2+
3+
var InputManager = new Class({
4+
5+
initialize:
6+
7+
function InputManager (state, game)
8+
{
9+
// The State that owns this plugin
10+
this.state = state;
11+
12+
// GlobalInputManager
13+
this.manager = game.input;
14+
15+
// Should use State event dispatcher?
16+
this.events = this.manager.events;
17+
18+
this.keyboard = this.manager.keyboard;
19+
this.mouse = this.manager.mouse;
20+
21+
this._list = [];
22+
this._pendingInsertion = [];
23+
this._pendingRemoval = [];
24+
},
25+
26+
begin: function ()
27+
{
28+
var toRemove = this._pendingRemoval.length;
29+
var toInsert = this._pendingInsertion.length;
30+
31+
if (toRemove === 0 && toInsert === 0)
32+
{
33+
// Quick bail
34+
return;
35+
}
36+
37+
var i;
38+
var gameObject;
39+
40+
// Delete old gameObjects
41+
for (i = 0; i < toRemove; i++)
42+
{
43+
gameObject = this._pendingRemoval[i];
44+
45+
var index = this._list.indexOf(gameObject);
46+
47+
if (index > -1)
48+
{
49+
this._list.splice(index, 1);
50+
}
51+
}
52+
53+
// Move pending to active
54+
this._list = this._list.concat(this._pendingInsertion.splice(0));
55+
56+
// Clear the lists
57+
this._pendingRemoval.length = 0;
58+
this._pendingInsertion.length = 0;
59+
},
60+
61+
update: function ()
62+
{
63+
},
64+
65+
add: function (child)
66+
{
67+
if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1)
68+
{
69+
this._pendingInsertion.push(child);
70+
}
71+
},
72+
73+
setHitArea: function (gameObject, shape, callback)
74+
{
75+
if (Array.isArray(gameObject))
76+
{
77+
for (var i = 0; i < gameObject.length; i++)
78+
{
79+
gameObject[i].hitArea = shape;
80+
gameObject[i].hitAreaCallback = callback;
81+
82+
this.add(gameObject[i]);
83+
}
84+
}
85+
else
86+
{
87+
gameObject.hitArea = shape;
88+
gameObject.hitAreaCallback = callback;
89+
90+
this.add(gameObject);
91+
}
92+
93+
return this;
94+
},
95+
96+
97+
});
98+
99+
module.exports = InputManager;

v3/src/state/InjectionMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var InjectionMap = {
88

99
anims: 'anims',
1010
cache: 'cache',
11-
input: 'input',
1211
registry: 'registry',
1312
textures: 'textures',
1413

@@ -17,6 +16,7 @@ var InjectionMap = {
1716
data: 'data',
1817
displayList: 'children',
1918
events: 'events',
19+
inputManager: 'input',
2020
load: 'load',
2121
make: 'make',
2222
pool: 'pool',

v3/src/state/Systems.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var DisplayList = require('../plugins/DisplayList');
77
var EventDispatcher = require('../events/EventDispatcher');
88
var GameObjectCreator = require('../plugins/GameObjectCreator');
99
var GameObjectFactory = require('../plugins/GameObjectFactory');
10+
var InputManager = require('../plugins/InputManager');
1011
var Loader = require('../plugins/Loader');
1112
var PoolManager = require('../plugins/PoolManager');
1213
var Settings = require('./Settings');
@@ -39,14 +40,14 @@ var Systems = new Class({
3940

4041
this.anims;
4142
this.cache;
42-
this.input;
4343
this.registry;
4444
this.textures;
4545

4646
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
4747
this.add;
4848
this.cameras;
4949
this.events;
50+
this.inputManager;
5051
this.load;
5152
this.make;
5253
this.pool;
@@ -70,12 +71,12 @@ var Systems = new Class({
7071

7172
this.anims = game.anims;
7273
this.cache = game.cache;
73-
this.input = game.input;
7474
this.registry = game.registry;
7575
this.textures = game.textures;
7676

7777
// State specific properties (transform, data, children, etc)
7878

79+
this.inputManager = new InputManager(state, game);
7980
this.updateList = new UpdateList(state);
8081
this.displayList = new DisplayList(state);
8182
this.data = new Data(state);

0 commit comments

Comments
 (0)