1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-09-20 01:00:53 +00:00
Funkin/source/animate/FlxAnimate.hx

210 lines
5.1 KiB
Haxe
Raw Normal View History

package animate;
2021-04-14 15:31:52 +00:00
// import animateAtlasPlayer.assets.AssetManager;
// import animateAtlasPlayer.core.Animation;
2021-09-01 19:34:20 +00:00
import animate.ParseAnimate.AnimJson;
import animate.ParseAnimate.Sprite;
import animate.ParseAnimate.Spritemap;
import flixel.FlxCamera;
import flixel.FlxSprite;
import flixel.graphics.FlxGraphic;
import flixel.graphics.frames.FlxAtlasFrames;
2021-09-01 19:34:20 +00:00
import flixel.graphics.frames.FlxFrame.FlxFrameAngle;
import flixel.math.FlxMatrix;
import flixel.math.FlxPoint;
import flixel.math.FlxRect;
import flixel.system.FlxAssets.FlxGraphicAsset;
2021-08-29 19:56:46 +00:00
import haxe.format.JsonParser;
import openfl.Assets;
import openfl.display.BitmapData;
import openfl.geom.Rectangle;
2021-04-14 15:31:52 +00:00
class FlxAnimate extends FlxSymbol
{
2021-04-14 15:31:52 +00:00
// var myAnim:Animation;
// var animBitmap:BitmapData;
var loadedQueue:Bool = false;
var swagFrames:Array<BitmapData> = [];
2021-09-01 19:34:20 +00:00
var jsonAnim:AnimJson;
public function new(x:Float, y:Float)
{
2021-09-01 19:34:20 +00:00
super(x, y);
var folder:String = "tightBarsLol";
frames = FlxAnimate.fromAnimate(Paths.file('images/' + folder + "/spritemap1.png"), Paths.file('images/$folder/spritemap1.json'));
jsonAnim = cast CoolUtil.coolJSON(Assets.getText(Paths.file('images/$folder/Animation.json')));
ParseAnimate.generateSymbolmap(jsonAnim.SD.S);
ParseAnimate.parseTimeline(jsonAnim.AN.TL, 0, 0);
/* var folder:String = 'tightestBars';
coolParse = cast Json.parse(Assets.getText(Paths.file('images/' + folder + '/Animation.json')));
2021-08-19 18:53:18 +00:00
2021-09-01 19:34:20 +00:00
// reverses the layers, for proper rendering!
coolParse.AN.TL.L.reverse();
super(x, y, coolParse);
frames = FlxAnimate.fromAnimate(Paths.file('images/' + folder + '/spritemap1.png'), Paths.file('images/' + folder + '/spritemap1.json'));
*/
2021-04-14 15:31:52 +00:00
// frames
}
override function draw()
{
2021-08-29 19:56:46 +00:00
// having this commented out fixes some wacky scaling bullshit?
// super.draw();
2021-09-01 19:34:20 +00:00
// renderFrame(coolParse.AN.TL, coolParse, true);
2021-06-16 01:15:06 +00:00
2021-09-01 19:34:20 +00:00
actualFrameRender();
}
2021-04-15 15:57:59 +00:00
2021-09-01 19:34:20 +00:00
function actualFrameRender()
{
for (i in ParseAnimate.frameList)
2021-04-15 15:57:59 +00:00
{
2021-09-01 19:34:20 +00:00
var spr:FlxSymbol = new FlxSymbol(0, 0); // redo this to recycle from a list later
spr.frames = frames;
spr.frame = spr.frames.getByName(i);
if (FlxG.keys.justPressed.I)
{
trace('\n\n\nSPR OLD: ' + spr._matrix);
}
ParseAnimate.matrixMap.get(i).reverse();
for (swagMatrix in ParseAnimate.matrixMap.get(i))
2021-04-15 15:57:59 +00:00
{
2021-09-01 19:34:20 +00:00
var alsoSwag:FlxMatrix = new FlxMatrix(swagMatrix[0], swagMatrix[1], swagMatrix[4], swagMatrix[5], swagMatrix[12], swagMatrix[13]);
spr.matrixExposed = true;
spr.transformMatrix.concat(alsoSwag);
if (FlxG.keys.justPressed.I)
2021-04-15 15:57:59 +00:00
{
2021-09-01 19:34:20 +00:00
trace(i + ": " + swagMatrix);
2021-04-15 15:57:59 +00:00
}
}
2021-09-01 19:34:20 +00:00
if (FlxG.keys.justPressed.I)
{
trace('SPR NEW: ' + spr._matrix);
}
// trace('MATRIX ' + spr._matrix);
// spr
spr.draw();
2021-04-15 15:57:59 +00:00
}
2021-04-14 15:31:52 +00:00
}
2021-04-14 15:31:52 +00:00
// notes to self
// account for different layers
2021-04-15 01:52:43 +00:00
var playingAnim:Bool = false;
var frameTickTypeShit:Float = 0;
var animFrameRate:Int = 24;
2021-04-14 15:31:52 +00:00
2021-09-01 19:34:20 +00:00
// redo all the matrix animation stuff
2021-04-14 15:31:52 +00:00
override function update(elapsed:Float)
{
super.update(elapsed);
2021-04-15 01:52:43 +00:00
if (FlxG.keys.justPressed.SPACE)
playingAnim = !playingAnim;
if (playingAnim)
{
frameTickTypeShit += elapsed;
// prob fix this framerate thing for higher framerates?
if (frameTickTypeShit >= 1 / 24)
{
changeFrame(1);
frameTickTypeShit = 0;
2021-09-01 19:34:20 +00:00
ParseAnimate.resetFrameList();
ParseAnimate.parseTimeline(jsonAnim.AN.TL, 0, daFrame);
2021-04-15 01:52:43 +00:00
}
}
if (FlxG.keys.justPressed.RIGHT)
2021-09-01 19:34:20 +00:00
{
2021-04-15 01:52:43 +00:00
changeFrame(1);
2021-09-01 19:34:20 +00:00
ParseAnimate.resetFrameList();
ParseAnimate.parseTimeline(jsonAnim.AN.TL, 0, daFrame);
}
2021-04-15 01:52:43 +00:00
if (FlxG.keys.justPressed.LEFT)
changeFrame(-1);
}
public static function fromAnimate(Source:FlxGraphicAsset, Description:String):FlxAtlasFrames
{
var graphic:FlxGraphic = FlxG.bitmap.add(Source);
if (graphic == null)
return null;
var frames:FlxAtlasFrames = FlxAtlasFrames.findFrame(graphic);
if (frames != null)
return frames;
if (graphic == null || Description == null)
return null;
frames = new FlxAtlasFrames(graphic);
2021-09-01 19:34:20 +00:00
var data:Spritemap;
var json:String = Description;
2021-09-01 19:34:20 +00:00
// trace(json);
2021-08-29 19:56:46 +00:00
var funnyJson:Dynamic = {};
if (Assets.exists(json))
2021-08-29 19:56:46 +00:00
funnyJson = JaySon.parseFile(json);
2021-08-29 19:56:46 +00:00
// trace(json);
2021-09-01 19:34:20 +00:00
// data = c
data = cast funnyJson;
2021-09-01 19:34:20 +00:00
for (sprite in data.ATLAS.SPRITES)
{
// probably nicer way to do this? Oh well
2021-09-01 19:34:20 +00:00
var swagSprite:Sprite = sprite.SPRITE;
var rect = FlxRect.get(swagSprite.x, swagSprite.y, swagSprite.w, swagSprite.h);
var size = new Rectangle(0, 0, rect.width, rect.height);
var offset = FlxPoint.get(-size.left, -size.top);
var sourceSize = FlxPoint.get(size.width, size.height);
frames.addAtlasFrame(rect, sourceSize, offset, swagSprite.name);
}
return frames;
}
}
2021-08-29 19:56:46 +00:00
class JaySon
{
public static function parseFile(name:String)
{
var cont = Assets.getText(name);
function is(n:Int, what:Int)
return cont.charCodeAt(n) == what;
return JsonParser.parse(cont.substr(if (is(0, 65279)) /// looks like a HL target, skipping only first character here:
1 else if (is(0, 239) && is(1, 187) && is(2, 191)) /// it seems to be Neko or PHP, start from position 3:
3 else /// all other targets, that prepare the UTF string correctly
0));
}
}