1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-22 18:58:48 +00:00

refactor: use Optional nuget instead of custom Optional<> struct

This commit is contained in:
Oliver Booth 2023-05-25 19:40:39 +01:00
parent c824467845
commit 67387f567d
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
8 changed files with 146 additions and 320 deletions

View File

@ -71,6 +71,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1"/> <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1"/>
<PackageReference Include="Optional" Version="4.0.0"/>
<PackageReference Include="System.Drawing.Common" Version="7.0.0"/> <PackageReference Include="System.Drawing.Common" Version="7.0.0"/>
<PackageReference Include="System.Reactive" Version="5.0.0"/> <PackageReference Include="System.Reactive" Version="5.0.0"/>
<PackageReference Include="X10D" Version="3.2.0"/> <PackageReference Include="X10D" Version="3.2.0"/>

View File

@ -96,20 +96,9 @@ public class VirtualParadiseModelObject : VirtualParadiseObject
base.ExtractFromBuilder(builder); base.ExtractFromBuilder(builder);
if (modelObjectBuilder.Model.HasValue) Model = modelObjectBuilder.Model.ValueOr(Model);
{ Description = modelObjectBuilder.Description.ValueOr(Description);
Model = modelObjectBuilder.Model.Value!; Action = modelObjectBuilder.Action.ValueOr(Action);
}
if (modelObjectBuilder.Description.HasValue)
{
Description = modelObjectBuilder.Description.Value!;
}
if (modelObjectBuilder.Action.HasValue)
{
Action = modelObjectBuilder.Action.Value!;
}
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -1,4 +1,5 @@
using VpSharp.Internal; using Optional;
using VpSharp.Internal;
using static VpSharp.Internal.NativeAttributes.StringAttribute; using static VpSharp.Internal.NativeAttributes.StringAttribute;
using static VpSharp.Internal.NativeMethods; using static VpSharp.Internal.NativeMethods;
@ -22,19 +23,19 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
/// Gets or sets the value of this object's <c>Action</c> field. /// Gets or sets the value of this object's <c>Action</c> field.
/// </summary> /// </summary>
/// <value>The value of this object's <c>Action</c> field, or <see langword="default" /> to leave unchanged.</value> /// <value>The value of this object's <c>Action</c> field, or <see langword="default" /> to leave unchanged.</value>
public Optional<string> Action { get; set; } public Option<string> Action { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value of this object's <c>Description</c> field. /// Gets or sets the value of this object's <c>Description</c> field.
/// </summary> /// </summary>
/// <value>The value of this object's <c>Description</c> field, or <see langword="default" /> to leave unchanged.</value> /// <value>The value of this object's <c>Description</c> field, or <see langword="default" /> to leave unchanged.</value>
public Optional<string> Description { get; set; } public Option<string> Description { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value of this object's <c>Model</c> field. /// Gets or sets the value of this object's <c>Model</c> field.
/// </summary> /// </summary>
/// <value>The value of this object's <c>Model</c> field, or <see langword="default" /> to leave unchanged.</value> /// <value>The value of this object's <c>Model</c> field, or <see langword="default" /> to leave unchanged.</value>
public Optional<string> Model { get; set; } public Option<string> Model { get; set; }
internal override void ApplyChanges() internal override void ApplyChanges()
{ {
@ -42,8 +43,8 @@ public sealed class VirtualParadiseModelObjectBuilder : VirtualParadiseObjectBui
nint handle = Client.NativeInstanceHandle; nint handle = Client.NativeInstanceHandle;
var targetObject = (VirtualParadiseModelObject)TargetObject; var targetObject = (VirtualParadiseModelObject)TargetObject;
vp_string_set(handle, ObjectModel, Model.HasValue ? Model.Value! : targetObject.Model); vp_string_set(handle, ObjectModel, Model.ValueOr(targetObject.Model));
vp_string_set(handle, ObjectDescription, Description.HasValue ? Description.Value! : targetObject.Description); vp_string_set(handle, ObjectDescription, Description.ValueOr(targetObject.Description));
vp_string_set(handle, ObjectAction, Action.HasValue ? Action.Value! : targetObject.Action); vp_string_set(handle, ObjectAction, Action.ValueOr(targetObject.Action));
} }
} }

View File

