diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs new file mode 100644 index 0000000..512a120 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs | |||
@@ -0,0 +1,72 @@ | |||
1 | |||
2 | using System; | ||
3 | using System.Text; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Region.Framework.Scenes; | ||
7 | //using OpenSim.Services.AssetService; | ||
8 | using OpenMetaverse; | ||
9 | |||
10 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | ||
11 | { | ||
12 | |||
13 | |||
14 | public class InventoryItem : IInventoryItem | ||
15 | { | ||
16 | TaskInventoryItem m_privateItem; | ||
17 | Scene m_rootSceene; | ||
18 | |||
19 | public InventoryItem(Scene rootScene, TaskInventoryItem internalItem) | ||
20 | { | ||
21 | m_rootSceene = rootScene; | ||
22 | m_privateItem = internalItem; | ||
23 | } | ||
24 | |||
25 | // Marked internal, to prevent scripts from accessing the internal type | ||
26 | internal TaskInventoryItem ToTaskInventoryItem() | ||
27 | { | ||
28 | return m_privateItem; | ||
29 | } | ||
30 | |||
31 | /// <summary> | ||
32 | /// This will attempt to convert from an IInventoryItem to an InventoryItem object | ||
33 | /// </summary> | ||
34 | /// <description> | ||
35 | /// In order for this to work the object which implements IInventoryItem must inherit from InventoryItem, otherwise | ||
36 | /// an exception is thrown. | ||
37 | /// </description> | ||
38 | /// <param name="i"> | ||
39 | /// The interface to upcast <see cref="IInventoryItem"/> | ||
40 | /// </param> | ||
41 | /// <returns> | ||
42 | /// The object backing the interface implementation <see cref="InventoryItem"/> | ||
43 | /// </returns> | ||
44 | internal static InventoryItem FromInterface(IInventoryItem i) | ||
45 | { | ||
46 | if(typeof(InventoryItem).IsAssignableFrom(i.GetType())) | ||
47 | { | ||
48 | return (InventoryItem)i; | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | throw new ApplicationException("[MRM] There is no legal conversion from IInventoryItem to InventoryItem"); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public int Type { get { return m_privateItem.Type; } } | ||
57 | public UUID AssetID { get { return m_privateItem.AssetID; } } | ||
58 | |||
59 | public T RetreiveAsset<T>() where T : OpenMetaverse.Asset, new() | ||
60 | { | ||
61 | AssetBase a = m_rootSceene.AssetService.Get(AssetID.ToString()); | ||
62 | T result = new T(); | ||
63 | |||
64 | if((sbyte)result.AssetType != a.Type) | ||
65 | throw new ApplicationException("[MRM] The supplied asset class does not match the found asset"); | ||
66 | |||
67 | result.AssetData = a.Data; | ||
68 | result.Decode(); | ||
69 | return result; | ||
70 | } | ||
71 | } | ||
72 | } | ||