Skip to content

Commit

Permalink
Godot 3.4: Weakly-typed area signal handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Shfty committed Nov 13, 2021
1 parent 21a380a commit c704fa5
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 509 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions addons/qodot/game_definitions/fgd/solid_classes/button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func _process(delta: float) -> void:
var target_position = base_translation + (axis * (depth if pressed else 0.0))
translation = translation.linear_interpolate(target_position, speed * delta)

func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
func body_shape_entered(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body is StaticBody:
return

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

overlaps += 1

func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
func body_shape_exited(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body is StaticBody:
return

Expand Down
Original file line number Diff line number Diff line change
@@ -1,113 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://addons/qodot/src/resources/game-definitions/fgd/qodot_fgd_solid_class.gd" type="Script" id=1]

[sub_resource type="GDScript" id=1]
script/source = "extends Area

signal trigger()
signal pressed()
signal released()

export(Dictionary) var properties setget set_properties

var pressed = false
var base_translation = Vector3.ZERO
var axis := Vector3.DOWN
var speed := 8.0
var depth := 0.8
var release_delay := 0.0
var trigger_signal_delay := 0.0
var press_signal_delay := 0.0
var release_signal_delay := 0.0

var overlaps := 0

func set_properties(new_properties: Dictionary) -> void:
if properties != new_properties:
properties = new_properties
update_properties()

func update_properties() -> void:
if 'axis' in properties:
axis = properties.axis.normalized()

if 'speed' in properties:
speed = properties.depth

if 'depth' in properties:
depth = properties.depth.to_float()

if 'release_delay' in properties:
release_delay = properties.release_delay

if 'trigger_signal_delay' in properties:
trigger_signal_delay = properties.trigger_signal_delay

if 'press_signal_delay' in properties:
press_signal_delay = properties.press_signal_delay

if 'release_signal_delay' in properties:
release_signal_delay = properties.release_signal_delay

func _init() -> void:
connect(\"body_shape_entered\", self, \"body_shape_entered\")
connect(\"body_shape_exited\", self, \"body_shape_exited\")

func _enter_tree() -> void:
base_translation = translation

func _process(delta: float) -> void:
var target_position = base_translation + (axis * (depth if pressed else 0.0))
translation = translation.linear_interpolate(target_position, speed * delta)

func body_shape_entered(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body is StaticBody:
return

if overlaps == 0:
press()

overlaps += 1

func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body is StaticBody:
return

overlaps -= 1
if overlaps == 0:
if release_delay == 0:
release()
elif release_delay > 0:
yield(get_tree().create_timer(release_delay), \"timeout\")
release()

func press() -> void:
if pressed:
return

pressed = true

emit_trigger()
emit_pressed()

func emit_trigger() -> void:
yield(get_tree().create_timer(trigger_signal_delay), \"timeout\")
emit_signal(\"trigger\")

func emit_pressed() -> void:
yield(get_tree().create_timer(press_signal_delay), \"timeout\")
emit_signal(\"pressed\")

func release() -> void:
if not pressed:
return

pressed = false

yield(get_tree().create_timer(release_signal_delay), \"timeout\")
emit_signal(\"released\")
"
[ext_resource path="res://addons/qodot/game_definitions/fgd/solid_classes/button.gd" type="Script" id=2]

[resource]
script = ExtResource( 1 )
Expand All @@ -126,10 +20,8 @@ class_properties = {
"trigger_signal_delay": 0.0
}
class_property_descriptions = {
}
meta_properties = {
}
node_options = "----------------------------------------------------------------"
node_class = "Area"
Expand All @@ -141,4 +33,4 @@ build_visuals = true
collision_build = "----------------------------------------------------------------"
collision_shape_type = 1
scripting = "----------------------------------------------------------------"
script_class = SubResource( 1 )
script_class = ExtResource( 2 )
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class_properties = {
"velocity": Vector3( 0, 0, 0 )
}
class_property_descriptions = {

}
meta_properties = {

}
node_options = "----------------------------------------------------------------"
node_class = "RigidBody"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class_property_descriptions = {
"speed": "Rotation Speed"
}
meta_properties = {

}
node_options = "----------------------------------------------------------------"
node_class = "KinematicBody"
Expand Down
10 changes: 5 additions & 5 deletions addons/qodot/game_definitions/worldspawn_layers/liquid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _init() -> void:
connect("body_shape_entered", self, "body_shape_entered")
connect("body_shape_exited", self, "body_shape_exited")

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

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

func body_shape_exited(body_id, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body in buoyancy_dict:
buoyancy_dict.erase(body)

func create_shape_aabb(shape: Shape) -> AABB:
if shape is ConvexPolygonShape:
return create_convex_aabb(shape)
Expand All @@ -53,10 +57,6 @@ func create_convex_aabb(convex_shape: ConvexPolygonShape) -> AABB:
func create_sphere_aabb(sphere_shape: SphereShape) -> AABB:
return AABB(-Vector3.ONE * sphere_shape.radius, Vector3.ONE * sphere_shape.radius)

func body_shape_exited(body_id: int, body: Node, body_shape_idx: int, self_shape_idx: int) -> void:
if body in buoyancy_dict:
buoyancy_dict.erase(body)

func _physics_process(delta: float) -> void:
for body in buoyancy_dict:
var buoyancy_data = buoyancy_dict[body]
Expand Down

0 comments on commit c704fa5

Please sign in to comment.