From ed7dfaad432b6e3fe838b9a2b5fe225abea5365d Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Tue, 26 May 2026 15:35:13 -0400 Subject: tbh i did a lot --- editor/editor.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 editor/editor.c (limited to 'editor/editor.c') diff --git a/editor/editor.c b/editor/editor.c new file mode 100644 index 0000000..7f88f59 --- /dev/null +++ b/editor/editor.c @@ -0,0 +1,100 @@ +#include "editor.h" + +#include +#include + +#define QOI_IMPLEMENTATION +#include "third/qoi.h" + +Editor editor = {0}; + +void tick(void) +{ + ty_draw_clear(TY_COLOR_BLACK); + + switch (editor.state) { + case EDITOR_TILE: + tile_proc(); + tile_draw(); + break; + } + + tyui_draw(); +} + +ty_Image load_qoi_image(const char *path) +{ + qoi_desc desc; + void *data = qoi_read(path, &desc, 3); + if (!data) + ty_log_fatal(TY_ERR_IO, "failed to read image"); + ty_Image img = ty_create_image(desc.width, desc.height, data); + free(data); + + return img; +} + +void load_font(ty_Font *font, const char *path) +{ + char font_chars[] = + "abcdefghijklmnopqrstuvwxyz0123456789" + "!\"'#$%&()*+,-./@[]\\^_`{}|~:;<>=? " + ; + ty_Image font_img = load_qoi_image(path); + + int glyph_height = 8; + + for (int i = 0; font_chars[i] != '\0'; i++) { + ty_Image glyph = ty_create_image( + font_img.width, + glyph_height, + font_img.data + font_img.width * glyph_height * i + ); + + uint8_t c = *(uint8_t*)&font_chars[i]; + + ty_font_add_glyph(font, c, glyph); + if (c >= 'a' && c <= 'z') + ty_font_add_glyph(font, c - ('a' - 'A'), glyph); + } + + ty_free_image(font_img); +} + +int editor_main(void) +{ + ty_Hints hints = { + .scr_width = SCREEN_WIDTH, + .scr_height = SCREEN_HEIGHT, + .game_title = "Demonchime", + .ticrate = 30, + }; + ty_init(hints); + tyui_init(&editor.font); + + load_font(&editor.font, "font.qoi"); + + editor.state = EDITOR_TILE; + + while (ty_is_game_running()) { + int ticks = ty_tick(); + for (int i = 0; i < ticks; i++) + tick(); + + ty_free_temp_allocs(); + } + + for (int i = 0; i < CHAR_MAX; i++) { + if (i >= 'a' && i <= 'z') + continue; + ty_Image glyph = editor.font.glyphs[i]; + if (glyph.width * glyph.height == 0) + continue; + ty_free_image(glyph); + } + + tyui_deinit(); + ty_deinit(); + + return 0; +} -- cgit v1.3-2-g0d8e