diff options
| author | 3gg <3gg@shellblade.net> | 2025-09-02 18:41:59 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-09-02 18:41:59 -0700 |
| commit | e6bf7e77797103ee7ab0eda57c360c38f1b2089c (patch) | |
| tree | b0cb40caf98c18e490b81feb59f9f26d47593670 | |
| parent | 5278a117ee31c911106346e60018e13c8f3e79fc (diff) | |
Add map orientation.
| -rw-r--r-- | include/isogfx/asset.h | 11 | ||||
| -rw-r--r-- | src/isogfx.c | 2 | ||||
| -rw-r--r-- | tools/mkasset.py | 10 |
3 files changed, 23 insertions, 0 deletions
diff --git a/include/isogfx/asset.h b/include/isogfx/asset.h index 6050500..361ffcd 100644 --- a/include/isogfx/asset.h +++ b/include/isogfx/asset.h | |||
| @@ -43,6 +43,16 @@ typedef struct Ts_TileSet { | |||
| 43 | // Tile map (TM) file format. | 43 | // Tile map (TM) file format. |
| 44 | // ----------------------------------------------------------------------------- | 44 | // ----------------------------------------------------------------------------- |
| 45 | 45 | ||
| 46 | typedef enum Tm_Orientation { | ||
| 47 | Tm_Orthogonal = 0, | ||
| 48 | Tm_Isometric = 1, | ||
| 49 | } Tm_Orientation; | ||
| 50 | |||
| 51 | typedef struct Tm_Flags { | ||
| 52 | Tm_Orientation orientation : 1; | ||
| 53 | int unused : 15; | ||
| 54 | } Tm_Flags; | ||
| 55 | |||
| 46 | typedef struct Tm_Layer { | 56 | typedef struct Tm_Layer { |
| 47 | Tile tiles[1]; // Count: world_width * world_height. | 57 | Tile tiles[1]; // Count: world_width * world_height. |
| 48 | } Tm_Layer; | 58 | } Tm_Layer; |
| @@ -54,6 +64,7 @@ typedef struct Tm_Map { | |||
| 54 | uint16_t base_tile_width; | 64 | uint16_t base_tile_width; |
| 55 | uint16_t base_tile_height; | 65 | uint16_t base_tile_height; |
| 56 | uint16_t num_layers; | 66 | uint16_t num_layers; |
| 67 | uint16_t flags; // Tm_flagsFlags | ||
| 57 | Tm_Layer layers[]; // Count: num_layers. | 68 | Tm_Layer layers[]; // Count: num_layers. |
| 58 | } Tm_Map; | 69 | } Tm_Map; |
| 59 | 70 | ||
diff --git a/src/isogfx.c b/src/isogfx.c index c3a87bf..865ebb4 100644 --- a/src/isogfx.c +++ b/src/isogfx.c | |||
| @@ -267,6 +267,8 @@ bool isogfx_load_world(IsoGfx* iso, const char* filepath) { | |||
| 267 | } | 267 | } |
| 268 | Tm_Map* const map = iso->map; | 268 | Tm_Map* const map = iso->map; |
| 269 | 269 | ||
| 270 | printf("Map orientation: %d\n", ((Tm_Flags*)&map->flags)->orientation); | ||
| 271 | |||
| 270 | // Load the tile set. | 272 | // Load the tile set. |
| 271 | // | 273 | // |
| 272 | // Tile set path is relative to the tile map file. Make it relative to the | 274 | // Tile set path is relative to the tile map file. Make it relative to the |
diff --git a/tools/mkasset.py b/tools/mkasset.py index 62d1d88..f21a2f9 100644 --- a/tools/mkasset.py +++ b/tools/mkasset.py | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | import argparse | 13 | import argparse |
| 14 | import ctypes | 14 | import ctypes |
| 15 | import sys | 15 | import sys |
| 16 | from enum import IntEnum | ||
| 16 | from typing import Generator | 17 | from typing import Generator |
| 17 | from xml.etree import ElementTree | 18 | from xml.etree import ElementTree |
| 18 | 19 | ||
| @@ -23,6 +24,12 @@ from PIL import Image | |||
| 23 | MAX_PATH_LENGTH = 128 | 24 | MAX_PATH_LENGTH = 128 |
| 24 | 25 | ||
| 25 | 26 | ||
| 27 | class Orientation(IntEnum): | ||
| 28 | """Map orientation. Must match Tm_Orientation in asset.h""" | ||
| 29 | Orthogonal = 0 | ||
| 30 | Isometric = 1 | ||
| 31 | |||
| 32 | |||
| 26 | def drop_extension(filepath): | 33 | def drop_extension(filepath): |
| 27 | return filepath[:filepath.rfind('.')] | 34 | return filepath[:filepath.rfind('.')] |
| 28 | 35 | ||
| @@ -178,11 +185,13 @@ def convert_tmx(input_filepath, output_filepath): | |||
| 178 | base_tile_width = int(root.attrib["tilewidth"]) | 185 | base_tile_width = int(root.attrib["tilewidth"]) |
| 179 | base_tile_height = int(root.attrib["tileheight"]) | 186 | base_tile_height = int(root.attrib["tileheight"]) |
| 180 | num_layers = 1 | 187 | num_layers = 1 |
| 188 | flags = Orientation.Isometric if (root.attrib["orientation"] == "isometric") else Orientation.Orthogonal | ||
| 181 | 189 | ||
| 182 | print(f"Map width: {map_width}") | 190 | print(f"Map width: {map_width}") |
| 183 | print(f"Map height: {map_height}") | 191 | print(f"Map height: {map_height}") |
| 184 | print(f"Tile width: {base_tile_width}") | 192 | print(f"Tile width: {base_tile_width}") |
| 185 | print(f"Tile height: {base_tile_height}") | 193 | print(f"Tile height: {base_tile_height}") |
| 194 | print(f"Orientation: {flags}") | ||
| 186 | 195 | ||
| 187 | tileset_path = None | 196 | tileset_path = None |
| 188 | 197 | ||
| @@ -205,6 +214,7 @@ def convert_tmx(input_filepath, output_filepath): | |||
| 205 | output.write(ctypes.c_uint16(base_tile_width)) | 214 | output.write(ctypes.c_uint16(base_tile_width)) |
| 206 | output.write(ctypes.c_uint16(base_tile_height)) | 215 | output.write(ctypes.c_uint16(base_tile_height)) |
| 207 | output.write(ctypes.c_uint16(num_layers)) | 216 | output.write(ctypes.c_uint16(num_layers)) |
| 217 | output.write(ctypes.c_uint16(flags)) | ||
| 208 | elif child.tag == "layer": | 218 | elif child.tag == "layer": |
| 209 | layer = child | 219 | layer = child |
| 210 | layer_id = int(layer.attrib["id"]) | 220 | layer_id = int(layer.attrib["id"]) |
