Skip to content

Commit dc081f0

Browse files
committed
More classes moved to the new structure.
1 parent e7708fe commit dc081f0

9 files changed

Lines changed: 210 additions & 231 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: '8b2cc8f0-60b3-11e7-9c06-896e751f0cb1'
2+
build: '74d62650-60b8-11e7-b90e-fbadfb05faa2'
33
};
44
module.exports = CHECKSUM;

v3/src/state/GlobalStateManager.js

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,61 @@
1-
/**
2-
* @author Richard Davey <rich@photonstorm.com>
3-
* @copyright 2016 Photon Storm Ltd.
4-
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5-
*/
61

2+
var CanvasInterpolation = require('../dom/CanvasInterpolation');
3+
var CanvasPool = require('../dom/CanvasPool');
4+
var Class = require('../utils/Class');
75
var CONST = require('../const');
6+
var EventDispatcher = require('../events/EventDispatcher');
7+
var GetContext = require('../canvas/GetContext');
8+
var GetValue = require('../utils/object/GetValue');
89
var NOOP = require('../utils/NOOP');
10+
var Rectangle = require('../geom/rectangle/Rectangle');
911
var State = require('./State');
1012
var Systems = require('./Systems');
11-
var GetValue = require('../utils/object/GetValue');
12-
var EventDispatcher = require('../events/EventDispatcher');
13-
var Rectangle = require('../geom/rectangle/Rectangle');
14-
var CanvasPool = require('../dom/CanvasPool');
15-
var CanvasInterpolation = require('../dom/CanvasInterpolation');
16-
var GetContext = require('../canvas/GetContext');
1713

