ContentEntry.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // ContentEntry.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework.Content;
  12. using System.Xml.Serialization;
  13. #endregion
  14. namespace RolePlayingGameData
  15. {
  16. /// <summary>
  17. /// A description of a piece of content and quantity for various purposes.
  18. /// </summary>
  19. public class ContentEntry<T> where T : ContentObject
  20. {
  21. /// <summary>
  22. /// The content name for the content involved.
  23. /// </summary>
  24. private string contentName;
  25. /// <summary>
  26. /// The content name for the content involved.
  27. /// </summary>
  28. [ContentSerializer(Optional=true)]
  29. public string ContentName
  30. {
  31. get { return contentName; }
  32. set { contentName = value; }
  33. }
  34. /// <summary>
  35. /// The content referred to by this entry.
  36. /// </summary>
  37. /// <remarks>
  38. /// This will not be automatically loaded, as the content path may be incomplete.
  39. /// </remarks>
  40. private T content;
  41. /// <summary>
  42. /// The content referred to by this entry.
  43. /// </summary>
  44. /// <remarks>
  45. /// This will not be automatically loaded, as the content path may be incomplete.
  46. /// </remarks>
  47. [ContentSerializerIgnore]
  48. [XmlIgnore]
  49. public T Content
  50. {
  51. get { return content; }
  52. set { content = value; }
  53. }
  54. /// <summary>
  55. /// The quantity of this content.
  56. /// </summary>
  57. private int count = 1;
  58. /// <summary>
  59. /// The quantity of this content.
  60. /// </summary>
  61. [ContentSerializer(Optional=true)]
  62. public int Count
  63. {
  64. get { return count; }
  65. set { count = value; }
  66. }
  67. #region Content Type Reader
  68. /// <summary>
  69. /// Reads a ContentEntry object from the content pipeline.
  70. /// </summary>
  71. public class ContentEntryReader : ContentTypeReader<ContentEntry<T>>
  72. {
  73. /// <summary>
  74. /// Reads a ContentEntry object from the content pipeline.
  75. /// </summary>
  76. protected override ContentEntry<T> Read(ContentReader input,
  77. ContentEntry<T> existingInstance)
  78. {
  79. ContentEntry<T> member = existingInstance;
  80. if (member == null)
  81. {
  82. member = new ContentEntry<T>();
  83. }
  84. member.ContentName = input.ReadString();
  85. member.Count = input.ReadInt32();
  86. return member;
  87. }
  88. }
  89. #endregion
  90. }
  91. }