Add SlotAttachmentPlaceholder expression.

This commit is contained in:
Davide Tantillo 2026-03-17 12:46:14 +01:00
parent f6c3d70153
commit a079413721
4 changed files with 66 additions and 2 deletions

View File

@ -715,6 +715,18 @@
} }
] ]
}, },
{
"id": "slot-attachment-placeholder",
"expressionName": "SlotAttachmentPlaceholder",
"highlight": false,
"returnType": "string",
"params": [
{
"id": "slot-name",
"type": "string"
}
]
},
{ {
"id": "bone-x", "id": "bone-x",
"expressionName": "BoneX", "expressionName": "BoneX",

View File

@ -27,6 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
import type { Attachment, Skin } from "@esotericsoftware/spine-construct3-lib";
import type { SDKInstanceClass as SpineC3Instance } from "./instance"; import type { SDKInstanceClass as SpineC3Instance } from "./instance";
const C3 = globalThis.C3; const C3 = globalThis.C3;
@ -34,13 +35,35 @@ const C3 = globalThis.C3;
C3.Plugins.EsotericSoftware_SpineConstruct3.Exps = C3.Plugins.EsotericSoftware_SpineConstruct3.Exps =
{ {
SlotAttachment (this: SpineC3Instance, slotName: string) { SlotAttachment (this: SpineC3Instance, slotName: string) {
if (!this.skeleton) return ""; const { skeleton } = this;
const slot = this.skeleton.findSlot(slotName); if (!skeleton) return "";
const slot = skeleton.findSlot(slotName);
if (!slot) return ""; if (!slot) return "";
const attachment = slot.pose.getAttachment(); const attachment = slot.pose.getAttachment();
return attachment ? attachment.name : ""; return attachment ? attachment.name : "";
}, },
SlotAttachmentPlaceholder (this: SpineC3Instance, slotName: string) {
const { skeleton } = this;
if (!skeleton) return "";
const slot = skeleton.findSlot(slotName);
if (!slot) return "";
const attachment = slot.pose.getAttachment();
if (!attachment) return "";
const slotIndex = slot.data.index;
const skin = skeleton.skin;
if (skin) {
const name = findPlaceholderName(skin, slotIndex, attachment);
if (name) return name;
}
const defaultSkin = skeleton.data.defaultSkin;
if (defaultSkin) {
const name = findPlaceholderName(defaultSkin, slotIndex, attachment);
if (name) return name;
}
return attachment.name;
},
BoneX (this: SpineC3Instance, boneName: string) { BoneX (this: SpineC3Instance, boneName: string) {
return this.getBoneX(boneName); return this.getBoneX(boneName);
}, },
@ -116,3 +139,12 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Exps =
return this.getBounds().height; return this.getBounds().height;
} }
}; };
function findPlaceholderName (skin: Skin, slotIndex: number, attachment: Attachment): string | null {
const dictionary = skin.attachments[slotIndex];
if (!dictionary) return null;
for (const name in dictionary) {
if (dictionary[name] === attachment) return name;
}
return null;
}

View File

@ -811,6 +811,16 @@
} }
} }
}, },
"slot-attachment-placeholder": {
"description": "Get the skin placeholder name of the attachment on a slot, or the attachment name if using the default skin. Returns empty string if no attachment.",
"translated-name": "SlotAttachmentPlaceholder",
"params": {
"slot-name": {
"name": "Slot name",
"desc": "Name of the slot"
}
}
},
"bone-x": { "bone-x": {
"description": "Get the world X position of a bone.", "description": "Get the world X position of a bone.",
"translated-name": "BoneX", "translated-name": "BoneX",

View File

@ -811,6 +811,16 @@
} }
} }
}, },
"slot-attachment-placeholder": {
"description": "获取插槽上附件的皮肤占位符名称,如果使用默认皮肤则返回附件名称。如果没有附件则返回空字符串。",
"translated-name": "SlotAttachmentPlaceholder",
"params": {
"slot-name": {
"name": "插槽名称",
"desc": "插槽的名称"
}
}
},
"bone-x": { "bone-x": {
"description": "获取骨骼的世界X位置。", "description": "获取骨骼的世界X位置。",
"translated-name": "BoneX", "translated-name": "BoneX",