replace dict key enums with string constants
This commit is contained in:
parent
3db3d07029
commit
2bc77aa297
@ -139,19 +139,19 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
_set_pressing_from_event(event_key)
|
||||
|
||||
if _keyboard.is_configuring and event_key.is_pressed():
|
||||
var new_char_type: KeyProps.Char
|
||||
var new_char_type: String
|
||||
if not _keyboard.alt_visual_layout:
|
||||
if not event_key.shift_pressed:
|
||||
new_char_type = KeyProps.Char.MAIN
|
||||
new_char_type = KeyProps.CHAR_MAIN
|
||||
else:
|
||||
new_char_type = KeyProps.Char.SHIFT
|
||||
new_char_type = KeyProps.CHAR_SHIFT
|
||||
else:
|
||||
if not event_key.shift_pressed:
|
||||
new_char_type = KeyProps.Char.ALT
|
||||
new_char_type = KeyProps.CHAR_ALT
|
||||
else:
|
||||
new_char_type = KeyProps.Char.ALT_SHIFT
|
||||
new_char_type = KeyProps.CHAR_ALT_SHIFT
|
||||
|
||||
var chars_dict: Dictionary[KeyProps.Char, String] = {
|
||||
var chars_dict: Dictionary[String, String] = {
|
||||
new_char_type: char(event_key.unicode).to_upper()
|
||||
}
|
||||
|
||||
@ -224,7 +224,7 @@ func _erase_keyboard_pressed_position() -> void:
|
||||
|
||||
|
||||
#region labels
|
||||
func _set_labels(chars_dict: Dictionary[KeyProps.Char, String] = {}) -> void:
|
||||
func _set_labels(chars_dict: Dictionary[String, String] = {}) -> void:
|
||||
_upper_left_label.text = ""
|
||||
_upper_right_label.text = ""
|
||||
_lower_left_label.text = ""
|
||||
@ -240,7 +240,7 @@ func _set_labels(chars_dict: Dictionary[KeyProps.Char, String] = {}) -> void:
|
||||
_center_label.visible = _center_label.text != ""
|
||||
|
||||
|
||||
func _set_labels_text(chars_dict: Dictionary[KeyProps.Char, String]) -> void:
|
||||
func _set_labels_text(chars_dict: Dictionary[String, String]) -> void:
|
||||
if Engine.is_editor_hint() or props.keycode == KEY_SPACE or not props.is_unicode():
|
||||
_center_label.text = OS.get_keycode_string(props.keycode)
|
||||
return
|
||||
|
||||
@ -313,7 +313,7 @@ func _regenerate_key(
|
||||
current_keys.erase(dict_key)
|
||||
else:
|
||||
var props_dict := LayoutConfig.get_key_config_dict(key_props.keycode)
|
||||
if props_dict:
|
||||
if props_dict and props_dict is Dictionary:
|
||||
key_props.chars_from_dict(props_dict)
|
||||
|
||||
var game_key := GameKey.instantiate_with_props(
|
||||
|
||||
@ -37,15 +37,11 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
print("layout config saved!")
|
||||
|
||||
|
||||
func get_key_config_dict(keycode: Key) -> Dictionary[KeyProps.Char, String]:
|
||||
func get_key_config_dict(keycode: Key) -> Dictionary:
|
||||
var param_key := str(keycode)
|
||||
if not _config.has_section_key(SECTION_KEYS, param_key):
|
||||
return {}
|
||||
|
||||
return (
|
||||
_config.get_value(SECTION_KEYS, param_key, {})
|
||||
as Dictionary[KeyProps.Char, String]
|
||||
)
|
||||
return _config.get_value(SECTION_KEYS, param_key, {}) as Dictionary
|
||||
|
||||
|
||||
func swap_layout(layout_name: String) -> void:
|
||||
@ -78,7 +74,9 @@ func _load_config() -> Error:
|
||||
|
||||
var layout_name := ""
|
||||
if _config.has_section_key(SECTION_INFO, PARAM_NAME):
|
||||
layout_name = _config.get_value(SECTION_INFO, PARAM_NAME, "") as String
|
||||
var config_name: Variant = _config.get_value(SECTION_INFO, PARAM_NAME, "")
|
||||
if config_name is String:
|
||||
layout_name = config_name as String
|
||||
else:
|
||||
push_error("layout config is missing '%s/%s'" % [SECTION_INFO, PARAM_NAME])
|
||||
|
||||
@ -97,10 +95,10 @@ func _load_config() -> Error:
|
||||
):
|
||||
continue
|
||||
|
||||
var dictionary := (
|
||||
_config.get_value(SECTION_KEYS, param_key, {}) as Dictionary
|
||||
)
|
||||
key_props.chars_from_dict(dictionary)
|
||||
var dictionary: Variant = _config.get_value(SECTION_KEYS, param_key)
|
||||
if dictionary is not Dictionary[String,String]:
|
||||
continue
|
||||
key_props.chars_from_dict(dictionary as Dictionary[String,String])
|
||||
|
||||
print("layout config loaded!\n")
|
||||
|
||||
|
||||
@ -1,29 +1,25 @@
|
||||
@tool
|
||||
class_name KeyProps extends Resource
|
||||
|
||||
enum Char {
|
||||
MAIN = 0,
|
||||
SHIFT,
|
||||
ALT,
|
||||
ALT_SHIFT,
|
||||
}
|
||||
const CHAR_MAIN = "char_main"
|
||||
const CHAR_SHIFT = "char_shift"
|
||||
const CHAR_ALT = "char_alt"
|
||||
const CHAR_ALT_SHIFT = "char_alt_shift"
|
||||
|
||||
enum {
|
||||
KEY = 12,
|
||||
LOC,
|
||||
W,
|
||||
H,
|
||||
X,
|
||||
Y,
|
||||
W2,
|
||||
H2,
|
||||
X2,
|
||||
Y2,
|
||||
R,
|
||||
PX,
|
||||
PY,
|
||||
NUB,
|
||||
}
|
||||
const KEY = "key"
|
||||
const LOC = "loc"
|
||||
const W = "w"
|
||||
const H = "h"
|
||||
const X = "x"
|
||||
const Y = "y"
|
||||
const W2 = "w2"
|
||||
const H2 = "h2"
|
||||
const X2 = "x2"
|
||||
const Y2 = "y2"
|
||||
const R = "r"
|
||||
const PX = "rx"
|
||||
const PY = "ry"
|
||||
const NUB = "nub"
|
||||
|
||||
var keycode: Key = KEY_NONE
|
||||
var location: KeyLocation = KEY_LOCATION_UNSPECIFIED
|
||||
@ -111,15 +107,15 @@ func props_from_dict(dict: Dictionary) -> KeyProps:
|
||||
return self
|
||||
|
||||
|
||||
func chars_from_dict(dict: Dictionary[Char, String], override: bool = true) -> KeyProps:
|
||||
if dict.has(Char.MAIN) and (override or not main_char):
|
||||
main_char = dict[Char.MAIN]
|
||||
if dict.has(Char.SHIFT) and (override or not shift_char):
|
||||
shift_char = dict[Char.SHIFT]
|
||||
if dict.has(Char.ALT) and (override or not alt_char):
|
||||
alt_char = dict[Char.ALT]
|
||||
if dict.has(Char.ALT_SHIFT) and (override or not alt_shift_char):
|
||||
alt_shift_char = dict[Char.ALT_SHIFT]
|
||||
func chars_from_dict(dict: Dictionary, override: bool = true) -> KeyProps:
|
||||
if dict.has(CHAR_MAIN) and (override or not main_char):
|
||||
main_char = dict[CHAR_MAIN]
|
||||
if dict.has(CHAR_SHIFT) and (override or not shift_char):
|
||||
shift_char = dict[CHAR_SHIFT]
|
||||
if dict.has(CHAR_ALT) and (override or not alt_char):
|
||||
alt_char = dict[CHAR_ALT]
|
||||
if dict.has(CHAR_ALT_SHIFT) and (override or not alt_shift_char):
|
||||
alt_shift_char = dict[CHAR_ALT_SHIFT]
|
||||
|
||||
if main_char == shift_char:
|
||||
shift_char = ""
|
||||
@ -131,15 +127,15 @@ func chars_from_dict(dict: Dictionary[Char, String], override: bool = true) -> K
|
||||
return self
|
||||
|
||||
|
||||
func chars_to_dict() -> Dictionary[Char, String]:
|
||||
var dict: Dictionary[Char, String] = {}
|
||||
func chars_to_dict() -> Dictionary[String, String]:
|
||||
var dict: Dictionary[String, String] = {}
|
||||
if main_char:
|
||||
dict[Char.MAIN] = main_char
|
||||
dict[CHAR_MAIN] = main_char
|
||||
if shift_char:
|
||||
dict[Char.SHIFT] = shift_char
|
||||
dict[CHAR_SHIFT] = shift_char
|
||||
if alt_char:
|
||||
dict[Char.ALT] = alt_char
|
||||
dict[CHAR_ALT] = alt_char
|
||||
if alt_shift_char:
|
||||
dict[Char.ALT_SHIFT] = alt_shift_char
|
||||
dict[CHAR_ALT_SHIFT] = alt_shift_char
|
||||
|
||||
return dict
|
||||
|
||||
Loading…
Reference in New Issue
Block a user