Skip to content

Commit

Permalink
Merge branch 'develop' into fps-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 authored May 30, 2024
2 parents 11fee0f + 2380058 commit 4ce79cc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 69 deletions.
24 changes: 22 additions & 2 deletions source/funkin/modding/events/ScriptEvent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,36 @@ class HitNoteScriptEvent extends NoteScriptEvent
*/
public var score:Int;

public function new(note:NoteSprite, healthChange:Float, score:Int, judgement:String, comboCount:Int = 0):Void
/**
* If the hit causes a combo break.
*/
public var isComboBreak:Bool = false;

/**
* The time difference when the player hit the note
*/
public var hitDiff:Float = 0;

/**
* If the hit causes a notesplash
*/
public var doesNotesplash: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
{
super(NOTE_HIT, note, healthChange, comboCount, true);
this.score = score;
this.judgement = judgement;
this.isComboBreak = isComboBreak;
this.doesNotesplash = doesNotesplash;
this.hitDiff = hitDiff;
}

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

Expand Down
112 changes: 46 additions & 66 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,8 @@ class PlayState extends MusicBeatSubState

// Call an event to allow canceling the note hit.
// NOTE: This is what handles the character animations!
var event:NoteScriptEvent = new HitNoteScriptEvent(note, 0.0, 0, 'perfect', 0);

var event:NoteScriptEvent = new HitNoteScriptEvent(note, 0.0, 0, 'perfect', false, 0);
dispatchEvent(event);

// Calling event.cancelEvent() skips all the other logic! Neat!
Expand Down Expand Up @@ -2211,7 +2212,7 @@ class PlayState extends MusicBeatSubState

// Call an event to allow canceling the note hit.
// NOTE: This is what handles the character animations!
var event:NoteScriptEvent = new HitNoteScriptEvent(note, 0.0, 0, 'perfect', 0);
var event:NoteScriptEvent = new HitNoteScriptEvent(note, 0.0, 0, 'perfect', false, 0);
dispatchEvent(event);

// Calling event.cancelEvent() skips all the other logic! Neat!
Expand Down Expand Up @@ -2416,27 +2417,41 @@ class PlayState extends MusicBeatSubState
var daRating = Scoring.judgeNote(noteDiff, PBOT1);

var healthChange = 0.0;
var isComboBreak = false;
switch (daRating)
{
case 'sick':
healthChange = Constants.HEALTH_SICK_BONUS;
isComboBreak = Constants.JUDGEMENT_SICK_COMBO_BREAK;
case 'good':
healthChange = Constants.HEALTH_GOOD_BONUS;
isComboBreak = Constants.JUDGEMENT_GOOD_COMBO_BREAK;
case 'bad':
healthChange = Constants.HEALTH_BAD_BONUS;
isComboBreak = Constants.JUDGEMENT_BAD_COMBO_BREAK;
case 'shit':
isComboBreak = Constants.JUDGEMENT_SHIT_COMBO_BREAK;
healthChange = Constants.HEALTH_SHIT_BONUS;
}

// Send the note hit event.
var event:HitNoteScriptEvent = new HitNoteScriptEvent(note, healthChange, score, daRating, Highscore.tallies.combo + 1);
var event:HitNoteScriptEvent = new HitNoteScriptEvent(note, healthChange, score, daRating, isComboBreak, Highscore.tallies.combo + 1, noteDiff,
daRating == 'sick');
dispatchEvent(event);

// Calling event.cancelEvent() skips all the other logic! Neat!
if (event.eventCanceled) return;

Highscore.tallies.totalNotesHit++;
// Display the hit on the strums
playerStrumline.hitNote(note, !isComboBreak);
if (event.doesNotesplash) playerStrumline.playNoteSplash(note.noteData.getDirection());
if (note.isHoldNote && note.holdNoteSprite != null) playerStrumline.playNoteHoldCover(note.holdNoteSprite);
vocals.playerVolume = 1;

// Display the combo meter and add the calculation to the score.
popUpScore(note, event.score, event.judgement, event.healthChange);
applyScore(event.score, event.judgement, event.healthChange, event.isComboBreak);
popUpScore(event.judgement);
}

