diff --git a/levels/mechanic_test/mechanic_test.tscn b/levels/mechanic_test/mechanic_test.tscn index 96ae237..0f3778f 100644 --- a/levels/mechanic_test/mechanic_test.tscn +++ b/levels/mechanic_test/mechanic_test.tscn @@ -160,7 +160,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="ResetSwitch" parent="ResetPodium" instance=ExtResource("2_pka60")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) -enabled = true +clean = true [node name="Label3D" type="Label3D" parent="ResetPodium"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) @@ -177,7 +177,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="WallSwitch" parent="NoduleSpawner" instance=ExtResource("2_pka60")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) -enabled = true +clean = true [node name="Label3D" type="Label3D" parent="NoduleSpawner"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) @@ -199,7 +199,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="WallSwitch" parent="AlarmSpawner" instance=ExtResource("2_pka60")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) -enabled = true +clean = true [node name="Label3D" type="Label3D" parent="AlarmSpawner"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) @@ -221,7 +221,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="AlarmTriggerSwitch" parent="AlarmTrigger" instance=ExtResource("2_pka60")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) -enabled = true +clean = true [node name="Label3D" type="Label3D" parent="AlarmTrigger"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) @@ -255,7 +255,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="OpenSwitch" parent="Bulkhead/Podium" instance=ExtResource("2_pka60")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) -enabled = true +clean = true [node name="Label3D" type="Label3D" parent="Bulkhead/Podium"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) @@ -273,6 +273,8 @@ shape = SubResource("ConcavePolygonShape3D_bg05n") [node name="CloseSwitch" parent="Bulkhead/Podium2" instance=ExtResource("2_pka60")] unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) +clean = true +enabled = false [node name="Label3D" type="Label3D" parent="Bulkhead/Podium2"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) diff --git a/src/props/wall_switch/wall_switch.gd b/src/props/wall_switch/wall_switch.gd index daee995..a1585bc 100644 --- a/src/props/wall_switch/wall_switch.gd +++ b/src/props/wall_switch/wall_switch.gd @@ -1,10 +1,11 @@ extends Node3D -signal cleared +signal cleaned signal activated -const CLEAR_THRESHOLD := 1500 +const CLEAN_THRESHOLD := 1400 +@export var clean := false @export var enabled := false @onready var animation_player: AnimationPlayer = %AnimationPlayer @@ -12,31 +13,53 @@ const CLEAR_THRESHOLD := 1500 @onready var gunk_body: GunkBody = %GunkBody @onready var interactive: Interactive = %Interactive +# XXX I must have been smoking crack when I wrote this logic. Why so complicated? + func _ready() -> void: + if clean: + gunk_body.clear_all() + _on_clean() if enabled: - enable() + _on_enable() ## Called once all gunk is cleared. Enables interaction & plays animations func enable() -> void: enabled = true + _on_enable() - # Clear off the rest of the gunk - gunk_body.clear_all() - light_animation.play("success") - interactive.enabled = true + +func _on_enable() -> void: + if clean: + light_animation.play("success") + if not animation_player.is_playing(): + interactive.enabled = true ## Called once the switch is no longer usable. Disables interaction & plays animations func disable() -> void: - if enabled: - light_animation.play("disable") - + _on_disable() enabled = false + + +func _on_disable() -> void: + if enabled and clean: + light_animation.play("disable") + else: + light_animation.play("RESET") interactive.enabled = false +func _on_clean() -> void: + clean = true + if enabled: + _on_enable() + else: + _on_disable() + cleaned.emit() + + func _activate() -> void: animation_player.play("activate") activated.emit() @@ -50,5 +73,5 @@ func _animation_finished(anim_name: StringName) -> void: func _on_gunk_body_clear_total_updated(clear_total: float) -> void: - if not enabled and clear_total >= CLEAR_THRESHOLD: - enable() + if not clean and clear_total >= CLEAN_THRESHOLD: + _on_clean() diff --git a/src/props/wall_switch/wall_switch.tscn b/src/props/wall_switch/wall_switch.tscn index 8ecbaed..156563d 100644 --- a/src/props/wall_switch/wall_switch.tscn +++ b/src/props/wall_switch/wall_switch.tscn @@ -148,9 +148,9 @@ tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { "times": PackedFloat32Array(0, 2), -"transitions": PackedFloat32Array(0.618, 1), +"transitions": PackedFloat32Array(0.269, 1), "update": 0, -"values": [2.0, 0.0] +"values": [8.0, 0.0] } [sub_resource type="Animation" id="Animation_pea1n"] @@ -196,7 +196,7 @@ tracks/0/keys = { "times": PackedFloat32Array(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45), "transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), "update": 1, -"values": [0.0, 2.0, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0] +"values": [0.0, 8.0, 0.0, 8.0, 0.0, 8.0, 0.0, 8.0, 0.0, 8.0] } tracks/1/type = "value" tracks/1/imported = false @@ -224,6 +224,7 @@ size = Vector3(0.475, 0.65, 0.2) [node name="WallSwitch" instance=ExtResource("2_whafo")] script = ExtResource("2_kfvqd") +enabled = true [node name="WallSwitch_2" parent="Armature/Skeleton3D" index="0"] mesh = SubResource("ArrayMesh_6aabu")