2021-03-30 01:00:30 +00:00
|
|
|
package animate;
|
|
|
|
|
|
|
|
import flixel.FlxG;
|
2021-03-30 01:06:35 +00:00
|
|
|
import flixel.addons.ui.FlxUIColorSwatchSelecter.SwatchGraphic;
|
2021-03-30 01:00:30 +00:00
|
|
|
import flixel.graphics.FlxGraphic;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-03-30 01:06:35 +00:00
|
|
|
import flixel.math.FlxPoint;
|
|
|
|
import flixel.math.FlxRect;
|
2021-03-30 01:00:30 +00:00
|
|
|
import flixel.system.FlxAssets.FlxGraphicAsset;
|
|
|
|
import haxe.Json;
|
|
|
|
import openfl.Assets;
|
2021-03-30 01:06:35 +00:00
|
|
|
import openfl.geom.Rectangle;
|
2021-03-30 01:00:30 +00:00
|
|
|
|
|
|
|
class AnimationAtlas
|
|
|
|
{
|
|
|
|
public function new(data:Dynamic, atlas:FlxAtlasFrames):Void {}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
var data:AnimateObject;
|
|
|
|
|
|
|
|
var json:String = Description;
|
|
|
|
|
|
|
|
trace(json);
|
|
|
|
|
|
|
|
if (Assets.exists(json))
|
|
|
|
json = Assets.getText(json);
|
|
|
|
|
|
|
|
trace(json);
|
|
|
|
|
|
|
|
data = cast Json.parse(json).ATLAS;
|
|
|
|
|
|
|
|
for (sprite in data.SPRITES)
|
|
|
|
{
|
|
|
|
// probably nicer way to do this? Oh well
|
|
|
|
var swagSprite:AnimateSprite = sprite.SPRITE;
|
|
|
|
|
2021-03-30 01:06:35 +00:00
|
|
|
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);
|
2021-03-30 01:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef AnimateObject =
|
|
|
|
{
|
|
|
|
SPRITES:Array<Dynamic>
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef AnimateSprite =
|
|
|
|
{
|
|
|
|
var name:String;
|
|
|
|
var x:Int;
|
|
|
|
var y:Int;
|
|
|
|
var w:Int;
|
|
|
|
var h:Int;
|
|
|
|
var rotated:Bool;
|
|
|
|
}
|