Example #1
0
 public override void saveState(object state)
 {
     UndoMemento memento = new UndoMemento()
     {
         State = new Computer(this.Name, this.X, this.Y, this.Width, this.Height, this.Type)
     };
 }
Example #2
0
    public override UndoMemento changeProperty(object state)
    {
        UndoMemento memento = new UndoMemento()
        {
            State = new Computer(this.Name, this.X, this.Y, this.Width, this.Height, this.Type)
        };

        X = x;
        Y = y;
        return(memento);
    }
Example #3
0
    public UndoMemento ChangeType(string type)
    {
        UndoMemento memento = new UndoMemento()
        {
            State = new TypeClass()
            {
                type = this.Type
            }, Command = new Action <object>(UndoChangeType)
        };

        Type = type;
        return(memento);
    }
Example #4
0
    public UndoMemento ChangeSize(double width, double height)
    {
        UndoMemento memento = new UndoMemento()
        {
            State = new Size()
            {
                Width = this.Width, Height = this.Height
            }, Command = new Action <object>(UndoChangeSize)
        };

        Width  = width;
        Height = height;
        return(memento);
    }
Example #5
0
    // The method to change the object state and perform operation but also externalize the previous state
    public UndoMemento ChangePosition(double x, double y)
    {
        UndoMemento memento = new UndoMemento()
        {
            State = new Position()
            {
                X = this.X, Y = this.Y
            }, Command = new Action <object>(UndoChangePosition)
        };

        X = x;
        Y = y;
        return(memento);
    }
Example #6
0
 public void swapUndo()
 {
     //Debug.Log("swapUndo:" + objectToUndo.name);
     //Debug.Log(oppositeUndoMemento == null);
     if (oppositeUndoMemento == null)
     {
         oppositeUndoMemento = createMementoFunc();
         oppositeUndoMemento.save(objectToUndo);
     }
     undoMemento.restore(objectToUndo);
     var lTemp = undoMemento;
     undoMemento = oppositeUndoMemento;
     oppositeUndoMemento = lTemp;
     //Debug.Log(oppositeUndoMemento == null);
 }
Example #7
0
 public UndoObject(Object pObjectToUndo, System.Func<UndoMemento> pCreateMementoFunc)
 {
     //Debug.Log("UndoObject:" + pObjectToUndo.name);
     createMementoFunc = pCreateMementoFunc;
     objectToUndo = pObjectToUndo;
     undoMemento = createMementoFunc();
     undoMemento.save(objectToUndo);
     oppositeUndoMemento = null;
 }