From 63666fef942bb7b7de07735b3c28c88d678735c4 Mon Sep 17 00:00:00 2001 From: Yoshman29 Date: Wed, 26 Oct 2022 16:17:08 +0200 Subject: [PATCH] note types!! --- buildnumber.txt | 2 +- launch.bat | 3 + source/funkin/game/Note.hx | 151 +++++------------- source/funkin/game/PlayState.hx | 14 +- source/funkin/options/Options.hx | 2 + .../scripting/events/NoteCreationEvent.hx | 59 +++++++ source/scripting/PlayStateScript.hx | 14 +- 7 files changed, 123 insertions(+), 122 deletions(-) create mode 100644 launch.bat create mode 100644 source/funkin/scripting/events/NoteCreationEvent.hx diff --git a/buildnumber.txt b/buildnumber.txt index c1891366..fc0b67d0 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -769 \ No newline at end of file +774 \ No newline at end of file diff --git a/launch.bat b/launch.bat new file mode 100644 index 00000000..54c4f8c8 --- /dev/null +++ b/launch.bat @@ -0,0 +1,3 @@ +cd export\release\windows\bin\ +CodenameEngine.exe +cd ..\..\..\..\ \ No newline at end of file diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index 8295e8f0..f2c935a8 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -7,6 +7,7 @@ import flixel.util.FlxColor; import flixel.math.FlxRect; import flixel.math.FlxPoint; import funkin.system.Conductor; +import funkin.scripting.events.*; #if polymod import polymod.format.ParseRules.TargetSignatureElement; #end @@ -34,7 +35,6 @@ class Note extends FlxSprite public var sustainLength:Float = 0; public var isSustainNote:Bool = false; - public var noteScore:Float = 1; public var noteTypeID:Int = 0; public var noteType(get, null):String; @@ -63,120 +63,57 @@ class Note extends FlxSprite this.noteData = noteData; - var daStage:String = PlayState.instance == null ? "stage" : PlayState.instance.curStage; + var event = new NoteCreationEvent(this, strumID, this.noteType, noteTypeID, mustPress, "NOTE_assets", 0.7); - switch (daStage) - { - case 'school' | 'schoolEvil': - loadGraphic(Paths.image('weeb/pixelUI/arrows-pixels'), true, 17, 17); + if (PlayState.instance != null) + event = PlayState.instance.scripts.event("onNoteCreation", event); - animation.add('greenScroll', [6]); - animation.add('redScroll', [7]); - animation.add('blueScroll', [5]); - animation.add('purpleScroll', [4]); + if (!event.cancelled) { + switch (event.noteType) + { + // case "My Custom Note Type": // hardcoding note types + default: + frames = Paths.getSparrowAtlas(event.noteSprite); - if (isSustainNote) - { - loadGraphic(Paths.image('weeb/pixelUI/arrowEnds'), true, 7, 6); + switch(event.strumID % 4) { + case 0: + animation.addByPrefix('scroll', 'purple0'); + animation.addByPrefix('hold', 'purple hold piece'); + animation.addByPrefix('holdend', 'pruple end hold'); + case 1: + animation.addByPrefix('scroll', 'blue0'); + animation.addByPrefix('hold', 'blue hold piece'); + animation.addByPrefix('holdend', 'blue hold end'); + case 2: + animation.addByPrefix('scroll', 'green0'); + animation.addByPrefix('hold', 'green hold piece'); + animation.addByPrefix('holdend', 'green hold end'); + case 3: + animation.addByPrefix('scroll', 'red0'); + animation.addByPrefix('hold', 'red hold piece'); + animation.addByPrefix('holdend', 'red hold end'); + } - animation.add('purpleholdend', [4]); - animation.add('greenholdend', [6]); - animation.add('redholdend', [7]); - animation.add('blueholdend', [5]); - - animation.add('purplehold', [0]); - animation.add('greenhold', [2]); - animation.add('redhold', [3]); - animation.add('bluehold', [1]); - } - - setGraphicSize(Std.int(width * PlayState.daPixelZoom)); - updateHitbox(); - - default: - frames = Paths.getSparrowAtlas('NOTE_assets'); - - animation.addByPrefix('greenScroll', 'green0'); - animation.addByPrefix('redScroll', 'red0'); - animation.addByPrefix('blueScroll', 'blue0'); - animation.addByPrefix('purpleScroll', 'purple0'); - - animation.addByPrefix('purpleholdend', 'pruple end hold'); - animation.addByPrefix('greenholdend', 'green hold end'); - animation.addByPrefix('redholdend', 'red hold end'); - animation.addByPrefix('blueholdend', 'blue hold end'); - - animation.addByPrefix('purplehold', 'purple hold piece'); - animation.addByPrefix('greenhold', 'green hold piece'); - animation.addByPrefix('redhold', 'red hold piece'); - animation.addByPrefix('bluehold', 'blue hold piece'); - - setGraphicSize(Std.int(width * 0.7)); - updateHitbox(); - antialiasing = true; + scale.set(event.noteScale, event.noteScale); + updateHitbox(); + antialiasing = true; + } } - switch (noteData) - { - case 0: - x += swagWidth * 0; - animation.play('purpleScroll'); - case 1: - x += swagWidth * 1; - animation.play('blueScroll'); - case 2: - x += swagWidth * 2; - animation.play('greenScroll'); - case 3: - x += swagWidth * 3; - animation.play('redScroll'); - } - - // trace(prevNote); + animation.play("scroll"); if (isSustainNote && prevNote != null) { - noteScore * 0.2; alpha = 0.6; - - x += width / 2; - - switch (noteData) - { - case 2: - animation.play('greenholdend'); - case 3: - animation.play('redholdend'); - case 1: - animation.play('blueholdend'); - case 0: - animation.play('purpleholdend'); - } + animation.play('holdend'); updateHitbox(); - x -= width / 2; - - if (daStage.startsWith('school')) - x += 30; - if (prevNote.isSustainNote) { - switch (prevNote.noteData) - { - case 0: - prevNote.animation.play('purplehold'); - case 1: - prevNote.animation.play('bluehold'); - case 2: - prevNote.animation.play('greenhold'); - case 3: - prevNote.animation.play('redhold'); - } - + prevNote.animation.play('hold'); prevNote.scale.y *= Conductor.stepCrochet / 100 * 1.5 * PlayState.instance.scrollSpeed; prevNote.updateHitbox(); - // prevNote.setGraphicSize(); } } } @@ -227,31 +164,23 @@ class Note extends FlxSprite super.draw(); } + // The * 0.5 is so that it's easier to hit them too late, instead of too early + public var earlyPressWindow:Float = 0.5; + public var latePressWindow:Float = 1; override function update(elapsed:Float) { super.update(elapsed); if (mustPress) { - // The * 0.5 is so that it's easier to hit them too late, instead of too early - if (strumTime > Conductor.songPosition - Conductor.safeZoneOffset - && strumTime < Conductor.songPosition + (Conductor.safeZoneOffset * 0.5)) - canBeHit = true; - else - canBeHit = false; + canBeHit = (strumTime > Conductor.songPosition - (Conductor.safeZoneOffset * latePressWindow) + && strumTime < Conductor.songPosition + (Conductor.safeZoneOffset * earlyPressWindow)) if (strumTime < Conductor.songPosition - Conductor.safeZoneOffset && !wasGoodHit) tooLate = true; } else canBeHit = false; - - - if (tooLate) - { - if (alpha > 0.3) - alpha = 0.3; - } } public function updateClipRect(strum:Strum) { diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index d06ae1a8..31a3dae8 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -484,9 +484,11 @@ class PlayState extends MusicBeatState generatedMusic = true; } - public function addNoteType(name:String) { - // TODO: add note type by string - return 0; + public function addNoteType(name:String):Int { + for(k=>e in noteTypesArray) + if (e == name) return k; + noteTypesArray.push(name); + return noteTypesArray.length-1; } function sortByShit(Obj1:Note, Obj2:Note):Int { @@ -1288,9 +1290,9 @@ class PlayState extends MusicBeatState } } - public function getNoteType(id:Int) { - // TODO: Note Types - return null; + public var noteTypesArray:Array = [null]; + public function getNoteType(id:Int):String { + return noteTypesArray[id]; } function goodNoteHit(note:Note):Void diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index 62a791c2..1a960bd7 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -1,5 +1,6 @@ package funkin.options; +import funkin.system.Controls; import openfl.Lib; import flixel.util.FlxSave; import flixel.input.keyboard.FlxKey; @@ -157,6 +158,7 @@ class Options }); __eventAdded = true; } + PlayerSettings.player1.setKeyboardScheme(Solo); } public static function save() { diff --git a/source/funkin/scripting/events/NoteCreationEvent.hx b/source/funkin/scripting/events/NoteCreationEvent.hx new file mode 100644 index 00000000..b2b6d7f4 --- /dev/null +++ b/source/funkin/scripting/events/NoteCreationEvent.hx @@ -0,0 +1,59 @@ +package funkin.scripting.events; + +import funkin.game.Note; + +class NoteCreationEvent extends CancellableEvent { + /** + * Note that is being created + */ + public var note:Note; + + /** + * ID of the strum (from 0 to 3) + */ + public var strumID:Int; + + /** + * Note Type (ex: "My Super Cool Note", or "Mine") + */ + public var noteType:String; + + /** + * ID of the note type. + */ + public var noteTypeID:Int; + + /** + * Whenever the note will need to be hit by the player + */ + public var mustHit:Bool; + + /** + * Note sprite, if you only want to replace the sprite. + */ + public var noteSprite:String; + + /** + * Note scale, if you only want to replace the scale. + */ + public var noteScale:Float; + + /** + * [Description] Creates a new NoteCreationEvent + * @param note + * @param strumID + * @param noteType + * @param noteTypeID + * @param mustHit + */ + public function new(note:Note, strumID:Int, noteType:String, noteTypeID:Int, mustHit:Bool, noteSprite:String, noteScale:Float) { + super(); + this.note = note; + this.strumID = strumID; + this.noteType = noteType; + this.noteTypeID = noteTypeID; + this.mustHit = mustHit; + this.noteSprite = noteSprite; + this.noteScale = noteScale; + } +} \ No newline at end of file diff --git a/source/scripting/PlayStateScript.hx b/source/scripting/PlayStateScript.hx index 511d5f38..8212c3e0 100644 --- a/source/scripting/PlayStateScript.hx +++ b/source/scripting/PlayStateScript.hx @@ -62,23 +62,29 @@ interface PlayStateScript { * Triggered whenever the player hits a note. * @param note Event object with the note being pressed, the character who pressed it, and functions to alter or cancel the default behaviour. */ - public function onPlayerHit(note:NoteHitEvent):Void; + public function onPlayerHit(event:NoteHitEvent):Void; /** * Triggered whenever the opponent hits a note. * @param note Event object with the note being pressed, the character who pressed it, and functions to alter or cancel the default behaviour. */ - public function onDadHit(note:NoteHitEvent):Void; + public function onDadHit(event:NoteHitEvent):Void; /** * Triggered whenever the input system updates. * @param note Event object with the pressed notes, which allows you to alter which notes are being pressed during this frame, or simply cancel the input update. */ - public function inputUpdate(note:InputSystemEvent):Void; + public function inputUpdate(event:InputSystemEvent):Void; /** * Triggered after the input system updates. * @param note Event object with the pressed, justPressed and justReleased notes. */ - public function inputUpdatePost(note:InputSystemEvent):Void; + public function inputUpdatePost(event:InputSystemEvent):Void; + + /** + * Triggered on each note creation + * @param event Event object containing information about the note. + */ + public function onNoteCreation(event:NoteCreationEvent):Void; } \ No newline at end of file