HiveBrain v1.2.0
Get Started
← Back to all entries
snippetModerate

XML format for game data

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
formatxmlgamefordata

Problem

I want to create an XML format in which I will define data objects for a game I am currently working on.

The base idea is that I will have Elements which can be combined in other Elements, Items or Spells.

A primal element is an element which is directly available.
If an element is not primal then in order to create it, it must be combined from other elements so it will have a recipe definition (list of components required to combine in order to create the specific entity).

Items and Spells also need to have a recipe.

As of now I created the sample XML:


    
        
        
        
        

        
            Fire
            Fire
            Earth
        

        
            Nature
            Mana
            Earth        
        

    

    
        
            Mana
            Grass
            Nature
        
    

    
        
            Fire
            Fire
            Mana
        

        
            Nature
            Nature
            Mana
        

        
            Lava
            Nature
            Mana
        

        
            Mana
            Mana
            Mana
        

    


As of now there aren't too many attributes, but in the future the entities will have all kind of attributes (damage, effect, usable conditions etc) so I need to have a format that would allow me to extend, for instance, all items but not spells or elements.

I will enforce with an XML schema that components used in the recipe must be already defined. So writing Air as a component without firstly defining it will yield an error.

Although as of now all recipes have 3 elements in the future I might decide to create some with a different number.

I would greatly appreciate feedback or tips on how can I improve the format.

Solution

I'd wrap the s in a ` tag. Maybe you want to add more attributes to spells later. In fact, I'd probably make and `.

I'm also thinking you might be better off here and there by using some sort of "quantity". Lets say a spell had 10 components (for some arbitrary game design reason)...


        Mana
        Mana
        Mana
        Mana
        Mana
        Mana
        Mana
        Mana
        Mana
        Mana
    


or


        Mana
    


I like the second one more, it's smaller. Plus, I don't wanna be the one who has to check if the balancing is done right by counting whether this spell has 10 components via a process which includes manually counting lines.

From this point, however, you can go pretty much everywhere. Future proofing your schema is hard without fully knowing what data it will have to support, so I'd focus on getting the domain model right and then looking at the xml schema again.

Code Snippets

<Spell name="RestoreMana">
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
        <Component>Mana</Component>
    </Spell>
<Spell name="RestoreMana">
        <Component quantity="10">Mana</Component>
    </Spell>

Context

StackExchange Code Review Q#57905, answer score: 13

Revisions (0)

No revisions yet.