From 1199bc736a9c1fba80bcb851b380c457c5626a97 Mon Sep 17 00:00:00 2001 From: RedisTKey Date: Thu, 1 Jan 2026 10:47:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _game/LevelDemonstration.tscn | 21 ++++++++++++- addons/reedscene/act/ActManager.gd | 47 ++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/_game/LevelDemonstration.tscn b/_game/LevelDemonstration.tscn index ec4c6e4..878e039 100644 --- a/_game/LevelDemonstration.tscn +++ b/_game/LevelDemonstration.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=4 uid="uid://bj2318o3y68x2"] +[gd_scene load_steps=25 format=4 uid="uid://bj2318o3y68x2"] [ext_resource type="PackedScene" uid="uid://1l06de041i40" path="res://_levels/l_level_1.tscn" id="1_p0ota"] [ext_resource type="PackedScene" uid="uid://cvqehvdjpoar4" path="res://_player/player_controller.tscn" id="2_gslp7"] @@ -14,7 +14,9 @@ [ext_resource type="Script" uid="uid://dsgl7lbyjsiif" path="res://addons/reedscene/act/ActManager.gd" id="12_xja44"] [ext_resource type="Script" uid="uid://5e157vdk6175" path="res://addons/reedscene/scene/ReedScene.gd" id="13_2tycc"] [ext_resource type="Script" uid="uid://pxjf5vst08eo" path="res://addons/reedscene/prop/PropManager.gd" id="14_3ihdv"] +[ext_resource type="Script" uid="uid://fxpk2ot6otfh" path="res://addons/reedscene/act/Act.gd" id="15_3ihdv"] [ext_resource type="Script" uid="uid://dn0ksjoswquf5" path="res://addons/reedscene/scene/SceneManager.gd" id="15_hc6q0"] +[ext_resource type="Script" uid="uid://baqgorvlumyju" path="res://addons/reedscene/act/SingleAct.gd" id="16_hc6q0"] [sub_resource type="Resource" id="Resource_2t6pm"] script = ExtResource("7_2t6pm") @@ -42,6 +44,18 @@ metadata/_custom_type_script = "uid://cdvgq0xqdbagk" [sub_resource type="Resource" id="Resource_xja44"] script = ExtResource("10_m16wo") +[sub_resource type="Resource" id="Resource_hc6q0"] +script = ExtResource("15_3ihdv") +metadata/_custom_type_script = "uid://fxpk2ot6otfh" + +[sub_resource type="Resource" id="Resource_mwuv1"] +script = ExtResource("15_3ihdv") +metadata/_custom_type_script = "uid://fxpk2ot6otfh" + +[sub_resource type="Resource" id="Resource_m325v"] +script = ExtResource("15_3ihdv") +metadata/_custom_type_script = "uid://fxpk2ot6otfh" + [node name="Game" type="Node2D"] [node name="level_1" parent="." instance=ExtResource("1_p0ota")] @@ -109,6 +123,11 @@ TransitionNode = NodePath("Transition") [node name="ActManager" type="Node" parent="ReedScene"] script = ExtResource("12_xja44") +prop_state_map = Dictionary[int, ExtResource("15_3ihdv")]({ +0: SubResource("Resource_hc6q0"), +1: SubResource("Resource_mwuv1"), +2: SubResource("Resource_m325v") +}) [node name="Props" type="Node2D" parent="ReedScene"] script = ExtResource("14_3ihdv") diff --git a/addons/reedscene/act/ActManager.gd b/addons/reedscene/act/ActManager.gd index 661753a..7bb3957 100644 --- a/addons/reedscene/act/ActManager.gd +++ b/addons/reedscene/act/ActManager.gd @@ -4,13 +4,19 @@ class_name ActManager extends Node ##ActManager里记录了一系列的ActID和对应的Act,主要用来同步场景的Act,比如,我们现在使用ActID = 0的Act,那么就会让所有的Act的状态重置回到ActID = 0的Act的状态 @export var prop_state_map: Dictionary[int, Act] = {} - ##用于生成一个基础的Act的工具按钮 @export_tool_button("Generate Default Act") var _gen_default_act: Callable = Callable(self, "_editor_generate_default_act") - +##用于生成一个Empty的工具按钮 +@export_tool_button("Generate Empty Act") +var _gen_empty_act: Callable = Callable(self, "_editor_generate_empty_act") ##是否要输出报错信息 @export var debug_log: bool = false +##关卡的初始Act,默认Clamp到Act的数量,防止出现错误 +@export var init_act_id: int = 0: + set(value): + var max_index := max(prop_state_map.size() - 1, 0) + init_act_id = clamp(value, 0, max_index) signal act_changed(from_act_id: int, to_act_id: int) @@ -43,6 +49,7 @@ func _scan_node_recursive(node: Node, out: Dictionary) -> void: for child in node.get_children(): _scan_node_recursive(child, out) +##生成一个默认的Act func _editor_generate_default_act() -> void: if not Engine.is_editor_hint(): return @@ -78,7 +85,11 @@ func _editor_generate_default_act() -> void: var pid := prop_comp.prop_id var init_state := prop_comp.initial_state_id - act.prop_state_map[pid].state_id = init_state + + var single := SingleAct.new() + single.state_id = init_state + + act.prop_state_map[pid] = single count += 1 prop_state_map[0] = act @@ -93,6 +104,27 @@ func _editor_generate_default_act() -> void: if debug_log: print("[ActManager][Editor] Generated Default Act with", count, "props.") +##生成一个空的Act +func _editor_generate_empty_act() -> void: + if not Engine.is_editor_hint(): + return + + var act := Act.new() + act.prop_state_map.clear() # 明确强调“空 Act” + + var act_id := _find_next_free_act_id() + prop_state_map[act_id] = act + + notify_property_list_changed() + + _editor_popup( + "Empty Act generated successfully.\n\nAct ID: %d\nProp count: 0" % act_id, + "Generate Empty Act - Success" + ) + + if debug_log: + print("[ActManager][Editor] Generated EMPTY Act with id =", act_id) + ## ============================== ## 工具函数 ## ============================== @@ -106,14 +138,23 @@ func _editor_popup(message: String, title: String = "ActManager") -> void: get_tree().root.add_child(dialog) dialog.popup_centered() +##找到场景scene节点 func _get_owner_scene() -> ReedScene: var p := get_parent() if p is ReedScene: return p as ReedScene return null +##找到PropComp func _find_prop_component_top(prop: Node) -> PropComponent: for child in prop.get_children(): if child is PropComponent: return child as PropComponent return null + +##找到最近的空位ActID +func _find_next_free_act_id() -> int: + var id := 0 + while prop_state_map.has(id): + id += 1 + return id