26 lines
693 B
TypeScript
Raw Normal View History

2022-12-08 21:14:02 +08:00
import { SpriteFrame } from "cc";
2022-11-27 23:23:47 +08:00
2022-12-08 21:14:02 +08:00
const INDEX_REG = /\((\d+)\)/;
2022-11-27 23:23:47 +08:00
2022-12-08 21:14:02 +08:00
const getNumberWithinString = (str: string) => parseInt(str.match(INDEX_REG)?.[1] || "0");
2022-11-27 23:23:47 +08:00
export const sortSpriteFrame = (spriteFrame: Array<SpriteFrame>) =>
2022-12-08 21:14:02 +08:00
spriteFrame.sort((a, b) => getNumberWithinString(a.name) - getNumberWithinString(b.name));
2022-11-27 23:23:47 +08:00
2022-12-08 21:14:02 +08:00
export const rad2Angle = (rad: number) => (rad / Math.PI) * 180;
export const deepClone = (obj: any) => {
if (typeof obj !== "object" || obj === null) {
return obj;
}
const res = Array.isArray(obj) ? [] : {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
res[key] = deepClone(obj[key]);
}
}
return res;
};