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/main.odin | |
| parent | 2b3a3ea9f4bc902b1b357fd149952d4570b25bf3 (diff) | |
NEW ASSET SYSTEM WOOOOOOOOHOOOOOOOOOOOOOOOOOOOOOOOOO
Diffstat (limited to 'tools/compile_assets/main.odin')
| -rw-r--r-- | tools/compile_assets/main.odin | 129 |
1 files changed, 84 insertions, 45 deletions
diff --git a/tools/compile_assets/main.odin b/tools/compile_assets/main.odin index 60c8a8c..68c5625 100644 --- a/tools/compile_assets/main.odin +++ b/tools/compile_assets/main.odin @@ -27,8 +27,8 @@ Image_Id :: enum { Animation_Id :: enum { <anim-enum>} -Map_Id :: enum { -<map-enum>} +Room_Id :: enum { +<room-enum>} Tileset_Id :: enum { <tileset-enum>} @@ -36,49 +36,46 @@ Tileset_Id :: enum { Resource_Id :: union { Image_Id, Animation_Id, - Map_Id, + Room_Id, Tileset_Id, } -images: [Image_Id]Image_Resource -animations: [Animation_Id]Animation_Resource -maps: [Map_Id]Map_Resource -tilesets: [Tileset_Id]Tileset_Resource +images: [Image_Id]Image_Resource = { +<image-load>} -path_to_id: map[string]Resource_Id +animations: [Animation_Id]Animation_Resource = { +<anim-load>} -load_resources :: proc() { - load_images() - load_anims() - load_maps() - load_tilesets() +rooms: [Room_Id]Room_Resource = { +<room-load>} - // Allow conversion from paths to a resource id, since it's a better way to - // reference resources in other resources (JSON is a good example). -<resource-paths>} +tilesets: [Tileset_Id]Tileset_Resource = { +<tileset-load>} -@(private="file") -load_images :: proc() { -<image-load>} +tiles: []Tile_Resource = { +<tiles-load>} -@(private="file") -load_anims :: proc() { -<anim-load>} +world: []Room_Position_Resource = { +<room-positions>} -@(private="file") -load_maps :: proc() { -<maps-load>} +path_to_id: map[string]Resource_Id = { +<resource-paths>} -@(private="file") -load_tilesets :: proc() { -<tileset-load>} +load_resources :: proc() { +} ` images: map[string]string animations: map[string]string -maps: map[string]string +rooms: map[string]string + +tiles: [dynamic]string tilesets: map[string]string +world: [dynamic]string + +output_dir: string + paths_to_res_type: map[string]string die :: proc(msg: string, args: ..any, exit_code := 1) { @@ -168,13 +165,11 @@ create_loads :: proc( for element in elements { load = strings.concatenate({ load, - " ", - map_name, - "[.", + " .", strings.to_upper_snake_case(element, context.temp_allocator), - "] = ", + " = ", elements[element], - "\n", + ",\n", }, allocator = context.temp_allocator) } return set_placeholder(content, placeholder, load) @@ -199,9 +194,29 @@ main :: proc() { print_help() } + // add dummy + append(&tiles, "") + + // Need to copy, cause you can't just free executable memory, you fool + no_anim_line := "{frame_count=1, frame_durations={100}, tags={}}" + no_anim_line_owned := make([]u8, len(no_anim_line)) + copy_from_string(no_anim_line_owned, no_anim_line) + animations["NONE"] = string(no_anim_line_owned) + input_dir := os.args[1] output_file_path := os.args[2] + abs_output_path, found_abs := filepath.abs( + output_file_path, + context.temp_allocator + ) + if !found_abs { + die("Could not find absolute path to output file") + } + + output_dir = filepath.dir(abs_output_path) + defer delete(output_dir) + output_file, open_err := os.open(output_file_path, {.Write, .Create, .Trunc}) if open_err != nil { die("Could not create output file '%v' (%v)", output_file_path, open_err) @@ -233,8 +248,8 @@ main :: proc() { loaders: map[string]Asset_Loader defer delete(loaders) - loaders["tmj"] = load_map - // loaders["world"] = load_json + loaders["tmj"] = load_room + loaders["world"] = load_world loaders["tsj"] = load_tileset loaders["qoi"] = load_qoi loaders["png"] = load_png @@ -248,7 +263,7 @@ main :: proc() { loader, has := &loaders[ext] if !has { fmt.printfln( - "%-25v Skipped\tNo loader for '%v'", + "%-25v Skipped\tNo loader for '.%v'", file.name, ext, ) @@ -262,7 +277,6 @@ main :: proc() { } defer os.close(f) - fmt.printfln("%-25v Loading...", file.name) loader^(file.fullpath, f, output_file) fmt.printfln("%-25v Loaded", file.name) @@ -276,14 +290,39 @@ main :: proc() { content = create_enum(content, "<image-enum>", images) content = create_enum(content, "<anim-enum>", animations) - content = create_enum(content, "<map-enum>", maps) + content = create_enum(content, "<room-enum>", rooms) content = create_enum(content, "<tileset-enum>", tilesets) content = create_loads(content, "images", "<image-load>", images) content = create_loads(content, "animations", "<anim-load>", animations) - content = create_loads(content, "maps", "<maps-load>", maps) + content = create_loads(content, "rooms", "<room-load>", rooms) content = create_loads(content, "tilesets", "<tileset-load>", tilesets) + tile_loads := "" + for tile, i in tiles { + if i == 0 { + continue + } + tile_loads = strings.concatenate({ + tile_loads, + " ", + tile, + ",\n", + }, allocator = context.temp_allocator) + } + content = set_placeholder(content, "<tiles-load>", tile_loads) + + room_pos_loads := "" + for room_pos, i in world { + room_pos_loads = strings.concatenate({ + room_pos_loads, + " ", + room_pos, + ",\n", + }, allocator = context.temp_allocator) + } + content = set_placeholder(content, "<room-positions>", room_pos_loads) + res_paths := "" cwd, _ := os.get_working_directory(context.temp_allocator) @@ -300,13 +339,13 @@ main :: proc() { rel_path, _ := filepath.rel(cwd, file.fullpath, context.temp_allocator) res_paths = strings.concatenate({ res_paths, - " path_to_id[\"", + " \"", rel_path, - "\"] = ", + "\" = ", res_type, ".", res_name, - "\n", + ",\n", }, allocator = context.temp_allocator) } content = set_placeholder(content, "<resource-paths>", res_paths) @@ -319,8 +358,8 @@ main :: proc() { for anim in animations { delete(animations[anim]) } - for tmap in maps { - delete(maps[tmap]) + for room in rooms { + delete(rooms[room]) } free_all(context.temp_allocator) |
