godot-plateformer/addons/reedscene/act/ActManagerInspector.gd

97 lines
2.7 KiB
GDScript3
Raw Normal View History

2025-12-31 13:07:31 +08:00
@tool
extends EditorInspectorPlugin
# ✅ 由 EditorPlugin 注入
var editor_interface: EditorInterface
func _can_handle(object) -> bool:
return object is ActManager
func _parse_begin(object) -> void:
var act_manager := object as ActManager
var reed_scene := _get_owner_scene(act_manager)
var text := ""
text += "Act Table (Debug)\n"
text += "Act Count: %d\n" % act_manager.prop_state_map.size()
text += "------------------\n"
if reed_scene == null:
text += "ERROR: ActManager must be a direct child of ReedScene.\n"
text += "Current parent: %s\n" % (act_manager.get_parent().name if act_manager.get_parent() else "<null>")
var label := Label.new()
label.text = text
label.autowrap_mode = TextServer.AUTOWRAP_WORD
add_custom_control(label)
return
var props_root := reed_scene.get_node_or_null(reed_scene.props_root_path)
if props_root == null:
text += "ERROR: ReedScene Props root not found: %s\n" % str(reed_scene.props_root_path)
var label2 := Label.new()
label2.text = text
label2.autowrap_mode = TextServer.AUTOWRAP_WORD
add_custom_control(label2)
return
# ✅ 只扫描 Props root 下的 Prop
var prop_index := _scan_props_root_for_props(props_root)
text += "Scene: %s\n" % reed_scene.name
text += "Props Root: %s\n" % str(props_root.get_path())
text += "Prop Count: %d\n" % prop_index.size()
text += "------------------\n"
for prop_id in prop_index.keys():
var info: Dictionary = prop_index[prop_id]
text += "PropID: %d | %s\n" % [int(prop_id), str(info["path"])]
var label := Label.new()
label.text = text
label.autowrap_mode = TextServer.AUTOWRAP_WORD
add_custom_control(label)
##扫描Prop root
func _scan_props_root_for_props(props_root: Node) -> Dictionary:
var result := {}
for prop in props_root.get_children():
if not prop is Node:
continue
# PropComponent 必须在 prop 的最上层子节点集中
var prop_comp := _find_prop_component_in_top_children(prop)
if prop_comp == null:
continue
var pid := prop_comp.prop_id
if result.has(pid):
var old_info: Dictionary = result[pid]
push_warning(
"[ActManagerInspector] Duplicate prop_id under Props root: %d\n A: %s\n B: %s"
% [pid, str(old_info["path"]), str(prop_comp.get_path())]
)
else:
result[pid] = {
"node": prop_comp,
"path": prop_comp.get_path()
}
return result
##获取到Prop下的所有的PropComponent
func _find_prop_component_in_top_children(prop: Node) -> PropComponent:
for child in prop.get_children():
if child is PropComponent:
return child as PropComponent
return null
##获取到ActManager上方的Scene应当自查为ReedScene
func _get_owner_scene(act_manager: ActManager) -> ReedScene:
var p := act_manager.get_parent()
if p is ReedScene:
return p as ReedScene
return null