/**
Expand All @@ -2447,9 +2462,6 @@ class PlayState extends MusicBeatSubState
{
// If we are here, we already CALLED the onNoteMiss script hook!

health += healthChange;
songScore -= 10;

if (!isPracticeMode)
{
// messy copy paste rn lol
Expand Down Expand Up @@ -2489,14 +2501,9 @@ class PlayState extends MusicBeatSubState
}
vocals.playerVolume = 0;

Highscore.tallies.missed++;
if (Highscore.tallies.combo != 0) if (Highscore.tallies.combo >= 10) comboPopUps.displayCombo(0);

if (Highscore.tallies.combo != 0)
{
// Break the combo.
if (Highscore.tallies.combo >= 10) comboPopUps.displayCombo(0);
Highscore.tallies.combo = 0;
}
applyScore(-10, 'miss', healthChange, true);

if (playSound)
{
Expand Down Expand Up @@ -2584,20 +2591,12 @@ class PlayState extends MusicBeatSubState
// Redirect to the chart editor playing the current song.
if (controls.DEBUG_CHART)
{
if (isChartingMode)
{
if (FlxG.sound.music != null) FlxG.sound.music.pause(); // Don't reset song position!
this.close(); // This only works because PlayState is a substate!
}
else
{
disableKeys = true;
persistentUpdate = false;
FlxG.switchState(() -> new ChartEditorState(
{
targetSongId: currentSong.id,
}));
}
disableKeys = true;
persistentUpdate = false;
FlxG.switchState(() -> new ChartEditorState(
{
targetSongId: currentSong.id,
}));
}
#end

Expand Down Expand Up @@ -2628,46 +2627,24 @@ class PlayState extends MusicBeatSubState
}

/**
* Handles health, score, and rating popups when a note is hit.
* Handles applying health, score, and ratings.
*/
function popUpScore(daNote:NoteSprite, score:Int, daRating:String, healthChange:Float):Void
function applyScore(score:Int, daRating:String, healthChange:Float, isComboBreak:Bool)
{
if (daRating == 'miss')
{
// If daRating is 'miss', that means we made a mistake and should not continue.
FlxG.log.warn('popUpScore judged a note as a miss!');
// TODO: Remove this.
// comboPopUps.displayRating('miss');
return;
}

vocals.playerVolume = 1;

var isComboBreak = false;
switch (daRating)
{
case 'sick':
Highscore.tallies.sick += 1;
Highscore.tallies.totalNotesHit++;
isComboBreak = Constants.JUDGEMENT_SICK_COMBO_BREAK;
case 'good':
Highscore.tallies.good += 1;
Highscore.tallies.totalNotesHit++;
isComboBreak = Constants.JUDGEMENT_GOOD_COMBO_BREAK;
case 'bad':
Highscore.tallies.bad += 1;
Highscore.tallies.totalNotesHit++;
isComboBreak = Constants.JUDGEMENT_BAD_COMBO_BREAK;
case 'shit':
Highscore.tallies.shit += 1;
Highscore.tallies.totalNotesHit++;
isComboBreak = Constants.JUDGEMENT_SHIT_COMBO_BREAK;
default:
FlxG.log.error('Wuh? Buh? Guh? Note hit judgement was $daRating!');
case 'miss':
Highscore.tallies.missed += 1;
}

health += healthChange;

if (isComboBreak)
{
// Break the combo, but don't increment tallies.misses.
Expand All @@ -2679,15 +2656,23 @@ class PlayState extends MusicBeatSubState
Highscore.tallies.combo++;
if (Highscore.tallies.combo > Highscore.tallies.maxCombo) Highscore.tallies.maxCombo = Highscore.tallies.combo;
}
songScore += score;
}

playerStrumline.hitNote(daNote, !isComboBreak);

if (daRating == 'sick')
/**
* Handles rating popups when a note is hit.
*/
function popUpScore(daRating:String, ?combo:Int):Void
{
if (daRating == 'miss')
{
playerStrumline.playNoteSplash(daNote.noteData.getDirection());
// If daRating is 'miss', that means we made a mistake and should not continue.
FlxG.log.warn('popUpScore judged a note as a miss!');
// TODO: Remove this.
// comboPopUps.displayRating('miss');
return;
}

songScore += score;
if (combo == null) combo = Highscore.tallies.combo;

if (!isPracticeMode)
{
Expand Down Expand Up @@ -2727,12 +2712,7 @@ class PlayState extends MusicBeatSubState
}
}
comboPopUps.displayRating(daRating);
if (Highscore.tallies.combo >= 10 || Highscore.tallies.combo == 0) comboPopUps.displayCombo(Highscore.tallies.combo);

if (daNote.isHoldNote && daNote.holdNoteSprite != null)
{
playerStrumline.playNoteHoldCover(daNote.holdNoteSprite);
}
if (combo >= 10 || combo == 0) comboPopUps.displayCombo(combo);

vocals.playerVolume = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/debug/charting/ChartEditorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6304,7 +6304,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
var tempNote:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault());
tempNote.noteData = noteData;
tempNote.scrollFactor.set(0, 0);
var event:NoteScriptEvent = new HitNoteScriptEvent(tempNote, 0.0, 0, 'perfect', 0);
var event:NoteScriptEvent = new HitNoteScriptEvent(tempNote, 0.0, 0, 'perfect', false, 0);
dispatchEvent(event);

// Calling event.cancelEvent() skips all the other logic! Neat!
Expand Down

0 comments on commit 4ce79cc

Please sign in to comment.