예제 #1
0
        MapManager()
        {
            this.maps = new Dictionary<int, Map>();
            this.mapInfo = new Dictionary<int, MapInfo>();

            try { xml = new XmlParser("DB/MapInfo.xml"); }
            catch (Exception) { Logger.ShowError("cannot read the MapInfo.xml file.", null); return; }

            XmlNodeList XMLitems = xml.Parse("map");
            Logger.ShowInfo("MapInfo database contains " + XMLitems.Count + " maps.", null);

            for (int i = 0; i < XMLitems.Count; i++)
            {
                Dictionary<string, string> data = new Dictionary<string, string>();
                List<Dictionary<string, string>> heightmaps = new List<Dictionary<string,string>>();

                XmlNodeList childList = XMLitems.Item(i).ChildNodes;
                for (int j = 0; j < childList.Count; j++)
                {
                    if (childList.Item(j).Name.ToLower() == "heightmap")
                    {
                        Dictionary<string, string> tmp = new Dictionary<string,string>();
                        for (int k = 0; k < childList.Item(j).ChildNodes.Count; k++)
                            tmp.Add(childList.Item(j).ChildNodes.Item(k).Name.ToLower(), childList.Item(j).ChildNodes.Item(k).InnerText);
                        heightmaps.Add(tmp);
                    }
                    else
                        data.Add(childList.Item(j).Name.ToLower(), childList.Item(j).InnerText);

                }
                if (!data.ContainsKey("id")) continue;
                if (!data.ContainsKey("name")) continue;

                try
                {
                    MapInfo info = new MapInfo();
                    info.id = int.Parse(data["id"]);
                    info.name = data["name"];
                    if (data.ContainsKey("cattleyamapid"))
                    {
                        info.CattleyaMapID = int.Parse(data["cattleyamapid"]);
                        info.CattleyaX = float.Parse(data["cattleyax"]);
                        info.CattleyaY = float.Parse(data["cattleyay"]);
                        info.CattleyaZ = float.Parse(data["cattleyaz"]);
                    }

                    info.heightmaps = new List<HeightMapInfo>();

                    foreach(Dictionary<string,string> hmap in heightmaps)
                    {
                        try
                        {
                            HeightMapInfo tmpInf = new HeightMapInfo();

                            tmpInf.name = hmap["name"];
                            tmpInf.size = int.Parse(hmap["size"]);
                            tmpInf.location = new float[3];
                            tmpInf.location[0] = float.Parse(hmap["x"]);
                            tmpInf.location[1] = float.Parse(hmap["y"]);
                            tmpInf.location[2] = float.Parse(hmap["z"]);
                            tmpInf.scale = new int[3];
                            tmpInf.scale[0] = int.Parse(hmap["scale-x"]);
                            tmpInf.scale[1] = int.Parse(hmap["scale-y"]);
                            tmpInf.scale[2] = int.Parse(hmap["scale-z"]);
                            if (hmap.ContainsKey("waterlevel")) tmpInf.water_level = float.Parse(hmap["waterlevel"]);

                            info.heightmaps.Add(tmpInf);

                        }
                        catch (Exception ex) {
                            Logger.ShowError("Cannot read heightmap info", null);
                            Logger.ShowError(ex, null);
                        }
                    }

                    this.mapInfo.Add(info.id, info);
                }
                catch (Exception e) { Logger.ShowError(" cannot parse mapInfo of map: " + data["id"], null); Logger.ShowError(e, null); continue; }
            }
            xml = null;
        }
예제 #2
0
파일: MapManager.cs 프로젝트: xxlio109/Saga
        MapManager()
        {
            this.maps    = new Dictionary <int, Map>();
            this.mapInfo = new Dictionary <int, MapInfo>();

            try { xml = new XmlParser("DB/MapInfo.xml"); }
            catch (Exception) { Logger.ShowError("cannot read the MapInfo.xml file.", null); return; }

            XmlNodeList XMLitems = xml.Parse("map");

            Logger.ShowInfo("MapInfo database contains " + XMLitems.Count + " maps.", null);

            for (int i = 0; i < XMLitems.Count; i++)
            {
                Dictionary <string, string>         data       = new Dictionary <string, string>();
                List <Dictionary <string, string> > heightmaps = new List <Dictionary <string, string> >();

                XmlNodeList childList = XMLitems.Item(i).ChildNodes;
                for (int j = 0; j < childList.Count; j++)
                {
                    if (childList.Item(j).Name.ToLower() == "heightmap")
                    {
                        Dictionary <string, string> tmp = new Dictionary <string, string>();
                        for (int k = 0; k < childList.Item(j).ChildNodes.Count; k++)
                        {
                            tmp.Add(childList.Item(j).ChildNodes.Item(k).Name.ToLower(), childList.Item(j).ChildNodes.Item(k).InnerText);
                        }
                        heightmaps.Add(tmp);
                    }
                    else
                    {
                        data.Add(childList.Item(j).Name.ToLower(), childList.Item(j).InnerText);
                    }
                }
                if (!data.ContainsKey("id"))
                {
                    continue;
                }
                if (!data.ContainsKey("name"))
                {
                    continue;
                }

                try
                {
                    MapInfo info = new MapInfo();
                    info.id   = int.Parse(data["id"]);
                    info.name = data["name"];
                    if (data.ContainsKey("cattleyamapid"))
                    {
                        info.CattleyaMapID = int.Parse(data["cattleyamapid"]);
                        info.CattleyaX     = float.Parse(data["cattleyax"]);
                        info.CattleyaY     = float.Parse(data["cattleyay"]);
                        info.CattleyaZ     = float.Parse(data["cattleyaz"]);
                    }

                    info.heightmaps = new List <HeightMapInfo>();

                    foreach (Dictionary <string, string> hmap in heightmaps)
                    {
                        try
                        {
                            HeightMapInfo tmpInf = new HeightMapInfo();

                            tmpInf.name        = hmap["name"];
                            tmpInf.size        = int.Parse(hmap["size"]);
                            tmpInf.location    = new float[3];
                            tmpInf.location[0] = float.Parse(hmap["x"]);
                            tmpInf.location[1] = float.Parse(hmap["y"]);
                            tmpInf.location[2] = float.Parse(hmap["z"]);
                            tmpInf.scale       = new int[3];
                            tmpInf.scale[0]    = int.Parse(hmap["scale-x"]);
                            tmpInf.scale[1]    = int.Parse(hmap["scale-y"]);
                            tmpInf.scale[2]    = int.Parse(hmap["scale-z"]);
                            if (hmap.ContainsKey("waterlevel"))
                            {
                                tmpInf.water_level = float.Parse(hmap["waterlevel"]);
                            }

                            info.heightmaps.Add(tmpInf);
                        }
                        catch (Exception ex) {
                            Logger.ShowError("Cannot read heightmap info", null);
                            Logger.ShowError(ex, null);
                        }
                    }

                    this.mapInfo.Add(info.id, info);
                }
                catch (Exception e) { Logger.ShowError(" cannot parse mapInfo of map: " + data["id"], null); Logger.ShowError(e, null); continue; }
            }
            xml = null;
        }