diff options
author | Justin Clark-Casey (justincc) | 2013-02-06 01:17:19 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-02-06 01:17:19 +0000 |
commit | 5c94346bd7fd218ede591182b045aeb4a57b108e (patch) | |
tree | f83bd890581a0cda00c6e0a24407f149d0981460 /OpenSim/Region/ScriptEngine/Shared/Api | |
parent | * the root prim was being given an OffsetPosition in addition to setting the ... (diff) | |
download | opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.zip opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.gz opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.bz2 opensim-SC_OLD-5c94346bd7fd218ede591182b045aeb4a57b108e.tar.xz |
refactor: Move functions that lookup asset ids from task inventory or pass them through to ScriptUtils class in OpenSim.Region.Framework.dll
Renames functions to better reflect what they do.
This is so that code registering with modInvoke() can reuse this code to provide functions that behave in a consistent manner with existing LSL/OSSL functions.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 104 |
1 files changed, 15 insertions, 89 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 0db6fe3..4fa3c60 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -45,6 +45,7 @@ using OpenSim.Region.CoreModules.World.Terrain; | |||
45 | using OpenSim.Region.Framework.Interfaces; | 45 | using OpenSim.Region.Framework.Interfaces; |
46 | using OpenSim.Region.Framework.Scenes; | 46 | using OpenSim.Region.Framework.Scenes; |
47 | using OpenSim.Region.Framework.Scenes.Animation; | 47 | using OpenSim.Region.Framework.Scenes.Animation; |
48 | using OpenSim.Region.Framework.Scenes.Scripting; | ||
48 | using OpenSim.Region.Physics.Manager; | 49 | using OpenSim.Region.Physics.Manager; |
49 | using OpenSim.Region.ScriptEngine.Shared; | 50 | using OpenSim.Region.ScriptEngine.Shared; |
50 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | 51 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; |
@@ -333,79 +334,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
333 | } | 334 | } |
334 | } | 335 | } |
335 | 336 | ||
336 | protected UUID InventoryKey(string name, int type) | ||
337 | { | ||
338 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name); | ||
339 | |||
340 | if (item != null && item.Type == type) | ||
341 | return item.AssetID; | ||
342 | else | ||
343 | return UUID.Zero; | ||
344 | } | ||
345 | |||
346 | /// <summary> | ||
347 | /// accepts a valid UUID, -or- a name of an inventory item. | ||
348 | /// Returns a valid UUID or UUID.Zero if key invalid and item not found | ||
349 | /// in prim inventory. | ||
350 | /// </summary> | ||
351 | /// <param name="k"></param> | ||
352 | /// <returns></returns> | ||
353 | protected UUID KeyOrName(string k) | ||
354 | { | ||
355 | UUID key; | ||
356 | |||
357 | // if we can parse the string as a key, use it. | ||
358 | // else try to locate the name in inventory of object. found returns key, | ||
359 | // not found returns UUID.Zero | ||
360 | if (!UUID.TryParse(k, out key)) | ||
361 | { | ||
362 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); | ||
363 | |||
364 | if (item != null) | ||
365 | key = item.AssetID; | ||
366 | else | ||
367 | key = UUID.Zero; | ||
368 | } | ||
369 | |||
370 | return key; | ||
371 | } | ||
372 | |||
373 | /// <summary> | ||
374 | /// Return the UUID of the asset matching the specified key or name | ||
375 | /// and asset type. | ||
376 | /// </summary> | ||
377 | /// <param name="k"></param> | ||
378 | /// <param name="type"></param> | ||
379 | /// <returns></returns> | ||
380 | protected UUID KeyOrName(string k, AssetType type) | ||
381 | { | ||
382 | UUID key; | ||
383 | |||
384 | if (!UUID.TryParse(k, out key)) | ||
385 | { | ||
386 | TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); | ||
387 | if (item != null && item.Type == (int)type) | ||
388 | key = item.AssetID; | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | lock (m_host.TaskInventory) | ||
393 | { | ||
394 | foreach (KeyValuePair<UUID, TaskInventoryItem> item in m_host.TaskInventory) | ||
395 | { | ||
396 | if (item.Value.Type == (int)type && item.Value.Name == k) | ||
397 | { | ||
398 | key = item.Value.ItemID; | ||
399 | break; | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | |||
405 | |||
406 | return key; | ||
407 | } | ||
408 | |||
409 | //These are the implementations of the various ll-functions used by the LSL scripts. | 337 | //These are the implementations of the various ll-functions used by the LSL scripts. |
410 | public LSL_Float llSin(double f) | 338 | public LSL_Float llSin(double f) |
411 | { | 339 | { |
@@ -1816,7 +1744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1816 | { | 1744 | { |
1817 | UUID textureID = new UUID(); | 1745 | UUID textureID = new UUID(); |
1818 | 1746 | ||
1819 | textureID = InventoryKey(texture, (int)AssetType.Texture); | 1747 | textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture); |
1820 | if (textureID == UUID.Zero) | 1748 | if (textureID == UUID.Zero) |
1821 | { | 1749 | { |
1822 | if (!UUID.TryParse(texture, out textureID)) | 1750 | if (!UUID.TryParse(texture, out textureID)) |
@@ -2450,7 +2378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2450 | if (m_SoundModule != null) | 2378 | if (m_SoundModule != null) |
2451 | { | 2379 | { |
2452 | m_SoundModule.SendSound(m_host.UUID, | 2380 | m_SoundModule.SendSound(m_host.UUID, |
2453 | KeyOrName(sound, AssetType.Sound), volume, false, 0, | 2381 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0, |
2454 | 0, false, false); | 2382 | 0, false, false); |
2455 | } | 2383 | } |
2456 | } | 2384 | } |
@@ -2460,7 +2388,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2460 | m_host.AddScriptLPS(1); | 2388 | m_host.AddScriptLPS(1); |
2461 | if (m_SoundModule != null) | 2389 | if (m_SoundModule != null) |
2462 | { | 2390 | { |
2463 | m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), | 2391 | m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), |
2464 | volume, 20, false); | 2392 | volume, 20, false); |
2465 | } | 2393 | } |
2466 | } | 2394 | } |
@@ -2470,7 +2398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2470 | m_host.AddScriptLPS(1); | 2398 | m_host.AddScriptLPS(1); |
2471 | if (m_SoundModule != null) | 2399 | if (m_SoundModule != null) |
2472 | { | 2400 | { |
2473 | m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), | 2401 | m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), |
2474 | volume, 20, true); | 2402 | volume, 20, true); |
2475 | } | 2403 | } |
2476 | } | 2404 | } |
@@ -2492,7 +2420,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2492 | if (m_SoundModule != null) | 2420 | if (m_SoundModule != null) |
2493 | { | 2421 | { |
2494 | m_SoundModule.SendSound(m_host.UUID, | 2422 | m_SoundModule.SendSound(m_host.UUID, |
2495 | KeyOrName(sound, AssetType.Sound), volume, false, 0, | 2423 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0, |
2496 | 0, true, false); | 2424 | 0, true, false); |
2497 | } | 2425 | } |
2498 | } | 2426 | } |
@@ -2504,7 +2432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2504 | if (m_SoundModule != null) | 2432 | if (m_SoundModule != null) |
2505 | { | 2433 | { |
2506 | m_SoundModule.SendSound(m_host.UUID, | 2434 | m_SoundModule.SendSound(m_host.UUID, |
2507 | KeyOrName(sound, AssetType.Sound), volume, true, 0, 0, | 2435 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0, |
2508 | false, false); | 2436 | false, false); |
2509 | } | 2437 | } |
2510 | } | 2438 | } |
@@ -2521,7 +2449,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2521 | { | 2449 | { |
2522 | m_host.AddScriptLPS(1); | 2450 | m_host.AddScriptLPS(1); |
2523 | if (m_SoundModule != null) | 2451 | if (m_SoundModule != null) |
2524 | m_SoundModule.PreloadSound(m_host.UUID, KeyOrName(sound), 0); | 2452 | m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0); |
2525 | ScriptSleep(1000); | 2453 | ScriptSleep(1000); |
2526 | } | 2454 | } |
2527 | 2455 | ||
@@ -3352,7 +3280,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3352 | if (presence != null) | 3280 | if (presence != null) |
3353 | { | 3281 | { |
3354 | // Do NOT try to parse UUID, animations cannot be triggered by ID | 3282 | // Do NOT try to parse UUID, animations cannot be triggered by ID |
3355 | UUID animID = InventoryKey(anim, (int)AssetType.Animation); | 3283 | UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation); |
3356 | if (animID == UUID.Zero) | 3284 | if (animID == UUID.Zero) |
3357 | presence.Animator.AddAnimation(anim, m_host.UUID); | 3285 | presence.Animator.AddAnimation(anim, m_host.UUID); |
3358 | else | 3286 | else |
@@ -3374,7 +3302,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
3374 | 3302 | ||
3375 | if (presence != null) | 3303 | if (presence != null) |
3376 | { | 3304 | { |
3377 | UUID animID = KeyOrName(anim); | 3305 | UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim); |
3378 | 3306 | ||
3379 | if (animID == UUID.Zero) | 3307 | if (animID == UUID.Zero) |
3380 | presence.Animator.RemoveAnimation(anim); | 3308 | presence.Animator.RemoveAnimation(anim); |
@@ -4319,7 +4247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4319 | 4247 | ||
4320 | private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) | 4248 | private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) |
4321 | { | 4249 | { |
4322 | UUID assetID = KeyOrName(destination); | 4250 | UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination); |
4323 | 4251 | ||
4324 | // The destinaion is not an asset ID and also doesn't name a landmark. | 4252 | // The destinaion is not an asset ID and also doesn't name a landmark. |
4325 | // Use it as a sim name | 4253 | // Use it as a sim name |
@@ -4386,7 +4314,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4386 | m_host.AddScriptLPS(1); | 4314 | m_host.AddScriptLPS(1); |
4387 | 4315 | ||
4388 | // TODO: Parameter check logic required. | 4316 | // TODO: Parameter check logic required. |
4389 | m_host.CollisionSound = KeyOrName(impact_sound, AssetType.Sound); | 4317 | m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); |
4390 | m_host.CollisionSoundVolume = (float)impact_volume; | 4318 | m_host.CollisionSoundVolume = (float)impact_volume; |
4391 | } | 4319 | } |
4392 | 4320 | ||
@@ -5912,7 +5840,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5912 | if (m_SoundModule != null) | 5840 | if (m_SoundModule != null) |
5913 | { | 5841 | { |
5914 | m_SoundModule.TriggerSoundLimited(m_host.UUID, | 5842 | m_SoundModule.TriggerSoundLimited(m_host.UUID, |
5915 | KeyOrName(sound, AssetType.Sound), volume, | 5843 | ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, |
5916 | bottom_south_west, top_north_east); | 5844 | bottom_south_west, top_north_east); |
5917 | } | 5845 | } |
5918 | } | 5846 | } |
@@ -6346,7 +6274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6346 | break; | 6274 | break; |
6347 | 6275 | ||
6348 | case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: | 6276 | case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: |
6349 | prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); | 6277 | prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1)); |
6350 | break; | 6278 | break; |
6351 | 6279 | ||
6352 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: | 6280 | case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: |
@@ -7269,9 +7197,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7269 | UUID sculptId; | 7197 | UUID sculptId; |
7270 | 7198 | ||
7271 | if (!UUID.TryParse(map, out sculptId)) | 7199 | if (!UUID.TryParse(map, out sculptId)) |
7272 | { | 7200 | sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture); |
7273 | sculptId = InventoryKey(map, (int)AssetType.Texture); | ||
7274 | } | ||
7275 | 7201 | ||
7276 | if (sculptId == UUID.Zero) | 7202 | if (sculptId == UUID.Zero) |
7277 | return; | 7203 | return; |