Пример #1
0
        protected static BiasingParameters.LocaleInfo ReadLocaleInformation(JObject locale, BiasingParameters parameters)
        {
            var localeInfo = new BiasingParameters.LocaleInfo {
                Name = (string)locale["NAME"]
            };
            var reactionCount = (int)locale["REACTION_COUNT"];
            var reactions     = (JArray)locale["REACTIONS"];

            if (reactionCount != reactions.Count)
            {
                throw new ReactionArrayCountException(string.Format("JSON data for locale '{0}' invalid, REACTION_COUNT doesn't match REACTION array size.", localeInfo.Name), localeInfo.Name);
            }
            foreach (JToken token in reactions)
            {
                var reaction     = (JObject)token;
                var reactionInfo = ReadReactionInformation(reaction, parameters.RareEvent.IntermediateRareEventCount);
                localeInfo.Reactions.Add(reactionInfo);
            }

            return(localeInfo);
        }
        protected static void WriteLocaleInformation(BiasingParameters.LocaleInfo locale, StringBuilder builder)
        {
            builder.AppendLine("        {");
            builder.AppendFormat("            \"NAME\" : \"{0}\",", locale.Name).AppendLine();
            builder.AppendFormat("            \"REACTION_COUNT\" : {0},", locale.ReactionCount).AppendLine();
            builder.AppendLine("            \"REACTIONS\" : [");
            int count = 0;

            foreach (var reaction in locale.Reactions)
            {
                WriteReactionInformation(reaction, builder);
                if (++count < locale.ReactionCount)
                {
                    builder.AppendLine(",");
                }
                else
                {
                    builder.AppendLine();
                }
            }
            builder.AppendLine("            ]");
            builder.Append("        }");
        }