Files
pixelheros/assets/script/game/map/TalentItemComp.ts
pan 9f2599e9ec refactor: 统一将 pool_lv 重命名为 card_lv 并清理废弃代码
本次提交完成了全项目范围内的术语统一重构:
1.  将所有`pool_lv`相关变量、字段、注释替换为`card_lv`,对齐卡牌等级的业务含义
2.  移除了配置中冗余的默认`pool_lv`赋值,简化数据结构
3.  删除了废弃的`HlistComp.ts`组件及其元文件
4.  修正了多处逻辑错误,确保卡牌等级正确驱动背景框切换
5.  更新了相关注释和文档,保持代码一致性
2026-07-27 15:54:53 +08:00

87 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file TalentItemComp.ts
* @description 天赋图鉴项组件UI 视图层)
*
* 职责:
* 1. 接收 TalentsComp 下发的天赋卡配置(技能卡)。
* 2. 渲染名称、描述、图标和背景。
* 3. 背景颜色根据 wave 映射为对应的 poolLv。
*
* 依赖:
* - CardSet.CardConfig —— 单条卡牌配置
* - SkillSet —— 获取技能图标
*/
import { _decorator, Label, Sprite, SpriteFrame } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { CardConfig } from "../common/config/CardSet";
import { FieldSkillSet, SkillSet } from "../common/config/SkillSet";
import { CardBgComp } from "./CardBgComp";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "db://oops-framework/core/Oops";
const { ccclass, property } = _decorator;
/** TalentItemComp —— 天赋图鉴项组件 */
@ccclass('TalentItemComp')
@ecs.register('TalentItem', false)
export class TalentItemComp extends CCComp {
@property({ type: Label, tooltip: "天赋名称" })
lbl_name: Label = null!;
@property({ type: Label, tooltip: "天赋说明" })
lbl_info: Label = null!;
@property({ type: Sprite, tooltip: "天赋图标" })
icon: Sprite = null!;
@property({ type: CardBgComp, tooltip: "卡牌背景组件" })
bg: CardBgComp = null!;
/**
* 刷新单条天赋展示
* @param config CardPoolList 中的天赋卡(技能卡)配置
*/
public updateItem(config: CardConfig): void {
if (!config) return;
if (this.lbl_name) this.lbl_name.string = config.name ?? "";
if (this.lbl_info) this.lbl_info.string = config.info ?? "";
// 直接复用 CardSet 中已映射好的 card_lv保证与技能卡牌背景一致
// CardSet 通过 waveToCardLv[wave] 由 SKILL_CARD_WAVES 索引推导wave 1→1, 5→2, 8→3
if (this.bg) {
this.bg.apply(config.card_lv || 1);
}
// 设置图标:驻场卡(skill=undefined 但有 field)走 FieldSkillSet否则走 SkillSet
// 与 SCardComp 保持一致,避免驻场卡无 icon 显示
if (this.icon) {
let iconId: string | undefined;
if (!config.skill && config.field && config.field.length > 0) {
// 驻场卡:用 FieldSkillSet[field[0]].icon
const fieldUuid = config.field[0];
iconId = FieldSkillSet[fieldUuid]?.icon || `${fieldUuid}`;
} else if (config.skill) {
// 技能卡:用 SkillSet[skill].icon
iconId = SkillSet[config.skill]?.icon;
}
if (iconId) {
if (smc.uiconsAtlas) {
const frame = smc.uiconsAtlas.getSpriteFrame(iconId);
if (frame) this.icon.spriteFrame = frame;
} else {
const sf = oops.res.get("game/heros/cards/" + iconId, SpriteFrame) as SpriteFrame;
if (sf) this.icon.spriteFrame = sf;
}
}
}
}
/** ECS 组件移除时销毁节点CCComp 抽象方法实现) */
reset() {
this.node.destroy();
}
}