From 15106f733fbb9c6438a08895fef49a583c0e73b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Tue, 30 Sep 2025 17:39:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Feed.gd):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=86=97=E4=BD=99=E7=9A=84UIState.player=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化代码逻辑,假设UIState.player始终有效,移除多处不必要的有效性检查 --- scripts/Structs/Feed.gd | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/Structs/Feed.gd b/scripts/Structs/Feed.gd index eccd24f..42863c0 100644 --- a/scripts/Structs/Feed.gd +++ b/scripts/Structs/Feed.gd @@ -67,10 +67,7 @@ func apply(entity: EntityBase): func countOf(index: int) -> int: return ceil(costCounts[index] * multipiler()) func multipiler() -> float: - if is_instance_valid(UIState.player): - return 1 - UIState.player.fields.get(FieldStore.Entity.PRICE_REDUCTION) - else: - return 1 + return 1 - UIState.player.fields.get(FieldStore.Entity.PRICE_REDUCTION) func rebuildInfo(): avatarRect.texture = avatarTexture nameLabel.displayName = displayName @@ -86,8 +83,7 @@ func rebuildInfo(): var fieldShow: FieldShow = ComponentManager.getUIComponent("FieldShow").instantiate() fieldShow.field = field fieldShow.value = value - if is_instance_valid(UIState.player): - fieldShow.maxed = value + UIState.player.fields[field] > FieldStore.entityMaxValueMap.get(field, INF) + fieldShow.maxed = value + UIState.player.fields[field] > FieldStore.entityMaxValueMap.get(field, INF) fieldsBox.add_child(fieldShow) if noField: fieldsBox.add_child(QuickUI.smallText("无词条")) @@ -96,8 +92,7 @@ func rebuildInfo(): for weapon in weapons: var weaponShow: WeaponShow = ComponentManager.getUIComponent("WeaponShow").instantiate() weaponShow.weapon = weapon - if is_instance_valid(UIState.player): - weaponShow.operation = WeaponShow.Operation.EXTRACT if UIState.player.weaponBag.has(weapon.instantiate().displayName) else WeaponShow.Operation.GET + weaponShow.operation = WeaponShow.Operation.EXTRACT if UIState.player.weaponBag.has(weapon.instantiate().displayName) else WeaponShow.Operation.GET weaponShow.visible = true weaponsBox.add_child(weaponShow) for i in costsBox.get_children(): @@ -106,7 +101,7 @@ func rebuildInfo(): var cost = costs[i] var count = countOf(i) var costShow: ItemShow = ComponentManager.getUIComponent("ItemShow").instantiate() - costShow.enough = is_instance_valid(UIState.player) and UIState.player.inventory[cost] >= count + costShow.enough = UIState.player.inventory[cost] >= count costShow.type = cost costShow.count = count costsBox.add_child(costShow)