18-
/**
19-
* The State Manager is responsible for loading, setting up and switching game states.
20-
*
21-
* @class Phaser.GlobalStateManager
22-
* @constructor
23-
* @param {Phaser.Game} game - A reference to the currently running game.
24-
*/
25-
var GlobalStateManager = function (game, stateConfig)
26-
{
27-
this.game = game;
14+
var GlobalStateManager = new Class({
2815

29-
// Everything kept in here
30-
this.keys = {};
31-
this.states = [];
16+
initialize:
3217

33-
// Only active states are kept in here
34-
this.active = [];
18+
function GlobalStateManager (game, stateConfig)
19+
{
20+
this.game = game;
3521

36-
this._pending = [];
22+
// Everything kept in here
23+
this.keys = {};
24+
this.states = [];
3725

38-
if (stateConfig)
39-
{
40-
if (Array.isArray(stateConfig))
26+
// Only active states are kept in here
27+
this.active = [];
28+
29+
this._pending = [];
30+
31+
if (stateConfig)
4132
{
42-
for (var i = 0; i < stateConfig.length; i++)
33+
if (Array.isArray(stateConfig))
34+
{
35+
for (var i = 0; i < stateConfig.length; i++)
36+
{
37+
// The i === 0 part just starts the first State given
38+
this._pending.push({
39+
index: i,
40+
key: 'default',
41+
state: stateConfig[i],
42+
autoStart: (i === 0),
43+
data: {}
44+
});
45+
}
46+
}
47+
else
4348
{
44-
// The i === 0 part just starts the first State given
4549
this._pending.push({
46-
index: i,
50+
index: 0,
4751
key: 'default',
48-
state: stateConfig[i],
49-
autoStart: (i === 0),
52+
state: stateConfig,
53+
autoStart: true,
5054
data: {}
5155
});
5256
}
5357
}
54-
else
55-
{
56-
this._pending.push({
57-
index: 0,
58-
key: 'default',
59-
state: stateConfig,
60-
autoStart: true,
61-
data: {}
62-
});
63-
}
64-
}
65-
};
66-
67-
GlobalStateManager.prototype.constructor = GlobalStateManager;
68-
69-
GlobalStateManager.prototype = {
58+
},
7059

7160
/**
7261
* The Boot handler is called by Phaser.Game when it first starts up.
@@ -669,6 +658,6 @@ GlobalStateManager.prototype = {
669658
}
670659
}
671660

672-
};
661+
});
673662

674663
module.exports = GlobalStateManager;

v3/src/state/State.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
/**
2-
* @author Richard Davey <rich@photonstorm.com>
3-
* @copyright 2016 Photon Storm Ltd.
4-
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5-
*/
61

2+
var Class = require('../utils/Class');
73
var Systems = require('./Systems');
84

9-
/**
10-
* A Base State Class.
11-
*
12-
* @class Phaser.State
13-
* @constructor
14-
*/
15-
var State = function (config)
16-
{
17-
// The State Systems. You must never overwrite this property, or all hell will break lose.
18-
this.sys = new Systems(this, config);
19-
};
5+
var State = new Class({
206

21-
State.prototype = {
7+
initialize:
8+
9+
function State (config)
10+
{
11+
// The State Systems. You must never overwrite this property, or all hell will break lose.
12+
this.sys = new Systems(this, config);
13+
},
2214

2315
// Should be overridden by your own States
2416
update: function ()
@@ -30,8 +22,6 @@ State.prototype = {
3022
{
3123
}
3224

33-
};
34-
35-
State.prototype.constructor = State;
25+
});
3626

3727
module.exports = State;

v3/src/state/Systems.js

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
var CameraManager = require('../plugins/CameraManager');
3+
var Class = require('../utils/Class');
34
var Clock = require('../time/Clock');
4-
// var Component = require('../components');
5-
var EventDispatcher = require('../events/EventDispatcher');
6-
var DisplayList = require('../plugins/DisplayList');
75
var Data = require('../plugins/Data');
6+
var DisplayList = require('../plugins/DisplayList');
7+
var EventDispatcher = require('../events/EventDispatcher');
88
var GameObjectCreator = require('../plugins/GameObjectCreator');
99
var GameObjectFactory = require('../plugins/GameObjectFactory');
1010
var Loader = require('../plugins/Loader');
@@ -13,47 +13,48 @@ var StableSort = require('../utils/array/StableSort');
1313
var StateManager = require('../plugins/StateManager');
1414
var TweenManager = require('../tween/TweenManager');
1515

16-
var Systems = function (state, config)
17-
{
18-
this.state = state;
16+
var Systems = new Class({
1917

20-
this.config = config;
21-
this.settings = Settings.create(config);
18+
initialize:
2219

23-
this.sortChildrenFlag = false;
20+
function Systems (state, config)
21+
{
22+
this.state = state;
23+
24+
this.config = config;
25+
this.settings = Settings.create(config);
2426

25-
// Set by the GlobalStateManager
26-
this.mask = null;
27-
this.canvas;
28-
this.context;
27+
this.sortChildrenFlag = false;
2928

30-
// CORE (GLOBAL) SYSTEMS / PROPERTIES
29+
// Set by the GlobalStateManager
30+
this.mask = null;
31+
this.canvas;
32+
this.context;
3133

32-
this.game;
34+
// CORE (GLOBAL) SYSTEMS / PROPERTIES
3335

34-
this.anims;
35-
this.cache;
36-
this.input;
37-
this.registry;
38-
this.textures;
36+
this.game;
3937

40-
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
41-
this.add;
42-
this.cameras;
43-
this.events;
44-
this.load;
45-
this.make;
46-
this.stateManager;
47-
this.time;
48-
this.tweens;
38+
this.anims;
39+
this.cache;
40+
this.input;
41+
this.registry;
42+
this.textures;
4943

50-
// State properties
51-
this.children;
52-
this.color;
53-
this.data;
54-
};
44+
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
45+
this.add;
46+
this.cameras;
47+
this.events;
48+
this.load;
49+
this.make;
50+
this.stateManager;
51+
this.time;
52+
this.tweens;
5553

56-
Systems.prototype = {
54+
// State properties
55+
this.children;
56+
this.data;
57+
},
5758

5859
init: function (game)
5960
{
@@ -72,7 +73,6 @@ Systems.prototype = {
7273
// State specific properties (transform, data, children, etc)
7374

7475
this.children = new DisplayList(state);
75-
// this.color = new Component.Color(state);
7676
this.data = new Data(state);
7777

7878
// State specific managers (Factory, Tweens, Loader, Physics, etc)
@@ -256,8 +256,7 @@ Systems.prototype = {
256256
this.state.destroy.call(this.state);
257257
}
258258
}
259-
};
260259

261-
Systems.prototype.constructor = Systems;
260+
});
262261

263262
module.exports = Systems;

v3/src/structs/Map.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var Class = require('../utils/Class');
2+
13
// The keys of a Map can be arbitrary values.
24

35
/*
@@ -8,22 +10,24 @@ var map = new Map([
810
]);
911
*/
1012

11-
var Map = function (elements)
12-
{
13-
this.entries = {};
13+
var Map = new Class({
1414

15-
this.size = 0;
15+
initialize:
1616

17-
if (Array.isArray(elements))
17+
function Map (elements)
1818
{
19-
for (var i = 0; i < elements.length; i++)
19+
this.entries = {};
20+
21+
this.size = 0;
22+
23+
if (Array.isArray(elements))
2024
{
21-
this.set(elements[i][0], elements[i][1]);
25+
for (var i = 0; i < elements.length; i++)
26+
{
27+
this.set(elements[i][0], elements[i][1]);
28+
}
2229
}
23-
}
24-
};
25-
26-
Map.prototype = {
30+
},
2731

2832
set: function (key, value)
2933
{
@@ -159,8 +163,7 @@ Map.prototype = {
159163

160164
return this;
161165
}
162-
};
163166

164-
Map.prototype.constructor = Map;
167+
});
165168

166169
module.exports = Map;

v3/src/structs/Set.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
var Class = require('../utils/Class');
2+
13
// A Set is a collection of unique elements.
4+
var Set = new Class({
25

3-
var Set = function (elements)
4-
{
5-
this.entries = [];
6+
initialize:
67

7-
if (Array.isArray(elements))
8+
function Set (elements)
89
{
9-
for (var i = 0; i < elements.length; i++)
10+
this.entries = [];
11+
12+
if (Array.isArray(elements))
1013
{
11-
this.set(elements[i]);
14+
for (var i = 0; i < elements.length; i++)
15+
{
16+
this.set(elements[i]);
17+
}
1218
}
13-
}
14-
};
15-
16-
Set.prototype = {
19+
},
1720

1821
set: function (value)
1922
{
@@ -151,16 +154,10 @@ Set.prototype = {
151154
});
152155

153156
return newSet;
154-
}
155-
156-
};
157-
158-
Object.defineProperties(Set.prototype, {
157+
},
159158

160159
size: {
161160

162-
enumerable: true,
163-
164161
get: function ()
165162
{
166163
return this.entries.length;
@@ -175,6 +172,4 @@ Object.defineProperties(Set.prototype, {
175172

176173
});
177174

178-
Set.prototype.constructor = Set;
179-
180175
module.exports = Set;

0 commit comments

Comments
 (0)