Skip to content

Commit 4905bb1

Browse files
committed
fix: use friendly names for asset indexes and sort list by version date
1 parent defd669 commit 4905bb1

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

scripts/control_create/control_create.gml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,18 @@ function control_create() {
488488
// Import sounds
489489
mc_default_path = string_copy(game_save_id, 0, string_last_pos("\\", string_copy(game_save_id, 1, string_length(game_save_id) - 1))) + ".minecraft\\";
490490
mc_install_path = mc_default_path;
491+
492+
var asset_index_names_keys = ["pre-1.6", "legacy", "1.7.3", "1.7.4", "1.7.10", "14w25a", "14w31a", "1.8", "1.9", "1.9-aprilfools", "1.10", "1.11", "1.12", "1.13", "1.13.1", "1.14", "1.14-af", "1.15", "1.16", "1.17", "1.18", "1.19", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "_"];
493+
var asset_index_names_values = ["Pre-1.6", "1.6-1.7", "1.7.3", "1.7.4", "1.7.10", "14w25a", "1.8 Pre-Release 1", "1.8", "1.9", "1.RV-Pre1", "1.10", "1.11", "1.12", "1.13", "1.13.1", "1.14", "3D Shareware v1.34", "1.15", "1.16", "1.17", "1.18", "1.19", "22w42a", "1.19.3", "1.19.4", "23w14a", "1.20", "23w31a", "1.20.2 Pre-Release 1", "1.20.2", "23w42a", "23w43a", "23w45a", "1.20.3", "24w06a", "24w09a", "24w11a", "1.20.5", "1.21", "Future version (1.21+)"];
494+
495+
sound_import_asset_index_names = ds_map_create();
496+
sound_import_asset_index_names_sort = ds_list_create(); // TODO: convert this to an array when array_get_index() is available
497+
498+
for (var i = 0; i < array_length(asset_index_names_keys); i++) {
499+
ds_map_add(sound_import_asset_index_names, asset_index_names_keys[i], asset_index_names_values[i]);
500+
ds_list_add(sound_import_asset_index_names_sort, asset_index_names_keys[i]);
501+
}
502+
491503
sound_import_selected_asset_index = "";
492504
sound_import_asset_index_select = 0;
493505
sound_import_asset_index_count = -1;

scripts/draw_window_sound_import/draw_window_sound_import.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function draw_window_sound_import() {
6767
y1 += 20;
6868
y1 += 1;
6969
draw_area(x1, y1, x1 + 86, y1 + 20);
70-
draw_text_dynamic(x1 + 4, y1 + 4, sound_import_selected_asset_index);
70+
draw_text_dynamic(x1 + 4, y1 + 4, get_asset_index_friendly_name(sound_import_selected_asset_index));
7171
if (draw_abutton(x1 + 86 - 16, y1 + 1, sound_import_menu_str == "")) {
7272
menu = show_menu_ext("sound_import_asset_index", x1, y1, sound_import_menu_str);
7373
}

scripts/sound_import/sound_import.gml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
function get_asset_index_friendly_name(asset_index) {
2+
var friendly_name = ds_map_find_value(sound_import_asset_index_names, asset_index);
3+
if (is_undefined(friendly_name)) {
4+
friendly_name = ds_map_find_value(sound_import_asset_index_names, "_") + " (" + asset_index + ")";
5+
}
6+
7+
return friendly_name;
8+
}
9+
110
function get_assets_dir() {
211
var assets_dir = mc_install_path;
312

@@ -9,7 +18,6 @@ function get_assets_dir() {
918
return assets_dir;
1019
}
1120

12-
1321
function find_asset_indexes() {
1422

1523
if (!directory_exists(mc_install_path)) {
@@ -29,6 +37,10 @@ function find_asset_indexes() {
2937
}
3038
file_find_close();
3139

40+
array_sort(asset_indexes, function(elm1, elm2) {
41+
return ds_list_find_index(sound_import_asset_index_names_sort, elm1) < ds_list_find_index(sound_import_asset_index_names_sort, elm2);
42+
});
43+
3244
return asset_indexes;
3345
}
3446

@@ -52,7 +64,7 @@ function update_asset_index_menu() {
5264
sound_import_menu_str = "";
5365
for (var i = 0; i < array_length(sound_import_asset_indexes); i++) {
5466
sound_import_menu_str += check(sound_import_asset_index_select == i);
55-
sound_import_menu_str += sound_import_asset_indexes[i] + "|";
67+
sound_import_menu_str += get_asset_index_friendly_name(sound_import_asset_indexes[i]) + "|";
5668
}
5769
sound_import_menu_str = string_delete(sound_import_menu_str, string_length(sound_import_menu_str), 1)
5870

0 commit comments

Comments
 (0)