From a8a91103e1f5c106d7b32fcadbb0ea94528185ab Mon Sep 17 00:00:00 2001 From: routersys Date: Wed, 1 Jul 2026 17:35:44 +0900 Subject: [PATCH] =?UTF-8?q?setanchor=E3=81=AE=E3=82=AA=E3=83=97=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E8=A7=A3=E6=9E=90=E3=83=BB=E6=97=A2=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=83=BB=E5=BA=A7=E6=A8=99=E8=A7=A3=E6=B1=BA?= =?UTF-8?q?=E3=83=BB=E3=83=89=E3=83=A9=E3=83=83=E3=82=B0=E9=81=A9=E7=94=A8?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/Anchor/AnchorSupport.cs | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 LuaScript/Anchor/AnchorSupport.cs diff --git a/LuaScript/Anchor/AnchorSupport.cs b/LuaScript/Anchor/AnchorSupport.cs new file mode 100644 index 0000000..7d7dcc9 --- /dev/null +++ b/LuaScript/Anchor/AnchorSupport.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace LuaScript.Anchor +{ + internal enum AnchorConnection + { + None, + Line, + Loop, + Star, + Arm, + } + + internal readonly record struct AnchorOptions(AnchorConnection Connection, bool Is3D); + + internal readonly record struct AnchorRequestData(string Group, int Count, AnchorConnection Connection, bool Is3D); + + internal static class AnchorSupport + { + public const int MaxAnchors = 32; + public const string TrackGroup = "track"; + + public static int ClampCount(int count) => Math.Clamp(count, 0, MaxAnchors); + + public static void ApplyOption(string option, ref AnchorConnection connection, ref bool is3D) + { + switch (option) + { + case "line": connection = AnchorConnection.Line; break; + case "loop": connection = AnchorConnection.Loop; break; + case "star": connection = AnchorConnection.Star; break; + case "arm": connection = AnchorConnection.Arm; break; + case "xyz": is3D = true; break; + } + } + + public static (double X, double Y) DefaultPosition(int index) + { + int col = index % 8; + int row = index / 8; + return ((col - 3.5) * 60d, (row - 1.5) * 60d); + } + + public static void ResolvePosition(IReadOnlyList? source, string group, int index, + out double x, out double y, out double z) + { + if (source is not null) + { + for (int i = 0; i < source.Count; i++) + { + var a = source[i]; + if (a.Index == index && string.Equals(a.Group, group, StringComparison.Ordinal)) + { + x = a.X; + y = a.Y; + z = a.Z; + return; + } + } + } + + var (dx, dy) = DefaultPosition(index); + x = dx; + y = dy; + z = 0d; + } + + public static ImmutableList ApplyDrag( + ImmutableList source, string group, int index, double dx, double dy, double dz) + { + for (int i = 0; i < source.Count; i++) + { + var a = source[i]; + if (a.Index == index && string.Equals(a.Group, group, StringComparison.Ordinal)) + { + return source.SetItem(i, new LuaAnchorPoint + { + Group = group, + Index = index, + X = a.X + dx, + Y = a.Y + dy, + Z = a.Z + dz, + }); + } + } + + var (bx, by) = DefaultPosition(index); + return source.Add(new LuaAnchorPoint + { + Group = group, + Index = index, + X = bx + dx, + Y = by + dy, + Z = dz, + }); + } + } +}