From 0a5041348e75bd7515197429d181282d9b099f63 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: Sun, 10 May 2026 13:38:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=B0=83=E8=AF=95=E5=B7=A5=E5=85=B7):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AD=A6=E5=99=A8=E8=BF=87=E6=BB=A4=E5=99=A8?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=B9=B6=E9=87=8D=E6=9E=84Feed=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构FeedFilter.gd使用Watcher类来管理状态,并添加新的WeaponFilter组件用于武器过滤 --- components/Debug/WeaponFilter.tscn | 7 +++++++ scripts/Debug/FeedFilter.gd | 21 +++++---------------- scripts/Debug/WeaponFilter.gd | 20 ++++++++++++++++++++ scripts/Debug/WeaponFilter.gd.uid | 1 + 4 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 components/Debug/WeaponFilter.tscn create mode 100644 scripts/Debug/WeaponFilter.gd create mode 100644 scripts/Debug/WeaponFilter.gd.uid diff --git a/components/Debug/WeaponFilter.tscn b/components/Debug/WeaponFilter.tscn new file mode 100644 index 0000000..1b1473e --- /dev/null +++ b/components/Debug/WeaponFilter.tscn @@ -0,0 +1,7 @@ +[gd_scene format=3 uid="uid://dfajyj3000hpq"] + +[ext_resource type="Script" uid="uid://uym0v2p43tm3" path="res://scripts/Debug/WeaponFilter.gd" id="1_0puhl"] + +[node name="WeaponFilter" type="HBoxContainer" unique_id=1023830568] +script = ExtResource("1_0puhl") +clickToRebuild = true diff --git a/scripts/Debug/FeedFilter.gd b/scripts/Debug/FeedFilter.gd index ef88b77..25a9e29 100644 --- a/scripts/Debug/FeedFilter.gd +++ b/scripts/Debug/FeedFilter.gd @@ -1,5 +1,5 @@ @tool -extends HBoxContainer +extends Control enum ComposeMode { ALL, @@ -11,38 +11,28 @@ enum ComposeMode { @export var composeMode: ComposeMode = ComposeMode.ALL @export var clickToRefresh: bool = false -var lastState: bool = false +var state: Watcher = Watcher.new(false) func _ready(): + state.changed.connect(rebuild) rebuild() - -func _physics_process(_delta): - if clickToRefresh != lastState: - lastState = clickToRefresh - rebuild() +func _process(_delta): + state.setState(clickToRefresh) func rebuild(): for i in get_children(): i.queue_free() - var files = DirTool.listdir("res://components/Feeds/") for file in files: var feed = load(file).instantiate() as Feed - - # 检查字段条件 var fieldPassed: bool = true if !targetFields.is_empty(): fieldPassed = checkFieldCondition(feed) - - # 检查主题条件 var topicPassed: bool = true if !targetTopics.is_empty(): topicPassed = checkTopicCondition(feed) - - # 如果两个条件都满足,则添加到容器中 if fieldPassed and topicPassed: add_child(feed) - func checkFieldCondition(feed: Feed) -> bool: var passed: bool = true for targetField in targetFields: @@ -59,7 +49,6 @@ func checkFieldCondition(feed: Feed) -> bool: if passed: break return passed - func checkTopicCondition(feed: Feed) -> bool: var passed: bool = false for targetTopic in targetTopics: diff --git a/scripts/Debug/WeaponFilter.gd b/scripts/Debug/WeaponFilter.gd new file mode 100644 index 0000000..b58b424 --- /dev/null +++ b/scripts/Debug/WeaponFilter.gd @@ -0,0 +1,20 @@ +@tool +extends Control + +@export var clickToRebuild: bool = false + +var watcher = Watcher.new(false) + +func _ready(): + watcher.changed.connect(rebuild) + rebuild() +func _process(_delta): + watcher.setState(clickToRebuild) + +func rebuild(): + for i in get_children(): + i.queue_free() + var files = DirTool.listdir("res://components/Weapons/") + for file in files: + var weapon = load(file).instantiate() as Weapon + add_child(weapon) diff --git a/scripts/Debug/WeaponFilter.gd.uid b/scripts/Debug/WeaponFilter.gd.uid new file mode 100644 index 0000000..55b1620 --- /dev/null +++ b/scripts/Debug/WeaponFilter.gd.uid @@ -0,0 +1 @@ +uid://uym0v2p43tm3