diff options
| author | zlago | 2024-09-27 18:34:24 +0200 | 
|---|---|---|
| committer | zlago | 2024-09-27 18:34:24 +0200 | 
| commit | e304b0a4acc3f0870f55e6b584c464096333dfdc (patch) | |
| tree | 9c985b966d758020e0aa0efdd8cbdb69ec716412 /utl | |
| parent | d3dc2389c308278442831f370950b2d25e5fa734 (diff) | |
tilemap collision
the 'middle ground' layer is the only layer which is solid,
and the boundary between the background and the foreground
additionally, the maps now can have a custom sky color
Diffstat (limited to 'utl')
| -rw-r--r-- | utl/json2map/main.c | 50 | 
1 files changed, 49 insertions, 1 deletions
diff --git a/utl/json2map/main.c b/utl/json2map/main.c index f3e7716..b298626 100644 --- a/utl/json2map/main.c +++ b/utl/json2map/main.c @@ -12,15 +12,22 @@ struct tilemap_T {  #define PACKED __attribute__((__packed__)) +#define MAGIC "TMv1" +  struct PACKED sets { +	uint8_t magic[4];  	uint32_t tilesets_count;  	uint32_t wang_count;  };  struct PACKED map { +	struct { +		uint8_t r, g, b, a; +	} backdrop;  	uint32_t width;  	uint32_t height;  	uint32_t layers; +	uint32_t middleground;  	uint8_t tiles[];  }; @@ -119,7 +126,7 @@ int main(int argc, char **argv) {  	uint32_t wang_height;  	char *tilesets_data = NULL;  	size_t tilesets_size = 0; -	struct sets counts = {0, 0}; +	struct sets counts = {MAGIC, 0, 0};  	cJSON_ArrayForEach(tileset, tilesets) {  		//printf("=== tileset (%% tiles) ===\n"); @@ -217,12 +224,39 @@ int main(int argc, char **argv) {  		return 1;  	}  	struct map map = { +		.backdrop = {0x9f, 0x9f, 0x9f, 0xff},  		.width = width_obj->valueint - 1,  		.height = height_obj->valueint - 1,  		.layers = 0, +		.middleground = 0,  	};  	uint8_t *tile_data = NULL;  	float *parallaxes = NULL; + +	cJSON const *backdrop = cJSON_GetObjectItemCaseSensitive(json, "backgroundcolor"); +	if (cJSON_IsString(backdrop)) { +		switch (strlen(backdrop->valuestring)) { +			unsigned value; +			case 9: +				value = strtoul(backdrop->valuestring + 1, NULL, 16); +				map.backdrop.r = value >> 16; +				map.backdrop.g = value >> 8; +				map.backdrop.b = value >> 0; +				map.backdrop.a = value >> 24; +				break; +			case 7: +				value = strtoul(backdrop->valuestring + 1, NULL, 16); +				map.backdrop.r = value >> 16; +				map.backdrop.g = value >> 8; +				map.backdrop.b = value >> 0; +				map.backdrop.a = 0xff; +				break; +			default: +				fputs("incorrect backdrop color format\n", stderr); +				return 1; +		} +	} +	//printf("sky: # %02x %02x %02x %02x\n", map.backdrop.r, map.backdrop.g, map.backdrop.b, map.backdrop.a);  	cJSON const *layers = cJSON_GetObjectItemCaseSensitive(json, "layers");  	cJSON const *layer = NULL; @@ -334,6 +368,20 @@ int main(int argc, char **argv) {  		} else {  			// ??? layer  		} + +		cJSON const *properties = cJSON_GetObjectItemCaseSensitive(layer, "properties"); +		cJSON const *property = NULL; +		cJSON_ArrayForEach (property, properties) { +			char const *const name = cJSON_GetObjectItemCaseSensitive(property, "name")->valuestring; +			if (strcmp(name, "middleground") == 0) { +				if (cJSON_IsTrue(cJSON_GetObjectItemCaseSensitive(property, "value"))) { +					map.middleground = map.layers; +				} +			} else { +				printf("unknown property '%s'\n", name); +				return 1; +			} +		}  	}  	fwrite(&counts, 1, sizeof (counts), outfile);  | 
