Sunday, October 22, 2006

Vehicular Fortitude: The Next Generation

This was a bad weekend for the car.  Four new tires and a tuneup.

There went $850.  Ouch.

Props

That last post was brought to you with Windows Live Writer and a nifty Source Code Formatter.

 

Now I just need to figure out how to make my chosen template look decent with the main text window wider, so the source code doesn't look bad.

String descritions from enums in C#

Anyone just looking for code can skip to the end.

My AE Item Maker has a SingleUseItem class, which uses an enum for each different kind of single use item.

public enum SUType
{
INVALID,
POTION,
OIL,
DETONATION,
OTHER,
}
Among other things I use the enum to generate names for items. In C++, I would probably write a function to convert the enum to the string I wanted, but this isn't c++, and I wanted to try something different.

My first thought was to use the nift ToString() method. This got me literal strings for values, like "INVALID", "POTION", etc. It was close, but not really what I wanted. So I turned to my favorite search engine for help.

The results were mixed. It seems you can't actually override the ToString() method on an enum. But I did find the next best thing.

First, I add a Description attribute to the enum (you need System.ComponentModel for this)

public enum SUType
{
[Description("Unknown type")]
INVALID,
[Description("Potion")]
POTION,
[Description("Oil")]
OIL,
[Description("Detonation")]
DETONATION,
[Description("Single Use Item")]
OTHER,
}


Next I added this public static method in a helper class:


 

public class ItemHelper
{
/// <summary>
/// Returns the DescriptionAttirbute for an
/// enum.
/// </summary>
/// <param name="nType">Any enum</param>
/// <returns>DescriptionAttribute for that
/// enum, if it exists</returns>
public static string GetTypeDescription(Enum nType)
{
Type oSystype = nType.GetType();
string strName = System.Enum.GetName(oSystype, nType);
FieldInfo oFieldInfo = oSystype.GetField(strName);
object[] rgObjs =
oFieldInfo.GetCustomAttributes(
typeof(DescriptionAttribute), false);
foreach (object obj in rgObjs)
{
DescriptionAttribute oDesc = obj as
DescriptionAttribute;
if (oDesc != null)
{
return oDesc.Description;
}
}

return "Unknown";
}
}

 


You use it like this:

string strType = ItemHelper.GetTypeDescription(m_nType);

This isn't perfect.  For one, if you have multiple description attributes you aren't guaranteed to find a particular one first.  It also doesn't handle localization at all.  But this works for what I need right now.

Thursday, October 19, 2006

Source Control update

After a while I remembered a discussion I had with a coworker about perforce, and now I have a workaround for checking out all the files and doing a "revert unchanged."

  1. Save the file. That brings up a few options, include "Save As." Click that.
  2. In the file list, find the file you want and right click it.
  3. From the right click menu, select Perforce, then "check out."
  4. Finally, cancel and save again. You've checked out the file.

It ain't pretty, and it's not as nice as source control integration, but it does work.

ItemMaker updates

I've been slowly working on the Arcana Evolved Item Maker. Very slowly.

So far I have tests for 4 different item types, but 3 of those need some refactoring. My current goal is to finish one kind of item and get that working in a UI. I've decided that the first Item type I want to tackle are single use items.

At a minimum in order to get an app together that does single use items, I need:

  1. Tested and debugged basic single use types --DONE
  2. Tested and debugged basic spells --DONE
  3. Code to load spells from disk
  4. Code to save single use items
  5. Code to load single use items
  6. A UI that doesn't suck


Extra stuff that would be cool:

  1. The ability to print items you've made in nice stat blocks
  2. The ability to sort spells by level, basic type (damage, buff, etc), descriptor, level, and alphabetically
  3. The ability to specify multiple sorts
  4. Some automated way to add new spells
  5. Images

And of course, other item types.

Ultimately, I'd like my item maker to be better than the existing one.

