refactor: replace LSL_Api.InventoryKey(string) largely with SceneObjectPartInventory.GetInventoryItem(string)

Also gets llStopAnimation() to call KeyOrName rather than duplicating logic.
0.7.4.1
Justin Clark-Casey (justincc) 2012-05-26 00:36:01 +01:00
parent 120f8145fc
commit ff53add54d
3 changed files with 42 additions and 45 deletions

View File

@ -163,6 +163,19 @@ namespace OpenSim.Region.Framework.Interfaces
/// </returns>
List<TaskInventoryItem> GetInventoryItems();
/// <summary>
/// Gets an inventory item by name
/// </summary>
/// <remarks>
/// This method returns the first inventory item that matches the given name. In SL this is all you need
/// since each item in a prim inventory must have a unique name.
/// </remarks>
/// <param name='name'></param>
/// <returns>
/// The inventory item. Null if no such item was found.
/// </returns>
TaskInventoryItem GetInventoryItem(string name);
/// <summary>
/// Get inventory items by name.
/// </summary>

View File

@ -582,14 +582,20 @@ namespace OpenSim.Region.Framework.Scenes
return item;
}
/// <summary>
/// Get inventory items by name.
/// </summary>
/// <param name="name"></param>
/// <returns>
/// A list of inventory items with that name.
/// If no inventory item has that name then an empty list is returned.
/// </returns>
public TaskInventoryItem GetInventoryItem(string name)
{
lock (m_items)
{
foreach (TaskInventoryItem item in m_items.Values)
{
if (item.Name == name)
return item;
}
}
return null;
}
public List<TaskInventoryItem> GetInventoryItems(string name)
{
List<TaskInventoryItem> items = new List<TaskInventoryItem>();

View File

@ -104,8 +104,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected int m_scriptConsoleChannel = 0;
protected bool m_scriptConsoleChannelEnabled = false;
protected IUrlModule m_UrlModule = null;
protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
new Dictionary<UUID, UserInfoCacheEntry>();
protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
@ -304,25 +303,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return UUID.Zero;
}
protected UUID InventoryKey(string name)
{
m_host.AddScriptLPS(1);
lock (m_host.TaskInventory)
{
foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
{
if (inv.Value.Name == name)
{
return inv.Value.AssetID;
}
}
}
return UUID.Zero;
}
/// <summary>
/// accepts a valid UUID, -or- a name of an inventory item.
/// Returns a valid UUID or UUID.Zero if key invalid and item not found
@ -332,19 +312,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
/// <returns></returns>
protected UUID KeyOrName(string k)
{
UUID key = UUID.Zero;
UUID key;
// if we can parse the string as a key, use it.
if (UUID.TryParse(k, out key))
{
return key;
}
// else try to locate the name in inventory of object. found returns key,
// not found returns UUID.Zero which will translate to the default particle texture
else
// not found returns UUID.Zero
if (!UUID.TryParse(k, out key))
{
return InventoryKey(k);
TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
if (item != null)
key = item.AssetID;
else
key = UUID.Zero;
}
return key;
}
// convert a LSL_Rotation to a Quaternion
@ -3315,17 +3298,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
{
UUID animID = new UUID();
if (!UUID.TryParse(anim, out animID))
{
animID = InventoryKey(anim);
}
ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
if (presence != null)
{
UUID animID = KeyOrName(anim);
if (animID == UUID.Zero)
presence.Animator.RemoveAnimation(anim);
else