Skip to content

Commit aeded62

Browse files
committed
fix parsing 'null' in the state.
1 parent 15db901 commit aeded62

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Assets/Plugins/Colyseus/DeltaListener/Compare.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ protected static void Generate(IndexedDictionary<string, object> mirror, Indexed
5353
for (int i = 0; i < oldKeys.Count; i++)
5454
{
5555
var key = oldKeys [i];
56-
if (obj.ContainsKey(key) && !(!obj.ContainsKey(key) && mirror.ContainsKey(key) && !(obj is List<object>)))
56+
if (
57+
obj.ContainsKey(key) &&
58+
obj[key] != null &&
59+
!(!obj.ContainsKey(key) && mirror.ContainsKey(key) &&
60+
!(obj is List<object>))
61+
)
5762
{
5863
var oldVal = mirror[key];
5964
var newVal = obj[key];

Assets/Tests/DeltaContainerTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ public void ListenAddString() {
3636
Assert.AreEqual (1, listenCalls);
3737
}
3838

39+
[Test]
40+
public void ListenAddNull() {
41+
var newData = GetRawData ();
42+
newData ["null_new"] = null;
43+
44+
var listenCalls = 0;
45+
container.Listen ("null_new", (DataChange change) => {
46+
listenCalls++;
47+
Assert.AreEqual("add", change.operation);
48+
Assert.AreEqual(null, change.value);
49+
});
50+
51+
container.Set (newData);
52+
Assert.AreEqual (1, listenCalls);
53+
}
54+
3955
[Test]
4056
public void ListenAddRemove() {
4157
var newData = GetRawData ();
@@ -198,6 +214,7 @@ protected IndexedDictionary<string, object> GetRawData () {
198214
}));
199215
data.Add ("players", players);
200216
data.Add ("turn", "none");
217+
data.Add ("null", null);
201218
data.Add ("messages", new List<object> { "one", "two", "three" });
202219
return data;
203220
}

0 commit comments

Comments
 (0)