public void AddSeed(Seed seed) { // Get or create the list for the crop type. if (!seedsByPlantType.TryGetValue(seed.CropTileName, out SortedList <uint, SeedGeneration> cropTypeGenerations)) { // Create a new list of seed generations. cropTypeGenerations = new SortedList <uint, SeedGeneration>(1); // Add the generations list to the dictionary keyed by the crop name. seedsByPlantType.Add(seed.CropTileName, cropTypeGenerations); } // If the seed generation list doesn't contain a seed generation for the given seed, create one. if (!cropTypeGenerations.TryGetValue(seed.Generation, out SeedGeneration seedGeneration)) { // Create a new seed generation using the seed's data. seedGeneration = new SeedGeneration(seed.CropTileName, seed.Generation); // Add the seed generation to the list. cropTypeGenerations.Add(seed.Generation, seedGeneration); // If the seed has a generation prior to the new one, copy the filter from it to the new one. if (cropTypeGenerations.IndexOfKey(seed.Generation) > 0) { seedGeneration.SetFilterFrom(cropTypeGenerations.Values[cropTypeGenerations.IndexOfKey(seed.Generation) - 1]); } } // Add the seed to the generation and invoke the event. seedGeneration.Add(seed); onSeedAdded.Invoke(seedGeneration); }