PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ContentSystem/Rendering/Helpers/EmitterData.cs

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