Пример #1
0
        private List <IStatisticsModule> LoadStatLines(string[] statLines)
        {
            var list       = new List <IStatisticsModule>(statLines.Length);
            var serializer = new JsonSerializer();

            foreach (var statLine in statLines)
            {
                var module = StatisticsModule.Create();
                var parts  = statLine.Split(new[] { SettingsProvider.SettingsDelimiter }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var part in parts)
                {
                    var index          = part.IndexOf(';');
                    var key            = (Statistic)int.Parse(part.Substring(0, index));
                    var conversionType = StatisticHelper.GetType(key);

                    using (var reader = new StringReader(part.Substring(index + 1)))
                    {
                        var value = serializer.Deserialize(reader, conversionType);
                        module[key] = value;
                    }
                }

                list.Add(module);
            }

            return(list);
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the StatisticsModule class.
        /// </summary>
        private StatisticsModule()
        {
            var defaultValues = StatisticHelper.GetGameStatistics();

            this.stats = new Dictionary <Statistic, object>(defaultValues.Count());

            foreach (var stat in StatisticHelper.GetGameStatistics())
            {
                this.stats.Add(stat, StatisticHelper.GetType(stat).GetDefaultValue());
            }
        }