mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
new way to instance nodes
This commit is contained in:
parent
074edb1e1f
commit
f9069db8be
8 changed files with 47 additions and 25 deletions
|
@ -12,6 +12,9 @@ var _belonging_to: Deck
|
|||
var _id: String
|
||||
var node_type: String
|
||||
|
||||
var description: String
|
||||
var aliases: Array[String]
|
||||
|
||||
var props_to_serialize: Array[StringName]
|
||||
|
||||
enum PortType{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
extends Node
|
||||
|
||||
const BASE_NODE_PATH := "res://classes/deck/nodes/"
|
||||
|
||||
# Dictionary[node_type, NodeDescriptor]
|
||||
var nodes: Dictionary = {}
|
||||
|
||||
|
||||
|
@ -11,12 +13,11 @@ func _init() -> void:
|
|||
while current_file != "":
|
||||
print(current_file)
|
||||
if current_file.ends_with(".gd"):
|
||||
var f := FileAccess.open(BASE_NODE_PATH.path_join(current_file), FileAccess.READ)
|
||||
var line := f.get_line()
|
||||
if !line.begins_with("###type="):
|
||||
current_file = dir.get_next()
|
||||
continue
|
||||
nodes[line.trim_prefix("###type=")] = BASE_NODE_PATH.path_join(current_file)
|
||||
# var f := FileAccess.open(BASE_NODE_PATH.path_join(current_file), FileAccess.READ)
|
||||
var script_path := BASE_NODE_PATH.path_join(current_file)
|
||||
var node: DeckNode = load(script_path).new() as DeckNode
|
||||
var descriptor := NodeDescriptor.new(script_path, node.name, node.description, node.aliases)
|
||||
nodes[node.node_type] = descriptor
|
||||
current_file = dir.get_next()
|
||||
|
||||
|
||||
|
@ -24,4 +25,23 @@ func instance_node(type: String) -> DeckNode:
|
|||
if !nodes.has(type):
|
||||
return null
|
||||
|
||||
return load(nodes[type]).new()
|
||||
return load(nodes[type]["script_path"]).new()
|
||||
|
||||
|
||||
class NodeDescriptor:
|
||||
var name: String
|
||||
var description: String
|
||||
var aliases: String
|
||||
|
||||
var script_path: String
|
||||
|
||||
|
||||
func _init(p_script_path: String, p_name: String, p_description: String, p_aliases: Array[String]) -> void:
|
||||
script_path = p_script_path
|
||||
|
||||
name = p_name
|
||||
description = p_description
|
||||
aliases = p_aliases.reduce(
|
||||
func(accum, el) -> void:
|
||||
accum += el
|
||||
, "")
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
###type=button
|
||||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
name = "Button"
|
||||
node_type = "button"
|
||||
description = "a button"
|
||||
|
||||
add_output_port(
|
||||
Deck.Types.BOOL,
|
||||
"Press me",
|
||||
"button"
|
||||
)
|
||||
|
||||
name = "Button"
|
||||
node_type = name.to_snake_case()
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
###type=get_deck_var
|
||||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
name = "Get Deck Var"
|
||||
node_type = name.to_snake_case()
|
||||
description = "retrieve a deck variable"
|
||||
|
||||
add_output_port(
|
||||
Deck.Types.STRING,
|
||||
"Variable",
|
||||
"field"
|
||||
)
|
||||
|
||||
name = "Get Deck Var"
|
||||
node_type = name.to_snake_case()
|
||||
|
||||
|
||||
func _value_request(from_port: int) -> Variant:
|
||||
var key = ports[0].value_callback.call()
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
extends Node
|
|
@ -1,8 +1,11 @@
|
|||
###type=print
|
||||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
name = "Print"
|
||||
node_type = name.to_snake_case()
|
||||
description = "print a value"
|
||||
|
||||
add_input_port(
|
||||
Deck.Types.STRING,
|
||||
"Text to print",
|
||||
|
@ -21,9 +24,6 @@ func _init() -> void:
|
|||
"label"
|
||||
)
|
||||
|
||||
name = "Print"
|
||||
node_type = name.to_snake_case()
|
||||
|
||||
|
||||
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
if to_port != 1:
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
###type=set_deck_var
|
||||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
name = "Set Deck Var"
|
||||
node_type = name.to_snake_case()
|
||||
description = "set deck variable"
|
||||
|
||||
add_input_port(
|
||||
Deck.Types.STRING,
|
||||
"Variable Name",
|
||||
|
@ -27,9 +30,6 @@ func _init() -> void:
|
|||
"label"
|
||||
)
|
||||
|
||||
name = "Set Deck Var"
|
||||
node_type = name.to_snake_case()
|
||||
|
||||
|
||||
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
if to_port != 2:
|
||||
|
|
|
@ -62,7 +62,7 @@ func _ready() -> void:
|
|||
|
||||
set_var.pressed.connect(
|
||||
func():
|
||||
var node := NodeDB.instance_node("set_deck_varbutton")
|
||||
var node := NodeDB.instance_node("set_deck_var")
|
||||
deck.add_node_inst(node)
|
||||
var node_renderer: DeckNodeRendererGraphNode = NODE_SCENE.instantiate()
|
||||
node_renderer.node = node
|
||||
|
|
Loading…
Reference in a new issue