Deltarune (Chapter 4) 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 == 2)
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(arg0);
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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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() { scr_debug_clear_persistent(); }
("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
            if (noteend[_i] > 0)
222
                clip_end[clip_size] = noteend[_i] - _clipstart;
223
            else
224
                clip_end[clip_size] = noteend[_i];
225
            clip_anim[clip_size] = noteanim[_i];
226
            clip_size++;
227
        }
228
    }
229
    if (_notesfound)
230
        debug_print(stringsetsub("copied ~1 notes to clipboard (~2 beats)", string(clip_size), string(round(arg0 / (meter / 4)))));
231
    else
232
        debug_print("nothing to copy.");
233
}
234
235
function scr_rhythmgame_editor_paste()
236
{
237
    if (clip_size == 0)
238
    {
239
        debug_print("Nothing to paste.");
240
    }
241
    else
242
    {
243
        var _pastestart = scr_floor_to_beat(trackpos + (meter * 0.125), bpm, 0.25) - (meter * 0.05);
244
        for (var _i = 0; _i < clip_size; _i++)
245
        {
246
            var _clip_end = clip_end[_i];
247
            if (_clip_end > 0)
248
                _clip_end += _pastestart;
249
            scr_rhythmgame_editor_insert_note(clip_time[_i] + _pastestart, clip_type[_i], _clip_end, false, clip_anim[_i]);
250
        }
251
        debug_print(stringsetsub("Pasted ~1 notes.", string(clip_size)));
252
        scr_rhythmgame_editor_refresh();
253
    }
254
}
255
256
function scr_rhythmgame_editor_refresh()
257
{
258
    with (obj_rhythmgame_editor_note_node)
259
        instance_destroy();
260
    if (paused)
261
        do_refresh = true;
262
}
263
264
function scr_rhythmgame_editor_note_refresh(arg0 = false)
265
{
266
    minnote = 0;
267
    var _starttime = arg0 ? 0 : trackpos;
268
    for (i = 0; i < maxnote; i++)
269
    {
270
        if (_starttime > notetime[i])
271
        {
272
            notealive[i] = false;
273
            minnote = i + 1;
274
        }
275
        else if (notealive[i] == true)
276
        {
277
            exit;
278
        }
279
        else
280
        {
281
            notescore[i] = 0;
282
            notealive[i] = true;
283
        }
284
    }
285
    scroll_init = 1;
286
}
287
288
function scr_rhythmgame_editor_save(arg0 = "music_timing.txt", arg1 = false)
289
{
290
    var _file = file_text_open_write(arg0);
291
    var _div = 0;
292
    for (i = 0; i < maxnote; i++)
293
    {
294
        if (instrument == 0 && song_id == 0 && _div < array_length(timestamp) && notetime[i] > timestamp[_div] && arg1)
295
        {
296
            if (_div == 0)
297
                file_text_write_string(_file, "\t//start of solo");
298
            else
299
                file_text_write_string(_file, "\t}");
300
            file_text_writeln(_file);
301
            if (_div != 3)
302
            {
303
                if (_div == 0)
304
                    file_text_write_string(_file, "\tif (argument0 == " + string(_div) + ")");
305
                else
306
                    file_text_write_string(_file, "\telse if (argument0 == " + string(_div) + ")");
307
                file_text_writeln(_file);
308
                file_text_write_string(_file, "\t{");
309
            }
310
            else
311
            {
312
                file_text_write_string(_file, "\t//start of finale");
313
            }
314
            file_text_writeln(_file);
315
            _div++;
316
        }
317
        var _string;
318
        if (noteend[i] > 0)
319
            _string = string(notetime[i]) + "," + string(notetype[i]) + "," + string(noteend[i]);
320
        else
321
            _string = string(notetime[i]) + "," + string(notetype[i]) + ",0";
322
        if (noteanim[i] > 0)
323
            _string += ("," + string(noteanim[i]));
324
        if (arg1)
325
        {
326
            if (_div == 4)
327
                file_text_write_string(_file, "\tscr_rhythmgame_addnote(" + _string + ");");
328
            else if (song_id == 2)
329
                file_text_write_string(_file, "\t\tscr_rhythmgame_addnote_range(" + _string + ");");
330
            else
331
                file_text_write_string(_file, "\t\tscr_rhythmgame_addnote(" + _string + ");");
332
        }
333
        else
334
        {
335
            file_text_write_string(_file, _string);
336
        }
337
        file_text_writeln(_file);
338
    }
339
    file_text_close(_file);
340
    changesmade = false;
341
}
342
343
function scr_rhythmgame_load(arg0 = "lead")
344
{
345
    scr_rhythmgame_notechart_lead();
346
    if (savecon == -1)
347
        savecon = -2;
348
}
349
350
function scr_rhythmgame_clear_notes(arg0 = true)
351
{
352
    maxnote = 0;
353
    notetime = [];
354
    notetype = [];
355
    noteend = [];
356
    notealive = [];
357
    notescore = [];
358
    noteanim = [];
359
    if (arg0)
360
    {
361
        undo_action = [];
362
        undo_index = [];
363
        undo_time = [];
364
        undo_type = [];
365
        undo_end = [];
366
        undo_anim = [];
367
        undo_queue = 0;
368
        undo_cap = 0;
369
    }
370
}
371
372
function scr_rhythmgame_editor_load(arg0 = "music_timing.txt")
373
{
374
    file = file_text_open_read(arg0);
375
    while (!file_text_eof(file))
376
    {
377
        var line = file_text_read_string(file);
378
        var l_arg = gml_std_string_split(line, ",");
379
        if (array_length(l_arg) >= 4)
380
            
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]));
381
        else if (array_length(l_arg) >= 3)
382
            
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]));
383
        file_text_readln(file);
384
    }
385
    file_text_close(file);
386
    changesmade = false;
387
    if (savecon == -1)
388
        savecon = -2;
389
}
390
391
function scr_rhythmgame_editor_trail_add(arg0, arg1)
392
{
393
    if (rec_count == rec_max)
394
    {
395
        array_delete(rec_time, 0, 1);
396
        array_delete(rec_type, 0, 1);
397
        array_delete(rec_endtime, 0, 1);
398
        rec_count--;
399
    }
400
    rec_time[rec_count] = arg0;
401
    rec_type[rec_count] = arg1;
402
    rec_endtime[rec_count] = 0;
403
    rec_count++;
404
}