From 4f9a146a72b587fb02705d52fd607c57cda5a485 Mon Sep 17 00:00:00 2001 From: Pawel Lampe Date: Sun, 29 Dec 2024 11:33:31 +0100 Subject: [PATCH] Align scripts to the guidelines --- project.godot | 8 +++--- source/match/IsometricCamera3D.gd | 41 +++++++++++++++++++++-------- source/match/debug/DiagnosticHud.gd | 24 +++++++++++------ 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/project.godot b/project.godot index 50a09dc..bbfd16b 100644 --- a/project.godot +++ b/project.godot @@ -201,14 +201,14 @@ unit_groups_access_9={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":57,"key_label":0,"unicode":57,"location":0,"echo":false,"script":null) ] } -rotate_map_clock={ +rotate_map_clockwise={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) ] } -rotate_map_counterclock={ +rotate_map_counterclockwise={ "deadzone": 0.5, -"events": [null, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null) +"events": [null, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) ] } diff --git a/source/match/IsometricCamera3D.gd b/source/match/IsometricCamera3D.gd index eecd9fa..a5f8d75 100644 --- a/source/match/IsometricCamera3D.gd +++ b/source/match/IsometricCamera3D.gd @@ -1,6 +1,7 @@ extends Camera3D # TODO: perform rotation calculations in 3D space +# TODO: introduce _rotate_by() and simplify arrowkey rotation const EXPECTED_X_ROTATION_DEGREES = -30.0 const EXPECTED_PROJECTION = PROJECTION_ORTHOGONAL @@ -28,6 +29,7 @@ var _camera_point_3d = null var _rotation_pos = Vector2.ZERO var _arrowkey_rotation = false + func _ready(): assert(projection == EXPECTED_PROJECTION, "unexpected projection") assert( @@ -54,24 +56,33 @@ func _physics_process(delta): func _process(_delta): - if !_is_rotating(): + if not _is_rotating(): _move() elif _arrowkey_rotation: - if (Input.is_action_pressed("rotate_map_clock")): + if Input.is_action_pressed("rotate_map_clockwise"): _rotation_pos.x += _delta * arrowkey_rotation_speed - if (Input.is_action_pressed("rotate_map_counterclock")): + if Input.is_action_pressed("rotate_map_counterclockwise"): _rotation_pos.x -= _delta * arrowkey_rotation_speed _rotate(_rotation_pos) func _unhandled_input(event): - if !_is_rotating(): - if Input.is_action_just_pressed("rotate_map_clock") or Input.is_action_just_pressed("rotate_map_counterclock"): + if not _is_rotating(): + if ( + Input.is_action_just_pressed("rotate_map_clockwise") + or Input.is_action_just_pressed("rotate_map_counterclockwise") + ): _arrowkey_rotation = true _start_rotation(event) else: - if Input.is_action_just_released("rotate_map_clock") or Input.is_action_just_released("rotate_map_counterclock") : - if not (Input.is_action_pressed("rotate_map_clock") or Input.is_action_pressed("rotate_map_counterclock")): + if ( + Input.is_action_just_released("rotate_map_clockwise") + or Input.is_action_just_released("rotate_map_counterclockwise") + ): + if not ( + Input.is_action_pressed("rotate_map_clockwise") + or Input.is_action_pressed("rotate_map_counterclockwise") + ): _arrowkey_rotation = false _stop_rotation() if event is InputEventMouseButton: @@ -83,13 +94,21 @@ func _unhandled_input(event): event.is_pressed() and event.button_index == MOUSE_BUTTON_MIDDLE and event.double_click ): _reset_rotation() - elif event.is_pressed() and event.button_index == MOUSE_BUTTON_MIDDLE and !_arrowkey_rotation: + elif ( + event.is_pressed() + and event.button_index == MOUSE_BUTTON_MIDDLE + and not _arrowkey_rotation + ): _start_rotation(event) - elif not event.is_pressed() and event.button_index == MOUSE_BUTTON_MIDDLE and !_arrowkey_rotation: + elif ( + not event.is_pressed() + and event.button_index == MOUSE_BUTTON_MIDDLE + and not _arrowkey_rotation + ): _stop_rotation() elif event is InputEventMouseMotion: - var rotation_pos = event.position #the mouse position - if !_arrowkey_rotation and _is_rotating(): + var rotation_pos = event.position #the mouse position + if not _arrowkey_rotation and _is_rotating(): _rotate(rotation_pos) diff --git a/source/match/debug/DiagnosticHud.gd b/source/match/debug/DiagnosticHud.gd index 178dc48..5b8383d 100644 --- a/source/match/debug/DiagnosticHud.gd +++ b/source/match/debug/DiagnosticHud.gd @@ -13,11 +13,19 @@ func _unhandled_input(event): func _physics_process(_delta): - _fps_label.text = "{0} FPS \n".format(["%0.1f" % (Performance.get_monitor(Performance.TIME_FPS))]) - _fps_label.text += str(OS.get_processor_name()) + " \n" - _fps_label.text += str(OS.get_processor_count()) + " Threads Used \n" - var MBs = OS.get_static_memory_usage()/int(1000000) - _fps_label.text += str(MBs) + " MBs of Memory Used \n" - _fps_label.text += str(RenderingServer.get_video_adapter_name()) + " " - _fps_label.text += str(RenderingServer.get_video_adapter_vendor()) + " \n" - _fps_label.text += "Using " + str(OS.get_name()) + " Operating System" + _fps_label.text = ( + "{0} FPS \n".format(["%0.1f" % (Performance.get_monitor(Performance.TIME_FPS))]) + + str(OS.get_processor_name()) + + " \n" + + str(OS.get_processor_count()) + + " Threads Used \n" + + str(OS.get_static_memory_usage() / int(1000000)) + + " MBs of Memory Used \n" + + str(RenderingServer.get_video_adapter_name()) + + " " + + str(RenderingServer.get_video_adapter_vendor()) + + " \n" + + "Using " + + str(OS.get_name()) + + " Operating System" + )