Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
  • Loading branch information
bofeng-song committed Sep 20, 2024
1 parent fa73743 commit 8768952
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cocos/spine/lib/spine-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ import spine from './spine-core.js';
import { js } from '../../core';

function resizeArray (array, newSize): Array<any> {
if (!array) return new Array(newSize);
if (newSize === array.length) return array;
if (newSize < array.length) return array.slice(0, newSize);
else return new Array(newSize);
if (!array) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return new Array(newSize);
}
if (newSize === array.length) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return array;
}
if (newSize < array.length) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return array.slice(0, newSize);
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return new Array(newSize);
}
}

function overrideDefineArrayProp (prototype: any, getPropVector: any, name: string): void {
Expand All @@ -44,6 +55,7 @@ function overrideDefineArrayProp (prototype: any, getPropVector: any, name: stri
array = resizeArray(array, count);
for (let i = 0; i < count; i++) array[i] = vectors.get(i);
this[_name] = array;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return array;
},
});
Expand Down Expand Up @@ -82,6 +94,7 @@ function overrideDefineArrayFunction (prototype: any, getPropVector: any, name:
array = resizeArray(array, count);
for (let i = 0; i < count; i++) array[i] = vectors.get(i);
this[_name] = array;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return array;
},
});
Expand Down Expand Up @@ -121,7 +134,6 @@ function overrideClass (wasm): void {
spine.Event = wasm.Event;
spine.EventData = wasm.EventData;
spine.Attachment = wasm.Attachment;
spine.SpineAnimationState = wasm.SpineAnimationState;
spine.VertexAttachment = wasm.VertexAttachment;
spine.BoundingBoxAttachment = wasm.BoundingBoxAttachment;
spine.ClippingAttachment = wasm.ClippingAttachment;
Expand Down

0 comments on commit 8768952

Please sign in to comment.