Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / A simple Undo/Redo and History list!

Author
Message
Yodaman Jer
User Banned
Posted: 22nd Nov 2014 18:22 Edited at: 22nd Nov 2014 20:12
For quite a while, I've been wondering how one might go about making an undo/redo list for something like an editor, and last night I had a revelation about it!

When I do buy AppGameKit 2 here in the nearish future, one of the first things I want to do is start coding a tile map editor for my game that I'll want to make. One of the features I'll want the most is the ability to have every action I do recorded (much like the history list in GIMP/Photoshop), and to be able to undo/redo whatever my last action was!

I can't take the credit for this method, as I know tiresius was using it in his level editor for the Marble Maze Construction Set, but I figured out how to implement it in my own way at 3am last night.

The best part is that it can be easily expanded to record actions of any kind. I'm sure there's a better method overall, but this is the program I came up with.

left click to "place a tile", right click to "move" it, press Z for undo and R for redo!



Now, it's not perfect. For example, if you undo an action and then perform an action in the middle of undo list, the redo list will still contain all of the original actions and won't know what to do. What should happen is that if the undo list has a length shorter than that of the redo list and a new action takes place, the redo list should be deleted, and that would solve that problem. I'm too lazy to figure that out though

EDIT: I thought of a way to fix the aforementioned problem! It seems to work very well so far, give it a shot!

Anyway, enjoy! Hope this helps somebody


Meh game development blaugh!
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 22nd Nov 2014 21:12
That's a nice API. How would you handle actions that require more metadata than just a type? (for example, surely undoing Tile Placement requires you to know where the tile was placed)

Yodaman Jer
User Banned
Posted: 22nd Nov 2014 21:27
Easy! You could expand the type that records the data like this...



Then when you're performing the action, you would just tell the program what type of action was done (1 for palce tile, 2 for delete tile, etc.,), and it will know what to record in the list accordingly. For example...



So it would be quite easy, in fact! Another way you could do it (though it would be more intensive) would be to write every action you perform to a temporary file, though you would have to do quite a lot of parsing and that could slow things down majorly!


Meh game development blaugh!
Yodaman Jer
User Banned
Posted: 24th Nov 2014 18:16
I have updated my example!

I'm on a Mac so I can't share the project file, so here's the source code:

main.agc:


constants.agc:


functions.agc:


This is a VERY basic (and messy!) example of how you might store a tile's data in the undo/redo list system. A better example would actually make it so that if you place a tile you can't place a new one on top of it - but like I said, this is a quick example, it's not perfect!

This video I made explains it a bit more in-depth. Apologies for the echoing audio, I really have no idea what happened when I exported from ScreenFlow. It also clips in a few places but it isn't too distracting.




Meh game development blaugh!

Login to post a reply

Server time is: 2024-11-25 11:23:49
Your offset time is: 2024-11-25 11:23:49