summaryrefslogtreecommitdiff
path: root/src/editor.c
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-07-12 00:24:13 +0100
committerdavidovski <david@davidovski.xyz>2023-07-12 00:24:13 +0100
commit894e465ffcdaf706eaa3de9e426d4c0c10d4513b (patch)
treedd0478beb6a1c678887228f811789bf0bfa103a7 /src/editor.c
parentbdf704744a19a0dc7ea13113321ba13b2fc0f598 (diff)
Add opts to editor
Diffstat (limited to 'src/editor.c')
-rw-r--r--src/editor.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/editor.c b/src/editor.c
index 69162fd..eddd6ad 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -1,6 +1,7 @@
#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "tiled.h"
@@ -94,8 +95,47 @@ TiledMap launchEditor(TiledMap tiledMap) {
return tiled.tiledMap;
}
-int main() {
- TiledMap tiledMap = loadTiledMap("map.tiles");
+void printUsage(char *progname) {
+ fprintf(stderr, "%s [-h] [-t tile_size] [-s map_size] [-a atlas.png]\n", progname);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ char * tiledFilePath;
+ const char * atlasFilePath = NULL;
+ int tileSize = 16;
+ int mapSize = 16;
+
+ int flags, opt;
+ while ((opt = getopt(argc, argv, "s:a:h")) != -1) {
+ switch (opt) {
+ case 's':
+ mapSize = atoi(optarg);
+ case 't':
+ tileSize = atoi(optarg);
+ case 'a':
+ atlasFilePath = optarg;
+ }
+ }
+
+ if (optind >= argc)
+ printUsage(argv[0]);
+
+ tiledFilePath = argv[optind];
+
+ TiledMap tiledMap;
+ if (access(tiledFilePath, F_OK)) {
+ if (atlasFilePath == NULL) {
+ fprintf(stderr, "Atlas file must be specified!\n");
+ printUsage(argv[0]);
+ }
+
+ Image atlasImage = LoadImage(atlasFilePath);
+ tiledMap = newTiledMap(atlasImage, tileSize, mapSize, mapSize);
+ } else {
+ tiledMap = loadTiledMap(tiledFilePath);
+ }
+
TiledMap editedTiledMap = launchEditor(tiledMap);
- saveTiledMap("map.tiles", tiledMap);
+ saveTiledMap(tiledFilePath, tiledMap);
}