Deltarune (Chapter 4) script viewer

← back to main script listing

gml_Object_obj_rhythmgame_editor_Step_0

(view raw script w/o annotations or w/e)
1
if (song_menu)
2
{
3
    if (start_buffer)
4
    {
5
        start_buffer = false;
6
        exit;
7
    }
8
    if (up_p())
9
    {
10
        if (selection > 0)
11
            selection--;
12
        snd_play(snd_menumove);
13
    }
14
    if (down_p())
15
    {
16
        if (selection < array_length(tracklist))
17
            selection++;
18
        snd_play(snd_menumove);
19
    }
20
    if (left_p())
21
    {
22
        if (instrument == 0)
23
            instrument = 1;
24
        else if (instrument == 2)
25
            instrument = 0;
26
        snd_play(snd_menumove);
27
    }
28
    if (right_p())
29
    {
30
        if (instrument == 0)
31
            instrument = 2;
32
        else if (instrument == 1)
33
            instrument = 0;
34
        snd_play(snd_menumove);
35
    }
36
    if (button1_p())
37
    {
38
        if (global.chapter == 3)
39
            song_id = selection;
40
        else
41
            scr_rhythmgame_song_select(selection);
42
        load_chart();
43
        song_menu = false;
44
    }
45
    exit;
46
}
47
if (scroll_init > 0)
48
{
49
    if (scroll_init < 5)
50
    {
51
        scroll_init++;
52
    }
53
    else
54
    {
55
        scr_rhythmgame_editor_note_refresh();
56
        do_refresh = true;
57
        scroll_init = 0;
58
    }
59
}
60
if (loadsong == 1)
61
{
62
    track1 = snd_init(track1_id);
63
    track2 = snd_init(track2_id);
64
    loadsong = 2;
65
    playtimer = 0;
66
}
67
if (loadsong == 2)
68
{
69
    playtimer++;
70
    if (playtimer == 4)
71
    {
72
        track1_instance = mus_loop(track1);
73
        track2_instance = mus_loop(track2);
74
    }
75
    if (playtimer == 5)
76
    {
77
        if (trackstart > 0)
78
        {
79
            audio_sound_set_track_position(track1_instance, trackstart);
80
            audio_sound_set_track_position(track2_instance, trackstart);
81
        }
82
        if (oneAtATime)
83
            mus_volume(track1_instance, 0, 0);
84
        if (song_id == 2)
85
            mus_volume(track1_instance, 0.75, 0);
86
        loadsong = 3;
87
        song_initialized = 1;
88
    }
89
}
90
if (song_initialized == 1)
91
{
92
    if (
scr_debug
scr_debug

function
scr_debug()
{ if (global.debug == 1) return 1; }
())
93
    {
94
        if (keyboard_check_pressed(ord("T")))
95
            scroll_init = 1;
96
        if (keyboard_check_pressed(ord("P")) || keyboard_check_pressed(vk_space))
97
            event_user(2);
98
    }
99
    if (!paused || scrollcon < 2)
100
        trackpos = audio_sound_get_track_position(track1_instance);
101
    if (song_id == 4)
102
    {
103
        var _pitch = remap_clamped(4, 7.25, 1, 0.05, trackpos);
104
        audio_sound_pitch(track1_instance, _pitch);
105
        audio_sound_pitch(track2_instance, _pitch);
106
    }
107
    var timeunit = trackpos - remtrackpos[0];
108
    var averagetimeunit = ((trackpos - remtrackpos[0]) + (remtrackpos[0] - remtrackpos[1]) + (remtrackpos[1] - remtrackpos[2])) / 3;
109
    remtrackpos[4] = remtrackpos[3];
110
    remtrackpos[3] = remtrackpos[2];
111
    remtrackpos[2] = remtrackpos[1];
112
    remtrackpos[1] = remtrackpos[0];
113
    remtrackpos[0] = trackpos;
114
    var notecheckmax = -1;
115
    var notecheck = minnote;
116
    var foundnotes = 0;
117
    while (notecheck < maxnote)
118
    {
119
        notecheckmax++;
120
        if (abs(notetime[notecheck] - trackpos) < 0.12)
121
        {
122
            foundnotes = 1;
123
            targetnote[notecheckmax] = notecheck;
124
            notecheck++;
125
        }
126
        else
127
        {
128
            notecheckmax--;
129
            break;
130
        }
131
    }
132
    pressedtimer[0]++;
133
    pressedtimer[1]++;
134
    buffer[0]--;
135
    buffer[1]--;
136
    hold_score = 0;
137
    var _loop_end = (instrument > 0) ? 3 : 2;
138
    for (i = 0; i < _loop_end; i++)
139
    {
140
        var checkpress, holdpress;
141
        if (paused)
142
        {
143
            checkpress = 0;
144
            holdpress = 0;
145
        }
146
        else if (i == 0)
147
        {
148
            checkpress = button1_p();
149
            if (checkpress)
150
            {
151
                kris.sprite_index = spr_kris_guitar;
152
                with (kris)
153
                {
154
                    sprite_index = spr_kris_guitar;
155
                    event_user(0);
156
                }
157
            }
158
            holdpress = button1_h() || auto_play;
159
        }
160
        else if (i == 1)
161
        {
162
            checkpress = button2_p();
163
            if (checkpress)
164
            {
165
                with (kris)
166
                {
167
                    sprite_index = spr_kris_guitar_high;
168
                    event_user(0);
169
                }
170
            }
171
            holdpress = button2_h() || auto_play;
172
        }
173
        else if (i == 2)
174
        {
175
            checkpress = button3_p();
176
            if (checkpress)
177
            {
178
                with (kris)
179
                {
180
                    sprite_index = spr_kris_guitar_high_hold;
181
                    event_user(0);
182
                }
183
            }
184
            holdpress = button3_h() || auto_play;
185
        }
186
        if (recording_mode && checkpress)
187
        {
188
            rec_time[rec_count] = trackpos;
189
            rec_endtime[rec_count] = trackpos;
190
            rec_type[rec_count] = i;
191
            rec_count++;
192
        }
193
        if (hold_end[i] > 0)
194
        {
195
            if (hold_end[i] < trackpos || !holdpress)
196
            {
197
                if (trackpos >= hold_start[i])
198
                {
199
                    var chainPoints = (floor(((min(hold_end[i], trackpos) - hold_start[i]) / meter) * 40) * 10) + 50;
200
                    total_score += chainPoints;
201
                    score_scale = 4;
202
                    combo += chainPoints;
203
                    if (instrument == 2)
204
                    {
205
                        note_hit_timer[0] = 0;
206
                        note_hit_timer[1] = 0;
207
                        note_hit_timer[2] = 0;
208
                        note_hit_timer[i] = 5;
209
                    }
210
                    else
211
                    {
212
                        note_hit_timer[i] = 4;
213
                    }
214
                }
215
                hold_end[i] = 0;
216
            }
217
            else if (trackpos >= hold_start[i])
218
            {
219
                hold_score += floor(((trackpos - hold_start[i]) / meter) * 400);
220
                if (score_scale < 2.5)
221
                    score_scale += 0.4;
222
                if (instrument == 2)
223
                {
224
                    if (note_hit_timer[0] == 1)
225
                        note_hit_timer[0] = 3;
226
                }
227
                else if (note_hit_timer[i] <= 1)
228
                {
229
                    note_hit_timer[i] = 3;
230
                }
231
            }
232
        }
233
        if (checkpress && buffer[i] <= 0)
234
        {
235
            if (instrument == 2)
236
            {
237
                note_hit_timer[0] = 0;
238
                note_hit_timer[1] = 0;
239
                note_hit_timer[2] = 0;
240
                note_hit_timer[i] = 5;
241
            }
242
            else
243
            {
244
                note_hit_timer[i] = 5;
245
            }
246
            pressedtimer[i] = 0;
247
            buffer[i] = 2;
248
        }
249
        if ((pressedtimer[i] < (room_speed / 10) || auto_play) && foundnotes == 1)
250
        {
251
            for (var notei = 0; notei <= notecheckmax; notei++)
252
            {
253
                if (notetype[targetnote[notei]] == i && notealive[targetnote[notei]] == 1)
254
                {
255
                    var leniency = 1.6;
256
                    if (auto_play)
257
                    {
258
                        if (notetime[targetnote[notei]] <= (trackpos + averagetimeunit))
259
                            notescore[targetnote[notei]] = 100;
260
                        else
261
                            break;
262
                    }
263
                    else if (abs(notetime[targetnote[notei]] - trackpos) < (averagetimeunit * leniency))
264
                    {
265
                        notescore[targetnote[notei]] = 100;
266
                    }
267
                    else if (abs(notetime[targetnote[notei]] - trackpos) < (averagetimeunit * leniency * 1.5))
268
                    {
269
                        notescore[targetnote[notei]] = 60;
270
                    }
271
                    else
272
                    {
273
                        notescore[targetnote[notei]] = 40;
274
                    }
275
                    total_score += notescore[targetnote[notei]];
276
                    combo += notescore[targetnote[notei]];
277
                    score_scale = min(4, score_scale + (notescore[targetnote[notei]] / 100));
278
                    if (notescore[targetnote[notei]] > 0)
279
                    {
280
                        if (auto_play)
281
                        {
282
                            if (instrument == 2)
283
                            {
284
                                note_hit_timer[0] = 0;
285
                                note_hit_timer[1] = 0;
286
                                note_hit_timer[2] = 0;
287
                                note_hit_timer[i] = 5;
288
                            }
289
                            else
290
                            {
291
                                note_hit_timer[i] = 5;
292
                            }
293
                        }
294
                        note_streak++;
295
                    }
296
                    if (noteanim[targetnote[notei]] > 0)
297
                    {
298
                        if (instrument == 0)
299
                        {
300
                            if (i == 1)
301
                                kris.sprite_index = spr_kris_guitar_high_hold;
302
                            else
303
                                kris.sprite_index = spr_kris_guitar_high;
304
                        }
305
                    }
306
                    if (notescore[targetnote[notei]] >= 40 && noteend[targetnote[notei]] > 0)
307
                    {
308
                        hold_start[i] = notetime[targetnote[notei]];
309
                        hold_end[i] = noteend[targetnote[notei]];
310
                    }
311
                    notealive[targetnote[notei]] = 0;
312
                    if (notescore[targetnote[notei]] != 100)
313
                        snd_play(snd_swing);
314
                    pressedtimer[i] = (room_speed / 10) + 1;
315
                    if (instrument == 0)
316
                    {
317
                        if (oneAtATime)
318
                            mus_volume(track1_instance, 0, 0);
319
                        mus_volume(track2_instance, 1, 0);
320
                    }
321
                }
322
            }
323
        }
324
    }
325
    if (keyboard_check(vk_lcontrol))
326
    {
327
        if (keyboard_check_pressed(ord("Z")))
328
        {
329
            if (keyboard_check(vk_lshift))
330
                scr_rhythmgame_editor_redo();
331
            else
332
                scr_rhythmgame_editor_undo();
333
        }
334
        else if (keyboard_check_pressed(ord("Y")))
335
        {
336
            scr_rhythmgame_editor_redo();
337
        }
338
        else if (keyboard_check_pressed(ord("C")))
339
        {
340
            scr_rhythmgame_editor_copy(keyboard_check(vk_lshift) ? (meter * 2) : meter);
341
        }
342
        else if (keyboard_check_pressed(ord("V")))
343
        {
344
            scr_rhythmgame_editor_paste();
345
        }
346
    }
347
    if (savecon == 0 && keyboard_check_pressed(ord("U")))
348
    {
349
        if (!paused)
350
            event_user(2);
351
        savecon = 1;
352
    }
353
    else if (savecon == 0 && keyboard_check_pressed(ord("I")))
354
    {
355
        if (!paused)
356
            event_user(2);
357
        savecon = -1;
358
    }
359
    else if (savecon == 1)
360
    {
361
        if (keyboard_check_pressed(ord("Z")))
362
        {
363
            event_user(0);
364
            savecon = 2;
365
            load_source = 1;
366
        }
367
        else if (keyboard_check_pressed(ord("X")))
368
        {
369
            savecon = 0;
370
        }
371
    }
372
    else if (savecon == -1)
373
    {
374
        if (keyboard_check_pressed(ord("Z")) || keyboard_check_pressed(ord("1")))
375
        {
376
            scr_rhythmgame_editor_load(savestring + ".txt");
377
        }
378
        else if (keyboard_check_pressed(ord("2")))
379
        {
380
            scr_rhythmgame_editor_load(savestring + "_autosave.txt");
381
        }
382
        else if (keyboard_check_pressed(ord("3")))
383
        {
384
            scr_rhythmgame_clear_notes();
385
            if (instrument == 0)
386
            {
387
                scr_rhythmgame_notechart_lead(song_id);
388
                if (song_id == 0)
389
                {
390
                    scr_rhythmgame_notechart_lead_solo(0);
391
                    scr_rhythmgame_notechart_lead_solo(1);
392
                    scr_rhythmgame_notechart_lead_solo(2);
393
                    scr_rhythmgame_notechart_lead_finale();
394
                }
395
            }
396
            else if (instrument == 1)
397
            {
398
                scr_rhythmgame_notechart_drums(song_id);
399
            }
400
            else if (instrument == 2)
401
            {
402
                scr_rhythmgame_notechart_vocals(song_id);
403
            }
404
            if (savecon == -1)
405
                savecon = -2;
406
            load_source = 2;
407
        }
408
        else if (keyboard_check_pressed(ord("X")) || keyboard_check_pressed(ord("4")))
409
        {
410
            savecon = 0;
411
        }
412
    }
413
    else if (abs(savecon) == 2)
414
    {
415
        if (keyboard_check_pressed(ord("Z")) || keyboard_check_pressed(ord("X")))
416
            savecon = 0;
417
    }
418
    if (!keyboard_check(vk_lcontrol) && keyboard_check_pressed(ord("V")))
419
    {
420
        rem_pos = trackpos;
421
        rem_mode = true;
422
    }
423
    if (rem_pos >= 0 && keyboard_check_pressed(ord("B")))
424
        rem_mode = !rem_mode;
425
    if (keyboard_check_pressed(ord("Q")))
426
    {
427
        auto_play = !auto_play;
428
        if (auto_play)
429
            
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(); }
("autoplay enabled");
430
        else
431
            
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(); }
("autoplay disabled");
432
    }
