[haxe] Removed lime dependency from Skeleton.hx

This commit is contained in:
Davide Tantillo 2025-07-29 18:05:18 +02:00
parent 108f9bf355
commit 6927995767
3 changed files with 30 additions and 25 deletions

View File

@ -29,12 +29,10 @@
package spine;
import lime.math.Rectangle;
import haxe.ds.StringMap;
import spine.Rectangle;
import spine.attachments.Attachment;
import spine.attachments.ClippingAttachment;
import spine.attachments.MeshAttachment;
import spine.attachments.PathAttachment;
import spine.attachments.RegionAttachment;
/** Stores the current pose for a skeleton.

View File

@ -51,6 +51,7 @@ import flixel.util.FlxColor;
import openfl.Vector;
import openfl.display.BlendMode;
import spine.Bone;
import spine.Rectangle;
import spine.Skeleton;
import spine.SkeletonData;
import spine.Slot;
@ -114,7 +115,7 @@ class SkeletonSprite extends FlxObject {
}
}
public function getAnimationBounds(animation:Animation, clip:Bool = true):lime.math.Rectangle {
public function getAnimationBounds(animation:Animation, clip:Bool = true):Rectangle {
var clipper = clip ? SkeletonSprite.clipper : null;
skeleton.setupPose();
@ -125,22 +126,23 @@ class SkeletonSprite extends FlxObject {
minY = 100000000.,
maxY = -100000000.;
var bounds = new lime.math.Rectangle();
for (i in 0...steps) {
animation.apply(skeleton, time, time, false, [], 1, MixBlend.setup, MixDirection.mixIn, false);
skeleton.updateWorldTransform(Physics.update);
bounds = skeleton.getBounds(clipper);
var boundsSkel = skeleton.getBounds(clipper);
if (!Math.isNaN(bounds.x) && !Math.isNaN(bounds.y) && !Math.isNaN(bounds.width) && !Math.isNaN(bounds.height)) {
minX = Math.min(bounds.x, minX);
minY = Math.min(bounds.y, minY);
maxX = Math.max(bounds.right, maxX);
maxY = Math.max(bounds.bottom, maxY);
if (!Math.isNaN(boundsSkel.x) && !Math.isNaN(boundsSkel.y) && !Math.isNaN(boundsSkel.width) && !Math.isNaN(boundsSkel.height)) {
minX = Math.min(boundsSkel.x, minX);
minY = Math.min(boundsSkel.y, minY);
maxX = Math.max(boundsSkel.x + boundsSkel.width, maxX);
maxY = Math.max(boundsSkel.y + boundsSkel.height, maxY);
} else
trace("ERROR");
throw new SpineException("Animation bounds are invalid: " + animation.name);
time += stepTime;
}
var bounds = new Rectangle();
bounds.x = minX;
bounds.y = minY;
bounds.width = maxX - minX;

View File

@ -33,8 +33,9 @@ import spine.animation.Animation;
import starling.animation.IAnimatable;
import openfl.geom.Matrix;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.geom.Rectangle as OpenFlRectangle;
import spine.Bone;
import spine.Rectangle;
import spine.Skeleton;
import spine.SkeletonClipping;
import spine.SkeletonData;
@ -43,7 +44,6 @@ import spine.animation.AnimationState;
import spine.animation.AnimationStateData;
import spine.animation.MixBlend;
import spine.animation.MixDirection;
import spine.attachments.Attachment;
import spine.attachments.ClippingAttachment;
import spine.attachments.MeshAttachment;
import spine.attachments.RegionAttachment;
@ -308,9 +308,9 @@ class SkeletonSprite extends DisplayObject implements IAnimatable {
return null;
}
override public function getBounds(targetSpace:DisplayObject, resultRect:Rectangle = null):Rectangle {
override public function getBounds(targetSpace:DisplayObject, resultRect:OpenFlRectangle = null):OpenFlRectangle {
if (resultRect == null) {
resultRect = new Rectangle();
resultRect = new OpenFlRectangle();
}
if (targetSpace == this) {
resultRect.setTo(0, 0, 0, 0);
@ -335,23 +335,28 @@ class SkeletonSprite extends DisplayObject implements IAnimatable {
minY = 100000000.,
maxY = -100000000.;
var bound:lime.math.Rectangle;
for (i in 0...steps) {
animation.apply(_skeleton, time, time, false, [], 1, MixBlend.setup, MixDirection.mixIn, false);
_skeleton.updateWorldTransform(Physics.update);
bound = _skeleton.getBounds(clipper);
var boundsSkel = _skeleton.getBounds(clipper);
if (!Math.isNaN(bound.x) && !Math.isNaN(bound.y) && !Math.isNaN(bound.width) && !Math.isNaN(bound.height)) {
minX = Math.min(bound.x, minX);
minY = Math.min(bound.y, minY);
maxX = Math.max(bound.right, maxX);
maxY = Math.max(bound.bottom, maxY);
if (!Math.isNaN(boundsSkel.x) && !Math.isNaN(boundsSkel.y) && !Math.isNaN(boundsSkel.width) && !Math.isNaN(boundsSkel.height)) {
minX = Math.min(boundsSkel.x, minX);
minY = Math.min(boundsSkel.y, minY);
maxX = Math.max(boundsSkel.x + boundsSkel.width, maxX);
maxY = Math.max(boundsSkel.y + boundsSkel.height, maxY);
} else
trace("ERROR");
throw new SpineException("Animation bounds are invalid: " + animation.name);
time += stepTime;
}
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
var bounds = new Rectangle();
bounds.x = minX;
bounds.y = minY;
bounds.width = maxX - minX;
bounds.height = maxY - minY;
return bounds;
}
public var skeleton(get, never):Skeleton;