Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
blueloveTH committed Aug 11, 2023
1 parent 15ecd74 commit 9e7a533
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
26 changes: 2 additions & 24 deletions workdir/ct/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._node import Node, get_node
from ._node import Node, get_node, build_scene_tree, print_scene_tree
from ._colors import Colors
from ._tween import Tweener, TweenList
from ._sound import play_sound
Expand All @@ -7,26 +7,4 @@
from ._setup import on_app_update, on_app_end
from ._tilemap import Tilemap

from _ct import *

def build_scene_tree(tree: dict, g, root: Node = None):
root: Node = root or Node._root
for key, child in tree.items():
if key == '_':
for k, v in child.items():
setattr(root, k, v)
continue
name, T = key.split('|')
T = g[T]
node = T(name, parent=root)
if child is not None:
build_scene_tree(child, g, node)

def print_scene_tree(root: Node = None, indent=0):
root: Node = root or Node._root
tp_name = type(root).__name__
if '.' in tp_name:
tp_name = tp_name.split('.')[-1]
print(' '*indent + '-', f'{root.name}|{tp_name}')
for child in root.children.values():
print_scene_tree(child, indent + 2)
from _ct import *
26 changes: 25 additions & 1 deletion workdir/ct/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,28 @@ def on_box2d_post_step(self):
self.rotation = self.b2_body.rotation

def get_node(path: str) -> Node:
return Node._root.get_node(path)
return Node._root.get_node(path)



def build_scene_tree(tree: dict, g, root: Node = None):
root: Node = root or Node._root
for key, child in tree.items():
if key == '_':
for k, v in child.items():
setattr(root, k, v)
continue
name, T = key.split('|')
T = g[T]
node = T(name, parent=root)
if child is not None:
build_scene_tree(child, g, node)

def print_scene_tree(root: Node = None, indent=0):
root: Node = root or Node._root
tp_name = type(root).__name__
if '.' in tp_name:
tp_name = tp_name.split('.')[-1]
print(' '*indent + '-', f'{root.name}|{tp_name}')
for child in root.children.values():
print_scene_tree(child, indent + 2)

0 comments on commit 9e7a533

Please sign in to comment.