diff --git a/spine-ts/spine-webcomponents/example/app.html b/spine-ts/spine-webcomponents/example/app.html index 75ea74166..72bac282c 100644 --- a/spine-ts/spine-webcomponents/example/app.html +++ b/spine-ts/spine-webcomponents/example/app.html @@ -411,7 +411,7 @@ (async () => { /* SECTION 1 */ - const widget1 = await spine.getSpineWidget("list").whenReady; + const widget1 = await spine.getSkeleton("list").whenReady; const setInteractionSectionOne = (itemName, trackNumber) => { const divName = `${itemName}Div`; @@ -501,7 +501,7 @@ /* SECTION 2 */ const btnNext2 = document.getElementById("btn-next-2"); - const widget2 = await spine.getSpineWidget("pan").whenReady; + const widget2 = await spine.getSkeleton("pan").whenReady; const foodPiece1 = widget2.skeleton.findSlot(`food-piece-1`); const foodPiece2 = widget2.skeleton.findSlot(`food-piece-2`); const foodPiece3 = widget2.skeleton.findSlot(`food-piece-3`); @@ -561,7 +561,7 @@ /* SECTION 2 */ /* SECTION 3 */ - const widget3 = await spine.getSpineWidget("delivery").whenReady; + const widget3 = await spine.getSkeleton("delivery").whenReady; const btnNext3 = document.getElementById("btn-next-3"); const box = widget3.skeleton.findSlot("box"); @@ -610,7 +610,7 @@ /* SECTION 4 */ - const widget4 = await spine.getSpineWidget("ready").whenReady; + const widget4 = await spine.getSkeleton("ready").whenReady; const slot4Bread = widget4.skeleton.findSlot("salad"); widget4.addPointerSlotEventCallback(slot4Bread, (slot, event) => { diff --git a/spine-ts/spine-webcomponents/example/game.html b/spine-ts/spine-webcomponents/example/game.html index 00538cf46..b3bbaa946 100644 --- a/spine-ts/spine-webcomponents/example/game.html +++ b/spine-ts/spine-webcomponents/example/game.html @@ -94,8 +94,8 @@ const containerGame = document.getElementById("container-game"); (async () => { - const spineboy = spine.getSpineWidget("spineboy-game"); - const windmill = spine.getSpineWidget("windmill-game"); + const spineboy = spine.getSkeleton("spineboy-game"); + const windmill = spine.getSkeleton("windmill-game"); await Promise.all([spineboy.whenReady, windmill.whenReady]); spineboy.state.setAnimation(2, "aim", true); diff --git a/spine-ts/spine-webcomponents/example/gui.html b/spine-ts/spine-webcomponents/example/gui.html index 2b825cce7..97a19b31c 100644 --- a/spine-ts/spine-webcomponents/example/gui.html +++ b/spine-ts/spine-webcomponents/example/gui.html @@ -57,7 +57,7 @@ @@ -1006,7 +1006,7 @@ async function updateCelesteAnimations() { @@ -1025,7 +1025,7 @@ async function updateCelesteAnimations() { > ... (async () => { - const widget = await spine.getSpineWidget("sack-debug").whenReady; + const widget = await spine.getSkeleton("sack-debug").whenReady; widget.skeleton.getRootBone().x += 50; })();` ); @@ -1352,7 +1352,7 @@ function removeDiv() { @@ -3400,11 +3400,11 @@ const darkPicker = document.getElementById("dark-picker"); ... (async () => { - const widget = await spine.getSpineWidget("potty2").whenReady; - widget.followSlot("rain/rain-color", spine.getSpineWidget("potty2-1"), { followVisibility: false, hideAttachment: true }); - widget.followSlot("rain/rain-white", spine.getSpineWidget("potty2-2"), { followVisibility: false, hideAttachment: true }); - widget.followSlot("rain/rain-blue", spine.getSpineWidget("potty2-3"), { followVisibility: false, hideAttachment: true }); - widget.followSlot("rain/rain-green", spine.getSpineWidget("potty2-4"), { followVisibility: false, hideAttachment: true }); + const widget = await spine.getSkeleton("potty2").whenReady; + widget.followSlot("rain/rain-color", spine.getSkeleton("potty2-1"), { followVisibility: false, hideAttachment: true }); + widget.followSlot("rain/rain-white", spine.getSkeleton("potty2-2"), { followVisibility: false, hideAttachment: true }); + widget.followSlot("rain/rain-blue", spine.getSkeleton("potty2-3"), { followVisibility: false, hideAttachment: true }); + widget.followSlot("rain/rain-green", spine.getSkeleton("potty2-4"), { followVisibility: false, hideAttachment: true }); })();`); diff --git a/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts b/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts index 6a6fb8cd9..4ca7af168 100644 --- a/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts +++ b/spine-ts/spine-webcomponents/src/SpineWebComponentSkeleton.ts @@ -475,7 +475,7 @@ export class SpineWebComponentSkeleton extends HTMLElement implements Disposable public debug = false; /** - * An identifier to obtain this widget using the {@link getSpineWidget} function. + * An identifier to obtain this widget using the {@link getSkeleton} function. * This is useful when you need to interact with the widget using js. * Connected to `identifier` attribute. */ @@ -1325,11 +1325,21 @@ export class SpineWebComponentSkeleton extends HTMLElement implements Disposable customElements.define("spine-skeleton", SpineWebComponentSkeleton); -export function getSpineWidget (identifier: string): SpineWebComponentSkeleton { +/** + * Return the first {@link SpineWebComponentSkeleton} with the given {@link SpineWebComponentSkeleton.identifier} + * @param identifier The {@link SpineWebComponentSkeleton.identifier} to search on the DOM + * @returns A skeleton web component instance with the given identifier + */ +export function getSkeleton (identifier: string): SpineWebComponentSkeleton { return document.querySelector(`spine-skeleton[identifier=${identifier}]`) as SpineWebComponentSkeleton; } -export function createSpineWidget (parameters: WidgetAttributes): SpineWebComponentSkeleton { +/** + * Create a {@link SpineWebComponentSkeleton} with the given {@link WidgetAttributes}. + * @param parameters The options to pass to the {@link SpineWebComponentSkeleton} + * @returns The skeleton web component instance created + */ +export function createSkeleton (parameters: WidgetAttributes): SpineWebComponentSkeleton { const widget = document.createElement("spine-skeleton") as SpineWebComponentSkeleton; Object.entries(SpineWebComponentSkeleton.attributesDescription).forEach(entry => {