From b638c7b9c2cd2bf3b455fbcf8ba65806748fbfe0 Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 30 Jun 2026 19:18:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=A4=9C=E5=87=BA=E3=82=92obj=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=90=E6=B1=8E=E7=94=A8=E6=96=B9=E5=BC=8F=E3=81=AB?= =?UTF-8?q?=E5=86=8D=E8=A8=AD=E8=A8=88=E3=81=97slider=E6=A4=9C=E5=87=BA?= =?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/Compat/ScriptParameterUsage.cs | 48 ++++++++++-------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/LuaScript/Compat/ScriptParameterUsage.cs b/LuaScript/Compat/ScriptParameterUsage.cs index c8ae374..e3d6a70 100644 --- a/LuaScript/Compat/ScriptParameterUsage.cs +++ b/LuaScript/Compat/ScriptParameterUsage.cs @@ -6,31 +6,29 @@ namespace LuaScript.Compat { internal readonly struct ScriptParameterUsage { - public bool Check0 { get; } - public bool Check1 { get; } - public bool Check2 { get; } - public bool Check3 { get; } - public bool Color { get; } + private readonly HashSet? _members; + private readonly bool _color; - private ScriptParameterUsage(bool check0, bool check1, bool check2, bool check3, bool color) + private ScriptParameterUsage(HashSet? members, bool color) { - Check0 = check0; - Check1 = check1; - Check2 = check2; - Check3 = check3; - Color = color; + _members = members; + _color = color; } public static readonly ScriptParameterUsage None = default; - public bool Check(int index) => index switch - { - 0 => Check0, - 1 => Check1, - 2 => Check2, - 3 => Check3, - _ => false, - }; + public bool Color => _color; + + public bool Uses(string member) => _members is not null && _members.Contains(member); + + public bool Check0 => Uses("check0"); + public bool Check1 => Uses("check1"); + public bool Check2 => Uses("check2"); + public bool Check3 => Uses("check3"); + + public bool Check(int index) => (uint)index < 4 && Uses("check" + (char)('0' + index)); + + public bool Slider(int index) => (uint)index < 4 && Uses("slider" + (char)('0' + index)); public static ScriptParameterUsage Detect(string? script) { @@ -47,7 +45,7 @@ namespace LuaScript.Compat return None; } - var checks = new bool[4]; + HashSet? members = null; bool color = false; for (int i = 0; i < tokens.Count; i++) @@ -68,17 +66,11 @@ namespace LuaScript.Compat tokens[i + 1].IsSymbol(".") && tokens[i + 2].Kind == LuaTokenKind.Name) { - string member = tokens[i + 2].Text; - if (member.Length == 6 && member.StartsWith("check", StringComparison.Ordinal)) - { - char digit = member[5]; - if (digit is >= '0' and <= '3') - checks[digit - '0'] = true; - } + (members ??= new HashSet(StringComparer.Ordinal)).Add(tokens[i + 2].Text); } } - return new ScriptParameterUsage(checks[0], checks[1], checks[2], checks[3], color); + return new ScriptParameterUsage(members, color); } } }