Esempio n. 1
0
        public void ModifyAdd(IConnectionSink sink, T newAbilityInstance, int modificationOwner)
        {
            newAbilityInstance.root    = root;
            newAbilityInstance.carrier = carrier;

            if (savedData != null && savedData.TryGetValue(modificationOwner, out var list))
            {
                var itemIndex = list.FindIndex(item => item.UId() == newAbilityInstance.UId());
                if (itemIndex != -1)
                {
                    // old save item from previous save
                    var item = list[itemIndex];
                    // is no longer needed and can be removed
                    list.RemoveAt(itemIndex);
                    if (list.Count == 0)
                    {
                        savedData.Remove(modificationOwner);
                    }
                }
            }
            else
            {
            }

            collection.Add(newAbilityInstance);
            newAbilityInstance.Enlive();
            sink.AddConnection(new AnonymousDisposable(() => collection.Remove(newAbilityInstance)));
        }
Esempio n. 2
0
 public static void ReadFromJson <T>(this ZergRush.ReactiveCore.ReactiveCollection <T> self, JsonTextReader reader) where T : ZergRush.Alive.Livable, ILivableModification, IHashable
 {
     if (reader.TokenType != JsonToken.StartArray)
     {
         throw new JsonSerializationException("Bad Json Format");
     }
     while (reader.Read())
     {
         if (reader.TokenType == JsonToken.EndArray)
         {
             break;
         }
         self.Add(null);
         self[self.Count - 1] = (T)ZergRush.Alive.Livable.CreatePolymorphic(reader.ReadJsonClassId());
         self[self.Count - 1].ReadFromJson(reader);
     }
 }
Esempio n. 3
0
 public static void ReadFromJson(this ZergRush.ReactiveCore.ReactiveCollection <Game.RocketInstance> self, JsonTextReader reader)
 {
     if (reader.TokenType != JsonToken.StartArray)
     {
         throw new JsonSerializationException("Bad Json Format");
     }
     while (reader.Read())
     {
         if (reader.TokenType == JsonToken.EndArray)
         {
             break;
         }
         Game.RocketInstance val = default;
         val = new Game.RocketInstance();
         val.ReadFromJson(reader);
         self.Add(val);
     }
 }
Esempio n. 4
0
 public IDisposable ModifyAdd(T elem)
 {
     collection.Add(elem);
     return(new AnonymousDisposable(() => collection.Remove(elem)));
 }