Skip to content

Commit

Permalink
* support for 1.9 tileset attributes "tilerendersize" and "fillmode"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghassan authored and baylej committed Mar 13, 2023
1 parent 956afde commit 14a60b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/tmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ enum tmx_obj_type {OT_NONE, OT_SQUARE, OT_POLYGON, OT_POLYLINE, OT_ELLIPSE, OT_T
enum tmx_property_type {PT_NONE, PT_INT, PT_FLOAT, PT_BOOL, PT_STRING, PT_COLOR, PT_FILE, PT_OBJECT, PT_CUSTOM};
enum tmx_horizontal_align {HA_NONE, HA_LEFT, HA_CENTER, HA_RIGHT, HA_JUSTIFY};
enum tmx_vertical_align {VA_NONE, VA_TOP, VA_CENTER, VA_BOTTOM};
enum tmx_tile_render_size {TRS_TILE, TRS_GRID};
enum tmx_fill_mode {FM_STRETCH, FM_PRESERVE_ASPECT_FIT};

/* Typedefs of the structures below */
typedef struct _tmx_prop tmx_property;
Expand Down Expand Up @@ -153,6 +155,9 @@ struct _tmx_ts { /* <tileset> and <tileoffset> */
unsigned int tilecount;
tmx_image *image;

enum tmx_tile_render_size tile_render_size;
enum tmx_fill_mode fill_mode;

tmx_user_data user_data;
tmx_properties *properties;
tmx_tile *tiles;
Expand Down
21 changes: 21 additions & 0 deletions src/tmx_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,27 @@ static int parse_tileset(xmlTextReaderPtr reader, tmx_tileset *ts_addr, tmx_reso
tmx_free_func(value);
}

if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"tilerendersize"))) { /* tilerendersize */
if (!strcmp(value, "tile")) ts_addr->tile_render_size = TRS_TILE;
else if (!strcmp(value, "grid")) ts_addr->tile_render_size = TRS_GRID;
else {
tmx_err(E_XDATA, "xml parser: unsupported tileset tile render size: '%s'", value);
tmx_free_func(value);
return 0;
}
tmx_free_func(value);
}
if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"fillmode"))) { /* fillmode */
if (!strcmp(value, "stretch")) ts_addr->fill_mode = FM_STRETCH;
else if (!strcmp(value, "preserve-aspect-fit")) ts_addr->fill_mode = FM_PRESERVE_ASPECT_FIT;
else {
tmx_err(E_XDATA, "xml parser: unsupported tileset fill mode: '%s'", value);
tmx_free_func(value);
return 0;
}
tmx_free_func(value);
}

if (!(ts_addr->tiles = alloc_tiles(ts_addr->tilecount))) return 0;

/* Parse each child */
Expand Down

0 comments on commit 14a60b3

Please sign in to comment.