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