print_tree.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from pydrk import SceneNodeType, PropertyType
  2. from .api import api
  3. def join(parent_path, child_name):
  4. if parent_path == "/":
  5. return f"/{child_name}"
  6. return f"{parent_path}/{child_name}"
  7. def print_tree():
  8. root_id = api.lookup_node_id("/")
  9. print("/")
  10. print_node_info(root_id, indent=1)
  11. def print_node_info(parent_id, indent):
  12. ws = " "*4*indent
  13. for (child_name, child_id, child_type) in api.get_children(parent_id):
  14. match child_type:
  15. case SceneNodeType.ROOT:
  16. child_type = "root"
  17. case SceneNodeType.WINDOW:
  18. child_type = "window"
  19. case SceneNodeType.WINDOW_INPUT:
  20. child_type = "window_input"
  21. case SceneNodeType.KEYBOARD:
  22. child_type = "keyboard"
  23. case SceneNodeType.MOUSE:
  24. child_type = "mouse"
  25. case SceneNodeType.RENDER_LAYER:
  26. child_type = "render_layer"
  27. case SceneNodeType.RENDER_OBJECT:
  28. child_type = "render_object"
  29. case SceneNodeType.RENDER_MESH:
  30. child_type = "render_mesh"
  31. case SceneNodeType.RENDER_TEXT:
  32. child_type = "render_text"
  33. case SceneNodeType.RENDER_TEXTURE:
  34. child_type = "render_texture"
  35. case SceneNodeType.FONTS:
  36. child_type = "fonts"
  37. case SceneNodeType.FONT:
  38. child_type = "font"
  39. case SceneNodeType.CHAT_VIEW:
  40. child_type = "chat_view"
  41. case SceneNodeType.EDIT_BOX:
  42. child_type = "edit_box"
  43. desc = f"{ws}{child_name}:{child_id}/"
  44. desc += " "*(50 - len(desc))
  45. desc += f"[{child_type}]"
  46. print(desc)
  47. print_node_info(child_id, indent+1)
  48. for prop in api.get_properties(parent_id):
  49. if prop.type != PropertyType.BUFFER:
  50. prop_val = api.get_property_value(parent_id, prop.name)
  51. if prop.type == PropertyType.STR:
  52. prop_val = [f"\"{pv}\"" for pv in prop_val]
  53. if len(prop_val) == 1:
  54. prop_val = prop_val[0]
  55. prop_val = f" = {prop_val}"
  56. else:
  57. prop_val = ""
  58. prop_type = PropertyType.to_str(prop.type)
  59. print(f"{ws}{prop.name}: {prop_type}{prop_val}")
  60. for sig in api.get_signals(parent_id):
  61. print(f"{ws}~{sig}")
  62. for slot_id, slot in api.get_slots(parent_id, sig):
  63. print(f"{ws}- '{slot}' ({slot_id})")
  64. for method_name in api.get_methods(parent_id):
  65. args, results = api.get_method(parent_id, method_name)
  66. args = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in args]
  67. results = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in results]
  68. method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
  69. print(f"{ws}{method_str}")