mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-10 03:35:42 +00:00
Add target object to object builder
Assign all properties in ApplyChanges
This commit is contained in:
parent
61bafac567
commit
a9a613f424
@ -53,7 +53,7 @@ public class VirtualParadiseModelObject : VirtualParadiseObject
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
|
||||
var builder = new VirtualParadiseModelObjectBuilder(Client, ObjectBuilderMode.Modify);
|
||||
var builder = new VirtualParadiseModelObjectBuilder(Client, this, ObjectBuilderMode.Modify);
|
||||
await Task.Run(() => action(builder)).ConfigureAwait(false);
|
||||
|
||||
lock (Client.Lock)
|
||||
|
@ -11,8 +11,12 @@ namespace VpSharp.Entities;
|
||||
/// </summary>
|
||||
public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBuilder
|
||||
{
|
||||
internal VirtualParadiseModelObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
||||
: base(client, mode)
|
||||
internal VirtualParadiseModelObjectBuilder(
|
||||
VirtualParadiseClient client,
|
||||
VirtualParadiseModelObject targetObject,
|
||||
ObjectBuilderMode mode
|
||||
)
|
||||
: base(client, targetObject, mode)
|
||||
{
|
||||
}
|
||||
|
||||
@ -106,21 +110,11 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
||||
internal void ApplyChanges()
|
||||
{
|
||||
nint handle = Client.NativeInstanceHandle;
|
||||
var targetObject = (VirtualParadiseModelObject)TargetObject;
|
||||
|
||||
if (Action is { } action)
|
||||
{
|
||||
vp_string_set(handle, StringAttribute.ObjectAction, action);
|
||||
}
|
||||
|
||||
if (Description is { } description)
|
||||
{
|
||||
vp_string_set(handle, StringAttribute.ObjectDescription, description);
|
||||
}
|
||||
|
||||
if (Model is { } model)
|
||||
{
|
||||
vp_string_set(handle, StringAttribute.ObjectModel, model);
|
||||
}
|
||||
vp_string_set(handle, StringAttribute.ObjectModel, Model ?? targetObject.Model);
|
||||
vp_string_set(handle, StringAttribute.ObjectDescription, Description ?? targetObject.Description);
|
||||
vp_string_set(handle, StringAttribute.ObjectAction, Action ?? targetObject.Action);
|
||||
|
||||
if (Position is { } position)
|
||||
{
|
||||
@ -133,6 +127,13 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
||||
{
|
||||
throw new ArgumentException("Position must be assigned when creating a new object.");
|
||||
}
|
||||
else
|
||||
{
|
||||
(double x, double y, double z) = targetObject.Location.Position;
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectX, x);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectY, y);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectZ, z);
|
||||
}
|
||||
|
||||
if (Rotation is null && Mode == ObjectBuilderMode.Create)
|
||||
{
|
||||
@ -154,6 +155,14 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationZ, z);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationAngle, angle);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObject.Location.Rotation.ToAxisAngle(out Vector3 axis, out float angle);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationX, axis.X);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationY, axis.Y);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationZ, axis.Z);
|
||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationAngle, angle);
|
||||
}
|
||||
|
||||
if (ModificationTimestamp is { } modificationTimestamp)
|
||||
{
|
||||
@ -164,6 +173,10 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
||||
|
||||
_ = vp_int_set(handle, IntegerAttribute.ObjectTime, (int)modificationTimestamp.ToUnixTimeSeconds());
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = vp_int_set(handle, IntegerAttribute.ObjectTime, (int)targetObject.ModificationTimestamp.ToUnixTimeSeconds());
|
||||
}
|
||||
|
||||
if (Owner is { } owner)
|
||||
{
|
||||
@ -174,5 +187,9 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
||||
|
||||
_ = vp_int_set(handle, IntegerAttribute.ObjectUserId, owner.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = vp_int_set(handle, IntegerAttribute.ObjectUserId, targetObject.Owner.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,20 @@ namespace VpSharp.Entities;
|
||||
/// </summary>
|
||||
public abstract class VirtualParadiseObjectBuilder
|
||||
{
|
||||
private protected VirtualParadiseObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
||||
private protected VirtualParadiseObjectBuilder(
|
||||
VirtualParadiseClient client,
|
||||
VirtualParadiseObject targetObject,
|
||||
ObjectBuilderMode mode
|
||||
)
|
||||
{
|
||||
Client = client;
|
||||
TargetObject = targetObject;
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
private protected VirtualParadiseClient Client { get; }
|
||||
|
||||
private protected ObjectBuilderMode Mode { get; }
|
||||
|
||||
private protected VirtualParadiseObject TargetObject { get; }
|
||||
}
|
||||
|
@ -14,8 +14,12 @@ namespace VpSharp.Entities;
|
||||
/// </summary>
|
||||
public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadiseObjectBuilder
|
||||
{
|
||||
internal VirtualParadiseParticleEmitterObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
||||
: base(client, mode)
|
||||
internal VirtualParadiseParticleEmitterObjectBuilder(
|
||||
VirtualParadiseClient client,
|
||||
VirtualParadiseParticleEmitterObject targetObject,
|
||||
ObjectBuilderMode mode
|
||||
)
|
||||
: base(client, targetObject, mode)
|
||||
{
|
||||
}
|
||||
|
||||
@ -201,14 +205,14 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
||||
/// </summary>
|
||||
/// <value>The tag, or <see langword="null" /> to leave unchanged.</value>
|
||||
[SerializationKey("tag")]
|
||||
public string Tag { get; set; }
|
||||
public string? Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the texture.
|
||||
/// </summary>
|
||||
/// <value>The texture, or <see langword="null" /> to leave unchanged.</value>
|
||||
[SerializationKey("texture")]
|
||||
public string Texture { get; set; }
|
||||
public string? Texture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum volume.
|
||||
@ -460,7 +464,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
||||
/// </summary>
|
||||
/// <param name="value">The tag, or <see langword="null" /> to leave unchanged.</param>
|
||||
/// <returns>The current instance.</returns>
|
||||
public VirtualParadiseParticleEmitterObjectBuilder WithTag(string value)
|
||||
public VirtualParadiseParticleEmitterObjectBuilder WithTag(string? value)
|
||||
{
|
||||
Tag = value;
|
||||
return this;
|
||||
@ -471,7 +475,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
||||
/// </summary>
|
||||
/// <param name="value">The texture, or <see langword="null" /> to leave unchanged.</param>
|
||||
/// <returns>The current instance.</returns>
|
||||
public VirtualParadiseParticleEmitterObjectBuilder WithTexture(string value)
|
||||
public VirtualParadiseParticleEmitterObjectBuilder WithTexture(string? value)
|
||||
{
|
||||
Texture = value;
|
||||
return this;
|
||||
|
Loading…
Reference in New Issue
Block a user