1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-12 08:25:13 +00:00

Merge pull request #367 from FunkinCrew/feature/script-event-note-incoming

Implement onNoteIncoming script event.
This commit is contained in:
Cameron Taylor 2024-03-06 00:04:21 -05:00 committed by GitHub
commit c98870e923
13 changed files with 75 additions and 24 deletions

2
assets

@ -1 +1 @@
Subproject commit 51b02f0d47e5b34bf8589065c092953c10c5040d
Subproject commit 095e91fb33dad70a5b51e37542e335cedd025d09

View file

@ -56,7 +56,20 @@ interface IStateStageProp extends IScriptedClass
*/
interface INoteScriptedClass extends IScriptedClass
{
public function onNoteHit(event:NoteScriptEvent):Void;
/**
* Called when a note enters the field of view and approaches the strumline.
*/
public function onNoteIncoming(event:NoteScriptEvent):Void;
/**
* Called when EITHER player hits a note.
* Query the note attached to the event to determine if it was hit by the player or CPU.
*/
public function onNoteHit(event:HitNoteScriptEvent):Void;
/**
* Called when EITHER player (usually the player) misses a note.
*/
public function onNoteMiss(event:NoteScriptEvent):Void;
}
@ -73,7 +86,7 @@ interface INoteScriptedClass extends IScriptedClass
/**
* Defines a set of callbacks available to scripted classes that involve the lifecycle of the Play State.
*/
interface IPlayStateScriptedClass extends IScriptedClass
interface IPlayStateScriptedClass extends INoteScriptedClass
{
/**
* Called when the game is paused.
@ -113,17 +126,6 @@ interface IPlayStateScriptedClass extends IScriptedClass
*/
public function onSongRetry(event:ScriptEvent):Void;
/**
* Called when EITHER player hits a note.
* Query the note attached to the event to determine if it was hit by the player or CPU.
*/
public function onNoteHit(event:NoteScriptEvent):Void;
/**
* Called when EITHER player (usually the player) misses a note.
*/
public function onNoteMiss(event:NoteScriptEvent):Void;
/**
* Called when the player presses a key when no note is on the strumline.
*/

View file

@ -71,17 +71,29 @@ class ScriptEventDispatcher
}
}
if (Std.isOfType(target, IPlayStateScriptedClass))
if (Std.isOfType(target, INoteScriptedClass))
{
var t:IPlayStateScriptedClass = cast(target, IPlayStateScriptedClass);
var t:INoteScriptedClass = cast(target, INoteScriptedClass);
switch (event.type)
{
case NOTE_INCOMING:
t.onNoteIncoming(cast event);
return;
case NOTE_HIT:
t.onNoteHit(cast event);
return;
case NOTE_MISS:
t.onNoteMiss(cast event);
return;
default: // Continue;
}
}
if (Std.isOfType(target, IPlayStateScriptedClass))
{
var t:IPlayStateScriptedClass = cast(target, IPlayStateScriptedClass);
switch (event.type)
{
case NOTE_GHOST_MISS:
t.onNoteGhostMiss(cast event);
return;

View file

@ -63,6 +63,13 @@ enum abstract ScriptEventType(String) from String to String
*/
var SONG_STEP_HIT = 'STEP_HIT';
/**
* Called when a note comes on screen and starts approaching the strumline.
*
* This event is not cancelable.
*/
var NOTE_INCOMING = 'NOTE_INCOMING';
/**
* Called when a character hits a note.
* Important information such as judgement/timing, note data, player/opponent, etc. are all provided.

View file

@ -83,7 +83,9 @@ class Module implements IPlayStateScriptedClass implements IStateChangingScripte
public function onGameOver(event:ScriptEvent) {}
public function onNoteHit(event:NoteScriptEvent) {}
public function onNoteIncoming(event:NoteScriptEvent) {}
public function onNoteHit(event:HitNoteScriptEvent) {}
public function onNoteMiss(event:NoteScriptEvent) {}

View file

@ -1627,7 +1627,9 @@ class PlayState extends MusicBeatSubState
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
playerStrumline = new Strumline(noteStyle, !isBotPlayMode);
playerStrumline.onNoteIncoming.add(onStrumlineNoteIncoming);
opponentStrumline = new Strumline(noteStyle, false);
opponentStrumline.onNoteIncoming.add(onStrumlineNoteIncoming);
add(playerStrumline);
add(opponentStrumline);
@ -1763,6 +1765,13 @@ class PlayState extends MusicBeatSubState
opponentStrumline.applyNoteData(opponentNoteData);
}
function onStrumlineNoteIncoming(noteSprite:NoteSprite):Void
{
var event:NoteScriptEvent = new NoteScriptEvent(NOTE_INCOMING, noteSprite, 0, false);
dispatchEvent(event);
}
/**
* Prepares to start the countdown.
* Ends any running cutscenes, creates the strumlines, and starts the countdown.
@ -1971,7 +1980,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 NoteScriptEvent(NOTE_HIT, note, 0, true);
var event:NoteScriptEvent = new HitNoteScriptEvent(note, 0.0, 0, 'perfect', 0);
dispatchEvent(event);
// Calling event.cancelEvent() skips all the other logic! Neat!

View file

@ -485,7 +485,7 @@ class BaseCharacter extends Bopper
* Every time a note is hit, check if the note is from the same strumline.
* If it is, then play the sing animation.
*/
public override function onNoteHit(event:NoteScriptEvent)
public override function onNoteHit(event:HitNoteScriptEvent)
{
super.onNoteHit(event);

View file

@ -1,5 +1,6 @@
package funkin.play.notes;
import flixel.util.FlxSignal.FlxTypedSignal;
import flixel.FlxG;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.group.FlxSpriteGroup;
@ -53,6 +54,8 @@ class Strumline extends FlxSpriteGroup
public var holdNotes:FlxTypedSpriteGroup<SustainTrail>;
public var onNoteIncoming:FlxTypedSignal<NoteSprite->Void>;
var strumlineNotes:FlxTypedSpriteGroup<StrumlineNote>;
var noteSplashes:FlxTypedSpriteGroup<NoteSplash>;
var noteHoldCovers:FlxTypedSpriteGroup<NoteHoldCover>;
@ -110,6 +113,8 @@ class Strumline extends FlxSpriteGroup
this.refresh();
this.onNoteIncoming = new FlxTypedSignal<NoteSprite->Void>();
for (i in 0...KEY_COUNT)
{
var child:StrumlineNote = new StrumlineNote(noteStyle, isPlayer, DIRECTIONS[i]);
@ -315,6 +320,8 @@ class Strumline extends FlxSpriteGroup
}
nextNoteIndex = noteIndex + 1; // Increment the nextNoteIndex rather than splicing the array, because splicing is slow.
onNoteIncoming.dispatch(noteSprite);
}
// Update rendering of notes.

View file

@ -364,7 +364,9 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
public function onSongRetry(event:ScriptEvent):Void {};
public function onNoteHit(event:NoteScriptEvent):Void {};
public function onNoteIncoming(event:NoteScriptEvent) {}
public function onNoteHit(event:HitNoteScriptEvent) {}
public function onNoteMiss(event:NoteScriptEvent):Void {};

View file

@ -353,7 +353,9 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
public function onGameOver(event:ScriptEvent) {}
public function onNoteHit(event:NoteScriptEvent) {}
public function onNoteIncoming(event:NoteScriptEvent) {}
public function onNoteHit(event:HitNoteScriptEvent) {}
public function onNoteMiss(event:NoteScriptEvent) {}

View file

@ -870,7 +870,9 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
public function onCountdownEnd(event:CountdownScriptEvent) {}
public function onNoteHit(event:NoteScriptEvent) {}
public function onNoteIncoming(event:NoteScriptEvent) {}
public function onNoteHit(event:HitNoteScriptEvent) {}
public function onNoteMiss(event:NoteScriptEvent) {}

View file

@ -5934,7 +5934,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 NoteScriptEvent(NOTE_HIT, tempNote, 1, true);
var event:NoteScriptEvent = new HitNoteScriptEvent(tempNote, 0.0, 0, 'perfect', 0);
dispatchEvent(event);
// Calling event.cancelEvent() skips all the other logic! Neat!

View file

@ -2,6 +2,7 @@ package funkin.ui.haxeui.components;
import funkin.modding.events.ScriptEvent.GhostMissNoteScriptEvent;
import funkin.modding.events.ScriptEvent.NoteScriptEvent;
import funkin.modding.events.ScriptEvent.HitNoteScriptEvent;
import funkin.modding.events.ScriptEvent.SongTimeScriptEvent;
import funkin.modding.events.ScriptEvent.UpdateScriptEvent;
import haxe.ui.core.IDataComponent;
@ -216,12 +217,17 @@ class CharacterPlayer extends Box
if (character != null) character.onStepHit(event);
}
public function onNoteIncoming(event:NoteScriptEvent)
{
if (character != null) character.onNoteIncoming(event);
}
/**
* Called when a note is hit in the song
* Used to play character animations.
* @param event The event.
*/
public function onNoteHit(event:NoteScriptEvent):Void
public function onNoteHit(event:HitNoteScriptEvent):Void
{
if (character != null) character.onNoteHit(event);
}