feat(navigation): extend RoomNavigator for horizontal room-within-floor navigation

This commit is contained in:
Steven Wroblewski
2026-04-17 13:50:00 +02:00
parent 2bb73c905c
commit 903df578e2

View File

@@ -1,12 +1,14 @@
## RoomNavigator — autoload that moves the Camera2D smoothly between hospital floors. ## RoomNavigator — autoload that moves the Camera2D smoothly between hospital floors and rooms.
extends Node extends Node
signal room_changed(floor_index: int) signal room_changed(floor_index: int, room_index: int)
const FLOOR_HEIGHT: float = 720.0 const FLOOR_HEIGHT: float = 720.0
const ROOM_WIDTH: float = 1280.0
const CAMERA_TWEEN_DURATION: float = 0.6 const CAMERA_TWEEN_DURATION: float = 0.6
var _current_floor: int = 0 var _current_floor: int = 0
var _current_room: int = 0
var _camera: Camera2D var _camera: Camera2D
@@ -15,16 +17,28 @@ func initialize(camera: Camera2D) -> void:
func go_to_floor(floor_index: int) -> void: func go_to_floor(floor_index: int) -> void:
if _camera == null or floor_index == _current_floor: go_to_room(floor_index, 0)
func go_to_room(floor_index: int, room_index: int) -> void:
if _camera == null:
return
if floor_index == _current_floor and room_index == _current_room:
return return
_current_floor = floor_index _current_floor = floor_index
_current_room = room_index
var target_x: float = room_index * ROOM_WIDTH + ROOM_WIDTH * 0.5
var target_y: float = floor_index * -FLOOR_HEIGHT + FLOOR_HEIGHT * 0.5 var target_y: float = floor_index * -FLOOR_HEIGHT + FLOOR_HEIGHT * 0.5
var tween: Tween = create_tween() var tween: Tween = create_tween()
tween.set_ease(Tween.EASE_IN_OUT) tween.set_ease(Tween.EASE_IN_OUT)
tween.set_trans(Tween.TRANS_SINE) tween.set_trans(Tween.TRANS_SINE)
tween.tween_property(_camera, "position:y", target_y, CAMERA_TWEEN_DURATION) tween.tween_property(_camera, "position", Vector2(target_x, target_y), CAMERA_TWEEN_DURATION)
tween.finished.connect(func() -> void: room_changed.emit(floor_index)) tween.finished.connect(func() -> void: room_changed.emit(floor_index, room_index))
func get_current_floor() -> int: func get_current_floor() -> int:
return _current_floor return _current_floor
func get_current_room() -> int:
return _current_room