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