Fixed light clean/enable logic
Some checks failed
linting & formatting / build (push) Failing after 3s

This commit is contained in:
Rob Kelly 2025-03-20 17:46:01 -06:00
parent b022005087
commit 0ea73b1221
3 changed files with 46 additions and 20 deletions

View File

@ -160,7 +160,7 @@ shape = SubResource("ConcavePolygonShape3D_bg05n")
[node name="ResetSwitch" parent="ResetPodium" instance=ExtResource("2_pka60")] [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) 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"] [node name="Label3D" type="Label3D" parent="ResetPodium"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) 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")] [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) 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"] [node name="Label3D" type="Label3D" parent="NoduleSpawner"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) 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")] [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) 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"] [node name="Label3D" type="Label3D" parent="AlarmSpawner"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) 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")] [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) 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"] [node name="Label3D" type="Label3D" parent="AlarmTrigger"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0.3) 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")] [node name="OpenSwitch" parent="Bulkhead/Podium" instance=ExtResource("2_pka60")]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) 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"] [node name="Label3D" type="Label3D" parent="Bulkhead/Podium"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) 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")] [node name="CloseSwitch" parent="Bulkhead/Podium2" instance=ExtResource("2_pka60")]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0.35) 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"] [node name="Label3D" type="Label3D" parent="Bulkhead/Podium2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9, 0.3)

View File

@ -1,10 +1,11 @@
extends Node3D extends Node3D
signal cleared signal cleaned
signal activated signal activated
const CLEAR_THRESHOLD := 1500 const CLEAN_THRESHOLD := 1400
@export var clean := false
@export var enabled := false @export var enabled := false
@onready var animation_player: AnimationPlayer = %AnimationPlayer @onready var animation_player: AnimationPlayer = %AnimationPlayer
@ -12,31 +13,53 @@ const CLEAR_THRESHOLD := 1500
@onready var gunk_body: GunkBody = %GunkBody @onready var gunk_body: GunkBody = %GunkBody
@onready var interactive: Interactive = %Interactive @onready var interactive: Interactive = %Interactive
# XXX I must have been smoking crack when I wrote this logic. Why so complicated?
func _ready() -> void: func _ready() -> void:
if clean:
gunk_body.clear_all()
_on_clean()
if enabled: if enabled:
enable() _on_enable()
## Called once all gunk is cleared. Enables interaction & plays animations ## Called once all gunk is cleared. Enables interaction & plays animations
func enable() -> void: func enable() -> void:
enabled = true enabled = true
_on_enable()
# Clear off the rest of the gunk
gunk_body.clear_all() func _on_enable() -> void:
if clean:
light_animation.play("success") light_animation.play("success")
if not animation_player.is_playing():
interactive.enabled = true interactive.enabled = true
## Called once the switch is no longer usable. Disables interaction & plays animations ## Called once the switch is no longer usable. Disables interaction & plays animations
func disable() -> void: func disable() -> void:
if enabled: _on_disable()
light_animation.play("disable")
enabled = false enabled = false
func _on_disable() -> void:
if enabled and clean:
light_animation.play("disable")
else:
light_animation.play("RESET")
interactive.enabled = false interactive.enabled = false
func _on_clean() -> void:
clean = true
if enabled:
_on_enable()
else:
_on_disable()
cleaned.emit()
func _activate() -> void: func _activate() -> void:
animation_player.play("activate") animation_player.play("activate")
activated.emit() activated.emit()
@ -50,5 +73,5 @@ func _animation_finished(anim_name: StringName) -> void:
func _on_gunk_body_clear_total_updated(clear_total: float) -> void: func _on_gunk_body_clear_total_updated(clear_total: float) -> void:
if not enabled and clear_total >= CLEAR_THRESHOLD: if not clean and clear_total >= CLEAN_THRESHOLD:
enable() _on_clean()

View File

@ -148,9 +148,9 @@ tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 2), "times": PackedFloat32Array(0, 2),
"transitions": PackedFloat32Array(0.618, 1), "transitions": PackedFloat32Array(0.269, 1),
"update": 0, "update": 0,
"values": [2.0, 0.0] "values": [8.0, 0.0]
} }
[sub_resource type="Animation" id="Animation_pea1n"] [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), "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), "transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 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/type = "value"
tracks/1/imported = false tracks/1/imported = false
@ -224,6 +224,7 @@ size = Vector3(0.475, 0.65, 0.2)
[node name="WallSwitch" instance=ExtResource("2_whafo")] [node name="WallSwitch" instance=ExtResource("2_whafo")]
script = ExtResource("2_kfvqd") script = ExtResource("2_kfvqd")
enabled = true
[node name="WallSwitch_2" parent="Armature/Skeleton3D" index="0"] [node name="WallSwitch_2" parent="Armature/Skeleton3D" index="0"]
mesh = SubResource("ArrayMesh_6aabu") mesh = SubResource("ArrayMesh_6aabu")