From 355b66b96319eaba22e2187dfbca57baf6436dac Mon Sep 17 00:00:00 2001 From: Laboredih123 <62359847+Laboredih123@users.noreply.github.com> Date: Sat, 9 May 2026 13:06:27 -0700 Subject: [PATCH 1/3] append and remove operators --- .../Objects/Types/DreamAssocList.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs index 01843f9130..5832f1efa4 100644 --- a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs @@ -148,4 +148,38 @@ public void Swap(int index1, int index2) { public bool ContainsValue(DreamValue value) { return _values.ContainsKey(value); } + + public override DreamValue OperatorAppend(DreamValue b) { + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (var pair in bList.EnumerateAssocValues()) { + if (ContainsKey(pair.Key)) { + continue; + } + + SetValue(pair.Key, pair.Value); + } + } else { + AddValue(b); + } + + IncRef(); + return new(this); + } + + public override DreamValue OperatorRemove(DreamValue b) { + if (b.TryGetValueAsIDreamList(out var bList)) { + var values = bList.EnumerateValues(); + + foreach (var value in values) { + RemoveValue(value); + } + } else { + RemoveValue(b); + } + + IncRef(); + return new(this); + } } + + From 0caf5b70dce17257e7915002b7a20fc586db04aa Mon Sep 17 00:00:00 2001 From: Laboredih123 <62359847+Laboredih123@users.noreply.github.com> Date: Sat, 16 May 2026 15:32:16 -0700 Subject: [PATCH 2/3] even more operators --- .../Objects/Types/DreamAssocList.cs | 90 ++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs index 5832f1efa4..9e5bf6c8f9 100644 --- a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs @@ -149,6 +149,73 @@ public bool ContainsValue(DreamValue value) { return _values.ContainsKey(value); } + public override DreamValue OperatorAdd(DreamValue b, DMProcState state) { + var listCopy = (DreamAssocList)CreateCopy(); + + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (var pair in bList.EnumerateAssocValues()) { + if (listCopy.ContainsKey(pair.Key)) { + continue; + } + + listCopy.SetValue(pair.Key, pair.Value); + } + } else { + listCopy.AddValue(b); + } + + return new DreamValue(listCopy); + } + + public override DreamValue OperatorSubtract(DreamValue b, DMProcState state) { + var listCopy = (DreamAssocList)CreateCopy(); + + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (DreamValue value in bList.EnumerateValues()) { + listCopy.RemoveValue(value); + } + } else { + listCopy.RemoveValue(b); + } + + return new DreamValue(listCopy); + } + + public override DreamValue OperatorOr(DreamValue b, DMProcState state) { + var listCopy = (DreamAssocList)CreateCopy(); + + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (var pair in bList.EnumerateAssocValues()) { + if (listCopy.ContainsKey(pair.Key)) { + continue; + } + + listCopy.SetValue(pair.Key, pair.Value); + } + } else { + listCopy.AddValue(b); + } + + return new DreamValue(listCopy); + } + + public override DreamValue OperatorCombine(DreamValue b) { + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (var pair in bList.EnumerateAssocValues()) { + if (ContainsKey(pair.Key)) { + continue; + } + + SetValue(pair.Key, pair.Value); + } + } else { + AddValue(b); + } + + IncRef(); + return new(this); + } + public override DreamValue OperatorAppend(DreamValue b) { if (b.TryGetValueAsIDreamList(out var bList)) { foreach (var pair in bList.EnumerateAssocValues()) { @@ -168,9 +235,7 @@ public override DreamValue OperatorAppend(DreamValue b) { public override DreamValue OperatorRemove(DreamValue b) { if (b.TryGetValueAsIDreamList(out var bList)) { - var values = bList.EnumerateValues(); - - foreach (var value in values) { + foreach (var value in bList.EnumerateValues()) { RemoveValue(value); } } else { @@ -180,6 +245,25 @@ public override DreamValue OperatorRemove(DreamValue b) { IncRef(); return new(this); } + + public override DreamValue OperatorMask(DreamValue b) { + if (b.TryGetValueAsIDreamList(out var bList)) { + foreach (var value in EnumerateValues()) { + if (!bList.ContainsKey(value)) { + RemoveValue(value); + } + } + } else { + foreach (var value in EnumerateValues()) { + if (value != b) { + RemoveValue(value); + } + } + } + + IncRef(); + return new(this); + } } From 41fd9b22cd1691577be13fa4af9984f5449ba6b5 Mon Sep 17 00:00:00 2001 From: Laboredih123 <62359847+Laboredih123@users.noreply.github.com> Date: Sat, 16 May 2026 16:42:47 -0700 Subject: [PATCH 3/3] equivalent operator --- .../Objects/Types/DreamAssocList.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs index 9e5bf6c8f9..2c0b6e68f0 100644 --- a/OpenDreamRuntime/Objects/Types/DreamAssocList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamAssocList.cs @@ -255,7 +255,7 @@ public override DreamValue OperatorMask(DreamValue b) { } } else { foreach (var value in EnumerateValues()) { - if (value != b) { + if (!value.Equals(b)) { RemoveValue(value); } } @@ -264,6 +264,26 @@ public override DreamValue OperatorMask(DreamValue b) { IncRef(); return new(this); } + + public override DreamValue OperatorEquivalent(DreamValue b) { + if (!b.TryGetValueAsIDreamList(out var secondList)) + return DreamValue.False; + if (GetLength() != secondList.GetLength()) + return DreamValue.False; + + foreach (var pair in secondList.EnumerateAssocValues()) { + if (!ContainsKey(pair.Key)) { + return DreamValue.False; + } + + using var temp = GetValue(pair.Key); + if (!temp.Equals(pair.Value)) { + return DreamValue.False; + } + } + + return DreamValue.True; + } }