private static void CreateSpecialAbilitiesSection(Monster monster, StringBuilder blocks)
        {
            try
            {
                if (monster.SpecialAbilitiesList.Count > 0)
                {
                    blocks.CreateSectionHeader("SPECIAL ABILITIES");

                    blocks.AppendOpenTag("p");


                    foreach (SpecialAbility spec in monster.SpecialAbilitiesList)
                    {
                        if (spec.Name != null && spec.Name.Length > 0)
                        {
                            string type = spec.Type;

                            if (spec.ConstructionPoints != null)
                            {
                                type += ", " + spec.ConstructionPoints + " CP";
                            }

                            blocks.CreateItemIfNotNull(spec.Name + " (" + type + ") "
                                                       , spec.Text);
                        }
                        else
                        {
                            blocks.CreateItemIfNotNull(null, spec.Text);
                        }
                    }

                    blocks.AppendCloseTag("p");
                }
            }
            catch (Exception ex)
            {
                DebugLogger.WriteLine(ex.ToString());
            }
        }
Пример #2
0
        public static T Load(string filename, bool appData)
        {
            T set = default(T);

            lastFile = filename;

#if MONO
            DateTime startTime = DateTime.Now;
            DebugLogger.WriteLine("Loading [" + filename + "]");
#endif

            try
            {
                // Open document
                XmlSerializer serializer = new XmlSerializer(typeof(T));

                serializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);

#if ANDROID
                string       path = filename;
                Stream       io;
                StreamReader fs;
                if (!appData)
                {
                    if (path.StartsWith("/"))
                    {
                        io = File.Open(path, FileMode.Open);
                        fs = new StreamReader(io);
                    }
                    else
                    {
                        io = CoreContext.Context.Assets.Open(path);
                        fs = new StreamReader(io);
                    }
                }
                else
                {
                    path = Path.Combine(AppDataDir, filename);
                    io   = File.Open(path, FileMode.Open);
                    fs   = new StreamReader(io);
                }
                using (io)
                {
                    using (fs)
                    {
#else
                String file = SaveFileName(filename, appData);

                if (new FileInfo(file).Exists)
                {
                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
#endif

                        xmlAttributeErrors = new Dictionary <string, string>();

                        set = (T)serializer.Deserialize(fs);

                        if (xmlAttributeErrors.Count > 0)
                        {
                            DebugLogger.WriteLine("XmlListLoader: " + lastFile);
                            foreach (string st in xmlAttributeErrors.Keys)
                            {
                                DebugLogger.WriteLine(st);
                            }
                        }

#if !ANDROID
                        fs.Close();
#endif
                    }
                }
            }
            catch (Exception ex)
            {
                DebugLogger.WriteLine(ex.ToString());
                if (!appData)
                {
                    throw;
                }
            }

#if MONO
            DebugLogger.WriteLine("Finished [" + filename + "]  Time: " +
                                  (DateTime.Now - startTime).TotalSeconds.ToString() + " secs");
#endif

            return(set);
        }