diff options
author | Charles Krinke | 2009-06-29 21:47:47 +0000 |
---|---|---|
committer | Charles Krinke | 2009-06-29 21:47:47 +0000 |
commit | 6942eaed5b3d8065ebf01dc465e905ca456c0fa4 (patch) | |
tree | ba35780085d13474160ea9a39d2a83b5e401f6a4 /OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs | |
parent | Thanks StrawberryFride, for a patch that fixes MSSQL migration: (diff) | |
download | opensim-SC-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.zip opensim-SC-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.tar.gz opensim-SC-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.tar.bz2 opensim-SC-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.tar.xz |
Thank you kindly, Snowdrop, for a patch that solves:
The current API for MRM is quite sparse, this patch
supplies basic support for accessing the task
inventory of object.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/Minimodule/InventoryItem.cs')
-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 | } | ||