Skip to content

Commit c704fa5

Browse files
author
Josh Palmer
committed
Godot 3.4: Weakly-typed area signal handlers
1 parent 21a380a commit c704fa5

File tree

8 files changed

+94
-509
lines changed

8 files changed

+94
-509
lines changed

addons/qodot/example_scenes/1-interactivity/2-worldspawn-layers/2-worldspawn-layers.tscn

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

addons/qodot/example_scenes/1-interactivity/3-basic-signal-wiring/3-basic-signal-wiring.tscn

Lines changed: 57 additions & 209 deletions
Large diffs are not rendered by default.

addons/qodot/example_scenes/1-interactivity/4-advanced-signal-wiring/4-advanced-signal-wiring.tscn

Lines changed: 17 additions & 169 deletions
Large diffs are not rendered by default.

addons/qodot/game_definitions/fgd/solid_classes/button.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func _process(delta: float) -> void:
5656
var target_position = base_translation + (axis * (depth if pressed else 0.0))
5757
translation = translation.linear_interpolate(target_position, speed * delta)
5858

59-
func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
59+
func body_shape_entered(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
6060
if body is StaticBody:
6161
return
6262

@@ -65,7 +65,7 @@ func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shap
6565

6666
overlaps += 1
6767

68-
func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
68+
func body_shape_exited(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
6969
if body is StaticBody:
7070
return
7171

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,7 @@
11
[gd_resource type="Resource" load_steps=3 format=2]
22

33
[ext_resource path="res://addons/qodot/src/resources/game-definitions/fgd/qodot_fgd_solid_class.gd" type="Script" id=1]
4-
5-
[sub_resource type="GDScript" id=1]
6-
script/source = "extends Area
7-
8-
signal trigger()
9-
signal pressed()
10-
signal released()
11-
12-
export(Dictionary) var properties setget set_properties
13-
14-
var pressed = false
15-
var base_translation = Vector3.ZERO
16-
var axis := Vector3.DOWN
17-
var speed := 8.0
18-
var depth := 0.8
19-
var release_delay := 0.0
20-
var trigger_signal_delay := 0.0
21-
var press_signal_delay := 0.0
22-
var release_signal_delay := 0.0
23-
24-
var overlaps := 0
25-
26-
func set_properties(new_properties: Dictionary) -> void:
27-
if properties != new_properties:
28-
properties = new_properties
29-
update_properties()
30-
31-
func update_properties() -> void:
32-
if 'axis' in properties:
33-
axis = properties.axis.normalized()
34-
35-
if 'speed' in properties:
36-
speed = properties.depth
37-
38-
if 'depth' in properties:
39-
depth = properties.depth.to_float()
40-
41-
if 'release_delay' in properties:
42-
release_delay = properties.release_delay
43-
44-
if 'trigger_signal_delay' in properties:
45-
trigger_signal_delay = properties.trigger_signal_delay
46-
47-
if 'press_signal_delay' in properties:
48-
press_signal_delay = properties.press_signal_delay
49-
50-
if 'release_signal_delay' in properties:
51-
release_signal_delay = properties.release_signal_delay
52-
53-
func _init() -> void:
54-
connect(\"body_shape_entered\", self, \"body_shape_entered\")
55-
connect(\"body_shape_exited\", self, \"body_shape_exited\")
56-
57-
func _enter_tree() -> void:
58-
base_translation = translation
59-
60-
func _process(delta: float) -> void:
61-
var target_position = base_translation + (axis * (depth if pressed else 0.0))
62-
translation = translation.linear_interpolate(target_position, speed * delta)
63-
64-
func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
65-
if body is StaticBody:
66-
return
67-
68-
if overlaps == 0:
69-
press()
70-
71-
overlaps += 1
72-
73-
func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
74-
if body is StaticBody:
75-
return
76-
77-
overlaps -= 1
78-
if overlaps == 0:
79-
if release_delay == 0:
80-
release()
81-
elif release_delay > 0:
82-
yield(get_tree().create_timer(release_delay), \"timeout\")
83-
release()
84-
85-
func press() -> void:
86-
if pressed:
87-
return
88-
89-
pressed = true
90-
91-
emit_trigger()
92-
emit_pressed()
93-
94-
func emit_trigger() -> void:
95-
yield(get_tree().create_timer(trigger_signal_delay), \"timeout\")
96-
emit_signal(\"trigger\")
97-
98-
func emit_pressed() -> void:
99-
yield(get_tree().create_timer(press_signal_delay), \"timeout\")
100-
emit_signal(\"pressed\")
101-
102-
func release() -> void:
103-
if not pressed:
104-
return
105-
106-
pressed = false
107-
108-
yield(get_tree().create_timer(release_signal_delay), \"timeout\")
109-
emit_signal(\"released\")
110-
"
4+
[ext_resource path="res://addons/qodot/game_definitions/fgd/solid_classes/button.gd" type="Script" id=2]
1115

1126
[resource]
1137
script = ExtResource( 1 )
@@ -126,10 +20,8 @@ class_properties = {
12620
"trigger_signal_delay": 0.0
12721
}
12822
class_property_descriptions = {
129-
13023
}
13124
meta_properties = {
132-
13325
}
13426
node_options = "----------------------------------------------------------------"
13527
node_class = "Area"
@@ -141,4 +33,4 @@ build_visuals = true
14133
collision_build = "----------------------------------------------------------------"
14234
collision_shape_type = 1
14335
scripting = "----------------------------------------------------------------"
144-
script_class = SubResource( 1 )
36+
script_class = ExtResource( 2 )

addons/qodot/game_definitions/fgd/solid_classes/physics_solid_class.tres

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class_properties = {
1515
"velocity": Vector3( 0, 0, 0 )
1616
}
1717
class_property_descriptions = {
18-
1918
}
2019
meta_properties = {
21-
2220
}
2321
node_options = "----------------------------------------------------------------"
2422
node_class = "RigidBody"

addons/qodot/game_definitions/fgd/solid_classes/rotate_solid_class.tres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class_property_descriptions = {
4646
"speed": "Rotation Speed"
4747
}
4848
meta_properties = {
49-
5049
}
5150
node_options = "----------------------------------------------------------------"
5251
node_class = "KinematicBody"

addons/qodot/game_definitions/worldspawn_layers/liquid.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func _init() -> void:
1111
connect("body_shape_entered", self, "body_shape_entered")
1212
connect("body_shape_exited", self, "body_shape_exited")
1313

14-
func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
14+
func body_shape_entered(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
1515
if not body is RigidBody:
1616
return
1717

@@ -30,6 +30,10 @@ func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shap
3030
'body_aabb': body_aabb
3131
}
3232

33+
func body_shape_exited(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
34+
if body in buoyancy_dict:
35+
buoyancy_dict.erase(body)
36+
3337
func create_shape_aabb(shape: Shape) -> AABB:
3438
if shape is ConvexPolygonShape:
3539
return create_convex_aabb(shape)
@@ -53,10 +57,6 @@ func create_convex_aabb(convex_shape: ConvexPolygonShape) -> AABB:
5357
func create_sphere_aabb(sphere_shape: SphereShape) -> AABB:
5458
return AABB(-Vector3.ONE * sphere_shape.radius, Vector3.ONE * sphere_shape.radius)
5559

56-
func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
57-
if body in buoyancy_dict:
58-
buoyancy_dict.erase(body)
59-
6060
func _physics_process(delta: float) -> void:
6161
for body in buoyancy_dict:
6262
var buoyancy_data = buoyancy_dict[body]

0 commit comments

Comments
 (0)