rename KeyAdjacency to KeyHelper and move is_adjacent to GameKey

This commit is contained in:
Teatov 2025-08-03 03:40:46 +10:00
parent 8998fcc84f
commit 8df1181be3
4 changed files with 13 additions and 15 deletions

View File

@ -195,6 +195,15 @@ func get_default_transform() -> Transform3D:
return Transform3D(Quaternion.from_euler(_default_rotation), _default_position)
func is_adjacent(to: GameKey) -> bool:
return (
KeyHelper.ADJACENCY_MAP.has(props.physical_keycode)
and (
to.props.physical_keycode in KeyHelper.ADJACENCY_MAP[props.physical_keycode]
)
)
#endregion
@ -437,7 +446,7 @@ func _on_keyboard_is_configuring_changed(value: bool) -> void:
func _on_keyboard_player_key_changed(game_key: GameKey) -> void:
_adjacency_light.visible = KeyAdjacency.is_adjacent(game_key, self)
_adjacency_light.visible = is_adjacent(game_key)
func _on_keyboard_player_finished_move(game_key: GameKey) -> void:

View File

@ -1,6 +1,6 @@
class_name KeyAdjacency
class_name KeyHelper
const MAP: Dictionary[Key, Array] = {
const ADJACENCY_MAP: Dictionary[Key, Array] = {
KEY_1: [KEY_2, KEY_Q],
KEY_2: [KEY_3, KEY_W, KEY_Q, KEY_1],
KEY_3: [KEY_4, KEY_E, KEY_W, KEY_2],
@ -49,10 +49,3 @@ const MAP: Dictionary[Key, Array] = {
KEY_PERIOD: [KEY_L, KEY_SEMICOLON, KEY_SLASH, KEY_COMMA],
KEY_SLASH: [KEY_SEMICOLON, KEY_APOSTROPHE, KEY_PERIOD],
}
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])
)

View File

@ -101,11 +101,7 @@ func _finish_move(_interrupted: bool) -> void:
#region event handlers
func _on_keyboard_key_press_changed(game_key: GameKey, event: InputEventKey) -> void:
if (
event.is_pressed()
and _current_key
and KeyAdjacency.is_adjacent(_current_key, game_key)
):
if event.is_pressed() and _current_key and _current_key.is_adjacent(game_key):
_move(game_key)
#endregion