Beispiel #1
0
        private void SaveRoom(string file)
        {
            window.Title = file;

            FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write);


            RoomDefinition room = new RoomDefinition();

            if (northDoor != null)
            {
                room.northDoor = true;
            }
            if (eastDoor != null)
            {
                room.eastDoor = true;
            }
            if (southDoor != null)
            {
                room.southDoor = true;
            }
            if (westDoor != null)
            {
                room.westDoor = true;
            }
            room.roomRarity = cmbRarity.SelectedIndex;
            room.roomType   = cmbRoomType.SelectedIndex;
            room.roomFloor  = cmbFloorType.SelectedIndex;

            SpawnGroupDefinition g = new SpawnGroupDefinition();

            //Update the following when spawn groups are implemented:
            foreach (Mesh d in floorLayer)
            {
                g.meshes.Add(new MeshDefinition()
                {
                    x = d.WorldOriginX, y = d.WorldOriginY, staticMesh = d.MeshType, rotation = d.Angle
                });
            }

            foreach (Mesh d in wallLayer)
            {
                g.meshes.Add(new MeshDefinition()
                {
                    x = d.WorldOriginX, y = d.WorldOriginY, staticMesh = d.MeshType, rotation = d.Angle
                });
            }

            //foreach (Mesh d in stuffLayer)
            //{
            //    g.meshes.Add(new MeshDefinition() { x = d.WorldOriginX, y = d.WorldOriginY, staticMesh = d.MeshType, rotation = d.Angle });
            //}



            foreach (Light d in lightsLayer)
            {
                g.lights.Add(new LightDefinition()
                {
                    x = d.WorldOriginX, y = d.WorldOriginY, radius = d.Radius
                });
            }

            foreach (DraggableGridSnapper d in stuffLayer)
            {
                if (d is Item)
                {
                    g.items.Add(new ItemDefinition()
                    {
                        x = d.WorldOriginX, y = d.WorldOriginY
                    });
                }
                else if (d is Guard)
                {
                    g.guards.Add(new GuardDefinition()
                    {
                        x = d.WorldOriginX, y = d.WorldOriginY, patrolRouteIndex = ((Guard)d).PatrolRouteIndex, startIndex = ((Guard)d).StartIndex, rotation = d.Angle
                    });
                }
                else if (d is Camera)
                {
                    g.cameras.Add(new CameraDefinition()
                    {
                        x = d.WorldOriginX, y = d.WorldOriginY, rotation = d.Angle
                    });
                }
                else if (d is Mesh)
                {
                    g.meshes.Add(new MeshDefinition()
                    {
                        x = d.WorldOriginX, y = d.WorldOriginY, staticMesh = ((Mesh)d).MeshType, rotation = d.Angle
                    });
                }
            }

            room.spawnGroups.Add(g);

            List <PatrolRouteDefinition> patrolRouteDefs = new List <PatrolRouteDefinition>();

            foreach (var pr in patrolRoutes)
            {
                patrolRouteDefs.Add(new PatrolRouteDefinition());
                foreach (PatrolPoint p in pr)
                {
                    patrolRouteDefs[patrolRouteDefs.Count - 1].patrolPoints.Add(new PatrolPointDefinition()
                    {
                        x = p.WorldOriginX, y = p.WorldOriginY
                    });
                }
            }
            room.patrolRoutes = patrolRouteDefs;

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RoomDefinition));

            serializer.WriteObject(fs, room);

            fs.Close();
        }
