Skip to content

Commit 81c6124

Browse files
committed
Added more toJSON GameObject functions.
1 parent 5eee822 commit 81c6124

6 files changed

Lines changed: 65 additions & 12 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: 'd62d2ed0-1f8b-11e7-b52d-db08b948d03e'
2+
build: 'dd446940-1fd6-11e7-b0f6-9b5f5f41e111'
33
};
44
module.exports = CHECKSUM;

v3/src/components/ToJSON.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ var ToJSON = function (gameObject)
66
var out = {
77
name: gameObject.name,
88
type: gameObject.type,
9-
position: {
10-
x: gameObject.x,
11-
y: gameObject.y,
12-
z: gameObject.z
13-
},
9+
x: gameObject.x,
10+
y: gameObject.y,
11+
z: gameObject.z,
1412
scale: {
1513
x: gameObject.scaleX,
1614
y: gameObject.scaleY
@@ -19,23 +17,22 @@ var ToJSON = function (gameObject)
1917
x: gameObject.originX,
2018
y: gameObject.originY
2119
},
22-
flip: {
23-
x: gameObject.flipX,
24-
y: gameObject.flipY
25-
},
20+
flipX: gameObject.flipX,
21+
flipY: gameObject.flipY,
2622
rotation: gameObject.rotation,
2723
alpha: gameObject.alpha,
2824
visible: gameObject.visible,
2925
scaleMode: gameObject.scaleMode,
3026
blendMode: gameObject.blendMode,
3127
textureKey: '',
32-
frameKey: ''
28+
frameKey: '',
29+
data: {}
3330
};
3431

3532
if (gameObject.texture)
3633
{
3734
out.textureKey = gameObject.texture.key;
38-
out.frameKey = gameObject.frame.key;
35+
out.frameKey = gameObject.frame.name;
3936
}
4037

4138
return out;

v3/src/gameobjects/GameObject.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Class = require('../utils/Class');
8+
var Components = require('../components');
89

910
/**
1011
* This is the base Game Object class that you can use when creating your own extended Game Objects.
@@ -37,6 +38,12 @@ var GameObject = new Class({
3738
{
3839
},
3940

41+
// Can be overridden by custom Game Objects, but provides default export functionality
42+
toJSON: function ()
43+
{
44+
return Components.ToJSON(this);
45+
},
46+
4047
destroy: function ()
4148
{
4249
this.parent.remove(this);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var BitmapText = new Class({
3030

3131
GameObject.call(this, state, 'BitmapText');
3232

33+
this.font = font;
3334
this.fontData = this.state.sys.cache.bitmapFont.get(font);
3435

3536
this.text = text;
@@ -76,6 +77,23 @@ var BitmapText = new Class({
7677
// global = the BitmapText, taking into account scale and world position
7778

7879
return GetBitmapTextSize(this);
80+
},
81+
82+
toJSON: function ()
83+
{
84+
var out = Components.ToJSON(this);
85+
86+
// Extra data is added here
87+
88+
var data = {
89+
font: this.font,
90+
text: this.text,
91+
fontSize: this.fontSize
92+
};
93+
94+
out.data = data;
95+
96+
return out;
7997
}
8098

8199
});

v3/src/gameobjects/sprite/Sprite.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ var Sprite = new Class({
4545
play: function (key, startFrame)
4646
{
4747
return this.anims.play(key, startFrame);
48+
},
49+
50+
toJSON: function ()
51+
{
52+
var data = Components.ToJSON(this);
53+
54+
// Extra Sprite data is added here
55+
56+
return data;
4857
}
4958

5059
});

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,28 @@ var Text = new Class({
265265
this.dirty = true;
266266

267267
return this;
268+
},
269+
270+
toJSON: function ()
271+
{
272+
var out = Components.ToJSON(this);
273+
274+
// Extra Text data is added here
275+
// TODO: TextStyle.toJSON
276+
277+
var data = {
278+
autoRound: this.autoRound,
279+
text: this.text,
280+
resolution: this.resolution,
281+
padding: {
282+
x: this.padding.x,
283+
y: this.padding.y
284+
}
285+
};
286+
287+
out.data = data;
288+
289+
return out;
268290
}
269291
});
270292

0 commit comments

Comments
 (0)