mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-23 00:18:46 +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);
|
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);
|
await Task.Run(() => action(builder)).ConfigureAwait(false);
|
||||||
|
|
||||||
lock (Client.Lock)
|
lock (Client.Lock)
|
||||||
|
@ -11,8 +11,12 @@ namespace VpSharp.Entities;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBuilder
|
public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBuilder
|
||||||
{
|
{
|
||||||
internal VirtualParadiseModelObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
internal VirtualParadiseModelObjectBuilder(
|
||||||
: base(client, mode)
|
VirtualParadiseClient client,
|
||||||
|
VirtualParadiseModelObject targetObject,
|
||||||
|
ObjectBuilderMode mode
|
||||||
|
)
|
||||||
|
: base(client, targetObject, mode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,21 +110,11 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
|||||||
internal void ApplyChanges()
|
internal void ApplyChanges()
|
||||||
{
|
{
|
||||||
nint handle = Client.NativeInstanceHandle;
|
nint handle = Client.NativeInstanceHandle;
|
||||||
|
var targetObject = (VirtualParadiseModelObject)TargetObject;
|
||||||
|
|
||||||
if (Action is { } action)
|
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);
|
vp_string_set(handle, StringAttribute.ObjectAction, Action ?? targetObject.Action);
|
||||||
}
|
|
||||||
|
|
||||||
if (Description is { } description)
|
|
||||||
{
|
|
||||||
vp_string_set(handle, StringAttribute.ObjectDescription, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Model is { } model)
|
|
||||||
{
|
|
||||||
vp_string_set(handle, StringAttribute.ObjectModel, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Position is { } position)
|
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.");
|
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)
|
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.ObjectRotationZ, z);
|
||||||
_ = vp_double_set(handle, FloatAttribute.ObjectRotationAngle, angle);
|
_ = 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)
|
if (ModificationTimestamp is { } modificationTimestamp)
|
||||||
{
|
{
|
||||||
@ -164,6 +173,10 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
|||||||
|
|
||||||
_ = vp_int_set(handle, IntegerAttribute.ObjectTime, (int)modificationTimestamp.ToUnixTimeSeconds());
|
_ = vp_int_set(handle, IntegerAttribute.ObjectTime, (int)modificationTimestamp.ToUnixTimeSeconds());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ = vp_int_set(handle, IntegerAttribute.ObjectTime, (int)targetObject.ModificationTimestamp.ToUnixTimeSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
if (Owner is { } owner)
|
if (Owner is { } owner)
|
||||||
{
|
{
|
||||||
@ -174,5 +187,9 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
|
|||||||
|
|
||||||
_ = vp_int_set(handle, IntegerAttribute.ObjectUserId, owner.Id);
|
_ = 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>
|
/// </summary>
|
||||||
public abstract class VirtualParadiseObjectBuilder
|
public abstract class VirtualParadiseObjectBuilder
|
||||||
{
|
{
|
||||||
private protected VirtualParadiseObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
private protected VirtualParadiseObjectBuilder(
|
||||||
|
VirtualParadiseClient client,
|
||||||
|
VirtualParadiseObject targetObject,
|
||||||
|
ObjectBuilderMode mode
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Client = client;
|
Client = client;
|
||||||
|
TargetObject = targetObject;
|
||||||
Mode = mode;
|
Mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private protected VirtualParadiseClient Client { get; }
|
private protected VirtualParadiseClient Client { get; }
|
||||||
|
|
||||||
private protected ObjectBuilderMode Mode { get; }
|
private protected ObjectBuilderMode Mode { get; }
|
||||||
|
|
||||||
|
private protected VirtualParadiseObject TargetObject { get; }
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,12 @@ namespace VpSharp.Entities;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadiseObjectBuilder
|
public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadiseObjectBuilder
|
||||||
{
|
{
|
||||||
internal VirtualParadiseParticleEmitterObjectBuilder(VirtualParadiseClient client, ObjectBuilderMode mode)
|
internal VirtualParadiseParticleEmitterObjectBuilder(
|
||||||
: base(client, mode)
|
VirtualParadiseClient client,
|
||||||
|
VirtualParadiseParticleEmitterObject targetObject,
|
||||||
|
ObjectBuilderMode mode
|
||||||
|
)
|
||||||
|
: base(client, targetObject, mode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,14 +205,14 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The tag, or <see langword="null" /> to leave unchanged.</value>
|
/// <value>The tag, or <see langword="null" /> to leave unchanged.</value>
|
||||||
[SerializationKey("tag")]
|
[SerializationKey("tag")]
|
||||||
public string Tag { get; set; }
|
public string? Tag { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the texture.
|
/// Gets or sets the texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The texture, or <see langword="null" /> to leave unchanged.</value>
|
/// <value>The texture, or <see langword="null" /> to leave unchanged.</value>
|
||||||
[SerializationKey("texture")]
|
[SerializationKey("texture")]
|
||||||
public string Texture { get; set; }
|
public string? Texture { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the maximum volume.
|
/// Sets the maximum volume.
|
||||||
@ -460,7 +464,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The tag, or <see langword="null" /> to leave unchanged.</param>
|
/// <param name="value">The tag, or <see langword="null" /> to leave unchanged.</param>
|
||||||
/// <returns>The current instance.</returns>
|
/// <returns>The current instance.</returns>
|
||||||
public VirtualParadiseParticleEmitterObjectBuilder WithTag(string value)
|
public VirtualParadiseParticleEmitterObjectBuilder WithTag(string? value)
|
||||||
{
|
{
|
||||||
Tag = value;
|
Tag = value;
|
||||||
return this;
|
return this;
|
||||||
@ -471,7 +475,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The texture, or <see langword="null" /> to leave unchanged.</param>
|
/// <param name="value">The texture, or <see langword="null" /> to leave unchanged.</param>
|
||||||
/// <returns>The current instance.</returns>
|
/// <returns>The current instance.</returns>
|
||||||
public VirtualParadiseParticleEmitterObjectBuilder WithTexture(string value)
|
public VirtualParadiseParticleEmitterObjectBuilder WithTexture(string? value)
|
||||||
{
|
{
|
||||||
Texture = value;
|
Texture = value;
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user