Exemplo n.º 1
0
        public void ParseChange(SharedDataChange change)
        {
            if (change.ChangeType == (int)SharedDataChangeType.Remove)
            {
                if (Collection.FirstOrDefault(e => e.Key == change.Key) is SharedData data)
                {
                    Collection.Remove(data);
                    foreach (var observer in Observers)
                    {
                        observer.DynamicInvoke(new CollectionChangeArgs(data.Key, change.ChangedBy, true, data.Value, null));
                    }
                }
            }
            else
            {
                SharedData data = new SharedData(change.Key, change.Value);

                SharedData oldData = null;

                if (Collection.FirstOrDefault(e => e.Key == change.Key) is SharedData existingData)
                {
                    oldData = existingData;
                    Collection.Remove(existingData);
                }

                Collection.Add(data);

                foreach (var observer in Observers)
                {
                    observer.DynamicInvoke(new CollectionChangeArgs(data.Key, change.ChangedBy, true, oldData.Value, data.Value));
                }
            }
        }
Exemplo n.º 2
0
 public void ShareChange(SharedDataChange data)
 {
     Helper.ModHelper.Multiplayer.SendMessage(
         message: data,
         messageType: $"SharedChange:{AssignedId}",
         modIDs: new string[] { Helper.ModHelper.ModRegistry.ModID });
 }