summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-09 15:47:28 +0200
committerkdx <kikoodx@paranoici.org>2023-04-09 16:00:06 +0200
commit35f474e43848d76fcbe93899fd3ef8569497bde8 (patch)
tree0d5e5542458d40766f88397fa219306bb6eec659
parent30cc0028ae12c7846f9558206366ab2cd495dd49 (diff)
downloadtiled2c-35f474e43848d76fcbe93899fd3ef8569497bde8.tar.gz
pass name as second arg
-rw-r--r--src/main.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index d85b52d..09341a9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,7 +37,7 @@ process_frame(cJSON *json)
{
JSON_GET(json, duration);
JSON_GET(json, tileid);
- printf("{%d,%d}", duration->valueint, tileid->valueint);
+ printf("{%d,%d},", duration->valueint, tileid->valueint);
return 0;
}
@@ -76,7 +76,7 @@ process_tile(cJSON *json)
printf("0,0");
else if (process_animation(anim) < 0)
return -1;
- printf("}");
+ printf("},");
return 0;
}
@@ -94,7 +94,8 @@ process_tileset(const char *word, cJSON *json)
JSON_GET(json, columns);
JSON_GET(json, tilecount);
- printf("static const Tiled2cSet %s={\"%s\",\"%s\",%d,%d,%d,%d,%d,%d,%d,"
+ printf("#include \"tiled2c.h\"\n"
+ "const Tiled2cSet %s={\"%s\",\"%s\",%d,%d,%d,%d,%d,%d,%d,"
"%d,(const Tiled2cTile[]){",
word, name->valuestring, image->valuestring,
imagewidth->valueint, imageheight->valueint,
@@ -105,7 +106,7 @@ process_tileset(const char *word, cJSON *json)
cJSON_ArrayForEach(tile, tiles)
if (process_tile(tile))
return -1;
- printf("};\n");
+ printf("}};\n");
return 0;
}
@@ -135,7 +136,7 @@ drain(FILE *fp, long *size)
}
static int
-process(const char *path)
+process(const char *path, const char *name)
{
FILE *fp = fopen(path, "rb");
if (fp == NULL) {
@@ -160,18 +161,14 @@ process(const char *path)
return -1;
}
- char word[256] = {0};
- for (size_t i = 0; i < sizeof(word) - 1 && path[i] != '\0'; i++)
- word[i] = isalnum(path[i]) ? path[i] : '_';
-
const char *const type_s = cJSON_GetStringValue(type);
switch (type_s[0]) {
case 'm': /* map */
- if (process_map(word, json) < 0)
+ if (process_map(name, json) < 0)
goto process_panic;
break;
case 't': /* tileset */
- if (process_tileset(word, json) < 0)
+ if (process_tileset(name, json) < 0)
goto process_panic;
break;
default:
@@ -191,12 +188,12 @@ process_panic:
int
main(int argc, char **argv)
{
- if (argc != 2) {
- fprintf(stderr, "usage: %s <tiled .tsj or .tmj>\n", argv[0]);
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s <tiled .tsj or .tmj> <name>\n",
+ argv[0]);
return 1;
}
- for (int i = 1; i < argc; i++)
- if (process(argv[i]) < 0)
- return 1;
+ if (process(argv[1], argv[2]) < 0)
+ return 1;
return 0;
}