refactor: Move DetachSingleAttachmentToInv to region module

need to rationalize method names later
slimupdates
Justin Clark-Casey (justincc) 2010-03-06 00:07:47 +00:00
parent e7422fe9b2
commit 395f343498
6 changed files with 82 additions and 78 deletions

View File

@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using System.Reflection;
using log4net;
using Nini.Config;
@ -131,26 +132,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
}
else
{
m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID);
m_log.DebugFormat("[ATTACHMENTS MODULE]: AttachObject found no such scene object {0}", objectLocalID);
return false;
}
return true;
}
/// <summary>
/// Update the user inventory to reflect an attachment
/// </summary>
/// <param name="att"></param>
/// <param name="remoteClient"></param>
/// <param name="itemID"></param>
/// <param name="AttachmentPt"></param>
/// <returns></returns>
}
public UUID SetAttachmentInventoryStatus(
SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
{
m_log.DebugFormat(
"[USER INVENTORY]: Updating inventory of {0} to show attachment of {1} (item ID {2})",
"[ATTACHMENTS MODULEY]: Updating inventory of {0} to show attachment of {1} (item ID {2})",
remoteClient.Name, att.Name, itemID);
if (!att.IsDeleted)
@ -184,19 +177,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (UUID.Zero == itemID)
{
m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
m_log.Error("[ATTACHMENTS MODULE]: Unable to save attachment. Error inventory item ID.");
return;
}
if (0 == AttachmentPt)
{
m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
m_log.Error("[ATTACHMENTS MODULE]: Unable to save attachment. Error attachment point.");
return;
}
if (null == att.RootPart)
{
m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
m_log.Error("[ATTACHMENTS MODULE]: Unable to save attachment for a prim without the rootpart!");
return;
}
@ -212,5 +205,53 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
}
}
public void ShowDetachInUserInventory(UUID itemID, IClientAPI remoteClient)
{
ScenePresence presence;
if (m_scene.TryGetAvatar(remoteClient.AgentId, out presence))
{
presence.Appearance.DetachAttachment(itemID);
// Save avatar attachment information
if (m_scene.AvatarFactory != null)
{
m_log.Debug("[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
}
}
DetachSingleAttachmentToInv(itemID, remoteClient);
}
// What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
// To LocalId or UUID, *THAT* is the question. How now Brown UUID??
protected void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
{
if (itemID == UUID.Zero) // If this happened, someone made a mistake....
return;
// We can NOT use the dictionries here, as we are looking
// for an entity by the fromAssetID, which is NOT the prim UUID
List<EntityBase> detachEntities = m_scene.GetEntities();
SceneObjectGroup group;
foreach (EntityBase entity in detachEntities)
{
if (entity is SceneObjectGroup)
{
group = (SceneObjectGroup)entity;
if (group.GetFromItemID() == itemID)
{
m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero);
group.DetachToInventoryPrep();
m_log.Debug("[ATTACHMENTS MODULE]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString());
m_scene.UpdateKnownItem(remoteClient, group,group.GetFromItemID(), group.OwnerID);
m_scene.DeleteSceneObject(group, false);
return;
}
}
}
}
}
}

View File

@ -57,5 +57,16 @@ namespace OpenSim.Region.Framework.Interfaces
/// <returns></returns>
UUID SetAttachmentInventoryStatus(
SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt);
/// <summary>
/// Update the user inventory to show a detach.
/// </summary>
/// <param name="itemID">
/// A <see cref="UUID"/>
/// </param>
/// <param name="remoteClient">
/// A <see cref="IClientAPI"/>
/// </param>
void ShowDetachInUserInventory(UUID itemID, IClientAPI remoteClient);
}
}

View File

@ -1858,7 +1858,7 @@ namespace OpenSim.Region.Framework.Scenes
if (att == null)
{
DetachSingleAttachmentToInv(itemID, remoteClient);
AttachmentsModule.ShowDetachInUserInventory(itemID, remoteClient);
return UUID.Zero;
}
@ -1904,24 +1904,6 @@ namespace OpenSim.Region.Framework.Scenes
SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
}
public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
{
ScenePresence presence;
if (TryGetAvatar(remoteClient.AgentId, out presence))
{
presence.Appearance.DetachAttachment(itemID);
// Save avatar attachment information
if (m_AvatarFactory != null)
{
m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
}
}
m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
}
public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
{
EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);

