예제 #1
0
        public static void game_save(string path, bool sysSave = false)
        {
            if (currentRoom != null)
            {
                Root root = new Root();

                foreach (RoomLayer r in currentRoom.Layers)
                {
                    if (r is ObjectLayer)
                    {
                        foreach (GameObject go in ((ObjectLayer)r).Objects)
                        {
                            go.EvtSave();
                            root.Objects.Add(go);
                        }
                    }

                    if (r is TileLayer)
                    {
                        foreach (Tile t in ((TileLayer)r).Tiles)
                        {
                            root.Tiles.Add(t);
                        }
                    }
                }

                GameRoom gr =
                    (GameRoom)Activator.CreateInstance(
                        Type.GetType(("SimplexResources.Rooms." + Form1.activeRoom.Text)));
                root.Room = gr;

                XmlSerializer ser = new XmlSerializer(typeof(Root), Form1.reflectedTypes.ToArray());

                // Create (nested) folders when needed
                // to prevent can't write file to nonexsiting folder error
                FileInfo file = new FileInfo(path);
                file.Directory?.Create();

                using (TextWriter w = new StreamWriter(path))
                {
                    ser.Serialize(w, root);
                }
            }
        }
예제 #2
0
        public static void room_goto(Type room)
        {
            // First (again) but I've tackled down later
            // we
            // need
            // to
            // weed... no! We need to check if current room is persistent
            // and if that's the case well then boy.. we gonna create a shadow copy of it
            // saving state of it for later (overwrite if needed

            // R u persistent madafaka?
            if (currentRoom != null && currentRoom.Persistent)
            {
                // Save teh bitch
                game_save("temp_" + currentRoom.GetType().ToString().Split('.').Last() + ".sav");
            }

            // Now we check if the next room is persistent
            // true --> load shadow copy of that room if it exists, otherwise create it from an actual copy
            // false --> load common copy

            // Instantiate that room to see what's inside
            GameRoom tempRoom   = (GameRoom)Activator.CreateInstance(room);
            string   mapContent = Path.Combine(RoomEditor.editorForm.currentProject.RootPath, @"\Maps\" + tempRoom.GetType().ToString().Split('.').Last());

            // Store persistent objects
            List <GameObject> persistentObjects = SceneObjects.Where(x => x.Persistent).ToList();

            if (tempRoom.Persistent)
            {
                // TODO
            }
            else
            {
                Form1.activeRoom = RoomEditor.roomsControl.dtv.Nodes[0].Nodes.FirstOrDefault(x => x.Text == tempRoom.GetType().ToString().Split('.').Last());
                RoomEditor.editorForm.setStatusBottom("Editing " + Form1.activeRoom.Text);
                game_load(mapContent);


                // Also we need to assign them all to appropriate layers
                foreach (GameObject go in persistentObjects)
                {
                    if (go.PersistentLayer == "")
                    {
                        // Try to find first ObjectLayer
                        ObjectLayer ol = (ObjectLayer)RoomEditor.currentRoom.Layers.FirstOrDefault(x => x is ObjectLayer);

                        if (ol != null)
                        {
                            go.Layer = ol;

                            go.LayerName = go.Layer.Name;
                            go.Layer.Objects.Add(go);
                            sh.RegisterObject(go);
                        }
                    }
                }

                SceneObjects.AddRange(persistentObjects);
            }
        }