ContentEntry.cs 2.8 KB

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