From 83fa57906e35433fd320a6e676a65bec0eb45352 Mon Sep 17 00:00:00 2001 From: Katajisto Date: Mon, 27 Oct 2025 22:50:20 +0200 Subject: [PATCH] work on animation editor a bit --- src/editor/animation_studio.jai | 69 +++++++++++++++++++++++++++++++++ src/editor/level_editor.jai | 2 +- src/main.jai | 1 + src/rendering/animation.jai | 1 + 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/editor/animation_studio.jai b/src/editor/animation_studio.jai index 282a50b..7daf3ee 100644 --- a/src/editor/animation_studio.jai +++ b/src/editor/animation_studio.jai @@ -22,6 +22,68 @@ tick_animation_studio :: () { } +add_anim :: (name: string) { + anim_name := sprint("%", name); + animation := Animation.{ + name = anim_name, + spritesheet = current_sheet_ptr.name, + fps = 1 + }; + table_add(*g_animations, sprint("%", anim_name), animation); +} @Command + +sanim :: () { + Jaison :: #import "Jaison"; + anims : [..]Animation; + anims.allocator = temp; + for v : g_animations { + array_add(*anims, v); + } + #if OS != .WASM { + file :: #import "File"; + json := Jaison.json_write_string(anims, " ",, temp); + file.write_entire_file("./game/resources/animations.json", json); + } +} @Command + +lanim :: () { + Jaison :: #import "Jaison"; + s := load_string_from_pack("./game/resources/animations.json"); + success, anims := Jaison.json_parse_string(s, [..]Animation,, temp); + if !success then return; + for anims { + print("Loaded %\n", it.name); + + ids : [..]u32; + for id : it.ids { + array_add(*ids, id); + } + + name_cpy := sprint("%", it.name); + newAnimation := Animation.{ + name = name_cpy, + fps = it.fps, + spritesheet = sprint("%", it.spritesheet), + ids = ids + }; + table_add(*g_animations, name_cpy, newAnimation); + } +} @Command + +draw_animation_picker :: (theme: *GR.Overall_Theme) { + r := GR.get_rect(ui_w(80,0), ui_h(5,0), ui_w(20, 0), ui_h(95, 0)); + ui_add_mouse_occluder(r); + draw_bg_rectangle(r, theme); + r.h = ui_h(5,0); + + i := 0; + for v : g_animations { + GR.button(r, v.name, *theme.button_theme, i); + r.y += r.h; + i += 1; + } +} + draw_animation_studio_ui :: (theme: *GR.Overall_Theme) { if g_spritesheets.count < 1 then return; @@ -55,6 +117,11 @@ draw_animation_studio_ui :: (theme: *GR.Overall_Theme) { GR.label(r2, "Step Y", *theme.label_theme); r2.y += r2.h * 1.1; GR.number_input(r2, tprint("%", current_sheet_ptr.step_y), *current_sheet_ptr.step_y, 0, 128, *number_theme); + + r2.y += r2.h * 1.1; + GR.label(r2, "Frames", *theme.label_theme); + r2.y += r2.h * 1.1; + GR.label(r2, "FPS", *theme.label_theme); uiTex := New(Ui_Texture ,,temp); uiTex.tex = current_sheet_ptr.sheet; @@ -72,4 +139,6 @@ draw_animation_studio_ui :: (theme: *GR.Overall_Theme) { immediate_quad(.{img_r.x, img_r.y}, .{img_r.x + img_r.w, img_r.y}, .{img_r.x + img_r.w, img_r.y + img_r.h}, .{img_r.x, img_r.y + img_r.h}); set_shader_for_color(); } + draw_animation_picker(theme); } + diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index a7a4650..12c1dcf 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -154,7 +154,7 @@ tick_level_editor_camera :: () { } - if get_mouse_state(Key_Code.MOUSE_BUTTON_LEFT) & .DOWN { + if get_mouse_state(Key_Code.MOUSE_BUTTON_RIGHT) & .DOWN { if mouse3Active { lastInputTime = get_time(); diff := mouse3ActivationPosition - Vector2.{input_mouse_x, input_mouse_y}; diff --git a/src/main.jai b/src/main.jai index 9e853d0..25fa9ce 100644 --- a/src/main.jai +++ b/src/main.jai @@ -120,6 +120,7 @@ init_after_asset_pack :: () { init_editor(); lworlds(); init_spritesheets(); + lanim(); init_rendering(); load_color_lut_images(); load_post_process_from_pack(); diff --git a/src/rendering/animation.jai b/src/rendering/animation.jai index 6eb8655..2417d52 100644 --- a/src/rendering/animation.jai +++ b/src/rendering/animation.jai @@ -13,6 +13,7 @@ Spritesheet :: struct { } Animation :: struct { + name : string; spritesheet : string; ids : [..]u32; fps : float;