433
    if (rem_pos >= 0 && keyboard_check_pressed(ord("N")))
434
        event_user(6);
435
    if (keyboard_check_pressed(ord("W")))
436
    {
437
        if (oneAtATime)
438
            mus_volume(track1_instance, 1, 0);
439
        mus_volume(track2_instance, 0, 0);
440
        debug_print("Guitar muted");
441
    }
442
    if (keyboard_check_pressed(ord("E")))
443
    {
444
        if (oneAtATime)
445
            mus_volume(track1_instance, 0, 0);
446
        mus_volume(track2_instance, 1, 0);
447
        debug_print("Guitar unmuted");
448
    }
449
    if (keyboard_check_pressed(vk_tab))
450
        tooltips = !tooltips;
451
    if (keyboard_check_pressed(189))
452
    {
453
        if (notespeed > 30)
454
            notespeed -= 15;
455
    }
456
    if (keyboard_check_pressed(187))
457
    {
458
        if (notespeed < 300)
459
            notespeed += 15;
460
    }
461
    if (keyboard_check(ord("0")))
462
        notespeed = original_notespeed;
463
    var _playhead_x = (camerax() + 640) - 20;
464
    var _playhead_y = lerp((cameray() + 480) - 20, cameray() + 20, trackpos / track_length);
