Skip to content

Commit

Permalink
Spine with no sequence crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Megabyteceer committed Dec 20, 2024
1 parent d8505bb commit 30d1b6d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion thing-editor/src/editor/editor-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 160,7 @@ type KeyedObject = { [key: string]: any };

type SerializedDataValidationError = undefined | {
message: string;
findObjectCallback: ((o: import('pixi.js').Container) => boolean);
findObjectCallback: ((o: import('pixi.js').Container) => boolean | undefined);
fieldName?: string;
errorCode?: number;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 150,16 @@ export default class SpineSequences extends ComponentDebounced<SpineSequencesPro
}

onAutoSelect(selectPath: string[]) {
this.setActiveSequence(this.spine.sequences[parseInt(selectPath[1])].n);
this.onSequenceItemClick(this.activeSequence.s[parseInt(selectPath[2])]);

getWindowElement('#sequence-item-' selectPath[1] '-' selectPath[2], '#spine-sequence').then(() => {
getWindowElement('.spine-sequence-animations-select-wrapper', '#spine-sequence').then((itemView: HTMLDivElement) => {
shakeDomElement(itemView);
if (this.spine.sequences) {
this.setActiveSequence(this.spine.sequences[parseInt(selectPath[1])].n);
this.onSequenceItemClick(this.activeSequence.s[parseInt(selectPath[2])]);

getWindowElement('#sequence-item-' selectPath[1] '-' selectPath[2], '#spine-sequence').then(() => {
getWindowElement('.spine-sequence-animations-select-wrapper', '#spine-sequence').then((itemView: HTMLDivElement) => {
shakeDomElement(itemView);
});
});
});
}
}

static onAutoSelect(selectPath: string[]) {
Expand Down Expand Up @@ -331,7 333,7 @@ export default class SpineSequences extends ComponentDebounced<SpineSequencesPro
}) : undefined;

return R.div({
id: 'sequence-item-' this.spine.sequences.indexOf(this.activeSequence) '-' itemId,
id: 'sequence-item-' this.spine.sequences!.indexOf(this.activeSequence) '-' itemId,
onMouseDown: (ev:MouseEvent) => {
sp(ev);
this.onSequenceItemClick(item);
Expand Down
48 changes: 23 additions & 25 deletions thing-editor/src/engine/lib/assets/src/extended/spine.c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 120,8 @@ const filterAssets = (file:FileDesc) => {

const sequencesByNamesCache = new Map() as Map<SpineSequence[], Map<string, SpineSequence>>;

const EMPTY_MAP = new Map();

export default class Spine extends Container implements IGoToLabelConsumer {

_speed = 1;
Expand Down Expand Up @@ -147,32 149,29 @@ export default class Spine extends Container implements IGoToLabelConsumer {
this._skinPoseAnimation = this.currentAnimation!;
this.playingSequence = undefined;

/// #if EDITOR
if (!this.sequences) {
this._sequencesByNames = new Map();
return;
}
/// #endif

if (!sequencesByNamesCache.has(this.sequences)) {
const names = new Map() as Map<string, SpineSequence>;
for (const s of this.sequences) {
names.set(s.n, s);
for (let i = 0; i < s.s.length; i ) {
const item = s.s[i];
item.___next = s.s[i 1] || s.s[s.l!];
item.___duration = this.getItemDurationFrames(item)!;
if (item.actions) {
for (let i = 0; i < item.actions.length; i ) {
const action = item.actions[i];
action.___next = item.actions[i 1];
if (this.sequences) {
if (!sequencesByNamesCache.has(this.sequences)) {
const names = new Map() as Map<string, SpineSequence>;
for (const s of this.sequences) {
names.set(s.n, s);
for (let i = 0; i < s.s.length; i ) {
const item = s.s[i];
item.___next = s.s[i 1] || s.s[s.l!];
item.___duration = this.getItemDurationFrames(item)!;
if (item.actions) {
for (let i = 0; i < item.actions.length; i ) {
const action = item.actions[i];
action.___next = item.actions[i 1];
}
}
}
}
sequencesByNamesCache.set(this.sequences, names);
}
sequencesByNamesCache.set(this.sequences, names);
this._sequencesByNames = sequencesByNamesCache.get(this.sequences)!;
} else {
this._sequencesByNames = EMPTY_MAP;
}
this._sequencesByNames = sequencesByNamesCache.get(this.sequences)!;
}

getItemDurationFrames(item:SpineSequenceItem) {
Expand Down Expand Up @@ -355,15 354,14 @@ export default class Spine extends Container implements IGoToLabelConsumer {
return ret;
}


@editable({type: 'spine-sequence', name: 'sequences'})
__sequences!: SpineSequence[];

@editable({type: 'spine-sequence', name: 'sequences'})
set sequences(val :SpineSequence[]) {
this.__sequences = JSON.parse(JSON.stringify(val));
}

get sequences(): SpineSequence[] {
get sequences(): SpineSequence[] | undefined {
return this.__isSerialization ? JSON.parse(JSON.stringify(this.__sequences)) : this.__sequences;
}

Expand Down Expand Up @@ -856,7 854,7 @@ export default class Spine extends Container implements IGoToLabelConsumer {
return this.___previewFrame || 0;
}

static __validateSpineHasAnimation(data:any, animationName:string, fieldName:string) {
static __validateSpineHasAnimation(data:any, animationName:string, fieldName:string): SerializedDataValidationError | undefined {
if (
!(Lib.resources[data.spineData].spineData as ISkeletonData).animations.find((a) => a.name == animationName)
) {
Expand Down

0 comments on commit 30d1b6d

Please sign in to comment.