-
Notifications
You must be signed in to change notification settings - Fork 28
Test serialization #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test serialization #132
Changes from all commits
edd1f65
4338632
8b41b8d
6a11ebe
eca64ac
2969212
6ff5dbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,13 @@ class IDHandler: | |
return unique_string | ||
|
||
|
||
func generate_text(root_node: TreeNode, start_depth: int = 0) -> String: | ||
static func generate_text(root_node: TreeNode, start_depth: int = 0) -> String: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 yes, these should be static. |
||
var out = PackedStringArray() | ||
generate_text_recursive(root_node, start_depth, out) | ||
return "".join(out) | ||
|
||
|
||
func generate_text_recursive(node: TreeNode, depth: int, out: PackedStringArray): | ||
static func generate_text_recursive(node: TreeNode, depth: int, out: PackedStringArray): | ||
if node.data != "": | ||
out.append("\t".repeat(depth) + node.data + "\n") | ||
|
||
|
@@ -57,3 +57,67 @@ func generate_text_recursive(node: TreeNode, depth: int, out: PackedStringArray) | |
|
||
if node.next: | ||
generate_text_recursive(node.next, depth, out) | ||
|
||
|
||
static func generate_script_from_nodes(nodes: Array[Node], bsd: BlockScriptData) -> String: | ||
var entry_blocks_by_entry_statement: Dictionary = {} | ||
|
||
for block in nodes: | ||
if !(block is Block): | ||
continue | ||
|
||
if block is EntryBlock: | ||
var entry_statement = block.get_entry_statement() | ||
if not entry_blocks_by_entry_statement.has(entry_statement): | ||
entry_blocks_by_entry_statement[entry_statement] = [] | ||
entry_blocks_by_entry_statement[entry_statement].append(block) | ||
|
||
var script: String = "" | ||
|
||
script += "extends %s\n\n" % bsd.script_inherits | ||
|
||
for variable in bsd.variables: | ||
script += "var %s: %s\n\n" % [variable.var_name, type_string(variable.var_type)] | ||
|
||
script += "\n" | ||
|
||
var init_func = TreeNode.new("func _init():") | ||
|
||
for entry_statement in entry_blocks_by_entry_statement: | ||
var entry_blocks: Array[EntryBlock] | ||
entry_blocks.assign(entry_blocks_by_entry_statement[entry_statement]) | ||
script += _generate_script_from_entry_blocks(entry_statement, entry_blocks, init_func) | ||
|
||
if init_func.children: | ||
script += generate_text(init_func) | ||
|
||
return script | ||
|
||
|
||
static func _generate_script_from_entry_blocks(entry_statement: String, entry_blocks: Array[EntryBlock], init_func: TreeNode) -> String: | ||
var script = entry_statement + "\n" | ||
var signal_node: TreeNode | ||
var is_empty = true | ||
|
||
InstructionTree.IDHandler.reset() | ||
|
||
for entry_block in entry_blocks: | ||
var next_block := entry_block.bottom_snap.get_snapped_block() | ||
|
||
if next_block != null: | ||
var instruction_node: TreeNode = next_block.get_instruction_node() | ||
var to_append := generate_text(instruction_node, 1) | ||
script += to_append | ||
script += "\n" | ||
is_empty = false | ||
|
||
if signal_node == null and entry_block.signal_name: | ||
signal_node = TreeNode.new("{0}.connect(_on_{0})".format([entry_block.signal_name])) | ||
|
||
if signal_node: | ||
init_func.add_child(signal_node) | ||
|
||
if is_empty: | ||
script += "\tpass\n\n" | ||
|
||
return script |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,13 @@ signal modified | |
@export var category: String | ||
|
||
## The next block in the line of execution (can be null if end) | ||
@export var bottom_snap_path: NodePath | ||
@export var bottom_snap: SnapPoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering about this. Thanks for doing it! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't have even noticed or bothered except it was making it a lot harder to test it without manually calling |
||
|
||
## The scope of the block (statement of matching entry block) | ||
@export var scope: String = "" | ||
|
||
var bottom_snap: SnapPoint | ||
|
||
|
||
func _ready(): | ||
bottom_snap = get_node_or_null(bottom_snap_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 yes! no need to do this. |
||
mouse_filter = Control.MOUSE_FILTER_IGNORE | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 not worth the generalization, there is a single kind of canvas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, at one point I thought maybe we could have scripts that aren't attached to nodes, which is an interesting idea, but for now
BlockCanvas
has already started accumulating code that is reliant on attaching scripts to a node, so it makes sense to combine them.