// adds a savepoint that can be retrieved with RetrieveSavePoint() public static void AddSavePoint(LevelData levelData) { // add the value to the existing value undoId += 1; Inventory inventory = Inventory.CreateCopy(ProgressManager.GetProgress().unlocks.inventory); savePoint = new UndoPoint(undoId, levelData, inventory); AddUndoPoint(); onSavePointChange.Invoke(); LevelLoader.SaveCustomLevel(levelData); }
// set the level to a certian undopoint private static bool RestoreUndoPoint(int id) { UndoPoint undoPoint = undoPoints.Find(x => x.id == id); Debug.Log("RestoreUndoPoint " + id); if (undoPoint != null) { ProgressManager.GetProgress().unlocks.SetInventory(undoPoint.inventory); VertHandler._instance.DestroyHandles(); LevelPlacer._instance.Place(undoPoint.levelData); LevelEditor.editLevel = undoPoint.levelData; return(true); } return(false); }
// adds an undo point, a copy of the current editotlevel, to the hastable and throws the oldest one away if neccessary. // also adds an inventory savepoint that corresponds to the editorlevel getting saved public static void AddUndoPoint() { LevelData levelData = LevelEditor.CreateLevelData(); Inventory inventory = Inventory.CreateCopy(ProgressManager.GetProgress().unlocks.inventory); undoId += 1; UndoPoint oldUndoPoint = undoPoints.Find(x => x.id == undoId); //Debug.Log("AddUndoPoint " + undoId + "inventory turrets: " + inventory.GetAmount(LevelObjects.LevelObject.ObjectType.turret)); // there is already an undo point with the id we want to add if (oldUndoPoint != null) { // remove that old f****r (jk) undoPoints.Remove(oldUndoPoint); } // add the new undo Point UndoPoint newUndoPoint = new UndoPoint(undoId, levelData, inventory); undoPoints.Add(newUndoPoint); onSavePointChange.Invoke(); // if there are too many saves, delete the last one if (undoPoints.Count > maxUndoSaves) { // find the lowest value key int lowest = 1000000; foreach (UndoPoint undo in undoPoints) { if (undo.id < lowest) { lowest = undo.id; } } undoPoints.Remove(undoPoints.Find(x => x.id == lowest)); } // Debug.Log("Added AddUndoPoint " + undoId + "inventory turrets: " + undoPoints.Find(x => x.id == undoId).inventory.GetAmount(LevelObjects.LevelObject.ObjectType.turret)); }
private static int maxUndoSaves = 10; // setting menu option private void Start() { undoPoints = new List <UndoPoint>(); savePoint = null; undoId = 0; }