小修改
This commit is contained in:
parent
d770c55851
commit
1199bc736a
|
|
@ -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://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"]
|
[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://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://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://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://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"]
|
[sub_resource type="Resource" id="Resource_2t6pm"]
|
||||||
script = ExtResource("7_2t6pm")
|
script = ExtResource("7_2t6pm")
|
||||||
|
|
@ -42,6 +44,18 @@ metadata/_custom_type_script = "uid://cdvgq0xqdbagk"
|
||||||
[sub_resource type="Resource" id="Resource_xja44"]
|
[sub_resource type="Resource" id="Resource_xja44"]
|
||||||
script = ExtResource("10_m16wo")
|
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="Game" type="Node2D"]
|
||||||
|
|
||||||
[node name="level_1" parent="." instance=ExtResource("1_p0ota")]
|
[node name="level_1" parent="." instance=ExtResource("1_p0ota")]
|
||||||
|
|
@ -109,6 +123,11 @@ TransitionNode = NodePath("Transition")
|
||||||
|
|
||||||
[node name="ActManager" type="Node" parent="ReedScene"]
|
[node name="ActManager" type="Node" parent="ReedScene"]
|
||||||
script = ExtResource("12_xja44")
|
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"]
|
[node name="Props" type="Node2D" parent="ReedScene"]
|
||||||
script = ExtResource("14_3ihdv")
|
script = ExtResource("14_3ihdv")
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,19 @@ class_name ActManager extends Node
|
||||||
|
|
||||||
##ActManager里记录了一系列的ActID和对应的Act,主要用来同步场景的Act,比如,我们现在使用ActID = 0的Act,那么就会让所有的Act的状态重置回到ActID = 0的Act的状态
|
##ActManager里记录了一系列的ActID和对应的Act,主要用来同步场景的Act,比如,我们现在使用ActID = 0的Act,那么就会让所有的Act的状态重置回到ActID = 0的Act的状态
|
||||||
@export var prop_state_map: Dictionary[int, Act] = {}
|
@export var prop_state_map: Dictionary[int, Act] = {}
|
||||||
|
|
||||||
##用于生成一个基础的Act的工具按钮
|
##用于生成一个基础的Act的工具按钮
|
||||||
@export_tool_button("Generate Default Act")
|
@export_tool_button("Generate Default Act")
|
||||||
var _gen_default_act: Callable = Callable(self, "_editor_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
|
@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)
|
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():
|
for child in node.get_children():
|
||||||
_scan_node_recursive(child, out)
|
_scan_node_recursive(child, out)
|
||||||
|
|
||||||
|
##生成一个默认的Act
|
||||||
func _editor_generate_default_act() -> void:
|
func _editor_generate_default_act() -> void:
|
||||||
if not Engine.is_editor_hint():
|
if not Engine.is_editor_hint():
|
||||||
return
|
return
|
||||||
|
|
@ -78,7 +85,11 @@ func _editor_generate_default_act() -> void:
|
||||||
|
|
||||||
var pid := prop_comp.prop_id
|
var pid := prop_comp.prop_id
|
||||||
var init_state := prop_comp.initial_state_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
|
count += 1
|
||||||
|
|
||||||
prop_state_map[0] = act
|
prop_state_map[0] = act
|
||||||
|
|
@ -93,6 +104,27 @@ func _editor_generate_default_act() -> void:
|
||||||
if debug_log:
|
if debug_log:
|
||||||
print("[ActManager][Editor] Generated Default Act with", count, "props.")
|
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)
|
get_tree().root.add_child(dialog)
|
||||||
dialog.popup_centered()
|
dialog.popup_centered()
|
||||||
|
|
||||||
|
##找到场景scene节点
|
||||||
func _get_owner_scene() -> ReedScene:
|
func _get_owner_scene() -> ReedScene:
|
||||||
var p := get_parent()
|
var p := get_parent()
|
||||||
if p is ReedScene:
|
if p is ReedScene:
|
||||||
return p as ReedScene
|
return p as ReedScene
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
##找到PropComp
|
||||||
func _find_prop_component_top(prop: Node) -> PropComponent:
|
func _find_prop_component_top(prop: Node) -> PropComponent:
|
||||||
for child in prop.get_children():
|
for child in prop.get_children():
|
||||||
if child is PropComponent:
|
if child is PropComponent:
|
||||||
return child as PropComponent
|
return child as PropComponent
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
##找到最近的空位ActID
|
||||||
|
func _find_next_free_act_id() -> int:
|
||||||
|
var id := 0
|
||||||
|
while prop_state_map.has(id):
|
||||||
|
id += 1
|
||||||
|
return id
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue