Make Note Vibrations stacked amplitude work as intended
This commit is contained in:
@@ -532,6 +532,10 @@ class PlayState extends MusicBeatSubState
|
||||
var pauseButton:FunkinSprite;
|
||||
#end
|
||||
|
||||
#if HAPTIC_VIBRATIONS
|
||||
var noteVibrations:NoteVibrationsHandler = new NoteVibrationsHandler();
|
||||
#end
|
||||
|
||||
/**
|
||||
* PROPERTIES
|
||||
*/
|
||||
@@ -2646,6 +2650,11 @@ class PlayState extends MusicBeatSubState
|
||||
|
||||
// Play the strumline animation.
|
||||
playerStrumline.playConfirm(input.noteDirection);
|
||||
|
||||
#if HAPTIC_VIBRATIONS
|
||||
// Set current note's status to isJustPressed.
|
||||
noteVibrations.noteStatuses[input.noteDirection] = NoteStatus.isJustPressed;
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2657,7 +2666,17 @@ class PlayState extends MusicBeatSubState
|
||||
playerStrumline.playStatic(input.noteDirection);
|
||||
|
||||
playerStrumline.releaseKey(input.noteDirection);
|
||||
|
||||
#if HAPTIC_VIBRATIONS
|
||||
// Set current note's status to isReleased.
|
||||
noteVibrations.noteStatuses[input.noteDirection] = NoteStatus.isReleased;
|
||||
#end
|
||||
}
|
||||
|
||||
#if HAPTIC_VIBRATIONS
|
||||
// Try to vibrate. Works if atleast one note status is NoteStatus.isJustPressed.
|
||||
noteVibrations.tryNoteVibration();
|
||||
#end
|
||||
}
|
||||
|
||||
function goodNoteHit(note:NoteSprite, input:PreciseInputEvent):Void
|
||||
@@ -2711,15 +2730,6 @@ class PlayState extends MusicBeatSubState
|
||||
// Display the combo meter and add the calculation to the score.
|
||||
applyScore(event.score, event.judgement, event.healthChange, event.isComboBreak);
|
||||
popUpScore(event.judgement);
|
||||
|
||||
// Processes note vibrations.
|
||||
#if HAPTIC_VIBRATIONS
|
||||
// Handle note statuses. Mostly needed for stacked amplitude.
|
||||
NoteVibrationsHandler.noteStatuses[input.noteDirection] = NoteStatus.isJustPressed;
|
||||
|
||||
// Try to vibrate. Works if atleast one note status is NoteStatus.isJustPressed.
|
||||
NoteVibrationsHandler.tryNoteVibration();
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,49 +10,56 @@ class NoteVibrationsHandler
|
||||
/**
|
||||
* Left note's status.
|
||||
*/
|
||||
static var leftNoteStatus:NoteStatus = NoteStatus.isReleased;
|
||||
var leftNoteStatus:NoteStatus;
|
||||
|
||||
/**
|
||||
* Down note's status.
|
||||
*/
|
||||
static var downNoteStatus:NoteStatus = NoteStatus.isReleased;
|
||||
var downNoteStatus:NoteStatus;
|
||||
|
||||
/**
|
||||
* Up note's status.
|
||||
*/
|
||||
static var upNoteStatus:NoteStatus = NoteStatus.isReleased;
|
||||
var upNoteStatus:NoteStatus;
|
||||
|
||||
/**
|
||||
* Right note's status.
|
||||
*/
|
||||
static var rightNoteStatus:NoteStatus = NoteStatus.isReleased;
|
||||
var rightNoteStatus:NoteStatus;
|
||||
|
||||
/**
|
||||
* An array of each note status.
|
||||
* Made for use in other classes.
|
||||
*/
|
||||
public static final noteStatuses:Array<NoteStatus> = [leftNoteStatus, downNoteStatus, upNoteStatus, rightNoteStatus];
|
||||
public var noteStatuses:Array<NoteStatus>;
|
||||
|
||||
/**
|
||||
* Note vibration's default amplitude.
|
||||
*/
|
||||
static final defaultNoteAmplitude:Int = Math.ceil(Constants.MAX_VIBRATION_AMPLITUDE / 2);
|
||||
final defaultNoteAmplitude:Int = Math.ceil(Constants.MAX_VIBRATION_AMPLITUDE / 2);
|
||||
|
||||
/**
|
||||
* An amplitude that is being decreased depending on how much notes are pressed right now.
|
||||
* Creates a new NoteVibrationsHandler instance.
|
||||
*/
|
||||
static var stackingAmplitude:Int = defaultNoteAmplitude;
|
||||
public function new()
|
||||
{
|
||||
noteStatuses = [leftNoteStatus, downNoteStatus, upNoteStatus, rightNoteStatus];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any note status is equal to NoteStatus.isJustPressed.
|
||||
* If yes, then vibration is being triggered, amplitude value is stacked depending on how much notes are pressed.
|
||||
*/
|
||||
public static function tryNoteVibration():Void
|
||||
public function tryNoteVibration():Void
|
||||
{
|
||||
var stackingAmplitude:Int = defaultNoteAmplitude;
|
||||
|
||||
for (currentNoteStatus in noteStatuses)
|
||||
{
|
||||
if (currentNoteStatus != NoteStatus.isJustPressed) continue;
|
||||
|
||||
trace("Note Status is Just Pressed!");
|
||||
|
||||
stackingAmplitude += Math.ceil(Constants.MAX_VIBRATION_AMPLITUDE / 8);
|
||||
|
||||
if (stackingAmplitude > 255) stackingAmplitude = 255;
|
||||
@@ -61,27 +68,13 @@ class NoteVibrationsHandler
|
||||
trace("amplitude: " + stackingAmplitude);
|
||||
|
||||
if (stackingAmplitude > defaultNoteAmplitude) HapticUtil.vibrate(0, 10, stackingAmplitude);
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset everything.
|
||||
*/
|
||||
public static function reset():Void
|
||||
{
|
||||
for (currentNoteStatus in noteStatuses)
|
||||
{
|
||||
currentNoteStatus = NoteStatus.isReleased;
|
||||
}
|
||||
stackingAmplitude = defaultNoteAmplitude;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An abstract that represents the note status for NoteVibrationsHandler.
|
||||
*/
|
||||
enum abstract NoteStatus(Int)
|
||||
enum abstract NoteStatus(Int) from Int to Int
|
||||
{
|
||||
var isReleased = 0;
|
||||
var isJustPressed = 1;
|
||||
|
||||
Reference in New Issue
Block a user