add lights to visualize key adjacency

This commit is contained in:
Teatov 2025-08-02 19:41:17 +10:00
parent e6b58236d7
commit 5b32ea57d6
3 changed files with 23 additions and 1 deletions

View File

@ -41,7 +41,7 @@ stream_6/stream = ExtResource("15_w7o33")
[sub_resource type="AudioStreamPolyphonic" id="AudioStreamPolyphonic_6rsff"]
[node name="GameKey" type="Node3D" node_paths=PackedStringArray("_skeleton_primary", "_skeleton_secondary", "_nub_mesh", "_upper_left_label", "_upper_right_label", "_lower_left_label", "_lower_right_label", "_center_label", "_press_light", "_sfx_player")]
[node name="GameKey" type="Node3D" node_paths=PackedStringArray("_skeleton_primary", "_skeleton_secondary", "_nub_mesh", "_upper_left_label", "_upper_right_label", "_lower_left_label", "_lower_right_label", "_center_label", "_press_light", "_adjacency_light", "_sfx_player")]
script = ExtResource("1_sypr4")
_skeleton_primary = NodePath("ModelPrimary/KeyArmature/Skeleton3D")
_skeleton_secondary = NodePath("ModelSecondary/KeyArmature/Skeleton3D")
@ -52,6 +52,7 @@ _lower_left_label = NodePath("LowerLeftAttachment/LowerLeftLabel")
_lower_right_label = NodePath("LowerRightAttachment/LowerRightLabel")
_center_label = NodePath("CenterLabel")
_press_light = NodePath("PressLight")
_adjacency_light = NodePath("AdjacencyLight")
_sfx_player = NodePath("SFXPlayer")
_press_sfx = SubResource("AudioStreamRandomizer_agrko")
_release_sfx = SubResource("AudioStreamRandomizer_ch32x")
@ -159,10 +160,16 @@ outline_size = 0
[node name="PressLight" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0)
visible = false
light_color = Color(1, 0.687333, 0.33, 1)
light_energy = 6.0
omni_range = 2.0
[node name="AdjacencyLight" type="OmniLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0)
light_color = Color(0.8325, 1, 0.33, 1)
omni_range = 0.6
[node name="SFXPlayer" type="AudioStreamPlayer3D" parent="."]
stream = SubResource("AudioStreamPolyphonic_6rsff")
volume_db = -15.0

View File

@ -11,6 +11,7 @@ class_name GameKey extends Node3D
@export var _lower_right_label: Label3D
@export var _center_label: Label3D
@export var _press_light: OmniLight3D
@export var _adjacency_light: OmniLight3D
@export var _sfx_player: AudioStreamPlayer3D
@export_group("Bones")
@ -92,7 +93,9 @@ func _ready() -> void:
keyboard.layout_size_changed.connect(_on_keyboard_layout_size_changed)
keyboard.keys_requested.connect(_on_keyboard_keys_requested)
keyboard.is_configuring_changed.connect(_on_keyboard_is_configuring_changed)
keyboard.key_press_changed.connect(_on_keyboard_key_press_changed)
_set_labels()
_adjacency_light.visible = false
func _process(delta: float) -> void:
@ -405,4 +408,9 @@ func _on_keyboard_is_configuring_changed(value: bool) -> void:
else:
_shake(0.2)
func _on_keyboard_key_press_changed(game_key: GameKey, event: InputEventKey) -> void:
if event.is_pressed():
_adjacency_light.visible = KeyAdjacency.is_adjacent(game_key, self)
#endregion

View File

@ -28,3 +28,10 @@ const MAP: Dictionary[Key, Array] = {
KEY_N: [KEY_H, KEY_J, KEY_M, KEY_B],
KEY_M: [KEY_J, KEY_K, KEY_N],
}
static func is_adjacent(from: GameKey, to: GameKey) -> bool:
return (
MAP.has(from.props.physical_keycode)
and (to.props.physical_keycode in KeyAdjacency.MAP[from.props.physical_keycode])
)