예제 #1
0
        public void Save()
        {
            SaveFile saveFile = new SaveFile("data/houses");
            Node houses = new Node("houses");
            foreach (KeyValuePair<string, House> house in this.houses)
            {
                Node playername = new Node(house.Key);
                playername.AddNode("x", new Node(house.Value.x.ToString()));
                playername.AddNode("y", new Node(house.Value.y.ToString()));
                playername.AddNode("type", new Node(house.Value.houseType.Name));

                if (house.Value.Furniture.Count > 0)
                {
                    Node furniture = new Node("furniture");
                    foreach (KeyValuePair<BlockPos, Furniture> f in house.Value.Furniture)
                    {
                        Node furnitureKey = new Node(f.Key.X + "|" + f.Key.Y);
                        furnitureKey.AddNode("x", new Node(f.Key.X.ToString()));
                        furnitureKey.AddNode("y", new Node(f.Key.Y.ToString()));
                        furnitureKey.AddNode("type", new Node(f.Value.Type));
                        furniture.AddNode(f.Key.X + "|" + f.Key.Y, furnitureKey);
                    }
                    playername.AddNode("furniture", furniture);
                }
                houses.AddNode(house.Key, playername);
            }
            saveFile.AddNode("houses", houses);
            saveFile.Save();
        }
예제 #2
0
        public void Save()
        {
            lock (saveloadLockObject)
            {
                if (!Directory.Exists(@"data\)"))
                    Directory.CreateDirectory(@"data\");

                string dataPath = @"data\" + player.Name;
                SaveFile saveFile = new SaveFile(dataPath);
                inventory.Save(saveFile);

                Node playerData = new Node("playerdata");
                playerData.AddNode("digxp", new Node(xp.ToString()));
                playerData.AddNode("digmoney", new Node(digMoney_.ToString()));
                saveFile.AddNode("playerdata", playerData);

                saveFile.Save();

                /*IFormatter formatter = new BinaryFormatter();
                Stream stream = new FileStream(dataPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                formatter.Serialize(stream, digXp);
                formatter.Serialize(stream, digMoney);
                stream.Close();*/
            }
        }