diff options
author | kdx <kikoodx@paranoici.org> | 2024-02-19 19:33:33 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2024-02-19 19:33:33 +0100 |
commit | bcea42a39273f2be44bd01def735f3227dad7e32 (patch) | |
tree | 1cd0fb65ace041d533ef70ace02c6f5834be622e | |
parent | 18de5bdcefbc8da75ac139f31a1087ee425139de (diff) | |
download | aancyk-bcea42a39273f2be44bd01def735f3227dad7e32.tar.gz |
-rw-r--r-- | inc/config.h | 2 | ||||
-rw-r--r-- | src/config.c | 9 | ||||
-rw-r--r-- | src/editor.c | 9 |
3 files changed, 20 insertions, 0 deletions
diff --git a/inc/config.h b/inc/config.h index 7b88182..47f5d72 100644 --- a/inc/config.h +++ b/inc/config.h @@ -1,4 +1,5 @@ #pragma once +#include <SDL2/SDL_scancode.h> typedef struct Config { int tile_width; @@ -10,6 +11,7 @@ typedef struct Config { char *path; char *tileset_path; char *world_path; + unsigned binds[10]; } Config; Config *config_load(const char *path); diff --git a/src/config.c b/src/config.c index 524f4ee..beca5af 100644 --- a/src/config.c +++ b/src/config.c @@ -1,5 +1,6 @@ #include "config.h" #include "ini.h" +#include <SDL2/SDL_keyboard.h> #define expect(X) if (!(X)) { \ pwrn("expect failed: "STR(X)); \ @@ -93,6 +94,14 @@ config_load(const char *path) } expect(cfg->world_height > 0); + forloop (i, 0, 10) { + char key[2] = { '0' + i, '\0' }; + with (bind, ini_get(ini, "bind", key)) + cfg->binds[i] = atoi(bind); + else + cfg->binds[i] = i; + } + ini_free(ini); return cfg; } diff --git a/src/editor.c b/src/editor.c index 85bfb9d..e64a708 100644 --- a/src/editor.c +++ b/src/editor.c @@ -204,4 +204,13 @@ _ev_key(Window *this, Root *root) world_move(root->world, 0, 1); if (input_key_pressed(input, SDL_SCANCODE_D)) world_move(root->world, 1, 0); + forloop (i, 0, 10) { + const SDL_Scancode k = SDL_SCANCODE_1 + i; + if (input_key_pressed(input, k)) { + grid_resize(root->brush, 1, 1); + grid_set(root->brush, 0, 0, root->cfg->binds[i] + 1); + this->redraw = true; + root->windows[WIN_TILES]->redraw = true; + } + } } |