print_tree.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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(node_path="/", depth=None):
  8. print(node_path)
  9. print_node_info(node_path, depth, indent=1)
  10. def print_node_info(parent_path, depth, indent):
  11. if indent - 1 == depth:
  12. return
  13. ws = " "*4*indent
  14. for (child_name, child_id, child_type) in api.get_children(parent_path):
  15. match child_type:
  16. case SceneNodeType.ROOT:
  17. child_type = "root"
  18. case SceneNodeType.WINDOW:
  19. child_type = "window"
  20. case SceneNodeType.WINDOW_INPUT:
  21. child_type = "window_input"
  22. case SceneNodeType.KEYBOARD:
  23. child_type = "keyboard"
  24. case SceneNodeType.MOUSE:
  25. child_type = "mouse"
  26. case SceneNodeType.LAYER:
  27. child_type = "layer"
  28. case SceneNodeType.OBJECT:
  29. child_type = "object"
  30. case SceneNodeType.VECTOR_ART:
  31. child_type = "vector_art"
  32. case SceneNodeType.TEXT:
  33. child_type = "text"
  34. case SceneNodeType.TEXTURE:
  35. child_type = "texture"
  36. case SceneNodeType.FONTS:
  37. child_type = "fonts"
  38. case SceneNodeType.FONT:
  39. child_type = "font"
  40. case SceneNodeType.CHAT_VIEW:
  41. child_type = "chat_view"
  42. case SceneNodeType.EDIT_BOX:
  43. child_type = "edit_box"
  44. case SceneNodeType.CHAT_EDIT:
  45. child_type = "chat_edit"
  46. case SceneNodeType.BUTTON:
  47. child_type = "button"
  48. case SceneNodeType.SETTING_ROOT:
  49. child_type = "setting_root"
  50. case SceneNodeType.SETTING:
  51. child_type = "setting"
  52. desc = f"{ws}{child_name}:{child_id}/"
  53. desc += " "*(50 - len(desc))
  54. desc += f"[{child_type}]"
  55. print(desc)
  56. if parent_path == "/":
  57. child_path = "/" + child_name
  58. else:
  59. child_path = parent_path + "/" + child_name
  60. print_node_info(child_path, depth, indent+1)
  61. for prop in api.get_properties(parent_path):
  62. if prop.type != PropertyType.BUFFER:
  63. prop_val = api.get_property_value(parent_path, prop.name)
  64. if prop.type == PropertyType.STR:
  65. prop_val = [f"\"{pv}\"" for pv in prop_val]
  66. elif prop.type == PropertyType.FLOAT32:
  67. prop_val = "[" + ", ".join(f"{pv:.2f}" for pv in prop_val) + "]"
  68. if len(prop_val) == 1:
  69. prop_val = prop_val[0]
  70. prop_val = f" = {prop_val}"
  71. else:
  72. prop_val = ""
  73. prop_type = PropertyType.to_str(prop.type)
  74. print(f"{ws}{prop.name}: {prop_type}{prop_val}")
  75. if prop.depends:
  76. print(f"{ws} depends: {prop.depends}")
  77. #for sig in api.get_signals(parent_id):
  78. # print(f"{ws}~{sig}")
  79. # for slot_id, slot in api.get_slots(parent_id, sig):
  80. # print(f"{ws}- '{slot}' ({slot_id})")
  81. #for method_name in api.get_methods(parent_id):
  82. # args, results = api.get_method(parent_id, method_name)
  83. # args = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in args]
  84. # results = [f"{name}: " + PropertyType.to_str(typ) for (name, _, typ) in results]
  85. # method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
  86. # print(f"{ws}{method_str}")