Add updating of node properties and node selection
This commit is contained in:
parent
9830aa00ea
commit
c27ad8ccc9
2 changed files with 134 additions and 22 deletions
|
@ -13,7 +13,6 @@ func node_to_tree(node, root=false):
|
|||
n["type"] = node.get_class()
|
||||
n["index"] = node.get_index()
|
||||
n["path"] = "/" + node.get_path().get_concatenated_names()
|
||||
print(n)
|
||||
var c = []
|
||||
for i in node.get_children():
|
||||
c.append(node_to_tree(i))
|
||||
|
@ -21,6 +20,47 @@ func node_to_tree(node, root=false):
|
|||
n["children"] = c
|
||||
return n
|
||||
|
||||
func node_to_props(node):
|
||||
var n = {}
|
||||
n["name"] = node.name
|
||||
n["type"] = node.get_class()
|
||||
n["path"] = "/" + node.get_path().get_concatenated_names()
|
||||
n["props"] = []
|
||||
var props = node.get_property_list()
|
||||
var i = 0
|
||||
# NOTE: I cannot begin to fathom the reasons for why this shit is done
|
||||
# the way that it is, but this is bordering on an exercise
|
||||
# in pure futility at this stage.
|
||||
while i < len(props):
|
||||
var p = props[i]
|
||||
if p["usage"] & 128 == 128:
|
||||
var cat = {}
|
||||
cat["name"] = p["name"]
|
||||
cat["props"] = []
|
||||
|
||||
if i == len(props) - 1:
|
||||
break
|
||||
|
||||
i += 1
|
||||
|
||||
while i < len(props):
|
||||
p = props[i]
|
||||
if p["usage"] & 128 == 128:
|
||||
break
|
||||
if p["usage"] & 4 == 4:
|
||||
var c = {}
|
||||
c["name"] = p["name"]
|
||||
c["value"] = node.get(p["name"])
|
||||
cat["props"].append(c)
|
||||
i += 1
|
||||
|
||||
n["props"].append(cat)
|
||||
else:
|
||||
print(p["name"], " ", p["usage"])
|
||||
break
|
||||
n["props"].reverse()
|
||||
return n
|
||||
|
||||
func parse_command(str: String, peer: StreamPeerTCP):
|
||||
var cmd = JSON.parse_string(str)
|
||||
print(cmd)
|
||||
|
@ -28,20 +68,41 @@ func parse_command(str: String, peer: StreamPeerTCP):
|
|||
"open-scene":
|
||||
print("Opening")
|
||||
EditorInterface.open_scene_from_path(cmd["scene"])
|
||||
|
||||
"select-node":
|
||||
var n = get_node(NodePath(cmd["path"]))
|
||||
EditorInterface.edit_node(n)
|
||||
|
||||
"get-scene-tree":
|
||||
var result = node_to_tree(EditorInterface.get_edited_scene_root(), true)
|
||||
var result = node_to_props(EditorInterface.get_selection().get_selected_nodes()[0])
|
||||
result = JSON.stringify({"for-cmd": "get-selected-node", "value": result})
|
||||
peer.put_data(result.to_utf8_buffer())
|
||||
|
||||
# TODO: this is terrible
|
||||
await get_tree().create_timer(0.05).timeout
|
||||
|
||||
result = node_to_tree(EditorInterface.get_edited_scene_root(), true)
|
||||
result = JSON.stringify({"for-cmd": "get-scene-tree", "value": result})
|
||||
peer.put_data(result.to_utf8_buffer())
|
||||
|
||||
"set-node-name":
|
||||
var n = get_node(NodePath(cmd["path"]))
|
||||
var new_name = cmd["new-name"]
|
||||
print("setting ", n, "'s name as ", new_name)
|
||||
n.name = new_name
|
||||
|
||||
"update-property":
|
||||
var n = get_node(NodePath(cmd["path"]))
|
||||
var prop = cmd["name"]
|
||||
var val = cmd ["new-value"]
|
||||
|
||||
n.set(prop, val)
|
||||
|
||||
_:
|
||||
print("Not a valid command: ", cmd["command"])
|
||||
|
||||
if cmd["command"] != "get-scene-tree":
|
||||
parse_command(JSON.stringify({"command": "get-scene-tree"}), peer)
|
||||
if cmd["command"] != "get-scene-tree":
|
||||
await parse_command(JSON.stringify({"command": "get-scene-tree"}), peer)
|
||||
|
||||
func _enter_tree() -> void:
|
||||
server = TCPServer.new()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue