aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/WearableItem.cs656
1 files changed, 328 insertions, 328 deletions
diff --git a/OpenSim/Framework/WearableItem.cs b/OpenSim/Framework/WearableItem.cs
index c4aa9bd..b2cb7e1 100644
--- a/OpenSim/Framework/WearableItem.cs
+++ b/OpenSim/Framework/WearableItem.cs
@@ -1,328 +1,328 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Globalization; 3using System.Globalization;
4using System.IO; 4using System.IO;
5using System.Text.RegularExpressions; 5using System.Text.RegularExpressions;
6using OpenMetaverse; 6using OpenMetaverse;
7 7
8namespace OpenSim.Framework 8namespace OpenSim.Framework
9{ 9{
10 public class WearableItem 10 public class WearableItem
11 { 11 {
12 public string WearableName = ""; 12 public string WearableName = "";
13 public WearableType WearType = WearableType.Invalid; 13 public WearableType WearType = WearableType.Invalid;
14 14
15 public string ItemInfo = "Created Wearable"; 15 public string ItemInfo = "Created Wearable";
16 16
17 public SortedList<int, VisualSetting> VisualSettings = new SortedList<int, VisualSetting>(); 17 public SortedList<int, VisualSetting> VisualSettings = new SortedList<int, VisualSetting>();
18 // public LLObject.TextureEntry TextureEntry = null; 18 // public LLObject.TextureEntry TextureEntry = null;
19 //public byte[] TextureEntry = null; 19 //public byte[] TextureEntry = null;
20 20
21 public List<string> TextureStrings = new List<string>(); 21 public List<string> TextureStrings = new List<string>();
22 22
23 //permissions 23 //permissions
24 public uint BaseMask = 0; 24 public uint BaseMask = 0;
25 public uint OwnerMask = 0; 25 public uint OwnerMask = 0;
26 public uint GroupMask = 0; 26 public uint GroupMask = 0;
27 public uint EveryoneMask = 0; 27 public uint EveryoneMask = 0;
28 public uint NextOwnerMask = 0; 28 public uint NextOwnerMask = 0;
29 29
30 public UUID CreatorID = UUID.Zero; 30 public UUID CreatorID = UUID.Zero;
31 public UUID OwnerID = UUID.Zero; 31 public UUID OwnerID = UUID.Zero;
32 public UUID LastOwnerID = UUID.Zero; 32 public UUID LastOwnerID = UUID.Zero;
33 public UUID GroupID = UUID.Zero; 33 public UUID GroupID = UUID.Zero;
34 34
35 //sale 35 //sale
36 public string SaleType = "not"; 36 public string SaleType = "not";
37 public int SalePrice = 10; 37 public int SalePrice = 10;
38 38
39 private string BuildString = ""; 39 private string BuildString = "";
40 40
41 41
42 public WearableItem(string wearableName, WearableType type) 42 public WearableItem(string wearableName, WearableType type)
43 { 43 {
44 WearableName = wearableName; 44 WearableName = wearableName;
45 WearType = type; 45 WearType = type;
46 } 46 }
47 47
48 public WearableItem(string wearableName) 48 public WearableItem(string wearableName)
49 { 49 {
50 WearableName = wearableName; 50 WearableName = wearableName;
51 WearType = ConvertNameToType(WearableName); 51 WearType = ConvertNameToType(WearableName);
52 } 52 }
53 53
54 public WearableItem(WearableType type) 54 public WearableItem(WearableType type)
55 { 55 {
56 WearType = type; 56 WearType = type;
57 WearableName = Enum.GetName(typeof(WearableType), type).ToLower(); 57 WearableName = Enum.GetName(typeof(WearableType), type).ToLower();
58 } 58 }
59 59
60 public WearableItem() 60 public WearableItem()
61 { 61 {
62 } 62 }
63 63
64 public void AddVisualSetting(VisualSetting setting) 64 public void AddVisualSetting(VisualSetting setting)
65 { 65 {
66 if (!VisualSettings.ContainsKey(setting.VisualParam.ParamID)) 66 if (!VisualSettings.ContainsKey(setting.VisualParam.ParamID))
67 { 67 {
68 VisualSettings.Add(setting.VisualParam.ParamID, setting); 68 VisualSettings.Add(setting.VisualParam.ParamID, setting);
69 } 69 }
70 } 70 }
71 71
72 public bool TryGetSetting(string paramName, out VisualSetting paramSetting) 72 public bool TryGetSetting(string paramName, out VisualSetting paramSetting)
73 { 73 {
74 foreach (VisualSetting setting in VisualSettings.Values) 74 foreach (VisualSetting setting in VisualSettings.Values)
75 { 75 {
76 if (setting.VisualParam.Name == paramName) 76 if (setting.VisualParam.Name == paramName)
77 { 77 {
78 paramSetting = setting; 78 paramSetting = setting;
79 return true; 79 return true;
80 } 80 }
81 } 81 }
82 82
83 paramSetting = null; 83 paramSetting = null;
84 return false; 84 return false;
85 } 85 }
86 86
87 public bool SetParamValue(string paramName, float value) 87 public bool SetParamValue(string paramName, float value)
88 { 88 {
89 VisualSetting paramSetting; 89 VisualSetting paramSetting;
90 if (TryGetSetting(paramName, out paramSetting)) 90 if (TryGetSetting(paramName, out paramSetting))
91 { 91 {
92 if ((value >= paramSetting.VisualParam.MinValue) && (value <= paramSetting.VisualParam.MaxValue)) 92 if ((value >= paramSetting.VisualParam.MinValue) && (value <= paramSetting.VisualParam.MaxValue))
93 { 93 {
94 paramSetting.Value = value; 94 paramSetting.Value = value;
95 return true; 95 return true;
96 } 96 }
97 } 97 }
98 return false; 98 return false;
99 } 99 }
100 100
101 public void RandomiseValues() 101 public void RandomiseValues()
102 { 102 {
103 foreach (VisualSetting setting in VisualSettings.Values) 103 foreach (VisualSetting setting in VisualSettings.Values)
104 { 104 {
105 //int randNum = Util.RandomClass.Next(0, 1000); 105 //int randNum = Util.RandomClass.Next(0, 1000);
106 float range = setting.VisualParam.MaxValue - setting.VisualParam.MinValue; 106 float range = setting.VisualParam.MaxValue - setting.VisualParam.MinValue;
107 // float val =((float) randNum )/ ((float)(1000.0f / range)); 107 // float val =((float) randNum )/ ((float)(1000.0f / range));
108 float val = (float)OpenSim.Framework.Util.RandomClass.NextDouble() * range * 0.2f; 108 float val = (float)OpenSim.Framework.Util.RandomClass.NextDouble() * range * 0.2f;
109 setting.Value = setting.VisualParam.MinValue + (range / 2) + val; 109 setting.Value = setting.VisualParam.MinValue + (range / 2) + val;
110 } 110 }
111 } 111 }
112 112
113 public WearableType ConvertNameToType(string name) 113 public WearableType ConvertNameToType(string name)
114 { 114 {
115 return (WearableType)Enum.Parse(typeof(WearableType), name, true); 115 return (WearableType)Enum.Parse(typeof(WearableType), name, true);
116 } 116 }
117 117
118 public string ToAssetFormat() 118 public string ToAssetFormat()
119 { 119 {
120 BuildString = "LLWearable version 22\n"; 120 BuildString = "LLWearable version 22\n";
121 BuildString += "New Item \n"; 121 BuildString += "New Item \n";
122 BuildString += ItemInfo + "\n"; 122 BuildString += ItemInfo + "\n";
123 123
124 124
125 AddSectionStart("permissions"); 125 AddSectionStart("permissions");
126 AddTabbedNameValueLine("base_mask", BaseMask.ToString("00000000")); 126 AddTabbedNameValueLine("base_mask", BaseMask.ToString("00000000"));
127 AddTabbedNameValueLine("owner_mask", OwnerMask.ToString("00000000")); 127 AddTabbedNameValueLine("owner_mask", OwnerMask.ToString("00000000"));
128 AddTabbedNameValueLine("group_mask", GroupMask.ToString("00000000")); 128 AddTabbedNameValueLine("group_mask", GroupMask.ToString("00000000"));
129 AddTabbedNameValueLine("everyone_mask", EveryoneMask.ToString("00000000")); 129 AddTabbedNameValueLine("everyone_mask", EveryoneMask.ToString("00000000"));
130 AddTabbedNameValueLine("next_owner_mask", NextOwnerMask.ToString("00000000")); 130 AddTabbedNameValueLine("next_owner_mask", NextOwnerMask.ToString("00000000"));
131 AddTabbedNameValueLine("creator_id", CreatorID.ToString()); 131 AddTabbedNameValueLine("creator_id", CreatorID.ToString());
132 AddTabbedNameValueLine("owner_id", OwnerID.ToString()); 132 AddTabbedNameValueLine("owner_id", OwnerID.ToString());
133 AddTabbedNameValueLine("last_owner_id", LastOwnerID.ToString()); 133 AddTabbedNameValueLine("last_owner_id", LastOwnerID.ToString());
134 AddTabbedNameValueLine("group_id", GroupID.ToString()); 134 AddTabbedNameValueLine("group_id", GroupID.ToString());
135 AddSectionEnd(); 135 AddSectionEnd();
136 136
137 AddSectionStart("sale_info"); 137 AddSectionStart("sale_info");
138 AddTabbedNameValueLine("sale_type", SaleType.ToString()); 138 AddTabbedNameValueLine("sale_type", SaleType.ToString());
139 AddTabbedNameValueLine("sale_price", SalePrice.ToString()); 139 AddTabbedNameValueLine("sale_price", SalePrice.ToString());
140 AddSectionEnd(); 140 AddSectionEnd();
141 141
142 AddNameValueLine("type", ((byte)WearType).ToString()); 142 AddNameValueLine("type", ((byte)WearType).ToString());
143 AddNameValueLine("parameters", VisualSettings.Count.ToString()); 143 AddNameValueLine("parameters", VisualSettings.Count.ToString());
144 144
145 foreach (KeyValuePair<int, VisualSetting> kp in VisualSettings) 145 foreach (KeyValuePair<int, VisualSetting> kp in VisualSettings)
146 { 146 {
147 AddNameValueLine(kp.Key.ToString(), kp.Value.Value.ToString(CultureInfo.InvariantCulture)); 147 AddNameValueLine(kp.Key.ToString(), kp.Value.Value.ToString(CultureInfo.InvariantCulture));
148 } 148 }
149 if (TextureStrings.Count == 0) 149 if (TextureStrings.Count == 0)
150 { 150 {
151 AddNameValueLine("textures", "0"); //todo output texture entry 151 AddNameValueLine("textures", "0"); //todo output texture entry
152 } 152 }
153 else 153 else
154 { 154 {
155 AddNameValueLine("textures", TextureStrings.Count.ToString()); 155 AddNameValueLine("textures", TextureStrings.Count.ToString());
156 for (int i = 0; i < TextureStrings.Count; i++) 156 for (int i = 0; i < TextureStrings.Count; i++)
157 { 157 {
158 BuildString += TextureStrings[i] + "\n"; 158 BuildString += TextureStrings[i] + "\n";
159 } 159 }
160 BuildString += "\n"; 160 BuildString += "\n";
161 161
162 } 162 }
163 163
164 return BuildString; 164 return BuildString;
165 } 165 }
166 166
167 public void SaveToFile(string fileName) 167 public void SaveToFile(string fileName)
168 { 168 {
169 File.WriteAllText(fileName, this.ToAssetFormat()); 169 File.WriteAllText(fileName, this.ToAssetFormat());
170 } 170 }
171 171
172 public void AddSectionStart(string sectionName) 172 public void AddSectionStart(string sectionName)
173 { 173 {
174 BuildString += "\t" + sectionName + " 0\n"; 174 BuildString += "\t" + sectionName + " 0\n";
175 BuildString += "\t{\n"; 175 BuildString += "\t{\n";
176 } 176 }
177 177
178 public void AddSectionEnd() 178 public void AddSectionEnd()
179 { 179 {
180 BuildString += "\t}\n"; 180 BuildString += "\t}\n";
181 } 181 }
182 182
183 private void AddTabbedNameValueLine(string name, string value) 183 private void AddTabbedNameValueLine(string name, string value)
184 { 184 {
185 BuildString += "\t\t"; 185 BuildString += "\t\t";
186 BuildString += name + "\t"; 186 BuildString += name + "\t";
187 BuildString += value + "\n"; 187 BuildString += value + "\n";
188 } 188 }
189 189
190 private void AddNameValueLine(string name, string value) 190 private void AddNameValueLine(string name, string value)
191 { 191 {
192 // BuildString += "\t\t"; 192 // BuildString += "\t\t";
193 BuildString += name + " "; 193 BuildString += name + " ";
194 BuildString += value + "\n"; 194 BuildString += value + "\n";
195 } 195 }
196 196
197 #region Static Methods 197 #region Static Methods
198 public static List<VisualParam> FindParamsForWearable(string wearableName) 198 public static List<VisualParam> FindParamsForWearable(string wearableName)
199 { 199 {
200 List<VisualParam> wearableParams = new List<VisualParam>(); 200 List<VisualParam> wearableParams = new List<VisualParam>();
201 foreach (VisualParam param in VisualParams.Params.Values) 201 foreach (VisualParam param in VisualParams.Params.Values)
202 { 202 {
203 if (param.Wearable == wearableName) 203 if (param.Wearable == wearableName)
204 { 204 {
205 wearableParams.Add(param); 205 wearableParams.Add(param);
206 } 206 }
207 } 207 }
208 208
209 return wearableParams; 209 return wearableParams;
210 } 210 }
211 211
212 public static WearableItem Create(string wearableTypeName) 212 public static WearableItem Create(string wearableTypeName)
213 { 213 {
214 WearableItem wearableItem = new WearableItem(wearableTypeName); 214 WearableItem wearableItem = new WearableItem(wearableTypeName);
215 List<VisualParam> typeParams = FindParamsForWearable(wearableTypeName); 215 List<VisualParam> typeParams = FindParamsForWearable(wearableTypeName);
216 foreach (VisualParam param in typeParams) 216 foreach (VisualParam param in typeParams)
217 { 217 {
218 wearableItem.AddVisualSetting(new VisualSetting(param)); 218 wearableItem.AddVisualSetting(new VisualSetting(param));
219 } 219 }
220 return wearableItem; 220 return wearableItem;
221 } 221 }
222 222
223 public static WearableItem CreateFromAsset(string assetData) 223 public static WearableItem CreateFromAsset(string assetData)
224 { 224 {
225 UUID creatorID = UUID.Zero; 225 UUID creatorID = UUID.Zero;
226 UUID ownerID = UUID.Zero; 226 UUID ownerID = UUID.Zero;
227 UUID lastOwnerID = UUID.Zero; 227 UUID lastOwnerID = UUID.Zero;
228 UUID groupID = UUID.Zero; 228 UUID groupID = UUID.Zero;
229 229
230 char[] newlineDelimiter = { '\n' }; 230 char[] newlineDelimiter = { '\n' };
231 string[] lines = assetData.Split(newlineDelimiter); 231 string[] lines = assetData.Split(newlineDelimiter);
232 232
233 WearableItem wearableObject = null; 233 WearableItem wearableObject = null;
234 Regex r = new Regex("[\t ]+"); 234 Regex r = new Regex("[\t ]+");
235 bool reachedParams = false; 235 bool reachedParams = false;
236 bool reachedTextures = false; 236 bool reachedTextures = false;
237 foreach (string line in lines) 237 foreach (string line in lines)
238 { 238 {
239 string trimLine = line.Trim(); 239 string trimLine = line.Trim();
240 // Console.WriteLine("line : " + trimLine); 240 // Console.WriteLine("line : " + trimLine);
241 241
242 string[] splitLine = r.Split(trimLine); 242 string[] splitLine = r.Split(trimLine);
243 if (splitLine.Length > 1) 243 if (splitLine.Length > 1)
244 { 244 {
245 switch (splitLine[0]) 245 switch (splitLine[0])
246 { 246 {
247 case "textures": 247 case "textures":
248 reachedParams = false; 248 reachedParams = false;
249 reachedTextures = true; 249 reachedTextures = true;
250 break; 250 break;
251 251
252 case "type": 252 case "type":
253 string wearableTypeName = Enum.GetName(typeof(WearableType), (WearableType)Convert.ToInt32(splitLine[1])); 253 string wearableTypeName = Enum.GetName(typeof(WearableType), (WearableType)Convert.ToInt32(splitLine[1]));
254 wearableObject = Create(wearableTypeName.ToLower()); 254 wearableObject = Create(wearableTypeName.ToLower());
255 break; 255 break;
256 256
257 case "parameters": 257 case "parameters":
258 reachedParams = true; 258 reachedParams = true;
259 break; 259 break;
260 260
261 case "creator_id": 261 case "creator_id":
262 creatorID = new UUID(splitLine[1]); 262 creatorID = new UUID(splitLine[1]);
263 break; 263 break;
264 264
265 case "owner_id": 265 case "owner_id":
266 ownerID = new UUID(splitLine[1]); 266 ownerID = new UUID(splitLine[1]);
267 break; 267 break;
268 268
269 case "last_owner_id": 269 case "last_owner_id":
270 lastOwnerID = new UUID(splitLine[1]); 270 lastOwnerID = new UUID(splitLine[1]);
271 break; 271 break;
272 272
273 case "group_id": 273 case "group_id":
274 groupID = new UUID(splitLine[1]); 274 groupID = new UUID(splitLine[1]);
275 break; 275 break;
276 276
277 default: 277 default:
278 if ((wearableObject != null) && (reachedParams)) 278 if ((wearableObject != null) && (reachedParams))
279 { 279 {
280 int id = Convert.ToInt32(splitLine[0]); 280 int id = Convert.ToInt32(splitLine[0]);
281 if (wearableObject.VisualSettings.ContainsKey(id)) 281 if (wearableObject.VisualSettings.ContainsKey(id))
282 { 282 {
283 283
284 wearableObject.VisualSettings[id].Value = Convert.ToSingle(splitLine[1], CultureInfo.InvariantCulture); 284 wearableObject.VisualSettings[id].Value = Convert.ToSingle(splitLine[1], CultureInfo.InvariantCulture);
285 } 285 }
286 } 286 }
287 else if ((wearableObject != null) && (reachedTextures)) 287 else if ((wearableObject != null) && (reachedTextures))
288 { 288 {
289 wearableObject.TextureStrings.Add(line); 289 wearableObject.TextureStrings.Add(line);
290 } 290 }
291 break; 291 break;
292 } 292 }
293 } 293 }
294 } 294 }
295 295
296 if (wearableObject != null) 296 if (wearableObject != null)
297 { 297 {
298 wearableObject.CreatorID = creatorID; 298 wearableObject.CreatorID = creatorID;
299 wearableObject.OwnerID = ownerID; 299 wearableObject.OwnerID = ownerID;
300 wearableObject.LastOwnerID = lastOwnerID; 300 wearableObject.LastOwnerID = lastOwnerID;
301 wearableObject.GroupID = groupID; 301 wearableObject.GroupID = groupID;
302 } 302 }
303 303
304 return wearableObject; 304 return wearableObject;
305 } 305 }
306 #endregion 306 #endregion
307 307
308 #region Nested Class 308 #region Nested Class
309 public class VisualSetting 309 public class VisualSetting
310 { 310 {
311 public VisualParam VisualParam; 311 public VisualParam VisualParam;
312 public float Value = 0; 312 public float Value = 0;
313 313
314 public VisualSetting(VisualParam param, float value) 314 public VisualSetting(VisualParam param, float value)
315 { 315 {
316 VisualParam = param; 316 VisualParam = param;
317 Value = value; 317 Value = value;
318 } 318 }
319 319
320 public VisualSetting(VisualParam param) 320 public VisualSetting(VisualParam param)
321 { 321 {
322 VisualParam = param; 322 VisualParam = param;
323 Value = param.DefaultValue; 323 Value = param.DefaultValue;
324 } 324 }
325 } 325 }
326 #endregion 326 #endregion
327 } 327 }
328} 328}