Skip to content

Commit 66de236

Browse files
committed
Added version info to nbt format
Fixes #18
1 parent cf8ef59 commit 66de236

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

scripts/control_create/control_create.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ ds_list_add(instrument_list, new_instrument("Banjo", "banjo.ogg", false)
256256
ds_list_add(instrument_list, new_instrument("Pling", "pling.ogg", false))
257257

258258
instrument = instrument_list[| 0]
259+
first_custom_index = ds_list_size(instrument_list)
259260
user_instruments = 0
260261

261262
// Initialize instruments

scripts/load_song/load_song.gml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// load_song(fn)
2-
var fn, file_ext, f, str, stats, tstr, ca, cb, bstr, a, b, c, d, w, hei;
2+
var fn, file_ext, f, str, stats, tstr, ca, cb, bstr, a, b, c, d, w, hei, byte1, byte2, song_first_custom_index, custom_index_diff
33
fn = argument0
44
if (confirm() < 0) return 0
55
if (fn = "") {
@@ -20,8 +20,22 @@ if (file_ext = ".schematic") {
2020
if (file_ext != ".nbs") {message("Error: This file cannot be opened in this program.", "Error") return 0}
2121
if (file_ext = ".nbs") {
2222
buffer = buffer_import(fn)
23-
buffer_read_short()
24-
hei = buffer_read_short()
23+
24+
byte1 = buffer_read_byte()
25+
byte2 = buffer_read_byte()
26+
27+
//First two bytes 0 = new nbt format
28+
if(byte1 = 0 && byte2 = 0){
29+
song_nbt_version = buffer_read_byte()
30+
song_first_custom_index = buffer_read_byte()
31+
custom_index_diff = first_custom_index - song_first_custom_index
32+
}else{
33+
song_nbt_version = 0
34+
custom_index_diff = 0
35+
song_first_custom_index = 0
36+
}
37+
38+
hei = buffer_read_short()
2539

2640
draw_set_font(fnt_main)
2741
// SONG NAME
@@ -70,6 +84,7 @@ if (file_ext = ".nbs") {
7084
if (a = 0) break
7185
cb += a
7286
var ins = buffer_read_byte();
87+
if(ins >= song_first_custom_index)ins += custom_index_diff //If instrument is custom, add custom_index_diff so it works when adding future instruments
7388
var key = buffer_read_byte();
7489
add_block(ca, cb, ins, median(0, key, 87), true)
7590
}
@@ -103,8 +118,8 @@ if (file_ext = ".nbs") {
103118
blocks_set_instruments()
104119
return 0
105120
}
106-
107-
// Custom instruments
121+
122+
// Custom instruments
108123
a = buffer_read_byte()
109124
str = ""
110125
for (b = 0; b < a; b++) {

scripts/macros/macros.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#macro gm_runtime_version "2.1.5.246"
22
#macro version_date "2019.03.21"
33
#macro version "3.3.8"
4+
#macro nbt_version 1
45

56
#macro link_download "https://github.com/HielkeMinecraft/OpenNoteBlockStudio/releases/latest"
67
#macro link_topic "https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-tools/2945101-open-minecraft-note-block-studio"

scripts/save_song/save_song.gml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ if (fn = "" || filename_ext(filename) != ".nbs") {
1010
}
1111
if (selected > 0) selection_place(0)
1212
buffer = buffer_create(8, buffer_grow, 1)
13-
buffer_write_short(enda)
13+
14+
buffer_write_short(0)
15+
buffer_write_byte(nbt_version)
16+
buffer_write_byte(first_custom_index)
17+
1418
buffer_write_short(endb2)
1519

1620
buffer_write_string_int(song_name)

0 commit comments

Comments
 (0)