コード例 #1
0
        /// <summary>
        /// Reads the "stuff" file from the given XmlWorldData.
        /// </summary>
        /// <param name="xmlWorldData"></param>
        /// <param name="gameThingList"></param>
        /// <returns>true on success, false on failure</returns>
        public bool ReadFromXml(XmlWorldData xmlWorldData, InGame.AddThingDelegate AddThing)
        {
            bool success = true;

            // Clear any existing paths.
            WayPoint.ClearPaths();

            // Read the Xml file into local data.
            XmlLevelData data;

            try
            {
                data = Load(BokuGame.Settings.MediaPath + xmlWorldData.stuffFilename, XnaStorageHelper.Instance);
            }
            catch
            {
#if !NETFX_CORE
                Debug.Print("Fail to read file " + BokuGame.Settings.MediaPath + xmlWorldData.stuffFilename);
#endif
                data    = null;
                success = false;
            }

            if (data != null)
            {
                this.waypoints = data.waypoints;
                this.actor     = data.actor;

                data = null;

                ToGame(AddThing);
            }

            return(success);
        }   // end of XmlLevelData ReadFromXml()
コード例 #2
0
        }   // end of FromGame()

        /// <summary>
        /// Hand off copies the objects in this XmlLevelData object
        /// into AddThing.
        /// </summary>
        /// <param name="gameThingList"></param>
        public void ToGame(InGame.AddThingDelegate AddThing)
        {
            WayPoint.ClearPaths();

            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            // Copy local data to sim classes.

            // Copy waypoint data to sim classes.

            // In with the new.
            for (int i = 0; i < waypoints.paths.Count; i++)
            {
                XmlData.Path  p    = (XmlData.Path)waypoints.paths[i];
                WayPoint.Path path = new WayPoint.Path(p.color);
                path.RoadName = p.roadName;

                // Create nodes.
                for (int j = 0; j < p.nodes.Count; j++)
                {
                    XmlData.Node  n    = (XmlData.Node)p.nodes[j];
                    WayPoint.Node node = new WayPoint.Node(path, new Vector3(n.position, n.height));
                }

                // Create edges.
                for (int j = 0; j < p.edges.Count; j++)
                {
                    XmlData.Edge  e  = (XmlData.Edge)p.edges[j];
                    WayPoint.Node n0 = (WayPoint.Node)path.Nodes[e.node0];
                    WayPoint.Node n1 = (WayPoint.Node)path.Nodes[e.node1];
                    WayPoint.CreateNewEdge(n0, n1, (WayPoint.Edge.Direction)e.direction);
                }

                path.RecalcHeights(onLoad: true);
                if (path.Road != null)
                {
                    path.Road.Build();
                }
            }

            for (int i = 0; i < actor.Count; ++i)
            {
                XmlData.Actor srcActor = (XmlData.Actor)actor[i];
                GameActor     dstActor = ActorFromString(srcActor.typename);
                if (dstActor != null)
                {
                    srcActor.ToActor(dstActor);

                    dstActor = (GameActor)AddThing(dstActor);
                    if (dstActor != null)
                    {
                        // Init InsideGlassWalls.
                        // TODO (****) Right now we're doing this by checking the height of the terrain.
                        // We should also be able to do this by checking the material index BUT it appears
                        // that when we erase terrain we only set the height to 0 without resetting the material.
                        // I think...
                        dstActor.Chassis.InsideGlassWalls = Terrain.GetTerrainAndPathHeight(dstActor.Movement.Position) > 0;
                    }
                }
            }
        }   // end of ToGame()