#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_end_frame(); } 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_clear_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; }