465
    var _playhead_hover = mouse_x >= (_playhead_x - 10) && mouse_y >= (_playhead_y - 10) && mouse_x <= (_playhead_x + 10) && mouse_y <= (_playhead_y + 10);
466
    if (_playhead_hover && scrollcon < 2)
467
    {
468
        if (mouse_button == mb_none)
469
            scrollcon = 1;
470
        else if (scrollcon == 1 && mouse_button == mb_left)
471
            scrollcon = 2;
472
    }
473
    else if (scrollcon == 1)
474
    {
475
        scrollcon = 0;
476
    }
477
    if (scrollcon == 2)
478
    {
479
        if (!paused)
480
            event_user(2);
481
        trackpos = remap_clamped((cameray() + 480) - 20, cameray() + 20, 0, track_length, mouse_y);
482
        if (mouse_button == mb_none)
483
        {
484
            audio_sound_set_track_position(track1_instance, trackpos);
485
            audio_sound_set_track_position(track2_instance, trackpos);
486
            scrollcon = _playhead_hover ? 1 : 0;
487
            scr_rhythmgame_editor_note_refresh();
488
        }
489
        else if (mouse_button == mb_right)
490
        {
491
            trackpos = audio_sound_get_track_position(track1_instance);
492
            scrollcon = _playhead_hover ? 1 : 0;
493
            scr_rhythmgame_editor_note_refresh();
494
        }
495
    }
496
    if (scrollcon < 2)
497
    {
498
        var _timechange = 0;
499
        if (keyboard_check(vk_up))
500
            _timechange += 0.03125;
501
        if (keyboard_check(vk_down))
502
            _timechange -= 0.03125;
503
        if (_timechange != 0)
504
        {
505
            arrow_scroll = true;
506
            if (keyboard_check(vk_lshift))
507
            {
508
                if (quickscroll_timer > 60)
509
                    _timechange *= 4;
510
                else
511
                    _timechange *= ((quickscroll_timer > 30) ? 3 : 2);
512
                quickscroll_timer++;
513
            }
514
            else if (keyboard_check(vk_lalt))
515
            {
516
                _timechange *= 0.5;
517
            }
518
            trackpos += _timechange;
519
            audio_sound_set_track_position(track1_instance, trackpos);
520
            audio_sound_set_track_position(track2_instance, trackpos);
521
        }
522
        else if (arrow_scroll)
523
        {
524
            arrow_scroll = false;
525
            scroll_init = 1;
526
            quickscroll_timer = 0;
527
        }
528
    }
529
}