aboutsummaryrefslogtreecommitdiff
path: root/editor/editor.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-26 15:35:13 -0400
committeriamcheeseman <[email protected]>2026-05-26 15:35:13 -0400
commited7dfaad432b6e3fe838b9a2b5fe225abea5365d (patch)
tree0af2e01a688d963ec6d2977802dbeb9156335845 /editor/editor.c
parent8122098e3854bf68ca63cc25e082ba51a27b8615 (diff)
tbh i did a lot
Diffstat (limited to 'editor/editor.c')
-rw-r--r--editor/editor.c100
1 files changed, 100 insertions, 0 deletions
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 <teensy.h>
+#include <teensy_ui.h>
+
+#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;
+}