Added triggers to parsing.
This commit is contained in:
@ -4,10 +4,10 @@
|
|||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"tiles": [
|
"tiles": [
|
||||||
1, 1, 1, 2, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 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, 2, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 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,
|
"x": 0,
|
||||||
"y": 0
|
"y": 0
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"triggers": [
|
||||||
|
{
|
||||||
|
"type": 1,
|
||||||
|
"x": 1,
|
||||||
|
"y": 1,
|
||||||
|
"width": 2,
|
||||||
|
"height": 2
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -81,15 +81,15 @@ void assetMapLoad(
|
|||||||
);
|
);
|
||||||
|
|
||||||
for(int32_t i = 0; i < entities->array.length; i++) {
|
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(
|
assertTrue(
|
||||||
jsonEntity->type == ASSET_JSON_DATA_TYPE_OBJECT,
|
jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT,
|
||||||
"assetMapLoad: Entity is not an object!"
|
"assetMapLoad: Entity is not an object!"
|
||||||
);
|
);
|
||||||
|
|
||||||
int32_t x = (int32_t)assetJsonGetObjectValue(jsonEntity, "x")->number;
|
int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number;
|
||||||
int32_t y = (int32_t)assetJsonGetObjectValue(jsonEntity, "y")->number;
|
int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number;
|
||||||
uint8_t type = (uint8_t)assetJsonGetObjectValue(jsonEntity, "type")->number;
|
uint8_t type = (uint8_t)assetJsonGetObjectValue(jEnt, "type")->number;
|
||||||
|
|
||||||
entity_t *ent = mapEntityAdd(map);
|
entity_t *ent = mapEntityAdd(map);
|
||||||
entityInit(ent, type, map);
|
entityInit(ent, type, map);
|
||||||
@ -98,5 +98,29 @@ void assetMapLoad(
|
|||||||
// TODO: Parse any extra data.
|
// 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);
|
assetJsonDispose(json);
|
||||||
}
|
}
|
Reference in New Issue
Block a user