diff --git a/assets/testmap.json b/assets/testmap.json index 9a6eb8d7..10870b09 100644 --- a/assets/testmap.json +++ b/assets/testmap.json @@ -4,10 +4,10 @@ "layers": [ { "tiles": [ - 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 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, 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, @@ -23,5 +23,14 @@ "x": 0, "y": 0 } + ], + "triggers": [ + { + "type": 1, + "x": 1, + "y": 1, + "width": 2, + "height": 2 + } ] } \ No newline at end of file diff --git a/src/dawn/asset/assetmap.c b/src/dawn/asset/assetmap.c index c3c40a8d..4717dc92 100644 --- a/src/dawn/asset/assetmap.c +++ b/src/dawn/asset/assetmap.c @@ -81,15 +81,15 @@ void assetMapLoad( ); for(int32_t i = 0; i < entities->array.length; i++) { - assetjson_t *jsonEntity = entities->array.value[i]; + assetjson_t *jEnt = entities->array.value[i]; assertTrue( - jsonEntity->type == ASSET_JSON_DATA_TYPE_OBJECT, + jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT, "assetMapLoad: Entity is not an object!" ); - int32_t x = (int32_t)assetJsonGetObjectValue(jsonEntity, "x")->number; - int32_t y = (int32_t)assetJsonGetObjectValue(jsonEntity, "y")->number; - uint8_t type = (uint8_t)assetJsonGetObjectValue(jsonEntity, "type")->number; + int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number; + int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number; + uint8_t type = (uint8_t)assetJsonGetObjectValue(jEnt, "type")->number; entity_t *ent = mapEntityAdd(map); entityInit(ent, type, map); @@ -98,5 +98,29 @@ void assetMapLoad( // TODO: Parse any extra data. } + // Load trigger data + assetjson_t *triggers = assetJsonGetObjectValue(json, "triggers"); + assertTrue( + triggers->type == ASSET_JSON_DATA_TYPE_ARRAY, + "assetMapLoad: Triggers is not an array!" + ); + + for(int32_t i = 0; i < triggers->array.length; i++) { + assetjson_t *jTrig = triggers->array.value[i]; + assertTrue( + jTrig->type == ASSET_JSON_DATA_TYPE_OBJECT, + "assetMapLoad: Trigger is not an object!" + ); + + int32_t x = (int32_t)assetJsonGetObjectValue(jTrig, "x")->number; + int32_t y = (int32_t)assetJsonGetObjectValue(jTrig, "y")->number; + int32_t width = (int32_t)assetJsonGetObjectValue(jTrig, "width")->number; + int32_t height = (int32_t)assetJsonGetObjectValue(jTrig, "height")->number; + uint8_t type = (uint8_t)assetJsonGetObjectValue(jTrig, "type")->number; + + trigger_t *trigger = mapTriggerAdd(map); + triggerInit(trigger, type, x, y, width, height); + } + assetJsonDispose(json); } \ No newline at end of file