コード例 #1
0
        public void ParseLocal(string filename)
        {
            IniFile ini = new IniFile(filename);

            string[] section_names = ini.GetSectionNames();

            List <string> ignored_assets = new List <string>();

            foreach (string sec in section_names)
            {
                string entry_type = sec.Split(':')[0];
                string name       = sec.Split(':')[1];

                Asset asset = null;

                if (entry_type == Asset.AssetType.biome.ToString())
                {
                    BiomeAsset biomeAsset = new BiomeAsset(name);
                    biomeAsset.LoadFrom(ini);
                    asset = biomeAsset;
                }
                if (entry_type == Asset.AssetType.tile.ToString())
                {
                    TileAsset tileAsset = new TileAsset(name);
                    tileAsset.LoadFrom(ini);
                    asset = tileAsset;
                }
                if (entry_type == Asset.AssetType.item.ToString())
                {
                    ItemAsset itemAsset = new ItemAsset(name);
                    itemAsset.LoadFrom(ini);
                    asset = itemAsset;
                }

                if (asset != null)
                {
                    this.AddNew(asset);
                }
                else
                {
                    ignored_assets.Add(sec);
                }
            }

            if (ignored_assets.Count > 0)
            {
                FileInfo file     = new FileInfo(filename);
                string   errormsg = file.Name + ": " + "Following assets could not be loaded, because parser for their type is either not present or not working:\n\n";

                foreach (string s in ignored_assets)
                {
                    errormsg += s + ", ";
                }

                errormsg = errormsg.Substring(0, errormsg.Length - 2);

                ui.MessageBox.Show(errormsg + "\n", ui.MessageBox.Buttons.OK);
            }
        }