From b529750548b74ae16c5b2e0f5393e2ef87626d50 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 9 Apr 2009 11:09:24 +0000 Subject: * Moves Name, GlobalID and WorldPosition into new IEntity interface. * Avatar and Object now inherit from IEntity. * Avatar.Position is now Avatar.WorldPosition to match IObject property. * Implements event World.OnChat += delegate(IWorld sender, ChatEventArgs e); --- .../Scripting/Minimodule/IAvatar.cs | 6 +- .../Scripting/Minimodule/IObject.cs | 18 +---- .../OptionalModules/Scripting/Minimodule/IWorld.cs | 12 ++++ .../Scripting/Minimodule/SPAvatar.cs | 5 +- .../OptionalModules/Scripting/Minimodule/World.cs | 79 ++++++++++++++++++++++ 5 files changed, 98 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/OptionalModules') diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs index a500154..fef85dd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs @@ -32,10 +32,8 @@ using OpenMetaverse; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - public interface IAvatar + public interface IAvatar : IEntity { - string Name { get; } - UUID GlobalID { get; } - Vector3 Position { get; } + } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs index fd62328..dc2e3fa 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs @@ -48,7 +48,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public delegate void OnTouchDelegate(IObject sender, TouchEventArgs e); - public interface IObject + public interface IObject : IEntity { #region Events @@ -92,17 +92,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule uint LocalID { get; } /// - /// The global 'world-unique' ID for this object. - /// (Note, may not actually be world unique) - /// - UUID GlobalID { get; } - - /// - /// The name of this Object. - /// - String Name { get; set; } - - /// /// The description assigned to this object. /// String Description { get; set; } @@ -141,11 +130,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule Quaternion OffsetRotation { get; set; } /// - /// The position of the object relative to the Scene - /// - Vector3 WorldPosition { get; set; } - - /// /// The position of the object relative to a parent object /// If root, works the same as WorldPosition /// diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs index b35b57d..e7d9024 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs @@ -25,13 +25,25 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; + namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { + public class ChatEventArgs : EventArgs + { + public string Text; + public IEntity Sender; + } + + public delegate void OnChatDelegate(IWorld sender, ChatEventArgs e); + public interface IWorld { IObjectAccessor Objects { get; } IAvatar[] Avatars { get; } IParcel[] Parcels { get; } IHeightmap Terrain { get; } + + event OnChatDelegate OnChat; } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs index 25b547c..41074c3 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System; using OpenMetaverse; using OpenSim.Region.Framework.Scenes; @@ -49,6 +50,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public string Name { get { return GetSP().Name; } + set { throw new InvalidOperationException("Avatar Names are a read-only property."); } } public UUID GlobalID @@ -56,9 +58,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule get { return m_ID; } } - public Vector3 Position + public Vector3 WorldPosition { get { return GetSP().AbsolutePosition; } + set { GetSP().AbsolutePosition = value; } } } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs index 05a6a84..e3553bf 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs @@ -26,6 +26,7 @@ */ using System.Collections.Generic; +using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -45,6 +46,84 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule m_objs = new ObjectAccessor(m_internalScene); } + #region Events + + #region OnChat + private event OnChatDelegate _OnChat; + private bool _OnChatActive; + + public event OnChatDelegate OnChat + { + add + { + if (!_OnChatActive) + { + _OnChatActive = true; + m_internalScene.EventManager.OnChatFromClient += EventManager_OnChatFromClient; + m_internalScene.EventManager.OnChatFromWorld += EventManager_OnChatFromWorld; + } + + _OnChat += value; + } + remove + { + _OnChat -= value; + + if (_OnChat == null) + { + _OnChatActive = false; + m_internalScene.EventManager.OnChatFromClient -= EventManager_OnChatFromClient; + m_internalScene.EventManager.OnChatFromWorld -= EventManager_OnChatFromWorld; + } + } + } + + void EventManager_OnChatFromWorld(object sender, OpenSim.Framework.OSChatMessage chat) + { + if (_OnChat != null) + { + HandleChatPacket(chat); + return; + } + } + + private void HandleChatPacket(OSChatMessage chat) + { + // Object? + if (chat.Sender == null && chat.SenderObject != null) + { + ChatEventArgs e = new ChatEventArgs(); + e.Sender = new SOPObject(m_internalScene, ((SceneObjectPart) chat.SenderObject).LocalId); + e.Text = chat.Message; + + _OnChat(this, e); + return; + } + // Avatar? + if (chat.SenderObject != null && chat.SenderObject == null) + { + ChatEventArgs e = new ChatEventArgs(); + e.Sender = new SPAvatar(m_internalScene, chat.SenderUUID); + e.Text = chat.Message; + + _OnChat(this, e); + return; + } + // Skip if other + } + + void EventManager_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage chat) + { + if (_OnChat != null) + { + HandleChatPacket(chat); + return; + } + } + #endregion + + #endregion + public IObjectAccessor Objects { get { return m_objs; } -- cgit v1.1