1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-09 22:55:42 +00:00

Extract updated properties after modifying object

This commit is contained in:
Oliver Booth 2022-12-06 13:28:16 +00:00
parent 7422a663af
commit c58fe6a2a3
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 68 additions and 1 deletions

View File

@ -82,6 +82,34 @@ public class VirtualParadiseModelObject : VirtualParadiseObject
{
throw new VirtualParadiseException(result);
}
ExtractFromBuilder(builder);
}
/// <inheritdoc />
protected internal override void ExtractFromBuilder(VirtualParadiseObjectBuilder builder)
{
if (builder is not VirtualParadiseModelObjectBuilder modelObjectBuilder)
{
return;
}
base.ExtractFromBuilder(builder);
if (modelObjectBuilder.Model.HasValue)
{
Model = modelObjectBuilder.Model.Value!;
}
if (modelObjectBuilder.Description.HasValue)
{
Description = modelObjectBuilder.Description.Value!;
}
if (modelObjectBuilder.Action.HasValue)
{
Action = modelObjectBuilder.Action.Value!;
}
}
/// <inheritdoc />

View File

@ -1,6 +1,5 @@
using System.Numerics;
using VpSharp.Exceptions;
using VpSharp.Extensions;
using VpSharp.Internal;
using VpSharp.Internal.NativeAttributes;
using X10D.Numerics;
@ -232,6 +231,46 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
return $"Object {Id}; Owner {Owner}; Location {Location}";
}
/// <summary>
/// Updates the object by extracting the values provided by a specified <see cref="VirtualParadiseObjectBuilder" />.
/// </summary>
/// <param name="builder">The builder whose values to extract.</param>
protected internal virtual void ExtractFromBuilder(VirtualParadiseObjectBuilder builder)
{
ArgumentNullException.ThrowIfNull(builder);
Location location = Location;
Vector3d position = location.Position;
Quaternion rotation = location.Rotation;
if (builder.Position.HasValue)
{
position = builder.Position.Value;
}
if (builder.Rotation.HasValue)
{
rotation = builder.Rotation.Value;
}
Location = new Location(location.World, position, rotation);
if (builder.Data.HasValue)
{
Data = builder.Data.Value!.ToArray();
}
if (builder.ModificationTimestamp.HasValue)
{
ModificationTimestamp = builder.ModificationTimestamp.Value;
}
if (builder.Owner.HasValue)
{
Owner = builder.Owner.Value!;
}
}
/// <summary>
/// Copies the properties from another object into this object.
/// </summary>