Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New settings widgets and customizable note effects #2793

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,63 @@ import funkin.save.Save;
*/
class Preferences
{
/**
* The sound that plays when a note is hit
* @default `"none"`
*/
public static var noteHitSound(get, set):String;

static function get_noteHitSound():String
{
return Save?.instance?.options?.noteHitSound;
}

static function set_noteHitSound(value:String):String
{
var save:Save = Save.instance;
save.options.noteHitSound = value;
save.flush();
return value;
}

/**
* The volume of the click sound that can play when a note is hit
* @default `100`
*/
public static var noteHitSoundVolume(get, set):Int;

static function get_noteHitSoundVolume():Int
{
return Save?.instance?.options?.noteHitSoundVolume;
}

static function set_noteHitSoundVolume(value:Int):Int
{
var save:Save = Save.instance;
save.options.noteHitSoundVolume = value;
save.flush();
return value;
}

/**
* Whenever to display a splash animation when perfectly hitting a note
* @default `true`
*/
public static var noteSplash(get, set):Bool;

static function get_noteSplash():Bool
{
return Save?.instance?.options?.noteSplash;
}

static function set_noteSplash(value:Bool):Bool
{
var save:Save = Save.instance;
save.options.noteSplash = value;
save.flush();
return value;
}

/**
* Whether some particularly fowl language is displayed.
* @default `true`
Expand Down
10 changes: 5 additions & 5 deletions source/funkin/modding/events/ScriptEvent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,25 @@ class HitNoteScriptEvent extends NoteScriptEvent
public var hitDiff:Float = 0;

/**
* If the hit causes a notesplash
* If the hit causes a notesplash, or a note hit sound
*/
public var doesNotesplash:Bool = false;
public var doesNoteHitEffects:Bool = false;

public function new(note:NoteSprite, healthChange:Float, score:Int, judgement:String, isComboBreak:Bool, comboCount:Int = 0, hitDiff:Float = 0,
doesNotesplash:Bool = false):Void
doesNoteHitEffects:Bool = false):Void
{
super(NOTE_HIT, note, healthChange, comboCount, true);
this.score = score;
this.judgement = judgement;
this.isComboBreak = isComboBreak;
this.doesNotesplash = doesNotesplash;
this.doesNoteHitEffects = doesNoteHitEffects;
this.hitDiff = hitDiff;
}

public override function toString():String
{
return 'HitNoteScriptEvent(note=' + note + ', comboCount=' + comboCount + ', judgement=' + judgement + ', score=' + score + ', isComboBreak='
+ isComboBreak + ', hitDiff=' + hitDiff + ', doesNotesplash=' + doesNotesplash + ')';
+ isComboBreak + ', hitDiff=' + hitDiff + ', doesNoteHitEffects=' + doesNoteHitEffects + ')';
}
}

Expand Down
9 changes: 7 additions & 2 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import lime.ui.Haptic;
import openfl.display.BitmapData;
import openfl.geom.Rectangle;
import openfl.Lib;
import funkin.ui.options.items.PercentagePreferenceItem;
#if discord_rpc
import Discord.DiscordClient;
#end
Expand Down Expand Up @@ -2422,7 +2423,6 @@ class PlayState extends MusicBeatSubState

// Play the strumline animation.
playerStrumline.playStatic(input.noteDirection);

playerStrumline.releaseKey(input.noteDirection);
}
}
Expand Down Expand Up @@ -2471,7 +2471,12 @@ class PlayState extends MusicBeatSubState
Highscore.tallies.totalNotesHit++;
// Display the hit on the strums
playerStrumline.hitNote(note, !isComboBreak);
if (event.doesNotesplash) playerStrumline.playNoteSplash(note.noteData.getDirection());
if (event.doesNoteHitEffects)
{
// they only play if enabled in settings
playerStrumline.playNoteSplash(note.noteData.getDirection());
playerStrumline.playNoteHitSound();
}
if (note.isHoldNote && note.holdNoteSprite != null) playerStrumline.playNoteHoldCover(note.holdNoteSprite);
vocals.playerVolume = 1;

Expand Down
17 changes: 13 additions & 4 deletions source/funkin/play/notes/Strumline.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import funkin.data.song.SongData.SongNoteData;
import funkin.ui.options.PreferencesMenu;
import funkin.util.SortUtil;
import funkin.modding.events.ScriptEvent;
import funkin.audio.FunkinSound;
import funkin.ui.options.MenuItemEnums;

/**
* A group of sprites which handles the receptor, the note splashes, and the notes (with sustains) for a given player.
Expand Down Expand Up @@ -653,10 +655,18 @@ class Strumline extends FlxSpriteGroup
return getByDirection(direction).isConfirm();
}

public function playNoteHitSound():Void
{
if (Preferences.noteHitSoundVolume <= 0 || Preferences.noteHitSound == NoteHitSoundType.None) return;

var hitSound:String = Preferences.noteHitSound + "Hit";
var path:String = Paths.sound('noteHitSounds/${hitSound}') ?? Paths.sound('noteHitSounds/pingPong');
FunkinSound.playOnce(path, Preferences.noteHitSoundVolume / 100);
}

public function playNoteSplash(direction:NoteDirection):Void
{
// TODO: Add a setting to disable note splashes.
// if (Settings.noSplash) return;
if (!Preferences.noteSplash) return;
if (!noteStyle.isNoteSplashEnabled()) return;

var splash:NoteSplash = this.constructNoteSplash();
Expand All @@ -676,8 +686,7 @@ class Strumline extends FlxSpriteGroup

public function playNoteHoldCover(holdNote:SustainTrail):Void
{
// TODO: Add a setting to disable note splashes.
// if (Settings.noSplash) return;
if (!Preferences.noteSplash) return;
if (!noteStyle.isHoldNoteCoverEnabled()) return;

var cover:NoteHoldCover = this.constructNoteHoldCover();
Expand Down
21 changes: 21 additions & 0 deletions source/funkin/save/Save.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import funkin.save.migrator.SaveDataMigrator;
import funkin.ui.debug.charting.ChartEditorState.ChartEditorLiveInputStyle;
import funkin.ui.debug.charting.ChartEditorState.ChartEditorTheme;
import funkin.util.SerializerUtil;
import funkin.ui.options.MenuItemEnums;
import thx.semver.Version;
import thx.semver.Version;

Expand Down Expand Up @@ -89,6 +90,9 @@ class Save
options:
{
// Reasonable defaults.
noteHitSound: NoteHitSoundType.None,
noteHitSoundVolume: 100,
noteSplash: true,
naughtyness: true,
downscroll: false,
flashingLights: true,
Expand Down Expand Up @@ -1055,6 +1059,23 @@ typedef SaveScoreTallyData =
*/
typedef SaveDataOptions =
{
/**
* The sound to play when a note is hit
*/
var noteHitSound:String;

/**
* The volume of the sound that can play when a note is hit
* @default `100`
*/
var noteHitSoundVolume:Int;

/**
* Whenever to display a splash animation when perfectly hitting a note
* @default `true`
*/
var noteSplash:Bool;

/**
* Whether some particularly fowl language is displayed.
* @default `true`
Expand Down
26 changes: 26 additions & 0 deletions source/funkin/ui/AtlasText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,32 @@ class AtlasText extends FlxTypedSpriteGroup<AtlasChar>
}
}

public function getWidth():Int
{
var width = 0;
for (char in this.text.split(""))
{
switch (char)
{
case " ":
{
width += 40;
}
case "\n":
{}
case char:
{
var sprite = new AtlasChar(atlas, char);
sprite.revive();
sprite.char = char;
sprite.alpha = 1;
width += Std.int(sprite.width);
}
}
}
return width;
}

override function toString()
{
return "InputItem, " + FlxStringUtil.getDebugString([
Expand Down
8 changes: 8 additions & 0 deletions source/funkin/ui/options/MenuItemEnums.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package funkin.ui.options;

class NoteHitSoundType
{
public static inline var None = "none";
public static inline var PingPong = "pingPong";
public static inline var VineBoom = "vineBoom";
}
Loading