Funkin/source/StrumNote.hx

191 lines
5.1 KiB
Haxe

package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.animation.FlxAnimationController;
import flixel.graphics.frames.FlxAtlasFrames;
import shaderslmfao.ColorSwap;
import Note;
using StringTools;
class StrumNote extends FlxSprite
{
private var colorSwap:ColorSwap;
public var resetAnim:Float = 0;
public var noteData:Int = 0;
public var direction:Float = 90;//plan on doing scroll directions soon -bb
public var downScroll:Bool = false;//plan on doing scroll directions soon -bb
public var sustainReduce:Bool = true;
private var player:Int;
public var texture(default, set):String = null;
private function set_texture(value:String):String {
if(texture != value) {
texture = value;
reloadNote();
}
return value;
}
public function new(x:Float, y:Float, leData:Int, player:Int) {
x += Note.swagWidth * leData;
colorSwap = new ColorSwap();
shader = colorSwap.shader;
noteData = leData;
this.player = player;
this.noteData = leData;
super(x, y);
var skin:String = 'NOTE_assets';
//if(PlayState.SONG.arrowSkin != null && PlayState.SONG.arrowSkin.length > 1) skin = PlayState.SONG.arrowSkin;
texture = skin; //Load texture and anims
scrollFactor.set();
}
public function reloadNote()
{
var lastAnim:String = null;
if(animation.curAnim != null) lastAnim = animation.curAnim.name;
if (PlayState.curStage.startsWith('school'))
{
loadGraphic(Paths.image('pixelUI/' + texture));
width = width / 4;
height = height / 5;
loadGraphic(Paths.image('pixelUI/' + texture), true, Math.floor(width), Math.floor(height));
antialiasing = false;
setGraphicSize(Std.int(width * PlayState.daPixelZoom));
animation.add('green', [6]);
animation.add('red', [7]);
animation.add('blue', [5]);
animation.add('purplel', [4]);
switch (Math.abs(noteData) % 4)
{
case 0:
animation.add('static', [0]);
animation.add('pressed', [4, 8], 12, false);
animation.add('confirm', [12, 16], 24, false);
case 1:
animation.add('static', [1]);
animation.add('pressed', [5, 9], 12, false);
animation.add('confirm', [13, 17], 24, false);
case 2:
animation.add('static', [2]);
animation.add('pressed', [6, 10], 12, false);
animation.add('confirm', [14, 18], 12, false);
case 3:
animation.add('static', [3]);
animation.add('pressed', [7, 11], 12, false);
animation.add('confirm', [15, 19], 24, false);
}
}
else
{
frames = Paths.getSparrowAtlas(texture);
animation.addByPrefix('green', 'arrowUP');
animation.addByPrefix('blue', 'arrowDOWN');
animation.addByPrefix('purple', 'arrowLEFT');
animation.addByPrefix('red', 'arrowRIGHT');
antialiasing = true;
setGraphicSize(Std.int(width * 0.7));
switch (Math.abs(noteData) % 4)
{
case 0:
animation.addByPrefix('static', 'arrow static instance 1');
animation.addByPrefix('pressed', 'left press', 24, false);
animation.addByPrefix('confirm', 'left confirm', 24, false);
case 1:
animation.addByPrefix('static', 'arrow static instance 2');
animation.addByPrefix('pressed', 'down press', 24, false);
animation.addByPrefix('confirm', 'down confirm', 24, false);
case 2:
animation.addByPrefix('static', 'arrow static instance 4');
animation.addByPrefix('pressed', 'up press', 24, false);
animation.addByPrefix('confirm', 'up confirm', 24, false);
case 3:
animation.addByPrefix('static', 'arrow static instance 3');
animation.addByPrefix('pressed', 'right press', 24, false);
animation.addByPrefix('confirm', 'right confirm', 24, false);
}
}
updateHitbox();
if(lastAnim != null)
{
playAnim(lastAnim, true);
}
}
public function postAddedToGroup() {
playAnim('static');
x += Note.swagWidth * noteData;
x += 50;
x += ((FlxG.width / 2) * player);
ID = noteData;
}
override function update(elapsed:Float) {
if(resetAnim > 0) {
resetAnim -= elapsed;
if(resetAnim <= 0) {
playAnim('static');
resetAnim = 0;
centerOffsets();
}
}
//if(animation.curAnim != null){ //my bad i was upset
if(animation.curAnim.name == 'confirm' && !PlayState.curStage.startsWith('school')) {
centerOffsets();
offset.x -= 13;
offset.y -= 13;
//}
}
super.update(elapsed);
}
function getAnimName(spr:FlxAnimationController):String
{
if (spr == null)
return "";
if (spr.curAnim == null)
return "";
return spr.curAnim.name;
}
public function playAnim(anim:String, ?force:Bool = false) {
animation.play(anim, force);
centerOffsets();
centerOrigin();
if(animation.curAnim == null || animation.curAnim.name == 'static') {
/*
colorSwap.hue = 0;
colorSwap.saturation = 0;
colorSwap.brightness = 0;
*/
} else {
/*
if (noteData > -1 && noteData < ClientPrefs.arrowHSV.length)
{
colorSwap.hue = ClientPrefs.arrowHSV[noteData][0] / 360;
colorSwap.saturation = ClientPrefs.arrowHSV[noteData][1] / 100;
colorSwap.brightness = ClientPrefs.arrowHSV[noteData][2] / 100;
}
*/
if(animation.curAnim.name == 'confirm' && !PlayState.curStage.startsWith('school')) {
centerOrigin();
centerOffsets();
offset.x -= 13;
offset.y -= 13;
}
}
}
}