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