From 41842f2b67d0c92ae8a67c4c32610c8d999dfd1b Mon Sep 17 00:00:00 2001 From: panFD Date: Sun, 23 Aug 2026 23:52:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config,map):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=8A=BD=E7=A6=BB=E5=8D=A1=E7=89=87=E8=83=8C=E6=99=AF=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将多处硬编码的卡片等级背景颜色数组移至公共配置文件, 同时重构英雄列表组件的等级显示逻辑,替换为标签直接赋值。 --- assets/script/game/common/config/GameSet.ts | 6 ++++ assets/script/game/map/CardBgComp.ts | 7 ++-- assets/script/game/map/CardLiteComp.ts | 7 ++-- assets/script/game/map/ChipComp.ts | 6 ++-- assets/script/game/map/HerosListComp.ts | 36 +++++++-------------- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/assets/script/game/common/config/GameSet.ts b/assets/script/game/common/config/GameSet.ts index d8ceed70..7eead1ec 100644 --- a/assets/script/game/common/config/GameSet.ts +++ b/assets/script/game/common/config/GameSet.ts @@ -195,3 +195,9 @@ export function getLvColor(lv: number): Color { default: return Color.WHITE; } } + +/** + * card_lv → 背景颜色节点名映射:1=green 2=blue 3=purple 4=yellow 5=red + * 用于 BG_node 下子节点的显隐切换 + */ +export const CARD_LV_BG_COLORS: string[] = ["green", "blue", "purple", "yellow", "red"]; diff --git a/assets/script/game/map/CardBgComp.ts b/assets/script/game/map/CardBgComp.ts index f3b63659..d28c4ded 100644 --- a/assets/script/game/map/CardBgComp.ts +++ b/assets/script/game/map/CardBgComp.ts @@ -1,14 +1,13 @@ import { _decorator, Component } from "cc"; +import { CARD_LV_BG_COLORS } from "../common/config/GameSet"; const { ccclass } = _decorator; -const POOL_COLORS = ["green", "blue", "purple", "yellow", "red"]; - @ccclass('CardBgComp') export class CardBgComp extends Component { - apply(poolLv: number) { - const color = POOL_COLORS[Math.min(poolLv, 5) - 1]; + apply(card_lv: number) { + const color = CARD_LV_BG_COLORS[Math.min(card_lv, 5) - 1]; this.node.children.forEach(c => c.active = c.name === color); } diff --git a/assets/script/game/map/CardLiteComp.ts b/assets/script/game/map/CardLiteComp.ts index eb47b27a..5cd74285 100644 --- a/assets/script/game/map/CardLiteComp.ts +++ b/assets/script/game/map/CardLiteComp.ts @@ -26,13 +26,12 @@ import { CardConfig, CardType, SpecialRefreshCardList, SpecialUpgradeCardList, C import { SkillCardList } from "../common/config/SCardSet"; import { HeroInfo } from "../common/config/heroSet"; import { SkillSet } from "../common/config/SkillSet"; -import { getLvColor } from "../common/config/GameSet"; +import { getLvColor, CARD_LV_BG_COLORS } from "../common/config/GameSet"; import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; -/** card_lv → BG_node 子节点(颜色)名映射:1=green 2=blue 3=purple 4=yellow 5=red */ -const BG_COLORS = ["green", "blue", "purple", "yellow", "red"]; +/** card_lv → BG_node 子节点(颜色)名映射已移至 GameSet.CARD_LV_BG_COLORS */ /** * CardLiteComp —— 单张卡牌简单视图组件 @@ -225,7 +224,7 @@ export class CardLiteComp extends CCComp { // 背景:按 card_lv 切换颜色底框(BG_node 下为 green/blue/purple/yellow/red 子节点) if (this.BG_node) { const bgLv = Math.min(Math.max(this.cardData.base_card_lv ?? this.cardData.card_lv ?? 1, 1), 5); - const color = BG_COLORS[bgLv - 1]; + const color = CARD_LV_BG_COLORS[bgLv - 1]; this.BG_node.children.forEach(child => child.active = (child.name === color)); } diff --git a/assets/script/game/map/ChipComp.ts b/assets/script/game/map/ChipComp.ts index 7c5e61da..d208ee98 100644 --- a/assets/script/game/map/ChipComp.ts +++ b/assets/script/game/map/ChipComp.ts @@ -15,12 +15,10 @@ import { _decorator, Animation, AnimationClip, Node, Sprite, Vec3, resources } f import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { HeroInfo } from "../common/config/heroSet"; +import { CARD_LV_BG_COLORS } from "../common/config/GameSet"; const { ccclass, property } = _decorator; -/** card_lv → BG_node 子节点(颜色)名映射:1=green 2=blue 3=purple 4=yellow 5=red */ -const BG_COLORS = ["green", "blue", "purple", "yellow", "red"]; - /** * ChipComp —— 单张英雄卡图标/背景视图组件 * @@ -58,7 +56,7 @@ export class ChipComp extends CCComp { // 背景:按 card_lv 切换颜色底框(green/blue/purple/yellow/red) if (this.BG_node) { - const color = BG_COLORS[Math.min(Math.max(hero.card_lv ?? 1, 1), 5) - 1]; + const color = CARD_LV_BG_COLORS[Math.min(Math.max(hero.card_lv ?? 1, 1), 5) - 1]; this.BG_node.children.forEach(child => child.active = (child.name === color)); } diff --git a/assets/script/game/map/HerosListComp.ts b/assets/script/game/map/HerosListComp.ts index 89c7da92..575083aa 100644 --- a/assets/script/game/map/HerosListComp.ts +++ b/assets/script/game/map/HerosListComp.ts @@ -24,10 +24,8 @@ import { oops } from "db://oops-framework/core/Oops"; import { mLogger } from "../common/Logger"; import { HeroInfo, HeroList } from "../common/config/heroSet"; import { buildSkillDesc } from "../common/config/HeroSkillDesc"; -import { CKind } from "../common/config/CardSet"; import { GameEvent } from "../common/config/GameEvent"; -import { HERO_UPGRADE_NEED_FRAGMENTS } from "../common/config/GameSet"; -import { CardBgComp } from "./CardBgComp"; +import { HERO_UPGRADE_NEED_FRAGMENTS, CARD_LV_BG_COLORS } from "../common/config/GameSet"; import { CardLiteComp } from "./CardLiteComp"; import { ChipComp } from "./ChipComp"; import { smc } from "../common/SingletonModuleComp"; @@ -70,8 +68,9 @@ export class HerosListComp extends CCComp { @property(Prefab) card_lite_prefab = null! - @property(Node) - lv_node = null! + /** 卡池等级 Label,直接显示 lv.X */ + @property(Label) + lv_label = null! @property(Node) type_node = null! @@ -270,14 +269,13 @@ export class HerosListComp extends CCComp { this.updateGrowthPanel(uuid) } - private updatePoolLvBg(poolLv: number) { + private updatePoolLvBg(card_lv: number) { if (!this.BG_node) return - const kindName = CKind[CKind.Hero]; + // BG_node 下直接放置颜色节点(green/blue/purple/yellow/red),按卡池等级激活对应颜色 + const color = CARD_LV_BG_COLORS[Math.min(card_lv, 5) - 1] this.BG_node.children.forEach(child => { - child.active = (child.name === kindName); - const bg = child.getComponent(CardBgComp); - if (bg) child.active ? bg.apply(poolLv) : bg.clear(); - }); + child.active = (child.name === color) + }) } private updateCdDisplay(hero: typeof HeroInfo[number]) { @@ -291,20 +289,8 @@ export class HerosListComp extends CCComp { } private updateLvDisplay(hero: typeof HeroInfo[number]) { - if (!this.lv_node) return - const cardLvStr = `lv${hero.card_lv ?? 1}` - this.lv_node.active = true - this.lv_node.children.forEach(child => { - - child.active = (child.name === cardLvStr) - - }) - const widget = this.lv_node.getComponent(Widget) - if (widget) widget.updateAlignment() - this.lv_node.children.forEach(child => { - const childWidget = child.getComponent(Widget) - if (childWidget) childWidget.updateAlignment() - }) + if (!this.lv_label) return + this.lv_label.string = `lv.${hero.card_lv ?? 1}` } private updateTypeDisplay(hero: typeof HeroInfo[number]) {