From 48d7969a84a56b58c62b82a7d0d4ab793063677e Mon Sep 17 00:00:00 2001 From: routersys Date: Mon, 29 Jun 2026 23:12:08 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88?= =?UTF-8?q?=E5=8F=82=E7=85=A7=E3=81=A7check=E3=81=A8color=E3=81=AEUI?= =?UTF-8?q?=E3=82=92=E8=87=AA=E5=8B=95=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript.Tests/LuaScript.Tests.csproj | 1 + LuaScript/Compat/ScriptParameterUsage.cs | 84 ++++++++++++++++++++++++ LuaScript/LuaScriptEffect.cs | 11 ++-- LuaScript/LuaScriptEffectProcessor.cs | 2 +- 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 LuaScript/Compat/ScriptParameterUsage.cs diff --git a/LuaScript.Tests/LuaScript.Tests.csproj b/LuaScript.Tests/LuaScript.Tests.csproj index fcb5dea..71a357d 100644 --- a/LuaScript.Tests/LuaScript.Tests.csproj +++ b/LuaScript.Tests/LuaScript.Tests.csproj @@ -39,6 +39,7 @@ + diff --git a/LuaScript/Compat/ScriptParameterUsage.cs b/LuaScript/Compat/ScriptParameterUsage.cs new file mode 100644 index 0000000..c8ae374 --- /dev/null +++ b/LuaScript/Compat/ScriptParameterUsage.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using LuaScript.Engine.Kernel; + +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 ScriptParameterUsage(bool check0, bool check1, bool check2, bool check3, bool color) + { + Check0 = check0; + Check1 = check1; + Check2 = check2; + Check3 = check3; + 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 static ScriptParameterUsage Detect(string? script) + { + if (string.IsNullOrEmpty(script)) + return None; + + List tokens; + try + { + tokens = LuaLexer.Tokenize(script); + } + catch (KernelUnsupportedException) + { + return None; + } + + var checks = new bool[4]; + bool color = false; + + for (int i = 0; i < tokens.Count; i++) + { + var token = tokens[i]; + if (token.Kind != LuaTokenKind.Name) + continue; + + if (token.Text == "color") + { + if (i == 0 || !tokens[i - 1].IsSymbol(".")) + color = true; + continue; + } + + if (token.Text == "obj" && + i + 2 < tokens.Count && + 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; + } + } + } + + return new ScriptParameterUsage(checks[0], checks[1], checks[2], checks[3], color); + } + } +} diff --git a/LuaScript/LuaScriptEffect.cs b/LuaScript/LuaScriptEffect.cs index c645e9e..0a242b0 100644 --- a/LuaScript/LuaScriptEffect.cs +++ b/LuaScript/LuaScriptEffect.cs @@ -118,16 +118,17 @@ namespace LuaScript Layout = layout; bool hasAny = layout.HasAny; + var usage = ScriptParameterUsage.Detect(_script); IsTrack0Visible = !hasAny || layout.HasTrack(0); IsTrack1Visible = !hasAny || layout.HasTrack(1); IsTrack2Visible = !hasAny || layout.HasTrack(2); IsTrack3Visible = !hasAny || layout.HasTrack(3); - IsCheck0Visible = layout.HasCheck(0); - IsCheck1Visible = layout.HasCheck(1); - IsCheck2Visible = layout.HasCheck(2); - IsCheck3Visible = layout.HasCheck(3); - IsColorVisible = layout.HasColor; + IsCheck0Visible = layout.HasCheck(0) || (!hasAny && usage.Check0); + IsCheck1Visible = layout.HasCheck(1) || (!hasAny && usage.Check1); + IsCheck2Visible = layout.HasCheck(2) || (!hasAny && usage.Check2); + IsCheck3Visible = layout.HasCheck(3) || (!hasAny && usage.Check3); + IsColorVisible = layout.HasColor || (!hasAny && usage.Color); SeedDefaults(layout); } diff --git a/LuaScript/LuaScriptEffectProcessor.cs b/LuaScript/LuaScriptEffectProcessor.cs index de3187f..99f998e 100644 --- a/LuaScript/LuaScriptEffectProcessor.cs +++ b/LuaScript/LuaScriptEffectProcessor.cs @@ -174,7 +174,7 @@ namespace LuaScript var t3 = ClampTrack(item.Track3.GetValue(frame, length, fps), layout, 3); bool c0 = item.Check0, c1 = item.Check1, c2 = item.Check2, c3 = item.Check3; - bool hasColor = layout.HasColor; + bool hasColor = item.IsColorVisible; int colorRgb = hasColor ? (item.Color.R << 16) | (item.Color.G << 8) | item.Color.B : 0; var inDesc = desc.DrawDescription;