WeightedContentEntry.cs 1.9 KB

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