コード例 #1
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()
コード例 #2
0
        /// <summary>
        /// Copies the current state of the objects in
        /// the game to this XmlLevelData object.
        /// </summary>
        /// <param name="gameThingList"></param>
        public void FromGame(List <GameThing> gameThingList)
        {
            waypoints.paths.Clear();

            // Get the WayPoint data.
            for (int i = 0; i < WayPoint.Paths.Count; i++)
            {
                WayPoint.Path path = (WayPoint.Path)WayPoint.Paths[i];
                XmlData.Path  p    = new XmlData.Path();

                // Add path to list.
                waypoints.paths.Add(p);

                // Fill in path data.
                p.color    = path.Color;
                p.roadName = path.RoadName;

                // Copy node info.
                for (int j = 0; j < path.Nodes.Count; j++)
                {
                    WayPoint.Node node = (WayPoint.Node)path.Nodes[j];
                    XmlData.Node  n    = new XmlData.Node();
                    n.position = new Vector2(node.Position.X, node.Position.Y);
                    n.height   = node.Height;
                    p.nodes.Add(n);
                }

                // Copy edge info.
                for (int j = 0; j < path.Edges.Count; j++)
                {
                    WayPoint.Edge edge = (WayPoint.Edge)path.Edges[j];
                    XmlData.Edge  e    = new XmlData.Edge();
                    e.node0     = path.Nodes.IndexOf(edge.Node0);
                    e.node1     = path.Nodes.IndexOf(edge.Node1);
                    e.direction = (int)edge.Dir;
                    p.edges.Add(e);
                }
            }

            // Loop through the gameThingList putting things into the
            // right Xml array for serialization.
            for (int i = 0; i < gameThingList.Count; i++)
            {
                GameActor srcActor = gameThingList[i] as GameActor;

                if (gameThingList[i].GetType() == typeof(Boku.SimWorld.CursorThing))
                {
                    // This space intentionally left blank.
                }
                else if (gameThingList[i].GetType() == Type.GetType("Boku.Fireball"))
                {
                    // This space intentionally left blank.
                }
                else if (gameThingList[i].GetType() == Type.GetType("Boku.CruiseMissile"))
                {
                    // This space intentionally left blank.
                }
                else if (actor != null)
                {
                    XmlData.Actor dstActor = new XmlData.Actor(srcActor.StaticActor.NonLocalizedName);
                    dstActor.FromActor(srcActor);
                    this.actor.Add(dstActor);
                }
                else
                {
                    Debug.Assert(false, @"Trying to serialize unrecognized type.");
                }
            }
        }   // end of FromGame()