diff options
author | Justin Clark-Casey (justincc) | 2013-02-06 01:17:19 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-02-06 01:17:19 +0000 |
commit | 5c94346bd7fd218ede591182b045aeb4a57b108e (patch) | |
tree | f83bd890581a0cda00c6e0a24407f149d0981460 /OpenSim/Region/Framework | |
parent | * the root prim was being given an OffsetPosition in addition to setting the ... (diff) | |
download | opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.zip opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.gz opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.bz2 opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.xz |
refactor: Move functions that lookup asset ids from task inventory or pass them through to ScriptUtils class in OpenSim.Region.Framework.dll
Renames functions to better reflect what they do.
This is so that code registering with modInvoke() can reuse this code to provide functions that behave in a consistent manner with existing LSL/OSSL functions.
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs new file mode 100644 index 0000000..d8aa258 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs | |||
@@ -0,0 +1,122 @@ | |||
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 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Region.Framework.Scenes.Scripting | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Utility functions for use by scripts manipulating the scene. | ||
37 | /// </summary> | ||
38 | public static class ScriptUtils | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Get an asset id given an item name and an item type. | ||
42 | /// </summary> | ||
43 | /// <returns>UUID.Zero if the name and type did not match any item.</returns> | ||
44 | /// <param name='part'></param> | ||
45 | /// <param name='name'></param> | ||
46 | /// <param name='type'></param> | ||
47 | public static UUID GetAssetIdFromItemName(SceneObjectPart part, string name, int type) | ||
48 | { | ||
49 | TaskInventoryItem item = part.Inventory.GetInventoryItem(name); | ||
50 | |||
51 | if (item != null && item.Type == type) | ||
52 | return item.AssetID; | ||
53 | else | ||
54 | return UUID.Zero; | ||
55 | } | ||
56 | |||
57 | /// <summary> | ||
58 | /// accepts a valid UUID, -or- a name of an inventory item. | ||
59 | /// Returns a valid UUID or UUID.Zero if key invalid and item not found | ||
60 | /// in prim inventory. | ||
61 | /// </summary> | ||
62 | /// <param name="part">Scene object part to search for inventory item</param> | ||
63 | /// <param name="key"></param> | ||
64 | /// <returns></returns> | ||
65 | public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier) | ||
66 | { | ||
67 | UUID key; | ||
68 | |||
69 | // if we can parse the string as a key, use it. | ||
70 | // else try to locate the name in inventory of object. found returns key, | ||
71 | // not found returns UUID.Zero | ||
72 | if (!UUID.TryParse(identifier, out key)) | ||
73 | { | ||
74 | TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); | ||
75 | |||
76 | if (item != null) | ||
77 | key = item.AssetID; | ||
78 | else | ||
79 | key = UUID.Zero; | ||
80 | } | ||
81 | |||
82 | return key; | ||
83 | } | ||
84 | |||
85 | |||
86 | /// <summary> | ||
87 | /// Return the UUID of the asset matching the specified key or name | ||
88 | /// and asset type. | ||
89 | /// </summary> | ||
90 | /// <param name="part">Scene object part to search for inventory item</param> | ||
91 | /// <param name="identifier"></param> | ||
92 | /// <param name="type"></param> | ||
93 | /// <returns></returns> | ||
94 | public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier, AssetType type) | ||
95 | { | ||
96 | UUID key; | ||
97 | |||
98 | if (!UUID.TryParse(identifier, out key)) | ||
99 | { | ||
100 | TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); | ||
101 | if (item != null && item.Type == (int)type) | ||
102 | key = item.AssetID; | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | lock (part.TaskInventory) | ||
107 | { | ||
108 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in part.TaskInventory) | ||
109 | { | ||
110 | if (item.Value.Type == (int)type && item.Value.Name == identifier) | ||
111 | { | ||
112 | key = item.Value.ItemID; | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | |||
119 | return key; | ||
120 | } | ||
121 | } | ||
122 | } \ No newline at end of file | ||