UNPKG

@pixi-spine/runtime-3.7

Version:

Pixi runtime for spine 3.7 models

50 lines (47 loc) 1.59 kB
'use strict'; class Skin { constructor(name) { this.attachments = new Array(); if (name == null) throw new Error("name cannot be null."); this.name = name; } addAttachment(slotIndex, name, attachment) { if (attachment == null) throw new Error("attachment cannot be null."); const attachments = this.attachments; if (slotIndex >= attachments.length) attachments.length = slotIndex + 1; if (!attachments[slotIndex]) attachments[slotIndex] = {}; attachments[slotIndex][name] = attachment; } /** @return May be null. */ getAttachment(slotIndex, name) { const dictionary = this.attachments[slotIndex]; return dictionary ? dictionary[name] : null; } /** Attach each attachment in this skin if the corresponding attachment in the old skin is currently attached. */ attachAll(skeleton, oldSkin) { let slotIndex = 0; for (let i = 0; i < skeleton.slots.length; i++) { const slot = skeleton.slots[i]; const slotAttachment = slot.getAttachment(); if (slotAttachment && slotIndex < oldSkin.attachments.length) { const dictionary = oldSkin.attachments[slotIndex]; for (const key in dictionary) { const skinAttachment = dictionary[key]; if (slotAttachment == skinAttachment) { const attachment = this.getAttachment(slotIndex, key); if (attachment != null) slot.setAttachment(attachment); break; } } } slotIndex++; } } } exports.Skin = Skin; //# sourceMappingURL=Skin.js.map