četvrtak, 14. kolovoza 2014.

Saving game

Another long pause on the blog but don't think it was equally long pause on the project! I've been working on save and load features and let's say I took longer road. Last time I was coding it, it was done in less then a week but it was boring copy-paste labor. For each chunk of data there was almost identical peace of code. It was OK once written but future edits got more prone to errors, adding new property (a piece of data) meant also ensuring that the property is saved and loaded properly and there was no mechanism that ensured that. This time I've made such mechanism and I must complain it was neither easy nor smooth.

Programmer rant:

I've made it with T4 which is kind of metawriting tool for writing code that generates text or in my case code. I've made text template with helper stuff for describing properties and classes and used it on each state data class. Each state data class is described by two or three files: text template filled with information about the class (which properties are there, how do they behave, does class need something extra, ...), C# code generated from template and optionally C# code with extra functionality that is either to hard to describe with template or doesn't belong there.
 
It all sounds great in theory but in practice it back to the stone age. Both Visual Studio (2010 at least) and SharpDevelop don't offer any content assistance, maintaining consistency over multiple files requires checking each file separately and there is no debugging support. If text generator throws exception, exception message and stack trace is all information you'll going to have. After a couple of rewrites I got system with satisfactory structure but I still feel the urge to complain. On the other hand I understand them, Microsoft took already existing ASP.Net renderer and reworked a little to generate any kind of text file and sold it.


Programmer rant over.

Anyway saving game works, file management and GUI needs some work. Loading should be up and running soon.