1
0

AnimationSet.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 System.Collections.Generic;
  29. using System.Text;
  30. using OpenMetaverse;
  31. namespace OpenSim.Framework
  32. {
  33. // public delegate bool AnimationSetValidator(UUID animID);
  34. public delegate uint AnimationSetValidator(UUID animID);
  35. public class AnimationSet
  36. {
  37. private bool m_parseError = false;
  38. public const uint createBasePermitions = (uint)(PermissionMask.All); // no export ?
  39. public const uint createNextPermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
  40. public const uint allowedBasePermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
  41. public const uint allowedNextPermitions = 0;
  42. public static void setCreateItemPermitions(InventoryItemBase it)
  43. {
  44. if (it == null)
  45. return;
  46. it.BasePermissions = createBasePermitions;
  47. it.CurrentPermissions = createBasePermitions;
  48. // it.GroupPermissions &= allowedPermitions;
  49. it.NextPermissions = createNextPermitions;
  50. // it.EveryOnePermissions &= allowedPermitions;
  51. it.GroupPermissions = 0;
  52. it.EveryOnePermissions = 0;
  53. }
  54. public static void enforceItemPermitions(InventoryItemBase it, bool IsCreator)
  55. {
  56. if (it == null)
  57. return;
  58. uint bp;
  59. uint np;
  60. if (IsCreator)
  61. {
  62. bp = createBasePermitions;
  63. np = createNextPermitions;
  64. }
  65. else
  66. {
  67. bp = allowedBasePermitions;
  68. np = allowedNextPermitions;
  69. }
  70. it.BasePermissions &= bp;
  71. it.CurrentPermissions &= bp;
  72. // it.GroupPermissions &= allowedPermitions;
  73. it.NextPermissions &= np;
  74. // it.EveryOnePermissions &= allowedPermitions;
  75. it.GroupPermissions = 0;
  76. it.EveryOnePermissions = 0;
  77. }
  78. public int AnimationCount { get; private set; }
  79. private Dictionary<string, KeyValuePair<string, UUID>> m_animations = new Dictionary<string, KeyValuePair<string, UUID>>();
  80. public UUID GetAnimation(string index)
  81. {
  82. KeyValuePair<string, UUID> val;
  83. if (m_animations.TryGetValue(index, out val))
  84. return val.Value;
  85. return UUID.Zero;
  86. }
  87. public string GetAnimationName(string index)
  88. {
  89. KeyValuePair<string, UUID> val;
  90. if (m_animations.TryGetValue(index, out val))
  91. return val.Key;
  92. return String.Empty;
  93. }
  94. public void SetAnimation(string index, string name, UUID anim)
  95. {
  96. if (anim.IsZero())
  97. {
  98. m_animations.Remove(index);
  99. return;
  100. }
  101. m_animations[index] = new KeyValuePair<string, UUID>(name, anim);
  102. }
  103. public AnimationSet(Byte[] data)
  104. {
  105. string assetData = System.Text.Encoding.ASCII.GetString(data);
  106. Console.WriteLine("--------------------");
  107. Console.WriteLine("AnimationSet length {0} bytes", assetData.Length);
  108. Console.WriteLine(assetData);
  109. Console.WriteLine("--------------------");
  110. }
  111. public static readonly byte[] ZeroCountBytesReply = osUTF8.GetASCIIBytes("version 1\ncount 0\n");
  112. public Byte[] ToBytes()
  113. {
  114. // If there was an error parsing the input, we give back an
  115. // empty set rather than the original data.
  116. if (m_parseError || m_animations.Count == 0)
  117. return ZeroCountBytesReply;
  118. osUTF8 sb = OSUTF8Cached.Acquire();
  119. sb.AppendASCII("$version 1\ncount {m_animations.Count}\n");
  120. foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
  121. sb.AppendASCII($"{kvp.Key} {kvp.Value.Value} {kvp.Value.Key}\n");
  122. return OSUTF8Cached.GetArrayAndRelease(sb);
  123. }
  124. /*
  125. public bool Validate(AnimationSetValidator val)
  126. {
  127. if (m_parseError)
  128. return false;
  129. List<string> badAnims = new List<string>();
  130. bool allOk = true;
  131. foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
  132. {
  133. if (!val(kvp.Value.Value))
  134. {
  135. allOk = false;
  136. badAnims.Add(kvp.Key);
  137. }
  138. }
  139. foreach (string idx in badAnims)
  140. m_animations.Remove(idx);
  141. return allOk;
  142. }
  143. */
  144. public uint Validate(AnimationSetValidator val)
  145. {
  146. if (m_parseError)
  147. return 0;
  148. uint ret = 0x7fffffff;
  149. uint t;
  150. foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
  151. {
  152. t = val(kvp.Value.Value);
  153. if (t == 0)
  154. return 0;
  155. ret &= t;
  156. }
  157. return ret;
  158. }
  159. }
  160. }