From 50976d770b5b89009cc6d98088d75209cb3aa6fd Mon Sep 17 00:00:00 2001 From: Yoshman29 Date: Mon, 10 Oct 2022 13:31:55 +0200 Subject: [PATCH] events but cooler --- assets/charts/guns/test.hx | 10 ++ buildnumber.txt | 2 +- docs/doc.xml | 12 ++- .../scripting/events/CancellableEvent.html | 4 +- .../scripting/events/InputSystemEvent.html | 4 +- .../funkin/scripting/events/NoteHitEvent.html | 4 +- source/funkin/game/Character.hx | 7 ++ source/funkin/game/Note.hx | 4 +- source/funkin/game/PlayState.hx | 92 ++++++------------- .../scripting/events/CancellableEvent.hx | 11 ++- .../funkin/scripting/events/NoteHitEvent.hx | 72 ++++++++++++--- 11 files changed, 135 insertions(+), 87 deletions(-) create mode 100644 assets/charts/guns/test.hx diff --git a/assets/charts/guns/test.hx b/assets/charts/guns/test.hx new file mode 100644 index 00000000..c889c5d2 --- /dev/null +++ b/assets/charts/guns/test.hx @@ -0,0 +1,10 @@ +import funkin.system.Conductor; +import flixel.tweens.FlxTween; +import funkin.scripting.events.NoteHitEvent; + +function onPlayerHit(event:NoteHitEvent) { + if (event.note.isSustainNote) return; + event.preventDeletion(); + FlxTween.tween(event.note, {strumTime: event.note.strumTime + (Conductor.crochet * 2)}, Conductor.crochet / 500, {ease: FlxEase.cubeOut}); + event.note.wasGoodHit = false; +} \ No newline at end of file diff --git a/buildnumber.txt b/buildnumber.txt index f1efb205..0e92c3c0 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -300 \ No newline at end of file +306 \ No newline at end of file diff --git a/docs/doc.xml b/docs/doc.xml index 05966757..e0b1f899 100644 --- a/docs/doc.xml +++ b/docs/doc.xml @@ -25029,9 +25029,9 @@ - <__touch get="inline" set="null" expr=""1.665394232e+012"" line="22" static="1"> + <__touch get="inline" set="null" expr=""1.665397787e+012"" line="22" static="1"> - "1.665394232e+012" + "1.665397787e+012" @@ -80736,7 +80736,13 @@ hide - + + + * Returns a string representation of the event, in this format: + * `[CancellableEvent]` + * `[CancellableEvent (Cancelled)]` + * @return String + * Creates a new cancellable event. diff --git a/pages/funkin/scripting/events/CancellableEvent.html b/pages/funkin/scripting/events/CancellableEvent.html index 7766ec9d..d55cc668 100644 --- a/pages/funkin/scripting/events/CancellableEvent.html +++ b/pages/funkin/scripting/events/CancellableEvent.html @@ -8,4 +8,6 @@ text-shadow: 0 0 0 transparent; }

Constructor

new()

Creates a new cancellable event. -This allows scripts to call cancel() to cancel the event.

Variables

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Methods

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

\ No newline at end of file +This allows scripts to call cancel() to cancel the event.

Variables

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Methods

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

Returns a string representation of the event, in this format: +[CancellableEvent] +[CancellableEvent (Cancelled)]

Returns:

String

\ No newline at end of file diff --git a/pages/funkin/scripting/events/InputSystemEvent.html b/pages/funkin/scripting/events/InputSystemEvent.html index 13a79d1a..3b35d705 100644 --- a/pages/funkin/scripting/events/InputSystemEvent.html +++ b/pages/funkin/scripting/events/InputSystemEvent.html @@ -10,4 +10,6 @@

Constructor

new(pressed:Array<Bool>, justPressed:Array<Bool>, justReleased:Array<Bool>)

Variables

justPressed:Array<Bool>

Array containing whenever a specific control was pressed (not hold) this frame or not. For example, justPressed[0] will return whenever the left strum was just pressed.

justReleased:Array<Bool>

Array containing whenever a specific control was released this frame or not. For example, justReleased[0] will return whenever the left strum was just released.

pressed:Array<Bool>

Array containing whenever a specific control is pressed or not. -For example, pressed[0] will return whenever the left strum was pressed.

Inherited Variables

Defined by CancellableEvent

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Inherited Methods

Defined by CancellableEvent

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

\ No newline at end of file +For example, pressed[0] will return whenever the left strum was pressed.

Inherited Variables

Defined by CancellableEvent

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Inherited Methods

Defined by CancellableEvent

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

Returns a string representation of the event, in this format: +[CancellableEvent] +[CancellableEvent (Cancelled)]

Returns:

String

