Skip to content

Commit

Permalink
feat: Added slot names to the Spine Sprite viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Aug 15, 2024
1 parent 2409b24 commit 9b52efa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/parser/src/spine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface SpineSummary<
> {
skinNames: string[];
eventNames: EventName[];
slotNames: string[];
animations: {
name: AnimationName;
duration: number;
Expand Down Expand Up @@ -51,6 +52,7 @@ export class Spine<
return {
skinNames: content.skins?.map((skin) => skin.name) || [],
eventNames: Object.keys(content.events || {}) as EventName[],
slotNames: content.slots?.map((slot) => slot.name) || [],
animations: Object.keys(content.animations || {}).map((animationName) => {
const animation: SpineAnimation =
content.animations![animationName as AnimationName];
Expand Down
5 changes: 5 additions & 0 deletions packages/vscode/webviews-legacy/spine-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
'sfx_sluggabun_look_sniff',
'sfx_sluggabun_mortar_mouth',
],
slotNames: ['body', 'eyes', 'mouth', 'teeth'],
animations: [
{
name: 'attack_bite',
Expand Down Expand Up @@ -308,6 +309,10 @@ <h1 class="name">???</h1>
<h2>Animations Events</h2>
<ul class="animations"></ul>
</section>
<section>
<h2>Slots</h2>
<ul class="slots"></ul>
</section>
</body>
<!-- The global data from VSCode will need to be injected before loading the main script -->
<!-- VSCODE-INJECT-DATA -->
Expand Down
13 changes: 13 additions & 0 deletions packages/vscode/webviews-legacy/spine-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const elements = {
animationsList: /** @type {HTMLUListElement} */ (
document.querySelector('ul.animations')
),
slotsList: /** @type {HTMLUListElement} */ (
document.querySelector('ul.slots')
),
};

// Initial & static data
Expand Down Expand Up @@ -75,6 +78,16 @@ for (const animation of sprite.summary.animations) {

// Add an inner list of events and their timings
}
// Add the list of slots
for (const slotName of sprite.summary.slotNames.sort((a, b) =>
a.toLowerCase().localeCompare(b.toLowerCase()),
)) {
const li = document.createElement('li');
li.classList.add('slot');
li.innerHTML = `<span class="name">${slotName}</span>`;
elements.slotsList.appendChild(li);
// Add an inner list of events and their timings
}

/**
* @param {any} condition
Expand Down

0 comments on commit 9b52efa

Please sign in to comment.