Beispiel #2
0
        private void LoadRoom(string file)
        {
            Clear();

            window.Title = file;

            FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RoomDefinition));
            RoomDefinition             room       = (RoomDefinition)serializer.ReadObject(fs);

            cmbRoomType.SelectedIndex  = room.roomType;
            cmbRarity.SelectedIndex    = room.roomRarity;
            cmbFloorType.SelectedIndex = room.roomFloor;


            if (room.northDoor)
            {
                //chkNorth_Checked(this, new RoutedEventArgs());
                chkNorth.IsChecked = true;
            }
            if (room.eastDoor)
            {
                //chkEast_Checked(this, new RoutedEventArgs());
                chkEast.IsChecked = true;
            }
            if (room.southDoor)
            {
                //chkSouth_Checked(this, new RoutedEventArgs());
                chkSouth.IsChecked = true;
            }
            if (room.westDoor)
            {
                //chkWest_Checked(this, new RoutedEventArgs());
                chkWest.IsChecked = true;
            }

            foreach (PatrolRouteDefinition prd in room.patrolRoutes)
            {
                ObservableCollection <PatrolPoint> pr = new ObservableCollection <PatrolPoint>();
                patrolRoutes.Add(pr);
                patrolRouteIndices.Add(patrolRoutes.Count);
                foreach (PatrolPointDefinition ppd in prd.patrolPoints)
                {
                    PatrolPoint pp = new PatrolPoint();
                    pp.Init(this);
                    canvasRoom.Children.Add(pp);
                    stuffLayer.Add(pp);
                    pp.WorldOriginX            = ppd.x;
                    pp.WorldOriginY            = ppd.y;
                    pp.cmbRoutes.SelectedIndex = patrolRoutes.Count - 1;
                }
            }


            foreach (SpawnGroupDefinition sgd in room.spawnGroups)
            {
                foreach (MeshDefinition md in sgd.meshes)
                {
                    if (md.staticMesh == "floor")
                    {
                        Mesh f = MeshFactory.MakeFloor(this);
                        f.Init(this);
                        canvasRoom.Children.Add(f);
                        floorLayer.Add(f);
                        f.WorldOriginX = md.x;
                        f.WorldOriginY = md.y;
                        f.Angle        = md.rotation;
                    }
                    else if (md.staticMesh == "wall400")
                    {
                        Mesh w = MeshFactory.MakeHorizontalWall400(this);
                        w.Init(this);
                        canvasRoom.Children.Add(w);
                        wallLayer.Add(w);
                        w.WorldOriginX = md.x;
                        w.WorldOriginY = md.y;
                        w.Angle        = md.rotation;
                        if (w.Angle != 0.0)
                        {
                            w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap;
                        }
                    }
                    else if (md.staticMesh == "wall200")
                    {
                        Mesh w = MeshFactory.MakeHorizontalWall200(this);
                        w.Init(this);
                        canvasRoom.Children.Add(w);
                        wallLayer.Add(w);
                        w.WorldOriginX = md.x;
                        w.WorldOriginY = md.y;
                        w.Angle        = md.rotation;
                        if (w.Angle != 0.0)
                        {
                            w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap;
                        }
                    }
                    else if (md.staticMesh == "wall100")
                    {
                        Mesh w = MeshFactory.MakeHorizontalWall100(this);
                        w.Init(this);
                        canvasRoom.Children.Add(w);
                        wallLayer.Add(w);
                        w.WorldOriginX = md.x;
                        w.WorldOriginY = md.y;
                        w.Angle        = md.rotation;
                        if (w.Angle != 0.0)
                        {
                            w.snapMode = DraggableGridSnapper.SnapMode.VerticalLineSnap;
                        }
                    }
                    else
                    {
                        foreach (CustomMesh cm in cmbObjects.Items)
                        {
                            if (cm.assetName == md.staticMesh)
                            {
                                Mesh m = MeshFactory.MakeCustomMesh(cm, this);
                                canvasRoom.Children.Add(m);
                                stuffLayer.Add(m);
                                m.WorldOriginX = md.x;
                                m.WorldOriginY = md.y;
                                m.Angle        = md.rotation;
                                break;
                            }
                        }
                    }
                }
                foreach (ItemDefinition id in sgd.items)
                {
                    Item i = new Item();
                    i.Init(this);
                    canvasRoom.Children.Add(i);
                    stuffLayer.Add(i);
                    i.WorldOriginX = id.x;
                    i.WorldOriginY = id.y;
                }

                foreach (GuardDefinition gd in sgd.guards)
                {
                    Guard g = new Guard();
                    g.Init(this);
                    canvasRoom.Children.Add(g);
                    stuffLayer.Add(g);
                    g.WorldOriginX            = gd.x;
                    g.WorldOriginY            = gd.y;
                    g.Angle                   = gd.rotation;
                    g.cmbRoutes.SelectedIndex = gd.patrolRouteIndex;
                    g.cmbStart.SelectedIndex  = gd.startIndex;
                }
                foreach (CameraDefinition cd in sgd.cameras)
                {
                    Camera c = new Camera();
                    c.Init(this);
                    canvasRoom.Children.Add(c);
                    stuffLayer.Add(c);
                    c.WorldOriginX = cd.x;
                    c.WorldOriginY = cd.y;
                    c.Angle        = cd.rotation;
                }

                if (sgd.lights != null)
                {
                    foreach (LightDefinition ld in sgd.lights)
                    {
                        Light l = new Light();
                        l.Init(this);
                        canvasRoom.Children.Add(l);
                        lightsLayer.Add(l);
                        l.WorldOriginX = ld.x;
                        l.WorldOriginY = ld.y;
                        l.Radius       = ld.radius;
                    }
                }
            }

            fs.Close();

            EnableStuffLayer();
        }