Skip to content

Commit 86b8efe

Browse files
committed
feat: complete import sound feature
1 parent 32674cb commit 86b8efe

File tree

5 files changed

+126
-61
lines changed

5 files changed

+126
-61
lines changed

scripts/control_create/control_create.gml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,12 @@ 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+
sound_import_selected_asset_index = "";
491492
sound_import_asset_index_select = 0;
492493
sound_import_asset_index_count = -1;
493494
sound_import_asset_indexes = [];
494495
sound_import_menu_str = "";
496+
sound_import_status = 0;
495497

496498
// Schematic
497499
reset_schematic_export(0)

scripts/draw_abutton/draw_abutton.gml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
function draw_abutton(argument0, argument1) {
1+
function draw_abutton(argument0, argument1, lock=false) {
22
// draw_abutton(x, y)
33
var xx, yy, m;
44
xx = argument0
55
yy = argument1
6-
m = mouse_rectangle(xx, yy, 17, 18) && sb_drag = -1 && w_isdragging = 0
6+
m = !lock && mouse_rectangle(xx, yy, 17, 18) && sb_drag = -1 && w_isdragging = 0
77
if (m) m += mouse_check_button(mb_left)
88
if (hires && theme = 3) draw_sprite_ext(spr_button_arrow_hires, m + 3 * (fdark && theme = 3), xx, yy, 0.25, 0.25, 0, -1, draw_get_alpha())
99
else draw_sprite(spr_button_arrow, m + 3 * theme + 3 * (fdark && theme = 3), xx, yy)
10-
return (m && mouse_check_button_released(mb_left))
10+
if (!lock) return (m && mouse_check_button_released(mb_left))
1111

1212

1313

scripts/draw_window_sound_import/draw_window_sound_import.gml

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ function draw_window_sound_import() {
66
var x1, y1, a, n;
77

88
// Window frame
9-
var width = 400;
10-
var height = 300;
9+
var width = 480;
10+
var height = 320;
1111
var startx = floor((rw - width) / 2);
1212
var starty = floor((rh - height) / 2) + windowoffset;
1313
var x1 = startx;
@@ -27,80 +27,102 @@ function draw_window_sound_import() {
2727
y1 += 20;
2828
draw_text_dynamic(
2929
x1, y1,
30-
"This assistant will help you extract sound files from your Minecraft:" + "\n" +
31-
"Java Edition installation." + "\n" +
32-
"Before continuing, ensure you have launched the version you want from " + "\n" +
33-
"the Minecraft Launcher!" + "\n" +
34-
"Click 'Find asset lists' to look for the available asset lists, select one" + "\n" +
35-
"from the list, and then click 'Import' to look for sounds!"
30+
"This assistant will help you extract sound files from your Minecraft: Java Edition" + "\n" +
31+
"installation." + "\n" +
32+
"Before continuing, ensure you have launched the version you want from the" + "\n" +
33+
"Minecraft Launcher." + "\n" +
34+
"Select a version from the list, and then click 'Import' to look for sounds!"
3635
)
3736

3837
// Minecraft installation path
3938
x1 = startx;
40-
y1 += 120;
39+
y1 += 100;
4140
draw_text_dynamic(x1, y1, "1. Set your Minecraft installation path:");
41+
x1 += 16;
4242
y1 += 20;
43-
draw_text_dynamic(x1, y1, mc_install_path);
43+
draw_text_dynamic(x1, y1, string_truncate(mc_install_path, 280, true));
4444
x1 += 300;
4545

4646
// Change button
4747
y1 -= 4
4848
if (draw_button2(x1, y1, 72, "Change", false, true)) {
4949
var fn = string(get_save_filename_ext("", "Select Minecraft installation directory", mc_install_path, "Minecraft installation directory"));
5050
if (fn != "") mc_install_path = filename_dir(fn);
51+
update_asset_index_menu();
5152
}
5253
x1 += 76;
5354

5455
// Use default button
5556
if (draw_button2(x1, y1, 72, "Use default", false, true)) {
56-
mc_install_path = mc_default_path
57+
mc_install_path = mc_default_path;
58+
update_asset_index_menu();
5759
}
5860
y1 += 4
5961

60-
// Import sounds button
61-
x1 = startx;
62-
y1 += 30;
63-
draw_text_dynamic(x1, y1, "2. Search for available asset lists:");
64-
y1 += 20;
65-
if (draw_button2(x1, y1, 112, "Find asset lists", false, true)) {
66-
sound_import_asset_indexes = find_asset_indexes();
67-
show_debug_message(sound_import_asset_indexes);
68-
69-
// Create menu
70-
for (var i = 0; i < array_length(sound_import_asset_indexes); i++) {
71-
sound_import_menu_str += check(sound_import_asset_index_select = i);
72-
sound_import_menu_str += sound_import_asset_indexes[i] + "|";
73-
}
74-
sound_import_menu_str = string_delete(sound_import_menu_str, string_length(sound_import_menu_str), 1)
75-
76-
}
77-
7862
// Asset index select menu
7963
x1 = startx;
80-
y1 += 30;
81-
draw_text_dynamic(x1, y1, "3. Select the asset list to copy sounds from:");
64+
y1 += 40;
65+
draw_text_dynamic(x1, y1, "2. Select the asset list to copy sounds from:");
66+
x1 += 16;
8267
y1 += 20;
83-
draw_area(x1, y1, x1 + 140, y1 + 16);
84-
if (draw_abutton(x1, y1)) {
68+
y1 += 1;
69+
draw_area(x1, y1, x1 + 100, y1 + 20);
70+
draw_text_dynamic(x1 + 4, y1 + 4, sound_import_selected_asset_index);
71+
if (draw_abutton(x1 + 100 - 16, y1 + 1, sound_import_menu_str == "")) {
8572
show_debug_message(sound_import_menu_str);
8673
menu = show_menu_ext("sound_import_asset_index", x1, y1, sound_import_menu_str);
8774
}
88-
x1 += 144
89-
90-
// Located sounds count
91-
if (sound_import_asset_index_count > -1) {
92-
draw_text_dynamic(x1, y1, sound_import_asset_index_count + " sounds located!")
93-
}
75+
y1 -= 1;
76+
x1 += 110;
9477

9578
// Copy sounds button
96-
if (draw_button2(x1, y1, 112, "Get sounds", false, true)) {
97-
asset_indexes = load_asset_index(sound_import_asset_index_select, copy = true)
79+
var is_locked = sound_import_selected_asset_index == "";
80+
if (draw_button2(x1, y1, 112, "Get sounds", is_locked, false)) {
81+
load_asset_index(true);
9882
}
9983

10084
x1 = startx;
10185
y1 += 30;
102-
10386

87+
// Status text
88+
x1 += 16;
89+
draw_theme_font(font_main_bold);
90+
draw_theme_color();
10491

105-
106-
}
92+
// 0 = idle; 1 = copying; 2 = copying done
93+
if (sound_import_status == 2) {
94+
if (theme == 3 && fdark || theme == 2) draw_set_color(c_lime);
95+
else draw_set_color(c_green);
96+
draw_text_dynamic(x1, y1, string(sound_import_asset_index_count) + " sounds have been copied!");
97+
} else if (sound_import_status == 1) {
98+
draw_text_dynamic(x1, y1, "Copying sounds... please wait!");
99+
} else {
100+
if (sound_import_asset_index_count > 0) {
101+
draw_text_dynamic(x1, y1, string(sound_import_asset_index_count) + " sounds located!");
102+
} else {
103+
draw_set_color(c_red);
104+
draw_text_dynamic(x1, y1, "No sounds located! Check your Minecraft installation path.");
105+
}
106+
}
107+
draw_theme_color();
108+
draw_theme_font(font_main);
109+
110+
// Instrument settings button
111+
x1 = startx + 12;
112+
y1 = starty + height - 20 - 12;
113+
if (draw_button2(x1, y1, 120, "Instrument settings...", false, true)) {
114+
window = w_instruments;
115+
}
116+
// Sounds folder button
117+
x1 += 120 + 12;
118+
if (draw_button2(x1, y1, 120, "Open sounds folder", false, true)) {
119+
open_url(sounds_directory);
120+
}
121+
122+
// OK button
123+
x1 = startx + width - 72 - 8 - 12;
124+
if (draw_button2(x1, y1, 72, "OK", false, false)) {
125+
sound_import_status = 0;
126+
window = 0;
127+
}
128+
}

scripts/menu_click/menu_click.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function menu_click(argument0) {
171171
ins -= floor((ins) / 26) // subtract the "More..." entries to get the instrument number
172172
if (sel < insoffset + 1) {instrument = instrument_list[| ins]; selected_vel = 100; selected_pan = 100; selected_pit = 0}
173173
if (sel = insoffset + 1) window = w_instruments
174-
if (sel = insoffset + 2) window = w_sound_import
174+
if (sel = insoffset + 2) { window = w_sound_import update_asset_index_menu() }
175175
if (sel = insoffset + 3) window = w_songinfoedit
176176
if (sel = insoffset + 4) window = w_properties
177177
if (sel = insoffset + 5) {selection_place(0) window = w_stats}
@@ -393,7 +393,7 @@ function menu_click(argument0) {
393393
}
394394
case "sound_import_asset_index": {
395395
sound_import_asset_index_select = sel;
396-
sound_import_asset_index_count = load_asset_index(sel, false);
396+
update_asset_index_menu();
397397
break;
398398
}
399399
}

scripts/sound_import/sound_import.gml

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
function find_asset_indexes() {
2-
3-
if (!directory_exists(mc_install_path)) {
4-
show_message("No Minecraft installation was found\nat the selected location!");
5-
return;
6-
}
1+
function get_assets_dir() {
2+
var assets_dir = mc_install_path;
73

8-
var assets_dir = mc_install_path
94
if (string_char_at(assets_dir, string_length(assets_dir)) != "\\") {
105
assets_dir = assets_dir + "\\";
116
}
7+
128
assets_dir = assets_dir + "assets\\";
9+
return assets_dir;
10+
}
11+
12+
13+
function find_asset_indexes() {
14+
15+
if (!directory_exists(mc_install_path)) {
16+
show_message("No Minecraft installation was found\nat the selected location!");
17+
return [];
18+
}
1319

1420
// Search for .json files in the assets/ folder
21+
var assets_dir = get_assets_dir();
1522
show_debug_message("Looking for index files at " + assets_dir);
1623
var asset_indexes = [];
1724
var file_name = file_find_first(assets_dir + "indexes\\*.json", 0);
@@ -26,12 +33,42 @@ function find_asset_indexes() {
2633
}
2734

2835

29-
function load_asset_index(index_name, copy = false) {
36+
function update_asset_index_menu() {
37+
sound_import_asset_indexes = find_asset_indexes();
38+
show_debug_message(sound_import_asset_indexes);
3039

40+
if (array_length(sound_import_asset_indexes) == 0) {
41+
sound_import_asset_index_select = 0;
42+
sound_import_selected_asset_index = "";
43+
sound_import_asset_index_count = 0;
44+
} else {
45+
if (sound_import_asset_index_select > array_length(sound_import_asset_indexes) - 1) {
46+
sound_import_asset_index_select = 0;
47+
}
48+
sound_import_selected_asset_index = sound_import_asset_indexes[sound_import_asset_index_select];
49+
}
50+
51+
// Create menu
52+
sound_import_menu_str = "";
53+
for (var i = 0; i < array_length(sound_import_asset_indexes); i++) {
54+
sound_import_menu_str += check(sound_import_asset_index_select == i);
55+
sound_import_menu_str += sound_import_asset_indexes[i] + "|";
56+
}
57+
sound_import_menu_str = string_delete(sound_import_menu_str, string_length(sound_import_menu_str), 1)
58+
59+
// Load selected asset index
60+
load_asset_index(false);
61+
}
62+
63+
64+
function load_asset_index(copy = false) {
3165
// Loads an asset index.
3266

3367
// Open and parse asset index
34-
var asset_index_path = assets_dir + "indexes\\" + "16.json"
68+
var assets_dir = get_assets_dir();
69+
var selected_asset_list = sound_import_selected_asset_index;
70+
if (selected_asset_list == "") return;
71+
var asset_index_path = assets_dir + "indexes\\" + selected_asset_list + ".json";
3572
if (!file_exists(asset_index_path)) {
3673
show_message("The file for the specified asset index could not be found!")
3774
return;
@@ -49,12 +86,13 @@ function load_asset_index(index_name, copy = false) {
4986

5087
var sounds_mc_subdir = sounds_directory + "minecraft";
5188

52-
if (directory_exists_lib(sounds_mc_subdir)) {
89+
if (copy && directory_exists_lib(sounds_mc_subdir)) {
5390
if (!message_yesnocancel("An existing folder with imported Minecraft sounds has been found in your Sounds folder. Would you like to replace it?", "Warning")) {
5491
return;
5592
} else {
5693
directory_delete_lib(sounds_mc_subdir);
5794
}
95+
sound_import_status = 1;
5896
}
5997

6098
for (var i = array_length(keys) - 1; i >= 0; --i) {
@@ -75,7 +113,7 @@ function load_asset_index(index_name, copy = false) {
75113

76114
if (copy) {
77115
var src = assets_dir + "objects\\" + string_copy(hash, 1, 2) + "\\" + hash;
78-
var dst = sounds_mc_subdir + string_replace(key, "minecraft/sounds/", "");
116+
var dst = sounds_mc_subdir + string_replace(key, "minecraft/sounds/", "\\");
79117

80118
if (!file_exists_lib(src)) {
81119
continue;
@@ -91,7 +129,10 @@ function load_asset_index(index_name, copy = false) {
91129
//show_debug_message(dst);
92130
}
93131

94-
return count;
132+
if (copy) sound_import_status = 2;
133+
else sound_import_status = 0;
134+
135+
sound_import_asset_index_count = count;
95136
}
96137

97138

0 commit comments

Comments
 (0)