1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-08-31 19:04:55 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
Abnormal a882308785
Merge f7daadb5c5 into 54ad34e5d0 2025-08-30 04:30:13 +00:00
Abnormal f7daadb5c5 how did this get through 2025-08-29 23:30:02 -05:00
Abnormal b61bd255c1 added legacyBoundsPosition
this option will offset the atlas such that it's positioned exactly like how it was in flxanimate. this exists as a sort of backwards-compatability layer for mods to use!
2025-08-29 22:44:11 -05:00
6 changed files with 88 additions and 16 deletions

View file

@ -103,6 +103,10 @@ class PlayerFreeplayDJData
var assetPath:String;
var animations:Array<AnimationData>;
@:optional
@:default(false)
var legacyBoundsPosition:Bool;
@:optional
@:default("BOYFRIEND")
var text1:String;
@ -154,6 +158,11 @@ class PlayerFreeplayDJData
return assetPath;
}
public function useLegacyBoundsPosition():Bool
{
return legacyBoundsPosition;
}
public function getFreeplayDJText(index:Int):String
{
switch (index)
@ -334,6 +343,10 @@ typedef PlayerResultsAnimationData =
*/
var renderType:String;
@:optional
@:default(false)
var legacyBoundsPosition:Bool;
@:optional
var assetPath:Null<String>;

View file

@ -86,6 +86,12 @@ typedef AtlasSpriteSettings =
*/
@:optional
var applyStageMatrix:Bool;
/**
* Whether to use legacy bounds positioning.
*/
@:optional
var legacyBoundsPosition:Bool;
}
/**
@ -96,6 +102,25 @@ typedef AtlasSpriteSettings =
@:nullSafety
class FunkinSprite extends FlxAnimate
{
/**
* NOTE: This will only work on texture atlases.
*
* If enabled, the sprite will be offset using the bounds origin.
* This imitates the behavior of the legacy bounds FlxAnimate had.
* Turning this on is not recommended, only use this if you know what you're doing.
* It's also worth noting that not all atlases will react correctly, some may need position tweaks.
*/
public var legacyBoundsPosition(default, set):Bool = false;
public function set_legacyBoundsPosition(value:Bool):Bool
{
if (!this.isAnimate) return false;
this.legacyBoundsPosition = value;
this.applyStageMatrix = value;
return value;
}
/**
* @param x Starting X position
* @param y Starting Y position
@ -108,7 +133,7 @@ class FunkinSprite extends FlxAnimate
override function initVars():Void
{
super.initVars();
// TODO: Make `animation` a stub that redirects calls to `mainSprite`?
var newController:FunkinAnimationController = new FunkinAnimationController(this);
animation = newController;
@ -282,7 +307,8 @@ class FunkinSprite extends FlxAnimate
cacheKey: settings?.cacheKey ?? null,
uniqueInCache: settings?.uniqueInCache ?? false,
onSymbolCreate: settings?.onSymbolCreate ?? null,
applyStageMatrix: settings?.applyStageMatrix ?? false
legacyBoundsPosition: settings?.legacyBoundsPosition ?? false,
applyStageMatrix: (settings?.applyStageMatrix ?? false || settings?.legacyBoundsPosition ?? false)
};
var assetLibrary:String = assetLibrary ?? "";
@ -304,6 +330,7 @@ class FunkinSprite extends FlxAnimate
}
this.applyStageMatrix = validatedSettings.applyStageMatrix ?? false;
this.legacyBoundsPosition = validatedSettings.legacyBoundsPosition ?? false;
frames = FlxAnimateFrames.fromAnimate(funkin.Assets.getPath(graphicKey), validatedSettings.spritemaps, validatedSettings.metadataJson,
validatedSettings.cacheKey, validatedSettings.uniqueInCache, {
@ -616,6 +643,12 @@ class FunkinSprite extends FlxAnimate
_rect.height = _rect.height * this.scale.y;
}
if (legacyBoundsPosition && this.isAnimate)
{
result.x += this.timeline.getBoundsOrigin().x;
result.y += this.timeline.getBoundsOrigin().y;
}
return result.subtract(camera.scroll.x * scrollFactor.x, camera.scroll.y * scrollFactor.y);
}

View file

@ -231,6 +231,11 @@ class ResultState extends MusicBeatSubState
if (animation == null) continue;
if (animData?.legacyBoundsPosition ?? false)
{
animation.legacyBoundsPosition = true;
}
animation.zIndex = animData.zIndex ?? 500;
animation.scale.set(animData.scale ?? 1.0, animData.scale ?? 1.0);

View file

@ -108,7 +108,10 @@ class CharSelectGF extends FunkinSprite implements IBPMSyncedScriptedClass
else if (previousGFPath != currentGFPath)
{
this.visible = true;
frames = CharSelectAtlasHandler.loadAtlas(currentGFPath);
frames = CharSelectAtlasHandler.loadAtlas(currentGFPath,
{
swfMode: true
});
enableVisualizer = gfData?.visualizer ?? false;
}

View file

@ -20,7 +20,8 @@ class CharSelectPlayer extends FunkinSprite implements IBPMSyncedScriptedClass
loadTextureAtlas("charSelect/bfChill",
{
applyStageMatrix: true
applyStageMatrix: true,
swfMode: true
});
anim.onFinish.add(function(animLabel:String) {

View file

@ -52,6 +52,11 @@ class FreeplayDJ extends FunkinSprite
filterQuality: HIGH
});
if (playableCharData?.useLegacyBoundsPosition() ?? false)
{
this.legacyBoundsPosition = true;
}
anim.onFrameChange.add(function(name, number, index) {
if (name == playableCharData?.getAnimationPrefix('cartoon'))
{
@ -462,25 +467,37 @@ class FreeplayDJ extends FunkinSprite
{
this.anim.play(id, Force, Reverse, Frame);
this.anim.curAnim.looped = Loop;
applyAnimOffset();
applyAnimationOffset();
}
function applyAnimOffset()
function applyAnimationOffset():Void
{
var AnimName = getCurrentAnimation();
var daOffset = playableCharData?.getAnimationOffsetsByPrefix(AnimName);
var daGlobalOffset = [this.x, this.y];
if (daOffset != null)
{
var xValue = daGlobalOffset[0] - daOffset[0] - (FreeplayState.CUTOUT_WIDTH * FreeplayState.DJ_POS_MULTI);
var yValue = daGlobalOffset[1] - daOffset[1];
var animationName:String = getCurrentAnimation();
var animationOffsets:Null<Array<Float>> = playableCharData?.getAnimationOffsetsByPrefix(animationName);
var globalOffsets:Array<Float> = [this.x, this.y];
trace('Successfully applied offset ($AnimName): ' + daOffset[0] + ', ' + daOffset[1]);
offset.set(xValue, yValue);
if (animationOffsets != null)
{
var finalOffsetX:Float = 0;
var finalOffsetY:Float = 0;
if (this.legacyBoundsPosition)
{
finalOffsetX = animationOffsets[0];
finalOffsetY = animationOffsets[1];
}
else
{
finalOffsetX = globalOffsets[0] - animationOffsets[0] - (FreeplayState.CUTOUT_WIDTH * FreeplayState.DJ_POS_MULTI);
finalOffsetY = globalOffsets[1] - animationOffsets[1];
}
trace('Successfully applied offset ($animationName): ' + animationOffsets[0] + ', ' + animationOffsets[1]);
offset.set(finalOffsetX, finalOffsetY);
}
else
{
trace('No offset found ($AnimName), defaulting to: 0, 0');
trace('No offset found ($animationName), defaulting to: 0, 0');
offset.set(0, 0);
}
}