Skip to content

Commit

Permalink
Implement cmptextEx()
Browse files Browse the repository at this point in the history
  • Loading branch information
ike709 committed Feb 2, 2025
1 parent 49dd94b commit 9ebbd72
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Content.Tests/DMProject/Tests/Builtins/cmptext.dm
Original file line number Diff line number Diff line change
@@ -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"))
2 changes: 0 additions & 2 deletions DMCompiler/DMStandard/UnsortedAdditions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/_Standard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions OpenDreamRuntime/Procs/Native/DreamProcNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 9ebbd72

Please sign in to comment.