moves = false & cool stuff
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package funkin.system;
|
||||
|
||||
import flixel.system.FlxAssets.FlxGraphicAsset;
|
||||
import flixel.addons.effects.FlxSkewedSprite;
|
||||
import haxe.io.Path;
|
||||
import funkin.scripting.events.PlayAnimEvent.PlayAnimContext;
|
||||
@@ -11,22 +12,26 @@ import funkin.interfaces.IBeatReceiver;
|
||||
import flixel.util.FlxDestroyUtil;
|
||||
|
||||
@:enum
|
||||
abstract XMLAnimType(Int) {
|
||||
abstract XMLAnimType(Int)
|
||||
{
|
||||
var NONE = 0;
|
||||
var BEAT = 1;
|
||||
var LOOP = 2;
|
||||
|
||||
public static function fromString(str:String, def:XMLAnimType = NONE) {
|
||||
return switch(str.trim().toLowerCase()) {
|
||||
case "none": NONE;
|
||||
case "beat" | "onbeat": BEAT;
|
||||
case "loop": LOOP;
|
||||
default: def;
|
||||
public static function fromString(str:String, def:XMLAnimType = NONE)
|
||||
{
|
||||
return switch (str.trim().toLowerCase())
|
||||
{
|
||||
case "none": NONE;
|
||||
case "beat" | "onbeat": BEAT;
|
||||
case "loop": LOOP;
|
||||
default: def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements IOffsetCompatible {
|
||||
class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements IOffsetCompatible
|
||||
{
|
||||
public var spriteAnimType:XMLAnimType = NONE;
|
||||
public var beatAnims:Array<String> = [];
|
||||
public var name:String;
|
||||
@@ -37,7 +42,23 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
@:noCompletion public var atlasPlayingAnim:String;
|
||||
@:noCompletion public var atlasPath:String;
|
||||
|
||||
public static function copyFrom(source:FunkinSprite) {
|
||||
public function new(?X:Float = 0, ?Y:Float = 0, ?SimpleGraphic:FlxGraphicAsset)
|
||||
{
|
||||
super(X, Y);
|
||||
|
||||
if (SimpleGraphic != null)
|
||||
{
|
||||
if (SimpleGraphic is String)
|
||||
loadSprite(cast SimpleGraphic);
|
||||
else
|
||||
loadGraphic(SimpleGraphic);
|
||||
}
|
||||
|
||||
moves = false;
|
||||
}
|
||||
|
||||
public static function copyFrom(source:FunkinSprite)
|
||||
{
|
||||
var spr = new FunkinSprite();
|
||||
@:privateAccess {
|
||||
spr.setPosition(source.x, source.y);
|
||||
@@ -53,49 +74,65 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
spr.skew.set(source.skew.x, source.skew.y);
|
||||
spr.transformMatrix = source.transformMatrix;
|
||||
spr.matrixExposed = source.matrixExposed;
|
||||
spr.animOffsets = source.animOffsets;
|
||||
spr.animOffsets = source.animOffsets.copy();
|
||||
}
|
||||
return spr;
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
public override function update(elapsed:Float)
|
||||
{
|
||||
super.update(elapsed);
|
||||
if (animateAtlas != null)
|
||||
animateAtlas.update(elapsed);
|
||||
}
|
||||
|
||||
public function loadSprite(path:String, Unique:Bool = false, Key:String = null) {
|
||||
public function loadSprite(path:String, Unique:Bool = false, Key:String = null)
|
||||
{
|
||||
var noExt = Path.withoutExtension(path);
|
||||
if (Assets.exists('$noExt/Animation.json')) {
|
||||
if (Assets.exists('$noExt/Animation.json'))
|
||||
{
|
||||
atlasPath = noExt;
|
||||
animateAtlas = new FlxAnimate(x, y, noExt);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
frames = CoolUtil.loadFrames(path, Unique, Key, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function beatHit(curBeat:Int) {
|
||||
if (beatAnims.length > 0) {
|
||||
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)];
|
||||
public function beatHit(curBeat:Int)
|
||||
{
|
||||
if (beatAnims.length > 0)
|
||||
{
|
||||
var anim = beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length - 1)];
|
||||
if (anim != null && anim != "null" && anim != "none")
|
||||
playAnim(anim);
|
||||
}
|
||||
}
|
||||
public function stepHit(curBeat:Int) {}
|
||||
public function measureHit(curMeasure:Int) {}
|
||||
|
||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect {
|
||||
public function stepHit(curBeat:Int)
|
||||
{
|
||||
}
|
||||
|
||||
public function measureHit(curMeasure:Int)
|
||||
{
|
||||
}
|
||||
|
||||
public override function getScreenBounds(?newRect:FlxRect, ?camera:FlxCamera):FlxRect
|
||||
{
|
||||
__doPreZoomScaleProcedure(camera);
|
||||
var r = super.getScreenBounds(newRect, camera);
|
||||
__doPostZoomScaleProcedure();
|
||||
return r;
|
||||
}
|
||||
public override function drawComplex(camera:FlxCamera) {
|
||||
|
||||
public override function drawComplex(camera:FlxCamera)
|
||||
{
|
||||
super.drawComplex(camera);
|
||||
}
|
||||
|
||||
public override function doAdditionalMatrixStuff(matrix:FlxMatrix, camera:FlxCamera) {
|
||||
public override function doAdditionalMatrixStuff(matrix:FlxMatrix, camera:FlxCamera)
|
||||
{
|
||||
super.doAdditionalMatrixStuff(matrix, camera);
|
||||
matrix.translate(-camera.width / 2, -camera.height / 2);
|
||||
|
||||
@@ -105,13 +142,15 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
matrix.translate(camera.width / 2, camera.height / 2);
|
||||
}
|
||||
|
||||
public override function getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint {
|
||||
if (__shouldDoScaleProcedure()) {
|
||||
public override function getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint
|
||||
{
|
||||
if (__shouldDoScaleProcedure())
|
||||
{
|
||||
__oldScale = FlxPoint.get(scrollFactor.x, scrollFactor.y);
|
||||
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom / camera.zoom;
|
||||
|
||||
scrollFactor.scale(1/diff);
|
||||
scrollFactor.scale(1 / diff);
|
||||
|
||||
var r = super.getScreenPosition(point, Camera);
|
||||
|
||||
@@ -126,16 +165,21 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
|
||||
// ANIMATE ATLAS DRAWING
|
||||
#if REGION
|
||||
public override function draw() {
|
||||
if (animateAtlas != null) {
|
||||
public override function draw()
|
||||
{
|
||||
if (animateAtlas != null)
|
||||
{
|
||||
copyAtlasValues();
|
||||
animateAtlas.draw();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
super.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public function copyAtlasValues() {
|
||||
public function copyAtlasValues()
|
||||
{
|
||||
@:privateAccess {
|
||||
animateAtlas.cameras = cameras;
|
||||
animateAtlas.scrollFactor = scrollFactor;
|
||||
@@ -157,7 +201,8 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
}
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
public override function destroy()
|
||||
{
|
||||
animateAtlas = FlxDestroyUtil.destroy(animateAtlas);
|
||||
super.destroy();
|
||||
}
|
||||
@@ -171,8 +216,10 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
var __oldScale:FlxPoint;
|
||||
var __skipZoomProcedure:Bool = false;
|
||||
|
||||
private function __doPreZoomScaleProcedure(camera:FlxCamera) {
|
||||
if (__skipZoomProcedure = !__shouldDoScaleProcedure()) return;
|
||||
private function __doPreZoomScaleProcedure(camera:FlxCamera)
|
||||
{
|
||||
if (__skipZoomProcedure = !__shouldDoScaleProcedure())
|
||||
return;
|
||||
__oldScale = FlxPoint.get(scale.x, scale.y);
|
||||
var requestedZoom = FlxMath.lerp(initialZoom, camera.zoom, zoomFactor);
|
||||
var diff = requestedZoom / camera.zoom;
|
||||
@@ -180,8 +227,10 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
scale.scale(diff);
|
||||
}
|
||||
|
||||
private function __doPostZoomScaleProcedure() {
|
||||
if (__skipZoomProcedure) return;
|
||||
private function __doPostZoomScaleProcedure()
|
||||
{
|
||||
if (__skipZoomProcedure)
|
||||
return;
|
||||
scale.set(__oldScale.x, __oldScale.y);
|
||||
__oldScale.put();
|
||||
__oldScale = null;
|
||||
@@ -191,12 +240,14 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
// OFFSETTING
|
||||
#if REGION
|
||||
public var animOffsets:Map<String, FlxPoint> = new Map<String, FlxPoint>();
|
||||
|
||||
public function addOffset(name:String, x:Float = 0, y:Float = 0)
|
||||
{
|
||||
animOffsets[name] = new FlxPoint(x, y);
|
||||
}
|
||||
|
||||
public function switchOffset(anim1:String, anim2:String) {
|
||||
public function switchOffset(anim1:String, anim2:String)
|
||||
{
|
||||
var old = animOffsets[anim1];
|
||||
animOffsets[anim1] = animOffsets[anim2];
|
||||
animOffsets[anim2] = old;
|
||||
@@ -206,18 +257,23 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
// PLAYANIM
|
||||
#if REGION
|
||||
public var lastAnimContext:PlayAnimContext = DANCE;
|
||||
|
||||
public function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void
|
||||
{
|
||||
if (AnimName == null) return;
|
||||
if (AnimName == null)
|
||||
return;
|
||||
|
||||
if (animateAtlas != null) {
|
||||
if (animateAtlas != null)
|
||||
{
|
||||
@:privateAccess
|
||||
//if (!animateAtlas.anim.animsMap.exists(AnimName) && !animateAtlas.anim.symbolDictionary.exists(AnimName)) return;
|
||||
// if (!animateAtlas.anim.animsMap.exists(AnimName) && !animateAtlas.anim.symbolDictionary.exists(AnimName)) return;
|
||||
animateAtlas.anim.play(AnimName, Force, Reversed, Frame);
|
||||
atlasPlayingAnim = AnimName;
|
||||
}
|
||||
else {
|
||||
if (!animation.exists(AnimName)) return;
|
||||
else
|
||||
{
|
||||
if (!animation.exists(AnimName))
|
||||
return;
|
||||
animation.play(AnimName, Force, Reversed, Frame);
|
||||
}
|
||||
|
||||
@@ -228,31 +284,35 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
|
||||
lastAnimContext = Context;
|
||||
}
|
||||
|
||||
public inline function getAnimOffset(name:String) {
|
||||
public inline function getAnimOffset(name:String)
|
||||
{
|
||||
if (animOffsets[name] != null)
|
||||
return animOffsets[name];
|
||||
return FlxPoint.weak(0, 0);
|
||||
}
|
||||
|
||||
public inline function hasAnimation(AnimName:String):Bool
|
||||
@:privateAccess
|
||||
return animateAtlas != null
|
||||
? (animateAtlas.anim.animsMap.exists(AnimName) || animateAtlas.anim.symbolDictionary.exists(AnimName))
|
||||
: animation.getByName(AnimName) != null;
|
||||
public inline function hasAnimation(AnimName:String):Bool @:privateAccess
|
||||
return animateAtlas != null ? (animateAtlas.anim.animsMap.exists(AnimName)
|
||||
|| animateAtlas.anim.symbolDictionary.exists(AnimName)) : animation.getByName(AnimName) != null;
|
||||
|
||||
public inline function getAnimName() {
|
||||
public inline function getAnimName()
|
||||
{
|
||||
var name = null;
|
||||
if (animateAtlas != null) {
|
||||
if (animateAtlas != null)
|
||||
{
|
||||
name = atlasPlayingAnim;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (animation.curAnim != null)
|
||||
name = animation.curAnim.name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public inline function isAnimFinished() {
|
||||
public inline function isAnimFinished()
|
||||
{
|
||||
return animateAtlas != null ? (animateAtlas.anim.finished) : (animation.curAnim != null ? animation.curAnim.finished : true);
|
||||
}
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user