axiosengine 

axiosengine Commit Details


Date:2012-05-07 22:20:22 (12 years 5 months ago)
Author:Natalie Adams
Branch:master
Commit:44cb32048dd53c9ea14dc2352ee652f0d92799f6
Parents: e2624fe638ec0e1a77221598e6e0340e725e5f78
Message:Adding license for Glee2D Adding support for Glee2D

Changes:

File differences

Glee2D.License.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Microsoft Public License (Ms-PL)
Microsoft Public License (Ms-PL)
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Axios Engine
============
Axios Engine is an open source 2D XNA Game Engine.
Mission Statement
-----------------
To create an open source game engine that thrives on simplicity without sacrificing usability.
Supported Platforms
-------------------
- Windows 7
- Windows Phone 7
- Xbox 360
Documentation
-------------
Official wiki:
http://wiki.axiosengine.com/
Build Instructions
------------------
Open the solution and hit build. DLLs for each platform will be put into the "Combined" folder.
Where can I download pre-built DLLs?
-------------------
Official versions can be downloaded here:
http://code.google.com/p/axiosengine/downloads/list
Of course you can always build from source from:
http://code.google.com/p/axiosengine/source/checkout
Authors
-------
General questions/comments/concerns can be directed at:
Nathan Adams - adamsna[at]datanethost.net
Copyright and License Information
---------------------------------
Axios - See Axios License.txt
- Written by Nathan Adams and released under the Apache License
Farseer - See Farseer License.txt
Glee2D - See Glee2D License.txt
axios/Axios_WP7.csproj
172172
173173
174174
175
176
177
178
175179
180
181
182
176183
177184
178185
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
<Compile Include="Engine\File\AxiosRegularFile.cs" />
<Compile Include="Engine\File\AxiosTitleFile.cs" />
<Compile Include="Engine\Glee2D\CircleItem.cs" />
<Compile Include="Engine\Glee2D\CustomProperty.cs" />
<Compile Include="Engine\Glee2D\Item.cs" />
<Compile Include="Engine\Glee2D\Layer.cs" />
<Compile Include="Engine\Glee2D\Level.cs" />
<Compile Include="Engine\Glee2D\PathItem.cs" />
<Compile Include="Engine\Glee2D\RectangleItem.cs" />
<Compile Include="Engine\Glee2D\TextureItem.cs" />
<Compile Include="Engine\Interfaces\IAxiosFile.cs" />
<Compile Include="Engine\Interfaces\IAxiosGameObject.cs" />
<Compile Include="Engine\Interfaces\IDrawableAxiosGameObject.cs" />
axios/Axios_Windows.csproj
215215
216216
217217
218
219
220
221
218222
223
224
225
219226
220227
221228
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
<Compile Include="Engine\File\AxiosRegularFile.cs" />
<Compile Include="Engine\File\AxiosTitleFile.cs" />
<Compile Include="Engine\Glee2D\CircleItem.cs" />
<Compile Include="Engine\Glee2D\CustomProperty.cs" />
<Compile Include="Engine\Glee2D\Item.cs" />
<Compile Include="Engine\Glee2D\Layer.cs" />
<Compile Include="Engine\Glee2D\Level.cs" />
<Compile Include="Engine\Glee2D\PathItem.cs" />
<Compile Include="Engine\Glee2D\RectangleItem.cs" />
<Compile Include="Engine\Glee2D\TextureItem.cs" />
<Compile Include="Engine\Interfaces\IAxiosFile.cs" />
<Compile Include="Engine\Interfaces\IAxiosGameObject.cs" />
<Compile Include="Engine\Interfaces\IDrawableAxiosGameObject.cs" />
axios/Axios_Xbox_360.csproj
165165
166166
167167
168
169
170
171
168172
173
174
175
169176
170177
171178
<Compile Include="Engine\File\AxiosIsolatedFile.cs" />
<Compile Include="Engine\File\AxiosRegularFile.cs" />
<Compile Include="Engine\File\AxiosTitleFile.cs" />
<Compile Include="Engine\Glee2D\CircleItem.cs" />
<Compile Include="Engine\Glee2D\CustomProperty.cs" />
<Compile Include="Engine\Glee2D\Item.cs" />
<Compile Include="Engine\Glee2D\Layer.cs" />
<Compile Include="Engine\Glee2D\Level.cs" />
<Compile Include="Engine\Glee2D\PathItem.cs" />
<Compile Include="Engine\Glee2D\RectangleItem.cs" />
<Compile Include="Engine\Glee2D\TextureItem.cs" />
<Compile Include="Engine\Interfaces\IAxiosFile.cs" />
<Compile Include="Engine\Interfaces\IAxiosGameObject.cs" />
<Compile Include="Engine\Interfaces\IDrawableAxiosGameObject.cs" />
axios/Engine/Glee2D/CircleItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Common;
using FarseerPhysics.SamplesFramework;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace Axios.Engine.Glee2D
{
public partial class CircleItem : Item
{
public float Radius;
public Color FillColor;
Body _body;
public CircleItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
_body = BodyFactory.CreateCircle(world, Radius, 1f);
_body.Position = Position;
_body.UserData = this;
}
}
}
axios/Engine/Glee2D/CustomProperty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Common;
using FarseerPhysics.SamplesFramework;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Xml;
using System.Xml.Serialization;
namespace Axios.Engine.Glee2D
{
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//
// NEEDED FOR SERIALIZATION. YOU SHOULDN'T CHANGE ANYTHING BELOW!
//
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
public class CustomProperty
{
public string name;
public object value;
public Type type;
public string description;
public CustomProperty()
{
}
public CustomProperty(string n, object v, Type t, string d)
{
name = n;
value = v;
type = t;
description = d;
}
public CustomProperty clone()
{
CustomProperty result = new CustomProperty(name, value, type, description);
return result;
}
}
public class SerializableDictionary : Dictionary<String, CustomProperty>, IXmlSerializable
{
public SerializableDictionary()
: base()
{
}
public SerializableDictionary(SerializableDictionary copyfrom)
: base(copyfrom)
{
string[] keyscopy = new string[Keys.Count];
Keys.CopyTo(keyscopy, 0);
foreach (string key in keyscopy)
{
this[key] = this[key].clone();
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
bool wasEmpty = reader.IsEmptyElement;
reader.Read();
if (wasEmpty) return;
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
CustomProperty cp = new CustomProperty();
cp.name = reader.GetAttribute("Name");
cp.description = reader.GetAttribute("Description");
string type = reader.GetAttribute("Type");
if (type == "string") cp.type = typeof(string);
if (type == "bool") cp.type = typeof(bool);
if (type == "Vector2") cp.type = typeof(Vector2);
if (type == "Color") cp.type = typeof(Color);
if (type == "Item") cp.type = typeof(Item);
if (cp.type == typeof(Item))
{
cp.value = reader.ReadInnerXml();
this.Add(cp.name, cp);
}
else
{
reader.ReadStartElement("Property");
XmlSerializer valueSerializer = new XmlSerializer(cp.type);
object obj = valueSerializer.Deserialize(reader);
#if WINDOWS
cp.value = Convert.ChangeType(obj, cp.type);
#elif WINDOWS_PHONE || XBOX360
cp.value = Convert.ChangeType(obj, cp.type, null);
#endif
this.Add(cp.name, cp);
reader.ReadEndElement();
}
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (String key in this.Keys)
{
writer.WriteStartElement("Property");
writer.WriteAttributeString("Name", this[key].name);
if (this[key].type == typeof(string)) writer.WriteAttributeString("Type", "string");
if (this[key].type == typeof(bool)) writer.WriteAttributeString("Type", "bool");
if (this[key].type == typeof(Vector2)) writer.WriteAttributeString("Type", "Vector2");
if (this[key].type == typeof(Color)) writer.WriteAttributeString("Type", "Color");
if (this[key].type == typeof(Item)) writer.WriteAttributeString("Type", "Item");
writer.WriteAttributeString("Description", this[key].description);
if (this[key].type == typeof(Item))
{
Item item = (Item)this[key].value;
if (item != null) writer.WriteString(item.Name);
else writer.WriteString("$null$");
}
else
{
XmlSerializer valueSerializer = new XmlSerializer(this[key].type);
valueSerializer.Serialize(writer, this[key].value);
}
writer.WriteEndElement();
}
}
/// <summary>
/// Must be called after all Items have been deserialized.
/// Restores the Item references in CustomProperties of type Item.
/// </summary>
public void RestoreItemAssociations(Level level)
{
foreach (CustomProperty cp in Values)
{
if (cp.type == typeof(Item)) cp.value = level.getItemByName((string)cp.value);
}
}
}
}
axios/Engine/Glee2D/Item.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using FarseerPhysics.Dynamics;
namespace Axios.Engine.Glee2D
{
[XmlInclude(typeof(TextureItem))]
[XmlInclude(typeof(RectangleItem))]
[XmlInclude(typeof(CircleItem))]
[XmlInclude(typeof(PathItem))]
public partial class Item
{
/// <summary>
/// The name of this item.
/// </summary>
[XmlAttribute()]
public String Name;
/// <summary>
/// Should this item be visible?
/// </summary>
[XmlAttribute()]
public bool Visible;
/// <summary>
/// The item's position in world space.
/// </summary>
public Vector2 Position;
/// <summary>
/// A Dictionary containing any user-defined Properties.
/// </summary>
public SerializableDictionary CustomProperties;
public Item()
{
CustomProperties = new SerializableDictionary();
}
/// <summary>
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
/// Should be overriden and can be used to load anything needed by the Item (e.g. a texture).
/// </summary>
public virtual void load(ContentManager cm, World world)
{
}
public virtual void draw(SpriteBatch sb)
{
}
}
}
axios/Engine/Glee2D/Layer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace Axios.Engine.Glee2D
{
public partial class Layer
{
/// <summary>
/// The name of the layer.
/// </summary>
[XmlAttribute()]
public String Name;
/// <summary>
/// Should this layer be visible?
/// </summary>
[XmlAttribute()]
public bool Visible;
/// <summary>
/// The list of the items in this layer.
/// </summary>
public List<Item> Items;
/// <summary>
/// The Scroll Speed relative to the main camera. The X and Y components are
/// interpreted as factors, so (1;1) means the same scrolling speed as the main camera.
/// Enables parallax scrolling.
/// </summary>
public Vector2 ScrollSpeed;
public Layer()
{
Items = new List<Item>();
ScrollSpeed = Vector2.One;
}
public void draw(SpriteBatch sb)
{
if (!Visible) return;
foreach (Item item in Items) item.draw(sb);
}
}
}
axios/Engine/Glee2D/Level.cs
102102
103103
104104
105
105106
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279107
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
108
505109
}
public partial class Layer
{
/// <summary>
/// The name of the layer.
/// </summary>
[XmlAttribute()]
public String Name;
/// <summary>
/// Should this layer be visible?
/// </summary>
[XmlAttribute()]
public bool Visible;
/// <summary>
/// The list of the items in this layer.
/// </summary>
public List<Item> Items;
/// <summary>
/// The Scroll Speed relative to the main camera. The X and Y components are
/// interpreted as factors, so (1;1) means the same scrolling speed as the main camera.
/// Enables parallax scrolling.
/// </summary>
public Vector2 ScrollSpeed;
public Layer()
{
Items = new List<Item>();
ScrollSpeed = Vector2.One;
}
public void draw(SpriteBatch sb)
{
if (!Visible) return;
foreach (Item item in Items) item.draw(sb);
}
}
[XmlInclude(typeof(TextureItem))]
[XmlInclude(typeof(RectangleItem))]
[XmlInclude(typeof(CircleItem))]
[XmlInclude(typeof(PathItem))]
public partial class Item
{
/// <summary>
/// The name of this item.
/// </summary>
[XmlAttribute()]
public String Name;
/// <summary>
/// Should this item be visible?
/// </summary>
[XmlAttribute()]
public bool Visible;
/// <summary>
/// The item's position in world space.
/// </summary>
public Vector2 Position;
/// <summary>
/// A Dictionary containing any user-defined Properties.
/// </summary>
public SerializableDictionary CustomProperties;
public Item()
{
CustomProperties = new SerializableDictionary();
}
/// <summary>
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
/// Should be overriden and can be used to load anything needed by the Item (e.g. a texture).
/// </summary>
public virtual void load(ContentManager cm, World world)
{
}
public virtual void draw(SpriteBatch sb)
{
}
}
public partial class TextureItem : Item
{
/// <summary>
/// The item's rotation in radians.
/// </summary>
public float Rotation;
/// <summary>
/// The item's scale factor.
/// </summary>
public float Scale;
/// <summary>
/// The color to tint the item's texture with (use white for no tint).
/// </summary>
public Color TintColor;
/// <summary>
/// If true, the texture is flipped horizontally when drawn.
/// </summary>
public bool FlipHorizontally;
/// <summary>
/// If true, the texture is flipped vertically when drawn.
/// </summary>
public bool FlipVertically;
/// <summary>
/// The path to the texture's filename (including the extension) relative to ContentRootFolder.
/// </summary>
public String texture_filename;
/// <summary>
/// The texture_filename without extension. For using in Content.Load<Texture2D>().
/// </summary>
public String asset_name;
/// <summary>
/// The XNA texture to be drawn. Can be loaded either from file (using "texture_filename")
/// or via the Content Pipeline (using "asset_name") - then you must ensure that the texture
/// exists as an asset in your project.
/// Loading is done in the Item's load() method.
/// </summary>
Texture2D texture;
/// <summary>
/// The item's origin relative to the upper left corner of the texture. Usually the middle of the texture.
/// Used for placing and rotating the texture when drawn.
/// </summary>
public Vector2 Origin;
public TextureItem()
{
}
/// <summary>
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
/// Loads all assets needed by the TextureItem, especially the Texture2D.
/// You must provide your own implementation. However, you can rely on all public fields being
/// filled by the level deserialization process.
/// </summary>
public override void load(ContentManager cm, World world)
{
//throw new NotImplementedException();
//TODO: provide your own implementation of how a TextureItem loads its assets
//for example:
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
//or by using the Content Pipeline:
this.texture = cm.Load<Texture2D>(asset_name);
}
public override void draw(SpriteBatch sb)
{
if (!Visible) return;
SpriteEffects effects = SpriteEffects.None;
if (FlipHorizontally) effects |= SpriteEffects.FlipHorizontally;
if (FlipVertically) effects |= SpriteEffects.FlipVertically;
sb.Draw(texture, Position, null, TintColor, Rotation, Origin, Scale, effects, 0);
}
}
public partial class RectangleItem : Item
{
public float Width;
public float Height;
public Color FillColor;
Body _body;
public RectangleItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
_body.Position = Position;
_body.UserData = this;
}
}
public partial class CircleItem : Item
{
public float Radius;
public Color FillColor;
Body _body;
public CircleItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
_body = BodyFactory.CreateCircle(world, Radius, 1f);
_body.Position = Position;
_body.UserData = this;
}
}
public partial class PathItem : Item
{
public Vector2[] LocalPoints;
public Vector2[] WorldPoints;
public bool IsPolygon;
public int LineWidth;
public Color LineColor;
Body _body;
public PathItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
Vertices v = new Vertices(WorldPoints.Length);
foreach (Vector2 vec in WorldPoints)
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
_body = BodyFactory.CreateLoopShape(world, v);
_body.Position = this.Position;
_body.UserData = this;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//
// NEEDED FOR SERIALIZATION. YOU SHOULDN'T CHANGE ANYTHING BELOW!
//
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
public class CustomProperty
{
public string name;
public object value;
public Type type;
public string description;
public CustomProperty()
{
}
public CustomProperty(string n, object v, Type t, string d)
{
name = n;
value = v;
type = t;
description = d;
}
public CustomProperty clone()
{
CustomProperty result = new CustomProperty(name, value, type, description);
return result;
}
}
public class SerializableDictionary : Dictionary<String, CustomProperty>, IXmlSerializable
{
public SerializableDictionary()
: base()
{
}
public SerializableDictionary(SerializableDictionary copyfrom)
: base(copyfrom)
{
string[] keyscopy = new string[Keys.Count];
Keys.CopyTo(keyscopy, 0);
foreach (string key in keyscopy)
{
this[key] = this[key].clone();
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
bool wasEmpty = reader.IsEmptyElement;
reader.Read();
if (wasEmpty) return;
while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
{
CustomProperty cp = new CustomProperty();
cp.name = reader.GetAttribute("Name");
cp.description = reader.GetAttribute("Description");
string type = reader.GetAttribute("Type");
if (type == "string") cp.type = typeof(string);
if (type == "bool") cp.type = typeof(bool);
if (type == "Vector2") cp.type = typeof(Vector2);
if (type == "Color") cp.type = typeof(Color);
if (type == "Item") cp.type = typeof(Item);
if (cp.type == typeof(Item))
{
cp.value = reader.ReadInnerXml();
this.Add(cp.name, cp);
}
else
{
reader.ReadStartElement("Property");
XmlSerializer valueSerializer = new XmlSerializer(cp.type);
object obj = valueSerializer.Deserialize(reader);
#if WINDOWS
cp.value = Convert.ChangeType(obj, cp.type);
#elif WINDOWS_PHONE || XBOX360
cp.value = Convert.ChangeType(obj, cp.type, null);
#endif
this.Add(cp.name, cp);
reader.ReadEndElement();
}
reader.MoveToContent();
}
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (String key in this.Keys)
{
writer.WriteStartElement("Property");
writer.WriteAttributeString("Name", this[key].name);
if (this[key].type == typeof(string)) writer.WriteAttributeString("Type", "string");
if (this[key].type == typeof(bool)) writer.WriteAttributeString("Type", "bool");
if (this[key].type == typeof(Vector2)) writer.WriteAttributeString("Type", "Vector2");
if (this[key].type == typeof(Color)) writer.WriteAttributeString("Type", "Color");
if (this[key].type == typeof(Item)) writer.WriteAttributeString("Type", "Item");
writer.WriteAttributeString("Description", this[key].description);
if (this[key].type == typeof(Item))
{
Item item = (Item)this[key].value;
if (item != null) writer.WriteString(item.Name);
else writer.WriteString("$null$");
}
else
{
XmlSerializer valueSerializer = new XmlSerializer(this[key].type);
valueSerializer.Serialize(writer, this[key].value);
}
writer.WriteEndElement();
}
}
/// <summary>
/// Must be called after all Items have been deserialized.
/// Restores the Item references in CustomProperties of type Item.
/// </summary>
public void RestoreItemAssociations(Level level)
{
foreach (CustomProperty cp in Values)
{
if (cp.type == typeof(Item)) cp.value = level.getItemByName((string)cp.value);
}
}
}
}
axios/Engine/Glee2D/PathItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Common;
using FarseerPhysics.SamplesFramework;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace Axios.Engine.Glee2D
{
public partial class PathItem : Item
{
public Vector2[] LocalPoints;
public Vector2[] WorldPoints;
public bool IsPolygon;
public int LineWidth;
public Color LineColor;
Body _body;
public PathItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
Vertices v = new Vertices(WorldPoints.Length);
foreach (Vector2 vec in WorldPoints)
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
_body = BodyFactory.CreateLoopShape(world, v);
_body.Position = this.Position;
_body.UserData = this;
}
}
}
axios/Engine/Glee2D/RectangleItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Common;
using FarseerPhysics.SamplesFramework;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace Axios.Engine.Glee2D
{
public partial class RectangleItem : Item
{
public float Width;
public float Height;
public Color FillColor;
Body _body;
public RectangleItem()
{
}
public override void load(ContentManager cm, World world)
{
base.load(cm, world);
_body = BodyFactory.CreateRectangle(world, Width, Height, 1f);
_body.Position = Position;
_body.UserData = this;
}
}
}
axios/Engine/Glee2D/TextureItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.IO;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Common;
using FarseerPhysics.SamplesFramework;
using FarseerPhysics.Factories;
namespace Axios.Engine.Glee2D
{
public partial class TextureItem : Item
{
/// <summary>
/// The item's rotation in radians.
/// </summary>
public float Rotation;
/// <summary>
/// The item's scale factor.
/// </summary>
public float Scale;
/// <summary>
/// The color to tint the item's texture with (use white for no tint).
/// </summary>
public Color TintColor;
/// <summary>
/// If true, the texture is flipped horizontally when drawn.
/// </summary>
public bool FlipHorizontally;
/// <summary>
/// If true, the texture is flipped vertically when drawn.
/// </summary>
public bool FlipVertically;
/// <summary>
/// The path to the texture's filename (including the extension) relative to ContentRootFolder.
/// </summary>
public String texture_filename;
/// <summary>
/// The texture_filename without extension. For using in Content.Load<Texture2D>().
/// </summary>
public String asset_name;
/// <summary>
/// The XNA texture to be drawn. Can be loaded either from file (using "texture_filename")
/// or via the Content Pipeline (using "asset_name") - then you must ensure that the texture
/// exists as an asset in your project.
/// Loading is done in the Item's load() method.
/// </summary>
Texture2D texture;
/// <summary>
/// The item's origin relative to the upper left corner of the texture. Usually the middle of the texture.
/// Used for placing and rotating the texture when drawn.
/// </summary>
public Vector2 Origin;
public TextureItem()
{
}
/// <summary>
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
/// Loads all assets needed by the TextureItem, especially the Texture2D.
/// You must provide your own implementation. However, you can rely on all public fields being
/// filled by the level deserialization process.
/// </summary>
public override void load(ContentManager cm, World world)
{
//throw new NotImplementedException();
//TODO: provide your own implementation of how a TextureItem loads its assets
//for example:
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
//or by using the Content Pipeline:
this.texture = cm.Load<Texture2D>(asset_name);
}
public override void draw(SpriteBatch sb)
{
if (!Visible) return;
SpriteEffects effects = SpriteEffects.None;
if (FlipHorizontally) effects |= SpriteEffects.FlipHorizontally;
if (FlipVertically) effects |= SpriteEffects.FlipVertically;
sb.Draw(texture, Position, null, TintColor, Rotation, Origin, Scale, effects, 0);
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.21311s using 14 queries.