RatDevelopment / WebCiv

0 stars 1 forks source link

Specify JSON format for tilemaps #4

Closed cezarywojcik closed 11 years ago

cezarywojcik commented 11 years ago

Relational vs Array-based tile specification?

My current thoughts:

Proposed format

{
  someOption: value,
  // other options
  tiles: [
    {type:1,...},
    {type:1,...},
    {type:2,...},...
  ]
}
Serneum commented 11 years ago

I'd go with arrays and, if possible, actual enumerations instead of 1, 2, etc. Could do a rest service that returns what each number is and cache it. If it's in the cache, we're fine, otherwise call out to the rest service

cezarywojcik commented 11 years ago

Relevant Chat Log: http://pastebin.com/shkDn1Gb

Summary:

Serneum commented 11 years ago
cezarywojcik commented 11 years ago

Sample JSON:

{
    "map": [
        [
            {
                "id": 1,
                "type": 1,
                "x": 0,
                "y": 0,
                "neighbors": [
                    12,
                    10,
                    2,
                    4,
                    6,
                    3
                ]
            },
            {
                "id": 2,
                "type": 1,
                "x": 1,
                "y": 0,
                "neighbors": [
                    1,
                    4,
                    5,
                    3,
                    10,
                    11
                ]
            },
            {
                "id": 3,
                "type": 1,
                "x": 2,
                "y": 0,
                "neighbors": [
                    11,
                    12,
                    1,
                    6,
                    5,
                    2
                ]
            }
        ],
        [
            {
                "id": 4,
                "type": 1,
                "x": 0,
                "y": 1,
                "neighbors": [
                    1,
                    2,
                    5,
                    8,
                    7,
                    6
                ]
            },
            {
                "id": 5,
                "type": 1,
                "x": 1,
                "y": 1,
                "neighbors": [
                    2,
                    3,
                    6,
                    9,
                    8,
                    4
                ]
            },
            {
                "id": 6,
                "type": 1,
                "x": 2,
                "y": 1,
                "neighbors": [
                    3,
                    11,
                    4,
                    7,
                    9,
                    5
                ]
            }
        ],
        [
            {
                "id": 7,
                "type": 1,
                "x": 0,
                "y": 2,
                "neighbors": [
                    6,
                    4,
                    8,
                    10,
                    12,
                    9
                ]
            },
            {
                "id": 8,
                "type": 1,
                "x": 1,
                "y": 2,
                "neighbors": [
                    4,
                    5,
                    9,
                    11,
                    10,
                    7
                ]
            },
            {
                "id": 9,
                "type": 1,
                "x": 2,
                "y": 2,
                "neighbors": [
                    5,
                    6,
                    7,
                    12,
                    11,
                    8
                ]
            }
        ],
        [
            {
                "id": 10,
                "type": 1,
                "x": 0,
                "y": 3,
                "neighbors": [
                    7,
                    8,
                    11,
                    2,
                    1,
                    12
                ]
            },
            {
                "id": 11,
                "type": 1,
                "x": 1,
                "y": 3,
                "neighbors": [
                    8,
                    9,
                    12,
                    3,
                    2,
                    10
                ]
            },
            {
                "id": 12,
                "type": 1,
                "x": 1,
                "y": 1,
                "neighbors": [
                    9,
                    7,
                    10,
                    1,
                    3,
                    11
                ]
            }
        ]
    ]
}

Shorter version:

{"map":[[{"id":1,"type":1,"x":0,"y":0,"neighbors":[12,10,2,4,6,3]},{"id":2,"type":1,"x":1,"y":0,"neighbors":[1,4,5,3,10,11]},{"id":3,"type":1,"x":2,"y":0,"neighbors":[11,12,1,6,5,2]}],[{"id":4,"type":1,"x":0,"y":1,"neighbors":[1,2,5,8,7,6]},{"id":5,"type":1,"x":1,"y":1,"neighbors":[2,3,6,9,8,4]},{"id":6,"type":1,"x":2,"y":1,"neighbors":[3,11,4,7,9,5]}],[{"id":7,"type":1,"x":0,"y":2,"neighbors":[6,4,8,10,12,9]},{"id":8,"type":1,"x":1,"y":2,"neighbors":[4,5,9,11,10,7]},{"id":9,"type":1,"x":2,"y":2,"neighbors":[5,6,7,12,11,8]}],[{"id":10,"type":1,"x":0,"y":3,"neighbors":[7,8,11,2,1,12]},{"id":11,"type":1,"x":1,"y":3,"neighbors":[8,9,12,3,2,10]},{"id":12,"type":1,"x":1,"y":1,"neighbors":[9,7,10,1,3,11]}]]}

Visualization off ids with copies "wrapped":

1  2  3  1  2  3
 4  5  6  4  5  6
7  8  9  7  8  9
 10 11 12 10 11 12
1  2  3  1  2  3
 4  5  6  4  5  6
7  8  9  7  8  9
 10 11 12 10 11 12