Skip to content

Commit

Permalink
fix code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Canvasfull committed Oct 9, 2023
1 parent f93cab8 commit d6d04cb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 63 deletions.
18 changes: 5 additions & 13 deletions cocos/spine/assembler/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ function _getSlotMaterial (blendMode: number, comp: Skeleton): MaterialInstance
}

export const simple: IAssembler = {

fillBuffers (render: UIRenderable, batcher: Batcher2D) {

},
updateColor (render: UIRenderable) {

},
vCount: 32767,
ensureAccessor (useTint: boolean) {
let accessor = useTint ? _tintAccessor : _accessor;
Expand Down Expand Up @@ -160,21 +153,20 @@ function realTimeTraverse (comp: Skeleton): void {
if (rd.vertexCount !== vc || rd.indexCount !== ic) {
rd.resize(vc, ic);
rd.indices = new Uint16Array(ic);
comp._vLength = vc * Float32Array.BYTES_PER_ELEMENT * floatStride;
comp._vLength = vc * Float32Array.BYTES_PER_ELEMENT * floatStride;
comp._vBuffer = new Uint8Array(rd.chunk.vb.buffer, rd.chunk.vb.byteOffset, Float32Array.BYTES_PER_ELEMENT * rd.chunk.vb.length);
comp._iLength = Uint16Array.BYTES_PER_ELEMENT * ic;
comp._iBuffer = new Uint8Array(rd.indices.buffer);
}

let vbuf = rd.chunk.vb;
const vbuf = rd.chunk.vb;
const vPtr = model.vPtr;
const iPtr = model.iPtr;
const ibuf = rd.indices!;
const HEAPU8 = spine.wasmUtil.wasm.HEAPU8;

comp._vBuffer?.set(HEAPU8.subarray(vPtr, vPtr + comp._vLength), 0);

Check failure on line 168 in cocos/spine/assembler/simple.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `ArrayLike<number>`
comp._iBuffer?.set(HEAPU8.subarray(iPtr, iPtr + comp._iLength), 0);

Check failure on line 169 in cocos/spine/assembler/simple.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `ArrayLike<number>`

const chunkOffset = rd.chunk.vertexOffset;
for (let i = 0; i < ic; i++) ibuf[i] += chunkOffset;

Expand All @@ -184,8 +176,8 @@ function realTimeTraverse (comp: Skeleton): void {
let indexCount = 0;
for (let i = 0; i < count; i += 6) {
indexCount = data.get(i+3);

Check failure on line 178 in cocos/spine/assembler/simple.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Operator '+' must be spaced
const material = _getSlotMaterial(data.get(i+4), comp);
const textureID = data.get(i+5);
const material = _getSlotMaterial(data.get(i + 4), comp);

Check failure on line 179 in cocos/spine/assembler/simple.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `number`
const textureID: number = data.get(i + 5);
comp.requestDrawData(material, textureID, indexOffset, indexCount);
indexOffset += indexCount;
}
Expand All @@ -201,7 +193,7 @@ function realTimeTraverse (comp: Skeleton): void {
tempVecPos.transformMat4(worldMat);
vbuf[index] = tempVecPos.x;
vbuf[index + 1] = tempVecPos.y;
vbuf[index + 2] = 0
vbuf[index + 2] = 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions cocos/spine/attach-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AttachUtil {
protected isInitialized = false;
protected skeletonBones: spine.Bone[] | FrameBoneInfo[] | undefined;

Check failure on line 39 in cocos/spine/attach-util.ts

View workflow job for this annotation

GitHub Actions / npm_test

Cannot find name 'FrameBoneInfo'.
protected socketNodes: Map<number, Node> | undefined;
private keysToDelete:number[] = [];
private keysToDelete: number[] = [];

constructor () {
this.isInitialized = false;
Expand All @@ -64,7 +64,7 @@ export class AttachUtil {
}

_syncAttachedNode (): void {
if(!this.isInitialized) return;
if (!this.isInitialized) return;
const socketNodes = this.socketNodes!;
for (const [boneIdx, boneNode] of socketNodes) {
if (!boneNode || !boneNode.isValid) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/spine/lib/spine-core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ declare namespace spine {
}

class SkeletonSystem {
public static updateAnimation(deltaTime:number): void;
public static updateAnimation(deltaTime: number): void;
public static updateRenderData(): void;
public static getCount(): number;
}
Expand Down
26 changes: 9 additions & 17 deletions cocos/spine/lib/spine-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@

import spine from './spine-core.js';
import { js } from '../../core';
import { array } from 'cocos/core/utils/js.js';


function resizeArray(array, newSize) {
function resizeArray (array, newSize) {

Check failure on line 30 in cocos/spine/lib/spine-define.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Missing return type on function
if (!array) return new Array(newSize);

Check failure on line 31 in cocos/spine/lib/spine-define.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any[]` typed value
if (newSize == array.length) return array;
if (newSize === array.length) return array;

Check failure on line 32 in cocos/spine/lib/spine-define.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value
if (newSize < array.length) return array.slice(0, newSize);

Check failure on line 33 in cocos/spine/lib/spine-define.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value
else return new Array(newSize);
}
Expand Down Expand Up @@ -96,13 +94,7 @@ function overrideDefinePtrStringFunction (prototype: any, getPtr: any, name: str
let str = '';
const ptr = getPtr.call(this);
const HEAPU8 = spine.wasmUtil.wasm.HEAPU8;
/*
let length = this.length + ptr;
for (let i = ptr; i < length; ++i) {
str += String.fromCharCode(HEAPU8[i]);
}
*/
let length = this.length;
const length = this.length;
const buffer = HEAPU8.subarray(ptr, ptr + length);
str = String.fromCharCode(...buffer);
return str;
Expand Down Expand Up @@ -203,8 +195,8 @@ function overrideProperty_String (): void {
{
proto: prototype,
property: 'str',
getter: prototype.str
}
getter: prototype.str,
},
];
propertyPolyfills.forEach((prop): void => {
js.get(prop.proto, prop.property, prop.getter);
Expand All @@ -225,7 +217,7 @@ function overrideProperty_Vector2 (): void {
proto: prototype,
property: 'y',
getter: prototype.getY,
setter: prototype.setY
setter: prototype.setY,
},
];
propertyPolyfills.forEach((prop): void => {
Expand Down Expand Up @@ -813,8 +805,8 @@ function overrideProperty_RegionAttachment (): void {
return array;
},
set (value: number[]) {
setUVs.call(this, value[0], value[1], value[2], value[3], value[4] == 1);
}
setUVs.call(this, value[0], value[1], value[2], value[3], value[4] === 1);
},
});

const originComputeWorldVertices = prototype.computeWorldVertices;
Expand Down Expand Up @@ -1331,7 +1323,7 @@ function overrideProperty_Skin (): void {
overrideDefineArrayProp(prototype, prototype.getAttachments, 'attachments');
overrideDefineArrayProp(prototype, prototype.getConstraints, 'constraints');
overrideDefineArrayFunction(prototype, prototype.getAttachments, 'getAttachments');
const originGetAttachmentsForSlot = prototype.getAttachmentsForSlot;
const originGetAttachmentsForSlot = prototype.getAttachmentsForSlot;
Object.defineProperty(prototype, 'getAttachmentsForSlot', {
value (slotIndex: number, attachments: Array<spine.SkinEntry>) {
const vectors = originGetAttachmentsForSlot.call(this, slotIndex);
Expand Down
19 changes: 3 additions & 16 deletions cocos/spine/skeleton-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,13 @@ export class AnimationCache {
modelData.vData = vUint8Buf;
modelData.iData = iUint16Buf;

/*
const meshes = model.getMeshes();
const count = meshes.size();
for (let i = 0; i < count; i++) {
const mesh = meshes.get(i);
const meshData = new SpineDrawItem();
meshData.iCount = mesh.iCount;
meshData.blendMode = mesh.blendMode;
meshData.textureID = mesh.textureID;
modelData.meshes.push(meshData);
}
*/

const data = model.getData();
const count = data.size();
for (let i = 0; i < count; i += 6) {
const meshData = new SpineDrawItem();
meshData.iCount = data.get(i+3);
meshData.blendMode = data.get(i+4);
meshData.textureID = data.get(i+5);
meshData.iCount = data.get(i + 3);
meshData.blendMode = data.get(i + 4);
meshData.textureID = data.get(i + 5);
modelData.meshes.push(meshData);
}

Expand Down
4 changes: 1 addition & 3 deletions cocos/spine/skeleton-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ export class SkeletonSystem extends System {
return;
}
this.index++;
if(!EDITOR_NOT_IN_PREVIEW) spine.SkeletonSystem.updateAnimation(dt);
if (!EDITOR_NOT_IN_PREVIEW) spine.SkeletonSystem.updateAnimation(dt);
this._skeletons.forEach((skeleton) => {
skeleton.updateAnimation(dt);
//skeleton.syncAttachedNode();
});
//this.index % 500 == 0 && console.log('spine update :', this.index , `count:${spine.SkeletonSystem.getCount()}`);
}

public prepareRenderData (): void {
Expand Down
21 changes: 10 additions & 11 deletions cocos/spine/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ export class Skeleton extends UIRenderer {
private _slotTextures: Map<number, Texture2D> | null = null;

_vLength = 0;
_vBuffer:Uint8Array | null = null;
_vBuffer: Uint8Array | null = null;
_iLength = 0;
_iBuffer:Uint8Array | null = null;
_model:any | undefined;
_tempColor:Color = new Color(1, 1, 1, 1);
_iBuffer: Uint8Array | null = null;
_model: any | undefined;
_tempColor: Color = new Color(1, 1, 1, 1);

constructor () {
super();
Expand Down Expand Up @@ -508,7 +508,7 @@ export class Skeleton extends UIRenderer {
set timeScale (value) {
if (value !== this._timeScale) {
this._timeScale = value;
if(this._instance) {
if (this._instance) {
this._instance.dtRate = this._timeScale * timeScale;
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ export class Skeleton extends UIRenderer {
}
this._sockets = val;
this._updateSocketBindings();
this.attachUtil.init(this);
this.attachUtil.init(this);
}

/**
Expand Down Expand Up @@ -683,7 +683,6 @@ export class Skeleton extends UIRenderer {
super.onDisable();
this._instance.enable = false;
SkeletonSystem.getInstance().remove(this);

}

public onDestroy (): void {
Expand Down Expand Up @@ -1612,10 +1611,10 @@ export class Skeleton extends UIRenderer {
const b = this._color.b / 255.0;
const a = this.node._uiProps.opacity;

if (this._tempColor.r == r ||
this._tempColor.g == g ||
this._tempColor.b == b)
return;
if (this._tempColor.r === r ||
this._tempColor.g === g ||
this._tempColor.b === b)
{ return; }
this._tempColor.set(r, g, b, this._tempColor.a);
this._instance.setColor(r, g, b, a);
}
Expand Down

0 comments on commit d6d04cb

Please sign in to comment.