Deltarune (Chapter 3) script viewer

← back to main script listing

gml_GlobalScript_scr_rhythmgame_tools

(view raw script w/o annotations or w/e)
1
function scr_rhythmgame_editor_insert_note(arg0, arg1, arg2 = 0, arg3 = false, arg4 = 0)
2
{
3
    for (i = 0; i <= maxnote; i++)
4
    {
5
        if (i == maxnote || arg0 < notetime[i])
6
        {
7
            if (maxnote == 0)
8
            {
9
                notetime[0] = arg0;
10
                notetype[0] = arg1;
11
                noteend[0] = arg2;
12
                notealive[0] = 1;
13
                notescore[0] = 0;
14
                noteanim[0] = arg4;
15
            }
16
            else
17
            {
18
                array_insert(notetime, i, arg0);
19
                array_insert(notetype, i, arg1);
20
                array_insert(noteend, i, arg2);
21
                array_insert(notealive, i, 1);
22
                array_insert(notescore, i, 0);
23
                array_insert(noteanim, i, arg4);
24
            }
25
            maxnote++;
26
            changesmade = true;
27
            erasecon = true;
28
            if (!arg3)
29
            {
30
                scr_rhythmgame_editor_add_undo(1, i, arg0, arg1, arg2);
31
                scr_rhythmgame_editor_refresh();
32
            }
33
            return i;
34
        }
35
        if (arg0 == notetime[i] && arg1 != notetype[i] && instrument != 1)
36
        {
37
            if (!arg3)
38
            {
39
                scr_rhythmgame_editor_record_undo(i);
40
                scr_rhythmgame_editor_refresh();
41
            }
42
            notetype[i] = arg1;
43
            changesmade = true;
44
            return i;
45
        }
46
    }
47
}
48
49
function scr_rhythmgame_editor_delete_note(arg0, arg1 = false)
50
{
51
    if (!arg1)
52
        scr_rhythmgame_editor_add_undo(-1, arg0, notetime[arg0], notetype[arg0], noteend[arg0], noteanim[arg0]);
53
    array_delete(notetime, arg0, 1);
54
    array_delete(notetype, arg0, 1);
55
    array_delete(noteend, arg0, 1);
56
    array_delete(notescore, arg0, 1);
57
    array_delete(notealive, arg0, 1);
58
    array_delete(noteanim, arg0, 1);
59
    maxnote--;
60
    changesmade = true;
61
    if (!arg1)
62
        scr_rhythmgame_editor_refresh();
63
}
64
65
function scr_rhythmgame_editor_note_anim(arg0, arg1 = false)
66
{
67
    if (!arg1)
68
    {
69
        scr_rhythmgame_editor_record_undo(i);
70
        scr_rhythmgame_editor_refresh();
71
    }
72
    noteanim[arg0] = 1 - noteanim[arg0];
73
    changesmade = true;
74
}
75
76
function scr_rhythmgame_editor_move_note(arg0, arg1, arg2, arg3 = 0, arg4 = false)
77
{
78
    if (!arg4)
79
        scr_rhythmgame_editor_add_undo(-2, arg0, notetime[arg0], notetype[arg0], noteend[arg0], noteanim[arg0]);
80
    var _anim = noteanim[arg0];
81
    scr_rhythmgame_editor_delete_note(arg0, true);
82
    var __newIndex = scr_rhythmgame_editor_insert_note(arg1, arg2, arg3, true, _anim);
83
    if (!arg4)
84
    {
85
        scr_rhythmgame_editor_add_undo(2, __newIndex, arg1, arg2, arg3);
86
        scr_rhythmgame_editor_refresh();
87
    }
88
}
89
90
function scr_rhythmgame_editor_record_undo(arg0)
91
{
92
    scr_rhythmgame_editor_add_undo(0, arg0, notetime[arg0], notetype[arg0], noteend[arg0], noteanim[arg0]);
93
}
94
95
function scr_rhythmgame_editor_add_undo(arg0, arg1, arg2, arg3, arg4 = 0, arg5 = 0)
96
{
97
    undo_action[undo_queue] = arg0;
98
    undo_index[undo_queue] = arg1;
99
    undo_time[undo_queue] = arg2;
100
    undo_type[undo_queue] = arg3;
101
    undo_end[undo_queue] = arg4;
102
    undo_anim[undo_queue] = arg5;
103
    undo_queue++;
104
    undo_cap = undo_queue;
105
}
106
107
function scr_rhythmgame_editor_undo()
108
{
109
    if (undo_queue == 0)
110
    {
111
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("No actions left to undo.");
112
        exit;
113
    }
114
    undo_queue--;
115
    var _action = undo_action[undo_queue];
116
    if (_action == -1)
117
    {
118
        scr_rhythmgame_editor_insert_note(undo_time[undo_queue], undo_type[undo_queue], undo_end[undo_queue], true, undo_anim[undo_queue]);
119
    }
120
    else if (_action == 1)
121
    {
122
        scr_rhythmgame_editor_delete_note(undo_index[undo_queue], true);
123
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Undid adding note.");
124
    }
125
    else if (_action == 2)
126
    {
127
        scr_rhythmgame_editor_move_note(undo_index[undo_queue], undo_time[undo_queue - 1], undo_type[undo_queue - 1], undo_end[undo_queue - 1], true, undo_anim[undo_queue - 1]);
128
        undo_queue--;
129
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Undid moving note.");
130
    }
131
    else if (_action == -2)
132
    {
133
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Undo started from the wrong end of a move action. Let Taxi know!");
134
    }
135
    else
136
    {
137
        scr_rhythmgame_editor_undo_swap();
138
    }
139
    scr_rhythmgame_editor_refresh();
140
}
141
142
function scr_rhythmgame_editor_undo_swap()
143
{
144
    var _index = undo_index[undo_queue];
145
    var _remtype = notetype[_index];
146
    var _remend = noteend[_index];
147
    var _remtime = notetime[_index];
148
    var _remanim = noteanim[_index];
149
    notetype[_index] = undo_type[undo_queue];
150
    noteend[_index] = undo_end[undo_queue];
151
    notetime[_index] = undo_time[undo_queue];
152
    noteanim[_index] = undo_anim[undo_queue];
153
    undo_type[undo_queue] = _remtype;
154
    undo_end[undo_queue] = _remend;
155
    undo_time[undo_queue] = _remtime;
156
    undo_anim[undo_queue] = _remanim;
157
    scr_rhythmgame_editor_refresh();
158
}
159
160
function scr_rhythmgame_editor_redo()
161
{
162
    if (undo_queue == undo_cap)
163
    {
164
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("No actions left to redo.");
165
        exit;
166
    }
167
    var _action = undo_action[undo_queue];
168
    if (_action == 1)
169
    {
170
        scr_rhythmgame_editor_insert_note(undo_time[undo_queue], undo_type[undo_queue], undo_end[undo_queue], true, undo_anim[undo_queue]);
171
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Redid adding note.");
172
    }
173
    else if (_action == -1)
174
    {
175
        scr_rhythmgame_editor_delete_note(undo_index[undo_queue], true);
176
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Redid erasing note.");
177
    }
178
    else if (_action == -2)
179
    {
180
        scr_rhythmgame_editor_move_note(undo_index[undo_queue], undo_time[undo_queue + 1], undo_type[undo_queue + 1], undo_end[undo_queue + 1], true, undo_anim[undo_queue]);
181
        undo_queue++;
182
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Redid moving note.");
183
    }
184
    else if (_action == 2)
185
    {
186
        
scr_debug_print
scr_debug_print

function
scr_debug_print(arg0)
{ } function print_message(arg0) { } function debug_print(arg0) { } function scr_debug_clear_all() { }
("Redo started from wrong end a move action. Let Taxi know!");
187
    }
188
    else
189
    {
190
        scr_rhythmgame_editor_undo_swap();
191
    }
192
    scr_rhythmgame_editor_refresh();
193
    undo_queue++;
194
}
195
196
function scr_rhythmgame_editor_copy(arg0 = -1)
197
{
198
    var _clipstart = scr_floor_to_beat(trackpos + (meter * 0.125), bpm, 0.25) - (meter * 0.05);
199
    if (arg0 <= 0)
200
        arg0 = meter;
201
    var _clipend = _clipstart + arg0;
202
    var _notesfound = false;
203
    for (var _i = 0; _i < maxnote; _i++)
204
    {
205
        var _notetime = notetime[_i];
206
        if (_notetime >= _clipend)
207
            break;
208
        if (notetime[_i] >= _clipstart)
209
        {
210
            if (!_notesfound)
211
            {
212
                _notesfound = true;
213
                clip_size = 0;
214
                clip_time = [];
215
                clip_end = [];
216
                clip_type = [];
217
                clip_anim = [];
218
            }
219
            clip_time[clip_size] = _notetime - _clipstart;
220
            clip_type[clip_size] = notetype[_i];
221
            clip_end[clip_size] = noteend[_i];
222
            clip_anim[clip_size] = noteanim[_i];
223
            clip_size++;
224
        }
225
    }
226
    if (_notesfound)
227
        debug_print(stringsetsub("copied ~1 notes to clipboard (~2 beats)", string(clip_size), string(round(arg0 / (meter / 4)))));
228
    else
229
        debug_print("nothing to copy.");
230
}
231
232
function scr_rhythmgame_editor_paste()
233
{
234
    if (clip_size == 0)
235
    {
236
        debug_print("Nothing to paste.");
237
    }
238
    else
239
    {
240
        var _pastestart = scr_floor_to_beat(trackpos + (meter * 0.125), bpm, 0.25) - (meter * 0.05);
241
        for (var _i = 0; _i < clip_size; _i++)
242
            scr_rhythmgame_editor_insert_note(clip_time[_i] + _pastestart, clip_type[_i], clip_end[_i], false, clip_anim[_i]);
243
        debug_print(stringsetsub("Pasted ~1 notes.", string(clip_size)));
244
        scr_rhythmgame_editor_refresh();
245
    }
246
}
247
248
function scr_rhythmgame_editor_refresh()
249
{
250
    with (obj_rhythmgame_editor_note_node)
251
        instance_destroy();
252
    if (paused)
253
        do_refresh = true;
254
}
255
256
function scr_rhythmgame_editor_note_refresh(arg0 = false)
257
{
258
    minnote = 0;
259
    var _starttime = arg0 ? 0 : trackpos;
260
    for (i = 0; i < maxnote; i++)
261
    {
262
        if (_starttime > notetime[i])
263
        {
264
            notealive[i] = false;
265
            minnote = i + 1;
266
        }
267
        else if (notealive[i] == true)
268
        {
269
            exit;
270
        }
271
        else
272
        {
273
            notescore[i] = 0;
274
            notealive[i] = true;
275
        }
276
    }
277
    scroll_init = 1;
278
}
279
280
function scr_rhythmgame_editor_save(arg0 = "music_timing.txt", arg1 = false)
281
{
282
    var _file = file_text_open_write(arg0);
283
    var _div = 0;
284
    for (i = 0; i < maxnote; i++)
285
    {
286
        if (instrument == 0 && song_id == 0 && _div < array_length(timestamp) && notetime[i] > timestamp[_div] && arg1)
287
        {
288
            if (_div == 0)
289
                file_text_write_string(_file, "\t//start of solo");
290
            else
291
                file_text_write_string(_file, "\t}");
292
            file_text_writeln(_file);
293
            if (_div != 3)
294
            {
295
                if (_div == 0)
296
                    file_text_write_string(_file, "\tif (argument0 == " + string(_div) + ")");
297
                else
298
                    file_text_write_string(_file, "\telse if (argument0 == " + string(_div) + ")");
299
                file_text_writeln(_file);
300
                file_text_write_string(_file, "\t{");
301
            }
302
            else
303
            {
304
                file_text_write_string(_file, "\t//start of finale");
305
            }
306
            file_text_writeln(_file);
307
            _div++;
308
        }
309
        var _string;
310
        if (noteend[i] > 0)
311
            _string = string(notetime[i]) + "," + string(notetype[i]) + "," + string(noteend[i]);
312
        else
313
            _string = string(notetime[i]) + "," + string(notetype[i]) + ",0";
314
        if (noteanim[i] > 0)
315
            _string += ("," + string(noteanim[i]));
316
        if (arg1)
317
        {
318
            if (_div == 4)
319
                file_text_write_string(_file, "\tscr_rhythmgame_addnote(" + _string + ");");
320
            else if (song_id == 2)
321
                file_text_write_string(_file, "\t\tscr_rhythmgame_addnote_range(" + _string + ");");
322
            else
323
                file_text_write_string(_file, "\t\tscr_rhythmgame_addnote(" + _string + ");");
324
        }
325
        else
326
        {
327
            file_text_write_string(_file, _string);
328
        }
329
        file_text_writeln(_file);
330
    }
331
    file_text_close(_file);
332
    changesmade = false;
333
}
334
335
function scr_rhythmgame_load(arg0 = "lead")
336
{
337
    scr_rhythmgame_notechart_lead();
338
    if (savecon == -1)
339
        savecon = -2;
340
}
341
342
function scr_rhythmgame_clear_notes(arg0 = true)
343
{
344
    maxnote = 0;
345
    notetime = [];
346
    notetype = [];
347
    noteend = [];
348
    notealive = [];
349
    notescore = [];
350
    noteanim = [];
351
    if (arg0)
352
    {
353
        undo_action = [];
354
        undo_index = [];
355
        undo_time = [];
356
        undo_type = [];
357
        undo_end = [];
358
        undo_anim = [];
359
        undo_queue = 0;
360
        undo_cap = 0;
361
    }
362
}
363
364
function scr_rhythmgame_editor_load(arg0 = "music_timing.txt")
365
{
366
    file = file_text_open_read(arg0);
367
    while (!file_text_eof(file))
368
    {
369
        var line = file_text_read_string(file);
370
        var l_arg = gml_std_string_split(line, ",");
371
        if (array_length(l_arg) >= 4)
372
            
scr_rhythmgame_addnote
scr_rhythmgame_addnote

function
scr_rhythmgame_addnote(arg0, arg1, arg2 = 0, arg3 = 0, arg4 = false)
{ notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg2; noteanim[maxnote] = arg3; notealive[maxnote] = 1; notescore[maxnote] = 0; maxnote++; } function scr_rhythmgame_addnote_range(arg0, arg1, arg2 = 0, arg3 = 0, arg4 = false) { if (chart_end == 0 || (arg0 < (chart_end - track_length) && arg0 >= (chart_start - track_length))) {
scr_rhythmgame_addnote(arg0, arg1, arg2, arg3, arg4);
if (chart_end > 0) { notealive[maxnote - 1] = 0; notescore[maxnote - 1] = 40; } exit; } else if ((arg0 < chart_start || arg0 > chart_end) && chart_end > 0) { exit; } else {
scr_rhythmgame_addnote(arg0, arg1, arg2, arg3, arg4);
} } function scr_rhythmgame_addnote_bpm(arg0, arg1, arg2 = 0) { arg0 *= meter; arg0 -= startoffset; if (arg2 != 0) { arg2 *= meter; arg0 -= startoffset; } notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg2; noteanim[maxnote] = 0; notealive[maxnote] = 1; notescore[maxnote] = 0; maxnote++; } function scr_rhythmgame_addnote_snap(arg0, arg1, arg2 = 0, arg3 = 16) { arg0 = (arg0 / meter) * arg3; arg0 = (round(arg0) / arg3) * meter; if (arg2 != 0) { arg2 = (arg0 / meter) * arg3; arg2 = (round(arg0) / arg3) * meter; } notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg3; notealive[maxnote] = 1; notescore[maxnote] = 0; noteanim[maxnote] = 0; maxnote++; }
(real(l_arg[0]), real(l_arg[1]), real(l_arg[2]), real(l_arg[3]));
373
        else if (array_length(l_arg) >= 3)
374
            
scr_rhythmgame_addnote
scr_rhythmgame_addnote

function
scr_rhythmgame_addnote(arg0, arg1, arg2 = 0, arg3 = 0, arg4 = false)
{ notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg2; noteanim[maxnote] = arg3; notealive[maxnote] = 1; notescore[maxnote] = 0; maxnote++; } function scr_rhythmgame_addnote_range(arg0, arg1, arg2 = 0, arg3 = 0, arg4 = false) { if (chart_end == 0 || (arg0 < (chart_end - track_length) && arg0 >= (chart_start - track_length))) {
scr_rhythmgame_addnote(arg0, arg1, arg2, arg3, arg4);
if (chart_end > 0) { notealive[maxnote - 1] = 0; notescore[maxnote - 1] = 40; } exit; } else if ((arg0 < chart_start || arg0 > chart_end) && chart_end > 0) { exit; } else {
scr_rhythmgame_addnote(arg0, arg1, arg2, arg3, arg4);
} } function scr_rhythmgame_addnote_bpm(arg0, arg1, arg2 = 0) { arg0 *= meter; arg0 -= startoffset; if (arg2 != 0) { arg2 *= meter; arg0 -= startoffset; } notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg2; noteanim[maxnote] = 0; notealive[maxnote] = 1; notescore[maxnote] = 0; maxnote++; } function scr_rhythmgame_addnote_snap(arg0, arg1, arg2 = 0, arg3 = 16) { arg0 = (arg0 / meter) * arg3; arg0 = (round(arg0) / arg3) * meter; if (arg2 != 0) { arg2 = (arg0 / meter) * arg3; arg2 = (round(arg0) / arg3) * meter; } notetime[maxnote] = arg0; notetype[maxnote] = arg1; noteend[maxnote] = arg3; notealive[maxnote] = 1; notescore[maxnote] = 0; noteanim[maxnote] = 0; maxnote++; }
(real(l_arg[0]), real(l_arg[1]), real(l_arg[2]));
375
        file_text_readln(file);
376
    }
377
    file_text_close(file);
378
    changesmade = false;
379
    if (savecon == -1)
380
        savecon = -2;
381
}
382
383
function scr_rhythmgame_editor_trail_add(arg0, arg1)
384
{
385
    if (rec_count == rec_max)
386
    {
387
        array_delete(rec_time, 0, 1);
388
        array_delete(rec_type, 0, 1);
389
        array_delete(rec_endtime, 0, 1);
390
        rec_count--;
391
    }
392
    rec_time[rec_count] = arg0;
393
    rec_type[rec_count] = arg1;
394
    rec_endtime[rec_count] = 0;
395
    rec_count++;
396
}