Skip to content

Commit 4fd0806

Browse files
KoloInDaCribAbnormalPoof
authored andcommitted
make volume settings optionally carry over to playtest
1 parent 5326c40 commit 4fd0806

File tree

4 files changed

+78
-9
lines changed

4 files changed

+78
-9
lines changed

source/funkin/play/PlayState.hx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,24 @@ class PlayState extends MusicBeatSubState
239239
*/
240240
public var playbackRate:Float = 1.0;
241241

242+
/**
243+
* The volume of the instrumental track.
244+
* @default `1.0` for 100%.
245+
*/
246+
public var instrumentalVolume:Float = 1.0;
247+
248+
/**
249+
* The volume of the player vocals track.
250+
* @default `1.0` for 100%.
251+
*/
252+
public var playerVocalsVolume:Float = 1.0;
253+
254+
/**
255+
* The volume of the opponent vocals track.
256+
* @default `1.0` for 100%.
257+
*/
258+
public var opponentVocalsVolume:Float = 1.0;
259+
242260
/**
243261
* An empty FlxObject contained in the scene.
244262
* The current gameplay camera will always follow this object. Tween its position to move the camera smoothly.
@@ -1028,16 +1046,15 @@ class PlayState extends MusicBeatSubState
10281046
}
10291047
}
10301048

1031-
if (FlxG.sound.music != null) FlxG.sound.music.volume = 1;
1049+
if (FlxG.sound.music != null) FlxG.sound.music.volume = instrumentalVolume;
10321050

10331051
if (vocals != null)
10341052
{
10351053
vocals.pause();
10361054
vocals.time = startTimestamp - Conductor.instance.instrumentalOffset;
10371055

1038-
vocals.volume = 1;
1039-
vocals.playerVolume = 1;
1040-
vocals.opponentVolume = 1;
1056+
vocals.playerVolume = playerVocalsVolume;
1057+
vocals.opponentVolume = opponentVocalsVolume;
10411058
}
10421059

10431060
if (!fromDeathState)
@@ -2512,7 +2529,7 @@ class PlayState extends MusicBeatSubState
25122529
}
25132530

25142531
// Prevent the volume from being wrong.
2515-
FlxG.sound.music.volume = 1.0;
2532+
FlxG.sound.music.volume = instrumentalVolume;
25162533
if (FlxG.sound.music.fadeTween != null) FlxG.sound.music.fadeTween.cancel();
25172534

25182535
if (vocals != null)
@@ -2522,7 +2539,8 @@ class PlayState extends MusicBeatSubState
25222539

25232540
vocals.time = startTimestamp - Conductor.instance.instrumentalOffset;
25242541
vocals.pitch = playbackRate;
2525-
vocals.volume = 1.0;
2542+
vocals.playerVolume = playerVocalsVolume;
2543+
vocals.opponentVolume = opponentVocalsVolume;
25262544

25272545
// trace('STARTING SONG AT:');
25282546
// trace('${FlxG.sound.music.time}');
@@ -2986,7 +3004,7 @@ class PlayState extends MusicBeatSubState
29863004
playerStrumline.hitNote(note, !event.isComboBreak);
29873005
if (event.doesNotesplash) playerStrumline.playNoteSplash(note.noteData.getDirection());
29883006
if (note.isHoldNote && note.holdNoteSprite != null) playerStrumline.playNoteHoldCover(note.holdNoteSprite);
2989-
if (vocals != null) vocals.playerVolume = 1;
3007+
if (vocals != null) vocals.playerVolume = playerVocalsVolume;
29903008

29913009
// Display the combo meter and add the calculation to the score.
29923010
if (note.scoreable)
@@ -3225,7 +3243,7 @@ class PlayState extends MusicBeatSubState
32253243
comboPopUps.displayRating(daRating);
32263244
if (combo >= 10) comboPopUps.displayCombo(combo);
32273245

3228-
if (vocals != null) vocals.playerVolume = 1;
3246+
if (vocals != null) vocals.playerVolume = playerVocalsVolume;
32293247
}
32303248

32313249
/**

source/funkin/save/Save.hx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class Save implements ConsoleClass
189189
chartEditorLiveInputStyle: ChartEditorLiveInputStyle.None,
190190
theme: ChartEditorTheme.Light,
191191
playtestStartTime: false,
192+
playtestAudioSettings: false,
192193
downscroll: false,
193194
showNoteKinds: true,
194195
metronomeVolume: 1.0,
@@ -413,6 +414,23 @@ class Save implements ConsoleClass
413414
return data.optionsChartEditor.playtestStartTime;
414415
}
415416

417+
public var chartEditorPlaytestAudioSettings(get, set):Bool;
418+
419+
function get_chartEditorPlaytestAudioSettings():Bool
420+
{
421+
if (data.optionsChartEditor.playtestAudioSettings == null) data.optionsChartEditor.playtestAudioSettings = false;
422+
423+
return data.optionsChartEditor.playtestAudioSettings;
424+
}
425+
426+
function set_chartEditorPlaytestAudioSettings(value:Bool):Bool
427+
{
428+
// Set and apply.
429+
data.optionsChartEditor.playtestAudioSettings = value;
430+
flush();
431+
return data.optionsChartEditor.playtestAudioSettings;
432+
}
433+
416434
public var chartEditorTheme(get, set):ChartEditorTheme;
417435

418436
function get_chartEditorTheme():ChartEditorTheme
@@ -1933,6 +1951,12 @@ typedef SaveDataChartEditorOptions =
19331951
*/
19341952
var ?playtestStartTime:Bool;
19351953

