8000 Add RigidBody2D block definitions · endlessm/godot-block-coding@575e7c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 575e7c8

Browse files
committed
Add RigidBody2D block definitions
https://phabricator.endlessm.com/T35591
1 parent 9514bbb commit 575e7c8

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dl1xd1jit2mlp"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_v2421"]
4+
5+
[resource]
6+
script = ExtResource("1_v2421")
7+
name = &"rigidbody2d_on_entered"
8+
target_node_class = "RigidBody2D"
9+
description = ""
10+
category = "Communication | Methods"
11+
type = 1
12+
variant_type = 0
13+
display_template = "On [body: OBJECT] entered"
14+
code_template = "func _on_body_entered(body: Node2D):
15+
"
16+
defaults = {}
17+
signal_name = "body_entered"
18+
scope = ""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c15ymi1kxb570"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_sahiu"]
4+
5+
[resource]
6+
script = ExtResource("1_sahiu")
7+
name = &"rigidbody2d_on_exited"
8+
target_node_class = "RigidBody2D"
9+
description = ""
10+
category = "Communication | Methods"
11+
type = 1
12+
variant_type = 0
13+
display_template = "On [body: OBJECT] exited"
14+
code_template = "func _on_body_exited(body: Node2D):
15+
"
16+
defaults = {}
17+
signal_name = "body_exited"
18+
scope = ""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ses5486g56q"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_72i54"]
4+
5+
[resource]
6+
script = ExtResource("1_72i54")
7+
name = &"rigidbody2d_physics_position"
8+
target_node_class = "RigidBody2D"
9+
description = ""
10+
category = "Transform | Position"
11+
type = 2
12+
variant_type = 0
13+
display_template = "Set Physics Position {position: VECTOR2}"
14+
code_template = "PhysicsServer2D.body_set_state(
15+
get_rid(),
16+
PhysicsServer2D.BODY_STATE_TRANSFORM,
17+
Transform2D.IDENTITY.translated({position})
18+
)
19+
"
20+
defaults = {}
21+
signal_name = ""
22+
scope = ""

addons/block_code/ui/picker/categories/category_factory.gd

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -351,42 +351,6 @@ static func get_built_in_blocks(_class_name: String) -> Array[Block]:
351351
}
352352

353353
"RigidBody2D":
354-
for verb in ["entered", "exited"]:
355-
var b = BLOCKS["entry_block"].instantiate()
356-
b.block_name = "rigidbody2d_on_%s" % verb
357-
b.block_format = "On [body: NODE_PATH] %s" % [verb]
358-
# HACK: Blocks refer to nodes by path but the callback receives the node itself;
359-
# convert to path
360-
b.statement = (
361-
(
362-
"""
363-
func _on_body_%s(_body: Node):
364-
var body: NodePath = _body.get_path()
365-
"""
366-
. dedent()
367-
)
368-
% [verb]
369-
)
370-
b.signal_name = "body_%s" % [verb]
371-
b.category = "Communication | Methods"
372-
block_list.append(b)
373-
374-
var b = BLOCKS["statement_block"].instantiate()
375-
b.block_name = "rigidbody2d_physics_position"
376-
b.block_format = "Set Physics Position {position: VECTOR2}"
377-
b.statement = (
378-
"""
379-
PhysicsServer2D.body_set_state(
380-
get_rid(),
381-
PhysicsServer2D.BODY_STATE_TRANSFORM,
382-
Transform2D.IDENTITY.translated({position})
383-
)
384-
"""
385-
. dedent()
386-
)
387-
b.category = "Transform | Position"
388-
block_list.append(b)
389-
390354
props = {
391355
"mass": {"category": "Physics | Mass"},
392356
"linear_velocity": {"category": "Physics | Velocity"},

0 commit comments

Comments
 (0)
0