fix: 更新提交

This commit is contained in:
han_han9
2025-11-26 22:57:07 +08:00
parent 8a6620cf8f
commit 4c16bec13f
640 changed files with 70914 additions and 13327 deletions

View File

@@ -0,0 +1,82 @@
import { Component, _decorator, sp } from "cc";
import { COMMON_FACE_ANIM, DRESS_PART, IDressInfo, PET_ANIM_NAME, PET_BODY_FACE_ANIM_MAP, PetInfo } from "./Types";
import { autoBind } from "@max-studio/core/ui/UIDecorator";
import { BasePart } from "./BasePart";
import { GlarePart } from "./GlarePart";
const { ccclass } = _decorator;
@ccclass("BasePet")
export class BasePet extends Component {
private petInfo: PetInfo;
@autoBind("RootNode/PetAni", sp.Skeleton)
private petBodySkeleton: sp.Skeleton = null;
@autoBind("RootNode/PetAni/face", sp.Skeleton)
private petFace: sp.Skeleton = null;
private parts: Map<DRESS_PART, BasePart> = new Map();
protected onLoad(): void {
this.parts.set(DRESS_PART.GLARE, new GlarePart(this.petBodySkeleton, DRESS_PART.GLARE));
this.parts.set(DRESS_PART.BAG, new BasePart(this.petBodySkeleton, DRESS_PART.BAG));
this.parts.set(DRESS_PART.GLASSES, new BasePart(this.petBodySkeleton, DRESS_PART.GLASSES));
this.parts.set(DRESS_PART.HAT, new BasePart(this.petBodySkeleton, DRESS_PART.HAT));
this.parts.set(DRESS_PART.ACCESS, new BasePart(this.petBodySkeleton, DRESS_PART.ACCESS));
}
public setInfo(info: PetInfo) {
this.petInfo = info;
}
public getInfo(): PetInfo {
return this.petInfo;
}
public async putOn(info: IDressInfo) {
const { type, sourceLocationType, sourceName } = info;
if (type == DRESS_PART.SUIT) {
if (info.dressMap) {
info.dressMap.forEach(async (dressInfo) => {
await this.parts.get(dressInfo.type)?.putOn(dressInfo);
});
}
return;
}
await this.parts.get(type)?.putOn(info);
}
public takeOff(type: DRESS_PART = DRESS_PART.ALL) {
if (type == DRESS_PART.ALL) {
this.parts.forEach((part) => {
part.takeOff();
});
} else {
this.parts.get(type)?.takeOff();
}
}
public playAnim(anim: PET_ANIM_NAME) {
this.petBodySkeleton.setAnimation(0, anim, true);
const faceAnim = PET_BODY_FACE_ANIM_MAP[anim] ?? PET_ANIM_NAME.IDLE;
this.petFace.setAnimation(0, faceAnim, true);
this.setFaceSkinFromAnim(faceAnim);
}
protected setFaceSkinFromAnim(faceAnim: PET_ANIM_NAME) {
let faceSkin: string = faceAnim;
if (!COMMON_FACE_ANIM.includes(faceAnim)) {
faceSkin = `eye/${this.petInfo.name}`;
}
this.petFace.setSkin(faceSkin);
this.petFace._skeleton?.slots.forEach((slot) => {
const slotName = slot.data.name.toLowerCase();
if (slotName.endsWith("_hui")) {
slot.color.a = slotName == `${this.petInfo.name}_hui`.toLowerCase() ? 1 : 0;
}
if (slotName.startsWith("dk")) {
console.log("slotName:", slotName);
}
});
}
}