Photos? Oh, right. I’ll get around to putting them up before too long. Really.
Also, spam-bots are getting more clever. I was almost taken in by this spam comment:
Are you a professional journalist? You write very well.
Flattery is a spam tactic I had not seen before. At least, not in unbroken English and with email and websites attached that didn’t look aggressively spammy. But I digress; the point of this post is to talk about where Game Toolbox is going.
I’m working on the next iteration of it. This version will change the interfaces for certain things, which probably won’t be a problem because I don’t think anyone is using Game Toolbox for anything yet? If you are, you will need to change some things for the new version, but I believe it is worth it. Here are some of the changes and new goodies that will be going in for 0.2.0:
- PlannerAction is no longer full of delegate properties. It is now an abstract base class which you are intended to implement subclasses of to represent the available actions in your game (or other application). This is better for a few reasons: the actions wouldn’t have been definable in data anyway, and you probably wouldn’t want to; delegates don’t play nicely with XmlSerializer; and it provides a better place for initialization of actions, which was kind of a mess before. Other changes:
- The Cost, IsValid, and Execute functions now take as a parameter the current state.
- I’m still working on this one, but you will be able to specify certain state symbols to be “parameters” for a given action; these must be symbols that the action can set to different values depending on the needs of the planner. The planner will pass the needed value to the action as a parameter in its functions and it can use that to make certain values have a higher cost or be unreachable, etc. This is primarily to enable the creation of a GoTo action which could modify a “Location” symbol to be set to whatever position is needed without having to create a separate action for every location that can be reached. But it could also be used for other types of actions, such as a “Buy” action where different types of items can be purchased using the same action.
- XML<T> is a new static class which makes it extremely easy to save and load files in XML format: just create a class which represents your file, containing public properties for each thing you want in the file. Give it a default constructor which initializes everything to default values (initialize things like Lists to have no elements; otherwise you will end up getting duplicates), and you can use XML<T>.Save(…) and XML<T>.Load(…) to save and load the object as an XML file.
If the file is not found or is invalid when Load is called, it automatically creates a new object instance with default values and saves it to the file before returning it, so no extra work is needed to generate a default file, and unless something goes horribly wrong you will always get a valid object returned.
Use the XML<T>.IsValid(…) function to check the validity of a file before attempting to load it if it is important not to overwrite something in the wrong format. Functions are also provided to save and load to/from streams.
Be sure to call XML<T>.Initialize() before using any of the other functions (and it needs to be initialized for each type which will be used with it). XML<T> is also subject to many of XmlSerializer’s limitations: properties with a public getter and a nonpublic setter will present a problem for it; use the [XmlIgnore] attribute to avoid serializing these if they do not need to be serialized. The same goes for any property with the type Object, or of a generic type with a type parameter of type Object; the serializer would not be able to figure out what type these should be for correct deserialization.
- FlyweightPool<T> is a new generic class which makes it easy to take advantage of the flyweight design pattern. It acts as a flyweight factory, and by default uses reflection to pre-load an instance of each subclass of the given type which exists in any currently-loaded assembly so that object creation is taken care of up front.
- PlannerActionPool is a FlyweightPool of PlannerActions. It provides the basic functionality of FlyweightPool and adds the ToSet() function, which returns a PlannerActionSet containing all available PlannerActions.
Once the work is done for implementing parameters for PlannerActions, 0.2.0 will be released. Please feel free to leave any feedback or ask questions on the project forum, or post a bug in the project’s bug tracker. Comments are fine here, too, of course.