From 9ebbd728bef15676ef809e23e0bae9091b46249d Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 1 Feb 2025 23:29:40 -0600 Subject: [PATCH] Implement `cmptextEx()` --- .../DMProject/Tests/Builtins/cmptext.dm | 6 ++++++ DMCompiler/DMStandard/UnsortedAdditions.dm | 2 -- DMCompiler/DMStandard/_Standard.dm | 1 + .../Procs/Native/DreamProcNative.cs | 1 + .../Procs/Native/DreamProcNativeRoot.cs | 19 +++++++++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 Content.Tests/DMProject/Tests/Builtins/cmptext.dm diff --git a/Content.Tests/DMProject/Tests/Builtins/cmptext.dm b/Content.Tests/DMProject/Tests/Builtins/cmptext.dm new file mode 100644 index 0000000000..8dda34f66d --- /dev/null +++ b/Content.Tests/DMProject/Tests/Builtins/cmptext.dm @@ -0,0 +1,6 @@ + +/proc/RunTest() + ASSERT(cmptext("Test", "test", "tEsT")) + ASSERT(!cmptext("foo", "bar")) + ASSERT(cmptextEx("hello world", "hello world")) + ASSERT(!cmptextEx("Hello World", "hello world")) diff --git a/DMCompiler/DMStandard/UnsortedAdditions.dm b/DMCompiler/DMStandard/UnsortedAdditions.dm index f2edd548ca..a39d6c9c64 100644 --- a/DMCompiler/DMStandard/UnsortedAdditions.dm +++ b/DMCompiler/DMStandard/UnsortedAdditions.dm @@ -2,8 +2,6 @@ set opendream_unimplemented = TRUE /proc/bounds_dist(Ref, Target) set opendream_unimplemented = TRUE -/proc/cmptextEx(T1) - set opendream_unimplemented = TRUE // An undocumented proc // Doesn't evaluate DM as you might expect, but instead DMScript diff --git a/DMCompiler/DMStandard/_Standard.dm b/DMCompiler/DMStandard/_Standard.dm index 65cd2fca98..410b1cd950 100644 --- a/DMCompiler/DMStandard/_Standard.dm +++ b/DMCompiler/DMStandard/_Standard.dm @@ -8,6 +8,7 @@ proc/ckey(Key) as text|null proc/ckeyEx(Text) as text|null proc/clamp(Value, Low, High) as /list|num|null proc/cmptext(T1) as num +proc/cmptextEx(T1) as num proc/copytext(T, Start = 1, End = 0) as text|null proc/copytext_char(T,Start=1,End=0) as text|null proc/CRASH(msg) as null diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNative.cs b/OpenDreamRuntime/Procs/Native/DreamProcNative.cs index 6ed7ebd2f3..acaaac09e2 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNative.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNative.cs @@ -13,6 +13,7 @@ public static void SetupNativeProcs(DreamObjectTree objectTree) { objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_ckeyEx); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_clamp); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_cmptext); + objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_cmptextEx); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_copytext); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_copytext_char); objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_CRASH); diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs index f327495fb1..e8c0511734 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs @@ -555,6 +555,25 @@ public static DreamValue NativeProc_cmptext(NativeProc.Bundle bundle, DreamObjec return DreamValue.True; } + [DreamProc("cmptextEx")] + [DreamProcParameter("T1", Type = DreamValueTypeFlag.String)] + public static DreamValue NativeProc_cmptextEx(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) { + if (!bundle.GetArgument(0, "T1").TryGetValueAsString(out var t1)) + return DreamValue.False; + + for (int i = 1; i < bundle.Arguments.Length; i++) { + var arg = bundle.Arguments[i]; + + if (!arg.TryGetValueAsString(out var t2)) + return DreamValue.False; + + if (!t2.Equals(t1, StringComparison.InvariantCulture)) + return DreamValue.False; + } + + return DreamValue.True; + } + [DreamProc("copytext")] [DreamProcParameter("T", Type = DreamValueTypeFlag.String)] [DreamProcParameter("Start", Type = DreamValueTypeFlag.Float, DefaultValue = 1)]