From 10e4038fea5200464785685b9f1a6afabb4b36f7 Mon Sep 17 00:00:00 2001 From: teatov Date: Sat, 2 Aug 2025 00:14:11 +1000 Subject: [PATCH] remove extra flags for secondary rect and rotation --- scripts/game_key.gd | 4 +-- scripts/game_keyboard.gd | 14 ++++----- scripts/key_props.gd | 42 ++++++++++++-------------- scripts/layouts/layout_abnt.gd | 1 - scripts/layouts/layout_ansi_variant.gd | 1 - scripts/layouts/layout_iso.gd | 1 - scripts/layouts/layout_jis.gd | 1 - scripts/layouts/parser_kle.gd | 7 ----- 8 files changed, 28 insertions(+), 43 deletions(-) diff --git a/scripts/game_key.gd b/scripts/game_key.gd index d2889e4..59b7194 100644 --- a/scripts/game_key.gd +++ b/scripts/game_key.gd @@ -155,7 +155,7 @@ func load_props(_props: KeyProps, init_pos: Vector3, default_angle: float) -> vo props = _props _skeleton_primary.visible = true - _skeleton_secondary.visible = props.secondary_rect + _skeleton_secondary.visible = props.has_secondary_rect() _set_bones() _nub_mesh.visible = props.homing_nub @@ -253,7 +253,7 @@ func _set_bones() -> void: _set_bones_from_rect(rect, _skeleton_primary) - if props.secondary_rect: + if props.has_secondary_rect(): var rect_secondary := Rect2( rect.position.x + props.x2 * keyboard.key_size, rect.position.y + props.y2 * keyboard.key_size, diff --git a/scripts/game_keyboard.gd b/scripts/game_keyboard.gd index 7ad3c91..173229d 100644 --- a/scripts/game_keyboard.gd +++ b/scripts/game_keyboard.gd @@ -155,14 +155,14 @@ func _iterate_row( pos.x = pivot.x for key_props in row: - if key_props.has_pivot_x: - pivot.x = key_props.pivot_x - if key_props.has_pivot_y: - pivot.y = key_props.pivot_y - if key_props.has_pivot_x or key_props.has_pivot_y: - pos = pivot - if key_props.has_angle: + if key_props.has_angle(): angle = -deg_to_rad(key_props.angle) + if key_props.has_pivot_x(): + pivot.x = key_props.pivot_x + if key_props.has_pivot_y(): + pivot.y = key_props.pivot_y + if key_props.has_pivot_x() or key_props.has_pivot_y(): + pos = pivot var key_pos := Vector3(pos.x + key_size / 2, 0, pos.y + key_size / 2) key_pos.x += ( diff --git a/scripts/key_props.gd b/scripts/key_props.gd index 76da5ee..8852671 100644 --- a/scripts/key_props.gd +++ b/scripts/key_props.gd @@ -14,14 +14,10 @@ enum { H, X, Y, - SECONDARY_RECT, W2, H2, X2, Y2, - HAS_ANGLE, - HAS_PIVOT_X, - HAS_PIVOT_Y, R, PX, PY, @@ -36,20 +32,14 @@ var height: float = 1 var x: float = 0 var y: float = 0 -var secondary_rect: bool = false 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 has_angle: bool = false -var has_pivot_x: bool = false -var has_pivot_y: bool = false -var angle: float = 0 -var pivot_x: float = 0 -var pivot_y: float = 0 +var angle: float = -INF +var pivot_x: float = -INF +var pivot_y: float = -INF var homing_nub: bool = false @@ -63,6 +53,22 @@ func is_char() -> bool: return OS.is_keycode_unicode(physical_keycode) +func has_secondary_rect() -> bool: + return width2 != 1 or height2 != 1 or x2 != 0 or y2 != 0 + + +func has_angle() -> bool: + return angle != -INF + + +func has_pivot_x() -> bool: + return pivot_x != -INF + + +func has_pivot_y() -> bool: + return pivot_y != -INF + + func props_from_dict(dict: Dictionary) -> KeyProps: if dict.has(KEY): physical_keycode = dict[KEY] @@ -78,25 +84,15 @@ func props_from_dict(dict: Dictionary) -> KeyProps: 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] - if dict.has(HAS_ANGLE): - has_angle = dict[HAS_ANGLE] - if dict.has(HAS_PIVOT_X): - has_pivot_x = dict[HAS_PIVOT_X] - if dict.has(HAS_PIVOT_Y): - has_pivot_y = dict[HAS_PIVOT_Y] if dict.has(R): angle = dict[R] if dict.has(PX): diff --git a/scripts/layouts/layout_abnt.gd b/scripts/layouts/layout_abnt.gd index 9acb397..9a2885f 100644 --- a/scripts/layouts/layout_abnt.gd +++ b/scripts/layouts/layout_abnt.gd @@ -19,7 +19,6 @@ func get_rows() -> Array[Array]: KeyProps.W: 1.25, KeyProps.H: 2, KeyProps.X: 0.25, - KeyProps.SECONDARY_RECT: true, KeyProps.W2: 1.5, KeyProps.X2: -0.25, } diff --git a/scripts/layouts/layout_ansi_variant.gd b/scripts/layouts/layout_ansi_variant.gd index 0098859..80462c1 100644 --- a/scripts/layouts/layout_ansi_variant.gd +++ b/scripts/layouts/layout_ansi_variant.gd @@ -21,7 +21,6 @@ func get_rows() -> Array[Array]: KeyProps.KEY: KEY_ENTER, KeyProps.W: 1.5, KeyProps.H: 2, - KeyProps.SECONDARY_RECT: true, KeyProps.W2: 2.25, KeyProps.Y2: 1, KeyProps.X2: -0.75, diff --git a/scripts/layouts/layout_iso.gd b/scripts/layouts/layout_iso.gd index c067854..58c5244 100644 --- a/scripts/layouts/layout_iso.gd +++ b/scripts/layouts/layout_iso.gd @@ -19,7 +19,6 @@ func get_rows() -> Array[Array]: KeyProps.W: 1.25, KeyProps.H: 2, KeyProps.X: 0.25, - KeyProps.SECONDARY_RECT: true, KeyProps.W2: 1.5, KeyProps.X2: -0.25, } diff --git a/scripts/layouts/layout_jis.gd b/scripts/layouts/layout_jis.gd index 5f428ad..7fc0c49 100644 --- a/scripts/layouts/layout_jis.gd +++ b/scripts/layouts/layout_jis.gd @@ -22,7 +22,6 @@ func get_rows() -> Array[Array]: KeyProps.W: 1.25, KeyProps.H: 2, KeyProps.X: 0.25, - KeyProps.SECONDARY_RECT: true, KeyProps.W2: 1.5, KeyProps.X2: -0.25, } diff --git a/scripts/layouts/parser_kle.gd b/scripts/layouts/parser_kle.gd index 959a064..e5ba1ab 100644 --- a/scripts/layouts/parser_kle.gd +++ b/scripts/layouts/parser_kle.gd @@ -163,26 +163,19 @@ func _deserialize_key(data_key: Dictionary) -> Dictionary: if data_key.has(W2): key_dict[KeyProps.W2] = data_key[W2] - key_dict[KeyProps.SECONDARY_RECT] = true if data_key.has(H2): key_dict[KeyProps.H2] = data_key[H2] - key_dict[KeyProps.SECONDARY_RECT] = true if data_key.has(X2): key_dict[KeyProps.X2] = data_key[X2] - key_dict[KeyProps.SECONDARY_RECT] = true if data_key.has(Y2): key_dict[KeyProps.Y2] = data_key[Y2] - key_dict[KeyProps.SECONDARY_RECT] = true if data_key.has(R): key_dict[KeyProps.R] = data_key[R] - key_dict[KeyProps.HAS_ANGLE] = true if data_key.has(RX): key_dict[KeyProps.PX] = data_key[RX] - key_dict[KeyProps.HAS_PIVOT_X] = true if data_key.has(RY): key_dict[KeyProps.PY] = data_key[RY] - key_dict[KeyProps.HAS_PIVOT_Y] = true if data_key.has(N): key_dict[KeyProps.NUB] = data_key[N]