1954+
/**
1955+
* If true, playtest songs with the current audio settings in the Chart Editor.
1956+
* @default `false`
1957+
*/
1958+
var ?playtestAudioSettings:Bool;
1959+
19361960
/**
19371961
* Theme music in the Chart Editor.
19381962
* @default `true`

source/funkin/ui/debug/charting/ChartEditorState.hx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,11 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
604604
*/
605605
var playtestBotPlayMode:Bool = false;
606606

607+
/**
608+
* If true, playtesting a chart will use the audio settings that were set here.
609+
*/
610+
var playtestAudioSettings:Bool = false;
611+
607612
/**
608613
* Enables or disables the "debugger" popup that appears when you run into a flixel error.
609614
*/
@@ -2486,6 +2491,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
24862491
showNoteKindIndicators = save.chartEditorShowNoteKinds;
24872492
showSubtitles = save.chartEditorShowSubtitles;
24882493
playtestStartTime = save.chartEditorPlaytestStartTime;
2494+
playtestAudioSettings = save.chartEditorPlaytestAudioSettings;
24892495
currentTheme = save.chartEditorTheme;
24902496
metronomeVolume = save.chartEditorMetronomeVolume;
24912497
hitsoundVolumePlayer = save.chartEditorHitsoundVolumePlayer;
@@ -2516,6 +2522,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
25162522
save.chartEditorDownscroll = isViewDownscroll;
25172523
save.chartEditorShowNoteKinds = showNoteKindIndicators;
25182524
save.chartEditorPlaytestStartTime = playtestStartTime;
2525+
save.chartEditorPlaytestAudioSettings = playtestAudioSettings;
25192526
save.chartEditorTheme = currentTheme;
25202527
save.chartEditorMetronomeVolume = metronomeVolume;
25212528
save.chartEditorHitsoundVolumePlayer = hitsoundVolumePlayer;
@@ -6268,7 +6275,16 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
62686275

62696276
Cursor.hide();
62706277

6271-
LoadingState.loadPlayState(targetStateParams, false, true, function(targetState) {
6278+
LoadingState.loadPlayState(targetStateParams, false, true, function(targetState)
6279+
{
6280+
// Apply volume settings.
6281+
if (playtestAudioSettings)
6282+
{
6283+
targetState.instrumentalVolume = (menubarItemVolumeInstrumental.value / 100.0) ?? 1.0;
6284+
targetState.playerVocalsVolume = (menubarItemVolumeVocalsPlayer.value / 100.0) ?? 1.0;
6285+
targetState.opponentVocalsVolume = (menubarItemVolumeVocalsOpponent.value / 100.0) ?? 1.0;
6286+
}
6287+
62726288
targetState.vocals = audioVocalTrackGroup;
62736289
});
62746290
}

source/funkin/ui/debug/charting/handlers/ChartEditorToolboxHandler.hx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,17 @@ class ChartEditorToolboxHandler
291291
state.playtestSongScripts = checkboxSongScripts.selected;
292292
};
293293

294+
var checkboxAudioSettings:Null<CheckBox> = toolbox.findComponent('playtestAudioSettingsCheckbox', CheckBox);
295+
296+
if (checkboxAudioSettings == null)
297+
throw 'ChartEditorToolboxHandler.buildToolboxPlaytestPropertiesLayout() - Could not find playtestAudioSettingsCheckbox component.';
298+
299+
state.playtestAudioSettings = checkboxAudioSettings.selected;
300+
301+
checkboxAudioSettings.onClick = _ -> {
302+
state.playtestAudioSettings = checkboxAudioSettings.selected;
303+
};
304+
294305
return toolbox;
295306
}
296307

0 commit comments

Comments
 (0)