From a23e9dea80ee9c8804114b8fc9d211e3962e7d99 Mon Sep 17 00:00:00 2001 From: Laki Date: Wed, 22 Apr 2026 21:45:26 -0500 Subject: [PATCH 1/4] update cam_area.gd, player now checked at `is_in_bounds()` function, music is switched on _ready() if it doesn't match what it should be --- components/cam_area/cam_area.gd | 64 +++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/components/cam_area/cam_area.gd b/components/cam_area/cam_area.gd index 690faec0..467b0c1c 100644 --- a/components/cam_area/cam_area.gd +++ b/components/cam_area/cam_area.gd @@ -42,10 +42,23 @@ func _ready() -> void: _physics_process.call_deferred(0) + + if is_in_bounds() and change_music: + var music_loader = get_node_or_null(music_loader_ref) + if !music_loader: + printerr("[CamArea] Can't resolve the MusicLoader node") + else: + print(Audio._music_channels) + await get_tree().physics_frame + if music_loader.music[set_music_index] != Audio._music_channels.get(music_loader.channel_id).stream: + music_loader._change_music(music_loader.index, music_loader.channel_id) + + _is_initial = false + return + await get_tree().physics_frame _is_initial = false - func _draw() -> void: if !Engine.is_editor_hint(): return draw_set_transform(-global_position, rotation, Vector2.ONE) @@ -79,28 +92,7 @@ func _get_cam_rect(rect: Control) -> Rect2: func _physics_process(_delta: float) -> void: if Engine.is_editor_hint(): return - var camera = Thunder._current_camera - var is_in_bounds: bool - var has_cam_area: bool = ( - (camera.has_meta(&"cam_area") && - camera.get_meta(&"cam_area", null) != self) || - !camera.has_meta(&"cam_area") - ) - var detections: Array = _det_areas if len(_det_areas) > 0 else [self] - var _int_detections: int = 0 - for i in detections: - var rect = _get_cam_rect(i) - - _int_detections += int( - has_cam_area && - camera.position.x >= rect.position.x && - camera.position.y >= rect.position.y && - camera.position.x < rect.end.x && - camera.position.y < rect.end.y - ) - is_in_bounds = bool(_int_detections) - - if is_in_bounds: + if is_in_bounds(): if is_current: return @@ -119,6 +111,8 @@ func _physics_process(_delta: float) -> void: _switch_bounds() + + if !is_in_bounds && is_current: is_current = false @@ -152,3 +146,27 @@ func _switch_bounds() -> void: if _is_initial: camera.force_update_scroll.call_deferred() + +func is_in_bounds(): + var camera = Thunder._current_camera + var in_bounds: bool + var has_cam_area: bool = ( + (camera.has_meta(&"cam_area") && + camera.get_meta(&"cam_area", null) != self) || + !camera.has_meta(&"cam_area") + ) + var detections: Array = _det_areas if len(_det_areas) > 0 else [self] + var _int_detections: int = 0 + for i in detections: + var rect = _get_cam_rect(i) + + _int_detections += int( + has_cam_area && + camera.position.x >= rect.position.x && + camera.position.y >= rect.position.y && + camera.position.x < rect.end.x && + camera.position.y < rect.end.y + ) + in_bounds = bool(_int_detections) + + return in_bounds From 22c4ea46073d61eb4465304c3e642fc98d730ad1 Mon Sep 17 00:00:00 2001 From: Laki Date: Thu, 23 Apr 2026 08:54:02 -0500 Subject: [PATCH 2/4] cam_area.gd change music on `_ready()` part 2 now changes music on `_ready()` through deferred `change_music_on_ready()` function also removed `print(Audio._music_channels)` --- components/cam_area/cam_area.gd | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/components/cam_area/cam_area.gd b/components/cam_area/cam_area.gd index 467b0c1c..0ac0a662 100644 --- a/components/cam_area/cam_area.gd +++ b/components/cam_area/cam_area.gd @@ -44,21 +44,20 @@ func _ready() -> void: if is_in_bounds() and change_music: - var music_loader = get_node_or_null(music_loader_ref) - if !music_loader: - printerr("[CamArea] Can't resolve the MusicLoader node") - else: - print(Audio._music_channels) - await get_tree().physics_frame - if music_loader.music[set_music_index] != Audio._music_channels.get(music_loader.channel_id).stream: - music_loader._change_music(music_loader.index, music_loader.channel_id) - - _is_initial = false - return + change_music_on_ready.call_deferred() + await get_tree().physics_frame _is_initial = false +func change_music_on_ready(): + var music_loader = get_node_or_null(music_loader_ref) + if !music_loader: + printerr("[CamArea] Can't resolve the MusicLoader node") + else: + if music_loader.music[set_music_index] != Audio._music_channels.get(music_loader.channel_id).stream: + music_loader._change_music(music_loader.index, music_loader.channel_id) + func _draw() -> void: if !Engine.is_editor_hint(): return draw_set_transform(-global_position, rotation, Vector2.ONE) From ae5edc6ce506c2506cb0ab73105e0f55833757c4 Mon Sep 17 00:00:00 2001 From: Laki Date: Thu, 23 Apr 2026 21:45:26 -0500 Subject: [PATCH 3/4] cam_area.gd music on _ready() part 3 forgot to check if the music channel even exists when trying to compare it --- components/cam_area/cam_area.gd | 1 + 1 file changed, 1 insertion(+) diff --git a/components/cam_area/cam_area.gd b/components/cam_area/cam_area.gd index 0ac0a662..dafe02e3 100644 --- a/components/cam_area/cam_area.gd +++ b/components/cam_area/cam_area.gd @@ -55,6 +55,7 @@ func change_music_on_ready(): if !music_loader: printerr("[CamArea] Can't resolve the MusicLoader node") else: + if !Audio._music_channels.get(music_loader.channel_id): return if music_loader.music[set_music_index] != Audio._music_channels.get(music_loader.channel_id).stream: music_loader._change_music(music_loader.index, music_loader.channel_id) From d9e36114779381f5b1ca895d9d986f5c17bcfb1f Mon Sep 17 00:00:00 2001 From: Laki Date: Sat, 25 Apr 2026 14:57:31 -0500 Subject: [PATCH 4/4] cam_area.gd changes part 4 that moment when you forget () and the entire thing breaks --- components/cam_area/cam_area.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cam_area/cam_area.gd b/components/cam_area/cam_area.gd index dafe02e3..e30c8bfb 100644 --- a/components/cam_area/cam_area.gd +++ b/components/cam_area/cam_area.gd @@ -113,7 +113,7 @@ func _physics_process(_delta: float) -> void: - if !is_in_bounds && is_current: + if !is_in_bounds() && is_current: is_current = false