View File

@ -2646,10 +2646,12 @@ namespace OpenSim.Region.Framework.Scenes
public virtual void SubscribeToClientAttachmentEvents(IClientAPI client)
{
client.OnRezSingleAttachmentFromInv += RezSingleAttachment;
client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments;
client.OnDetachAttachmentIntoInv += DetachSingleAttachmentToInv;
client.OnRezMultipleAttachmentsFromInv += RezMultipleAttachments;
client.OnObjectAttach += m_sceneGraph.AttachObject;
client.OnObjectDetach += m_sceneGraph.DetachObject;
if (AttachmentsModule != null)
client.OnDetachAttachmentIntoInv += AttachmentsModule.ShowDetachInUserInventory;
}
public virtual void SubscribeToClientTeleportEvents(IClientAPI client)
@ -2696,8 +2698,7 @@ namespace OpenSim.Region.Framework.Scenes
}
protected virtual void UnsubscribeToClientEvents(IClientAPI client)
{
{
}
/// <summary>
@ -2719,7 +2720,6 @@ namespace OpenSim.Region.Framework.Scenes
UnSubscribeToClientNetworkEvents(client);
// EventManager.TriggerOnNewClient(client);
}
@ -2799,12 +2799,14 @@ namespace OpenSim.Region.Framework.Scenes
}
public virtual void UnSubscribeToClientAttachmentEvents(IClientAPI client)
{
client.OnRezSingleAttachmentFromInv -= RezSingleAttachment;
{
client.OnRezMultipleAttachmentsFromInv -= RezMultipleAttachments;
client.OnDetachAttachmentIntoInv -= DetachSingleAttachmentToInv;
client.OnRezSingleAttachmentFromInv -= RezSingleAttachment;
client.OnObjectAttach -= m_sceneGraph.AttachObject;
client.OnObjectDetach -= m_sceneGraph.DetachObject;
if (AttachmentsModule != null)
client.OnDetachAttachmentIntoInv -= AttachmentsModule.ShowDetachInUserInventory;
}
public virtual void UnSubscribeToClientTeleportEvents(IClientAPI client)

View File

@ -452,7 +452,7 @@ namespace OpenSim.Region.Framework.Scenes
if (group != null)
{
//group.DetachToGround();
m_parentScene.DetachSingleAttachmentToInv(group.GetFromItemID(), remoteClient);
m_parentScene.AttachmentsModule.ShowDetachInUserInventory(group.GetFromItemID(), remoteClient);
}
}
@ -574,39 +574,6 @@ namespace OpenSim.Region.Framework.Scenes
return null;
}
// What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
// To LocalId or UUID, *THAT* is the question. How now Brown UUID??
public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
{
if (itemID == UUID.Zero) // If this happened, someone made a mistake....
return;
// We can NOT use the dictionries here, as we are looking
// for an entity by the fromAssetID, which is NOT the prim UUID
//
List<EntityBase> detachEntities = GetEntities();
SceneObjectGroup group;
foreach (EntityBase entity in detachEntities)
{
if (entity is SceneObjectGroup)
{
group = (SceneObjectGroup)entity;
if (group.GetFromItemID() == itemID)
{
m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
group.DetachToInventoryPrep();
m_log.Debug("[DETACH]: Saving attachpoint: " +
((uint)group.GetAttachmentPoint()).ToString());
m_parentScene.UpdateKnownItem(remoteClient, group,
group.GetFromItemID(), group.OwnerID);
m_parentScene.DeleteSceneObject(group, false);
return;
}
}
}
}
protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance)
{
ScenePresence newAvatar = null;

View File

@ -2931,8 +2931,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
m_ScriptEngine.World.DetachSingleAttachmentToInv(itemID,
presence.ControllingClient);
IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
if (attachmentsModule != null)
attachmentsModule.ShowDetachInUserInventory(itemID, presence.ControllingClient);
}
}