WeightedContentEntry.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // WeightedContentEntry.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. #endregion
  13. namespace RolePlayingGameData
  14. {
  15. /// <summary>
  16. /// A description of a piece of content, quantity and weight for various purposes.
  17. /// </summary>
  18. public class WeightedContentEntry<T> : ContentEntry<T> where T : ContentObject
  19. {
  20. /// <summary>
  21. /// The weight of this content within the group, for statistical distribution.
  22. /// </summary>
  23. private int weight;
  24. /// <summary>
  25. /// The weight of this content within the group, for statistical distribution.
  26. /// </summary>
  27. public int Weight
  28. {
  29. get { return weight; }
  30. set { weight = value; }
  31. }
  32. #region Content Type Reader
  33. /// <summary>
  34. /// Reads a WeightedContentEntry object from the content pipeline.
  35. /// </summary>
  36. public class WeightedContentEntryReader :
  37. ContentTypeReader<WeightedContentEntry<T>>
  38. {
  39. /// <summary>
  40. /// Reads a WeightedContentEntry object from the content pipeline.
  41. /// </summary>
  42. protected override WeightedContentEntry<T> Read(ContentReader input,
  43. WeightedContentEntry<T> existingInstance)
  44. {
  45. WeightedContentEntry<T> entry = existingInstance;
  46. if (entry == null)
  47. {
  48. entry = new WeightedContentEntry<T>();
  49. }
  50. input.ReadRawObject<ContentEntry<T>>(entry as ContentEntry<T>);
  51. entry.Weight = input.ReadInt32();
  52. return entry;
  53. }
  54. }
  55. #endregion
  56. }
  57. }