public void Load() { houses.Clear(); SaveFile saveFile = new SaveFile("data/houses"); saveFile.Load(); Dictionary<string, Node> nodes = saveFile.Nodes; if (nodes.ContainsKey("houses")) { Node houses2 = nodes["houses"]; foreach (KeyValuePair<string, Node> house in houses2.Nodes) { int x = int.Parse(house.Value.Nodes["x"].Value); int y = int.Parse(house.Value.Nodes["y"].Value); string type = house.Value.Nodes["type"].Value; House newhouse = new House(houseTypes[type], house.Key, x, y, houseTypes[type].Width, houseTypes[type].Height); if (house.Value.Nodes.ContainsKey("furniture")) // <furniture> { Node furniture = house.Value.Nodes["furniture"]; foreach (KeyValuePair<string, Node> furnitures in furniture.Nodes) { // <x|y> int furniturex = int.Parse(furnitures.Value.Nodes["x"].Value); int furniturey = int.Parse(furnitures.Value.Nodes["y"].Value); string furnituretype = furnitures.Value.Nodes["type"].Value; Furniture newFurniture = FurnitureManager.FurnitureTypes[furnituretype].FromNode(furnitures.Value); newhouse.Furniture.Add(new BlockPos(0, furniturex, furniturey), newFurniture); } } this.houses.Add(newhouse.builder, newhouse); DrawHouse(newhouse); } } }
public void Load() { lock (saveloadLockObject) { if (!Directory.Exists(@"data\)")) Directory.CreateDirectory(@"data\"); string dataPath = @"data\" + player.Name; if (!File.Exists(dataPath)) return; SaveFile saveFile = new SaveFile(dataPath); saveFile.Load(); if (saveFile.Nodes.ContainsKey("playerdata")) { Node playerData = saveFile.Nodes["playerdata"]; if (playerData.Nodes.ContainsKey("digxp")) xp = float.Parse(playerData.GetNode("digxp").Value); if (playerData.Nodes.ContainsKey("digmoney")) digMoney_ = int.Parse(playerData.GetNode("digmoney").Value); } inventory.Load(saveFile); /*digLevel_ = 0; IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); digXp = (int)formatter.Deserialize(stream); digMoney_ = (int)formatter.Deserialize(stream); stream.Close(); xpRequired = getXpRequired(digLevel);*/ } }