make detecting numpad enter dependant on previous keycode
This commit is contained in:
parent
a17becae83
commit
5dba5cdc2f
@ -127,13 +127,16 @@ func _deserialize_row(
|
||||
var key_pos := Vector2(0, row_index)
|
||||
|
||||
var current_key_data_dict: Dictionary = {}
|
||||
var prev_keycode: Key = KEY_NONE
|
||||
for data_key: Variant in data_row:
|
||||
if data_key is Dictionary:
|
||||
current_key_data_dict = data_key as Dictionary
|
||||
|
||||
if data_key is String:
|
||||
var legend := (data_key as String).split("\n")
|
||||
var keycode := _get_keycode_from_legend(legend, current_key_data_dict)
|
||||
var keycode := _get_keycode_from_legend(
|
||||
legend, current_key_data_dict, prev_keycode
|
||||
)
|
||||
var key_dict := {KeyProps.KEY: keycode}
|
||||
key_dict.merge(_deserialize_key(current_key_data_dict))
|
||||
layout_row.append(key_dict)
|
||||
@ -147,6 +150,7 @@ func _deserialize_row(
|
||||
key_pos.x += key_dict[KeyProps.W] if key_dict.has(KeyProps.W) else 1.0
|
||||
|
||||
current_key_data_dict = {}
|
||||
prev_keycode = key_dict[KeyProps.KEY]
|
||||
|
||||
return layout_row
|
||||
|
||||
@ -185,13 +189,15 @@ func _deserialize_key(data_key: Dictionary) -> Dictionary:
|
||||
return key_dict
|
||||
|
||||
|
||||
func _get_keycode_from_legend(legend: Array[String], data_key: Dictionary) -> Key:
|
||||
func _get_keycode_from_legend(
|
||||
legend: Array[String], data_key: Dictionary, prev_keycode: Key
|
||||
) -> Key:
|
||||
if legend.size() == 1 and legend[0] == "" and data_key.has(W) and data_key[W] > 1:
|
||||
return KEY_SPACE
|
||||
|
||||
var keycode := KEY_NONE
|
||||
|
||||
keycode = _get_numpad_keycode_from_legend(legend)
|
||||
keycode = _get_numpad_keycode_from_legend(legend, prev_keycode)
|
||||
|
||||
if keycode == KEY_NONE:
|
||||
keycode = OS.find_keycode_from_string(legend[0])
|
||||
@ -228,7 +234,7 @@ func _get_keycode_from_legend(legend: Array[String], data_key: Dictionary) -> Ke
|
||||
return keycode
|
||||
|
||||
|
||||
func _get_numpad_keycode_from_legend(legend: Array[String]) -> Key:
|
||||
func _get_numpad_keycode_from_legend(legend: Array[String], prev_keycode: Key) -> Key:
|
||||
if legend.size() == 1 or legend.size() >= 2:
|
||||
if legend[0].length() == 1 and legend[0].is_valid_int():
|
||||
return KEY_KP_0 + int(legend[0]) as Key
|
||||
@ -238,6 +244,12 @@ func _get_numpad_keycode_from_legend(legend: Array[String]) -> Key:
|
||||
):
|
||||
return LABEL_TO_NUMPAD_KEYCODE_MAP[legend[0]]
|
||||
|
||||
for label in legend:
|
||||
if OS.find_keycode_from_string(label) == KEY_ENTER:
|
||||
if prev_keycode >= KEY_KP_MULTIPLY and prev_keycode <= KEY_KP_9:
|
||||
return KEY_KP_ENTER
|
||||
break
|
||||
|
||||
return KEY_NONE
|
||||
|
||||
|
||||
@ -275,10 +287,6 @@ func _get_key_locations(key_pos_dicts: Dictionary[Key, Array]) -> void:
|
||||
if key_pos_dict_left == key_pos_dict_right:
|
||||
continue
|
||||
|
||||
if keycode == KEY_ENTER:
|
||||
key_pos_dict_right[KEY_DICT][KeyProps.KEY] = KEY_KP_ENTER
|
||||
continue
|
||||
|
||||
if keycode == KEY_BACKSLASH:
|
||||
key_pos_dict_left[KEY_DICT][KeyProps.KEY] = KEY_SECTION
|
||||
continue
|
||||
|
||||
Loading…
Reference in New Issue
Block a user