Skip to content

Commit

Permalink
Merge pull request #19 from endlessm/godotcon
Browse files Browse the repository at this point in the history
Update plugin & add GodotCon demo
  • Loading branch information
wjt authored Oct 25, 2024
2 parents b496173 + 0f6fb85 commit af353e1
Show file tree
Hide file tree
Showing 193 changed files with 9,528 additions and 8,625 deletions.
43 changes: 35 additions & 8 deletions addons/block_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ Our aim is to reduce the learning curve faced by learners who are on the early p

With this project, we aim to reduce the height of the mountain that such learners have to climb. Specifically, we aim to eliminate the requirement of learners having to simultaneously learn to code while building their first games. Instead of writing GDScript to implement games, this plugin enables learners use block coding. Tools like [Scratch](https://scratch.mit.edu/), [Blockly](https://developers.google.com/blockly), and [MakeCode](https://www.microsoft.com/en-us/makecode) have demonstrated that block coding can be much more accessible and intuitive to beginners than textual programming—we are bringing those concepts into Godot to help learners become familiar with some aspects of Godot itself while simplifying the creation of their first games.

### Constraints

In order to be learner-friendly, we have to implement blocks at a suitable level of abstraction. For example, in GDScript you would typically move a sprite around the screen by examining input events and adjusting a sprite's movement vector accordingly—but we do not wish to express this level of detail in blocks. Instead, we lean much more towards the kinds of blocks you can find in MakeCode Arcade, such as having a single block for "move mySprite with buttons".

Expressing an appropriate layer of abstraction is perhaps the most challenging aspect of this project, and will likely place limits upon what can be achieved with this tool. We do not aim to express the full power of Godot & GDScript with this block coding plugin, but rather, our objective is to provide a gentler introduction to Godot for learners, such that they can get familiar with other aspects of the Godot Editor and learn programming concepts while creating basic games. We envision that learners would use block coding as a stepping stone and then later progress onto learning GDScript.
In order to be learner-friendly, we implement blocks at a suitable level of abstraction. For example, we have blocks that allow the user to trivially connect keyboard input to the movement of a particular game element, and to make the score show up on-screen. That abstraction does place limits on what can be achieved with this tool, while still allowing us to provide a gentler introduction to Godot for learners, such that they can get familiar with other aspects of the Godot Editor and learn programming concepts while creating basic games. We envision that learners would use block coding as a stepping stone and then later progress onto learning GDScript.

That said, we are in no way opposed to having this project grow to be able to create more complex games, as long as it does not negatively affect the experience for early stage learners.

See our [pedagogy and audience documentation](docs/PEDAGOGY.md) for more info.

## Getting Started

1. Install the plugin through the Godot AssetLib searching for the name
Expand All @@ -32,11 +30,11 @@ That said, we are in no way opposed to having this project grow to be able to cr

2. Make sure to enable the plugin in **Project****Project Settings****Plugins**.

3. You're ready to get started! Open a scene, and add a **BlockCode** child node to any node in the scene using the **Add Child Node** menu dialog.
3. You're ready to get started! Open a scene, select a node, and observe that there's a **Block Code** section within the lower central pane of the Godot editor, where you usually find debugging, animation and shader functionality. Click **Block Code** and then use the **Add Block Code** button to create a block canvas.

4. The **Block Code** editor will open in a new tab. Drag blocks from the picker and snap them together to create a script. You can switch to other Block Code scripts by selecting the respective BlockCode node in the scene tree.
4. Drag blocks from the picker and snap them together to create a script. You can switch to other Block Code scripts by selecting the respective node from the scene tree.

5. **Run** the scene to see your Block Code scripts in action. Block Code scripts are attached to the BlockCode node's parent, and are saved to the scene.
5. **Run** the scene to see your Block Code scripts in action. Block Code scripts are saved within the scene.

If you clone the plugin's git repository and open it in Godot, you will be presented with a block-built Pong game as an example.

Expand All @@ -50,6 +48,20 @@ We will now seek feedback from learners, educators and game makers, as well as r
- Should this be a plugin or an extension?
- Should blocks generate GDScript or be dynamically executed?

There is no language or data format stability implemented or expected in these early stages. If you upgrade the block coding plugin within an existing project, expect any existing block scripts to stop working and need reimplementing from scratch. For now, you probably want to avoid updating the plugin within your project if it's meeting your needs, or only doing that very sporadically. We will consider offering stability guarantees in future stages of development.

## General user guidance

Block scripts run against the node where you created them. The "Queue Free" block is going to free that node, not any other.

The selection of available blocks varies based on the node type. For example, create a block script on an `Area2D` and you will notice that you have an `On body entered` signal handling block available. Create a node script on an `AnimationPlayer` node and you will observe blocks for starting and stopping animations.

If you wish to switch context to another node, you need to define a function in that other node, and then call it. Once execution jumps into that function, blocks will now act against that other node, and you'll have access to type-specific blocks belonging to that other node. You'll need do this kind of thing if you want to trigger the freeing of another node, or trigger an animation to start playing. This is both strong in conveying the concepts of objects and encapsulation, while also a bit tedious - we may revisit in future!

We have some high level blocks for simplifying common game elements. Add a SimpleCharacter node to get a game element that can be connected to keyboard input with just one type-specific block. Add a SimpleScoring node to display a score on-screen, accompanied by simple blocks for adjusting that score.

Lean into animations! Godot's animations functionality goes beyond just simple animations of graphics. You can do so much by combining block coding with Godot's powerful animations editor.

## Feedback

Please share feedback in the [Godot Forum Block Coding thread](https://forum.godotengine.org/t/block-coding-high-level-block-based-visual-programming/68941).
Expand Down Expand Up @@ -90,3 +102,18 @@ There are several other GUT command line options for running specific tests.
For example, `-gtest=path/to/test_script_1.gd,path/to/test_script_2.gd` can be
used to run specific test scripts. A specific test function can be specified
with `-gunit_test_name=test_to_run`.

### Using the Development Version of the Plugin

1. If your project already has the BlockCode plugin installed:
1. Ensure you have committed your project to Git, including the `addons/block_code` directory.
At this stage of development, **block code programs written for an older plugin version will
likely not work with a newer version of the plugin**, so it is essential that you take a
snapshot of your project before changing the plugin version.
2. Under *Project**Project Settings…**Plugins*, disable the BlockCode plugin
3. In the *FileSystem* sidebar, delete the `res://addons/block_code` directory
2. Download
[a development snapshot](https://github.com/endlessm/godot-block-coding/archive/main.zip)
3. Under *AssetLib*, click *Import…*, and browse to the `main.zip` file you just downloaded
4. Check the *☑ Ignore assert root* option, and click *Install*
5. Under *Project**Project Settings…**Plugins*, enable the BlockCode plugin
46 changes: 10 additions & 36 deletions addons/block_code/block_code_plugin.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@tool
extends EditorPlugin

const MainPanelScene := preload("res://addons/block_code/ui/main_panel.tscn")
const MainPanel = preload("res://addons/block_code/ui/main_panel.gd")
const Types = preload("res://addons/block_code/types/types.gd")
Expand All @@ -12,7 +13,6 @@ const BlockInspectorPlugin := preload("res://addons/block_code/inspector_plugin/
var block_inspector_plugin: BlockInspectorPlugin

var editor_inspector: EditorInspector
var editor_selection: EditorSelection

var _selected_block_code: BlockCode

Expand All @@ -24,8 +24,6 @@ const DISABLED_CLASSES := [
"ParameterBlock",
"StatementBlock",
"SnapPoint",
"BlockSerialization",
"BlockSerializedProperties",
"BlockScriptSerialization",
"CategoryFactory",
]
Expand All @@ -35,7 +33,6 @@ func _enter_tree():
Types.init_cast_graph()

editor_inspector = EditorInterface.get_inspector()
editor_selection = EditorInterface.get_selection()

main_panel = MainPanelScene.instantiate()
main_panel.script_window_requested.connect(script_window_requested)
Expand Down Expand Up @@ -95,43 +92,20 @@ func _exit_tree():


func _ready():
connect("scene_changed", _on_scene_changed)
editor_inspector.connect("edited_object_changed", _on_editor_inspector_edited_object_changed)
_on_scene_changed(EditorInterface.get_edited_scene_root())
_on_editor_inspector_edited_object_changed()


func _on_scene_changed(scene_root: Node):
main_panel.switch_scene(scene_root)


func _on_editor_inspector_edited_object_changed():
var edited_object = editor_inspector.get_edited_object()
#var edited_node = edited_object as Node
var selected_nodes = editor_selection.get_selected_nodes()

if edited_object is BlockCode:
var block_code_node = edited_object as BlockCode
if block_code_node:
# If a block code node was explicitly selected, activate the
# Block Code panel.
make_bottom_panel_item_visible(main_panel)

if edited_object is BlockCode and selected_nodes.size() == 1 and edited_object.owner and edited_object != _selected_block_code:
# If a BlockCode node is being edited, and it was explicitly selected
# (as opposed to edited in the Inspector alone), select its parent node
# as well. This provides a clearer indication of what is being edited.
# Changing the selection will cause edited_object_changed to fire again,
# so we will return early to avoid duplicate work.
var parent_node = edited_object.get_parent()
if parent_node:
editor_selection.add_node.call_deferred(parent_node)
return

if edited_object and edited_object.get_class() == "MultiNodeEdit":
# If multiple nodes are shown in the inspector, we will find the first
# BlockCode node in the list of selected nodes and use that. This
# occurs when the user selects multiple items in the Scene panel, or
# when we select the parent of a BlockCode node.
edited_object = selected_nodes.filter(func(node): return node is BlockCode).pop_front()

var block_code_node = list_block_code_nodes_for_node(edited_object as Node).pop_front()
else:
# Find the first block code child.
block_code_node = list_block_code_nodes_for_node(edited_object as Node).pop_front()
select_block_code_node(block_code_node)


Expand All @@ -145,15 +119,15 @@ func select_block_code_node(block_code: BlockCode):
if not is_block_code_editable(block_code):
block_code = null

if _selected_block_code:
if is_instance_valid(_selected_block_code):
_selected_block_code.tree_entered.disconnect(_on_selected_block_code_changed)
_selected_block_code.tree_exited.disconnect(_on_selected_block_code_changed)
_selected_block_code.property_list_changed.disconnect(_on_selected_block_code_changed)
editor_inspector.property_edited.disconnect(_on_editor_inspector_property_edited)

_selected_block_code = block_code

if _selected_block_code:
if is_instance_valid(_selected_block_code):
_selected_block_code.tree_entered.connect(_on_selected_block_code_changed)
_selected_block_code.tree_exited.connect(_on_selected_block_code_changed)
_selected_block_code.property_list_changed.connect(_on_selected_block_code_changed)
Expand Down
17 changes: 14 additions & 3 deletions addons/block_code/blocks/communication/add_node_to_group.tres
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bpvefei72nh3a"]
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bpvefei72nh3a"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_5qal7"]
[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="1_auf06"]
[ext_resource type="Script" path="res://addons/block_code/blocks/communication/groups.gd" id="1_p83c7"]

[sub_resource type="Resource" id="Resource_sus0f"]
script = ExtResource("1_auf06")
selected = 0
items = []

[resource]
script = ExtResource("1_5qal7")
name = &"add_node_to_group"
target_node_class = ""
description = "Add the node into the group"
category = "Communication | Groups"
type = 2
variant_type = 0
display_template = "Add {node: OBJECT} to group {group: STRING}"
display_template = "add {node: OBJECT} to group {group: STRING}"
code_template = "{node}.add_to_group({group})"
defaults = {}
defaults = {
"group": SubResource("Resource_sus0f")
}
signal_name = ""
scope = ""
extension_script = ExtResource("1_p83c7")
16 changes: 13 additions & 3 deletions addons/block_code/blocks/communication/add_to_group.tres
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bvrmau8atjx1x"]
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bvrmau8atjx1x"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="1_aom4j"]
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_bcm71"]
[ext_resource type="Script" path="res://addons/block_code/blocks/communication/groups.gd" id="2_42ixf"]

[sub_resource type="Resource" id="Resource_fk0wa"]
script = ExtResource("1_aom4j")
selected = 0
items = []

[resource]
script = ExtResource("1_bcm71")
Expand All @@ -10,8 +17,11 @@ description = "Add this node into the group"
category = "Communication | Groups"
type = 2
variant_type = 0
display_template = "Add to group {group: STRING}"
display_template = "add to group {group: STRING}"
code_template = "add_to_group({group})"
defaults = {}
defaults = {
"group": SubResource("Resource_fk0wa")
}
signal_name = ""
scope = ""
extension_script = ExtResource("2_42ixf")
4 changes: 2 additions & 2 deletions addons/block_code/blocks/communication/area2d_on_entered.tres
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ description = ""
category = "Communication | Methods"
type = 1
variant_type = 0
display_template = "On [body: OBJECT] entered"
code_template = "func _on_body_entered(body: Node2D):
display_template = "when this node collides with [something: OBJECT]"
code_template = "func _on_body_entered(something: Node2D):
"
defaults = {}
signal_name = "body_entered"
Expand Down
4 changes: 2 additions & 2 deletions addons/block_code/blocks/communication/area2d_on_exited.tres
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ description = ""
category = "Communication | Methods"
type = 1
variant_type = 0
display_template = "On [body: OBJECT] exited"
code_template = "func _on_body_exited(body: Node2D):
display_template = "when this node stops colliding with [something: OBJECT]"
code_template = "func _on_body_exited(something: Node2D):
"
defaults = {}
signal_name = "body_exited"
Expand Down
22 changes: 17 additions & 5 deletions addons/block_code/blocks/communication/call_method_group.tres
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c15vtdfihdxb8"]
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://c15vtdfihdxb8"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="1_3nuts"]
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_mlm68"]
[ext_resource type="Script" path="res://addons/block_code/blocks/communication/groups.gd" id="1_of577"]

[sub_resource type="Resource" id="Resource_f4ctg"]
script = ExtResource("1_3nuts")
selected = 0
items = []

[resource]
script = ExtResource("1_mlm68")
name = &"call_method_group"
target_node_class = ""
description = "Calls the method/function on each member of the given group"
category = "Communication | Methods"
type = 2
variant_type = 0
display_template = "Call method {method_name: STRING} in group {group: STRING}"
display_template = "call method {method_name: STRING} in group {group: STRING}"
code_template = "get_tree().call_group({group}, {method_name})"
description = "Calls the method/function on each member of the given group"
category = "Communication | Methods"
defaults = {}
defaults = {
"group": SubResource("Resource_f4ctg")
}
signal_name = ""
scope = ""
extension_script = ExtResource("1_of577")
3 changes: 2 additions & 1 deletion addons/block_code/blocks/communication/call_method_node.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
[resource]
script = ExtResource("1_pg363")
name = &"call_method_node"
target_node_class = ""
description = "Calls the method/function of the given node"
category = "Communication | Methods"
type = 2
variant_type = 0
display_template = "Call method {method_name: STRING} in node {node: OBJECT}"
display_template = "call method {method_name: STRING} on node {node: OBJECT}"
code_template = "{node}.call({method_name})"
defaults = {}
signal_name = ""
Expand Down
3 changes: 2 additions & 1 deletion addons/block_code/blocks/communication/define_method.tres
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
[resource]
script = ExtResource("1_6e473")
name = &"define_method"
target_node_class = ""
description = "Define a method/function with following statements"
category = "Communication | Methods"
type = 1
variant_type = 0
display_template = "Define method {method_name: NIL}"
display_template = "define method {method_name: STRING_NAME}"
code_template = "func {method_name}():"
defaults = {}
signal_name = ""
Expand Down
33 changes: 33 additions & 0 deletions addons/block_code/blocks/communication/get_node.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@tool
extends BlockExtension

const OptionData = preload("res://addons/block_code/code_generation/option_data.gd")
const Util = preload("res://addons/block_code/ui/util.gd")


func _find_paths(paths: Array[NodePath], node: Node, path_root: Node, block_parent: Node):
# Add any non-BlockCode nodes that aren't the parent of the current
# BlockCode node.
if not node is BlockCode:
var node_path: NodePath = Util.node_scene_path(node, block_parent, path_root)
if not node_path in [^"", ^"."]:
paths.append(node_path)

for child in node.get_children():
_find_paths(paths, child, path_root, block_parent)


func get_defaults_for_node(context_node: Node) -> Dictionary:
# The default paths are only needed in the editor.
if not Engine.is_editor_hint():
return {}

var scene_root: Node = EditorInterface.get_edited_scene_root()
var path_root: Node = scene_root.get_parent()
var paths: Array[NodePath]
_find_paths(paths, scene_root, path_root, context_node)

if not paths:
return {}

return {"path": OptionData.new(paths)}
27 changes: 27 additions & 0 deletions addons/block_code/blocks/communication/get_node.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://canpdkahokjqs"]

[ext_resource type="Script" path="res://addons/block_code/code_generation/option_data.gd" id="1_bk47y"]
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_d60g7"]
[ext_resource type="Script" path="res://addons/block_code/blocks/communication/get_node.gd" id="1_we5wl"]

[sub_resource type="Resource" id="Resource_esr4a"]
script = ExtResource("1_bk47y")
selected = 0
items = []

[resource]
script = ExtResource("1_d60g7")
name = &"get_node"
target_node_class = ""
description = "Get the node at the given path"
category = "Communication | Nodes"
type = 3
variant_type = 24
display_template = "{path: NIL}"
code_template = "get_node(\"{path}\")"
defaults = {
"path": SubResource("Resource_esr4a")
}
signal_name = ""
scope = ""
extension_script = ExtResource("1_we5wl")
Loading

0 comments on commit af353e1

Please sign in to comment.