\ No newline at end of file diff --git a/pages/funkin/scripting/events/NoteHitEvent.html b/pages/funkin/scripting/events/NoteHitEvent.html index 524b423d..e38df826 100644 --- a/pages/funkin/scripting/events/NoteHitEvent.html +++ b/pages/funkin/scripting/events/NoteHitEvent.html @@ -7,4 +7,6 @@ float: none; text-shadow: 0 0 0 transparent; } -

Constructor

new(note:Note, character:Character, player:Bool, noteType:String, direction:Int)

Creates a new NoteHitEvent with the following values:

Parameters:

note
character
player
null

noteType

Variables

Methods

preventAnim():Void

Prevents the default sing animation from being played.

Inherited Variables

Defined by CancellableEvent

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Inherited Methods

Defined by CancellableEvent

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

\ No newline at end of file +

Constructor

new(note:Note, character:Character, player:Bool, noteType:String, direction:Int)

Creates a new NoteHitEvent with the following values:

Parameters:

note
character
player
null

noteType

Variables

Methods

preventAnim():Void

Prevents the default sing animation from being played.

Inherited Variables

Defined by CancellableEvent

@:value({ })data:Dynamic = { }

Additional data if used in scripts

Inherited Methods

Defined by CancellableEvent

@:value({ c : true })preventDefault(c:Bool = true):Void

Prevents default action from occuring.

Parameters:

c

Whenever the scripts following this one should be called or not. (Defaults to true)

toString():String

Returns a string representation of the event, in this format: +[CancellableEvent] +[CancellableEvent (Cancelled)]

Returns:

String

