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