PageRenderTime 102ms CodeModel.GetById 39ms app.highlight 4ms RepoModel.GetById 57ms app.codeStats 0ms

/ContentSystem/Rendering/Helpers/EmitterData.cs

#
C# | 96 lines | 57 code | 6 blank | 33 comment | 2 complexity | ff5f46a69edfab4812fb7432642587aa MD5 | raw file
 1using System.Collections.Generic;
 2using System.IO;
 3using Delta.Engine.Dynamic;
 4using Delta.Utilities;
 5
 6namespace Delta.ContentSystem.Rendering.Helpers
 7{
 8	/// <summary>
 9	/// Emitter data class, used for EffectData, which just contains a list of
10	/// emitters. Please note that this class can be derived for additional
11	/// functionality and each of the modifiers stored here can also be
12	/// any class using the IEffectModifier interface.
13	/// </summary>
14	public class EmitterData : ISaveLoadBinary
15	{
16		#region Name (Public)
17		/// <summary>
18		/// The name of the Emitter.
19		/// </summary>
20		public string Name
21		{
22			get;
23			set;
24		}
25		#endregion
26
27		#region Modifiers (Public)
28		/// <summary>
29		/// The list of modifiers for this emitter.
30		/// </summary>
31		public List<IEffectModifier> Modifiers
32		{
33			get;
34			private set;
35		}
36		#endregion
37
38		#region Constructors
39		/// <summary>
40		/// Create a new emitter data instance.
41		/// </summary>
42		public EmitterData()
43		{
44			Modifiers = new List<IEffectModifier>();
45			Name = "Emitter";
46		}
47		#endregion
48
49		#region ISaveLoadBinary Members
50		/// <summary>
51		/// Load the emitter data and all the modifiers.
52		/// </summary>
53		/// <param name="reader">BinaryReader for reading the data</param>
54		public void Load(BinaryReader reader)
55		{
56			// Load the name and number of modifiers.
57			Name = reader.ReadString();
58			int numberOfModifiers = reader.ReadInt32();
59			// Iterate through the modifiers...
60			for (int index = 0; index < numberOfModifiers; index++)
61			{
62				// Load the modifier data via the Factory and add it to the list.
63				Modifiers.Add(Factory.Load<IEffectModifier>(reader));
64			} // for
65		}
66
67		/// <summary>
68		/// Save the emitter data and all the modifiers.
69		/// </summary>
70		/// <param name="writer">BinaryWriter for the stream to write into</param>
71		public void Save(BinaryWriter writer)
72		{
73			// Save the name and number of modifiers.
74			writer.Write(Name);
75			writer.Write(Modifiers.Count);
76			// Iterate through the modifiers...
77			for (int index = 0; index < Modifiers.Count; index++)
78			{
79				// And save them via the Factory.
80				Factory.Save(writer, Modifiers[index]);
81			} // for
82		}
83		#endregion
84
85		#region ToString (Public)
86		/// <summary>
87		/// To string helper method to print out the name of this emitter instance.
88		/// </summary>
89		/// <returns>String representing this EmitterData instance (name)</returns>
90		public override string ToString()
91		{
92			return base.ToString() + " " + Name;
93		}
94		#endregion
95	}
96}