diff options
| author | iamcheeseman <[hidden email]> | 2026-01-12 20:51:28 -0500 |
|---|---|---|
| committer | iamcheeseman <[hidden email]> | 2026-01-12 20:51:28 -0500 |
| commit | 7fb83578b99aa224f7545f4118a46e84b58a9295 (patch) | |
| tree | 515e294ac7de167c4501cc0a8d375b13213faf36 /tools/compile_assets/loaders.odin | |
| parent | 2b3a3ea9f4bc902b1b357fd149952d4570b25bf3 (diff) | |
NEW ASSET SYSTEM WOOOOOOOOHOOOOOOOOOOOOOOOOOOOOOOOOO
Diffstat (limited to 'tools/compile_assets/loaders.odin')
| -rw-r--r-- | tools/compile_assets/loaders.odin | 97 |
1 files changed, 73 insertions, 24 deletions
diff --git a/tools/compile_assets/loaders.odin b/tools/compile_assets/loaders.odin index 136ba07..648fe49 100644 --- a/tools/compile_assets/loaders.odin +++ b/tools/compile_assets/loaders.odin @@ -11,20 +11,35 @@ import "core:image/qoi" import ase "aseprite" import aseutil "aseprite/utils" -load_map :: proc(path: string, _: ^os.File, _: ^os.File) { - line := fmt.aprintf("#load(\"%v\")", path) - maps[filepath.stem(path)] = line - paths_to_res_type[path] = "Map_Id" +load_world :: proc(path: string, file: ^os.File, _: ^os.File) { + load_json_world(path) +} + +load_room :: proc(path: string, file: ^os.File, _: ^os.File) { + load_json_room(path, file) + paths_to_res_type[path] = "Room_Id" } load_tileset :: proc(path: string, _: ^os.File, _: ^os.File) { - line := fmt.aprintf("#load(\"%v\")", path) - tilesets[filepath.stem(path)] = line - paths_to_res_type[path] = "Tileset_Id" + load_json_tileset(path) } load_qoi :: proc(path: string, qoi: ^os.File, output: ^os.File) { - line := fmt.aprintf("{{data = #load(%w)}}", path) + rel_path, rel_err := filepath.rel( + output_dir, + path, + context.temp_allocator, + ) + if rel_err != nil { + die( + "Could not find relative path from %v to %v (%v)", + output_dir, + path, + rel_err, + ) + } + + line := fmt.aprintf("{{data = #load(%w), anim = .NONE}}", rel_path) images[filepath.stem(path)] = line paths_to_res_type[path] = "Image_Id" @@ -60,22 +75,39 @@ load_png :: proc(path: string, png_file: ^os.File, output: ^os.File) { die("Could not convert PNG to QOI (%v)", qoi_err) } - absolute_path, abs_ok := filepath.abs( + abs_path, found_abs := filepath.abs( compiled_path, - allocator = context.temp_allocator, + context.temp_allocator ) - if !abs_ok { - die("Could not find absolute path to a compiled file (%v)", compiled_path) + if !found_abs { + die("Could not find absolute path for %v", compiled_path) } - line := fmt.aprintf("{{data = #load(%w)}}", absolute_path) + rel_path, rel_err := filepath.rel( + output_dir, + abs_path, + context.temp_allocator, + ) + if rel_err != nil { + die( + "Could not find relative path from %v to %v (%v)", + output_dir, + compiled_path, + rel_err, + ) + } + + line := fmt.aprintf("{{data = #load(%w), anim = .NONE}}", rel_path) images[filepath.stem(path)] = line paths_to_res_type[path] = "Image_Id" } @(private="file") -load_sprite_sheet :: proc(path: string, doc: ^ase.Document) { +load_sprite_sheet :: proc( + path: string, + doc: ^ase.Document +) { sprite_sheet, ss_err := aseutil.create_sprite_sheet(doc, { size = {int(doc.header.width), int(doc.header.height)}, count = int(doc.header.frames), @@ -89,8 +121,6 @@ load_sprite_sheet :: proc(path: string, doc: ^ase.Document) { } defer aseutil.destroy(sprite_sheet) - fmt.println("loaded ss") - pixels := make( []image.RGBA_Pixel, sprite_sheet.width * sprite_sheet.height, @@ -126,15 +156,34 @@ load_sprite_sheet :: proc(path: string, doc: ^ase.Document) { die("Could not save spritesheet %v (%v)", path, qoi_err) } - absolute_path, abs_ok := filepath.abs( + abs_path, found_abs := filepath.abs( compiled_path, - allocator = context.temp_allocator, + context.temp_allocator + ) + if !found_abs { + die("Could not find absolute path for %v", compiled_path) + } + + rel_path, rel_err := filepath.rel( + output_dir, + abs_path, + context.temp_allocator, ) - if !abs_ok { - die("Could not find absolute path to a compiled file (%v)", compiled_path) + if rel_err != nil { + die( + "Could not find relative path from %v to %v (%v)", + output_dir, + compiled_path, + rel_err, + ) } - line := fmt.aprintf("{{data = #load(%w)}}", absolute_path) + anim_name := strings.to_screaming_snake_case( + filepath.stem(path), + allocator = context.temp_allocator, + ) + + line := fmt.aprintf("{{data = #load(%w), anim = .%v}}", rel_path, anim_name) images[filepath.stem(path)] = line paths_to_res_type[path] = "Image_Id" } @@ -191,9 +240,9 @@ load_ase :: proc(path: string, ase_file: ^os.File, output: ^os.File) { die("Could not unmarshal aseprite file %v (%v)", path, unmarshal_err) } - // Load sprite sheet - load_sprite_sheet(path, &doc) - // Load animation load_animation(path, &doc) + + // Load sprite sheet + load_sprite_sheet(path, &doc) } |
