Skip to content

Commit

Permalink
improve performance of note splashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Nov 4, 2024
1 parent 0e0625f commit d4c7080
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 74 deletions.
29 changes: 16 additions & 13 deletions source/game/NoteSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class NoteSplash extends FlxSprite {
public var affectedbycolor:Bool = false;
public var jsonData:JsonData;

public function setup_splash(noteData:Int, target:FlxSprite, ?isPlayer:Bool = false, ?ui_Skin:String) {
this.target = target;
public function new(?X:Float = 0, ?Y:Float = 0){
super(X, Y);

var localKeyCount = isPlayer ? PlayState.SONG.playerKeyCount : PlayState.SONG.keyCount;
colorSwap = new ColorSwap();

alpha = 0.8;

Expand All @@ -32,6 +32,19 @@ class NoteSplash extends FlxSprite {
frames = Paths.getSparrowAtlas("ui skins/default/arrows/Note_Splashes");
}

if(Assets.exists(Paths.json("ui skins/" + PlayState.SONG.ui_Skin + "/config"))){
jsonData = Json.parse(Assets.getText(Paths.json("ui skins/" + PlayState.SONG.ui_Skin + "/config")));
for (value in jsonData.values) {
this.affectedbycolor = value.affectedbycolor;
}
}
}

public function setup_splash(noteData:Int, target:FlxSprite, ?isPlayer:Bool = false) {

var localKeyCount:Int = isPlayer ? PlayState.SONG.playerKeyCount : PlayState.SONG.keyCount;

this.target = target;
graphic.destroyOnNoUse = false;

animation.addByPrefix("default", "note splash " + NoteVariables.Other_Note_Anim_Stuff[localKeyCount - 1][noteData] + "0", FlxG.random.int(22, 26),
Expand All @@ -45,17 +58,7 @@ class NoteSplash extends FlxSprite {
updateHitbox();
centerOffsets();

if (ui_Skin == null)
ui_Skin = PlayState.SONG.ui_Skin;

if(Assets.exists(Paths.json("ui skins/" + ui_Skin + "/config"))){
jsonData = Json.parse(Assets.getText(Paths.json("ui skins/" + ui_Skin + "/config")));
for (value in jsonData.values) {
this.affectedbycolor = value.affectedbycolor;
}
}

colorSwap = new ColorSwap();
shader = affectedbycolor ? colorSwap.shader : null;

noteColor = NoteColors.getNoteColor(NoteVariables.Other_Note_Anim_Stuff[PlayState.SONG.keyCount - 1][noteData]);
Expand Down
102 changes: 43 additions & 59 deletions source/game/SpraycanAtlasSprite.hx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//fuck you hscript
// fuck you hscript
package game;

import states.PlayState;
Expand All @@ -7,73 +7,57 @@ import flixel.math.FlxPoint;
import game.FlxAtlasSprite;

class SpraycanAtlasSprite extends FlxAtlasSprite {
public var STATE_ARCING:Int = 2; // In the air.
public var STATE_ARCING:Int = 2; // In the air.
public var STATE_SHOT:Int = 3; // Hit by the player.
public var STATE_IMPACTED:Int = 4; // Impacted the player.

public var currentState:Int = 2;

override public function new(x:Float, y:Float)
{
super(x, y, Paths.getTextureAtlas('streets/spraycanAtlas', 'stages'), {
FrameRate: 24.0,
Reversed: false,
// ?OnComplete:Void -> Void,
ShowPivot: false,
Antialiasing: Options.getData("antialiasing"),
ScrollFactor: new FlxPoint(1, 1),
});

trace('Spawned Atlas Spraycan!');
trace('Got frames: ' + this.anim.length);
trace('Got animations: ' + listAnimations());

onAnimationFinish.add(finishCanAnimation);
}

public function finishCanAnimation(name:String) {
switch(name) {
case 'Can Start':
trace('Can Start finished');
playHitPico();
case 'Can Shot':
trace('Can Shot finished');
this.kill();
case 'Hit Pico':
trace('Hit Pico finished');
playHitExplosion();
this.kill();
}
}

public function playHitExplosion():Void {
var explodeEZ:FlxSprite = new FlxSprite(this.x + 1050, this.y + 150);
explodeEZ.frames = Paths.getSparrowAtlas('streets/spraypaintExplosionEZ', 'stages');
public var currentState:Int = 2;

override public function new(x:Float, y:Float) {
super(x, y, Paths.getTextureAtlas('streets/spraycanAtlas', 'stages'), {
FrameRate: 24.0,
Reversed: false,
// ?OnComplete:Void -> Void,
ShowPivot: false,
Antialiasing: Options.getData("antialiasing"),
ScrollFactor: new FlxPoint(1, 1),
});
onAnimationFinish.add(finishCanAnimation);
}

public function finishCanAnimation(name:String) {
switch (name) {
case 'Can Start':
playHitPico();
case 'Can Shot':
this.kill();
case 'Hit Pico':
playHitExplosion();
this.kill();
}
}

public function playHitExplosion():Void {
var explodeEZ:FlxSprite = new FlxSprite(this.x + 1050, this.y + 150);
explodeEZ.frames = Paths.getSparrowAtlas('streets/spraypaintExplosionEZ', 'stages');
explodeEZ.animation.addByPrefix("idle", "explosion round 1 short0", 24, false);
explodeEZ.animation.play("idle");

PlayState.instance.stage.add(explodeEZ);
explodeEZ.animation.finishCallback = (name:String) -> {
trace('killing explodeEZ');
explodeEZ.kill();
};
}

public function playCanStart():Void {
trace('Atlas Spraycan playCanStart');

this.playAnimation('Can Start');
}

public function playCanShot():Void {
trace('Atlas Spraycan playCanShot');
explodeEZ.kill();
};
}

this.playAnimation('Can Shot');
}
public function playCanStart():Void {
this.playAnimation('Can Start');
}

public function playHitPico():Void {
trace('Atlas Spraycan playHitPico');
public function playCanShot():Void {
this.playAnimation('Can Shot');
}

this.playAnimation('Hit Pico');
}
public function playHitPico():Void {
this.playAnimation('Hit Pico');
}
}
4 changes: 2 additions & 2 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ class PlayState extends MusicBeatState {
}

if (!note.isSustainNote && opponentNoteSplashes) {
var splash = splash_group.recycle(NoteSplash);
var splash:NoteSplash = splash_group.recycle(NoteSplash);
splash.setup_splash(spr.ID, spr, false);
if (note.colorSwap != null) {
splash.colorSwap.r = note.colorSwap.r;
Expand Down Expand Up @@ -2857,7 +2857,7 @@ class PlayState extends MusicBeatState {
if ((daRating == "sick" || daRating == "marvelous") && playerNoteSplashes) {
playerStrums.forEachAlive(function(spr:StrumNote) {
if (spr.ID == Math.abs(noteData)) {
var splash = splash_group.recycle(NoteSplash);
var splash:NoteSplash = splash_group.recycle(NoteSplash);
splash.setup_splash(noteData, spr, true);
if (spr.colorSwap != null) {
splash.colorSwap.r = spr.colorSwap.r;
Expand Down

0 comments on commit d4c7080

Please sign in to comment.