From 8f53ecbdc7c970d2c2ce630c302e5a8955567983 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Sat, 27 Mar 2021 19:15:08 +0100 Subject: [PATCH] Tile first config option (-tile-first) --- README | 1 + include/conf.h | 1 + include/options.h | 1 + sample.kble | Bin 262 -> 262 bytes src/editing_area/draw.c | 5 ++--- src/main.c | 4 ++++ src/options.c | 1 + 7 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README b/README index 8ea20b1..7df6888 100644 --- a/README +++ b/README @@ -64,6 +64,7 @@ These flags take integers as argument. -tile-height -level-width : used by -create -level-height : used by -create +-tile-first -editor-width -editor-height -editor-target-fps diff --git a/include/conf.h b/include/conf.h index 9f53a66..24dfaea 100644 --- a/include/conf.h +++ b/include/conf.h @@ -6,6 +6,7 @@ #define TILE_WIDTH 16 #define TILE_HEIGHT 16 +#define TILE_FIRST 0 #define EDITOR_BACKGROUND_COLOR \ (Color) { 0, 0, 0, 255 } diff --git a/include/options.h b/include/options.h index 3818247..25d0269 100644 --- a/include/options.h +++ b/include/options.h @@ -13,6 +13,7 @@ struct Options { /* optionnal arguments, default values in conf.h */ int tile_width; int tile_height; + int tile_first; int new_level_width; int new_level_height; int editor_width; diff --git a/sample.kble b/sample.kble index 3c18d3bc85b8ea3921243f949b5e1f6bf30468e7..71997e21b93c00a026744a5f17d029a3713c7596 100644 GIT binary patch literal 262 zcmaKm%Mrjp2tuWU^xv%E!Fb3e>#U04XEcv(YfGGU;7MAM1OxJ^gw$wVGjB8JDp<@Y otdMqhc4$%@YIwIEQ`mLn_sUm&ga0DR@J_NQgFb6G)hy08zW|UgEdT%j literal 262 zcmZQzWDo#Ctbh>&;4)wyLIlhLi$PQXnP3K#hH)7fAS?tQC;(K5WH1B54!C8w88Cy0 Kr(tH{u?7G~Gyq}% diff --git a/src/editing_area/draw.c b/src/editing_area/draw.c index cc96203..d7c24fc 100644 --- a/src/editing_area/draw.c +++ b/src/editing_area/draw.c @@ -18,10 +18,9 @@ void level_draw(struct Level level, struct Options options, /* if tile index is out of bound, skip */ if (tile_index >= level.width * level.height) continue; - const Tile tile = - level.data[x + y * level.width]; + const Tile tile = level.data[tile_index] - options.tile_first; /* if tile is not in tileset, skip */ - if (!tile || tile >= options.tileset_width * + if (tile < 0 || (!tile && !options.tile_first) || tile >= options.tileset_width * options.tileset_height) continue; diff --git a/src/main.c b/src/main.c index 1085be4..b2a3e3f 100644 --- a/src/main.c +++ b/src/main.c @@ -99,6 +99,7 @@ static void process_arguments(int argc, char **argv, {"tileset", required_argument, 0, 't'}, {"tile-width", required_argument, 0, 'w'}, {"tile-height", required_argument, 0, 'h'}, + {"tile-first", required_argument, 0, 'I'}, {"level-width", required_argument, 0, 'i'}, {"level-height", required_argument, 0, 'e'}, {"editor-width", required_argument, 0, 'W'}, @@ -136,6 +137,9 @@ static void process_arguments(int argc, char **argv, case 'h': /* tile height */ options->tile_height = int_arg_min(opt, 1); break; + case 'I': /* first tile index */ + options->tile_first = int_arg_min(opt, 0); + break; case 'i': /* new level width */ options->new_level_width = int_arg_min(opt, 1); break; diff --git a/src/options.c b/src/options.c index 12e92f8..5911d51 100644 --- a/src/options.c +++ b/src/options.c @@ -8,6 +8,7 @@ struct Options options_defaults(void) .level_path = "", .tile_width = TILE_WIDTH, .tile_height = TILE_HEIGHT, + .tile_first = TILE_FIRST, .tileset_width = 0, .tileset_height = 0, .new_level_width = NEW_LEVEL_WIDTH,