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