public List <TileEntitySceneObject> LoadSceneObjects(string mapID) { string mapJson = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/HellscapeDebug/save/001/" + mapID + ".json"); List <MapLoaderSceneObject> mapObjects = JsonConvert.DeserializeObject <List <MapLoaderSceneObject> >(mapJson); if (mapJson != "") { foreach (MapLoaderSceneObject o in mapObjects) { TileEntitySceneObject newTileObject = new TileEntitySceneObject(o); SceneObjects.Add(newTileObject); } } return(SceneObjects); }
public void SaveSceneObjects(string mapID, List <TileEntitySceneObject> tileSceneObjects) { if (tileSceneObjects.Count > 0) { List <MapLoaderSceneObject> mapObjects = new List <MapLoaderSceneObject>(); for (int i = tileSceneObjects.Count - 1; i >= 0; i--) { TileEntitySceneObject obj = tileSceneObjects.ElementAt(i); mapObjects.Add(new MapLoaderSceneObject(obj.Object.ShortName, obj.Position.X, obj.Position.Y, obj.Quantity)); tileSceneObjects.RemoveAt(i); } string jsonSaveString = JsonConvert.SerializeObject(mapObjects, Formatting.Indented); File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/HellscapeDebug/save/001/" + mapID + ".json", jsonSaveString); } else { File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/HellscapeDebug/save/001/" + mapID + ".json", ""); } }
public bool AddItem(TileEntitySceneObject item) { // There's still room in the Inventory if the Max Slot is not filled foreach (InventoryItem ii in Items) { if (ii.Item.ShortName == "nullItem") { //Inventory has open slot, just add ii.Replace(item.Object, item.Quantity); return(true); } else if (ii.Item == item.Object) { // Items are the same, compare quantity if (ii.Quantity + item.Quantity <= item.Object.MaxQuantity) { ii.SetQuantity(ii.Quantity + item.Quantity); return(true); } else { if (Items.Count < MaxSlots) { int toFillQuantity = item.Object.MaxQuantity - ii.Quantity; int remainder = item.Quantity - toFillQuantity; ii.SetQuantity(item.Object.MaxQuantity); Items.Add(new InventoryItem(item.Object, remainder)); return(true); } } } } //Add Item Failed, Display Dialog here when implemented for "Not Enough Space" return(false); }
public void RemoveTileSceneObject(TileEntitySceneObject obj) { TileSceneObjects.Remove(obj); }