mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Improved parameter checking.
This commit is contained in:
parent
de2b7674c4
commit
bcee9ede8d
@ -251,8 +251,9 @@ public class Animation {
|
||||
frames = new float[frameCount << 1];
|
||||
}
|
||||
|
||||
public void setBoneIndex (int boneIndex) {
|
||||
this.boneIndex = boneIndex;
|
||||
public void setBoneIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.boneIndex = index;
|
||||
}
|
||||
|
||||
public int getBoneIndex () {
|
||||
@ -319,8 +320,9 @@ public class Animation {
|
||||
frames = new float[frameCount * ENTRIES];
|
||||
}
|
||||
|
||||
public void setBoneIndex (int boneIndex) {
|
||||
this.boneIndex = boneIndex;
|
||||
public void setBoneIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.boneIndex = index;
|
||||
}
|
||||
|
||||
public int getBoneIndex () {
|
||||
@ -432,8 +434,9 @@ public class Animation {
|
||||
frames = new float[frameCount * ENTRIES];
|
||||
}
|
||||
|
||||
public void setSlotIndex (int slotIndex) {
|
||||
this.slotIndex = slotIndex;
|
||||
public void setSlotIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.slotIndex = index;
|
||||
}
|
||||
|
||||
public int getSlotIndex () {
|
||||
@ -503,12 +506,13 @@ public class Animation {
|
||||
return frames.length;
|
||||
}
|
||||
|
||||
public int getSlotIndex () {
|
||||
return slotIndex;
|
||||
public void setSlotIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.slotIndex = index;
|
||||
}
|
||||
|
||||
public void setSlotIndex (int slotIndex) {
|
||||
this.slotIndex = slotIndex;
|
||||
public int getSlotIndex () {
|
||||
return slotIndex;
|
||||
}
|
||||
|
||||
public float[] getFrames () {
|
||||
@ -660,8 +664,9 @@ public class Animation {
|
||||
frameVertices = new float[frameCount][];
|
||||
}
|
||||
|
||||
public void setSlotIndex (int slotIndex) {
|
||||
this.slotIndex = slotIndex;
|
||||
public void setSlotIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.slotIndex = index;
|
||||
}
|
||||
|
||||
public int getSlotIndex () {
|
||||
@ -750,6 +755,7 @@ public class Animation {
|
||||
}
|
||||
|
||||
public void setIkConstraintIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.ikConstraintIndex = index;
|
||||
}
|
||||
|
||||
@ -806,6 +812,7 @@ public class Animation {
|
||||
}
|
||||
|
||||
public void setTransformConstraintIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.transformConstraintIndex = index;
|
||||
}
|
||||
|
||||
@ -874,6 +881,7 @@ public class Animation {
|
||||
}
|
||||
|
||||
public void setPathConstraintIndex (int index) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
this.pathConstraintIndex = index;
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ public class AnimationStateData {
|
||||
float defaultMix;
|
||||
|
||||
public AnimationStateData (SkeletonData skeletonData) {
|
||||
if (skeletonData == null) throw new IllegalArgumentException("skeletonData cannot be null.");
|
||||
this.skeletonData = skeletonData;
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@ public class Bone implements Updatable {
|
||||
* @param parent May be null. */
|
||||
public Bone (Bone bone, Skeleton skeleton, Bone parent) {
|
||||
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
this.skeleton = skeleton;
|
||||
this.parent = parent;
|
||||
data = bone.data;
|
||||
|
||||
@ -46,6 +46,7 @@ public class BoneData {
|
||||
|
||||
/** @param parent May be null. */
|
||||
public BoneData (int index, String name, BoneData parent) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
|
||||
@ -39,6 +39,7 @@ public class Event {
|
||||
final float time;
|
||||
|
||||
public Event (float time, EventData data) {
|
||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||
this.time = time;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@ -43,20 +43,22 @@ public class IkConstraint implements Updatable {
|
||||
int bendDirection;
|
||||
|
||||
public IkConstraint (IkConstraintData data, Skeleton skeleton) {
|
||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
this.data = data;
|
||||
mix = data.mix;
|
||||
bendDirection = data.bendDirection;
|
||||
|
||||
bones = new Array(data.bones.size);
|
||||
if (skeleton != null) {
|
||||
for (BoneData boneData : data.bones)
|
||||
bones.add(skeleton.findBone(boneData.name));
|
||||
target = skeleton.findBone(data.target.name);
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy constructor. */
|
||||
public IkConstraint (IkConstraint constraint, Skeleton skeleton) {
|
||||
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
data = constraint.data;
|
||||
bones = new Array(constraint.bones.size);
|
||||
for (Bone bone : constraint.bones)
|
||||
|
||||
@ -41,6 +41,7 @@ public class IkConstraintData {
|
||||
float mix = 1;
|
||||
|
||||
public IkConstraintData (String name) {
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -57,6 +58,7 @@ public class IkConstraintData {
|
||||
}
|
||||
|
||||
public void setTarget (BoneData target) {
|
||||
if (target == null) throw new IllegalArgumentException("target cannot be null.");
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@ public class PathConstraint implements Updatable {
|
||||
final FloatArray lengths = new FloatArray(), positions = new FloatArray(), temp = new FloatArray();
|
||||
|
||||
public PathConstraint (PathConstraintData data, Skeleton skeleton) {
|
||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
this.data = data;
|
||||
position = data.position;
|
||||
rotateMix = data.rotateMix;
|
||||
@ -31,6 +33,8 @@ public class PathConstraint implements Updatable {
|
||||
|
||||
/** Copy constructor. */
|
||||
public PathConstraint (PathConstraint constraint, Skeleton skeleton) {
|
||||
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
data = constraint.data;
|
||||
bones = new Array(constraint.bones.size);
|
||||
for (Bone bone : constraint.bones)
|
||||
@ -84,8 +88,7 @@ public class PathConstraint implements Updatable {
|
||||
|
||||
for (int i = 0; i < boneCount; i++) {
|
||||
Bone bone = bones.get(i);
|
||||
float length = bone.data.length;
|
||||
float x = length * bone.a, y = length * bone.c;
|
||||
float length = bone.data.length, x = length * bone.a, y = length * bone.c;
|
||||
lengths.add((float)Math.sqrt(x * x + y * y));
|
||||
}
|
||||
float[] positions = computeWorldPositions(path, false);
|
||||
|
||||
@ -11,6 +11,7 @@ public class PathConstraintData {
|
||||
float offsetRotation;
|
||||
|
||||
public PathConstraintData (String name) {
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@ -303,6 +303,7 @@ public class Skeleton {
|
||||
|
||||
/** Sets the slots and the order they will be drawn. */
|
||||
public void setDrawOrder (Array<Slot> drawOrder) {
|
||||
if (drawOrder == null) throw new IllegalArgumentException("drawOrder cannot be null.");
|
||||
this.drawOrder = drawOrder;
|
||||
}
|
||||
|
||||
@ -423,10 +424,12 @@ public class Skeleton {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Returns the axis aligned bounding box (AABB) of the region, mesh, and skinned mesh attachments for the current pose.
|
||||
/** Returns the axis aligned bounding box (AABB) of the region and mesh attachments for the current pose.
|
||||
* @param offset The distance from the skeleton origin to the bottom left corner of the AABB.
|
||||
* @param size The width and height of the AABB. */
|
||||
public void getBounds (Vector2 offset, Vector2 size) {
|
||||
if (offset == null) throw new IllegalArgumentException("offset cannot be null.");
|
||||
if (size == null) throw new IllegalArgumentException("size cannot be null.");
|
||||
Array<Slot> drawOrder = this.drawOrder;
|
||||
float minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
|
||||
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
||||
@ -458,6 +461,7 @@ public class Skeleton {
|
||||
|
||||
/** A convenience method for setting the skeleton color. The color can also be set by modifying {@link #getColor()}. */
|
||||
public void setColor (Color color) {
|
||||
if (color == null) throw new IllegalArgumentException("color cannot be null.");
|
||||
this.color.set(color);
|
||||
}
|
||||
|
||||
|
||||
@ -89,6 +89,7 @@ public class SkeletonBinary {
|
||||
}
|
||||
|
||||
public SkeletonBinary (AttachmentLoader attachmentLoader) {
|
||||
if (attachmentLoader == null) throw new IllegalArgumentException("attachmentLoader cannot be null.");
|
||||
this.attachmentLoader = attachmentLoader;
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ public class SkeletonBounds {
|
||||
};
|
||||
|
||||
public void update (Skeleton skeleton, boolean updateAabb) {
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
Array<BoundingBoxAttachment> boundingBoxes = this.boundingBoxes;
|
||||
Array<FloatArray> polygons = this.polygons;
|
||||
Array<Slot> slots = skeleton.slots;
|
||||
@ -221,6 +222,7 @@ public class SkeletonBounds {
|
||||
|
||||
/** Returns the polygon for the specified bounding box, or null. */
|
||||
public FloatArray getPolygon (BoundingBoxAttachment boundingBox) {
|
||||
if (boundingBox == null) throw new IllegalArgumentException("boundingBox cannot be null.");
|
||||
int index = boundingBoxes.indexOf(boundingBox, true);
|
||||
return index == -1 ? null : polygons.get(index);
|
||||
}
|
||||
|
||||
@ -74,6 +74,7 @@ public class SkeletonJson {
|
||||
}
|
||||
|
||||
public SkeletonJson (AttachmentLoader attachmentLoader) {
|
||||
if (attachmentLoader == null) throw new IllegalArgumentException("attachmentLoader cannot be null.");
|
||||
this.attachmentLoader = attachmentLoader;
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +104,7 @@ public class Slot {
|
||||
}
|
||||
|
||||
public void setAttachmentVertices (FloatArray attachmentVertices) {
|
||||
if (attachmentVertices == null) throw new IllegalArgumentException("attachmentVertices cannot be null.");
|
||||
this.attachmentVertices = attachmentVertices;
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ public class SlotData {
|
||||
BlendMode blendMode;
|
||||
|
||||
public SlotData (int index, String name, BoneData boneData) {
|
||||
if (index < 0) throw new IllegalArgumentException("index must be >= 0.");
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
if (boneData == null) throw new IllegalArgumentException("boneData cannot be null.");
|
||||
this.index = index;
|
||||
|
||||
@ -12,20 +12,22 @@ public class TransformConstraint implements Updatable {
|
||||
final Vector2 temp = new Vector2();
|
||||
|
||||
public TransformConstraint (TransformConstraintData data, Skeleton skeleton) {
|
||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
this.data = data;
|
||||
rotateMix = data.rotateMix;
|
||||
translateMix = data.translateMix;
|
||||
scaleMix = data.scaleMix;
|
||||
shearMix = data.shearMix;
|
||||
|
||||
if (skeleton != null) {
|
||||
bone = skeleton.findBone(data.bone.name);
|
||||
target = skeleton.findBone(data.target.name);
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy constructor. */
|
||||
public TransformConstraint (TransformConstraint constraint, Skeleton skeleton) {
|
||||
if (constraint == null) throw new IllegalArgumentException("constraint cannot be null.");
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
data = constraint.data;
|
||||
bone = skeleton.bones.get(constraint.bone.data.index);
|
||||
target = skeleton.bones.get(constraint.target.data.index);
|
||||
|
||||
@ -8,6 +8,7 @@ public class TransformConstraintData {
|
||||
float offsetRotation, offsetX, offsetY, offsetScaleX, offsetScaleY, offsetShearY;
|
||||
|
||||
public TransformConstraintData (String name) {
|
||||
if (name == null) throw new IllegalArgumentException("name cannot be null.");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -20,6 +21,7 @@ public class TransformConstraintData {
|
||||
}
|
||||
|
||||
public void setBone (BoneData bone) {
|
||||
if (bone == null) throw new IllegalArgumentException("bone cannot be null.");
|
||||
this.bone = bone;
|
||||
}
|
||||
|
||||
@ -28,6 +30,7 @@ public class TransformConstraintData {
|
||||
}
|
||||
|
||||
public void setTarget (BoneData target) {
|
||||
if (target == null) throw new IllegalArgumentException("target cannot be null.");
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user