add noteCardReader
parent
478a8218b3
commit
74f1401b5a
|
@ -0,0 +1,103 @@
|
|||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenSim.Modules.Appearance2Avatar.helper
|
||||
{
|
||||
class NoteCardReader
|
||||
{
|
||||
private Scene World = null;
|
||||
private SceneObjectPart m_host = null;
|
||||
|
||||
public NoteCardReader(Scene scene, SceneObjectPart host)
|
||||
{
|
||||
World = scene;
|
||||
m_host = host;
|
||||
}
|
||||
|
||||
public string LoadNotecard(string notecardNameOrUuid)
|
||||
{
|
||||
UUID assetID = CacheNotecard(notecardNameOrUuid);
|
||||
|
||||
if (assetID != UUID.Zero)
|
||||
{
|
||||
StringBuilder notecardData = new StringBuilder();
|
||||
|
||||
for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
|
||||
{
|
||||
string line = NotecardCache.GetLine(assetID, count) + "\n";
|
||||
|
||||
// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
|
||||
|
||||
notecardData.Append(line);
|
||||
}
|
||||
|
||||
return notecardData.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
protected UUID CacheNotecard(string notecardNameOrUuid)
|
||||
{
|
||||
UUID assetID = UUID.Zero;
|
||||
|
||||
bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
|
||||
|
||||
if (!notecardNameIsUUID)
|
||||
{
|
||||
assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
|
||||
}
|
||||
|
||||
if (assetID == UUID.Zero)
|
||||
return UUID.Zero;
|
||||
|
||||
if (!NotecardCache.IsCached(assetID))
|
||||
{
|
||||
AssetBase a = World.AssetService.Get(assetID.ToString());
|
||||
|
||||
if (a == null)
|
||||
{
|
||||
// Whoops, it's still possible here that the notecard name was properly
|
||||
// formatted like a UUID but isn't an asset UUID so lets look it up by name after all
|
||||
assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
|
||||
if (assetID == UUID.Zero)
|
||||
return UUID.Zero;
|
||||
|
||||
if (!NotecardCache.IsCached(assetID))
|
||||
{
|
||||
a = World.AssetService.Get(assetID.ToString());
|
||||
|
||||
if (a == null)
|
||||
{
|
||||
return UUID.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotecardCache.Cache(assetID, a.Data);
|
||||
};
|
||||
|
||||
return assetID;
|
||||
}
|
||||
protected UUID SearchTaskInventoryForAssetId(string name)
|
||||
{
|
||||
UUID assetId = UUID.Zero;
|
||||
m_host.TaskInventory.LockItemsForRead(true);
|
||||
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
|
||||
{
|
||||
if (item.Type == 7 && item.Name == name)
|
||||
{
|
||||
assetId = item.AssetID;
|
||||
}
|
||||
}
|
||||
m_host.TaskInventory.LockItemsForRead(false);
|
||||
return assetId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue