Settings don't have to match the actual object.


While trying to figure out how to do my maps, I was writing the json for the config file. For each tile, I needed a few properties. I started up with the tile information id and an angle. I ended up with a lot of bytes and the config file was getting big.

tilesInfo: [
{
tileId: 1,
angle: 1
},
{
tileId: 1,
angle: 1
},
{
tileId: 1,
angle: 1
},
{
tileId: 1,
angle: 1
},
{
tileId: 1,
angle: 1
}, ...
]

I decided to split the properties into two same size array.

        tilesId: [1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1, 1, 1],
        tilesAngle: [1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1,
                     1, 1, 1, 1, 1, 1, 1]

This made the config file much smaller and easier to edit manually. After loading the data in memory, the tile id and it's angle will be combined properly in the object.

function TileInstanceInformation() {
    this.id = 0;
    this.tileRef = 0;
    this.angle = 1;
} function SectionInformation() {
    this.id = 0;
    this.name = "";     this.width = 0;
    this.tilesInformation = []; // Array of TileInstanceInformation()
}

The config file does not need to be in the same format as the object in memory.

Leave a comment

Log in with itch.io to leave a comment.