Tuesday, August 28, 2007

Some UI stuff Game working

Upgrade
 Soon it will be time for a new computer. Actually, no, it was time for a new computer a while ago. But at some point, I'll actually do something about it. In the meantime, I need to accept occasional random shutdowns as a necessary evil. Well, as an evil anyway.

Game
 I'm going to write (and test) a function that displays all of the player's current options. This is in anticipation of putting together a test game that someone (you, maybe) can actually play.
 I'm treading a bit carefully, as I'm not sure, in general, how much UI stuff should be tested. My vague plan is to write functions like DisplayCurrentOptions(...) and make sure that the output matches the expected results (a DebugPrint, if you would). There's probably a more clever way, and I hope I stumble upon it.

DisplayCurrentOptions(objCharacter, arrLocalNPCs)
 We'll start with the parameters I know I'll need. Given a character and the local NPCs available to talk to, show me my options.
 Shouldn't I start with the simplest version that makes sense? Yes, I'll leave NPCs out of it for now.
 Eek, a lot of syntax errors. I'm a bit embarrassed to make so many simple mistakes. Ok, I've got my basic test working - a character without any abilities. For now, I don't really care about abilities, so I'll leave that untested for now.

Adding NPCs
 So, now, I'll pass an NPC object. Eventually, I'll need to update it to include an array of NPCs, but, for now, this will suffice.
 Ok, tests pass, but this function has unveiled a design flaw. I'd like objNPC.Name to be something like "Mike", not the full response "My name's Mike", as it is now. That's really objNPC.NameResponse. So, a little renaming is required for Name, Job, and Health to NameResponse, JobResponse, HealthResponse. A simple change that I can make fearlessly with my tests in place.
 Ok, two tests fail with the change. One was expected (I'll need to update snapshots). The other one, testAskStageManagerAboutBasicInfo, is probably accessing data directly that it shouldn't. Upon reflection, this second test is a pale shadow of the DebugPrint test, so I'll just delete it. It was a stepping stone to the other (better) test.
 Now to try my re-generating snapshots method. Excellent. Two clicks later, and the test is passing again. Ah, I meant to create a name for my stage manager first, but *shrug* it's easy enough to fix. In fact, first, I'll add a little loop to make regenerating snapshots easier.
 Wow. A bug in the setup routine makes all tests fail. Interesting (and a little scary) to stare at a wall of red failure notices.

UI
 So, here's the question. Do I want to display all of the people that you could talk to as a select list? Or as a bunch of little graphics? I like the second idea. So, I'll need to add a Thumbnail to the NPC class. I'll be doing that a lot as I start to be concerned about not only what these objects do, but what they look like.
 Now for the fun part - searching google images for a good "generic NPC" image icon. If I'm not careful, I can spend hours doing this. Spend = waste.

Next Steps
 Ok, this has lead me in a few directions. First, I need to break up my successful_Tests repository into actual tests, and setup functions. Then, I need to replace my setup functions with Load functions. Of course, to do this, I'm going to have to stuff each object into a database, and write update, insert, and retrieve functions. I may write something to generate the update/insert/retrieve code for me. That will depend on how ambitious I get.
 Baby steps - break up setup functions and change file dependancies, so that the game.asp page has access to the global parameters object (which, someday, I hope to eliminate completely). Done.
 Upon reflection, I wonder if more design up-front would have saved me from creating these canonical objects and global parameter arrays? I tend to doubt it. I'm also pretty happy with the amount of functionality I have at this point, for relatively little effort.
 Another thought is the fact that every time I think I'm at a position where I can start writing the game interface, I quickly find a slew of internal changes that drive me back to my test page.