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

Unifying XML formatting with inheritable parsing

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

Problem

Inspired by the XML format for game data question, I was interested to see how my system works for storing game data. My system works a lot like Halo, where there are a variety of gametypes and configurations vary between them, but some basic items are always configurable.

For example, every game has a time limit, but team deathmatch has points per kill while capture the flag has a flag idle reset time. How should I store and load the universal and variable data? Something to note is that every game type has a variety of different variants with different config values, but the same format.

With the 5 or so gametypes we have, changing data around is pretty easy, but when we add more gametypes, I want to unify as much as possible for easy copy pasting / editing.

Currently my XML storage looks like the following (Yes this is Minecraft data):

Team Deathmatch (Slayer.xml):


    
    Slayer
    Kill the enemy team.
    1.0.0

    
    
        
            Red Team
            &cRed Team
            &c
            &r
            
                LEATHER_HELMET
                LEATHER_CHESTPLATE
                LEATHER_LEGGINGS
                LEATHER_BOOTS
            
        
        
            Blue Team
            &9Blue Team
            &9
            &r
            
                LEATHER_HELMET
                LEATHER_CHESTPLATE
                LEATHER_LEGGINGS
                LEATHER_BOOTS
            
        
    

    
    1
    0
    -1
    -1

    
    50
    10
    false
    true
    1.0
    true

    
    1
    0

    
    
    
        STONE_SWORD
        BOW
        ARROW
    


Team Deathmatch Heavies (Heavies.xml):

```


Heavies
Kill the enemy team.
1.0.0




Red Team
&cRed Team
&c
&r

LEATHER_HELMET
LEATHER_CHESTPLATE
LEATHER_LEGGINGS
LEATHER_BOOTS



Solution

SQL

I'm really not sure what you would gain from storing in SQL honestly. But I guess it would be worth a try. It would likely result in either a few very wide tables, or lots of very small tables that you would have to join. I'll provide a brief example below, please note being that I'm not sure what SQL engine you would be using that the syntax would vary. Below is using PostgreSQL but it would look/work very similar on other SQL engines.

CREATE TABLE core_settings(
    game_name VARCHAR PRIMARY KEY,
    description VARCHAR,
    version VARCHAR
);
CREATE TABLE team_settings(
    game_name VARCHAR REFERENCES core_settings(game_name),
    team_name VARCHAR,
    PRIMARY KEY (game_name,team_name),
    helmet_name VARCHAR,
    helmet_color VARCHAR,
    chestplate_name VARCHAR,
    chestplate_color VARCHAR,
    leggings_name VARCHAR,
    leggings_color VARCHAR,
    boots_name VARCHAR,
    boots_color VARCHAR
);
-- etc. for your other nested sets of data

INSERT INTO core_settings
    (game_name, description, version)
VALUES
    ('Slayer', 'Kill the enemy team.', '1.0.0'),
    ('Heavies', 'Kill the enemy team.', '1.0.0'),
    ('Capture the flag', 'Bring the enemy flag back to base.', '1.0.0')
;
INSERT INTO team_settings(
    game_name,
    team_name,
    helmet_name,
    helmet_color,
    chestplate_name,
    chestplate_color,
    leggings_name,
    leggings_color,
    boots_name,
    boots_color
)
VALUES  (
    'Slayer',
    'Red Team',
    'LEATHER_HELMET',
    'FF0000',
    'LEATHER_CHESTPLACE',
    'FF0000',
    'LEATHER_LEGGINGS',
    'FF0000',
    'LEATHER_BOOTS',
    'FF0000'
    ),
    (
    'Slayer',
    'Blue Team',
    'LEATHER_HELMET',
    '0000FF',
    'LEATHER_CHESTPLACE',
    '0000FF',
    'LEATHER_LEGGINGS',
    '0000FF',
    'LEATHER_BOOTS',
    '0000FF'
    );
-- etc. for each game, team, setting...

Code Snippets

CREATE TABLE core_settings(
    game_name VARCHAR PRIMARY KEY,
    description VARCHAR,
    version VARCHAR
);
CREATE TABLE team_settings(
    game_name VARCHAR REFERENCES core_settings(game_name),
    team_name VARCHAR,
    PRIMARY KEY (game_name,team_name),
    helmet_name VARCHAR,
    helmet_color VARCHAR,
    chestplate_name VARCHAR,
    chestplate_color VARCHAR,
    leggings_name VARCHAR,
    leggings_color VARCHAR,
    boots_name VARCHAR,
    boots_color VARCHAR
);
-- etc. for your other nested sets of data


INSERT INTO core_settings
    (game_name, description, version)
VALUES
    ('Slayer', 'Kill the enemy team.', '1.0.0'),
    ('Heavies', 'Kill the enemy team.', '1.0.0'),
    ('Capture the flag', 'Bring the enemy flag back to base.', '1.0.0')
;
INSERT INTO team_settings(
    game_name,
    team_name,
    helmet_name,
    helmet_color,
    chestplate_name,
    chestplate_color,
    leggings_name,
    leggings_color,
    boots_name,
    boots_color
)
VALUES  (
    'Slayer',
    'Red Team',
    'LEATHER_HELMET',
    'FF0000',
    'LEATHER_CHESTPLACE',
    'FF0000',
    'LEATHER_LEGGINGS',
    'FF0000',
    'LEATHER_BOOTS',
    'FF0000'
    ),
    (
    'Slayer',
    'Blue Team',
    'LEATHER_HELMET',
    '0000FF',
    'LEATHER_CHESTPLACE',
    '0000FF',
    'LEATHER_LEGGINGS',
    '0000FF',
    'LEATHER_BOOTS',
    '0000FF'
    );
-- etc. for each game, team, setting...

Context

StackExchange Code Review Q#57956, answer score: 2

Revisions (0)

No revisions yet.