diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/compile_assets/main.odin | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/tools/compile_assets/main.odin b/tools/compile_assets/main.odin index ea1ff90..b9c33db 100644 --- a/tools/compile_assets/main.odin +++ b/tools/compile_assets/main.odin @@ -4,6 +4,7 @@ import os "core:os/os2" import "core:fmt" import "core:path/filepath" import "core:strings" +import "core:sort" COMPILED_DIR :: ".compiled-res/" HELP_STR :: `USAGE: %v [input dir] [output file].odin` @@ -136,6 +137,22 @@ recursive_read_directory :: proc( return full_files[:], nil } +sort_keys :: proc( + m: map[string]$V, + allocator := context.allocator, +) -> []string { + arr := make([]string, len(m), allocator) + i := 0 + for k, _ in m { + arr[i] = k + i += 1 + } + + sort.merge_sort(arr) + + return arr +} + create_enum :: proc( content: string, replace: string, @@ -143,11 +160,12 @@ create_enum :: proc( ) -> string { ids := "" - for element in elements { + keys := sort_keys(elements, context.temp_allocator) + for key in keys { ids = strings.concatenate({ ids, " ", - strings.to_upper_snake_case(element, context.temp_allocator), + strings.to_upper_snake_case(key, context.temp_allocator), ",\n" }, allocator = context.temp_allocator) } @@ -169,13 +187,14 @@ create_loads :: proc( elements: map[string]string ) -> string { load := "" - for element in elements { + keys := sort_keys(elements, context.temp_allocator) + for key in keys { load = strings.concatenate({ load, " .", - strings.to_upper_snake_case(element, context.temp_allocator), + strings.to_upper_snake_case(key, context.temp_allocator), " = ", - elements[element], + elements[key], ",\n", }, allocator = context.temp_allocator) } @@ -358,8 +377,10 @@ main :: proc() { content = set_placeholder(content, "<resource-paths>", res_paths) object_type_enum := "" - - for object_type in object_type_names { + for object_type in sort_keys( + object_type_names, + allocator = context.temp_allocator, + ) { object_type_enum = strings.concatenate({ object_type_enum, " ", |
