108 lines
2.2 KiB
GDScript
108 lines
2.2 KiB
GDScript
class_name KeyProps
|
|
|
|
enum Char { MAIN, SHIFT, ALT, ALT_SHIFT }
|
|
|
|
const KEY := "key"
|
|
const LOC := "location"
|
|
|
|
const W := "w"
|
|
const H := "h"
|
|
const X := "x"
|
|
const Y := "y"
|
|
|
|
const SECONDARY_RECT := "secondary_rect"
|
|
const W2 := "w2"
|
|
const H2 := "h2"
|
|
const X2 := "x2"
|
|
const Y2 := "y2"
|
|
|
|
var physical_keycode: Key
|
|
var location: KeyLocation = KEY_LOCATION_UNSPECIFIED
|
|
var secondary_rect: bool = false
|
|
|
|
var width: float = 1
|
|
var height: float = 1
|
|
var x: float = 0
|
|
var y: float = 0
|
|
|
|
var width2: float = 1
|
|
var width_init2: float = 1
|
|
var height2: float = 1
|
|
var height_init2: float = 1
|
|
var x2: float = 0
|
|
var y2: float = 0
|
|
|
|
var main_char: String
|
|
var shift_char: String
|
|
var alt_char: String
|
|
var alt_shift_char: String
|
|
|
|
|
|
func is_char() -> bool:
|
|
return OS.is_keycode_unicode(physical_keycode)
|
|
|
|
|
|
func props_from_dict(dict: Dictionary) -> KeyProps:
|
|
if dict.has(KEY):
|
|
physical_keycode = dict[KEY]
|
|
if dict.has(LOC):
|
|
location = dict[LOC]
|
|
|
|
if dict.has(W):
|
|
width = dict[W]
|
|
if dict.has(H):
|
|
height = dict[H]
|
|
if dict.has(X):
|
|
x = dict[X]
|
|
if dict.has(Y):
|
|
y = dict[Y]
|
|
|
|
if dict.has(SECONDARY_RECT):
|
|
secondary_rect = dict[SECONDARY_RECT]
|
|
if dict.has(W2):
|
|
width2 = dict[W2]
|
|
width_init2 = dict[W2]
|
|
if dict.has(H2):
|
|
height2 = dict[H2]
|
|
height_init2 = dict[H2]
|
|
if dict.has(X2):
|
|
x2 = dict[X2]
|
|
if dict.has(Y2):
|
|
y2 = dict[Y2]
|
|
|
|
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]
|
|
|
|
if main_char == shift_char:
|
|
shift_char = ""
|
|
if main_char == alt_char:
|
|
alt_char = ""
|
|
if alt_char == alt_shift_char or shift_char == alt_shift_char:
|
|
alt_shift_char = ""
|
|
|
|
return self
|
|
|
|
|
|
func chars_to_dict() -> Dictionary[Char, String]:
|
|
var dict: Dictionary[Char, String] = {}
|
|
if main_char:
|
|
dict[Char.MAIN] = main_char
|
|
if shift_char:
|
|
dict[Char.SHIFT] = shift_char
|
|
if alt_char:
|
|
dict[Char.ALT] = alt_char
|
|
if alt_shift_char:
|
|
dict[Char.ALT_SHIFT] = alt_shift_char
|
|
|
|
return dict
|