Right now I have code that loads the spells from an XML file, but it's pretty brittle. If an entry in the spell data is missing or not in the right order it croaks.

I really have to watch myself. I'm trying, unsuccessfully, to keep things simple. YAGNI. So far I've made a SpellWriter, which writes out spell data in the appropriate XML format. I don't need it. I wrote it to play with more of the .NET XML classes. Oh well, maybe I'll be able to use it for something else later on.

At 6 you can learn Python

Or at least enough python to write a game about vampires.

HAARG!

The whole thing is pretty entertaining.

Thursday, October 12, 2006

The latest in cube war technology

Even though I work from home, I so need this:

USB Missle Launcher

Sunday, October 08, 2006

Source Control and Visual C# Express

I'm continuing my work on my Arcana Evolved ItemMaker after a long break.

I'm still using C#, but right now I'm considering using this app to learn .NET 3.0 / WinFX / Avalon.

I'm using Visual C# Express, which is pretty nice, but I have one big complaint.

The worst part by far is that, like all of the Express downloads, VC# Express doesn't do plugins. This means that it can't do source control integration, which is a big pain. I'm working around this right now by checking out everything when I want to work, and using Perforce's "Revert Unchanged" feature to clear out the files I didn't edit when I want to check everything in. This works for the ItemMaker, but that's only because it's trivially small now.

ItemMaker now consists of about 10 core classes, plus 6 test classes. I haven't started on the UI yet. So far, that's 16 class files plus associated project files that I check out, revert, and check in every time I make changes. And doing TDD, I make a lot of small changes.

Any software developer needs source control. Joel Spolsky covers why (briefly) in the Joel Test. Eric Sink also has a post about it. If nothing else, source control is a great undo feature. Those changes you made aren't working? Can't remember what you changed? Check source control. Is it still unclear? Revert and start over. Without source control, you don't know where you've been, you don't know exactly what changed, and you certainly can't recover easily from a bad mistake.

I won't even work on small stuff without source control. For the record, I use Perforce at home because the single user license is free. If you are braver than me, or need a multi-user source control system, check out subversion.

I'm really happy that Microsoft released free versions of its compilers, but not being able to use integrated source control is almost a deal breaker. For C# IDEs, my only other (free) choice is Mono. I'm not yet annoyed enough to make the switch.

Fun game or crazy money making scheme? You make the call

Step 1: The Game of Alien Abduction
Step 2: ?
Step 3: Profit

Switching to blogger beta

I just switched to the new blogger beta so I can start taking advantage of the labels and other new features. This is stuff I've wanted since a few of my buddies went over to livejournal.

THIS BLOG HAS MOVED!

To:
http://martiank9.blogspot.com

The phpwebhosting address will be going away soon.

Where the wild pies roam

We visited Ktorrek last friday, and generally had a good time. Except for the horrible traffic getting there, and my illness afterwards.

Around 9 p.m. I was eating tasty Mac & Cheese and Chicken. Around 3 a.m. I was sad. I blame Salmonella.

The pies, however, were excellent.

Wednesday, October 04, 2006

LOST season 3

I just finished watching the first episode of the third season of Lost.

I haven't seen the whole second season yet, so I have no idea what's going on.

Two things come to mind.

First, wow. Lost is just cool. As usual, I can't wait for the next episode.

Second, I really dislike TV as it is now. Sitting and watching Lost I was thinking about how I need to either get a TiVo, go old school with a VCR, or just watch the series on DVD.

When we moved back to the Midwest we got TV again. I miss not having it. TV sucks away time. It's so easy to sit and stare at the pretty lights and moving pictures, and wake up 3 months later with very little else having been accomplished.

Watching series on DVD or (I imagine) on TiVo is different. You get to see what you're interested in and you don't have to watch the commercials. To me, DVD's are not quite as bad as TV, because you get to watch them on your own terms.

Anyway, I'm off to play with C# some more. No more TV tonight!