Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary> Copies the score filter from the given <paramref name="priorGeneration"/> into this generation's <see cref="ScoreFilter"/>, completely clearing the old values. </summary>
        /// <param name="priorGeneration"> The generation from which to copy. </param>
        public void SetFilterFrom(SeedGeneration priorGeneration)
        {
            // Clear the score filter.
            ScoreFilter.Clear();

            // Copy each stat filter from the given generation's dictionary.
            foreach (string statName in priorGeneration.ScoreFilter.Keys)
            {
                ScoreFilter.Add(statName, priorGeneration.ScoreFilter[statName]);
            }
        }