From e6bf7e77797103ee7ab0eda57c360c38f1b2089c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 2 Sep 2025 18:41:59 -0700 Subject: Add map orientation. --- include/isogfx/asset.h | 11 +++++++++++ src/isogfx.c | 2 ++ tools/mkasset.py | 10 ++++++++++ 3 files changed, 23 insertions(+) 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 { // Tile map (TM) file format. // ----------------------------------------------------------------------------- +typedef enum Tm_Orientation { + Tm_Orthogonal = 0, + Tm_Isometric = 1, +} Tm_Orientation; + +typedef struct Tm_Flags { + Tm_Orientation orientation : 1; + int unused : 15; +} Tm_Flags; + typedef struct Tm_Layer { Tile tiles[1]; // Count: world_width * world_height. } Tm_Layer; @@ -54,6 +64,7 @@ typedef struct Tm_Map { uint16_t base_tile_width; uint16_t base_tile_height; uint16_t num_layers; + uint16_t flags; // Tm_flagsFlags Tm_Layer layers[]; // Count: num_layers. } Tm_Map; 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) { } Tm_Map* const map = iso->map; + printf("Map orientation: %d\n", ((Tm_Flags*)&map->flags)->orientation); + // Load the tile set. // // 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 @@ import argparse import ctypes import sys +from enum import IntEnum from typing import Generator from xml.etree import ElementTree @@ -23,6 +24,12 @@ from PIL import Image MAX_PATH_LENGTH = 128 +class Orientation(IntEnum): + """Map orientation. Must match Tm_Orientation in asset.h""" + Orthogonal = 0 + Isometric = 1 + + def drop_extension(filepath): return filepath[:filepath.rfind('.')] @@ -178,11 +185,13 @@ def convert_tmx(input_filepath, output_filepath): base_tile_width = int(root.attrib["tilewidth"]) base_tile_height = int(root.attrib["tileheight"]) num_layers = 1 + flags = Orientation.Isometric if (root.attrib["orientation"] == "isometric") else Orientation.Orthogonal print(f"Map width: {map_width}") print(f"Map height: {map_height}") print(f"Tile width: {base_tile_width}") print(f"Tile height: {base_tile_height}") + print(f"Orientation: {flags}") tileset_path = None @@ -205,6 +214,7 @@ def convert_tmx(input_filepath, output_filepath): output.write(ctypes.c_uint16(base_tile_width)) output.write(ctypes.c_uint16(base_tile_height)) output.write(ctypes.c_uint16(num_layers)) + output.write(ctypes.c_uint16(flags)) elif child.tag == "layer": layer = child layer_id = int(layer.attrib["id"]) -- cgit v1.2.3