Animation.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using OpenMetaverse;
  29. using OpenMetaverse.StructuredData;
  30. namespace OpenSim.Framework
  31. {
  32. /// <summary>
  33. /// Information about an Animation
  34. /// </summary>
  35. [Serializable]
  36. public class Animation
  37. {
  38. private UUID animID;
  39. /// <summary>
  40. /// ID of Animation
  41. /// </summary>
  42. public UUID AnimID
  43. {
  44. get { return animID; }
  45. set { animID = value; }
  46. }
  47. private int sequenceNum;
  48. public int SequenceNum
  49. {
  50. get { return sequenceNum; }
  51. set { sequenceNum = value; }
  52. }
  53. private UUID objectID;
  54. /// <summary>
  55. /// Unique ID of object that is being animated
  56. /// </summary>
  57. public UUID ObjectID
  58. {
  59. get { return objectID; }
  60. set { objectID = value; }
  61. }
  62. public Animation()
  63. {
  64. }
  65. /// <summary>
  66. /// Creates an Animation based on the data
  67. /// </summary>
  68. /// <param name="animID">UUID ID of animation</param>
  69. /// <param name="sequenceNum"></param>
  70. /// <param name="objectID">ID of object to be animated</param>
  71. public Animation(UUID animID, int sequenceNum, UUID objectID)
  72. {
  73. this.animID = animID;
  74. this.sequenceNum = sequenceNum;
  75. this.objectID = objectID;
  76. }
  77. /// <summary>
  78. /// Animation from OSDMap from LLSD XML or LLSD json
  79. /// </summary>
  80. /// <param name="args"></param>
  81. public Animation(OSDMap args)
  82. {
  83. UnpackUpdateMessage(args);
  84. }
  85. /// <summary>
  86. /// Pack this object up as an OSDMap for transferring via LLSD XML or LLSD json
  87. /// </summary>
  88. /// <returns></returns>
  89. public OSDMap PackUpdateMessage()
  90. {
  91. OSDMap anim = new OSDMap();
  92. anim["animation"] = OSD.FromUUID(animID);
  93. anim["object_id"] = OSD.FromUUID(objectID);
  94. anim["seq_num"] = OSD.FromInteger(sequenceNum);
  95. return anim;
  96. }
  97. /// <summary>
  98. /// Fill object with data from OSDMap
  99. /// </summary>
  100. /// <param name="args"></param>
  101. public void UnpackUpdateMessage(OSDMap args)
  102. {
  103. OSD tmp;
  104. if (args.TryGetValue("animation", out tmp))
  105. animID = tmp.AsUUID();
  106. if (args.TryGetValue("object_id", out tmp))
  107. objectID = tmp.AsUUID();
  108. if (args.TryGetValue("seq_num", out tmp))
  109. sequenceNum = tmp.AsInteger();
  110. }
  111. public override bool Equals(object obj)
  112. {
  113. Animation other = obj as Animation;
  114. if (other != null)
  115. {
  116. return (other.AnimID.Equals(this.AnimID)
  117. && other.SequenceNum == this.SequenceNum
  118. && other.ObjectID.Equals(this.ObjectID) );
  119. }
  120. return base.Equals(obj);
  121. }
  122. public override int GetHashCode()
  123. {
  124. return base.GetHashCode();
  125. }
  126. public override string ToString()
  127. {
  128. return "AnimID=" + AnimID.ToString()
  129. + "/seq=" + SequenceNum.ToString()
  130. + "/objID=" + ObjectID.ToString();
  131. }
  132. }
  133. }