January 27, 2012

XML work finished

Well, finished for now...

Over the last month, I have accomplished the following:

1) Loading of game data from external XML files, enabling modding of the game's parameters.  XML files contain information on the relative proportion of star types, the sizes of galaxies, the colors of stars, and so on.  I have plans to use XML data to define game events, ship designs, and more.

2) Loading/saving of game objects from/to XML files.  I likely have a bit more work to do in this area, but the base capability is there and works for now.  I'll revisit this during later development as the need arises.

3) Refactoring of my object structure, moving away from inheritance and toward composition with interfaces.  It feels more intuitive to me to assemble an object from smaller pieces than it does to inherit.  With composition, you can mix and match as needed, provided you code to the interfaces that go with each piece.

My next step is to fully create a single StarSystem object--the data model, graphics for its view, and the controller that handles its events.  I want to be able to experiment with level-of-detail changes, clicking and highlighting, audio effects, loading/saving it, switching between views of the model, and adding modifiers to its model data.  The toughest part will likely be handling the graphics and views, as I've neglected that aspect of the game so far and am not sure how robust my current structure will be.

I'm guessing this work will take most of February to finish.

January 22, 2012

Code re-tooling

This is where my naivete with working in Java shows itself.  I'm largely self-taught and there are definitely some holes in my knowledge when it comes to good coding practice, designing flexible code, etc.  While testing out XStream to save a simple starSystem object, I realized that my existing code structure for in-game objects--based purely on inheritance--would make things somewhat difficult to load/save and was also going to make it very difficult to go back and refactor code later on.

So, I'm switching to a structure using interfaces and object composition ("has-a" instead of inheritance's "is-a" relationship).  Shouldn't take too long to retool--I've already created the necessary interfaces and have reworked the Star model classes already.  Next I'll rework the Star controllers and then move on to the starSystem classes.

A couple hours effort overall, then its back to working on the load/save system!

January 20, 2012

Custom Galaxy Shapes Implemented!

All this mucking around with XML is paying off!  Modders can now create custom galaxy shapes by entering (x,y) coordinates and a name into an XML file and placing it in a folder called CustomGalaxies in the game directory.  The way you enter the points is to imagine that you're drawing the shape without ever "taking your pencil off the paper."

January 8, 2012

More XML

Well, playing Deus Ex: HR definitely took more time than I wanted... :).  The new year also brought a bit more stress at work, so I've been less productive after work than usual.

In the interest of simplicity, I'm going to try and use XStream for all my XML needs.  I've developed a basic XMLLoader class which loads data from a pre-defined list of files into pre-defined Java classes, which are then accessible to various game systems as needed.  This should still provide modding flexibility, as each XML file will host an expandable list of entities of a given type.

For example, a file named SpaceMonsters.xml will contain a listing of all the space monsters in the game.  Each monster would be contained within a tag such as <spacemonster></spacemonster>.  New monsters can be added by simply creating a new set of these tags at the end of the document and filling in the relevant details.  In code, all space monsters will implement the same ISpaceMonster interface.  Using XStream, I can read SpaceMonsters.xml entries into an ArrayList in code and then handle any given monster via its interface.  It should be straightforward to implement a similar system for technologies, random events, default starship designs, etc.

Tasks remaining:

1) Finish conversion of remaining Java Enumerations into XML files/classes.
2) Add in support for custom XML galaxy shapes.
3) Implement load/save capability for a single star object (as a test run).