change dictionaries to inner classes in main_camera and cursor

This commit is contained in:
2025-03-03 14:06:41 +10:00
parent a782d1e820
commit 0835f66ac4
6 changed files with 40 additions and 25 deletions

View File

@@ -33,12 +33,11 @@ func _handle_cursors(delta: float) -> void:
func _init_player_cursor(id: int) -> void:
var cursor_node: Control = _cursor_scene.instantiate() as Control
add_child(cursor_node)
_cursors[id] = {
"base": cursor_node,
"bat": cursor_node.get_node("CursorBat"),
"arrow": cursor_node.get_node("CursorArrow"),
"side": 0
}
_cursors[id] = PlayerCursor.new(
cursor_node,
cursor_node.get_node("CursorBat") as Control,
cursor_node.get_node("CursorArrow") as Control
)
func _handle_cursor(player_index: int, delta: float) -> void:
@@ -58,15 +57,15 @@ func _handle_cursor(player_index: int, delta: float) -> void:
clamp_corner_min += Vector2(screen_inset, screen_inset)
clamp_corner_max -= Vector2(screen_inset, screen_inset)
var cursor: Dictionary = _cursors[id]
var cursor: PlayerCursor = _cursors[id]
cursor["base"].position = (
cursor.base.position = (
cursor_pos_screen.clamp(clamp_corner_min, clamp_corner_max)
- cursor["base"].size / 2
- cursor.base.size / 2
)
cursor["side"] = lerpf(
cursor["side"] as float,
cursor.side = lerpf(
cursor.side as float,
(PI / 2.0) * (1.0 if player.attack.side == PlayerAttack.Side.LEFT else -1.0),
side_change_speed * delta
)
@@ -75,14 +74,26 @@ func _handle_cursor(player_index: int, delta: float) -> void:
var bat_rotation_point_screen := Referencer.main_camera.unproject_position(
(
cursor_pos_world
+ aim_offset_normalized.rotated(Vector3.UP, cursor["side"] as float)
+ aim_offset_normalized.rotated(Vector3.UP, cursor.side as float)
)
)
var arrow_rotation_point_screen := Referencer.main_camera.unproject_position(
cursor_pos_world + aim_offset_normalized
)
cursor["bat"].rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
cursor["arrow"].rotation = cursor_pos_screen.angle_to_point(
cursor.bat.rotation = cursor_pos_screen.angle_to_point(bat_rotation_point_screen)
cursor.arrow.rotation = cursor_pos_screen.angle_to_point(
arrow_rotation_point_screen
)
class PlayerCursor:
var base: Control
var bat: Control
var arrow: Control
var side: float = 0
func _init(_base: Control, _bat: Control, _arrow: Control) -> void:
base = _base
bat = _bat
arrow = _arrow