From 1b69714c44c0357f7858bc36a417a870a623aafa Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Sun, 6 Jul 2008 13:08:52 +0000
Subject: * minor: documentation in SceneObjectPart.Inventory.cs. Refactor
AddInventoryItem methods to reduce code duplication
---
.../Scenes/SceneObjectPart.Inventory.cs | 73 +++++++++++++---------
1 file changed, 45 insertions(+), 28 deletions(-)
(limited to 'OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs')
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
index 27b00ee..fea131e 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -90,6 +90,10 @@ namespace OpenSim.Region.Environment.Scenes
}
}
+ ///
+ /// Change every item in this prim's inventory to a new owner.
+ ///
+ ///
public void ChangeInventoryOwner(LLUUID ownerId)
{
lock (TaskInventory)
@@ -122,8 +126,7 @@ namespace OpenSim.Region.Environment.Scenes
{
foreach (TaskInventoryItem item in m_taskInventory.Values)
{
- // XXX more hardcoding badness. Should be an enum in TaskInventoryItem
- if (10 == item.Type)
+ if ((int)InventoryType.LSL == item.InvType)
{
CreateScriptInstance(item, startParam, postOnRez);
}
@@ -140,7 +143,7 @@ namespace OpenSim.Region.Environment.Scenes
{
foreach (TaskInventoryItem item in m_taskInventory.Values)
{
- if (10 == item.Type)
+ if ((int)InventoryType.LSL == item.InvType)
{
RemoveScriptInstance(item.ItemID);
RemoveScriptEvents(item.ItemID);
@@ -154,7 +157,6 @@ namespace OpenSim.Region.Environment.Scenes
///
///
///
-
public void CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez)
{
// m_log.InfoFormat(
@@ -200,7 +202,6 @@ namespace OpenSim.Region.Environment.Scenes
if (m_taskInventory.ContainsKey(itemId))
{
CreateScriptInstance(m_taskInventory[itemId], startParam, postOnRez);
-
}
else
{
@@ -232,7 +233,12 @@ namespace OpenSim.Region.Environment.Scenes
}
}
- // Assumes a lock is held on the inventory
+ ///
+ /// Check if the inventory holds an item with a given name.
+ /// This method assumes that the task inventory is already locked.
+ ///
+ ///
+ ///
private bool InventoryContainsName(string name)
{
foreach (TaskInventoryItem item in m_taskInventory.Values)
@@ -243,6 +249,12 @@ namespace OpenSim.Region.Environment.Scenes
return false;
}
+ ///
+ /// For a given item name, return that name if it is available. Otherwise, return the next available
+ /// similar name (which is currently the original name with the next available numeric suffix).
+ ///
+ ///
+ ///
private string FindAvailableInventoryName(string name)
{
if (!InventoryContainsName(name))
@@ -260,49 +272,54 @@ namespace OpenSim.Region.Environment.Scenes
}
///
- /// Add an item to this prim's inventory.
+ /// Add an item to this prim's inventory. If an item with the same name already exists, then an alternative
+ /// name is chosen.
///
///
public void AddInventoryItem(TaskInventoryItem item)
{
- item.ParentID = UUID;
- item.ParentPartID = UUID;
-
string name = FindAvailableInventoryName(item.Name);
if (name == String.Empty)
return;
- item.Name=name;
-
- lock (m_taskInventory)
- {
- m_taskInventory.Add(item.ItemID, item);
- TriggerScriptChangedEvent(Changed.INVENTORY);
- }
-
- m_inventorySerial++;
- //m_inventorySerial += 2;
- HasInventoryChanged = true;
- ParentGroup.HasGroupChanged = true;
+ AddInventoryItem(name, item);
}
+ ///
+ /// Add an item to this prim's inventory. If an item with the same name already exists, it is replaced.
+ ///
+ ///
public void AddInventoryItemExclusive(TaskInventoryItem item)
{
- item.ParentID = UUID;
- item.ParentPartID = UUID;
-
List il = new List(m_taskInventory.Values);
foreach(TaskInventoryItem i in il)
{
- if(i.Name == item.Name)
+ if (i.Name == item.Name)
{
- if(i.Type == 10)
+ if (i.InvType == (int)InventoryType.LSL)
RemoveScriptInstance(i.ItemID);
+
RemoveInventoryItem(i.ItemID);
break;
}
}
+ AddInventoryItem(item.Name, item);
+ }
+
+ ///
+ /// Add an item to this prim's inventory.
+ ///
+ /// The name that the new item should have.
+ ///
+ /// The item itself. The name within this structure is ignored in favour of the name
+ /// given in this method's arguments
+ ///
+ protected void AddInventoryItem(string name, TaskInventoryItem item)
+ {
+ item.ParentID = UUID;
+ item.ParentPartID = UUID;
+
lock (m_taskInventory)
{
m_taskInventory.Add(item.ItemID, item);
@@ -312,7 +329,7 @@ namespace OpenSim.Region.Environment.Scenes
m_inventorySerial++;
//m_inventorySerial += 2;
HasInventoryChanged = true;
- ParentGroup.HasGroupChanged = true;
+ ParentGroup.HasGroupChanged = true;
}
///
--
cgit v1.1