diff options
author | Justin Clark-Casey (justincc) | 2011-08-09 22:05:47 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-08-09 22:05:47 +0100 |
commit | 795c8e6c22d4174d942ad56e70a0acbe507e2ec7 (patch) | |
tree | b5eef28c55c1eeeb9d20c52d320de6f1037880bd /OpenSim/Region/ScriptEngine/Shared | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-795c8e6c22d4174d942ad56e70a0acbe507e2ec7.zip opensim-SC_OLD-795c8e6c22d4174d942ad56e70a0acbe507e2ec7.tar.gz opensim-SC_OLD-795c8e6c22d4174d942ad56e70a0acbe507e2ec7.tar.bz2 opensim-SC_OLD-795c8e6c22d4174d942ad56e70a0acbe507e2ec7.tar.xz |
Add osOwnerSaveAppearance() to help with setting up NPC appearances. Not yet ready for user use.
Adds regression test.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
4 files changed, 153 insertions, 10 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 07b36de..a05c623 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -2147,14 +2147,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2147 | return new LSL_Key(UUID.Zero.ToString()); | 2147 | return new LSL_Key(UUID.Zero.ToString()); |
2148 | } | 2148 | } |
2149 | 2149 | ||
2150 | /// <summary> | ||
2151 | /// Save the current appearance of the NPC permanently to the named notecard. | ||
2152 | /// </summary> | ||
2153 | /// <param name="avatar"></param> | ||
2154 | /// <param name="notecardName">The name of the notecard to which to save the appearance.</param> | ||
2155 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2150 | public LSL_Key osNpcSaveAppearance(string avatar, string notecardName) | 2156 | public LSL_Key osNpcSaveAppearance(string avatar, string notecardName) |
2151 | { | 2157 | { |
2152 | CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance"); | 2158 | CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance"); |
2153 | 2159 | ||
2154 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | 2160 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); |
2155 | IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>(); | ||
2156 | 2161 | ||
2157 | if (npcModule != null && appearanceModule != null) | 2162 | if (npcModule != null) |
2158 | { | 2163 | { |
2159 | UUID avatarId = UUID.Zero; | 2164 | UUID avatarId = UUID.Zero; |
2160 | if (!UUID.TryParse(avatar, out avatarId)) | 2165 | if (!UUID.TryParse(avatar, out avatarId)) |
@@ -2163,14 +2168,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2163 | if (!npcModule.IsNPC(avatarId, m_host.ParentGroup.Scene)) | 2168 | if (!npcModule.IsNPC(avatarId, m_host.ParentGroup.Scene)) |
2164 | return new LSL_Key(UUID.Zero.ToString()); | 2169 | return new LSL_Key(UUID.Zero.ToString()); |
2165 | 2170 | ||
2166 | appearanceModule.SaveBakedTextures(avatarId); | 2171 | return SaveAppearanceToNotecard(avatarId, notecardName); |
2167 | ScenePresence sp = m_host.ParentGroup.Scene.GetScenePresence(avatarId); | ||
2168 | OSDMap appearancePacked = sp.Appearance.Pack(); | ||
2169 | |||
2170 | TaskInventoryItem item | ||
2171 | = SaveNotecard(notecardName, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); | ||
2172 | |||
2173 | return new LSL_Key(item.AssetID.ToString()); | ||
2174 | } | 2172 | } |
2175 | 2173 | ||
2176 | return new LSL_Key(UUID.Zero.ToString()); | 2174 | return new LSL_Key(UUID.Zero.ToString()); |
@@ -2236,6 +2234,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2236 | module.DeleteNPC(new UUID(npc.m_string), World); | 2234 | module.DeleteNPC(new UUID(npc.m_string), World); |
2237 | } | 2235 | } |
2238 | } | 2236 | } |
2237 | |||
2238 | /// <summary> | ||
2239 | /// Save the current appearance of the script owner permanently to the named notecard. | ||
2240 | /// </summary> | ||
2241 | /// <param name="notecardName">The name of the notecard to which to save the appearance.</param> | ||
2242 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2243 | public LSL_Key osOwnerSaveAppearance(string notecardName) | ||
2244 | { | ||
2245 | CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance"); | ||
2246 | |||
2247 | return SaveAppearanceToNotecard(m_host.OwnerID, notecardName); | ||
2248 | } | ||
2249 | |||
2250 | protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecardName) | ||
2251 | { | ||
2252 | IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>(); | ||
2253 | |||
2254 | if (appearanceModule != null) | ||
2255 | { | ||
2256 | appearanceModule.SaveBakedTextures(m_host.OwnerID); | ||
2257 | ScenePresence sp = m_host.ParentGroup.Scene.GetScenePresence(m_host.OwnerID); | ||
2258 | OSDMap appearancePacked = sp.Appearance.Pack(); | ||
2259 | |||
2260 | TaskInventoryItem item | ||
2261 | = SaveNotecard(notecardName, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); | ||
2262 | |||
2263 | return new LSL_Key(item.AssetID.ToString()); | ||
2264 | } | ||
2265 | else | ||
2266 | { | ||
2267 | return new LSL_Key(UUID.Zero.ToString()); | ||
2268 | } | ||
2269 | } | ||
2239 | 2270 | ||
2240 | /// <summary> | 2271 | /// <summary> |
2241 | /// Get current region's map texture UUID | 2272 | /// Get current region's map texture UUID |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 868af27..92473ae 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -176,6 +176,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
176 | void osNpcSay(key npc, string message); | 176 | void osNpcSay(key npc, string message); |
177 | void osNpcRemove(key npc); | 177 | void osNpcRemove(key npc); |
178 | 178 | ||
179 | LSL_Key osOwnerSaveAppearance(string notecardName); | ||
180 | |||
179 | key osGetMapTexture(); | 181 | key osGetMapTexture(); |
180 | key osGetRegionMapTexture(string regionName); | 182 | key osGetRegionMapTexture(string regionName); |
181 | LSL_List osGetRegionStats(); | 183 | LSL_List osGetRegionStats(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 959b5d5..4b21c88 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -508,6 +508,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
508 | m_OSSL_Functions.osNpcRemove(npc); | 508 | m_OSSL_Functions.osNpcRemove(npc); |
509 | } | 509 | } |
510 | 510 | ||
511 | public LSL_Key osOwnerSaveAppearance(string notecardName) | ||
512 | { | ||
513 | return m_OSSL_Functions.osOwnerSaveAppearance(notecardName); | ||
514 | } | ||
515 | |||
511 | public OSSLPrim Prim; | 516 | public OSSLPrim Prim; |
512 | 517 | ||
513 | [Serializable] | 518 | [Serializable] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs new file mode 100644 index 0000000..fc8b551 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.Assets; | ||
35 | using OpenMetaverse.StructuredData; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.ScriptEngine.Shared; | ||
40 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | using OpenSim.Tests.Common.Mock; | ||
44 | |||
45 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// Tests for OSSL_Api | ||
49 | /// </summary> | ||
50 | [TestFixture] | ||
51 | public class OSSL_ApiAppearanceTest | ||
52 | { | ||
53 | [Test] | ||
54 | public void TestOsOwnerSaveAppearance() | ||
55 | { | ||
56 | TestHelpers.InMethod(); | ||
57 | // log4net.Config.XmlConfigurator.Configure(); | ||
58 | |||
59 | IConfigSource initConfigSource = new IniConfigSource(); | ||
60 | IConfig config = initConfigSource.AddConfig("XEngine"); | ||
61 | config.Set("Enabled", "true"); | ||
62 | config.Set("AllowOSFunctions", "true"); | ||
63 | config.Set("OSFunctionThreatLevel", "Severe"); | ||
64 | |||
65 | UUID userId = TestHelpers.ParseTail(0x1); | ||
66 | float newHeight = 1.9f; | ||
67 | |||
68 | Scene scene = SceneHelpers.SetupScene(); | ||
69 | SceneHelpers.SetupSceneModules(scene, new AvatarFactoryModule()); | ||
70 | ScenePresence sp = SceneHelpers.AddScenePresence(scene, userId); | ||
71 | sp.Appearance.AvatarHeight = newHeight; | ||
72 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
73 | SceneObjectPart part = so.RootPart; | ||
74 | scene.AddSceneObject(so); | ||
75 | |||
76 | XEngine.XEngine engine = new XEngine.XEngine(); | ||
77 | engine.Initialise(initConfigSource); | ||
78 | engine.AddRegion(scene); | ||
79 | |||
80 | OSSL_Api osslApi = new OSSL_Api(); | ||
81 | osslApi.Initialize(engine, part, part.LocalId, part.UUID); | ||
82 | |||
83 | string notecardName = "appearanceNc"; | ||
84 | |||
85 | osslApi.osOwnerSaveAppearance(notecardName); | ||
86 | |||
87 | IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName); | ||
88 | Assert.That(items.Count, Is.EqualTo(1)); | ||
89 | |||
90 | TaskInventoryItem ncItem = items[0]; | ||
91 | Assert.That(ncItem.Name, Is.EqualTo(notecardName)); | ||
92 | |||
93 | AssetBase ncAsset = scene.AssetService.Get(ncItem.AssetID.ToString()); | ||
94 | Assert.That(ncAsset, Is.Not.Null); | ||
95 | |||
96 | AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data); | ||
97 | anc.Decode(); | ||
98 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText); | ||
99 | AvatarAppearance savedAppearance = new AvatarAppearance(); | ||
100 | savedAppearance.Unpack(appearanceOsd); | ||
101 | |||
102 | Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight)); | ||
103 | } | ||
104 | } | ||
105 | } \ No newline at end of file | ||