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 | |
parent | Thanks StrawberryFride, for a patch that fixes MSSQL migration: (diff) | |
download | opensim-SC_OLD-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.zip opensim-SC_OLD-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.tar.gz opensim-SC_OLD-6942eaed5b3d8065ebf01dc465e905ca456c0fa4.tar.bz2 opensim-SC_OLD-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')
8 files changed, 320 insertions, 2 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs index 51ba36c..3345988 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IAvatar.cs | |||
@@ -50,6 +50,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
50 | //// <value> | 50 | //// <value> |
51 | /// Array of worn attachments, empty but not null, if no attachments are worn | 51 | /// Array of worn attachments, empty but not null, if no attachments are worn |
52 | /// </value> | 52 | /// </value> |
53 | IAvatarAttachment[] Attachments { get; } | 53 | |
54 | IAvatarAttachment[] Attachments { get; } | ||
55 | |||
56 | /// <summary> | ||
57 | /// Request to open an url clientside | ||
58 | /// </summary> | ||
59 | void LoadUrl(IObject sender, string message, string url); | ||
54 | } | 60 | } |
55 | } | 61 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IInventoryItem.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IInventoryItem.cs new file mode 100644 index 0000000..7490dda --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IInventoryItem.cs | |||
@@ -0,0 +1,16 @@ | |||
1 | using System; | ||
2 | using OpenMetaverse; | ||
3 | |||
4 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | ||
5 | { | ||
6 | |||
7 | /// <summary> | ||
8 | /// This implements the methods needed to operate on individual inventory items. | ||
9 | /// </summary> | ||
10 | public interface IInventoryItem | ||
11 | { | ||
12 | int Type { get; } | ||
13 | UUID AssetID { get; } | ||
14 | T RetreiveAsset<T>() where T : OpenMetaverse.Asset, new(); | ||
15 | } | ||
16 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IObject.cs index dd9cc29..1be3b71 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IObject.cs | |||
@@ -179,6 +179,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
179 | /// <param name="msg">The message to send to the user</param> | 179 | /// <param name="msg">The message to send to the user</param> |
180 | void Say(string msg); | 180 | void Say(string msg); |
181 | 181 | ||
182 | //// <value> | ||
183 | /// Grants access to the objects inventory | ||
184 | /// </value> | ||
185 | IObjectInventory Inventory { get; } | ||
182 | } | 186 | } |
183 | 187 | ||
184 | public enum PhysicsMaterial | 188 | public enum PhysicsMaterial |
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 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Object/IObjectInventory.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Object/IObjectInventory.cs new file mode 100644 index 0000000..98ac13d --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Object/IObjectInventory.cs | |||
@@ -0,0 +1,17 @@ | |||
1 | |||
2 | using System; | ||
3 | using System.Collections.Generic; | ||
4 | |||
5 | using OpenMetaverse; | ||
6 | |||
7 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Object | ||
8 | { | ||
9 | |||
10 | /// <summary> | ||
11 | /// This implements the methods neccesary to operate on the inventory of an object | ||
12 | /// </summary> | ||
13 | public interface IObjectInventory : IDictionary<UUID, IInventoryItem> | ||
14 | { | ||
15 | IInventoryItem this[string name] { get; } | ||
16 | } | ||
17 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs index a40a0d9..689c70e1d 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs | |||
@@ -301,7 +301,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
301 | get { return this; } | 301 | get { return this; } |
302 | } | 302 | } |
303 | 303 | ||
304 | #region Public Functions | 304 | public IObjectInventory Inventory |
305 | { | ||
306 | get { return new SOPObjectInventory(m_rootScene, GetSOP().TaskInventory); } | ||
307 | } | ||
308 | |||
309 | #region Public Functions | ||
305 | 310 | ||
306 | public void Say(string msg) | 311 | public void Say(string msg) |
307 | { | 312 | { |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObjectInventory.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObjectInventory.cs new file mode 100644 index 0000000..19740bd --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObjectInventory.cs | |||
@@ -0,0 +1,190 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Region.Framework.Scenes; | ||
7 | using OpenMetaverse; | ||
8 | |||
9 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Object | ||
10 | { | ||
11 | |||
12 | |||
13 | public class SOPObjectInventory : IObjectInventory | ||
14 | { | ||
15 | TaskInventoryDictionary m_privateInventory; /// OpenSim's task inventory | ||
16 | Dictionary<UUID, IInventoryItem> m_publicInventory; /// MRM's inventory | ||
17 | Scene m_rootScene; | ||
18 | |||
19 | public SOPObjectInventory(Scene rootScene, TaskInventoryDictionary taskInventory) | ||
20 | { | ||
21 | m_rootScene = rootScene; | ||
22 | m_privateInventory = taskInventory; | ||
23 | m_publicInventory = new Dictionary<UUID, IInventoryItem>(); | ||
24 | } | ||
25 | |||
26 | /// <summary> | ||
27 | /// Fully populate the public dictionary with the contents of the private dictionary | ||
28 | /// </summary> | ||
29 | /// <description> | ||
30 | /// This will only convert those items which hasn't already been converted. ensuring that | ||
31 | /// no items are converted twice, and that any references already in use are maintained. | ||
32 | /// </description> | ||
33 | private void SynchronizeDictionaries() | ||
34 | { | ||
35 | foreach(TaskInventoryItem privateItem in m_privateInventory.Values) | ||
36 | if(!m_publicInventory.ContainsKey(privateItem.ItemID)) | ||
37 | m_publicInventory.Add(privateItem.ItemID, new InventoryItem(m_rootScene, privateItem)); | ||
38 | } | ||
39 | |||
40 | #region IDictionary<UUID, IInventoryItem> implementation | ||
41 | public void Add (UUID key, IInventoryItem value) | ||
42 | { | ||
43 | m_publicInventory.Add(key, value); | ||
44 | m_privateInventory.Add(key, InventoryItem.FromInterface(value).ToTaskInventoryItem()); | ||
45 | } | ||
46 | |||
47 | public bool ContainsKey (UUID key) | ||
48 | { | ||
49 | return m_privateInventory.ContainsKey(key); | ||
50 | } | ||
51 | |||
52 | public bool Remove (UUID key) | ||
53 | { | ||
54 | m_publicInventory.Remove(key); | ||
55 | return m_privateInventory.Remove(key); | ||
56 | } | ||
57 | |||
58 | public bool TryGetValue (UUID key, out IInventoryItem value) | ||
59 | { | ||
60 | value = null; | ||
61 | |||
62 | bool result = false; | ||
63 | if(!m_publicInventory.TryGetValue(key, out value)) | ||
64 | { | ||
65 | // wasn't found in the public inventory | ||
66 | TaskInventoryItem privateItem; | ||
67 | |||
68 | result = m_privateInventory.TryGetValue(key, out privateItem); | ||
69 | if(result) | ||
70 | { | ||
71 | value = new InventoryItem(m_rootScene, privateItem); | ||
72 | m_publicInventory.Add(key, value); // add item, so we don't convert again | ||
73 | } | ||
74 | } else | ||
75 | return true; | ||
76 | |||
77 | return result; | ||
78 | } | ||
79 | |||
80 | public ICollection<UUID> Keys { | ||
81 | get { | ||
82 | return m_privateInventory.Keys; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public ICollection<IInventoryItem> Values { | ||
87 | get { | ||
88 | SynchronizeDictionaries(); | ||
89 | return m_publicInventory.Values; | ||
90 | } | ||
91 | } | ||
92 | #endregion | ||
93 | |||
94 | #region IEnumerable<KeyValuePair<UUID, IInventoryItem>> implementation | ||
95 | public IEnumerator<KeyValuePair<UUID, IInventoryItem>> GetEnumerator () | ||
96 | { | ||
97 | SynchronizeDictionaries(); | ||
98 | return m_publicInventory.GetEnumerator(); | ||
99 | } | ||
100 | |||
101 | #endregion | ||
102 | |||
103 | #region IEnumerable implementation | ||
104 | IEnumerator IEnumerable.GetEnumerator () | ||
105 | { | ||
106 | SynchronizeDictionaries(); | ||
107 | return m_publicInventory.GetEnumerator(); | ||
108 | } | ||
109 | |||
110 | #endregion | ||
111 | |||
112 | #region ICollection<KeyValuePair<UUID, IInventoryItem>> implementation | ||
113 | public void Add (KeyValuePair<UUID, IInventoryItem> item) | ||
114 | { | ||
115 | Add(item.Key, item.Value); | ||
116 | } | ||
117 | |||
118 | public void Clear () | ||
119 | { | ||
120 | m_publicInventory.Clear(); | ||
121 | m_privateInventory.Clear(); | ||
122 | } | ||
123 | |||
124 | public bool Contains (KeyValuePair<UUID, IInventoryItem> item) | ||
125 | { | ||
126 | return m_privateInventory.ContainsKey(item.Key); | ||
127 | } | ||
128 | |||
129 | public void CopyTo (KeyValuePair<UUID, IInventoryItem>[] array, int arrayIndex) | ||
130 | { | ||
131 | throw new NotImplementedException(); | ||
132 | } | ||
133 | |||
134 | public bool Remove (KeyValuePair<UUID, IInventoryItem> item) | ||
135 | { | ||
136 | return Remove(item.Key); | ||
137 | } | ||
138 | |||
139 | public int Count { | ||
140 | get { | ||
141 | return m_privateInventory.Count; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | public bool IsReadOnly { | ||
146 | get { | ||
147 | return false; | ||
148 | } | ||
149 | } | ||
150 | #endregion | ||
151 | |||
152 | #region Explicit implementations | ||
153 | IInventoryItem System.Collections.Generic.IDictionary<UUID, IInventoryItem>.this[UUID key] | ||
154 | { | ||
155 | get { | ||
156 | IInventoryItem result; | ||
157 | if(TryGetValue(key, out result)) | ||
158 | return result; | ||
159 | else | ||
160 | throw new KeyNotFoundException("[MRM] The requrested item ID could not be found"); | ||
161 | } | ||
162 | set { | ||
163 | m_publicInventory[key] = value; | ||
164 | m_privateInventory[key] = InventoryItem.FromInterface(value).ToTaskInventoryItem(); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<UUID, IInventoryItem>>.CopyTo(System.Collections.Generic.KeyValuePair<UUID,IInventoryItem>[] array, int offset) | ||
169 | { | ||
170 | throw new NotImplementedException(); | ||
171 | } | ||
172 | #endregion | ||
173 | |||
174 | public IInventoryItem this[string name] | ||
175 | { | ||
176 | get { | ||
177 | foreach(TaskInventoryItem i in m_privateInventory.Values) | ||
178 | if(i.Name == name) | ||
179 | { | ||
180 | if(!m_publicInventory.ContainsKey(i.ItemID)) | ||
181 | m_publicInventory.Add(i.ItemID, new InventoryItem(m_rootScene, i)); | ||
182 | |||
183 | return m_publicInventory[i.ItemID]; | ||
184 | } | ||
185 | throw new KeyNotFoundException(); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | } | ||
190 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs index 6fd36bf..a71d1e5 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs | |||
@@ -32,6 +32,7 @@ using System.Collections.Generic; | |||
32 | 32 | ||
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Region.Framework.Scenes; | 34 | using OpenSim.Region.Framework.Scenes; |
35 | using OpenSim.Region.Framework.Interfaces; | ||
35 | 36 | ||
36 | using log4net; | 37 | using log4net; |
37 | 38 | ||
@@ -90,6 +91,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
90 | return attachments.ToArray(); | 91 | return attachments.ToArray(); |
91 | } | 92 | } |
92 | } | 93 | } |
94 | |||
95 | public void LoadUrl(IObject sender, string message, string url) | ||
96 | { | ||
97 | IDialogModule dm = m_rootScene.RequestModuleInterface<IDialogModule>(); | ||
98 | if(dm != null) | ||
99 | dm.SendUrlToUser(GetSP().UUID, sender.Name, sender.GlobalID, GetSP().UUID, false, message, url); | ||
100 | } | ||
93 | #endregion | 101 | #endregion |
94 | } | 102 | } |
95 | } | 103 | } |