public void AddWorld(World world)
        {
            lock(this.worlds)
            {
                if(this.worlds.ContainsKey (world.Name))
                    throw new WorldAlreadyExistsException (world.Name);

                this.worlds.Add (world.Name, world);
            }
        }
Пример #2
0
        public IEnumerable<World> GetWorlds(Uri location)
        {
            if(!location.IsFile)
                throw new ArgumentException("World location must be a file on the local system.");
            else if(!new FileInfo(location.LocalPath).Exists)
                throw new FileNotFoundException("The world file was not found.");

            List<World> worlds = new List<World>();

            XmlDocument doc = new XmlDocument();
            doc.Load(location.LocalPath);

            XmlNodeList worldNodesParent = doc.GetElementsByTagName("Worlds");

            foreach(XmlNode worldNodes in worldNodesParent)
            {
                foreach(XmlNode worldNode in worldNodes)
                {
                    World world = new World(worldNode.Attributes.GetNamedItem("Name").InnerText);

                    foreach(XmlNode node in worldNode.ChildNodes)
                    {
                        if(node.Name == "MapLoc")
                        {
                            /* Load the map header from an XML node */

                            string mapname = string.Empty;
                            string mappath = string.Empty;
                            int x = 0, y = 0;

                            foreach(XmlNode cnode in node.ChildNodes)
                            {
                                if(cnode.Name == "Name")
                                    mapname = cnode.InnerText;
                                else if(cnode.Name == "Uri")
                                    mappath =  cnode.InnerText;
                                else if(cnode.Name == "X")
                                    x = Convert.ToInt32(cnode.InnerText);
                                else if(cnode.Name == "Y")
                                    y = Convert.ToInt32(cnode.InnerText);
                            }

                            MapHeader header = new MapHeader(mapname, new MapPoint(x, y), mappath);

                            world.AddMap(header);
                        }
                    }

                    worlds.Add(world);
                }
            }

            return worlds;
        }
Пример #3
0
        public static void SetCurrentMap(Map map)
        {
            if (map == null)
                throw new ArgumentNullException("map");

            GameInstance.Engine.WorldManager.ClearWorlds();

            MapEditorManager.CurrentMap = map;

            MapHeader header = new MapHeader(map.Name, new MapPoint(0, 0), string.Empty);
            header.Map = map;

            World world = new World("Default");
            world.AddMap(header);

            GameInstance.Engine.WorldManager.AddWorld(world);

            var camera = GameInstance.Engine.SceneProvider.Cameras.GetItems().FirstOrDefault().Value;
            if (camera != null)
            {
                camera.CenterOriginOnPoint(0, 0);
                camera.CurrentMap = header;
            }

            ActionManager.Reset();
        }