Chaos Project

Featured Projects => Tasks => Advanced RPG Creator => Finished Tasks => Topic started by: Ryex on April 09, 2011, 07:45:29 pm

Title: [Finished] [ARCed] Undo/Redo Action Framework
Post by: Ryex on April 09, 2011, 07:45:29 pm
Undo/Redo Action Framework




Description

In order to facilitate the undo and redo functionality of an editor we need to be able to track and reverse changes we make to the project data.
in order to do this we need a Framework that can wrap the functionality.

the framework should consist of two parts

1) A manager:


2) An Action template:





Priority

High



Prerequisites

None



Assigned

None



Everything else

This system should be included in the Core library in it's own module name "Actions". Don't worry about doing the house keeping code to register the system to the Kernel, I'll take care of that.
Title: Re: [Editor] Actions: Undo/Redo framework
Post by: Zeriab on April 10, 2011, 01:40:13 pm
Consider using a doubly-linked list as the structure for recording actions in a sequential manner. You can then go forward and backwards in time (undo/redo) by moving a pointer around the list. It's easier than the hassle of moving data between two data structures.

*hugs*
Title: Re: [Editor] Actions: Undo/Redo framework
Post by: Blizzard on April 10, 2011, 02:14:39 pm
Since we're using Python, a normal Python array will be used for this.
I think a simple data structure with an action ID, the previous state and the new state should be enough for an undo/redo functionality.
Title: Re: Editor Undo/Redo Action Framework
Post by: Ryex on April 10, 2011, 03:13:39 pm
I'm not sure what your saying.I thought that two lists was pretty simple
Title: Re: Editor Undo/Redo Action Framework
Post by: ForeverZer0 on April 10, 2011, 03:22:22 pm
* I think * what he means is each action has an ID, and is stored in array. Then when the Undo is executed, it simply goes back through the array, reads the ID and then knows what protocol to use to make the action.
Title: Re: [ARCed] Undo/Redo Action Framework
Post by: Ryex on October 09, 2011, 07:35:49 pm
Alright, G_G I was hoping that you would be the one to do this but we can't wait any longer. I'm going to do it tonight. I'll probably finish it too. if you've done ANY work on it commit the work as it will likely save me time.
Title: Re: [Finished] [ARCed] Undo/Redo Action Framework
Post by: Ryex on October 10, 2011, 07:14:36 pm
ok
Action framework done
to create an action you subclass the ActionTemplate class from the Action.py in the Core
the init method should take any data that the action need to know in order to change data in the project. it should also call the __init__ method of the super class
super(<classname>, self).__init__()

the subclass should then define a "do_apply" method (no arguments) that will a)record data in the project necessary for the action to be undone and b) set the new data in the project
then the action needs to have a "do_undo" method (no arguments) that will a)record data so the action can be redone and b) use recorded data from the do_apply method to undo the action
the recorded data can be recorded to the action object itself
Title: Re: [Finished] [ARCed] Undo/Redo Action Framework
Post by: ForeverZer0 on October 10, 2011, 07:29:57 pm
You so sexy.

The pieces of the editor are coming along nicely. Now comes the horrible task of linking them all together. :P
Title: Re: [Finished] [ARCed] Undo/Redo Action Framework
Post by: Blizzard on October 11, 2011, 02:25:57 am
I suggest you alias do_apply with do_redo as well. This will make the code easier to read because when you call the event for the redo button, the code will read "action.do_redo".
Title: Re: [Finished] [ARCed] Undo/Redo Action Framework
Post by: Ryex on October 11, 2011, 03:23:41 am
actualy it will read
action.apply()
the apply method of the action class will add the action to the action stack if it not in the stack already and call the do_apply method in the middle in the template class the do_apply method does nothing it just has a simple pass statement. then all we to do to create create an actual action is subclass and make the do_apply and do_undo methods actually do something along with make the init method collect data to carry out the action.

I suppose I'll make one action as an example for how it will work.

also, there is no alias in python. a similar effect can be achieved but we don't need to do that here.
Title: Re: [Finished] [ARCed] Undo/Redo Action Framework
Post by: Blizzard on October 11, 2011, 04:22:56 am
I meant alias in general, not literally Ruby's function. xD

class Woman(object):
   def do(self):
       # hurr hurr hurr code comes here
   def do_again(self):
       self.do()