@ -240,35 +240,13 @@ public abstract class VirtualParadiseObject : IEquatable<VirtualParadiseObject>
ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(builder);
Location location = Location; Location location = Location;
Vector3d position = location.Position; Vector3d position = builder.Position.ValueOr(location.Position);
Rotation rotation = location.Rotation; Rotation rotation = builder.Rotation.ValueOr(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); Location = new Location(location.World, position, rotation);
Data = builder.Data.ValueOr(Data).ToArray();
if (builder.Data.HasValue) ModificationTimestamp = builder.ModificationTimestamp.ValueOr(ModificationTimestamp);
{ Owner = builder.Owner.ValueOr(Owner);
Data = builder.Data.Value!.ToArray();
}
if (builder.ModificationTimestamp.HasValue)
{
ModificationTimestamp = builder.ModificationTimestamp.Value;
}
if (builder.Owner.HasValue)
{
Owner = builder.Owner.Value!;
}
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using VpSharp.Internal; using Optional;
using VpSharp.Internal;
using static VpSharp.Internal.NativeAttributes.DataAttribute; using static VpSharp.Internal.NativeAttributes.DataAttribute;
using static VpSharp.Internal.NativeAttributes.FloatAttribute; using static VpSharp.Internal.NativeAttributes.FloatAttribute;
using static VpSharp.Internal.NativeAttributes.IntegerAttribute; using static VpSharp.Internal.NativeAttributes.IntegerAttribute;
@ -32,7 +33,7 @@ public abstract class VirtualParadiseObjectBuilder
/// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at /// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at
/// any other point. /// any other point.
/// </remarks> /// </remarks>
public Optional<DateTimeOffset> ModificationTimestamp { get; set; } public Option<DateTimeOffset> ModificationTimestamp { get; set; }
/// <summary> /// <summary>
/// Gets or sets the owner of this object. /// Gets or sets the owner of this object.
@ -42,21 +43,21 @@ public abstract class VirtualParadiseObjectBuilder
/// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at /// This property may only be set during an object load, and will throw <see cref="InvalidOperationException" /> at
/// any other point. /// any other point.
/// </remarks> /// </remarks>
public Optional<VirtualParadiseUser> Owner { get; set; } public Option<VirtualParadiseUser> Owner { get; set; }
/// <summary> /// <summary>
/// Gets or sets the position of the object. /// Gets or sets the position of the object.
/// </summary> /// </summary>
/// <value>The position of the object, or <see langword="default" /> to leave unchanged.</value> /// <value>The position of the object, or <see langword="default" /> to leave unchanged.</value>
public Optional<Vector3d> Position { get; set; } public Option<Vector3d> Position { get; set; }
/// <summary> /// <summary>
/// Gets or sets the rotation of the object. /// Gets or sets the rotation of the object.
/// </summary> /// </summary>
/// <value>The rotation of the object, or <see langword="default" /> to leave unchanged.</value> /// <value>The rotation of the object, or <see langword="default" /> to leave unchanged.</value>
public Optional<Rotation> Rotation { get; set; } public Option<Rotation> Rotation { get; set; }
internal Optional<IReadOnlyList<byte>> Data { get; set; } internal Option<IReadOnlyList<byte>> Data { get; set; }
private protected VirtualParadiseClient Client { get; } private protected VirtualParadiseClient Client { get; }
@ -76,76 +77,49 @@ public abstract class VirtualParadiseObjectBuilder
private void ApplyData() private void ApplyData()
{ {
nint handle = Client.NativeInstanceHandle; nint handle = Client.NativeInstanceHandle;
if (Data.HasValue) byte[] data = Data.ValueOr(ArraySegment<byte>.Empty).ToArray();
{ _ = vp_data_set(handle, ObjectData, data.Length, data);
IReadOnlyList<byte> data = Data.Value!;
_ = vp_data_set(handle, ObjectData, data.Count, data.ToArray());
}
else
{
_ = vp_data_set(handle, ObjectData, 0, Array.Empty<byte>());
}
} }
private void ApplyOwner() private void ApplyOwner()
{ {
nint handle = Client.NativeInstanceHandle; nint handle = Client.NativeInstanceHandle;
if (Owner.HasValue)
{
if (Mode != ObjectBuilderMode.Load)
{
throw new InvalidOperationException("Owner can only be assigned during an object load.");
}
_ = vp_int_set(handle, ObjectUserId, Owner.Value!.Id); if (Owner.HasValue && Mode != ObjectBuilderMode.Load)
}
else
{ {
_ = vp_int_set(handle, ObjectUserId, TargetObject.Owner.Id); throw new InvalidOperationException("Owner can only be assigned during an object load.");
} }
VirtualParadiseUser oldOwner = TargetObject.Owner;
_ = vp_int_set(handle, ObjectUserId, Owner.ValueOr(oldOwner).Id);
} }
private void ApplyModificationTimestamp() private void ApplyModificationTimestamp()
{ {
nint handle = Client.NativeInstanceHandle; nint handle = Client.NativeInstanceHandle;
if (ModificationTimestamp.HasValue) if (ModificationTimestamp.HasValue && Mode != ObjectBuilderMode.Load)
{ {
if (Mode != ObjectBuilderMode.Load) throw new InvalidOperationException("Modification timestamp can only be assigned during an object load.");
{ }
throw new InvalidOperationException("Modification timestamp can only be assigned during an object load.");
}
_ = vp_int_set(handle, ObjectTime, (int)ModificationTimestamp.Value.ToUnixTimeSeconds()); DateTimeOffset oldTimestamp = TargetObject.ModificationTimestamp;
} _ = vp_int_set(handle, ObjectTime, (int)ModificationTimestamp.ValueOr(oldTimestamp).ToUnixTimeSeconds());
else
{
_ = vp_int_set(handle, ObjectTime, (int)TargetObject.ModificationTimestamp.ToUnixTimeSeconds());
}
} }
private void ApplyPosition() private void ApplyPosition()
{ {
nint handle = Client.NativeInstanceHandle; nint handle = Client.NativeInstanceHandle;
if (Position.HasValue) if (!Position.HasValue && Mode == ObjectBuilderMode.Create)
{
(double x, double y, double z) = Position.Value;
_ = vp_double_set(handle, ObjectX, x);
_ = vp_double_set(handle, ObjectY, y);
_ = vp_double_set(handle, ObjectZ, z);
}
else if (Mode == ObjectBuilderMode.Create)
{ {
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) = Position.ValueOr(TargetObject.Location.Position);
(double x, double y, double z) = TargetObject.Location.Position; _ = vp_double_set(handle, ObjectX, x);
_ = vp_double_set(handle, ObjectX, x); _ = vp_double_set(handle, ObjectY, y);
_ = vp_double_set(handle, ObjectY, y); _ = vp_double_set(handle, ObjectZ, z);
_ = vp_double_set(handle, ObjectZ, z);
}
} }
private void ApplyRotation() private void ApplyRotation()
@ -154,24 +128,13 @@ public abstract class VirtualParadiseObjectBuilder
if (!Rotation.HasValue && Mode == ObjectBuilderMode.Create) if (!Rotation.HasValue && Mode == ObjectBuilderMode.Create)
{ {
Rotation = VpSharp.Rotation.None; Rotation = Option.Some(VpSharp.Rotation.None);
} }
if (Rotation.HasValue) (double x, double y, double z, double angle) = Rotation.ValueOr(TargetObject.Location.Rotation);
{ _ = vp_double_set(handle, ObjectRotationX, x);
(double x, double y, double z, double angle) = Rotation.Value; _ = vp_double_set(handle, ObjectRotationY, y);
_ = vp_double_set(handle, ObjectRotationX, x); _ = vp_double_set(handle, ObjectRotationZ, z);
_ = vp_double_set(handle, ObjectRotationY, y); _ = vp_double_set(handle, ObjectRotationAngle, angle);
_ = vp_double_set(handle, ObjectRotationZ, z);
_ = vp_double_set(handle, ObjectRotationAngle, angle);
}
else
{
(double x, double y, double z, double angle) = TargetObject.Location.Rotation;
_ = vp_double_set(handle, ObjectRotationX, x);
_ = vp_double_set(handle, ObjectRotationY, y);
_ = vp_double_set(handle, ObjectRotationZ, z);
_ = vp_double_set(handle, ObjectRotationAngle, angle);
}
} }
} }

View File

@ -3,6 +3,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
using System.Drawing; using System.Drawing;
using Optional;
using VpSharp.Internal; using VpSharp.Internal;
using VpSharp.Internal.Attributes; using VpSharp.Internal.Attributes;
using VpSharp.Internal.ValueConverters; using VpSharp.Internal.ValueConverters;
@ -29,7 +30,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum acceleration, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum acceleration, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("acceleration_max")] [SerializationKey("acceleration_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> AccelerationMax { get; set; } public Option<Vector3d> AccelerationMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum acceleration. /// Gets or sets the minimum acceleration.
@ -37,7 +38,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum acceleration, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum acceleration, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("acceleration_min")] [SerializationKey("acceleration_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> AccelerationMin { get; set; } public Option<Vector3d> AccelerationMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the blend mode. /// Gets or sets the blend mode.
@ -45,7 +46,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The blend mode, or <see langword="default" /> to leave unchanged.</value> /// <value>The blend mode, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("blend")] [SerializationKey("blend")]
[ValueConverter(typeof(StringToEnumConverter<ParticleBlendMode>))] [ValueConverter(typeof(StringToEnumConverter<ParticleBlendMode>))]
public Optional<ParticleBlendMode> BlendMode { get; set; } public Option<ParticleBlendMode> BlendMode { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum color. /// Gets or sets the maximum color.
@ -53,7 +54,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum color, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum color, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("color_max")] [SerializationKey("color_max")]
[ValueConverter(typeof(HexToColorConverter))] [ValueConverter(typeof(HexToColorConverter))]
public Optional<Color> ColorMax { get; set; } public Option<Color> ColorMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum color. /// Gets or sets the minimum color.
@ -61,7 +62,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum color, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum color, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("color_min")] [SerializationKey("color_min")]
[ValueConverter(typeof(HexToColorConverter))] [ValueConverter(typeof(HexToColorConverter))]
public Optional<Color> ColorMin { get; set; } public Option<Color> ColorMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the emitter lifespan. /// Gets or sets the emitter lifespan.
@ -69,7 +70,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The emitter lifespan, or <see langword="default" /> to leave unchanged.</value> /// <value>The emitter lifespan, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("emitter_lifespan")] [SerializationKey("emitter_lifespan")]
[ValueConverter(typeof(MillisecondToTimeSpanConverter))] [ValueConverter(typeof(MillisecondToTimeSpanConverter))]
public Optional<TimeSpan> EmitterLifespan { get; set; } public Option<TimeSpan> EmitterLifespan { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this emitter interpolates its values. /// Gets or sets a value indicating whether this emitter interpolates its values.
@ -80,14 +81,14 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </value> /// </value>
[SerializationKey("interpolate")] [SerializationKey("interpolate")]
[ValueConverter(typeof(IntToBoolConverter))] [ValueConverter(typeof(IntToBoolConverter))]
public Optional<bool> Interpolate { get; set; } public Option<bool> Interpolate { get; set; }
/// <summary> /// <summary>
/// Gets or sets the opacity. /// Gets or sets the opacity.
/// </summary> /// </summary>
/// <value>The opacity, or <see langword="default" /> to leave unchanged.</value> /// <value>The opacity, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("opacity")] [SerializationKey("opacity")]
public Optional<double> Opacity { get; set; } public Option<double> Opacity { get; set; }
/// <summary> /// <summary>
/// Gets or sets the particle lifespan. /// Gets or sets the particle lifespan.
@ -95,7 +96,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The particle lifespan, or <see langword="default" /> to leave unchanged.</value> /// <value>The particle lifespan, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("particle_lifespan")] [SerializationKey("particle_lifespan")]
[ValueConverter(typeof(MillisecondToTimeSpanConverter))] [ValueConverter(typeof(MillisecondToTimeSpanConverter))]
public Optional<TimeSpan> ParticleLifespan { get; set; } public Option<TimeSpan> ParticleLifespan { get; set; }
/// <summary> /// <summary>
/// Gets or sets the particle type. /// Gets or sets the particle type.
@ -103,14 +104,14 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The particle type, or <see langword="default" /> to leave unchanged.</value> /// <value>The particle type, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("particle_type")] [SerializationKey("particle_type")]
[ValueConverter(typeof(StringToEnumConverter<ParticleType>))] [ValueConverter(typeof(StringToEnumConverter<ParticleType>))]
public Optional<ParticleType> ParticleType { get; set; } public Option<ParticleType> ParticleType { get; set; }
/// <summary> /// <summary>
/// Gets or sets the release count. /// Gets or sets the release count.
/// </summary> /// </summary>
/// <value>The release count, or <see langword="default" /> to leave unchanged.</value> /// <value>The release count, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("release_count")] [SerializationKey("release_count")]
public Optional<int> ReleaseCount { get; set; } public Option<int> ReleaseCount { get; set; }
/// <summary> /// <summary>
/// Gets or sets the release time. /// Gets or sets the release time.
@ -118,7 +119,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The release time, or <see langword="default" /> to leave unchanged.</value> /// <value>The release time, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("release_time")] [SerializationKey("release_time")]
[ValueConverter(typeof(MillisecondToTimeSpanConverter))] [ValueConverter(typeof(MillisecondToTimeSpanConverter))]
public Optional<TimeSpan> ReleaseTime { get; set; } public Option<TimeSpan> ReleaseTime { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum size. /// Gets or sets the maximum size.
@ -126,7 +127,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum size, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum size, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("size_max")] [SerializationKey("size_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SizeMax { get; set; } public Option<Vector3d> SizeMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum size. /// Gets or sets the minimum size.
@ -134,7 +135,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum size, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum size, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("size_min")] [SerializationKey("size_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SizeMin { get; set; } public Option<Vector3d> SizeMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum speed. /// Gets or sets the maximum speed.
@ -142,7 +143,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum speed, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum speed, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("speed_max")] [SerializationKey("speed_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SpeedMax { get; set; } public Option<Vector3d> SpeedMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum speed. /// Gets or sets the minimum speed.
@ -150,7 +151,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum speed, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum speed, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("speed_min")] [SerializationKey("speed_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SpeedMin { get; set; } public Option<Vector3d> SpeedMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum spin. /// Gets or sets the maximum spin.
@ -158,7 +159,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum spin, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum spin, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("spin_max")] [SerializationKey("spin_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SpinMax { get; set; } public Option<Vector3d> SpinMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum spin. /// Gets or sets the minimum spin.
@ -166,7 +167,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum spin, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum spin, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("spin_min")] [SerializationKey("spin_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> SpinMin { get; set; } public Option<Vector3d> SpinMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum start angle. /// Gets or sets the maximum start angle.
@ -174,7 +175,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum start angle, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum start angle, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("start_angle_max")] [SerializationKey("start_angle_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> StartAngleMax { get; set; } public Option<Vector3d> StartAngleMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum start angle. /// Gets or sets the minimum start angle.
@ -182,7 +183,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum start angle, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum start angle, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("start_angle_min")] [SerializationKey("start_angle_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> StartAngleMin { get; set; } public Option<Vector3d> StartAngleMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the maximum volume. /// Gets or sets the maximum volume.
@ -190,7 +191,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The maximum volume, or <see langword="default" /> to leave unchanged.</value> /// <value>The maximum volume, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("volume_max")] [SerializationKey("volume_max")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> VolumeMax { get; set; } public Option<Vector3d> VolumeMax { get; set; }
/// <summary> /// <summary>
/// Gets or sets the minimum volume. /// Gets or sets the minimum volume.
@ -198,28 +199,28 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <value>The minimum volume, or <see langword="default" /> to leave unchanged.</value> /// <value>The minimum volume, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("volume_min")] [SerializationKey("volume_min")]
[ValueConverter(typeof(Vector3dConverter))] [ValueConverter(typeof(Vector3dConverter))]
public Optional<Vector3d> VolumeMin { get; set; } public Option<Vector3d> VolumeMin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the tag. /// Gets or sets the tag.
/// </summary> /// </summary>
/// <value>The tag, or <see langword="default" /> to leave unchanged.</value> /// <value>The tag, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("tag")] [SerializationKey("tag")]
public Optional<string> Tag { get; set; } public Option<string> Tag { get; set; }
/// <summary> /// <summary>
/// Gets or sets the texture. /// Gets or sets the texture.
/// </summary> /// </summary>
/// <value>The texture, or <see langword="default" /> to leave unchanged.</value> /// <value>The texture, or <see langword="default" /> to leave unchanged.</value>
[SerializationKey("texture")] [SerializationKey("texture")]
public Optional<string> Texture { get; set; } public Option<string> Texture { get; set; }
/// <summary> /// <summary>
/// Sets the maximum volume. /// Sets the maximum volume.
/// </summary> /// </summary>
/// <param name="value">The maximum volume, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum volume, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithAccelerationMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithAccelerationMax(Option<Vector3d> value)
{ {
AccelerationMax = value; AccelerationMax = value;
return this; return this;
@ -230,7 +231,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum acceleration, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum acceleration, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithAccelerationMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithAccelerationMin(Option<Vector3d> value)
{ {
AccelerationMin = value; AccelerationMin = value;
return this; return this;
@ -241,7 +242,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The blend mode, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The blend mode, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithBlendMode(Optional<ParticleBlendMode> value) public VirtualParadiseParticleEmitterObjectBuilder WithBlendMode(Option<ParticleBlendMode> value)
{ {
BlendMode = value; BlendMode = value;
return this; return this;
@ -252,7 +253,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum color, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum color, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithColorMax(Optional<Color> value) public VirtualParadiseParticleEmitterObjectBuilder WithColorMax(Option<Color> value)
{ {
ColorMax = value; ColorMax = value;
return this; return this;
@ -263,7 +264,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum color, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum color, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithColorMin(Optional<Color> value) public VirtualParadiseParticleEmitterObjectBuilder WithColorMin(Option<Color> value)
{ {
ColorMin = value; ColorMin = value;
return this; return this;
@ -274,7 +275,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The emitter lifespan, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The emitter lifespan, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithEmitterLifespan(Optional<TimeSpan> value) public VirtualParadiseParticleEmitterObjectBuilder WithEmitterLifespan(Option<TimeSpan> value)
{ {
EmitterLifespan = value; EmitterLifespan = value;
return this; return this;
@ -288,7 +289,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// <see langword="default" /> to leave unchanged. /// <see langword="default" /> to leave unchanged.
/// </param> /// </param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithInterpolation(Optional<bool> value) public VirtualParadiseParticleEmitterObjectBuilder WithInterpolation(Option<bool> value)
{ {
Interpolate = value; Interpolate = value;
return this; return this;
@ -299,7 +300,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The opacity, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The opacity, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithOpacity(Optional<double> value) public VirtualParadiseParticleEmitterObjectBuilder WithOpacity(Option<double> value)
{ {
Opacity = value; Opacity = value;
return this; return this;
@ -310,7 +311,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The particle lifespan, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The particle lifespan, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithParticleLifespan(Optional<TimeSpan> value) public VirtualParadiseParticleEmitterObjectBuilder WithParticleLifespan(Option<TimeSpan> value)
{ {
ParticleLifespan = value; ParticleLifespan = value;
return this; return this;
@ -321,7 +322,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The particle type, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The particle type, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithParticleType(Optional<ParticleType> value) public VirtualParadiseParticleEmitterObjectBuilder WithParticleType(Option<ParticleType> value)
{ {
ParticleType = value; ParticleType = value;
return this; return this;
@ -332,7 +333,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The release count, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The release count, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithReleaseCount(Optional<int> value) public VirtualParadiseParticleEmitterObjectBuilder WithReleaseCount(Option<int> value)
{ {
ReleaseCount = value; ReleaseCount = value;
return this; return this;
@ -343,7 +344,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The release time, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The release time, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithReleaseTime(Optional<TimeSpan> value) public VirtualParadiseParticleEmitterObjectBuilder WithReleaseTime(Option<TimeSpan> value)
{ {
ReleaseTime = value; ReleaseTime = value;
return this; return this;
@ -354,7 +355,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum size, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum size, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSizeMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSizeMax(Option<Vector3d> value)
{ {
SizeMax = value; SizeMax = value;
return this; return this;
@ -365,7 +366,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum size, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum size, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSizeMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSizeMin(Option<Vector3d> value)
{ {
SizeMin = value; SizeMin = value;
return this; return this;
@ -376,7 +377,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum speed, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum speed, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSpeedMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSpeedMax(Option<Vector3d> value)
{ {
SpeedMax = value; SpeedMax = value;
return this; return this;
@ -387,7 +388,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum speed, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum speed, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSpeedMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSpeedMin(Option<Vector3d> value)
{ {
SpeedMin = value; SpeedMin = value;
return this; return this;
@ -398,7 +399,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum spin, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum spin, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSpinMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSpinMax(Option<Vector3d> value)
{ {
SpinMax = value; SpinMax = value;
return this; return this;
@ -409,7 +410,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum spin, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum spin, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithSpinMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithSpinMin(Option<Vector3d> value)
{ {
SpinMin = value; SpinMin = value;
return this; return this;
@ -420,7 +421,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum start angle, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum start angle, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithStartAngleMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithStartAngleMax(Option<Vector3d> value)
{ {
StartAngleMax = value; StartAngleMax = value;
return this; return this;
@ -431,7 +432,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum start angle, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum start angle, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithStartAngleMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithStartAngleMin(Option<Vector3d> value)
{ {
StartAngleMin = value; StartAngleMin = value;
return this; return this;
@ -442,7 +443,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The maximum volume, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The maximum volume, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithVolumeMax(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithVolumeMax(Option<Vector3d> value)
{ {
VolumeMax = value; VolumeMax = value;
return this; return this;
@ -453,7 +454,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The minimum volume, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The minimum volume, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithVolumeMin(Optional<Vector3d> value) public VirtualParadiseParticleEmitterObjectBuilder WithVolumeMin(Option<Vector3d> value)
{ {
VolumeMin = value; VolumeMin = value;
return this; return this;
@ -464,7 +465,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The tag, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The tag, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithTag(Optional<string> value) public VirtualParadiseParticleEmitterObjectBuilder WithTag(Option<string> value)
{ {
Tag = value; Tag = value;
return this; return this;
@ -475,7 +476,7 @@ public sealed class VirtualParadiseParticleEmitterObjectBuilder : VirtualParadis
/// </summary> /// </summary>
/// <param name="value">The texture, or <see langword="default" /> to leave unchanged.</param> /// <param name="value">The texture, or <see langword="default" /> to leave unchanged.</param>
/// <returns>The current instance.</returns> /// <returns>The current instance.</returns>
public VirtualParadiseParticleEmitterObjectBuilder WithTexture(Optional<string> value) public VirtualParadiseParticleEmitterObjectBuilder WithTexture(Option<string> value)
{ {
Texture = value; Texture = value;
return this; return this;

View File

@ -1,108 +0,0 @@
namespace VpSharp;
#pragma warning disable CA1716
#pragma warning disable CA2225
/// <summary>
/// Represents an optional value.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
public readonly struct Optional<T> : IEquatable<Optional<T>>
{
private readonly T? _value;
/// <summary>
/// Initializes a new instance of the <see cref="Optional{T}" /> struct.
/// </summary>
/// <param name="value"></param>
public Optional(T? value)
{
HasValue = true;
_value = value;
}
/// <summary>
/// Gets a value indicating whether this <see cref="Optional{T}" /> has a value.
/// </summary>
/// <value><see langword="true" /> if a value is defined; otherwise, <see langword="false" />.</value>
public bool HasValue { get; }
/// <summary>
/// Gets the underlying value of this optional.
/// </summary>
/// <value>The value.</value>
public T? Value
{
get
{
if (!HasValue)
{
throw new InvalidOperationException("Cannot access the value of a valueless optional.");
}
return _value;
}
}
/// <summary>
/// Returns a value indicating whether two instances of <see cref="Optional{T}" /> are equal.
/// </summary>
/// <param name="left">The first <see cref="Optional{T}" />.</param>
/// <param name="right">The second <see cref="Optional{T}" />.</param>
/// <value><see langword="true" /> if the two instances are equal; otherwise, <see langword="false" />.</value>
public static bool operator ==(Optional<T> left, Optional<T> right)
{
return left.Equals(right);
}
/// <summary>
/// Returns a value indicating whether two instances of <see cref="Optional{T}" /> are not equal.
/// </summary>
/// <param name="left">The first <see cref="Optional{T}" />.</param>
/// <param name="right">The second <see cref="Optional{T}" />.</param>
/// <value><see langword="true" /> if the two instances are not equal; otherwise, <see langword="false" />.</value>
public static bool operator !=(Optional<T> left, Optional<T> right)
{
return !left.Equals(right);
}
/// <summary>
/// Implicitly converts a value to a new instance of <see cref="Optional{T}" />.
/// </summary>
/// <returns>A new instance of <see cref="Optional{T}" />, wrapping <paramref name="value" />.</returns>
public static implicit operator Optional<T>(T? value)
{
return new Optional<T>(value);
}
/// <summary>
/// Implicitly converts a value to a new instance of <see cref="Optional{T}" />.
/// </summary>
/// <returns>A new instance of <see cref="Optional{T}" />, wrapping <paramref name="value" />.</returns>
public static explicit operator T?(Optional<T?> value)
{
return value.Value;
}
/// <summary>
/// Returns a value indicating whether this <see cref="Optional{T}" /> and another <see cref="Optional{T}" /> are equal.
/// </summary>
/// <param name="other">The other <see cref="Optional{T}" />.</param>
/// <value><see langword="true" /> if the two instances are equal; otherwise, <see langword="false" />.</value>
public bool Equals(Optional<T> other)
{
return HasValue == other.HasValue && EqualityComparer<T?>.Default.Equals(Value, other._value);
}
/// <inheritdoc />
public override bool Equals(object? obj)
{
return obj is Optional<T> other && Equals(other);
}
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(HasValue, Value);
}
}

View File

@ -1,5 +1,6 @@
using System.Drawing; using System.Drawing;
using System.Numerics; using System.Numerics;
using Optional;
using VpSharp.Internal; using VpSharp.Internal;
using VpSharp.Internal.Attributes; using VpSharp.Internal.Attributes;
using VpSharp.Internal.ValueConverters; using VpSharp.Internal.ValueConverters;
@ -25,28 +26,28 @@ public sealed class WorldSettingsBuilder
/// </summary> /// </summary>
/// <value><see langword="true" /> if the debug menu is enabled; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if the debug menu is enabled; otherwise, <see langword="false" />.</value>
[SerializationKey("allow_debug_menu")] [SerializationKey("allow_debug_menu")]
public bool? AllowDebugMenu { get; set; } public Option<bool> AllowDebugMenu { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether flying is enabled. /// Gets or sets a value indicating whether flying is enabled.
/// </summary> /// </summary>
/// <value><see langword="true" /> if flying is enabled; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if flying is enabled; otherwise, <see langword="false" />.</value>
[SerializationKey("allow_flight")] [SerializationKey("allow_flight")]
public bool? AllowFlight { get; set; } public Option<bool> AllowFlight { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether pass-through is enabled. /// Gets or sets a value indicating whether pass-through is enabled.
/// </summary> /// </summary>
/// <value><see langword="true" /> if pass-through is enabled; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if pass-through is enabled; otherwise, <see langword="false" />.</value>
[SerializationKey("allow_passthrough")] [SerializationKey("allow_passthrough")]
public bool? AllowPassThrough { get; set; } public Option<bool> AllowPassThrough { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name of the avatar list file in the object path. /// Gets or sets the name of the avatar list file in the object path.
/// </summary> /// </summary>
/// <value>The name of the avatar list file in the object path..</value> /// <value>The name of the avatar list file in the object path..</value>
[SerializationKey("avatar")] [SerializationKey("avatar")]
public string? AvatarsFile { get; set; } public Option<string> AvatarsFile { get; set; }
/// <summary> /// <summary>
/// Gets or sets the entry position of the world, also known as "landing zone" (LZ) or "ground zero" (GZ). /// Gets or sets the entry position of the world, also known as "landing zone" (LZ) or "ground zero" (GZ).
@ -54,7 +55,7 @@ public sealed class WorldSettingsBuilder
/// <value>The entry position of the world.</value> /// <value>The entry position of the world.</value>
[SerializationKey("entry_point")] [SerializationKey("entry_point")]
[ValueConverter(typeof(Vector4ToVector3Converter))] [ValueConverter(typeof(Vector4ToVector3Converter))]
public Vector3? EntryPosition { get; set; } public Option<Vector3> EntryPosition { get; set; }
/// <summary> /// <summary>
/// Gets or sets the entry yaw of the world. /// Gets or sets the entry yaw of the world.
@ -62,28 +63,28 @@ public sealed class WorldSettingsBuilder
/// <value>The entry yaw of the world.</value> /// <value>The entry yaw of the world.</value>
[SerializationKey("entry_point")] [SerializationKey("entry_point")]
[ValueConverter(typeof(VectorToNthComponentConverter), 4)] [ValueConverter(typeof(VectorToNthComponentConverter), 4)]
public float? EntryYaw { get; set; } public Option<float> EntryYaw { get; set; }
/// <summary> /// <summary>
/// Gets or sets the camera's far-plane distance in decameters. /// Gets or sets the camera's far-plane distance in decameters.
/// </summary> /// </summary>
/// <value>The camera's far-plane distance, in decameters.</value> /// <value>The camera's far-plane distance, in decameters.</value>
[SerializationKey("farplane")] [SerializationKey("farplane")]
public float? FarPlane { get; set; } public Option<float> FarPlane { get; set; }
/// <summary> /// <summary>
/// Gets or sets the camera's field of view. /// Gets or sets the camera's field of view.
/// </summary> /// </summary>
/// <value>The camera's field of view.</value> /// <value>The camera's field of view.</value>
[SerializationKey("fov")] [SerializationKey("fov")]
public float? FieldOfView { get; set; } public Option<float> FieldOfView { get; set; }
/// <summary> /// <summary>
/// Gets or sets the distance at which fog begins. /// Gets or sets the distance at which fog begins.
/// </summary> /// </summary>
/// <value>The distance at which fog begins.</value> /// <value>The distance at which fog begins.</value>
[SerializationKey("fog_begin")] [SerializationKey("fog_begin")]
public float? FogBegin { get; set; } public Option<float> FogBegin { get; set; }
/// <summary> /// <summary>
/// Gets or sets the fog color. /// Gets or sets the fog color.
@ -91,21 +92,21 @@ public sealed class WorldSettingsBuilder
/// <value>The fog color.</value> /// <value>The fog color.</value>
[SerializationKey("fog_color")] [SerializationKey("fog_color")]
[ValueConverter(typeof(HexToColorConverter))] [ValueConverter(typeof(HexToColorConverter))]
public Color? FogColor { get; set; } public Option<Color> FogColor { get; set; }
/// <summary> /// <summary>
/// Gets or sets the density of the fog. /// Gets or sets the density of the fog.
/// </summary> /// </summary>
/// <value>The density of the fog.</value> /// <value>The density of the fog.</value>
[SerializationKey("fog_density")] [SerializationKey("fog_density")]
public float? FogDensity { get; set; } public Option<float> FogDensity { get; set; }
/// <summary> /// <summary>
/// Gets or sets the distance at which fog ends. /// Gets or sets the distance at which fog ends.
/// </summary> /// </summary>
/// <value>The distance at which fog ends.</value> /// <value>The distance at which fog ends.</value>
[SerializationKey("fog_end")] [SerializationKey("fog_end")]
public float? FogEnd { get; set; } public Option<float> FogEnd { get; set; }
/// <summary> /// <summary>
/// Gets or sets the fog mode. /// Gets or sets the fog mode.
@ -113,63 +114,63 @@ public sealed class WorldSettingsBuilder
/// <value>The fog mode.</value> /// <value>The fog mode.</value>
[SerializationKey("fog_mode")] [SerializationKey("fog_mode")]
[ValueConverter(typeof(StringToEnumConverter<FogMode>))] [ValueConverter(typeof(StringToEnumConverter<FogMode>))]
public FogMode? FogMode { get; set; } public Option<FogMode> FogMode { get; set; }
/// <summary> /// <summary>
/// Gets or sets the ground object. /// Gets or sets the ground object.
/// </summary> /// </summary>
/// <value>The ground object. This value will be empty if <see cref="Terrain" /> is <see langword="true" />.</value> /// <value>The ground object. This value will be empty if <see cref="Terrain" /> is <see langword="true" />.</value>
[SerializationKey("ground")] [SerializationKey("ground")]
public string? Ground { get; set; } public Option<string> Ground { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the ground object specified by <see cref="Ground" /> should repeat. /// Gets or sets a value indicating whether the ground object specified by <see cref="Ground" /> should repeat.
/// </summary> /// </summary>
/// <value><see langword="true" /> if the ground should repeat; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if the ground should repeat; otherwise, <see langword="false" />.</value>
[SerializationKey("groundrepeats")] [SerializationKey("groundrepeats")]
public bool? GroundRepeats { get; set; } public Option<bool> GroundRepeats { get; set; }
/// <summary> /// <summary>
/// Gets or sets the camera's near-plane distance in decameters. /// Gets or sets the camera's near-plane distance in decameters.
/// </summary> /// </summary>
/// <value>The camera's near-plane distance, in decameters.</value> /// <value>The camera's near-plane distance, in decameters.</value>
[SerializationKey("nearplane")] [SerializationKey("nearplane")]
public float? NearPlane { get; set; } public Option<float> NearPlane { get; set; }
/// <summary> /// <summary>
/// Gets or sets the password for extracting password-protected ZIP files from the object path. /// Gets or sets the password for extracting password-protected ZIP files from the object path.
/// </summary> /// </summary>
/// <value>The password for extracting password-protected ZIP files from the object path.</value> /// <value>The password for extracting password-protected ZIP files from the object path.</value>
[SerializationKey("objectpassword")] [SerializationKey("objectpassword")]
public string? ObjectPassword { get; set; } public Option<string> ObjectPassword { get; set; }
/// <summary> /// <summary>
/// Gets or sets the object path. /// Gets or sets the object path.
/// </summary> /// </summary>
/// <value>The object path.</value> /// <value>The object path.</value>
[SerializationKey("objectpath")] [SerializationKey("objectpath")]
public string? ObjectPath { get; set; } public Option<string> ObjectPath { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether per-pixel lighting is recommended. /// Gets or sets a value indicating whether per-pixel lighting is recommended.
/// </summary> /// </summary>
/// <value><see langword="true" /> if per-pixel lighting is recommended; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if per-pixel lighting is recommended; otherwise, <see langword="false" />.</value>
[SerializationKey("recommended_per_pixel_lighting")] [SerializationKey("recommended_per_pixel_lighting")]
public bool? PerPixelLightingRecommended { get; set; } public Option<bool> PerPixelLightingRecommended { get; set; }
/// <summary> /// <summary>
/// Gets or sets the speed at which users run. /// Gets or sets the speed at which users run.
/// </summary> /// </summary>
/// <value>The speed at which users run.</value> /// <value>The speed at which users run.</value>
[SerializationKey("run_speed")] [SerializationKey("run_speed")]
public float? RunSpeed { get; set; } public Option<float> RunSpeed { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether gradient sky is enabled. /// Gets or sets a value indicating whether gradient sky is enabled.
/// </summary> /// </summary>
/// <value><see langword="true" /> if gradient sky is enabled; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if gradient sky is enabled; otherwise, <see langword="false" />.</value>
[SerializationKey("sky")] [SerializationKey("sky")]
public bool? Sky { get; set; } public Option<bool> Sky { get; set; }
/// <summary> /// <summary>
/// Gets or sets the color for the first sky cloud layer. /// Gets or sets the color for the first sky cloud layer.
@ -177,7 +178,7 @@ public sealed class WorldSettingsBuilder
/// <value>The color for the first sky cloud layer.</value> /// <value>The color for the first sky cloud layer.</value>
[SerializationKey("sky_clouds1_color")] [SerializationKey("sky_clouds1_color")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyClouds1Color { get; set; } public Option<ColorF> SkyClouds1Color { get; set; }
/// <summary> /// <summary>
/// Gets or sets the color for the second sky cloud layer. /// Gets or sets the color for the second sky cloud layer.
@ -185,7 +186,7 @@ public sealed class WorldSettingsBuilder
/// <value>The color for the second sky cloud layer.</value> /// <value>The color for the second sky cloud layer.</value>
[SerializationKey("sky_clouds2_color")] [SerializationKey("sky_clouds2_color")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyClouds2Color { get; set; } public Option<ColorF> SkyClouds2Color { get; set; }
/// <summary> /// <summary>
/// Gets or sets the scale for the first sky cloud layer. /// Gets or sets the scale for the first sky cloud layer.
@ -193,7 +194,7 @@ public sealed class WorldSettingsBuilder
/// <value>The scale for the first sky cloud layer.</value> /// <value>The scale for the first sky cloud layer.</value>
[SerializationKey("sky_clouds1_scale")] [SerializationKey("sky_clouds1_scale")]
[ValueConverter(typeof(Vector2Converter))] [ValueConverter(typeof(Vector2Converter))]
public Vector2? SkyClouds1Scale { get; set; } public Option<Vector2> SkyClouds1Scale { get; set; }
/// <summary> /// <summary>
/// Gets or sets the scale for the second sky cloud layer. /// Gets or sets the scale for the second sky cloud layer.
@ -201,21 +202,21 @@ public sealed class WorldSettingsBuilder
/// <value>The scale for the second sky cloud layer.</value> /// <value>The scale for the second sky cloud layer.</value>
[SerializationKey("sky_clouds2_scale")] [SerializationKey("sky_clouds2_scale")]
[ValueConverter(typeof(Vector2Converter))] [ValueConverter(typeof(Vector2Converter))]
public Vector2? SkyClouds2Scale { get; set; } public Option<Vector2> SkyClouds2Scale { get; set; }
/// <summary> /// <summary>
/// Gets or sets the texture for the first sky cloud layer. /// Gets or sets the texture for the first sky cloud layer.
/// </summary> /// </summary>
/// <value>The texture for the first sky cloud layer.</value> /// <value>The texture for the first sky cloud layer.</value>
[SerializationKey("sky_clouds1")] [SerializationKey("sky_clouds1")]
public string? SkyClouds1Texture { get; set; } public Option<string> SkyClouds1Texture { get; set; }
/// <summary> /// <summary>
/// Gets or sets the texture for the second sky cloud layer. /// Gets or sets the texture for the second sky cloud layer.
/// </summary> /// </summary>
/// <value>The texture for the second sky cloud layer.</value> /// <value>The texture for the second sky cloud layer.</value>
[SerializationKey("sky_clouds2")] [SerializationKey("sky_clouds2")]
public string? SkyClouds2Texture { get; set; } public Option<string> SkyClouds2Texture { get; set; }
/// <summary> /// <summary>
/// Gets or sets the velocity for the first sky cloud layer. /// Gets or sets the velocity for the first sky cloud layer.
@ -223,7 +224,7 @@ public sealed class WorldSettingsBuilder
/// <value>The velocity for the first sky cloud layer.</value> /// <value>The velocity for the first sky cloud layer.</value>
[SerializationKey("sky_clouds1_velocity")] [SerializationKey("sky_clouds1_velocity")]
[ValueConverter(typeof(Vector2Converter))] [ValueConverter(typeof(Vector2Converter))]
public Vector2? SkyClouds1Velocity { get; set; } public Option<Vector2> SkyClouds1Velocity { get; set; }
/// <summary> /// <summary>
/// Gets or sets the velocity for the second sky cloud layer. /// Gets or sets the velocity for the second sky cloud layer.
@ -231,7 +232,7 @@ public sealed class WorldSettingsBuilder
/// <value>The velocity for the second sky cloud layer.</value> /// <value>The velocity for the second sky cloud layer.</value>
[SerializationKey("sky_clouds2_velocity")] [SerializationKey("sky_clouds2_velocity")]
[ValueConverter(typeof(Vector2Converter))] [ValueConverter(typeof(Vector2Converter))]
public Vector2? SkyClouds2Velocity { get; set; } public Option<Vector2> SkyClouds2Velocity { get; set; }
/// <summary> /// <summary>
/// Gets or sets the first sky gradient color. /// Gets or sets the first sky gradient color.
@ -239,7 +240,7 @@ public sealed class WorldSettingsBuilder
/// <value>The first sky gradient color.</value> /// <value>The first sky gradient color.</value>
[SerializationKey("sky_color1")] [SerializationKey("sky_color1")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyColor1 { get; set; } public Option<ColorF> SkyColor1 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the second sky gradient color. /// Gets or sets the second sky gradient color.
@ -247,7 +248,7 @@ public sealed class WorldSettingsBuilder
/// <value>The second sky gradient color.</value> /// <value>The second sky gradient color.</value>
[SerializationKey("sky_color2")] [SerializationKey("sky_color2")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyColor2 { get; set; } public Option<ColorF> SkyColor2 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the third sky gradient color. /// Gets or sets the third sky gradient color.
@ -255,7 +256,7 @@ public sealed class WorldSettingsBuilder
/// <value>The third sky gradient color.</value> /// <value>The third sky gradient color.</value>
[SerializationKey("sky_color3")] [SerializationKey("sky_color3")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyColor3 { get; set; } public Option<ColorF> SkyColor3 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the fourth sky gradient color. /// Gets or sets the fourth sky gradient color.
@ -263,7 +264,7 @@ public sealed class WorldSettingsBuilder
/// <value>The fourth sky gradient color.</value> /// <value>The fourth sky gradient color.</value>
[SerializationKey("sky_color4")] [SerializationKey("sky_color4")]
[ValueConverter(typeof(Vector4ToColorConverter))] [ValueConverter(typeof(Vector4ToColorConverter))]
public ColorF? SkyColor4 { get; set; } public Option<ColorF> SkyColor4 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the sky color space. /// Gets or sets the sky color space.
@ -271,21 +272,21 @@ public sealed class WorldSettingsBuilder
/// <value>The sky color space.</value> /// <value>The sky color space.</value>
[SerializationKey("sky_srgb_colors")] [SerializationKey("sky_srgb_colors")]
[ValueConverter(typeof(IntToEnumConverter<ColorSpace>))] [ValueConverter(typeof(IntToEnumConverter<ColorSpace>))]
public ColorSpace? SkyColorSpace { get; set; } public Option<ColorSpace> SkyColorSpace { get; set; }
/// <summary> /// <summary>
/// Gets or sets the skybox texture. /// Gets or sets the skybox texture.
/// </summary> /// </summary>
/// <value>The skybox texture.</value> /// <value>The skybox texture.</value>
[SerializationKey("skybox")] [SerializationKey("skybox")]
public string? Skybox { get; set; } public Option<string> Skybox { get; set; }
/// <summary> /// <summary>
/// Gets or sets the file extension for skybox textures. /// Gets or sets the file extension for skybox textures.
/// </summary> /// </summary>
/// <value>The file extension for skybox textures.</value> /// <value>The file extension for skybox textures.</value>
[SerializationKey("skybox_extension")] [SerializationKey("skybox_extension")]
public string? SkyboxExtension { get; set; } public Option<string> SkyboxExtension { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the X axis of skybox textures should be swapped. /// Gets or sets a value indicating whether the X axis of skybox textures should be swapped.
@ -295,49 +296,49 @@ public sealed class WorldSettingsBuilder
/// </value> /// </value>
/// <remarks>If <see langword="true" />, _lf and _rt faces are swapped.</remarks> /// <remarks>If <see langword="true" />, _lf and _rt faces are swapped.</remarks>
[SerializationKey("skybox_extension")] [SerializationKey("skybox_extension")]
public bool? SkyboxSwapX { get; set; } public Option<bool> SkyboxSwapX { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether terrain is enabled. /// Gets or sets a value indicating whether terrain is enabled.
/// </summary> /// </summary>
/// <value><see langword="true" /> if terrain is enabled; otherwise, <see langword="false" />.</value> /// <value><see langword="true" /> if terrain is enabled; otherwise, <see langword="false" />.</value>
[SerializationKey("terrain")] [SerializationKey("terrain")]
public bool? Terrain { get; set; } public Option<bool> Terrain { get; set; }
/// <summary> /// <summary>
/// Gets or sets the vertical offset for the terrain. /// Gets or sets the vertical offset for the terrain.
/// </summary> /// </summary>
/// <value>The vertical offset for the terrain.</value> /// <value>The vertical offset for the terrain.</value>
[SerializationKey("terrainoffset")] [SerializationKey("terrainoffset")]
public float? TerrainOffset { get; set; } public Option<float> TerrainOffset { get; set; }
/// <summary> /// <summary>
/// Gets or sets the scale factor for the terrain grid. /// Gets or sets the scale factor for the terrain grid.
/// </summary> /// </summary>
/// <value>The scale factor for the terrain grid.</value> /// <value>The scale factor for the terrain grid.</value>
[SerializationKey("terrainscale")] [SerializationKey("terrainscale")]
public float? TerrainScale { get; set; } public Option<float> TerrainScale { get; set; }
/// <summary> /// <summary>
/// Gets or sets the speed at which users walk. /// Gets or sets the speed at which users walk.
/// </summary> /// </summary>
/// <value>The speed at which users walk.</value> /// <value>The speed at which users walk.</value>
[SerializationKey("walk_speed")] [SerializationKey("walk_speed")]
public float? WalkSpeed { get; set; } public Option<float> WalkSpeed { get; set; }
/// <summary> /// <summary>
/// Gets or sets the URL of the in-world web overlay. /// Gets or sets the URL of the in-world web overlay.
/// </summary> /// </summary>
/// <value>The URL of the in-world web overlay.</value> /// <value>The URL of the in-world web overlay.</value>
[SerializationKey("web_overlay")] [SerializationKey("web_overlay")]
public string? WebOverlay { get; set; } public Option<string> WebOverlay { get; set; }
/// <summary> /// <summary>
/// Gets or sets the welcome message. /// Gets or sets the welcome message.
/// </summary> /// </summary>
/// <value>The welcome message.</value> /// <value>The welcome message.</value>
[SerializationKey("welcome")] [SerializationKey("welcome")]
public string? WelcomeMessage { get; set; } public Option<string> WelcomeMessage { get; set; }
/// <summary> /// <summary>
/// Gets or sets the ambient light color of the world. /// Gets or sets the ambient light color of the world.
@ -345,7 +346,7 @@ public sealed class WorldSettingsBuilder
/// <value>The ambient light color.</value> /// <value>The ambient light color.</value>
[SerializationKey("worldlight_ambient")] [SerializationKey("worldlight_ambient")]
[ValueConverter(typeof(Vector3ToColorConverter))] [ValueConverter(typeof(Vector3ToColorConverter))]
public ColorF? WorldLightAmbient { get; set; } public Option<ColorF> WorldLightAmbient { get; set; }
/// <summary> /// <summary>
/// Gets or sets the diffuse light color of the world. /// Gets or sets the diffuse light color of the world.
@ -353,7 +354,7 @@ public sealed class WorldSettingsBuilder
/// <value>The diffuse light color.</value> /// <value>The diffuse light color.</value>
[SerializationKey("worldlight_diffuse")] [SerializationKey("worldlight_diffuse")]
[ValueConverter(typeof(Vector3ToColorConverter))] [ValueConverter(typeof(Vector3ToColorConverter))]
public ColorF? WorldLightDiffuse { get; set; } public Option<ColorF> WorldLightDiffuse { get; set; }
/// <summary> /// <summary>
/// Gets or sets the world light position. /// Gets or sets the world light position.
@ -361,7 +362,7 @@ public sealed class WorldSettingsBuilder
/// <value>The world light position.</value> /// <value>The world light position.</value>
[SerializationKey("worldlight_position")] [SerializationKey("worldlight_position")]
[ValueConverter(typeof(Vector3Converter))] [ValueConverter(typeof(Vector3Converter))]
public Vector3? WorldLightPosition { get; set; } public Option<Vector3> WorldLightPosition { get; set; }
/// <summary> /// <summary>
/// Gets or sets the specular light color of the world. /// Gets or sets the specular light color of the world.
@ -369,14 +370,14 @@ public sealed class WorldSettingsBuilder
/// <value>The specular light color.</value> /// <value>The specular light color.</value>
[SerializationKey("worldlight_specular")] [SerializationKey("worldlight_specular")]
[ValueConverter(typeof(Vector3ToColorConverter))] [ValueConverter(typeof(Vector3ToColorConverter))]
public ColorF? WorldLightSpecular { get; set; } public Option<ColorF> WorldLightSpecular { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name of the world. /// Gets or sets the name of the world.
/// </summary> /// </summary>
/// <value>The name of the world.</value> /// <value>The name of the world.</value>
[SerializationKey("worldname")] [SerializationKey("worldname")]
public string? WorldName { get; set; } public Option<string> WorldName { get; set; }
internal void SendChanges() internal void SendChanges()
{ {