Skip to content

Commit 3282ead

Browse files
committed
Merge branch 'master' into rendering-cleanup
2 parents 5ca2805 + c625b87 commit 3282ead

61 files changed

Lines changed: 330 additions & 495 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@
4242
"uuid": "^3.1.0",
4343
"webpack": "^3.10.0",
4444
"webpack-shell-plugin": "^0.5.0"
45+
},
46+
"dependencies": {
47+
"eventemitter3": "^3.0.0"
4548
}
4649
}

src/animations/frame/Animation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var Animation = new Class({
2525
this.type = 'frame';
2626

2727
// Extract all the frame data into the frames array
28-
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []));
28+
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []), GetValue(config, 'defaultTextureKey', null));
2929

3030
// The frame rate of playback in frames per second (default 24 if duration is null)
3131
this.frameRate = GetValue(config, 'frameRate', null);
@@ -99,8 +99,8 @@ var Animation = new Class({
9999
// Global pause, effects all Game Objects using this Animation instance
100100
this.paused = false;
101101

102-
this.manager.events.on('PAUSE_ALL_ANIMATION_EVENT', this.pause.bind(this));
103-
this.manager.events.on('RESUME_ALL_ANIMATION_EVENT', this.resume.bind(this));
102+
this.manager.on('pauseall', this.pause.bind(this));
103+
this.manager.on('resumeall', this.resume.bind(this));
104104
},
105105

106106
addFrame: require('./inc/AddFrame'),

src/animations/frame/inc/GetFrames.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var GetValue = require('../../../utils/object/GetValue');
1212
*
1313
* @return {Phaser.Animations.AnimationFrame[]} [description]
1414
*/
15-
var GetFrames = function (textureManager, frames)
15+
var GetFrames = function (textureManager, frames, defaultTextureKey)
1616
{
1717
// frames: [
1818
// { key: textureKey, frame: textureFrame },
@@ -38,7 +38,8 @@ var GetFrames = function (textureManager, frames)
3838

3939
frames = [];
4040

41-
frameKeys.forEach(function (idx, value) {
41+
frameKeys.forEach(function (idx, value)
42+
{
4243
frames.push({ key: textureKey, frame: value });
4344
});
4445
}
@@ -54,7 +55,7 @@ var GetFrames = function (textureManager, frames)
5455
{
5556
var item = frames[i];
5657

57-
var key = GetValue(item, 'key', null);
58+
var key = GetValue(item, 'key', defaultTextureKey);
5859

5960
if (!key)
6061
{

src/animations/manager/AnimationManager.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var Class = require('../../utils/Class');
2-
var EventDispatcher = require('../../events/EventDispatcher');
2+
var EventEmitter = require('eventemitter3');
33
var CustomMap = require('../../structs/Map');
44

55
// Animations are managed by the global AnimationManager. This is a singleton class that is
@@ -9,6 +9,8 @@ var CustomMap = require('../../structs/Map');
99

1010
var AnimationManager = new Class({
1111

12+
Extends: EventEmitter,
13+
1214
initialize:
1315

1416
/**
@@ -23,6 +25,8 @@ var AnimationManager = new Class({
2325
*/
2426
function AnimationManager (game)
2527
{
28+
EventEmitter.call(this);
29+
2630
/**
2731
* [description]
2832
*
@@ -39,14 +43,6 @@ var AnimationManager = new Class({
3943
*/
4044
this.textureManager = null;
4145

42-
/**
43-
* [description]
44-
*
45-
* @property {Phaser.Events.EventDispatcher} events
46-
* @protected
47-
*/
48-
this.events = new EventDispatcher();
49-
5046
/**
5147
* [description]
5248
*

src/animations/manager/inc/AddAnimation.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var Event = require('../events/');
2-
31
/**
42
* [description]
53
*
@@ -16,15 +14,15 @@ var AddAnimation = function (key, animation)
1614
{
1715
if (this.anims.has(key))
1816
{
19-
console.error('Animation with key', key, 'already exists');
17+
console.warn('Animation with key', key, 'already exists');
2018
return;
2119
}
2220

2321
animation.key = key;
2422

2523
this.anims.set(key, animation);
2624

27-
this.events.dispatch(new Event.ADD_ANIMATION_EVENT(key, animation));
25+
this.emit('add', key, animation);
2826

2927
return this;
3028
};

src/animations/manager/inc/CreateFrameAnimation.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var Event = require('../events/');
21
var Animation = require('../../frame/Animation');
32

43
/**
@@ -26,7 +25,7 @@ var CreateFrameAnimation = function (config)
2625

2726
this.anims.set(key, anim);
2827

29-
this.events.dispatch(new Event.ADD_ANIMATION_EVENT(key, anim));
28+
this.emit('add', key, anim);
3029

3130
return anim;
3231
};

src/animations/manager/inc/PauseAll.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var Event = require('../events/');
2-
31
/**
42
* [description]
53
*
@@ -15,7 +13,7 @@ var PauseAll = function ()
1513
{
1614
this.paused = true;
1715

18-
this.events.dispatch(new Event.PAUSE_ALL_ANIMATION_EVENT());
16+
this.emit('pauseall');
1917
}
2018

2119
return this;

src/animations/manager/inc/RemoveAnimation.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var Event = require('../events/');
2-
31
/**
42
* [description]
53
*
@@ -17,7 +15,7 @@ var RemoveAnimation = function (key)
1715

1816
if (anim)
1917
{
20-
this.events.dispatch(new Event.REMOVE_ANIMATION_EVENT(key, anim));
18+
this.emit('remove', key, anim);
2119

2220
this.anims.delete(key);
2321
}

src/animations/manager/inc/ResumeAll.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var Event = require('../events/');
2-
31
/**
42
* [description]
53
*
@@ -15,7 +13,7 @@ var ResumeAll = function ()
1513
{
1614
this.paused = false;
1715

18-
this.events.dispatch(new Event.RESUME_ALL_ANIMATION_EVENT());
16+
this.emit('resumeall');
1917
}
2018

2119
return this;

src/boot/Game.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var NOOP = require('../utils/NOOP');
66

77
var AddToDOM = require('../dom/AddToDOM');
88
var DOMContentLoaded = require('../dom/DOMContentLoaded');
9-
var EventDispatcher = require('../events/EventDispatcher');
9+
var EventEmitter = require('eventemitter3');
1010
var VisibilityHandler = require('./VisibilityHandler');
1111

1212
var AnimationManager = require('../animations/manager/AnimationManager');
@@ -82,7 +82,7 @@ var Game = new Class({
8282
*
8383
* @property {Phaser.Events.EventDispatcher} events
8484
*/
85-
this.events = new EventDispatcher();
85+
this.events = new EventEmitter();
8686

8787
/**
8888
* [description]
@@ -195,10 +195,10 @@ var Game = new Class({
195195

196196
VisibilityHandler(this.events);
197197

198-
this.events.on('HIDDEN', this.onHidden.bind(this));
199-
this.events.on('VISIBLE', this.onVisible.bind(this));
200-
this.events.on('ON_BLUR', this.onBlur.bind(this));
201-
this.events.on('ON_FOCUS', this.onFocus.bind(this));
198+
this.events.on('hidden', this.onHidden.bind(this));
199+
this.events.on('visible', this.onVisible.bind(this));
200+
this.events.on('blur', this.onBlur.bind(this));
201+
this.events.on('focus', this.onFocus.bind(this));
202202
},
203203

204204
/**

0 commit comments

Comments
 (0)