Skip to content

Commit 929d6fc

Browse files
committed
Enforced GameObjects to specify their type (a string based const)
1 parent 612db78 commit 929d6fc

11 files changed

Lines changed: 47 additions & 20 deletions

File tree

v3/src/gameobjects/GameObject.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ var GameObject = new Class({
1616

1717
initialize:
1818

19-
function GameObject (state)
19+
function GameObject (state, type)
2020
{
2121
this.state = state;
2222

2323
this.id = 0;
24+
this.type = type;
2425
this.name = '';
2526

2627
this.parent;

v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var DynamicBitmapText = new Class({
2828
if (size === undefined) { size = 32; }
2929
if (align === undefined) { align = 'left'; }
3030

31-
GameObject.call(this, state);
31+
GameObject.call(this, state, 'DynamicBitmapText');
3232

3333
this.fontData = this.state.sys.cache.bitmapFont.get(font);
3434

v3/src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var BitmapText = new Class({
2828
if (size === undefined) { size = 32; }
2929
if (align === undefined) { align = 'left'; }
3030

31-
GameObject.call(this, state);
31+
GameObject.call(this, state, 'BitmapText');
3232

3333
this.fontData = this.state.sys.cache.bitmapFont.get(font);
3434

v3/src/gameobjects/blitter/Blitter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Blitter = new Class({
4343

4444
function Blitter (state, x, y, texture, frame)
4545
{
46-
GameObject.call(this, state);
46+
GameObject.call(this, state, 'Blitter');
4747

4848
this.setTexture(texture, frame);
4949
this.setPosition(x, y);

v3/src/gameobjects/effectlayer/EffectLayer.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,39 @@ var EffectLayer = new Class({
2424

2525
initialize:
2626

27-
function EffectLayer(state, x, y, width, height, effectName, fragmentShader)
27+
function EffectLayer (state, x, y, width, height, effectName, fragmentShader)
2828
{
29-
GameObject.call(this, state);
29+
GameObject.call(this, state, 'EffectLayer');
3030

3131
var resourceManager = state.game.renderer.resourceManager;
3232
var gl;
3333

34-
this.dstRenderTarget = null
34+
this.dstRenderTarget = null;
3535
this.dstRenderTexture = null;
3636
this.dstShader = null;
3737
this.uniforms = {};
3838

3939
if (resourceManager !== undefined)
4040
{
4141
gl = state.game.renderer.gl;
42+
4243
this.dstShader = resourceManager.createShader(effectName, {
4344
vert: TexturedAndNormalizedTintedShader.vert,
4445
frag: fragmentShader
4546
});
47+
4648
this.dstRenderTexture = resourceManager.createTexture(
47-
0,
48-
gl.LINEAR, gl.LINEAR,
49-
gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE,
50-
gl.RGBA,
49+
0,
50+
gl.LINEAR, gl.LINEAR,
51+
gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE,
52+
gl.RGBA,
5153
null, width, height
5254
);
53-
this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.dstRenderTexture, null);
55+
56+
this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.dstRenderTexture, null);
5457
//state.game.renderer.currentTexture = null; // force rebinding of prev texture
5558
}
59+
5660
this.flipY = true;
5761
this.setPosition(x, y);
5862
this.setSize(width, height);
@@ -72,7 +76,7 @@ var EffectLayer = new Class({
7276
if (gameObject.renderTarget !== undefined)
7377
{
7478
gameObject.renderTarget = null;
75-
}
79+
}
7680
},
7781

7882
getUniformLocation: function (uniformName)
@@ -99,7 +103,9 @@ var EffectLayer = new Class({
99103
var dstShader = this.dstShader;
100104

101105
if (dstShader === null)
106+
{
102107
return;
108+
}
103109

104110
dstShader.setConstantFloat1(this.getUniformLocation(uniformName), x);
105111
},
@@ -109,7 +115,9 @@ var EffectLayer = new Class({
109115
var dstShader = this.dstShader;
110116

111117
if (dstShader === null)
118+
{
112119
return;
120+
}
113121

114122
dstShader.setConstantFloat2(this.getUniformLocation(uniformName), x, y);
115123
},
@@ -119,7 +127,9 @@ var EffectLayer = new Class({
119127
var dstShader = this.dstShader;
120128

121129
if (dstShader === null)
130+
{
122131
return;
132+
}
123133

124134
dstShader.setConstantFloat3(this.getUniformLocation(uniformName), x, y, z);
125135
},
@@ -129,7 +139,9 @@ var EffectLayer = new Class({
129139
var dstShader = this.dstShader;
130140

131141
if (dstShader === null)
142+
{
132143
return;
144+
}
133145

134146
dstShader.setConstantFloat4(this.getUniformLocation(uniformName), x, y, z, w);
135147
},
@@ -139,7 +151,9 @@ var EffectLayer = new Class({
139151
var dstShader = this.dstShader;
140152

141153
if (dstShader === null)
154+
{
142155
return;
156+
}
143157

144158
dstShader.setConstantInt1(this.getUniformLocation(uniformName), x);
145159
},
@@ -149,7 +163,9 @@ var EffectLayer = new Class({
149163
var dstShader = this.dstShader;
150164

151165
if (dstShader === null)
166+
{
152167
return;
168+
}
153169

154170
dstShader.setConstantInt2(this.getUniformLocation(uniformName), x, y);
155171
},
@@ -159,7 +175,9 @@ var EffectLayer = new Class({
159175
var dstShader = this.dstShader;
160176

161177
if (dstShader === null)
178+
{
162179
return;
180+
}
163181

164182
dstShader.setConstantInt3(this.getUniformLocation(uniformName), x, y, z);
165183
},
@@ -169,7 +187,9 @@ var EffectLayer = new Class({
169187
var dstShader = this.dstShader;
170188

171189
if (dstShader === null)
190+
{
172191
return;
192+
}
173193

174194
dstShader.setConstantInt4(this.getUniformLocation(uniformName), x, y, z, w);
175195
},
@@ -179,7 +199,9 @@ var EffectLayer = new Class({
179199
var dstShader = this.dstShader;
180200

181201
if (dstShader === null)
202+
{
182203
return;
204+
}
183205

184206
dstShader.setConstantMatrix2x2(this.getUniformLocation(uniformName), matrix);
185207
},
@@ -189,7 +211,9 @@ var EffectLayer = new Class({
189211
var dstShader = this.dstShader;
190212

191213
if (dstShader === null)
214+
{
192215
return;
216+
}
193217

194218
dstShader.setConstantMatrix3x3(this.getUniformLocation(uniformName), matrix);
195219
},
@@ -199,7 +223,9 @@ var EffectLayer = new Class({
199223
var dstShader = this.dstShader;
200224

201225
if (dstShader === null)
226+
{
202227
return;
228+
}
203229

204230
dstShader.setConstantMatrix4x4(this.getUniformLocation(uniformName), matrix);
205231
}

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Graphics = new Class({
2626
var x = GetObjectValue(options, 'x', 0);
2727
var y = GetObjectValue(options, 'y', 0);
2828

29-
GameObject.call(this, state);
29+
GameObject.call(this, state, 'Graphics');
3030

3131
this.setPosition(x, y);
3232

v3/src/gameobjects/image/Image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var Image = new Class({
2727

2828
function Image (state, x, y, texture, frame)
2929
{
30-
GameObject.call(this, state);
30+
GameObject.call(this, state, 'Image');
3131

3232
this.setTexture(texture, frame);
3333
this.setPosition(x, y);

v3/src/gameobjects/renderpass/RenderPass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var RenderPass = new Class({
2323

2424
initialize:
2525

26-
function RenderPass(state, x, y, width, height, shaderName, fragmentShader)
26+
function RenderPass (state, x, y, width, height, shaderName, fragmentShader)
2727
{
28-
GameObject.call(this, state);
28+
GameObject.call(this, state, 'RenderPass');
2929

3030
var resourceManager = state.game.renderer.resourceManager;
3131
var gl;

v3/src/gameobjects/sprite/Sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var Sprite = new Class({
2727

2828
function Sprite (state, x, y, texture, frame)
2929
{
30-
GameObject.call(this, state);
30+
GameObject.call(this, state, 'Sprite');
3131

3232
this.anims = new Components.Animation(this);
3333

v3/src/gameobjects/text/static/Text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var Text = new Class({
3232
if (y === undefined) { y = 0; }
3333
if (text === undefined) { text = ''; }
3434

35-
GameObject.call(this, state);
35+
GameObject.call(this, state, 'Text');
3636

3737
this.setPosition(x, y);
3838
this.setOrigin(0, 0);

0 commit comments

Comments
 (0)