\ No newline at end of file diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index 728526f4..9c744a5d 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -52,6 +52,13 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom midpoint.x + (isPlayer ? -100 : 150) + globalOffset.x + cameraOffset.x, midpoint.y - 100 + globalOffset.y + cameraOffset.y); } + + public function playSingAnim(direction:Int, suffix:String = "") { + // TODO: Script Events + var anims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; + playAnim('${anims[direction]}$suffix', true); + } + public function new(x:Float, y:Float, ?character:String = "bf", ?isPlayer:Bool = false) { super(x, y); diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index 1ac87713..91817670 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -60,7 +60,7 @@ class Note extends FlxSprite this.noteData = noteData; - var daStage:String = PlayState.instance.curStage; + var daStage:String = PlayState.instance == null ? "stage" : PlayState.instance.curStage; switch (daStage) { @@ -154,7 +154,7 @@ class Note extends FlxSprite x -= width / 2; - if (PlayState.instance.curStage.startsWith('school')) + if (daStage.startsWith('school')) x += 30; if (prevNote.isSustainNote) diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 15cd28bb..6b121adf 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -209,7 +209,7 @@ class PlayState extends MusicBeatState // ADD YOUR HARDCODED SCRIPTS HERE! default: trace('charts/${SONG.song}/'); - var content = Paths.getFolderContent('charts/${SONG.song}/', false, true, false); + var content = Paths.getFolderContent('charts/${SONG.song}/', false, true, !fromMods); trace(content); for(file in content) { @@ -1351,72 +1351,38 @@ class PlayState extends MusicBeatState { if (!note.wasGoodHit) { - camZooming = true; - if (note.mustPress) { - // TODO: See TODO above - var event = scripts.event("onPlayerHit", new NoteHitEvent(note, boyfriend, true, note.noteType, note.strumID)); - if (!event.cancelled) { - if (!note.isSustainNote) - { - combo++; - popUpScore(note.strumTime); - } - - if (note.noteData >= 0) - health += 0.023; - else - health += 0.004; - - if (!event.animCancelled) { - switch (event.direction) - { - case 0: - boyfriend.playAnim('singLEFT', true); - case 1: - boyfriend.playAnim('singDOWN', true); - case 2: - boyfriend.playAnim('singUP', true); - case 3: - boyfriend.playAnim('singRIGHT', true); - } - } - - playerStrums.forEach(function(str:Strum) { - if (str.ID == Math.abs(note.noteData % 4)) { - str.press(note.strumTime); - } - }); - } - } else { - // TODO: See TODO above the todo above - var event = scripts.event("onDadHit", new NoteHitEvent(note, dad, false, note.noteType, note.strumID)); - if (!event.cancelled) { - if (!event.animCancelled) { - switch (event.direction) - { - case 0: - dad.playAnim('singLEFT', true); - case 1: - dad.playAnim('singDOWN', true); - case 2: - dad.playAnim('singUP', true); - case 3: - dad.playAnim('singRIGHT', true); - } - } + note.wasGoodHit = true; - cpuStrums.forEach(function(str:Strum) { - if (str.ID == Math.abs(note.noteData % 4)) { - str.press(note.strumTime); - } - }); + var event:NoteHitEvent; + if (note.mustPress) + event = scripts.event("onPlayerHit", new NoteHitEvent(note, boyfriend, true, note.noteType, note.strumID, note.noteData > 0 ? 0.023 : 0.004)); + else + event = scripts.event("onDadHit", new NoteHitEvent(note, dad, false, note.noteType, note.strumID, 0)); + + if (!event.cancelled) { + if (event.player && !note.isSustainNote) + { + combo++; + popUpScore(note.strumTime); } + + health += event.healthGain; + + if (!event.animCancelled) { + event.character.playSingAnim(event.direction); + } + + (event.player ? playerStrums : cpuStrums).forEach(function(str:Strum) { + if (str.ID == Math.abs(note.strumID)) { + str.press(note.strumTime); + } + }); } - note.wasGoodHit = true; - vocals.volume = 1; + if (event.unmuteVocals) vocals.volume = 1; + if (event.enableCamZooming) camZooming = true; - if (!note.isSustainNote) deleteNote(note); + if (event.deleteNote && !note.isSustainNote) deleteNote(note); } } @@ -1482,4 +1448,4 @@ class PlayState extends MusicBeatState } public var curLight:Int = 0; -} +} \ No newline at end of file diff --git a/source/funkin/scripting/events/CancellableEvent.hx b/source/funkin/scripting/events/CancellableEvent.hx index 0bedf327..8b52f950 100644 --- a/source/funkin/scripting/events/CancellableEvent.hx +++ b/source/funkin/scripting/events/CancellableEvent.hx @@ -30,9 +30,16 @@ class CancellableEvent { */ public function new() {} + /** + * Returns a string representation of the event, in this format: + * `[CancellableEvent]` + * `[CancellableEvent (Cancelled)]` + * @return String + */ public function toString():String { - var rep = '[CancellableEvent ${cancelled ? "(Cancelled)" : ""} - ]'; - // TODO: List all fields + var fields = Reflect.fields(this); + var claName = Type.getClassName(Type.getClass(this)).split("."); + var rep = '[${claName[claName.length-1]}${cancelled ? " (Cancelled)" : ""}]'; return rep; } } \ No newline at end of file diff --git a/source/funkin/scripting/events/NoteHitEvent.hx b/source/funkin/scripting/events/NoteHitEvent.hx index 7dce8da7..0bd68ec7 100644 --- a/source/funkin/scripting/events/NoteHitEvent.hx +++ b/source/funkin/scripting/events/NoteHitEvent.hx @@ -5,28 +5,47 @@ import funkin.game.Character; class NoteHitEvent extends CancellableEvent { @:dox(hide) public var animCancelled:Bool = false; - - public var note:Note; - public var character:Character; - public var player:Bool; - public var noteType:String; - public var direction:Int; + @:dox(hide) public var deleteNote:Bool = true; + @:dox(hide) public var unmuteVocals:Bool = true; + @:dox(hide) public var enableCamZooming:Bool = true; /** - * Creates a new NoteHitEvent with the following values: - * @param note - * @param character - * @param player - * @param noteType + * Note that has been pressed */ - public function new(note:Note, character:Character, player:Bool, noteType:String, direction:Int) { + public var note:Note; + /** + * Character that pressed the note + */ + public var character:Character; + /** + * Whenever the Character is the player + */ + public var player:Bool; + /** + * Note Type name (null if default note) + */ + public var noteType:String; + /** + * Direction of the press (0 = Left, 1 = Down, 2 = Up, 3 = Right) + */ + public var direction:Int; + /** + * The amount of health that'll be gained from pressing that note. + */ + public var healthGain:Float; + + /** + * Creates a new NoteHitEvent. + */ + public function new(note:Note, character:Character, player:Bool, noteType:String, direction:Int, healthGain:Float) { super(); this.note = note; this.character = character; this.player = player; this.noteType = noteType; - this.direction = direction; + this.direction = cast direction; + this.healthGain = healthGain; } /** @@ -38,4 +57,31 @@ class NoteHitEvent extends CancellableEvent { @:dox(hide) public function cancelAnim() {preventAnim();} + + /** + * Prevents the note from being deleted. + */ + public function preventDeletion() { + deleteNote = false; + } + @:dox(hide) + public function cancelDeletion() {preventDeletion();} + + /** + * Prevents the vocals volume from being set to 1 after pressing the note. + */ + public function preventVocalsUnmute() { + unmuteVocals = false; + } + @:dox(hide) + public function cancelVocalsUnmute() {preventVocalsUnmute();} + + /** + * Prevents the camera zoom every 4 beats from enabling. + */ + public function preventCamZooming() { + enableCamZooming = false; + } + @:dox(hide) + public function cancelCamZooming() {preventCamZooming();} } \ No newline at end of file