work on animation editor a bit

This commit is contained in:
Tuomas Katajisto 2025-10-27 22:50:20 +02:00
parent 3c4bb9e100
commit 83fa57906e
4 changed files with 72 additions and 1 deletions

View File

@ -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) { draw_animation_studio_ui :: (theme: *GR.Overall_Theme) {
if g_spritesheets.count < 1 then return; 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); GR.label(r2, "Step Y", *theme.label_theme);
r2.y += r2.h * 1.1; 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); 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 := New(Ui_Texture ,,temp);
uiTex.tex = current_sheet_ptr.sheet; 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}); 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(); set_shader_for_color();
} }
draw_animation_picker(theme);
} }

View File

@ -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 { if mouse3Active {
lastInputTime = get_time(); lastInputTime = get_time();
diff := mouse3ActivationPosition - Vector2.{input_mouse_x, input_mouse_y}; diff := mouse3ActivationPosition - Vector2.{input_mouse_x, input_mouse_y};

View File

@ -120,6 +120,7 @@ init_after_asset_pack :: () {
init_editor(); init_editor();
lworlds(); lworlds();
init_spritesheets(); init_spritesheets();
lanim();
init_rendering(); init_rendering();
load_color_lut_images(); load_color_lut_images();
load_post_process_from_pack(); load_post_process_from_pack();

View File

@ -13,6 +13,7 @@ Spritesheet :: struct {
} }
Animation :: struct { Animation :: struct {
name : string;
spritesheet : string; spritesheet : string;
ids : [..]u32; ids : [..]u32;
fps : float; fps : float;