diff --git a/assets/testmap.json b/assets/testmap.json index 6b583934..9fa54719 100644 --- a/assets/testmap.json +++ b/assets/testmap.json @@ -45,7 +45,12 @@ { "type": 4, "x": 6, - "y": 8 + "y": 8, + "door": { + "x": 0, + "y": 0, + "direction": 3 + } } ] } \ No newline at end of file diff --git a/src/dawn/asset/assetmap.c b/src/dawn/asset/assetmap.c index 0979a6c8..342306f9 100644 --- a/src/dawn/asset/assetmap.c +++ b/src/dawn/asset/assetmap.c @@ -129,6 +129,32 @@ void assetMapLoad( signTextSet(&ent->sign, val->string); } break; + + case ENTITY_TYPE_DOOR: + val = assetJsonGetObjectValue(jEnt, "door"); + if(val != NULL) { + assetjson_t *door = assetJsonGetObjectValue(val, "x"); + x = (int32_t)door->number; + assertTrue( + door->type == ASSET_JSON_DATA_TYPE_NUMBER, + "assetMapLoad: Door x is not a number!" + ); + + door = assetJsonGetObjectValue(val, "y"); + y = (int32_t)door->number; + assertTrue( + door->type == ASSET_JSON_DATA_TYPE_NUMBER, + "assetMapLoad: Door y is not a number!" + ); + entitydirection_t direction = (entitydirection_t)assetJsonGetObjectValue( + val, "direction" + )->number; + doorDestinationSet(&ent->door, x, y, direction); + } + break; + + default: + break; } // TODO: Parse any extra data. diff --git a/src/dawn/rpg/entity/door.c b/src/dawn/rpg/entity/door.c index 46922e72..1b22bc0b 100644 --- a/src/dawn/rpg/entity/door.c +++ b/src/dawn/rpg/entity/door.c @@ -10,5 +10,16 @@ void doorInit(door_t *door) { assertNotNull(door, "Door cannot be NULL."); - door->bruv = 0; +} + +void doorDestinationSet( + door_t *door, + const int32_t x, + const int32_t y, + const entitydirection_t direction +) { + assertNotNull(door, "Door cannot be NULL."); + door->x = x; + door->y = y; + door->direction = direction; } \ No newline at end of file diff --git a/src/dawn/rpg/entity/door.h b/src/dawn/rpg/entity/door.h index 9176f5f7..c784c748 100644 --- a/src/dawn/rpg/entity/door.h +++ b/src/dawn/rpg/entity/door.h @@ -6,10 +6,12 @@ */ #pragma once -#include "dawn.h" +#include "entitydirection.h" typedef struct { - uint8_t bruv; + int32_t x; + int32_t y; + entitydirection_t direction; } door_t; /** @@ -17,4 +19,19 @@ typedef struct { * * @param door Door to initialize. */ -void doorInit(door_t *door); \ No newline at end of file +void doorInit(door_t *door); + +/** + * Sets the destination of a door. + * + * @param door Door to set the destination of. + * @param x X coordinate of the destination. + * @param y Y coordinate of the destination. + * @param direction Direction the player should face when they arrive. + */ +void doorDestinationSet( + door_t *door, + const int32_t x, + const int32_t y, + const entitydirection_t direction +); \ No newline at end of file diff --git a/src/dawn/rpg/entity/interact.c b/src/dawn/rpg/entity/interact.c index b2ea7b0f..7a94ec2d 100644 --- a/src/dawn/rpg/entity/interact.c +++ b/src/dawn/rpg/entity/interact.c @@ -32,7 +32,8 @@ void entityInteractEntity( return; case ENTITY_TYPE_DOOR: - textboxSetText("Door", "It's a door."); + entityPositionSet(source, target->door.x, target->door.y); + source->direction = target->door.direction; return; default: