2023-09-11 14:06:13 +02:00

91 lines
2.4 KiB
Haxe

package spine;
import openfl.errors.ArgumentError;
import openfl.Vector;
import spine.attachments.Attachment;
import spine.attachments.VertexAttachment;
class Slot {
private var _data:SlotData;
private var _bone:Bone;
public var color:Color;
public var darkColor:Color;
private var _attachment:Attachment;
public var sequenceIndex = -1;
public var attachmentState:Int = 0;
public var deform:Vector<Float> = new Vector<Float>();
public function new(data:SlotData, bone:Bone) {
if (data == null)
throw new ArgumentError("data cannot be null.");
if (bone == null)
throw new ArgumentError("bone cannot be null.");
_data = data;
_bone = bone;
this.color = new Color(1, 1, 1, 1);
this.darkColor = data.darkColor == null ? null : new Color(1, 1, 1, 1);
setToSetupPose();
}
public var data(get, never):SlotData;
private function get_data():SlotData {
return _data;
}
public var bone(get, never):Bone;
private function get_bone():Bone {
return _bone;
}
public var skeleton(get, never):Skeleton;
private function get_skeleton():Skeleton {
return _bone.skeleton;
}
/** @return May be null. */
public var attachment(get, set):Attachment;
private function get_attachment():Attachment {
return _attachment;
}
/** Sets the slot's attachment and, if the attachment changed, resets {@link #attachmentTime} and clears the {@link #deform}.
* The deform is not cleared if the old attachment has the same {@link VertexAttachment#getDeformAttachment()} as the specified attachment.
* @param attachment May be null. */
public function set_attachment(attachmentNew:Attachment):Attachment {
if (attachment == attachmentNew)
return attachmentNew;
if (!Std.isOfType(attachmentNew, VertexAttachment)
|| !Std.isOfType(attachment, VertexAttachment)
|| cast(attachmentNew, VertexAttachment).timelineAttachment != cast(attachment, VertexAttachment).timelineAttachment) {
deform = new Vector<Float>();
}
_attachment = attachmentNew;
sequenceIndex = -1;
return attachmentNew;
}
public function setToSetupPose():Void {
color.setFromColor(data.color);
if (darkColor != null)
darkColor.setFromColor(data.darkColor);
if (_data.attachmentName == null) {
attachment = null;
} else {
_attachment = null;
attachment = skeleton.getAttachmentForSlotIndex(data.index, data.attachmentName);
}
}
public function toString():String {
return _data.name != null ? _data.name : "Slot?";
}
}