strumline extensibility

This commit is contained in:
Dirk-Dinkum
2023-05-24 17:51:42 +02:00
parent 0f3103998b
commit bc9a7ba907
5 changed files with 42 additions and 39 deletions
@@ -21,6 +21,11 @@ final class StrumCreationEvent extends CancellableEvent {
*/
public var strumID:Int;
/**
* Animation prefix (`left` = `arrowLEFT`, `left press`, `left confirm`).
*/
public var animPrefix:String;
/**
* Sprite path, in case you only want to change the sprite.
*/
+1 -1
View File
@@ -61,7 +61,7 @@ class Note extends FlxSprite
public var strumID(get, never):Int;
private function get_strumID() {
var id = noteData % 4;
var id = noteData % strumLine.members.length;
if (id < 0) id = 0;
return id;
}
+7 -6
View File
@@ -635,6 +635,12 @@ class PlayState extends MusicBeatState
// CAMERA & HUD INITIALISATION
#if REGION
if (!scripts.event("onPreGenerateStrums", new CancellableEvent()).cancelled) {
generateStrums();
scripts.call("onPostGenerateStrums");
}
for(str in strumLines)
str.generate(str.data, (chartingMode && Charter.startHere) ? Charter.startTime : null);
@@ -661,7 +667,7 @@ class PlayState extends MusicBeatState
healthBarBG.scrollFactor.set();
add(healthBarBG);
healthBar = new FlxBar(healthBarBG.x + 4, healthBarBG.y + 4, RIGHT_TO_LEFT, Std.int(healthBarBG.width - 8), Std.int(healthBarBG.height - 8), this,
'health', 0, maxHealth);
@@ -786,11 +792,6 @@ class PlayState extends MusicBeatState
if (scripts.event("onStartCountdown", new CancellableEvent()).cancelled) return;
}
if (!scripts.event("onPreGenerateStrums", new CancellableEvent()).cancelled) {
generateStrums();
scripts.call("onPostGenerateStrums");
}
startedCountdown = true;
Conductor.songPosition = 0;
Conductor.songPosition -= Conductor.crochet * introLength;
+6 -6
View File
@@ -9,7 +9,7 @@ class Strum extends FlxSprite {
public var scrollSpeed:Null<Float> = null; // custom scroll speed per strum
public var noteAngle:Null<Float> = null;
public var lastDrawCameras(default, null):Array<FlxCamera> = [];
public var getPressed:StrumLine->Bool = null;
@@ -50,7 +50,7 @@ class Strum extends FlxSprite {
if (PlayState.instance != null) return PlayState.instance.scrollSpeed;
return 1;
}
public inline function getNotesAngle(?note:Note):Float {
if (note != null && note.noteAngle != null) return note.noteAngle;
if (noteAngle != null) return noteAngle;
@@ -76,7 +76,7 @@ class Strum extends FlxSprite {
public function updateNotePosition(daNote:Note) {
if (!daNote.exists) return;
daNote.__strumCameras = lastDrawCameras;
daNote.__strum = this;
daNote.scrollFactor.set(scrollFactor.x, scrollFactor.y);
@@ -95,7 +95,7 @@ class Strum extends FlxSprite {
var realOffset = FlxPoint.get(0, 0);
if (daNote.isSustainNote) offset.y -= N_WIDTHDIV2;
if (Std.int(daNote.__noteAngle % 360) != 0) {
var noteAngleCos = FlxMath.fastCos(daNote.__noteAngle / PIX180);
var noteAngleSin = FlxMath.fastSin(daNote.__noteAngle / PIX180);
@@ -113,9 +113,9 @@ class Strum extends FlxSprite {
realOffset.y = offset.y;
}
realOffset.y *= -1;
daNote.setPosition(x + realOffset.x, y + realOffset.y);
offset.put();
realOffset.put();
}
+23 -26
View File
@@ -193,7 +193,7 @@ class StrumLine extends FlxTypedGroup<Strum> {
__justReleased.push(s.__getJustReleased(this));
}
var event = PlayState.instance.scripts.event("onKeyShit", EventManager.get(InputSystemEvent).recycle(__pressed, __justPressed, __justReleased, this, id));
var event = PlayState.instance.scripts.event("onInputUpdate", EventManager.get(InputSystemEvent).recycle(__pressed, __justPressed, __justReleased, this, id));
if (event.cancelled) return;
__pressed = CoolUtil.getDefault(event.pressed, []);
@@ -226,9 +226,9 @@ class StrumLine extends FlxTypedGroup<Strum> {
for(e in __notePerStrum) if (e != null) PlayState.instance.goodNoteHit(this, e);
forEach(function(str:Strum) {
str.updatePlayerInput(__pressed[str.ID], __justPressed[str.ID], __justReleased[str.ID]);
str.updatePlayerInput(str.__getPressed(this), str.__getJustPressed(this), str.__getJustReleased(this));
});
PlayState.instance.scripts.call("onPostKeyShit");
PlayState.instance.scripts.call("onPostInputUpdate");
}
public inline function addHealth(health:Float)
@@ -239,13 +239,24 @@ class StrumLine extends FlxTypedGroup<Strum> {
add(createStrum(i));
}
public function createStrum(i:Int, spr:Int = -1) {
/**
* Creates a strum and returns the created strum (needs to be added manually).
* @param i Index of the strum
* @param animPrefix (Optional) Animation prefix (`left` = `arrowLEFT`, `left press`, `left confirm`).
*/
public function createStrum(i:Int, ?animPrefix:String) {
if (animPrefix == null)
animPrefix = switch(i % 4) {
case 0: "left";
case 1: "down";
case 2: "up";
case 3: "right";
case _: "up";
}
var babyArrow:Strum = new Strum((FlxG.width * strumOffset) + (Note.swagWidth * (i - 2)), PlayState.instance.strumLine.y);
babyArrow.ID = i;
if (spr < 0)
spr = i % 4;
var event = PlayState.instance.scripts.event("onStrumCreation", EventManager.get(StrumCreationEvent).recycle(babyArrow, PlayState.instance.strumLines.members.indexOf(this), i));
var event = PlayState.instance.scripts.event("onStrumCreation", EventManager.get(StrumCreationEvent).recycle(babyArrow, PlayState.instance.strumLines.members.indexOf(this), i, animPrefix));
if (!event.cancelled) {
babyArrow.frames = Paths.getFrames(event.sprite);
@@ -257,25 +268,9 @@ class StrumLine extends FlxTypedGroup<Strum> {
babyArrow.antialiasing = true;
babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7));
switch (spr)
{
case 0:
babyArrow.animation.addByPrefix('static', 'arrowLEFT');
babyArrow.animation.addByPrefix('pressed', 'left press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false);
case 1:
babyArrow.animation.addByPrefix('static', 'arrowDOWN');
babyArrow.animation.addByPrefix('pressed', 'down press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false);
case 2:
babyArrow.animation.addByPrefix('static', 'arrowUP');
babyArrow.animation.addByPrefix('pressed', 'up press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false);
case 3:
babyArrow.animation.addByPrefix('static', 'arrowRIGHT');
babyArrow.animation.addByPrefix('pressed', 'right press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false);
}
babyArrow.animation.addByPrefix('static', 'arrow${event.animPrefix.toUpperCase()}');
babyArrow.animation.addByPrefix('pressed', '${event.animPrefix} press', 24, false);
babyArrow.animation.addByPrefix('confirm', '${event.animPrefix} confirm', 24, false);
}
babyArrow.cpu = cpu;
@@ -289,6 +284,8 @@ class StrumLine extends FlxTypedGroup<Strum> {
FlxTween.tween(babyArrow, {y: babyArrow.y + 10, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * i)});
}
babyArrow.playAnim('static');
insert(i, babyArrow);
return babyArrow;
}