Skip to content

Commit e4bdfe3

Browse files
committed
1 parent c860a87 commit e4bdfe3

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs

+19-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ public class DataChange
8080
public delegate void KeyValueEventHandler<T, K>(T value, K key);
8181
public delegate void OnRemoveEventHandler();
8282

83-
public interface ISchemaCollection
83+
public interface ISchemaCollection : IRef
8484
{
85-
void MoveEventHandlers(ISchemaCollection previousInstance);
8685
void InvokeOnAdd(object item, object index);
8786
void InvokeOnChange(object item, object index);
8887
void InvokeOnRemove(object item, object index);
@@ -115,6 +114,8 @@ public interface IRef
115114

116115
object GetByIndex(int index);
117116
void DeleteByIndex(int index);
117+
118+
void MoveEventHandlers(IRef previousInstance);
118119
}
119120

120121
public class Schema : IRef
@@ -176,6 +177,21 @@ public object this[string propertyName]
176177
return fieldChildTypes;
177178
}
178179

180+
public void MoveEventHandlers(IRef previousInstance)
181+
{
182+
OnChange = ((Schema)previousInstance).OnChange;
183+
OnRemove = ((Schema)previousInstance).OnRemove;
184+
185+
foreach (var item in ((Schema)previousInstance).fieldsByIndex)
186+
{
187+
var child = GetByIndex(item.Key);
188+
if (child is IRef)
189+
{
190+
((IRef)child).MoveEventHandlers((IRef)previousInstance.GetByIndex(item.Key));
191+
}
192+
}
193+
}
194+
179195
public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = null)
180196
{
181197
var decode = Decoder.GetInstance();
@@ -349,8 +365,7 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul
349365

350366
if (previousValue != null)
351367
{
352-
((Schema)value).OnChange = ((Schema)previousValue).OnChange;
353-
((Schema)value).OnRemove = ((Schema)previousValue).OnRemove;
368+
((Schema)value).MoveEventHandlers((Schema)previousValue);
354369

355370
if (
356371
((IRef)previousValue).__refId > 0 &&

Assets/Plugins/Colyseus/Serializer/Schema/Types/ArraySchema.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Colyseus.Schema
66
{
7-
public class ArraySchema<T> : ISchemaCollection, IRef
7+
public class ArraySchema<T> : ISchemaCollection
88
{
99
public Dictionary<int, T> Items;
1010
public event KeyValueEventHandler<T, int> OnAdd;
@@ -159,7 +159,7 @@ public void TriggerAll()
159159
}
160160
}
161161

162-
public void MoveEventHandlers(ISchemaCollection previousInstance)
162+
public void MoveEventHandlers(IRef previousInstance)
163163
{
164164
OnAdd = ((ArraySchema<T>)previousInstance).OnAdd;
165165
OnChange = ((ArraySchema<T>)previousInstance).OnChange;

Assets/Plugins/Colyseus/Serializer/Schema/Types/MapSchema.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Colyseus.Schema
77
{
8-
public class MapSchema<T> : ISchemaCollection, IRef
8+
public class MapSchema<T> : ISchemaCollection
99
{
1010
public OrderedDictionary Items = new OrderedDictionary();
1111
public event KeyValueEventHandler<T, string> OnAdd;
@@ -225,7 +225,7 @@ public void TriggerAll()
225225
}
226226
}
227227

228-
public void MoveEventHandlers(ISchemaCollection previousInstance)
228+
public void MoveEventHandlers(IRef previousInstance)
229229
{
230230
OnAdd = ((MapSchema<T>)previousInstance).OnAdd;
231231
OnChange = ((MapSchema<T>)previousInstance).OnChange;

Server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@colyseus/social": "^0.10.0",
17-
"colyseus": "^0.14.0",
17+
"colyseus": "^0.14.1",
1818
"cors": "^2.8.5",
1919
"express": "^4.13.3",
2020
"express-jwt": "^5.3.1",

0 commit comments

Comments
 (0)