aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AnimationSet.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/AnimationSet.cs186
1 files changed, 186 insertions, 0 deletions
diff --git a/OpenSim/Framework/AnimationSet.cs b/OpenSim/Framework/AnimationSet.cs
new file mode 100644
index 0000000..8753088
--- /dev/null
+++ b/OpenSim/Framework/AnimationSet.cs
@@ -0,0 +1,186 @@
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
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31
32namespace OpenSim.Framework
33{
34// public delegate bool AnimationSetValidator(UUID animID);
35 public delegate uint AnimationSetValidator(UUID animID);
36
37 public class AnimationSet
38 {
39 private bool m_parseError = false;
40
41 public const uint createBasePermitions = (uint)(PermissionMask.All); // no export ?
42 public const uint createNextPermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
43
44 public const uint allowedBasePermitions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
45 public const uint allowedNextPermitions = 0;
46
47 public static void setCreateItemPermitions(InventoryItemBase it)
48 {
49 if (it == null)
50 return;
51
52 it.BasePermissions = createBasePermitions;
53 it.CurrentPermissions = createBasePermitions;
54 // it.GroupPermissions &= allowedPermitions;
55 it.NextPermissions = createNextPermitions;
56 // it.EveryOnePermissions &= allowedPermitions;
57 it.GroupPermissions = 0;
58 it.EveryOnePermissions = 0;
59 }
60
61 public static void enforceItemPermitions(InventoryItemBase it, bool IsCreator)
62 {
63 if (it == null)
64 return;
65
66 uint bp;
67 uint np;
68
69 if (IsCreator)
70 {
71 bp = createBasePermitions;
72 np = createNextPermitions;
73 }
74 else
75 {
76 bp = allowedBasePermitions;
77 np = allowedNextPermitions;
78 }
79
80 it.BasePermissions &= bp;
81 it.CurrentPermissions &= bp;
82 // it.GroupPermissions &= allowedPermitions;
83 it.NextPermissions &= np;
84 // it.EveryOnePermissions &= allowedPermitions;
85 it.GroupPermissions = 0;
86 it.EveryOnePermissions = 0;
87 }
88
89 public int AnimationCount { get; private set; }
90 private Dictionary<string, KeyValuePair<string, UUID>> m_animations = new Dictionary<string, KeyValuePair<string, UUID>>();
91
92 public UUID GetAnimation(string index)
93 {
94 KeyValuePair<string, UUID> val;
95 if (m_animations.TryGetValue(index, out val))
96 return val.Value;
97
98 return UUID.Zero;
99 }
100
101 public string GetAnimationName(string index)
102 {
103 KeyValuePair<string, UUID> val;
104 if (m_animations.TryGetValue(index, out val))
105 return val.Key;
106
107 return String.Empty;
108 }
109
110 public void SetAnimation(string index, string name, UUID anim)
111 {
112 if (anim == UUID.Zero)
113 {
114 m_animations.Remove(index);
115 return;
116 }
117
118 m_animations[index] = new KeyValuePair<string, UUID>(name, anim);
119 }
120
121 public AnimationSet(Byte[] data)
122 {
123 string assetData = System.Text.Encoding.ASCII.GetString(data);
124 Console.WriteLine("--------------------");
125 Console.WriteLine("AnimationSet length {0} bytes", assetData.Length);
126 Console.WriteLine(assetData);
127 Console.WriteLine("--------------------");
128 }
129
130 public Byte[] ToBytes()
131 {
132 // If there was an error parsing the input, we give back an
133 // empty set rather than the original data.
134 if (m_parseError)
135 {
136 string dummy = "version 1\ncount 0\n";
137 return System.Text.Encoding.ASCII.GetBytes(dummy);
138 }
139
140 string assetData = String.Format("version 1\ncount {0}\n", m_animations.Count);
141 foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
142 assetData += String.Format("{0} {1} {2}\n", kvp.Key, kvp.Value.Value.ToString(), kvp.Value.Key);
143 return System.Text.Encoding.ASCII.GetBytes(assetData);
144 }
145/*
146 public bool Validate(AnimationSetValidator val)
147 {
148 if (m_parseError)
149 return false;
150
151 List<string> badAnims = new List<string>();
152
153 bool allOk = true;
154 foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
155 {
156 if (!val(kvp.Value.Value))
157 {
158 allOk = false;
159 badAnims.Add(kvp.Key);
160 }
161 }
162
163 foreach (string idx in badAnims)
164 m_animations.Remove(idx);
165
166 return allOk;
167 }
168*/
169 public uint Validate(AnimationSetValidator val)
170 {
171 if (m_parseError)
172 return 0;
173
174 uint ret = 0x7fffffff;
175 uint t;
176 foreach (KeyValuePair<string, KeyValuePair<string, UUID>> kvp in m_animations)
177 {
178 t = val(kvp.Value.Value);
179 if (t == 0)
180 return 0;
181 ret &= t;
182 }
183 return ret;
184 }
185 }
186}