Skip to content

Commit

Permalink
fix: correct how debug camera 2d works, simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yusdacra committed Dec 5, 2024
1 parent 5a60cb5 commit 24bbfab
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
10 changes: 6 additions & 4 deletions addons/debug_camera/scripts/DebugCamAutoload.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ var debug_cam_2d = preload("res://addons/debug_camera/scripts/DebugCamera2D.gd")
var debug_cam_3d = preload("res://addons/debug_camera/scripts/DebugCamera3D.gd")

func _ready() -> void:
var cur_scene: Node = get_tree().current_scene
# run if play current scene
if ProjectSettings.get("application/run/main_scene") != cur_scene.scene_file_path:
add_debug_cam(cur_scene)
if not OS.is_debug_build(): return
# hook the debug camera in for all scenes we load (if debug)
Scenes.scene_changed.connect(
func(scene: Node, _params: Dictionary) -> void:
add_debug_cam(scene)
)

## call this function after you scene is ready to add the debug camera to it
func add_debug_cam(scene: Node) -> void:
Expand Down
15 changes: 9 additions & 6 deletions addons/debug_camera/scripts/DebugCamera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ var main_cam : Camera2D


func _ready() -> void:
enabled = false; name = "DebugCamera2D"
main_cam = get_viewport().get_camera_2d()


func _process(_delta: float) -> void:
if !enabled:
position = main_cam.global_position
Loggie.debug("debug camera", self)
Loggie.debug("scene camera", main_cam)


func _unhandled_input(event: InputEvent) -> void:
Expand All @@ -39,6 +37,11 @@ func _unhandled_input(event: InputEvent) -> void:
var cam := main_cam
cam.enabled = !cam.enabled
enabled = !cam.enabled
if enabled:
self.make_current()
else:
self.global_position = cam.global_position
cam.make_current()
Loggie.info("toggled 2D debug cam (%s)" % enabled)

if not enabled: return
Expand All @@ -58,5 +61,5 @@ func _unhandled_input(event: InputEvent) -> void:
else:
_moveCamera = false
elif event is InputEventMouseMotion && _moveCamera:
position += (_previousPosition - event.position) / _zoom_level
global_position += (_previousPosition - event.position) / _zoom_level
_previousPosition = event.position
4 changes: 4 additions & 0 deletions addons/debug_camera/scripts/DebugCamera3D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ var main_cam : Camera3D


func _ready() -> void:
current = false
name = "DebugCamera3D"
main_cam = get_viewport().get_camera_3d()
Loggie.debug("debug camera", self)
Loggie.debug("scene camera", main_cam)


func _process(delta: float) -> void:
Expand Down
3 changes: 1 addition & 2 deletions addons/scenes/scenes.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ func _ready() -> void:
change_started.emit(cur_scene.scene_file_path, _params)
# if playing a specific scene
if ProjectSettings.get("application/run/main_scene") != cur_scene.scene_file_path:
if not cur_scene.is_node_ready():
await cur_scene.ready
if not cur_scene.is_node_ready(): await cur_scene.ready
scene_loaded.emit(cur_scene, _params)
scene_changed.emit(cur_scene, _params)

Expand Down
7 changes: 4 additions & 3 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ buses/default_bus_layout="uid://cii2gmf3t8nk4"
[autoload]

Loggie="*res://addons/loggie/loggie.gd"
DebugMenu="*res://addons/debug_menu/debug_menu.tscn"
DebugCam="*res://addons/debug_camera/scripts/DebugCamAutoload.gd"
Scenes="*res://addons/scenes/scenes.gd"
State="*res://utils/state/state.tscn"
Scenes="*res://addons/scenes/scenes.gd"
Shortcuts="*res://addons/shortcuts/shortcuts.gd"
DebugMenu="*res://addons/debug_menu/debug_menu.tscn"
DebugCam="*res://addons/debug_camera/scripts/DebugCamAutoload.gd"

[debug]

Expand Down Expand Up @@ -78,6 +78,7 @@ general/show_loggie_specs=0
timestamps/output_timestamps=true
formats/timestamp="[{hour}:{minute}:{second}]"
formats/info_message="[b][color=green][INFO]:[/color][/b] {msg}"
general/log_level=4
[physics]
Expand Down
6 changes: 0 additions & 6 deletions scenes/_entrypoint/entrypoint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,5 @@ func _ready() -> void:
CONNECT_ONE_SHOT
)
)
# hook the debug camera in for all scenes we load (if debug)
if OS.is_debug_build():
Scenes.scene_changed.connect(
func(scene: Node, _params: Dictionary) -> void:
DebugCam.add_debug_cam(scene)
)
# load our scene
Scenes.change_scene_to(initial_scene)

0 comments on commit 24bbfab

Please sign in to comment.