Skip to content

T35536 renames #178

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

Merged
merged 8 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions addons/block_code/block_code_node/block_code.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class_name BlockCode
extends Node

@export var block_script: BlockScriptData = null
@export var block_script: BlockScriptSerialization = null


func _ready():
Expand All @@ -25,10 +25,10 @@ func _enter_tree():

# Create script
if block_script == null:
var new_bsd: BlockScriptData = load("res://addons/block_code/ui/bsd_templates/default_bsd.tres").duplicate(true)
new_bsd.script_inherits = _get_custom_or_native_class(get_parent())
new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits)
block_script = new_bsd
var new_block_script: BlockScriptSerialization = load("res://addons/block_code/serialization/default_block_script.tres").duplicate(true)
new_block_script.script_inherits = _get_custom_or_native_class(get_parent())
new_block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits)
block_script = new_block_script


func _update_parent_script():
Expand Down
7 changes: 3 additions & 4 deletions addons/block_code/block_code_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ var _selected_block_code: BlockCode
var old_feature_profile: String = ""

const DISABLED_CLASSES := [
"BlockScriptData",
"Block",
"ControlBlock",
"ParameterBlock",
"StatementBlock",
"SnapPoint",
"SerializedBlockTreeNodeArray",
"SerializedBlockTreeNode",
"SerializedBlock",
"BlockSerialization",
"BlockSerializedProperties",
"BlockScriptSerialization",
"CategoryFactory",
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends Object

const BlockDefinition = preload("res://addons/block_code/block_definition.gd")
const BlockDefinition = preload("res://addons/block_code/code_generation/block_definition.gd")
const Types = preload("res://addons/block_code/types/types.gd")

static var _catalog: Dictionary
Expand All @@ -18,7 +18,7 @@ static func setup():
block_definition.category = "Lifecycle"
_catalog[&"ready_block"] = block_definition

block_definition = BlockDefinition.new(&"print", Types.BlockType.EXECUTE)
block_definition = BlockDefinition.new(&"print", Types.BlockType.STATEMENT)
block_definition.label_template = "print {text: STRING}"
block_definition.code_template = "print({text})"
block_definition.defaults = {"text": "Hello"}
Expand Down
141 changes: 58 additions & 83 deletions addons/block_code/examples/pong_game/pong_game.tscn

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class_name BlockScriptData
class_name BlockScriptSerialization
extends Resource

@export var script_inherits: String
@export var block_trees: SerializedBlockTreeNodeArray
@export var block_trees: Array[BlockSerialization]
@export var variables: Array[VariableResource]
@export var generated_script: String
@export var version: int


func _init(p_script_inherits: String = "", p_block_trees: SerializedBlockTreeNodeArray = null, p_variables: Array[VariableResource] = [], p_generated_script: String = "", p_version = 0):
func _init(p_script_inherits: String = "", p_block_trees: Array[BlockSerialization] = [], p_variables: Array[VariableResource] = [], p_generated_script: String = "", p_version = 0):
script_inherits = p_script_inherits
block_trees = p_block_trees
generated_script = p_generated_script
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class_name SerializedBlockTreeNode
class_name BlockSerialization
extends Resource

@export var name: StringName
@export var position: Vector2
@export var path_child_pairs: Array

# TODO: Remove once the data/UI decouple is done.
@export var serialized_block: SerializedBlock
@export var block_serialized_properties: BlockSerializedProperties


func _init(p_name: StringName, p_position: Vector2 = Vector2.ZERO, p_serialized_block: SerializedBlock = null, p_path_child_pairs: Array = []):
func _init(p_name: StringName, p_position: Vector2 = Vector2.ZERO, p_block_serialized_properties: BlockSerializedProperties = null, p_path_child_pairs: Array = []):
name = p_name
position = p_position
serialized_block = p_serialized_block
block_serialized_properties = p_block_serialized_properties
path_child_pairs = p_path_child_pairs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class_name SerializedBlock
class_name BlockSerializedProperties
extends Resource

# TODO: Remove this class after removing the remaining serialization.

@export var block_class: StringName
@export var serialized_props: Array

Expand Down
25 changes: 25 additions & 0 deletions addons/block_code/serialization/default_block_script.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[gd_resource type="Resource" script_class="BlockScriptSerialization" load_steps=6 format=3 uid="uid://dit7fykhl3h48"]

[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialization.gd" id="1_barc5"]
[ext_resource type="Script" path="res://addons/block_code/serialization/block_serialized_properties.gd" id="2_cgfpx"]
[ext_resource type="Script" path="res://addons/block_code/serialization/block_script_serialization.gd" id="4_cqq7x"]

[sub_resource type="Resource" id="Resource_b0aen"]
script = ExtResource("2_cgfpx")
block_class = &"EntryBlock"
serialized_props = [["color", Color(0.92549, 0.231373, 0.34902, 1)], ["scope", ""], ["param_input_strings", {}]]

[sub_resource type="Resource" id="Resource_1h6wi"]
script = ExtResource("1_barc5")
name = &"ready_block"
position = Vector2(54, 47)
path_child_pairs = []
block_serialized_properties = SubResource("Resource_b0aen")

[resource]
script = ExtResource("4_cqq7x")
script_inherits = "INHERIT_DEFAULT"
block_trees = Array[ExtResource("1_barc5")]([SubResource("Resource_1h6wi")])
variables = Array[Resource("res://addons/block_code/ui/block_canvas/variable_resource.gd")]([])
generated_script = "extends INHERIT_DEFAULT"
version = 0
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static func get_custom_blocks() -> Array[Block]:
# Movement
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_name = "simplecharacter_move"
b.block_type = Types.BlockType.EXECUTE
b.block_type = Types.BlockType.STATEMENT
b.block_format = "Move with {player: OPTION} buttons as {kind: OPTION}"
# TODO: delta here is assumed to be the parameter name of
# the _process or _physics_process method:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ static func get_custom_blocks() -> Array[Block]:
for player in _POSITIONS_FOR_PLAYER:
b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_name = "simplescoring_set_score"
b.block_type = Types.BlockType.EXECUTE
b.block_type = Types.BlockType.STATEMENT
b.block_format = "Set player %s score to {score: INT}" % player
b.statement = "score_%s = {score}" % _POSITIONS_FOR_PLAYER[player]
b.category = "Info | Score"
block_list.append(b)

b = CategoryFactory.BLOCKS["statement_block"].instantiate()
b.block_name = "simplescoring_change_score"
b.block_type = Types.BlockType.EXECUTE
b.block_type = Types.BlockType.STATEMENT
b.block_format = "Change player %s score by {score: INT}" % player
b.statement = "score_%s += {score}" % _POSITIONS_FOR_PLAYER[player]
b.category = "Info | Score"
Expand Down
3 changes: 2 additions & 1 deletion addons/block_code/types/types.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ extends Node
enum BlockType {
NONE,
ENTRY,
EXECUTE,
STATEMENT,
VALUE,
CONTROL,
}

const VARIANT_TYPE_TO_STRING: Dictionary = {
Expand Down
47 changes: 20 additions & 27 deletions addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ZOOM_FACTOR: float = 1.1
@onready var _mouse_override: Control = %MouseOverride
@onready var _zoom_label: Label = %ZoomLabel

var _current_bsd: BlockScriptData
var _current_block_script: BlockScriptSerialization
var _block_scenes_by_class = {}
var _panning := false
var zoom: float:
Expand Down Expand Up @@ -96,12 +96,12 @@ func set_child(n: Node):
set_child(c)


func bsd_selected(bsd: BlockScriptData):
func block_script_selected(block_script: BlockScriptSerialization):
clear_canvas()

var edited_node = EditorInterface.get_inspector().get_edited_object() as Node

if bsd != _current_bsd:
if block_script != _current_block_script:
_window.position = Vector2(0, 0)
zoom = 1

Expand All @@ -115,18 +115,18 @@ func bsd_selected(bsd: BlockScriptData):
_open_scene_button.disabled = true
_replace_block_code_button.disabled = true

if bsd != null:
_load_bsd(bsd)
if block_script != null:
_load_block_script(block_script)
_window.visible = true
_zoom_label.visible = true

if bsd != _current_bsd:
if block_script != _current_block_script:
reset_window_position()
elif edited_node == null:
_empty_box.visible = true
elif BlockCodePlugin.node_has_block_code(edited_node):
# If the selected node has a block code node, but BlockCodePlugin didn't
# provide it to bsd_selected, we assume the block code itself is not
# provide it to block_script_selected, we assume the block code itself is not
# editable. In that case, provide options to either edit the node's
# scene file, or override the BlockCode node. This is mostly to avoid
# creating a situation where a node has multiple BlockCode nodes.
Expand All @@ -139,35 +139,28 @@ func bsd_selected(bsd: BlockScriptData):
_selected_node_label.text = _selected_node_label_format.format({"node": edited_node.name})
_add_block_code_button.disabled = false

_current_bsd = bsd
_current_block_script = block_script


func _load_bsd(bsd: BlockScriptData):
for tree in bsd.block_trees.array:
func _load_block_script(block_script: BlockScriptSerialization):
for tree in block_script.block_trees:
load_tree(_window, tree)


func scene_has_bsd_nodes() -> bool:
var scene_root = EditorInterface.get_edited_scene_root()
if not scene_root:
return false
return scene_root.find_children("*", "BlockCode").size() > 0


func clear_canvas():
for child in _window.get_children():
_window.remove_child(child)
child.queue_free()


func load_tree(parent: Node, node: SerializedBlockTreeNode):
func load_tree(parent: Node, node: BlockSerialization):
var scene: Block = Util.instantiate_block(node.name)

# TODO: Remove once the data/UI decouple is done.
if scene == null:
var _block_scene_path = _block_scenes_by_class[node.serialized_block.block_class]
var _block_scene_path = _block_scenes_by_class[node.block_serialized_properties.block_class]
scene = load(_block_scene_path).instantiate()
for prop_pair in node.serialized_block.serialized_props:
for prop_pair in node.block_serialized_properties.serialized_props:
scene.set(prop_pair[0], prop_pair[1])

scene.position = node.position
Expand All @@ -182,14 +175,14 @@ func load_tree(parent: Node, node: SerializedBlockTreeNode):


func rebuild_block_trees(undo_redo):
var block_trees_array: Array[SerializedBlockTreeNode]
var block_trees: Array[BlockSerialization]
for c in _window.get_children():
block_trees_array.append(build_tree(c, undo_redo))
undo_redo.add_undo_property(_current_bsd.block_trees, "array", _current_bsd.block_trees.array)
undo_redo.add_do_property(_current_bsd.block_trees, "array", block_trees_array)
block_trees.append(build_tree(c, undo_redo))
undo_redo.add_undo_property(_current_block_script, "block_trees", _current_block_script.block_trees)
undo_redo.add_do_property(_current_block_script, "block_trees", block_trees)


func build_tree(block: Block, undo_redo: EditorUndoRedoManager) -> SerializedBlockTreeNode:
func build_tree(block: Block, undo_redo: EditorUndoRedoManager) -> BlockSerialization:
var path_child_pairs = []
block.update_resources(undo_redo)

Expand Down Expand Up @@ -326,6 +319,6 @@ func set_mouse_override(override: bool):
_mouse_override.mouse_default_cursor_shape = Control.CURSOR_ARROW


func generate_script_from_current_window(bsd: BlockScriptData) -> String:
func generate_script_from_current_window(block_script: BlockScriptSerialization) -> String:
# TODO: implement multiple windows
return BlockTreeUtil.generate_script_from_nodes(_window.get_children(), bsd)
return BlockTreeUtil.generate_script_from_nodes(_window.get_children(), block_script)

This file was deleted.

6 changes: 3 additions & 3 deletions addons/block_code/ui/block_tree_util.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends Object
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")


static func generate_script_from_nodes(nodes: Array[Node], bsd: BlockScriptData) -> String:
static func generate_script_from_nodes(nodes: Array[Node], block_script: BlockScriptSerialization) -> String:
var entry_blocks_by_entry_statement: Dictionary = {}

for block in nodes:
Expand All @@ -18,9 +18,9 @@ static func generate_script_from_nodes(nodes: Array[Node], bsd: BlockScriptData)

var script: String = ""

script += "extends %s\n\n" % bsd.script_inherits
script += "extends %s\n\n" % block_script.script_inherits

for variable in bsd.variables:
for variable in block_script.variables:
script += "var %s: %s\n\n" % [variable.var_name, type_string(variable.var_type)]

script += "\n"
Expand Down
16 changes: 8 additions & 8 deletions addons/block_code/ui/blocks/block/block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class_name Block
extends MarginContainer

const BlocksCatalog = preload("res://addons/block_code/blocks_catalog.gd")
const BlocksCatalog = preload("res://addons/block_code/code_generation/blocks_catalog.gd")
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
const Types = preload("res://addons/block_code/types/types.gd")

Expand All @@ -19,7 +19,7 @@ signal modified
@export var color: Color = Color(1., 1., 1.)

## Type of block to check if can be attached to snap point
@export var block_type: Types.BlockType = Types.BlockType.EXECUTE
@export var block_type: Types.BlockType = Types.BlockType.STATEMENT

## Category to add the block to
@export var category: String
Expand All @@ -32,7 +32,7 @@ signal modified
@export var scope: String = ""

## The resource containing the block properties and the snapped blocks
@export var resource: SerializedBlockTreeNode
@export var resource: BlockSerialization

# FIXME: Add export to this variable and remove bottom_snap_path above.
# There is a bug in Godot 4.2 that prevents using SnapPoint directly:
Expand Down Expand Up @@ -117,8 +117,8 @@ func get_instruction_node() -> InstructionTree.TreeNode:

func update_resources(undo_redo: EditorUndoRedoManager):
if resource == null:
var serialized_block = SerializedBlock.new(get_block_class(), get_serialized_props())
resource = SerializedBlockTreeNode.new(block_name, position, serialized_block)
var block_serialized_properties = BlockSerializedProperties.new(get_block_class(), get_serialized_props())
resource = BlockSerialization.new(block_name, position, block_serialized_properties)
return

if resource.position != position:
Expand All @@ -127,9 +127,9 @@ func update_resources(undo_redo: EditorUndoRedoManager):

var serialized_props = get_serialized_props()

if serialized_props != resource.serialized_block.serialized_props:
undo_redo.add_undo_property(resource.serialized_block, "serialized_props", resource.serialized_block.serialized_props)
undo_redo.add_do_property(resource.serialized_block, "serialized_props", serialized_props)
if serialized_props != resource.block_serialized_properties.serialized_props:
undo_redo.add_undo_property(resource.block_serialized_properties, "serialized_props", resource.block_serialized_properties.serialized_props)
undo_redo.add_do_property(resource.block_serialized_properties, "serialized_props", serialized_props)


# Override this method to add more serialized properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var param_input_strings: Dictionary # Only loaded from serialized
func _ready():
super()

if block_type != Types.BlockType.EXECUTE:
if block_type != Types.BlockType.STATEMENT:
_background.show_top = false
_background.color = color

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends MarginContainer

const Types = preload("res://addons/block_code/types/types.gd")

@export var block_type: Types.BlockType = Types.BlockType.EXECUTE
@export var block_type: Types.BlockType = Types.BlockType.STATEMENT

@export var snapped_block: Block:
get:
Expand Down
Loading