Ejemplo n.º 1
0
        public static string FormatSettingJsonText(Type type, string text)
        {
            string NewLine   = text.Contains("\r\n") ? "\r\n" : "\n";
            string NewIndent = NewLine + Indent;

            foreach (MemberInfo member in type.GetMembers())
            {
                if ((member.MemberType | MemberTypes.Field | MemberTypes.Property) == 0)
                {
                    continue;
                }
                object[] sections = member.GetCustomAttributes(typeof(JsonSection), true);
                object[] comments = member.GetCustomAttributes(typeof(JsonComment), true);
                if (sections.Length <= 0 && comments.Length <= 0)
                {
                    continue;
                }
                string propName  = NewLine + Indent + JsonConvert.ToString(member.Name);
                string injection = "";
                if (sections.Length > 0)
                {
                    injection += NewLine +
                                 NewIndent + "//" +
                                 NewIndent + "// " + (sections[0] as JsonSection)?.Section +
                                 NewIndent + "//" + NewLine +
                                 NewLine;
                }
                if (comments.Length > 0)
                {
                    string[] lines = (comments[0] as JsonComment)?.Comments;
                    // Insert blank line if not new section
                    if (sections.Length <= 0)
                    {
                        injection += NewLine + NewLine;
                    }
                    // Actual property comment
                    if (lines.Length > 1)
                    {
                        injection += Indent + "/* " + lines[0];
                        for (int i = 1, len = lines.Length; i < len; i++)
                        {
                            injection += NewIndent + " * " + lines[i];
                        }
                        injection += " */";
                    }
                    else if (lines.Length > 0)
                    {
                        injection += Indent + "/* " + lines[0] + " */";
                    }
                    injection += NewLine;
                }
                text = BattleModModule.ReplaceFirst(text, propName, injection + propName);
            }
            return(text);
        }
Ejemplo n.º 2
0
 public BattleMod Add(BattleModModule module)
 {
     if (!modules.TryGetValue(this, out List <BattleModModule> list))
     {
         modules.Add(this, list = new List <BattleModModule>());
     }
     if (!list.Contains(module))
     {
         if (module != this)
         {
             if (module.Id == Id)
             {
                 module.Id += "." + Idify(module.Name);
             }
         }
         list.Add(module);
         TryRun(Log, module.ModStarts);
     }
     return(this);
 }