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:
commit
c98870e923
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 51b02f0d47e5b34bf8589065c092953c10c5040d
|
Subproject commit 095e91fb33dad70a5b51e37542e335cedd025d09
|
|
@ -56,7 +56,20 @@ interface IStateStageProp extends IScriptedClass
|
||||||
*/
|
*/
|
||||||
interface INoteScriptedClass 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;
|
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.
|
* 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.
|
* Called when the game is paused.
|
||||||
|
@ -113,17 +126,6 @@ interface IPlayStateScriptedClass extends IScriptedClass
|
||||||
*/
|
*/
|
||||||
public function onSongRetry(event:ScriptEvent):Void;
|
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.
|
* Called when the player presses a key when no note is on the strumline.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
|
case NOTE_INCOMING:
|
||||||
|
t.onNoteIncoming(cast event);
|
||||||
|
return;
|
||||||
case NOTE_HIT:
|
case NOTE_HIT:
|
||||||
t.onNoteHit(cast event);
|
t.onNoteHit(cast event);
|
||||||
return;
|
return;
|
||||||
case NOTE_MISS:
|
case NOTE_MISS:
|
||||||
t.onNoteMiss(cast event);
|
t.onNoteMiss(cast event);
|
||||||
return;
|
return;
|
||||||
|
default: // Continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Std.isOfType(target, IPlayStateScriptedClass))
|
||||||
|
{
|
||||||
|
var t:IPlayStateScriptedClass = cast(target, IPlayStateScriptedClass);
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
case NOTE_GHOST_MISS:
|
case NOTE_GHOST_MISS:
|
||||||
t.onNoteGhostMiss(cast event);
|
t.onNoteGhostMiss(cast event);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -63,6 +63,13 @@ enum abstract ScriptEventType(String) from String to String
|
||||||
*/
|
*/
|
||||||
var SONG_STEP_HIT = 'STEP_HIT';
|
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.
|
* Called when a character hits a note.
|
||||||
* Important information such as judgement/timing, note data, player/opponent, etc. are all provided.
|
* Important information such as judgement/timing, note data, player/opponent, etc. are all provided.
|
||||||
|
|
|
@ -83,7 +83,9 @@ class Module implements IPlayStateScriptedClass implements IStateChangingScripte
|
||||||
|
|
||||||
public function onGameOver(event:ScriptEvent) {}
|
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) {}
|
public function onNoteMiss(event:NoteScriptEvent) {}
|
||||||
|
|
||||||
|
|
|
@ -1627,7 +1627,9 @@ class PlayState extends MusicBeatSubState
|
||||||
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
|
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
|
||||||
|
|
||||||
playerStrumline = new Strumline(noteStyle, !isBotPlayMode);
|
playerStrumline = new Strumline(noteStyle, !isBotPlayMode);
|
||||||
|
playerStrumline.onNoteIncoming.add(onStrumlineNoteIncoming);
|
||||||
opponentStrumline = new Strumline(noteStyle, false);
|
opponentStrumline = new Strumline(noteStyle, false);
|
||||||
|
opponentStrumline.onNoteIncoming.add(onStrumlineNoteIncoming);
|
||||||
add(playerStrumline);
|
add(playerStrumline);
|
||||||
add(opponentStrumline);
|
add(opponentStrumline);
|
||||||
|
|
||||||
|
@ -1763,6 +1765,13 @@ class PlayState extends MusicBeatSubState
|
||||||
opponentStrumline.applyNoteData(opponentNoteData);
|
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.
|
* Prepares to start the countdown.
|
||||||
* Ends any running cutscenes, creates the strumlines, and starts 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.
|
// Call an event to allow canceling the note hit.
|
||||||
// NOTE: This is what handles the character animations!
|
// 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);
|
dispatchEvent(event);
|
||||||
|
|
||||||
// Calling event.cancelEvent() skips all the other logic! Neat!
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
||||||
|
|
|
@ -485,7 +485,7 @@ class BaseCharacter extends Bopper
|
||||||
* Every time a note is hit, check if the note is from the same strumline.
|
* Every time a note is hit, check if the note is from the same strumline.
|
||||||
* If it is, then play the sing animation.
|
* If it is, then play the sing animation.
|
||||||
*/
|
*/
|
||||||
public override function onNoteHit(event:NoteScriptEvent)
|
public override function onNoteHit(event:HitNoteScriptEvent)
|
||||||
{
|
{
|
||||||
super.onNoteHit(event);
|
super.onNoteHit(event);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package funkin.play.notes;
|
package funkin.play.notes;
|
||||||
|
|
||||||
|
import flixel.util.FlxSignal.FlxTypedSignal;
|
||||||
import flixel.FlxG;
|
import flixel.FlxG;
|
||||||
import funkin.play.notes.notestyle.NoteStyle;
|
import funkin.play.notes.notestyle.NoteStyle;
|
||||||
import flixel.group.FlxSpriteGroup;
|
import flixel.group.FlxSpriteGroup;
|
||||||
|
@ -53,6 +54,8 @@ class Strumline extends FlxSpriteGroup
|
||||||
|
|
||||||
public var holdNotes:FlxTypedSpriteGroup<SustainTrail>;
|
public var holdNotes:FlxTypedSpriteGroup<SustainTrail>;
|
||||||
|
|
||||||
|
public var onNoteIncoming:FlxTypedSignal<NoteSprite->Void>;
|
||||||
|
|
||||||
var strumlineNotes:FlxTypedSpriteGroup<StrumlineNote>;
|
var strumlineNotes:FlxTypedSpriteGroup<StrumlineNote>;
|
||||||
var noteSplashes:FlxTypedSpriteGroup<NoteSplash>;
|
var noteSplashes:FlxTypedSpriteGroup<NoteSplash>;
|
||||||
var noteHoldCovers:FlxTypedSpriteGroup<NoteHoldCover>;
|
var noteHoldCovers:FlxTypedSpriteGroup<NoteHoldCover>;
|
||||||
|
@ -110,6 +113,8 @@ class Strumline extends FlxSpriteGroup
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
|
||||||
|
this.onNoteIncoming = new FlxTypedSignal<NoteSprite->Void>();
|
||||||
|
|
||||||
for (i in 0...KEY_COUNT)
|
for (i in 0...KEY_COUNT)
|
||||||
{
|
{
|
||||||
var child:StrumlineNote = new StrumlineNote(noteStyle, isPlayer, DIRECTIONS[i]);
|
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.
|
nextNoteIndex = noteIndex + 1; // Increment the nextNoteIndex rather than splicing the array, because splicing is slow.
|
||||||
|
|
||||||
|
onNoteIncoming.dispatch(noteSprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update rendering of notes.
|
// Update rendering of notes.
|
||||||
|
|
|
@ -364,7 +364,9 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
|
||||||
|
|
||||||
public function onSongRetry(event:ScriptEvent):Void {};
|
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 {};
|
public function onNoteMiss(event:NoteScriptEvent):Void {};
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,9 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
|
||||||
|
|
||||||
public function onGameOver(event:ScriptEvent) {}
|
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) {}
|
public function onNoteMiss(event:NoteScriptEvent) {}
|
||||||
|
|
||||||
|
|
|
@ -870,7 +870,9 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
|
||||||
|
|
||||||
public function onCountdownEnd(event:CountdownScriptEvent) {}
|
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) {}
|
public function onNoteMiss(event:NoteScriptEvent) {}
|
||||||
|
|
||||||
|
|
|
@ -5934,7 +5934,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
|
||||||
var tempNote:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault());
|
var tempNote:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault());
|
||||||
tempNote.noteData = noteData;
|
tempNote.noteData = noteData;
|
||||||
tempNote.scrollFactor.set(0, 0);
|
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);
|
dispatchEvent(event);
|
||||||
|
|
||||||
// Calling event.cancelEvent() skips all the other logic! Neat!
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
||||||
|
|
|
@ -2,6 +2,7 @@ package funkin.ui.haxeui.components;
|
||||||
|
|
||||||
import funkin.modding.events.ScriptEvent.GhostMissNoteScriptEvent;
|
import funkin.modding.events.ScriptEvent.GhostMissNoteScriptEvent;
|
||||||
import funkin.modding.events.ScriptEvent.NoteScriptEvent;
|
import funkin.modding.events.ScriptEvent.NoteScriptEvent;
|
||||||
|
import funkin.modding.events.ScriptEvent.HitNoteScriptEvent;
|
||||||
import funkin.modding.events.ScriptEvent.SongTimeScriptEvent;
|
import funkin.modding.events.ScriptEvent.SongTimeScriptEvent;
|
||||||
import funkin.modding.events.ScriptEvent.UpdateScriptEvent;
|
import funkin.modding.events.ScriptEvent.UpdateScriptEvent;
|
||||||
import haxe.ui.core.IDataComponent;
|
import haxe.ui.core.IDataComponent;
|
||||||
|
@ -216,12 +217,17 @@ class CharacterPlayer extends Box
|
||||||
if (character != null) character.onStepHit(event);
|
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
|
* Called when a note is hit in the song
|
||||||
* Used to play character animations.
|
* Used to play character animations.
|
||||||
* @param event The event.
|
* @param event The event.
|
||||||
*/
|
*/
|
||||||
public function onNoteHit(event:NoteScriptEvent):Void
|
public function onNoteHit(event:HitNoteScriptEvent):Void
|
||||||
{
|
{
|
||||||
if (character != null) character.onNoteHit(event);
|
if (character != null) character.onNoteHit(event);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue