-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement branching nodes, add menu bar; basic save and load
- Loading branch information
Showing
14 changed files
with
267 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
extends Container | ||
|
||
@export var graph: ScriptGraphEdit | ||
@export var file_menu: MenuButton | ||
|
||
func _enter_tree() -> void: | ||
var file_popup := file_menu.get_popup() | ||
file_popup.id_pressed.connect(_on_file_menu_id_pressed) | ||
|
||
func _on_file_menu_id_pressed(id: int) -> void: | ||
match id: | ||
0: | ||
print("New") | ||
for c in graph.get_children(): | ||
if c is GraphNode: | ||
c.queue_free() | ||
|
||
graph.connections.clear() | ||
1: | ||
print("Open") | ||
var file := FileAccess.open("user://test.json", FileAccess.READ) | ||
var data := JSON.parse_string(file.get_as_text()) as Dictionary | ||
print(data) | ||
|
||
var in_conn_data: Array[Dictionary] | ||
var out_conn_data: Array[Dictionary] | ||
|
||
for name_key in data: | ||
var node_data := data[name_key] as Dictionary | ||
var graph_node := (load("res://nodes/"+node_data["t"]) as PackedScene).instantiate() as GraphNode | ||
in_conn_data.append_array(node_data["i"]) | ||
out_conn_data.append_array(node_data["o"]) | ||
graph_node.position_offset = Vector2(node_data["px"], node_data["py"]) | ||
graph_node.size = Vector2(node_data["sx"], node_data["sy"]) | ||
if node_data.has("v"): | ||
graph_node.set_value(node_data["v"]) | ||
graph.add_child(graph_node) | ||
|
||
for in_conn in in_conn_data: | ||
graph.connect_node(in_conn["fn"], in_conn["fp"], in_conn["tn"], in_conn["tp"]) | ||
|
||
for out_conn in out_conn_data: | ||
graph.connect_node(out_conn["fn"], out_conn["fp"], out_conn["tn"], out_conn["tp"]) | ||
2: | ||
print("Save") | ||
var nodes := graph.parse() | ||
var data := {} | ||
|
||
for name_key in nodes: | ||
var node := nodes[name_key] | ||
var node_data := { | ||
"t": node.node.scene_file_path.get_file(), | ||
"px": node.node.position_offset.x, | ||
"py": node.node.position_offset.y, | ||
"sx": node.node.size.x, | ||
"sy": node.node.size.y, | ||
"i": [], | ||
"o": [], | ||
} | ||
|
||
if node.node is ValueGraphNode: | ||
node_data["v"] = node.node.get_value() | ||
|
||
for in_conn in node.in_connections: | ||
node_data["i"].append({ | ||
"fp": in_conn.from_port, | ||
"tp": in_conn.to_port, | ||
"fn": in_conn.from_node.node.name, | ||
"tn": in_conn.to_node.node.name, | ||
}) | ||
|
||
for out_conn in node.out_connections: | ||
node_data["o"].append({ | ||
"fp": out_conn.from_port, | ||
"tp": out_conn.to_port, | ||
"fn": out_conn.from_node.node.name, | ||
"tn": out_conn.to_node.node.name, | ||
}) | ||
|
||
data[name_key] = node_data | ||
|
||
var file := FileAccess.open("user://test.json", FileAccess.WRITE) | ||
file.store_string(JSON.stringify(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://ba0kyhwc8edji |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class_name BranchingGraphNode | ||
extends ExecutableGraphNode | ||
|
||
@warning_ignore("unused_parameter") | ||
func next_flow(out_connections: Array[ScriptGraphEdit.GraphNodeConnection]) -> ScriptGraphEdit.GraphNodeConnection: | ||
push_error("Cannot call function on abstract class") | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://xwkltjh75otp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class_name GraphNodeEquals | ||
extends BranchingGraphNode | ||
|
||
var _decision = null | ||
|
||
func execute(args: Array) -> void: | ||
print("exec called") | ||
print(get_stack()) | ||
_decision = args[0] == args[1] | ||
|
||
func next_flow(out_connections: Array[ScriptGraphEdit.GraphNodeConnection]) -> ScriptGraphEdit.GraphNodeConnection: | ||
if out_connections.is_empty(): | ||
return | ||
elif _decision == null: | ||
push_error("Reading decision before execute") | ||
return | ||
else: | ||
var target_from_port := 0 if _decision else 1 | ||
for conn in out_connections: | ||
print(conn.from_port) | ||
if conn.from_port == target_from_port: | ||
return conn | ||
|
||
push_error("Missing connection") | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://eo4o7tqi5aw0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[gd_scene load_steps=4 format=3 uid="uid://cqe2legqrhp0k"] | ||
|
||
[ext_resource type="Texture2D" uid="uid://bhop1cdyv78s4" path="res://ui/caret-right.svg" id="1_j257i"] | ||
[ext_resource type="Script" uid="uid://dcx1bl2m38n6b" path="res://nodes/executable_node.gd" id="2_fi83x"] | ||
[ext_resource type="Script" uid="uid://eo4o7tqi5aw0" path="res://nodes/equals_node.gd" id="2_nks3r"] | ||
|
||
[node name="EqualsNode" type="GraphNode"] | ||
resizable = true | ||
title = "Equals" | ||
ignore_invalid_connection_type = true | ||
slot/0/left_enabled = true | ||
slot/0/left_type = 69 | ||
slot/0/left_color = Color(1, 1, 1, 1) | ||
slot/0/left_icon = ExtResource("1_j257i") | ||
slot/0/right_enabled = false | ||
slot/0/right_type = 69 | ||
slot/0/right_color = Color(1, 1, 1, 1) | ||
slot/0/right_icon = ExtResource("1_j257i") | ||
slot/0/draw_stylebox = true | ||
slot/1/left_enabled = true | ||
slot/1/left_type = 42 | ||
slot/1/left_color = Color(1, 1, 1, 1) | ||
slot/1/left_icon = null | ||
slot/1/right_enabled = true | ||
slot/1/right_type = 69 | ||
slot/1/right_color = Color(1, 1, 1, 1) | ||
slot/1/right_icon = ExtResource("1_j257i") | ||
slot/1/draw_stylebox = true | ||
slot/2/left_enabled = true | ||
slot/2/left_type = 42 | ||
slot/2/left_color = Color(1, 1, 1, 1) | ||
slot/2/left_icon = null | ||
slot/2/right_enabled = true | ||
slot/2/right_type = 69 | ||
slot/2/right_color = Color(1, 1, 1, 1) | ||
slot/2/right_icon = ExtResource("1_j257i") | ||
slot/2/draw_stylebox = true | ||
script = ExtResource("2_nks3r") | ||
metadata/_custom_type_script = ExtResource("2_fi83x") | ||
|
||
[node name="Flow" type="Label" parent="."] | ||
layout_mode = 2 | ||
|
||
[node name="A" type="HBoxContainer" parent="."] | ||
layout_mode = 2 | ||
theme_override_constants/separation = 16 | ||
|
||
[node name="Left" type="Label" parent="A"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 2 | ||
text = "A" | ||
|
||
[node name="Right" type="Label" parent="A"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 10 | ||
text = "True" | ||
horizontal_alignment = 2 | ||
|
||
[node name="B" type="HBoxContainer" parent="."] | ||
layout_mode = 2 | ||
theme_override_constants/separation = 16 | ||
|
||
[node name="Left" type="Label" parent="B"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 2 | ||
text = "B" | ||
|
||
[node name="Right" type="Label" parent="B"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 10 | ||
text = "False" | ||
horizontal_alignment = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.