Skip to content

Commit b784799

Browse files
committed
toy properties, no waypointtoy
1 parent dc7dfe2 commit b784799

8 files changed

Lines changed: 269 additions & 45 deletions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.Exceptions;
6+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
7+
using SER.Code.MethodSystem.MethodDescriptors;
8+
using UnityEngine;
9+
10+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
11+
12+
[UsedImplicitly]
13+
public class CameraPropertiesMethod : SynchronousMethod, ICanError
14+
{
15+
public override string Description => $"Sets the properties of a {nameof(CameraToy)}.";
16+
17+
public string[] ErrorReasons =>
18+
[
19+
"up constraint has to be lower or equal to down constraint",
20+
"left constraint has to be lower or equal to right constraint",
21+
"minimal zoom has to be lower or equal to maximal zoom",
22+
];
23+
24+
public override Argument[] ExpectedArguments { get; } =
25+
[
26+
new ReferenceArgument<CameraToy>("camera reference"),
27+
28+
new TextArgument("label")
29+
{ DefaultValue = new(null, "not changing") },
30+
new FloatArgument("up constraint", -180, 180)
31+
{ DefaultValue = new(null, "not changing") },
32+
new FloatArgument("down constraint", -180, 180)
33+
{ DefaultValue = new(null, "not changing") },
34+
new FloatArgument("left constraint", -180, 180)
35+
{ DefaultValue = new(null, "not changing") },
36+
new FloatArgument("right constraint", -180, 180)
37+
{ DefaultValue = new(null, "not changing") },
38+
new FloatArgument("minimal zoom", 0, 1)
39+
{ DefaultValue = new(null, "not changing") },
40+
new FloatArgument("maximal zoom", 0, 1)
41+
{ DefaultValue = new(null, "not changing") },
42+
];
43+
public override void Execute()
44+
{
45+
var camera = Args.GetReference<CameraToy>("camera reference");
46+
47+
var up = Args.GetNullableFloat("up constraint");
48+
var down = Args.GetNullableFloat("down constraint");
49+
var left = Args.GetNullableFloat("left constraint");
50+
var right = Args.GetNullableFloat("right constraint");
51+
var minZoom = Args.GetNullableFloat("minimal zoom");
52+
var maxZoom = Args.GetNullableFloat("maximal zoom");
53+
54+
if (up > down) throw new ScriptRuntimeError(this, ErrorReasons[0]);
55+
if (left > right) throw new ScriptRuntimeError(this, ErrorReasons[1]);
56+
if (minZoom > maxZoom) throw new ScriptRuntimeError(this, ErrorReasons[2]);
57+
58+
if (Args.GetText("label") is { } label) camera.Label = label;
59+
60+
camera.VerticalConstraints = new(
61+
up ?? camera.VerticalConstraints.x,
62+
down ?? camera.VerticalConstraints.y
63+
);
64+
camera.HorizontalConstraint = new(
65+
left ?? camera.HorizontalConstraint.x,
66+
right ?? camera.HorizontalConstraint.y
67+
);
68+
camera.ZoomConstraints = new(
69+
minZoom ?? camera.ZoomConstraints.x,
70+
maxZoom ?? camera.ZoomConstraints.y
71+
);
72+
}
73+
74+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.Exceptions;
6+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
7+
using SER.Code.ValueSystem;
8+
9+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
10+
11+
[UsedImplicitly]
12+
public class GetToyPropertiesMethod : ReturningMethod<NumberValue>
13+
{
14+
public override string Description => "Returns information about an Admin Toy";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new ReferenceArgument<AdminToy>("toy reference"),
19+
new OptionsArgument("property",
20+
"netId",
21+
"positionX",
22+
"positionY",
23+
"positionZ",
24+
"rotationX",
25+
"rotationY",
26+
"rotationZ",
27+
"scaleX",
28+
"scaleY",
29+
"scaleZ")
30+
]; // TODO: add every property from every toy type
31+
32+
public override void Execute()
33+
{
34+
var toy = Args.GetReference<AdminToy>("toy reference");
35+
36+
ReturnValue = Args.GetOption("property") switch
37+
{
38+
"netid" => toy.Base.netId,
39+
"positionx" => (decimal)toy.Position.x,
40+
"positiony" => (decimal)toy.Position.y,
41+
"positionz" => (decimal)toy.Position.z,
42+
"rotationx" => (decimal)toy.Rotation.eulerAngles.x,
43+
"rotationy" => (decimal)toy.Rotation.eulerAngles.y,
44+
"rotationz" => (decimal)toy.Rotation.eulerAngles.z,
45+
"scalex" => (decimal)toy.Scale.x,
46+
"scaley" => (decimal)toy.Scale.y,
47+
"scalez" => (decimal)toy.Scale.z,
48+
_ => throw new TosoksFuckedUpException("out of order")
49+
};
50+
}
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using UnityEngine;
6+
using LightSourceToy = LabApi.Features.Wrappers.LightSourceToy;
7+
8+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
9+
10+
[UsedImplicitly]
11+
public class LightSourcePropertiesMethod : SynchronousMethod
12+
{
13+
public override string Description => $"Sets the properties of a {nameof(LightSourceToy)}.";
14+
15+
public override Argument[] ExpectedArguments { get; } =
16+
[
17+
new ReferenceArgument<LightSourceToy>("light reference"),
18+
19+
new FloatArgument("intensity") { DefaultValue = new(null, "not changing") },
20+
new FloatArgument("range") { DefaultValue = new(null, "not changing") },
21+
new ColorArgument("color") { DefaultValue = new(null, "not changing") },
22+
new EnumArgument<LightShadows>("shadow type") { DefaultValue = new(null, "not changing") },
23+
new FloatArgument("shadow strength") { DefaultValue = new(null, "not changing") },
24+
new EnumArgument<LightType>("light type") { DefaultValue = new(null, "not changing") },
25+
];
26+
public override void Execute()
27+
{
28+
var light = Args.GetReference<LightSourceToy>("light reference");
29+
30+
if (Args.GetNullableFloat("intensity") is { } intensity) light.Intensity = intensity;
31+
if (Args.GetNullableFloat("range") is { } range) light.Range = range;
32+
if (Args.GetNullableColor("color") is { } color) light.Color = color;
33+
if (Args.GetNullableEnum<LightShadows>("shadow type") is { } shadows) light.ShadowType = shadows;
34+
if (Args.GetNullableFloat("shadow strength") is { } strength) light.ShadowStrength = strength;
35+
if (Args.GetNullableEnum<LightType>("light type") is { } type) light.Type = type;
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using AdminToys;
2+
using JetBrains.Annotations;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using UnityEngine;
7+
using PrimitiveObjectToy = LabApi.Features.Wrappers.PrimitiveObjectToy;
8+
9+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
10+
11+
[UsedImplicitly]
12+
public class PrimitiveObjectPropertiesMethod : SynchronousMethod
13+
{
14+
public override string Description => $"Sets properties of a {nameof(PrimitiveObjectToy)}.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new ReferenceArgument<PrimitiveObjectToy>("toy reference"),
19+
20+
new EnumArgument<PrimitiveType>("type") { DefaultValue = new(null, "not changing") },
21+
new ColorArgument("color") { DefaultValue = new(null, "not changing") },
22+
new FlagsArgument<PrimitiveFlags>("flags") { DefaultValue = new(null, "not changing") },
23+
];
24+
25+
public override void Execute()
26+
{
27+
var toy = Args.GetReference<PrimitiveObjectToy>("toy reference");
28+
29+
if (Args.GetNullableEnum<PrimitiveType>("type") is { } type) toy.Type = type;
30+
if (Args.GetNullableColor("color") is { } color) toy.Color = color;
31+
if (Args.GetNullableFlags<PrimitiveFlags>("flags") is { } flags) toy.Flags = flags;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
7+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
8+
9+
[UsedImplicitly]
10+
public class ShootingTargetPropertiesMethod : SynchronousMethod
11+
{
12+
public override string Description => $"Sets the properties of a {nameof(ShootingTargetToy)}.";
13+
14+
public override Argument[] ExpectedArguments { get; } =
15+
[
16+
new ReferenceArgument<ShootingTargetToy>("target reference"),
17+
18+
new IntArgument("max hp", 1, 256)
19+
{ DefaultValue = new(null, "not changing") },
20+
new IntArgument("auto reset time", -1, 11)
21+
{ DefaultValue = new(null, "not changing") },
22+
new BoolArgument("synchronize damage?")
23+
{ DefaultValue = new(null, "not changing") },
24+
];
25+
public override void Execute()
26+
{
27+
var target = Args.GetReference<ShootingTargetToy>("target reference");
28+
29+
if (Args.GetNullableInt("max hp") is { } hp) target.Base._maxHp = hp;
30+
if (Args.GetNullableInt("auto reset time") is { } autoReset) target.Base._autoDestroyTime = autoReset;
31+
if (Args.GetNullableBool("sync mode") is { } sync) target.Base._syncMode = sync;
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.Exceptions;
6+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
7+
using SER.Code.MethodSystem.MethodDescriptors;
8+
using UnityEngine;
9+
10+
namespace SER.Code.MethodSystem.Methods.AdminToyPropertyMethods;
11+
12+
[UsedImplicitly]
13+
public class TextPropertiesMethod : SynchronousMethod
14+
{
15+
public override string Description => $"Sets the properties of a {nameof(TextToy)}.";
16+
17+
public override Argument[] ExpectedArguments { get; } =
18+
[
19+
new ReferenceArgument<TextToy>("text toy reference"),
20+
21+
new TextArgument("label") { DefaultValue = new(null, "not changing") },
22+
new FloatArgument("display width") { DefaultValue = new(null, "not changing") },
23+
new FloatArgument("display height") { DefaultValue = new(null, "not changing") },
24+
];
25+
public override void Execute()
26+
{
27+
var text = Args.GetReference<TextToy>("text toy reference");
28+
29+
var width = Args.GetNullableFloat("display width");
30+
var height = Args.GetNullableFloat("display height");
31+
32+
if (Args.GetText("label") is { } label) text.TextFormat = label;
33+
34+
text.DisplaySize = new(
35+
height ?? text.DisplaySize.x,
36+
width ?? text.DisplaySize.y
37+
);
38+
}
39+
40+
}

Code/MethodSystem/Methods/AdminToysMethods/CreateToyMethod.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using LightSourceToy = LabApi.Features.Wrappers.LightSourceToy;
1212
using PrimitiveObjectToy = LabApi.Features.Wrappers.PrimitiveObjectToy;
1313
using TextToy = LabApi.Features.Wrappers.TextToy;
14-
using WaypointToy = LabApi.Features.Wrappers.WaypointToy;
1514

1615
namespace SER.Code.MethodSystem.Methods.AdminToysMethods;
1716

@@ -32,8 +31,7 @@ public class CreateToyMethod : ReferenceReturningMethod<AdminToy>, IAdditionalDe
3231
Option.Reference<InteractableToy>("interactable"),
3332
Option.Reference<CameraToy>("camera"),
3433
Option.Reference<CapybaraToy>("capybara"),
35-
Option.Reference<TextToy>("text"),
36-
Option.Reference<WaypointToy>("waypoint")
34+
Option.Reference<TextToy>("text")
3735
)
3836
];
3937

@@ -48,7 +46,6 @@ public override void Execute()
4846
"camera" => CameraToy.Create(networkSpawn: false),
4947
"capybara" => CapybaraToy.Create(networkSpawn: false),
5048
"text" => TextToy.Create(networkSpawn: false),
51-
"waypoint" => WaypointToy.Create(networkSpawn: false),
5249
_ => throw new TosoksFuckedUpException("out of order")
5350
};
5451
}

Code/MethodSystem/Methods/AdminToysMethods/SetPrimitiveObjectToyPropertiesMethod.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)