diff --git a/assets/testmap.json b/assets/testmap.json index 10870b09..8c1beba8 100644 --- a/assets/testmap.json +++ b/assets/testmap.json @@ -23,14 +23,5 @@ "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 4717dc92..6b7ed2e0 100644 --- a/src/dawn/asset/assetmap.c +++ b/src/dawn/asset/assetmap.c @@ -75,51 +75,55 @@ void assetMapLoad( // Load entity data assetjson_t *entities = assetJsonGetObjectValue(json, "entities"); - assertTrue( - entities->type == ASSET_JSON_DATA_TYPE_ARRAY, - "assetMapLoad: Entities is not an array!" - ); - - for(int32_t i = 0; i < entities->array.length; i++) { - assetjson_t *jEnt = entities->array.value[i]; + if(entities != NULL) { assertTrue( - jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT, - "assetMapLoad: Entity is not an object!" + entities->type == ASSET_JSON_DATA_TYPE_ARRAY, + "assetMapLoad: Entities is not an array!" ); - 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; + for(int32_t i = 0; i < entities->array.length; i++) { + assetjson_t *jEnt = entities->array.value[i]; + assertTrue( + jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT, + "assetMapLoad: Entity is not an object!" + ); - entity_t *ent = mapEntityAdd(map); - entityInit(ent, type, map); - entityPositionSet(ent, x, y); + 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; - // TODO: Parse any extra data. + entity_t *ent = mapEntityAdd(map); + entityInit(ent, type, map); + entityPositionSet(ent, x, y); + + // 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]; + if(triggers != NULL) { assertTrue( - jTrig->type == ASSET_JSON_DATA_TYPE_OBJECT, - "assetMapLoad: Trigger is not an object!" + triggers->type == ASSET_JSON_DATA_TYPE_ARRAY, + "assetMapLoad: Triggers is not an array!" ); - 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; + 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!" + ); - trigger_t *trigger = mapTriggerAdd(map); - triggerInit(trigger, type, x, y, width, height); + 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);