Skip to content

Commit

Permalink
Preliminary Settings Asset/Inventory support
Browse files Browse the repository at this point in the history
  • Loading branch information
cinderblocks committed Jul 5, 2024
1 parent 00a1447 commit 07e6683
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
8 changes: 5 additions & 3 deletions LibreMetaverse.Types/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ public enum InventoryType : sbyte
Landmark = 3,
/*
/// <summary>Script</summary>
//[Obsolete("See LSL")] Script = 4,
[Obsolete("See LSL")] Script = 4,
/// <summary>Clothing</summary>
//[Obsolete("See Wearable")] Clothing = 5,
[Obsolete("See Wearable")] Clothing = 5,
*/
/// <summary>Object, both single and coalesced</summary>
*/
Object = 6,
/// <summary>Notecard</summary>
Notecard = 7,
Expand Down Expand Up @@ -265,6 +265,8 @@ public enum InventoryType : sbyte

/// <summary></summary>
Mesh = 22,
/// <summary></summary>
Settings = 23,
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions LibreMetaverse/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,9 @@ public Asset CreateAssetWrapper(AssetType type)
case AssetType.CallingCard:
asset = new AssetCallingCard();
break;
case AssetType.Settings:
asset = new AssetSettings();
break;
default:
asset = new AssetMutable(type);
Logger.Log("Unimplemented asset type: " + type, Helpers.LogLevel.Error);
Expand Down
75 changes: 75 additions & 0 deletions LibreMetaverse/Assets/AssetTypes/AssetSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024, Sjofn LLC
* All rights reserved.
*
* - Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Neither the name of the openmetaverse.co nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

using OpenMetaverse.StructuredData;

namespace OpenMetaverse.Assets
{
public class AssetSettings : Asset
{
public override AssetType AssetType => AssetType.Settings;

public OSD Settings;

/// <summary>Initializes a new instance of an AssetSettings object</summary>
public AssetSettings() { }

/// <summary>
/// Construct an Asset object of type Settings
/// </summary>
/// <param name="assetId">A unique <see cref="UUID"/> specific to this asset</param>
/// <param name="assetData">A byte array containing the raw asset data</param>
public AssetSettings(UUID assetId, byte[] assetData)
: base(assetId, assetData)
{
Decode();
}

public override void Encode()
{
AssetData = Utils.StringToBytes(Settings.AsString());
}

public sealed override bool Decode()
{
if (AssetData != null && AssetData.Length > 0)
{
try
{
var raw = Utils.BytesToString(AssetData);
Settings = OSD.FromString(raw);
return true;
}
catch
{
return false;
}
}

return false;
}
}
}
23 changes: 23 additions & 0 deletions LibreMetaverse/InventoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,29 @@ public InventoryGesture(SerializationInfo info, StreamingContext ctxt)
}
}

/// <inheritdoc />
/// <summary>
/// InventorySettings, LLSD settings blob as an asset
/// </summary>
[Serializable]
public class InventorySettings : InventoryItem
{
/// <summary>
/// Construct an InventorySettings object
/// </summary>
/// <param name="itemID">A <seealso cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects AssetUUID</param>
public InventorySettings(UUID itemID) : base(itemID)
{
InventoryType = InventoryType.Settings;
}

public InventorySettings(SerializationInfo info, StreamingContext ctxt) : base(info, ctxt)
{
InventoryType = InventoryType.Settings;
}
}

/// <inheritdoc />
/// <summary>
/// A folder contains <seealso cref="T:OpenMetaverse.InventoryItem" />s and has certain attributes specific
Expand Down
1 change: 1 addition & 0 deletions LibreMetaverse/InventoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,7 @@ public static InventoryItem CreateInventoryItem(InventoryType type, UUID id)
case InventoryType.Wearable: return new InventoryWearable(id);
case InventoryType.Animation: return new InventoryAnimation(id);
case InventoryType.Gesture: return new InventoryGesture(id);
case InventoryType.Settings: return new InventorySettings(id);
default: return new InventoryItem(type, id);
}
}
Expand Down

0 comments on commit 07e6683

Please sign in to comment.