Map loading basically done for now

This commit is contained in:
2024-10-06 19:03:22 -05:00
parent ffc46c677c
commit b7987401af
2 changed files with 36 additions and 41 deletions

View File

@ -23,14 +23,5 @@
"x": 0, "x": 0,
"y": 0 "y": 0
} }
],
"triggers": [
{
"type": 1,
"x": 1,
"y": 1,
"width": 2,
"height": 2
}
] ]
} }

View File

@ -75,51 +75,55 @@ void assetMapLoad(
// Load entity data // Load entity data
assetjson_t *entities = assetJsonGetObjectValue(json, "entities"); assetjson_t *entities = assetJsonGetObjectValue(json, "entities");
assertTrue( if(entities != NULL) {
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];
assertTrue( assertTrue(
jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT, entities->type == ASSET_JSON_DATA_TYPE_ARRAY,
"assetMapLoad: Entity is not an object!" "assetMapLoad: Entities is not an array!"
); );
int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number; for(int32_t i = 0; i < entities->array.length; i++) {
int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number; assetjson_t *jEnt = entities->array.value[i];
uint8_t type = (uint8_t)assetJsonGetObjectValue(jEnt, "type")->number; assertTrue(
jEnt->type == ASSET_JSON_DATA_TYPE_OBJECT,
"assetMapLoad: Entity is not an object!"
);
entity_t *ent = mapEntityAdd(map); int32_t x = (int32_t)assetJsonGetObjectValue(jEnt, "x")->number;
entityInit(ent, type, map); int32_t y = (int32_t)assetJsonGetObjectValue(jEnt, "y")->number;
entityPositionSet(ent, x, y); 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 // Load trigger data
assetjson_t *triggers = assetJsonGetObjectValue(json, "triggers"); assetjson_t *triggers = assetJsonGetObjectValue(json, "triggers");
assertTrue( if(triggers != NULL) {
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( assertTrue(
jTrig->type == ASSET_JSON_DATA_TYPE_OBJECT, triggers->type == ASSET_JSON_DATA_TYPE_ARRAY,
"assetMapLoad: Trigger is not an object!" "assetMapLoad: Triggers is not an array!"
); );
int32_t x = (int32_t)assetJsonGetObjectValue(jTrig, "x")->number; for(int32_t i = 0; i < triggers->array.length; i++) {
int32_t y = (int32_t)assetJsonGetObjectValue(jTrig, "y")->number; assetjson_t *jTrig = triggers->array.value[i];
int32_t width = (int32_t)assetJsonGetObjectValue(jTrig, "width")->number; assertTrue(
int32_t height = (int32_t)assetJsonGetObjectValue(jTrig, "height")->number; jTrig->type == ASSET_JSON_DATA_TYPE_OBJECT,
uint8_t type = (uint8_t)assetJsonGetObjectValue(jTrig, "type")->number; "assetMapLoad: Trigger is not an object!"
);
trigger_t *trigger = mapTriggerAdd(map); int32_t x = (int32_t)assetJsonGetObjectValue(jTrig, "x")->number;
triggerInit(trigger, type, x, y, width, height); 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);