summaryrefslogtreecommitdiff
path: root/tools/nitrogfx/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/nitrogfx/json.c')
-rw-r--r--tools/nitrogfx/json.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/tools/nitrogfx/json.c b/tools/nitrogfx/json.c
index 7804a2ba..7907b515 100644
--- a/tools/nitrogfx/json.c
+++ b/tools/nitrogfx/json.c
@@ -175,6 +175,17 @@ struct JsonToScreenOptions *ParseNSCRJson(char *path)
cJSON *layer = NULL;
cJSON *layers = cJSON_GetObjectItemCaseSensitive(json, "layers");
int palette = 0;
+ cJSON *tilesets = cJSON_GetObjectItemCaseSensitive(json, "tilesets");
+ int tilesetSize = 0;
+ if (cJSON_GetArraySize(tilesets) != 1)
+ {
+ cJSON *tileset = cJSON_GetArrayItem(tilesets, 1);
+ cJSON *firstGid = cJSON_GetObjectItemCaseSensitive(tileset, "firstgid");
+ tilesetSize = GetInt(firstGid) - 1;
+ if (tilesetSize <= 1)
+ FATAL_ERROR("Wrong tileset index (tileset 0 should be added first)\n");
+ }
+
cJSON_ArrayForEach(layer, layers)
{
cJSON *tile = NULL;
@@ -183,6 +194,11 @@ struct JsonToScreenOptions *ParseNSCRJson(char *path)
cJSON_ArrayForEach(tile, data)
{
int tileInt = GetInt(tile) - 1;
+ if (tilesetSize != 0)
+ {
+ palette = tileInt / tilesetSize;
+ tileInt %= tilesetSize;
+ }
if (tileInt != -1)
{
bool vFlip = tileInt >> 30;
@@ -194,7 +210,6 @@ struct JsonToScreenOptions *ParseNSCRJson(char *path)
}
i++;
}
- palette++;
}
cJSON_Delete(json);