Now that we’ve – more or less – moved into our new flat (complete with floors! And electricity!), I’m managing to scrounge some time back from frantically organising a house move to… well, it’s more frantic organising, really, but less of my furniture is being scratched this time.
After I decided to refactor Cuthbert to be more efficient, I sat down with the code to work out where to begin. That bit was easy. The easy bit, that’s where I’d begin – my Grunt file.
Grunt is a task runner – it automatically runs small scripts for you, to save time when you’re coding. Things like minifying and compressing files so they download faster, and compiling fast-for-me-to-write-impossible-for-browsers-to-understand SASS into readable stylesheets.
I’d also written some tasks specifically for Cuthbert, getting the code to loop through all of the rooms and characters and objects I’d created, and automatically add in styling and images for them to limit the repetitive, manual work. And let me change characters’ names without having to do loads of refactoring.
The result was 216 lines of code that was hard to parse, hard to find any one particular bit of functionality to make changes to it.
From this…
Changing that into small, individual modules which I could tweak and amend independently of one another – and which I could add to without bloating the code and making it harder to understand, since this file is only going to get bigger from here – seemed like a sensible starting place.
…to this.
Where to go next was a tougher question.
The code was all jumbled together, borne of trying to get the work done and not lose momentum. While I’d separated out characters and rooms that were specific to Cuthbert’s first adventure (working title: The Legacy of Once-Upon-Thames. Eh? Eh?), the core game engine, the bit that actually drives the game – lets you pick things up and give them to people and talk and hit people with a sword – was still intertwined with Cuthbert.
I could make a Cuthbert sequel, if Cuthbert himself was still the protagonist and still had the same hint system and the same artwork. I couldn’t make a second adventure game. I couldn’t have a story set in Cuthbert‘s universe with a different lead character, or a horror story investigating a nightmarish haunted house, where the game plays tricks on you – or did you just imagine that used to say something else? Or a Sherlock Holmes game where you swap between Holmes and Watson to solve crime.
Er, just to give some off the top of my head examples I haven’t ever thought about before, ever.
I own all this for, uh, completely unrelated reasons. DollarPhotoClub
The problem is, separating out what belongs to this game, the one I’ve got plotted out and several novels-worth of content written for, and what belongs to a more general engine that can be used to power more games later isn’t a quick job.
But, if doing another game later is something I think I might do, it doesn’t make sense to refactor the code I have now and not split it out into Legacy and reusable code.
So. Hmm. Well.
Refactoring might go on for a scooch longer than anticipated…