From 520b4a787023e5c4172d448b46a16ecc707224f5 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 11 Oct 2025 05:03:59 -0700 Subject: [PATCH] Improve style in many demos (#1263) --- 2d/bullet_shower/player.gd | 8 +- 2d/custom_drawing/animation.gd | 2 +- 2d/custom_drawing/animation_slice.gd | 4 +- 2d/custom_drawing/lines.gd | 2 +- 2d/custom_drawing/polygons.gd | 2 +- 2d/custom_drawing/rectangles.gd | 2 +- 2d/custom_drawing/text.gd | 2 +- 2d/custom_drawing/textures.gd | 2 +- 2d/dynamic_tilemap_layers/level/tile_map.gd | 2 +- .../debug/states_stack_displayer.gd | 4 +- .../player/weapon/sword.gd | 2 +- .../state_machine/state_machine.gd | 2 +- 2d/glow/beach_cave.gd | 10 ++- 2d/instancing/ball_factory.gd | 10 ++- 2d/lights_and_shadows/light_shadows.gd | 10 +-- 2d/navigation/character.gd | 6 +- 2d/navigation_astar/character.gd | 8 +- 2d/particles/pause.gd | 15 ++-- 2d/physics_platformer/coin/coin.gd | 2 +- 2d/physics_platformer/enemy/enemy.gd | 2 +- 2d/physics_platformer/player/bullet.gd | 2 +- 2d/physics_platformer/player/player.gd | 12 +-- 2d/physics_tests/test.gd | 8 +- 2d/physics_tests/tests.gd | 4 +- .../tests/functional/test_character.gd | 25 +++--- .../tests/functional/test_character_pixels.gd | 21 ++--- .../functional/test_character_tilemap.gd | 24 +++--- .../tests/functional/test_collision_pairs.gd | 6 +- .../tests/functional/test_joints.gd | 28 ++++--- .../functional/test_one_way_collision.gd | 37 +++++---- .../tests/functional/test_pyramid.gd | 4 +- .../tests/functional/test_raycasting.gd | 6 +- .../tests/functional/test_stack.gd | 6 +- .../tests/performance/test_perf_broadphase.gd | 2 +- .../tests/performance/test_perf_contacts.gd | 2 +- 2d/physics_tests/tests_menu.gd | 5 +- .../utils/characterbody_controller.gd | 10 +-- 2d/physics_tests/utils/label_engine.gd | 2 +- 2d/physics_tests/utils/label_test.gd | 2 +- 2d/physics_tests/utils/option_menu.gd | 2 +- .../utils/rigidbody_controller.gd | 6 +- 2d/physics_tests/utils/rigidbody_pick.gd | 10 +-- 2d/physics_tests/utils/scroll_log.gd | 2 +- 2d/platformer/game.gd | 6 +- 2d/platformer/player/player.gd | 8 +- .../combat/combatants/combatant.gd | 2 +- .../dialogue_player/dialogue_player.gd | 4 +- .../grid_movement/pawns/pawn.gd | 2 +- .../grid_movement/pawns/walker.gd | 2 +- 2d/skeleton/player/player.gd | 6 +- 3d/antialiasing/anti_aliasing.gd | 19 +++-- 3d/csg/csg.gd | 25 +++--- 3d/decals/tester.gd | 20 +++-- 3d/global_illumination/camera.gd | 11 +-- 3d/global_illumination/test.gd | 10 +-- 3d/graphics_settings/settings.gd | 4 +- 3d/labels_and_texts/3d_labels_and_texts.gd | 33 ++++---- 3d/labels_and_texts/label_3d_layout.gd | 4 +- 3d/lights_and_shadows/tester.gd | 17 ++-- 3d/material_testers/tester.gd | 18 ++-- 3d/navigation/character.gd | 4 +- 3d/navigation/navmesh.gd | 14 ++-- 3d/occlusion_culling_mesh_lod/camera.gd | 12 +-- 3d/occlusion_culling_mesh_lod/door.gd | 37 +++++---- 3d/occlusion_culling_mesh_lod/node_3d.gd | 11 +-- 3d/particles/tester.gd | 16 ++-- 3d/physical_light_camera_units/options.gd | 2 + 3d/physics_interpolation/player.gd | 8 +- 3d/physics_tests/project.godot | 4 +- 3d/physics_tests/test.gd | 8 +- .../tests/functional/test_collision_pairs.gd | 20 +++-- .../tests/functional/test_joints.gd | 28 ++++--- .../tests/functional/test_moving_platform.gd | 22 ++--- .../tests/functional/test_pyramid.gd | 8 +- .../tests/functional/test_raycasting.gd | 5 +- .../functional/test_rigidbody_ground_check.gd | 6 +- .../tests/functional/test_stack.gd | 8 +- .../tests/performance/test_perf_broadphase.gd | 24 +++--- .../tests/performance/test_perf_contacts.gd | 18 ++-- 3d/physics_tests/tests_menu.gd | 4 +- 3d/physics_tests/utils/camera_orbit.gd | 16 ++-- .../utils/characterbody_physics.gd | 8 +- 3d/physics_tests/utils/container_log.gd | 1 + 3d/physics_tests/utils/control3d.gd | 2 + 3d/physics_tests/utils/label_engine.gd | 3 +- 3d/physics_tests/utils/label_fps.gd | 1 + 3d/physics_tests/utils/label_pause.gd | 1 + 3d/physics_tests/utils/label_test.gd | 3 +- 3d/physics_tests/utils/label_version.gd | 1 + 3d/physics_tests/utils/option_menu.gd | 4 +- .../utils/rigidbody_ground_check.gd | 22 ++--- 3d/physics_tests/utils/rigidbody_pick.gd | 26 +++--- 3d/physics_tests/utils/scroll_log.gd | 4 +- 3d/physics_tests/utils/system.gd | 2 + 3d/physics_tests/utils/system_log.gd | 2 + 3d/platformer/coin/coin.gd | 4 +- 3d/platformer/enemy/enemy.gd | 24 +++--- 3d/platformer/player/bullet/bullet.gd | 2 +- 3d/platformer/player/follow_camera.gd | 12 +-- 3d/platformer/player/player.gd | 32 ++++---- 3d/platformer/project.godot | 1 + 3d/platformer/touch_screen_ui.gd | 1 + .../virtual_joystick/virtual_joystick.gd | 82 +++++++++---------- 3d/procedural_materials/loading.gd | 1 + 3d/procedural_materials/scripts/grid.gd | 2 + 3d/procedural_materials/tester.gd | 28 ++++--- 3d/ragdoll_physics/ragdoll_physics.gd | 23 +++--- 3d/sky_shaders/main.gd | 17 ++-- 3d/soft_body_physics/tester.gd | 29 +++---- 3d/sprites/scripts/3d_sprites.gd | 17 ++-- 3d/truck_town/town/town_scene.gd | 4 +- 3d/truck_town/vehicles/follow_camera.gd | 4 +- 3d/variable_rate_shading/vrs.gd | 2 + 3d/volumetric_fog/camera.gd | 24 +++--- 3d/voxel/player/player.gd | 6 +- 3d/voxel/world/chunk.gd | 2 +- 3d/voxel/world/voxel_world.gd | 4 +- 3d/waypoints/camera.gd | 12 +-- 3d/waypoints/main.gd | 1 + 3d/waypoints/waypoint.gd | 6 +- audio/bpm_sync/bpm_sync.gd | 2 +- audio/device_changer/Changer.gd | 2 +- audio/mic_record/MicRecord.gd | 2 +- compute/post_shader/main.gd | 6 +- compute/post_shader/post_process_shader.gd | 2 +- compute/texture/water_plane/water_plane.gd | 10 +-- gui/accessibility/custom_control.gd | 10 +-- gui/bidi_and_font_features/bidi.gd | 2 +- gui/gd_paint/paint_control.gd | 4 +- gui/gd_paint/tools_panel.gd | 4 +- gui/input_mapping/ActionRemapButton.gd | 18 ++-- gui/input_mapping/KeyPersistence.gd | 2 +- gui/msdf_font/sdf_font_demo.gd | 4 +- loading/serialization/player.gd | 10 +-- .../addons/node25d/main_screen/gizmo_25d.gd | 9 +- .../node25d/main_screen/viewport_25d.gd | 35 ++++---- misc/2.5d/addons/node25d/node25d_plugin.gd | 1 + misc/2.5d/addons/node25d/shadow_math_25d.gd | 1 + misc/2.5d/addons/node25d/y_sort_25d.gd | 2 +- misc/2.5d/assets/cube/cube_math.gd | 3 +- misc/2.5d/assets/platform/platform_sprite.gd | 2 + misc/2.5d/assets/player/player_math_25d.gd | 5 +- misc/2.5d/assets/player/player_sprite.gd | 6 +- misc/2.5d/assets/ui/control_hints.gd | 4 +- misc/custom_logging/custom_logger_ui.gd | 6 +- misc/custom_logging/main.gd | 11 +-- .../graphics_tablet_input.gd | 8 +- misc/joypads/remap/joy_mapping.gd | 12 +-- misc/joypads/remap/remap_wizard.gd | 20 +++-- misc/joypads/remap/remap_wizard.tscn | 1 + misc/large_world_coordinates/controls.gd | 12 +-- .../marker/AxisMarker2D.svg.import | 2 +- .../marker/AxisMarker3D.svg.import | 2 +- .../draggable_window/draggable_region.gd | 7 +- misc/noise_viewer/noise_viewer.gd | 6 +- misc/os_test/actions.gd | 1 + misc/os_test/os_test.gd | 6 +- misc/pause/pause_button.gd | 1 + misc/pause/process_mode.gd | 1 + misc/window_management/control.gd | 12 +-- misc/window_management/observer/observer.gd | 8 +- misc/window_management/window_management.tscn | 2 +- mobile/android_iap/iap_demo.gd | 2 +- .../{CubeScene.tscn => cube_scene.tscn} | 0 .../{GestureArea.gd => gesture_area.gd} | 49 +++++------ ...GestureArea.gd.uid => gesture_area.gd.uid} | 0 .../multitouch_cubes/{Main.tscn => main.tscn} | 4 +- mobile/multitouch_cubes/project.godot | 4 +- mobile/multitouch_view/{Main.gd => main.gd} | 1 + .../{Main.gd.uid => main.gd.uid} | 0 .../multitouch_view/{Main.tscn => main.tscn} | 4 +- mobile/multitouch_view/project.godot | 4 +- .../{TouchHelper.gd => touch_helper.gd} | 20 +++-- ...TouchHelper.gd.uid => touch_helper.gd.uid} | 0 mobile/sensors/main.gd | 2 +- networking/multiplayer_bomber/gamestate.gd | 2 +- networking/multiplayer_bomber/player.gd | 4 +- .../multiplayer_bomber/player_controls.gd | 2 +- networking/multiplayer_bomber/score.gd | 2 +- networking/multiplayer_pong/logic/ball.gd | 2 +- networking/multiplayer_pong/logic/paddle.gd | 4 +- networking/multiplayer_pong/logic/pong.gd | 2 +- .../client/multiplayer_client.gd | 2 +- .../client/ws_webrtc_client.gd | 8 +- .../server/ws_webrtc_server.gd | 8 +- .../websocket/WebSocketServer.gd | 4 +- networking/websocket_minimal/client.gd | 4 +- networking/websocket_minimal/server.gd | 2 +- viewport/3d_scaling/hud.gd | 8 +- .../dynamic_split_screen/camera_controller.gd | 2 +- viewport/gui_in_3d/gui_3d.gd | 28 ++++--- viewport/split_screen_input/player.gd | 13 +-- .../start_vr.gd | 2 +- xr/openxr_composition_layers/start_vr.gd | 2 +- xr/openxr_hand_tracking_demo/start_vr.gd | 2 +- xr/openxr_origin_centric_movement/start_vr.gd | 2 +- xr/openxr_render_models/start_vr.gd | 2 +- 197 files changed, 904 insertions(+), 766 deletions(-) rename mobile/multitouch_cubes/{CubeScene.tscn => cube_scene.tscn} (100%) rename mobile/multitouch_cubes/{GestureArea.gd => gesture_area.gd} (72%) rename mobile/multitouch_cubes/{GestureArea.gd.uid => gesture_area.gd.uid} (100%) rename mobile/multitouch_cubes/{Main.tscn => main.tscn} (98%) rename mobile/multitouch_view/{Main.gd => main.gd} (99%) rename mobile/multitouch_view/{Main.gd.uid => main.gd.uid} (100%) rename mobile/multitouch_view/{Main.tscn => main.tscn} (73%) rename mobile/multitouch_view/{TouchHelper.gd => touch_helper.gd} (61%) rename mobile/multitouch_view/{TouchHelper.gd.uid => touch_helper.gd.uid} (100%) diff --git a/2d/bullet_shower/player.gd b/2d/bullet_shower/player.gd index 5b519c88..afc2de53 100644 --- a/2d/bullet_shower/player.gd +++ b/2d/bullet_shower/player.gd @@ -5,7 +5,7 @@ extends Node2D # is less visual. Bullets are managed together in the `bullets.gd` script. ## The number of bullets currently touched by the player. -var touching := 0 +var touching: int = 0 @onready var sprite: AnimatedSprite2D = $AnimatedSprite2D @@ -16,10 +16,10 @@ func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: # Getting the movement of the mouse so the sprite can follow its position. - if event is InputEventMouseMotion: - position = event.position - Vector2(0, 16) + if input_event is InputEventMouseMotion: + position = input_event.position - Vector2(0, 16) func _on_body_shape_entered(_body_id: RID, _body: Node2D, _body_shape_index: int, _local_shape_index: int) -> void: diff --git a/2d/custom_drawing/animation.gd b/2d/custom_drawing/animation.gd index ee56a326..a21351cc 100644 --- a/2d/custom_drawing/animation.gd +++ b/2d/custom_drawing/animation.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false var time := 0.0 diff --git a/2d/custom_drawing/animation_slice.gd b/2d/custom_drawing/animation_slice.gd index 518800b2..28d0404e 100644 --- a/2d/custom_drawing/animation_slice.gd +++ b/2d/custom_drawing/animation_slice.gd @@ -1,6 +1,8 @@ extends Control -var use_antialiasing := false + +var use_antialiasing: bool = false + func _draw() -> void: var margin := Vector2(240, 70) diff --git a/2d/custom_drawing/lines.gd b/2d/custom_drawing/lines.gd index 61c81721..e678d6af 100644 --- a/2d/custom_drawing/lines.gd +++ b/2d/custom_drawing/lines.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false func _draw() -> void: diff --git a/2d/custom_drawing/polygons.gd b/2d/custom_drawing/polygons.gd index b4e50c35..22c78622 100644 --- a/2d/custom_drawing/polygons.gd +++ b/2d/custom_drawing/polygons.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false func _draw() -> void: diff --git a/2d/custom_drawing/rectangles.gd b/2d/custom_drawing/rectangles.gd index 7d9fd59f..b06852eb 100644 --- a/2d/custom_drawing/rectangles.gd +++ b/2d/custom_drawing/rectangles.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false func _draw() -> void: diff --git a/2d/custom_drawing/text.gd b/2d/custom_drawing/text.gd index 66109f43..840a58ff 100644 --- a/2d/custom_drawing/text.gd +++ b/2d/custom_drawing/text.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false func _draw() -> void: diff --git a/2d/custom_drawing/textures.gd b/2d/custom_drawing/textures.gd index 6d83e817..c9c5ef16 100644 --- a/2d/custom_drawing/textures.gd +++ b/2d/custom_drawing/textures.gd @@ -2,7 +2,7 @@ @tool extends Panel -var use_antialiasing := false +var use_antialiasing: bool = false func _draw() -> void: const ICON = preload("res://icon.svg") diff --git a/2d/dynamic_tilemap_layers/level/tile_map.gd b/2d/dynamic_tilemap_layers/level/tile_map.gd index d46f02b1..b0d2e0dc 100644 --- a/2d/dynamic_tilemap_layers/level/tile_map.gd +++ b/2d/dynamic_tilemap_layers/level/tile_map.gd @@ -1,7 +1,7 @@ extends TileMapLayer # You can have multiple layers if you make this an array. -var player_in_secret := false +var player_in_secret: bool = false var layer_alpha := 1.0 diff --git a/2d/finite_state_machine/debug/states_stack_displayer.gd b/2d/finite_state_machine/debug/states_stack_displayer.gd index 790e2f0d..1c8de04f 100644 --- a/2d/finite_state_machine/debug/states_stack_displayer.gd +++ b/2d/finite_state_machine/debug/states_stack_displayer.gd @@ -3,8 +3,8 @@ extends Panel @onready var fsm_node: Node = get_node(^"../../Player/StateMachine") func _process(_delta: float) -> void: - var states_names := "" - var numbers := "" + var states_names: String = "" + var numbers: String = "" var index := 0 for state: Node in fsm_node.states_stack: diff --git a/2d/finite_state_machine/player/weapon/sword.gd b/2d/finite_state_machine/player/weapon/sword.gd index b563e44e..afc9744b 100644 --- a/2d/finite_state_machine/player/weapon/sword.gd +++ b/2d/finite_state_machine/player/weapon/sword.gd @@ -15,7 +15,7 @@ enum AttackInputStates { var state: States = States.IDLE var attack_input_state := AttackInputStates.IDLE -var ready_for_next_attack := false +var ready_for_next_attack: bool = false const MAX_COMBO_COUNT = 3 var combo_count := 0 diff --git a/2d/finite_state_machine/state_machine/state_machine.gd b/2d/finite_state_machine/state_machine/state_machine.gd index d2e0a0cc..5818d791 100644 --- a/2d/finite_state_machine/state_machine/state_machine.gd +++ b/2d/finite_state_machine/state_machine/state_machine.gd @@ -15,7 +15,7 @@ var states_map := {} var states_stack := [] var current_state: Node = null -var _active := false: +var _active: bool = false: set(value): _active = value set_active(value) diff --git a/2d/glow/beach_cave.gd b/2d/glow/beach_cave.gd index b277f67f..8d3732b2 100644 --- a/2d/glow/beach_cave.gd +++ b/2d/glow/beach_cave.gd @@ -1,16 +1,18 @@ extends Node2D + const CAVE_LIMIT = 1000 var glow_map := preload("res://glow_map.webp") @onready var cave: Node2D = $Cave -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseMotion and event.button_mask > 0: - cave.position.x = clampf(cave.position.x + event.screen_relative.x, -CAVE_LIMIT, 0) - if event.is_action_pressed(&"toggle_glow_map"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event is InputEventMouseMotion and input_event.button_mask > 0: + cave.position.x = clampf(cave.position.x + input_event.screen_relative.x, -CAVE_LIMIT, 0) + + if input_event.is_action_pressed(&"toggle_glow_map"): if $WorldEnvironment.environment.glow_map: $WorldEnvironment.environment.glow_map = null # Restore glow intensity to its default value diff --git a/2d/instancing/ball_factory.gd b/2d/instancing/ball_factory.gd index 4950930d..349ccbb1 100644 --- a/2d/instancing/ball_factory.gd +++ b/2d/instancing/ball_factory.gd @@ -1,13 +1,15 @@ extends Node2D + @export var ball_scene: PackedScene = preload("res://ball.tscn") -func _unhandled_input(event: InputEvent) -> void: - if event.is_echo(): + +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_echo(): return - if event is InputEventMouseButton and event.is_pressed(): - if event.button_index == MOUSE_BUTTON_LEFT: + if input_event is InputEventMouseButton and input_event.is_pressed(): + if input_event.button_index == MOUSE_BUTTON_LEFT: spawn(get_global_mouse_position()) diff --git a/2d/lights_and_shadows/light_shadows.gd b/2d/lights_and_shadows/light_shadows.gd index 8ad28896..315068a3 100644 --- a/2d/lights_and_shadows/light_shadows.gd +++ b/2d/lights_and_shadows/light_shadows.gd @@ -1,17 +1,17 @@ extends Node2D -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_directional_light"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_directional_light"): $DirectionalLight2D.visible = not $DirectionalLight2D.visible - if event.is_action_pressed(&"toggle_point_lights"): + if input_event.is_action_pressed(&"toggle_point_lights"): for point_light in get_tree().get_nodes_in_group(&"point_light"): point_light.visible = not point_light.visible - if event.is_action_pressed(&"cycle_directional_light_shadows_quality"): + if input_event.is_action_pressed(&"cycle_directional_light_shadows_quality"): $DirectionalLight2D.shadow_filter = wrapi($DirectionalLight2D.shadow_filter + 1, 0, 3) - if event.is_action_pressed(&"cycle_point_light_shadows_quality"): + if input_event.is_action_pressed(&"cycle_point_light_shadows_quality"): for point_light in get_tree().get_nodes_in_group(&"point_light"): point_light.shadow_filter = wrapi(point_light.shadow_filter + 1, 0, 3) diff --git a/2d/navigation/character.gd b/2d/navigation/character.gd index 75a6e9bd..581cb85a 100644 --- a/2d/navigation/character.gd +++ b/2d/navigation/character.gd @@ -1,9 +1,11 @@ extends CharacterBody2D + var movement_speed := 200.0 @onready var navigation_agent: NavigationAgent2D = $NavigationAgent2D + func _ready() -> void: # These values need to be adjusted for the actor's speed # and the navigation layout. @@ -14,8 +16,8 @@ func _ready() -> void: # The "click" event is a custom input action defined in # Project > Project Settings > Input Map tab. -func _unhandled_input(event: InputEvent) -> void: - if not event.is_action_pressed(&"click"): +func _unhandled_input(input_event: InputEvent) -> void: + if not input_event.is_action_pressed(&"click"): return set_movement_target(get_global_mouse_position()) diff --git a/2d/navigation_astar/character.gd b/2d/navigation_astar/character.gd index 1d5f64e8..6acd7fac 100644 --- a/2d/navigation_astar/character.gd +++ b/2d/navigation_astar/character.gd @@ -1,5 +1,6 @@ extends Node2D + const PathFindAStar = preload("./pathfind_astar.gd") enum State { @@ -21,6 +22,7 @@ var _next_point := Vector2() @onready var _tile_map: PathFindAStar = $"../TileMapLayer" + func _ready() -> void: _change_state(State.IDLE) @@ -38,14 +40,14 @@ func _physics_process(_delta: float) -> void: _next_point = _path[0] -func _unhandled_input(event: InputEvent) -> void: +func _unhandled_input(input_event: InputEvent) -> void: _click_position = get_global_mouse_position() if _tile_map.is_point_walkable(_click_position): - if event.is_action_pressed(&"teleport_to", false, true): + if input_event.is_action_pressed(&"teleport_to", false, true): _change_state(State.IDLE) global_position = _tile_map.round_local_position(_click_position) reset_physics_interpolation() - elif event.is_action_pressed(&"move_to"): + elif input_event.is_action_pressed(&"move_to"): _change_state(State.FOLLOW) diff --git a/2d/particles/pause.gd b/2d/particles/pause.gd index 76432565..804d23dd 100644 --- a/2d/particles/pause.gd +++ b/2d/particles/pause.gd @@ -1,6 +1,7 @@ extends Label -var is_compatibility := false + +var is_compatibility: bool = false func _ready() -> void: @@ -12,27 +13,27 @@ func _ready() -> void: get_node(^"../..").environment.glow_intensity = 4.0 -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_pause"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_pause"): get_tree().paused = not get_tree().paused - if not is_compatibility and event.is_action_pressed(&"toggle_trails"): + if not is_compatibility and input_event.is_action_pressed(&"toggle_trails"): # Particles disappear if trail type is changed while paused. # Prevent changing particle type while paused to avoid confusion. for particles in get_tree().get_nodes_in_group(&"trailable_particles"): particles.trail_enabled = not particles.trail_enabled - if not is_compatibility and event.is_action_pressed(&"increase_trail_length"): + if not is_compatibility and input_event.is_action_pressed(&"increase_trail_length"): # Particles disappear if trail type is changed while paused. # Prevent changing particle type while paused to avoid confusion. for particles in get_tree().get_nodes_in_group(&"trailable_particles"): particles.trail_lifetime = clampf(particles.trail_lifetime + 0.05, 0.1, 1.0) - if not is_compatibility and event.is_action_pressed(&"decrease_trail_length"): + if not is_compatibility and input_event.is_action_pressed(&"decrease_trail_length"): # Particles disappear if trail type is changed while paused. # Prevent changing particle type while paused to avoid confusion. for particles in get_tree().get_nodes_in_group(&"trailable_particles"): particles.trail_lifetime = clampf(particles.trail_lifetime - 0.05, 0.1, 1.0) - if event.is_action_pressed(&"toggle_glow"): + if input_event.is_action_pressed(&"toggle_glow"): get_node(^"../..").environment.glow_enabled = not get_node(^"../..").environment.glow_enabled diff --git a/2d/physics_platformer/coin/coin.gd b/2d/physics_platformer/coin/coin.gd index 5218ad1f..c4a295a5 100644 --- a/2d/physics_platformer/coin/coin.gd +++ b/2d/physics_platformer/coin/coin.gd @@ -1,7 +1,7 @@ class_name Coin extends Area2D -var taken := false +var taken: bool = false func _on_body_enter(body: Node2D) -> void: if not taken and body is Player: diff --git a/2d/physics_platformer/enemy/enemy.gd b/2d/physics_platformer/enemy/enemy.gd index 97bc3ad4..1cc45ea1 100644 --- a/2d/physics_platformer/enemy/enemy.gd +++ b/2d/physics_platformer/enemy/enemy.gd @@ -11,7 +11,7 @@ enum State { var _state := State.WALKING var direction := -1 -var anim := "" +var anim: String = "" @onready var rc_left := $RaycastLeft as RayCast2D @onready var rc_right := $RaycastRight as RayCast2D diff --git a/2d/physics_platformer/player/bullet.gd b/2d/physics_platformer/player/bullet.gd index 01408684..60046cfe 100644 --- a/2d/physics_platformer/player/bullet.gd +++ b/2d/physics_platformer/player/bullet.gd @@ -1,7 +1,7 @@ class_name Bullet extends RigidBody2D -var disabled := false +var disabled: bool = false func _ready() -> void: ($Timer as Timer).start() diff --git a/2d/physics_platformer/player/player.gd b/2d/physics_platformer/player/player.gd index b9ec5275..6ec2d2d2 100644 --- a/2d/physics_platformer/player/player.gd +++ b/2d/physics_platformer/player/player.gd @@ -14,11 +14,11 @@ const MAX_FLOOR_AIRBORNE_TIME = 0.15 const BULLET_SCENE = preload("res://player/bullet.tscn") const ENEMY_SCENE = preload("res://enemy/enemy.tscn") -var anim := "" -var siding_left := false -var jumping := false -var stopping_jump := false -var shooting := false +var anim: String = "" +var siding_left: bool = false +var jumping: bool = false +var stopping_jump: bool = false +var shooting: bool = false var floor_h_velocity: float = 0.0 @@ -55,7 +55,7 @@ func _integrate_forces(state: PhysicsDirectBodyState2D) -> void: floor_h_velocity = 0.0 # Find the floor (a contact with upwards facing collision normal). - var found_floor := false + var found_floor: bool = false var floor_index := -1 for contact_index in state.get_contact_count(): diff --git a/2d/physics_tests/test.gd b/2d/physics_tests/test.gd index 92350606..3ea688a5 100644 --- a/2d/physics_tests/test.gd +++ b/2d/physics_tests/test.gd @@ -3,17 +3,17 @@ extends Node2D signal wait_done() -@export var _enable_debug_collision := true +@export var _enable_debug_collision: bool = true var _timer: Timer -var _timer_started := false +var _timer_started: bool = false -var _wait_physics_ticks_counter := 0 +var _wait_physics_ticks_counter: int = 0 class Circle2D: extends Node2D var center := Vector2() - var radius := 0.0 + var radius: float = 0.0 var color := Color() func _draw() -> void: diff --git a/2d/physics_tests/tests.gd b/2d/physics_tests/tests.gd index b9d813d6..01653df3 100644 --- a/2d/physics_tests/tests.gd +++ b/2d/physics_tests/tests.gd @@ -1,6 +1,6 @@ extends Node -var _tests := [ +var _tests: Array[Dictionary] = [ { "id": "Functional Tests/Shapes", "path": "res://tests/functional/test_shapes.tscn", @@ -58,5 +58,5 @@ var _tests := [ func _ready() -> void: var test_menu: OptionMenu = $TestsMenu - for test: Variant in _tests: + for test: Dictionary in _tests: test_menu.add_test(test.id, test.path) diff --git a/2d/physics_tests/tests/functional/test_character.gd b/2d/physics_tests/tests/functional/test_character.gd index 94acdaff..e5aadf83 100644 --- a/2d/physics_tests/tests/functional/test_character.gd +++ b/2d/physics_tests/tests/functional/test_character.gd @@ -1,6 +1,7 @@ class_name TestCharacter extends Test + enum BodyType { CHARACTER_BODY, CHARACTER_BODY_RAY, @@ -20,19 +21,19 @@ const OPTION_MOVE_CHARACTER_CONSTANT_SPEED = "Move Options/Use constant speed (C @export var _initial_velocity := Vector2.ZERO @export var _constant_velocity := Vector2.ZERO -@export var _motion_speed := 400.0 -@export var _gravity_force := 50.0 -@export var _jump_force := 1000.0 -@export var _snap_distance := 0.0 -@export var _floor_max_angle := 45.0 +@export var _motion_speed: float = 400.0 +@export var _gravity_force: float = 50.0 +@export var _jump_force: float = 1000.0 +@export var _snap_distance: float = 0.0 +@export var _floor_max_angle: float = 45.0 @export var _body_type := BodyType.CHARACTER_BODY @onready var options: OptionMenu = $Options -var _use_snap := true -var _use_stop_on_slope := true -var _use_floor_only := true -var _use_constant_speed := false +var _use_snap: bool = true +var _use_stop_on_slope: bool = true +var _use_floor_only: bool = true +var _use_constant_speed: bool = false var _body_parent: Node = null var _character_body_template: CharacterBody2D = null @@ -99,8 +100,8 @@ func _process(_delta: float) -> void: label_floor.visible = false -func _input(event: InputEvent) -> void: - var key_event := event as InputEventKey +func _input(input_event: InputEvent) -> void: + var key_event := input_event as InputEventKey if key_event and not key_event.pressed: if key_event.keycode == KEY_1: if _character_body_template: @@ -180,7 +181,7 @@ func _start_test() -> void: _moving_body.queue_free() _moving_body = null - var test_label := "Testing: " + var test_label: String = "Testing: " var template: PhysicsBody2D = null match _body_type: diff --git a/2d/physics_tests/tests/functional/test_character_pixels.gd b/2d/physics_tests/tests/functional/test_character_pixels.gd index 630bdb54..62eb1116 100644 --- a/2d/physics_tests/tests/functional/test_character_pixels.gd +++ b/2d/physics_tests/tests/functional/test_character_pixels.gd @@ -7,12 +7,13 @@ const OPTION_TEST_CASE_DETECT_FLOOR_MOTION_CHANGES = "Test Cases/Floor detection const MOTION_CHANGES_DIR = Vector2(1.0, 1.0) const MOTION_CHANGES_SPEEDS: Array[float] = [0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0] -var _test_floor_detection := false -var _test_motion_changes := false -var _floor_detected := false -var _floor_lost := false +var _test_floor_detection: bool = false +var _test_motion_changes: bool = false +var _floor_detected: bool = false +var _floor_lost: bool = false + +var _failed_reason: String = "" -var _failed_reason := "" func _ready() -> void: super._ready() @@ -42,11 +43,11 @@ func _physics_process(delta: float) -> void: #Log.print_log("Velocity: %s" % velocity) -func _input(event: InputEvent) -> void: - super._input(event) +func _input(input_event: InputEvent) -> void: + super._input(input_event) - if event is InputEventKey and not event.pressed: - if event.keycode == KEY_0: + if input_event is InputEventKey and not input_event.pressed: + if input_event.keycode == KEY_0: await _on_option_selected(OPTION_TEST_CASE_ALL) @@ -118,7 +119,7 @@ func _test_all() -> void: func _set_result(test_passed: bool) -> void: - var result := "" + var result: String = "" if test_passed: result = "PASSED" else: diff --git a/2d/physics_tests/tests/functional/test_character_tilemap.gd b/2d/physics_tests/tests/functional/test_character_tilemap.gd index 79a595ec..e4e9bda8 100644 --- a/2d/physics_tests/tests/functional/test_character_tilemap.gd +++ b/2d/physics_tests/tests/functional/test_character_tilemap.gd @@ -1,5 +1,6 @@ extends TestCharacter + const OPTION_TEST_CASE_ALL = "Test Cases/TEST ALL (0)" const OPTION_TEST_CASE_JUMP_ONE_WAY_RIGID = "Test Cases/Jump through one-way tiles (Rigid Body)" const OPTION_TEST_CASE_JUMP_ONE_WAY_CHARACTER = "Test Cases/Jump through one-way tiles (Character Body)" @@ -7,13 +8,14 @@ const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_RIGID = "Test Cases/Jump through one- const OPTION_TEST_CASE_JUMP_ONE_WAY_CORNER_CHARACTER = "Test Cases/Jump through one-way corner (Character Body)" const OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER = "Test Cases/Fall and pushed on one-way tiles (Character Body)" -var _test_jump_one_way := false -var _test_jump_one_way_corner := false -var _test_fall_one_way := false +var _test_jump_one_way: bool = false +var _test_jump_one_way_corner: bool = false +var _test_fall_one_way: bool = false var _extra_body: PhysicsBody2D = null -var _failed_reason := "" +var _failed_reason: String = "" + func _ready() -> void: super._ready() @@ -26,11 +28,11 @@ func _ready() -> void: options.add_menu_item(OPTION_TEST_CASE_FALL_ONE_WAY_CHARACTER) -func _input(event: InputEvent) -> void: - super._input(event) +func _input(input_event: InputEvent) -> void: + super._input(input_event) - if event is InputEventKey and not event.pressed: - if event.keycode == KEY_0: + if input_event is InputEventKey and not input_event.pressed: + if input_event.keycode == KEY_0: await _on_option_selected(OPTION_TEST_CASE_ALL) @@ -113,7 +115,7 @@ func _test_all() -> void: func _set_result(test_passed: bool) -> void: - var result := "" + var result: String = "" if test_passed: result = "PASSED" else: @@ -187,7 +189,7 @@ func _start_fall_one_way() -> void: func _finalize_jump_one_way() -> void: - var passed := true + var passed: bool = true if not $JumpTargetArea2D.overlaps_body(_moving_body): passed = false _failed_reason = ": the body wasn't able to jump all the way through." @@ -199,7 +201,7 @@ func _finalize_jump_one_way() -> void: func _finalize_fall_one_way() -> void: - var passed := true + var passed: bool = true if $FallTargetArea2D.overlaps_body(_moving_body): passed = false _failed_reason = ": the body was pushed through the one-way collision." diff --git a/2d/physics_tests/tests/functional/test_collision_pairs.gd b/2d/physics_tests/tests/functional/test_collision_pairs.gd index 61d4331f..208dc76c 100644 --- a/2d/physics_tests/tests/functional/test_collision_pairs.gd +++ b/2d/physics_tests/tests/functional/test_collision_pairs.gd @@ -19,7 +19,7 @@ const OFFSET_RANGE = 120.0 @onready var options: OptionMenu = $Options -var _update_collision := false +var _update_collision: bool = false var _collision_test_index := 0 var _collision_shapes: Array[Shape2D] = [] @@ -50,8 +50,8 @@ func _ready() -> void: _update_collision = true -func _input(event: InputEvent) -> void: - var key_event := event as InputEventKey +func _input(input_event: InputEvent) -> void: + var key_event := input_event as InputEventKey if key_event and not key_event.pressed: if key_event.keycode == KEY_1: _on_option_selected(OPTION_TYPE_RECTANGLE) diff --git a/2d/physics_tests/tests/functional/test_joints.gd b/2d/physics_tests/tests/functional/test_joints.gd index e6fa99dd..2595beb5 100644 --- a/2d/physics_tests/tests/functional/test_joints.gd +++ b/2d/physics_tests/tests/functional/test_joints.gd @@ -1,5 +1,6 @@ extends Test + const OPTION_JOINT_TYPE = "Joint Type/%s Joint (%d)" const OPTION_TEST_CASE_BODIES_COLLIDE = "Test case/Attached bodies collide" @@ -10,27 +11,28 @@ const OPTION_TEST_CASE_CHANGE_POSITIONS = "Test case/Set body positions after ad const BOX_SIZE = Vector2(64, 64) -var _update_joint := false +var _update_joint: bool = false var _selected_joint: Joint2D = null -var _bodies_collide := false -var _world_attachement := false -var _dynamic_attachement := false -var _destroy_body := false -var _change_positions := false +var _bodies_collide: bool = false +var _world_attachement: bool = false +var _dynamic_attachement: bool = false +var _destroy_body: bool = false +var _change_positions: bool = false + +var _joint_types: Dictionary[String, Joint2D] = {} -var _joint_types := {} func _ready() -> void: var options: OptionMenu = $Options var joints: Node2D = $Joints for joint_index in joints.get_child_count(): - var joint_node := joints.get_child(joint_index) + var joint_node: Joint2D = joints.get_child(joint_index) joint_node.visible = false var joint_name := String(joint_node.name) - var joint_short := joint_name.substr(0, joint_name.length() - 7) - var option_name := OPTION_JOINT_TYPE % [joint_short, joint_index + 1] + var joint_short: String = joint_name.substr(0, joint_name.length() - 7) + var option_name: String = OPTION_JOINT_TYPE % [joint_short, joint_index + 1] options.add_menu_item(option_name) _joint_types[option_name] = joint_node @@ -54,9 +56,9 @@ func _process(_delta: float) -> void: $LabelJointType.text = "Joint Type: " + String(_selected_joint.name) -func _input(event: InputEvent) -> void: - if event is InputEventKey and not event.pressed: - var joint_index: int = event.keycode - KEY_1 +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey and not input_event.pressed: + var joint_index: int = input_event.keycode - KEY_1 if joint_index >= 0 and joint_index < _joint_types.size(): _selected_joint = _joint_types.values()[joint_index] _update_joint = true diff --git a/2d/physics_tests/tests/functional/test_one_way_collision.gd b/2d/physics_tests/tests/functional/test_one_way_collision.gd index 4f2f1748..a7b37fd1 100644 --- a/2d/physics_tests/tests/functional/test_one_way_collision.gd +++ b/2d/physics_tests/tests/functional/test_one_way_collision.gd @@ -1,6 +1,7 @@ @tool extends Test + signal all_tests_done() signal test_done() @@ -18,23 +19,23 @@ const OPTION_TEST_CASE_MOVING_PLATFORM_CHARACTER = "Test Cases/Moving Platform ( const TEST_ALL_ANGLES_STEP = 15.0 const TEST_ALL_ANGLES_MAX = 344.0 -@export_range(64, 256, 0.1) var _platform_size := 128.0: +@export_range(64, 256, 0.1) var _platform_size: float = 128.0: set(value): if value == _platform_size: return _platform_size = value _update_platform_size(value) -@export_range(0, 360, 0.1) var _platform_angle := 0.0: +@export_range(0, 360, 0.1) var _platform_angle: float = 0.0: set(value): if value == _platform_angle: return _platform_angle = value _update_platform_angle(value) -@export var _platform_speed := 0.0 +@export var _platform_speed: float = 0.0 -@export_range(0, 360, 0.1) var _body_angle := 0.0: +@export_range(0, 360, 0.1) var _body_angle: float = 0.0: set(value): if value == _body_angle: return @@ -42,7 +43,7 @@ const TEST_ALL_ANGLES_MAX = 344.0 _update_rigidbody_angle(value) @export var _body_velocity := Vector2(400.0, 0.0) -@export var _use_character_body := false +@export var _use_character_body: bool = false @onready var options: OptionMenu = $Options @@ -56,15 +57,15 @@ var _platform_velocity := Vector2.ZERO @onready var _target_area: Area2D = $TargetArea2D -var _contact_detected := false -var _target_entered := false -var _test_passed := false +var _contact_detected: bool = false +var _target_entered: bool = false +var _test_passed: bool = false var _test_step := 0 -var _test_all_angles := false -var _lock_controls := false +var _test_all_angles: bool = false +var _lock_controls: bool = false -var _test_canceled := false +var _test_canceled: bool = false func _ready() -> void: @@ -124,13 +125,13 @@ func _physics_process(delta: float) -> void: _platform_body.global_position += motion -func _input(event: InputEvent) -> void: - if event is InputEventKey and not event.pressed: - if event.keycode == KEY_0: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey and not input_event.pressed: + if input_event.keycode == KEY_0: await _on_option_selected(OPTION_TEST_CASE_ALL) - if event.keycode == KEY_1: + if input_event.keycode == KEY_1: await _on_option_selected(OPTION_OBJECT_TYPE_RIGIDBODY) - elif event.keycode == KEY_2: + elif input_event.keycode == KEY_2: await _on_option_selected(OPTION_OBJECT_TYPE_CHARACTER) @@ -347,7 +348,7 @@ func _test_all() -> void: func _start_test() -> void: - var test_label := "Testing: " + var test_label: String = "Testing: " var platform_angle := _platform_template.rotation if _platform_body: @@ -510,7 +511,7 @@ func _on_timeout() -> void: func _set_result() -> void: - var result := "" + var result: String = "" if _test_passed: result = "PASSED" $LabelResult.self_modulate = Color.GREEN diff --git a/2d/physics_tests/tests/functional/test_pyramid.gd b/2d/physics_tests/tests/functional/test_pyramid.gd index 9273dcd5..f1f1b785 100644 --- a/2d/physics_tests/tests/functional/test_pyramid.gd +++ b/2d/physics_tests/tests/functional/test_pyramid.gd @@ -1,9 +1,11 @@ extends Test -@export_range(1, 100) var height := 10 + +@export_range(1, 100) var height: int = 10 @export var box_size := Vector2(40.0, 40.0) @export var box_spacing := Vector2(0.0, 0.0) + func _ready() -> void: _create_pyramid() diff --git a/2d/physics_tests/tests/functional/test_raycasting.gd b/2d/physics_tests/tests/functional/test_raycasting.gd index b1bc2f03..9852acad 100644 --- a/2d/physics_tests/tests/functional/test_raycasting.gd +++ b/2d/physics_tests/tests/functional/test_raycasting.gd @@ -1,9 +1,11 @@ extends Test + const OPTION_TEST_CASE_HIT_FROM_INSIDE = "Test case/Hit from inside" -var _hit_from_inside := false -var _do_raycasts := false +var _hit_from_inside: bool = false +var _do_raycasts: bool = false + func _ready() -> void: var options: OptionMenu = $Options diff --git a/2d/physics_tests/tests/functional/test_stack.gd b/2d/physics_tests/tests/functional/test_stack.gd index 09786140..1e13c42f 100644 --- a/2d/physics_tests/tests/functional/test_stack.gd +++ b/2d/physics_tests/tests/functional/test_stack.gd @@ -1,10 +1,12 @@ extends Test -@export var height := 10 -@export var width := 1 + +@export var height: int = 10 +@export var width: int = 1 @export var box_size := Vector2(40.0, 40.0) @export var box_spacing := Vector2(0.0, 0.0) + func _ready() -> void: _create_stack() diff --git a/2d/physics_tests/tests/performance/test_perf_broadphase.gd b/2d/physics_tests/tests/performance/test_perf_broadphase.gd index 29c07270..b2317823 100644 --- a/2d/physics_tests/tests/performance/test_perf_broadphase.gd +++ b/2d/physics_tests/tests/performance/test_perf_broadphase.gd @@ -8,7 +8,7 @@ const BOX_SPACE = Vector2(50, 50) var _objects: Array[Node2D] = [] -var _log_physics := false +var _log_physics: bool = false var _log_physics_time := 0 var _log_physics_time_start := 0 diff --git a/2d/physics_tests/tests/performance/test_perf_contacts.gd b/2d/physics_tests/tests/performance/test_perf_contacts.gd index 3d32c775..befeef98 100644 --- a/2d/physics_tests/tests/performance/test_perf_contacts.gd +++ b/2d/physics_tests/tests/performance/test_perf_contacts.gd @@ -15,7 +15,7 @@ const OPTION_TYPE_CONCAVE_POLYGON = "Shape type/Concave Polygon" var _object_templates: Array[Node2D] = [] -var _log_physics := false +var _log_physics: bool = false var _log_physics_time := 0 var _log_physics_time_start := 0 diff --git a/2d/physics_tests/tests_menu.gd b/2d/physics_tests/tests_menu.gd index 71f64347..379492f7 100644 --- a/2d/physics_tests/tests_menu.gd +++ b/2d/physics_tests/tests_menu.gd @@ -2,8 +2,8 @@ extends OptionMenu class TestData: - var id := "" - var scene_path := "" + var id: String = "" + var scene_path: String = "" var _test_list := [] @@ -11,6 +11,7 @@ var _test_list := [] var _current_test: TestData = null var _current_test_scene: Node = null + func _ready() -> void: option_selected.connect(_on_option_selected) diff --git a/2d/physics_tests/utils/characterbody_controller.gd b/2d/physics_tests/utils/characterbody_controller.gd index df228b46..a7f59c8f 100644 --- a/2d/physics_tests/utils/characterbody_controller.gd +++ b/2d/physics_tests/utils/characterbody_controller.gd @@ -8,11 +8,11 @@ var _jump_force := 1000.0 var _velocity := Vector2.ZERO var _snap := 0.0 var _floor_max_angle := 45.0 -var _stop_on_slope := false -var _move_on_floor_only := false -var _constant_speed := false -var _jumping := false -var _keep_velocity := false +var _stop_on_slope: bool = false +var _move_on_floor_only: bool = false +var _constant_speed: bool = false +var _jumping: bool = false +var _keep_velocity: bool = false func _physics_process(delta: float) -> void: diff --git a/2d/physics_tests/utils/label_engine.gd b/2d/physics_tests/utils/label_engine.gd index 7e97aca9..28646ff4 100644 --- a/2d/physics_tests/utils/label_engine.gd +++ b/2d/physics_tests/utils/label_engine.gd @@ -1,7 +1,7 @@ extends Label func _ready() -> void: - var engine_name := "" + var engine_name: String = "" match System.get_physics_engine(): System.PhysicsEngine.GODOT_PHYSICS: diff --git a/2d/physics_tests/utils/label_test.gd b/2d/physics_tests/utils/label_test.gd index 6fdcc123..ff7e759f 100644 --- a/2d/physics_tests/utils/label_test.gd +++ b/2d/physics_tests/utils/label_test.gd @@ -1,6 +1,6 @@ extends Label -var test_name := "": +var test_name: String = "": set(value): if (test_name != value): return diff --git a/2d/physics_tests/utils/option_menu.gd b/2d/physics_tests/utils/option_menu.gd index 460e361c..7c244d11 100644 --- a/2d/physics_tests/utils/option_menu.gd +++ b/2d/physics_tests/utils/option_menu.gd @@ -10,7 +10,7 @@ func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = fa var path_element_count := path_elements.size() assert(path_element_count > 0) - var path := "" + var path: String = "" var popup := get_popup() for element_index in range(path_element_count - 1): var popup_label := path_elements[element_index] diff --git a/2d/physics_tests/utils/rigidbody_controller.gd b/2d/physics_tests/utils/rigidbody_controller.gd index 1b616158..e7216bac 100644 --- a/2d/physics_tests/utils/rigidbody_controller.gd +++ b/2d/physics_tests/utils/rigidbody_controller.gd @@ -7,9 +7,9 @@ var _gravity_force := 50.0 var _jump_force := 1000.0 var _velocity := Vector2.ZERO var _floor_max_angle := 45.0 -var _on_floor := false -var _jumping := false -var _keep_velocity := false +var _on_floor: bool = false +var _jumping: bool = false +var _keep_velocity: bool = false func _ready() -> void: gravity_scale = 0.0 diff --git a/2d/physics_tests/utils/rigidbody_pick.gd b/2d/physics_tests/utils/rigidbody_pick.gd index 516bb683..f3c24e1b 100644 --- a/2d/physics_tests/utils/rigidbody_pick.gd +++ b/2d/physics_tests/utils/rigidbody_pick.gd @@ -1,6 +1,6 @@ extends RigidBody2D -var _picked := false +var _picked: bool = false var _last_mouse_pos := Vector2.ZERO @@ -8,14 +8,14 @@ func _ready() -> void: input_pickable = true -func _input(event: InputEvent) -> void: - var mouse_event := event as InputEventMouseButton +func _input(any_input_event: InputEvent) -> void: + var mouse_event := any_input_event as InputEventMouseButton if mouse_event and not mouse_event.pressed: _picked = false -func _input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: - var mouse_event := event as InputEventMouseButton +func _input_event(_viewport: Node, any_input_event: InputEvent, _shape_idx: int) -> void: + var mouse_event := any_input_event as InputEventMouseButton if mouse_event and mouse_event.pressed: _picked = true _last_mouse_pos = get_global_mouse_position() diff --git a/2d/physics_tests/utils/scroll_log.gd b/2d/physics_tests/utils/scroll_log.gd index 12496e0d..02da1fa4 100644 --- a/2d/physics_tests/utils/scroll_log.gd +++ b/2d/physics_tests/utils/scroll_log.gd @@ -1,6 +1,6 @@ extends ScrollContainer -@export var auto_scroll := false +@export var auto_scroll: bool = false func _ready() -> void: var scrollbar := get_v_scroll_bar() diff --git a/2d/platformer/game.gd b/2d/platformer/game.gd index 5ba24a10..d8acc613 100644 --- a/2d/platformer/game.gd +++ b/2d/platformer/game.gd @@ -5,8 +5,8 @@ extends Node @onready var _pause_menu := $InterfaceLayer/PauseMenu as PauseMenu -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_fullscreen"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_fullscreen"): var mode := DisplayServer.window_get_mode() if mode == DisplayServer.WINDOW_MODE_FULLSCREEN or \ mode == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN: @@ -15,7 +15,7 @@ func _unhandled_input(event: InputEvent) -> void: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) get_tree().root.set_input_as_handled() - elif event.is_action_pressed(&"toggle_pause"): + elif input_event.is_action_pressed(&"toggle_pause"): var tree := get_tree() tree.paused = not tree.paused if tree.paused: diff --git a/2d/platformer/player/player.gd b/2d/platformer/player/player.gd index 3d371874..b8d301ac 100644 --- a/2d/platformer/player/player.gd +++ b/2d/platformer/player/player.gd @@ -12,7 +12,7 @@ const TERMINAL_VELOCITY = 700 ## The player listens for input actions appended with this suffix.[br] ## Used to separate controls for multiple players in splitscreen. -@export var action_suffix := "" +@export var action_suffix: String = "" var gravity: int = ProjectSettings.get(&"physics/2d/default_gravity") @onready var platform_detector := $PlatformDetector as RayCast2D @@ -22,7 +22,7 @@ var gravity: int = ProjectSettings.get(&"physics/2d/default_gravity") @onready var jump_sound := $Jump as AudioStreamPlayer2D @onready var gun: Gun = sprite.get_node(^"Gun") @onready var camera := $Camera as Camera2D -var _double_jump_charged := false +var _double_jump_charged: bool = false func _physics_process(delta: float) -> void: @@ -48,7 +48,7 @@ func _physics_process(delta: float) -> void: floor_stop_on_slope = not platform_detector.is_colliding() move_and_slide() - var is_shooting := false + var is_shooting: bool = false if Input.is_action_just_pressed("shoot" + action_suffix): is_shooting = gun.shoot(sprite.scale.x) @@ -59,7 +59,7 @@ func _physics_process(delta: float) -> void: animation_player.play(animation) -func get_new_animation(is_shooting := false) -> String: +func get_new_animation(is_shooting: bool = false) -> String: var animation_new: String if is_on_floor(): if absf(velocity.x) > 0.1: diff --git a/2d/role_playing_game/combat/combatants/combatant.gd b/2d/role_playing_game/combat/combatants/combatant.gd index a2194cb5..faf114a2 100644 --- a/2d/role_playing_game/combat/combatants/combatant.gd +++ b/2d/role_playing_game/combat/combatants/combatant.gd @@ -6,7 +6,7 @@ signal turn_finished @export var damage := 1 @export var defense := 1 -var active := false: set = set_active +var active: bool = false: set = set_active @onready var animation_playback: AnimationNodeStateMachinePlayback = $Sprite2D/AnimationTree.get(&"parameters/playback") diff --git a/2d/role_playing_game/dialogue/dialogue_player/dialogue_player.gd b/2d/role_playing_game/dialogue/dialogue_player/dialogue_player.gd index e874ccbf..389e54d6 100644 --- a/2d/role_playing_game/dialogue/dialogue_player/dialogue_player.gd +++ b/2d/role_playing_game/dialogue/dialogue_player/dialogue_player.gd @@ -5,9 +5,9 @@ signal dialogue_finished @export_file("*.json") var dialogue_file: String var dialogue_keys := [] -var dialogue_name := "" +var dialogue_name: String = "" var current := 0 -var dialogue_text := "" +var dialogue_text: String = "" func start_dialogue() -> void: diff --git a/2d/role_playing_game/grid_movement/pawns/pawn.gd b/2d/role_playing_game/grid_movement/pawns/pawn.gd index 2e599bae..ab12134e 100644 --- a/2d/role_playing_game/grid_movement/pawns/pawn.gd +++ b/2d/role_playing_game/grid_movement/pawns/pawn.gd @@ -9,7 +9,7 @@ enum CellType { @export var type := CellType.ACTOR -var active := true: set = set_active +var active: bool = true: set = set_active func set_active(value: bool) -> void: active = value diff --git a/2d/role_playing_game/grid_movement/pawns/walker.gd b/2d/role_playing_game/grid_movement/pawns/walker.gd index 1c45dc26..0a4b20b5 100644 --- a/2d/role_playing_game/grid_movement/pawns/walker.gd +++ b/2d/role_playing_game/grid_movement/pawns/walker.gd @@ -5,7 +5,7 @@ extends Pawn @export var combat_actor: PackedScene @export var pose_anims: SpriteFrames -var lost := false +var lost: bool = false var grid_size: float @onready var grid : Grid = get_parent() diff --git a/2d/skeleton/player/player.gd b/2d/skeleton/player/player.gd index 5bbe8cf6..3499ffa1 100644 --- a/2d/skeleton/player/player.gd +++ b/2d/skeleton/player/player.gd @@ -16,8 +16,8 @@ const JUMP_VELOCITY = -400.0 ## Maximum speed at which the player can fall. const TERMINAL_VELOCITY = 400 -var falling_slow := false -var falling_fast := false +var falling_slow: bool = false +var falling_fast: bool = false var no_move_horizontal_time := 0.0 @onready var gravity := float(ProjectSettings.get_setting("physics/2d/default_gravity")) @@ -30,7 +30,7 @@ func _ready() -> void: func _physics_process(delta: float) -> void: - var is_jumping := false + var is_jumping: bool = false if Input.is_action_just_pressed(&"jump"): is_jumping = try_jump() elif Input.is_action_just_released(&"jump") and velocity.y < 0.0: diff --git a/3d/antialiasing/anti_aliasing.gd b/3d/antialiasing/anti_aliasing.gd index cbd22e6a..20fb75b9 100644 --- a/3d/antialiasing/anti_aliasing.gd +++ b/3d/antialiasing/anti_aliasing.gd @@ -1,5 +1,6 @@ extends Node + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE @@ -15,7 +16,7 @@ var camera_distance := 2.0 @onready var camera: Camera3D = $CameraHolder/RotationX/Camera3D @onready var fps_label: Label = $FPSLabel -var is_compatibility := false +var is_compatibility: bool = false func _ready() -> void: @@ -41,22 +42,22 @@ func _ready() -> void: get_viewport().size_changed.connect(_on_viewport_size_changed) -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: camera_distance -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: camera_distance += ZOOM_SPEED camera_distance = clamp(camera_distance, 1.5, 6) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clamp(rot_x, -1.57, 0) diff --git a/3d/csg/csg.gd b/3d/csg/csg.gd index 5f0b3982..2b787de8 100644 --- a/3d/csg/csg.gd +++ b/3d/csg/csg.gd @@ -1,13 +1,14 @@ extends Node + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE -var tester_index := 0 -var rot_x := -TAU / 16 # This must be kept in sync with RotationX. -var rot_y := TAU / 8 # This must be kept in sync with CameraHolder. -var camera_distance := 4.0 +var tester_index: int = 0 +var rot_x: float = -TAU / 16 # This must be kept in sync with RotationX. +var rot_y: float = TAU / 8 # This must be kept in sync with CameraHolder. +var camera_distance: float = 4.0 @onready var testers: Node3D = $Testers @onready var camera_holder: Node3D = $CameraHolder # Has a position and rotates on Y. @@ -29,22 +30,22 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: camera_distance -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: camera_distance += ZOOM_SPEED camera_distance = clamp(camera_distance, 1.5, 6) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clamp(rot_x, -1.57, 0) diff --git a/3d/decals/tester.gd b/3d/decals/tester.gd index f594bd89..09ba3d53 100644 --- a/3d/decals/tester.gd +++ b/3d/decals/tester.gd @@ -1,5 +1,6 @@ extends WorldEnvironment + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE @@ -14,19 +15,20 @@ var zoom := 1.5 @onready var rotation_x: Node3D = $CameraHolder/RotationX @onready var camera: Camera3D = $CameraHolder/RotationX/Camera3D + func _ready() -> void: camera_holder.transform.basis = Basis.from_euler(Vector3(0, rot_y, 0)) rotation_x.transform.basis = Basis.from_euler(Vector3(rot_x, 0, 0)) update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event.is_action_pressed(&"place_decal"): + if input_event.is_action_pressed(&"place_decal"): var origin := camera.global_position var target := camera.project_position(get_viewport().get_mouse_position(), 100) @@ -40,16 +42,16 @@ func _unhandled_input(event: InputEvent) -> void: decal.position = result["position"] decal.transform.basis = camera.global_transform.basis - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clampf(zoom, 1.5, 4) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clampf(rot_x, deg_to_rad(-90), 0) diff --git a/3d/global_illumination/camera.gd b/3d/global_illumination/camera.gd index a37650d2..b222df3d 100644 --- a/3d/global_illumination/camera.gd +++ b/3d/global_illumination/camera.gd @@ -1,5 +1,6 @@ extends Camera3D + const MOUSE_SENSITIVITY = 0.002 const MOVE_SPEED = 1.5 @@ -10,16 +11,16 @@ func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: # Mouse look (only if the mouse is captured). - if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + if input_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: # Horizontal mouse look. - rot.y -= event.screen_relative.x * MOUSE_SENSITIVITY + rot.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY # Vertical mouse look. - rot.x = clamp(rot.x - event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) + rot.x = clamp(rot.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) transform.basis = Basis.from_euler(rot) - if event.is_action_pressed(&"toggle_mouse_capture"): + if input_event.is_action_pressed(&"toggle_mouse_capture"): if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) else: diff --git a/3d/global_illumination/test.gd b/3d/global_illumination/test.gd index 0bdf3c56..6ce0db9d 100644 --- a/3d/global_illumination/test.gd +++ b/3d/global_illumination/test.gd @@ -51,7 +51,7 @@ var gi_mode_texts: Array[String] = [ var gi_mode := GIMode.NONE var reflection_probe_mode := ReflectionProbeMode.NONE var ssil_mode := SSILMode.NONE -var is_compatibility := false +var is_compatibility: bool = false # This is replaced further below if using Compatibility to point to a newly created DirectionalLight3D # (which does not affect sky rendering). @@ -93,8 +93,8 @@ Escape or F10: Toggle mouse capture""" set_ssil_mode(ssil_mode) -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"cycle_gi_mode"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"cycle_gi_mode"): if is_compatibility: # Only LightmapGI is supported in Compatibility. # Note that the actual GI mode is the opposite of what's being set here, due to a bug @@ -103,10 +103,10 @@ func _input(event: InputEvent) -> void: else: set_gi_mode(wrapi(gi_mode + 1, 0, GIMode.MAX)) - if event.is_action_pressed(&"cycle_reflection_probe_mode"): + if input_event.is_action_pressed(&"cycle_reflection_probe_mode"): set_reflection_probe_mode(wrapi(reflection_probe_mode + 1, 0, ReflectionProbeMode.MAX)) - if event.is_action_pressed(&"cycle_ssil_mode"): + if input_event.is_action_pressed(&"cycle_ssil_mode"): set_ssil_mode(wrapi(ssil_mode + 1, 0, SSILMode.MAX)) diff --git a/3d/graphics_settings/settings.gd b/3d/graphics_settings/settings.gd index cff0a4a8..a82a5e23 100644 --- a/3d/graphics_settings/settings.gd +++ b/3d/graphics_settings/settings.gd @@ -10,7 +10,7 @@ extends Control @onready var fps_label := $FPSLabel @onready var resolution_label := $ResolutionLabel -var counter := 0.0 +var counter: float = 0.0 # When the screen changes size, we need to update the 3D # viewport quality setting. If we don't do this, the viewport will take @@ -20,7 +20,7 @@ var viewport_start_size := Vector2( ProjectSettings.get_setting(&"display/window/size/viewport_height") ) -var is_compatibility := false +var is_compatibility: bool = false func _ready() -> void: diff --git a/3d/labels_and_texts/3d_labels_and_texts.gd b/3d/labels_and_texts/3d_labels_and_texts.gd index fe3bbb30..20d87bd7 100644 --- a/3d/labels_and_texts/3d_labels_and_texts.gd +++ b/3d/labels_and_texts/3d_labels_and_texts.gd @@ -1,13 +1,14 @@ extends Node + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE -var tester_index := 0 -var rot_x := -TAU / 16 # This must be kept in sync with RotationX. -var rot_y := TAU / 8 # This must be kept in sync with CameraHolder. -var camera_distance := 2.0 +var tester_index: int = 0 +var rot_x: float = -TAU / 16 # This must be kept in sync with RotationX. +var rot_y: float = TAU / 8 # This must be kept in sync with CameraHolder. +var camera_distance: float = 2.0 @onready var testers: Node3D = $Testers @onready var camera_holder: Node3D = $CameraHolder # Has a position and rotates on Y. @@ -21,25 +22,25 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: camera_distance -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: camera_distance += ZOOM_SPEED - camera_distance = clamp(camera_distance, 1.5, 6) + camera_distance = clampf(camera_distance, 1.5, 6.0) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED - rot_x = clamp(rot_x, -1.57, 0) + rot_x = clampf(rot_x, -1.57, 0.0) camera_holder.transform.basis = Basis.from_euler(Vector3(0, rot_y, 0)) rotation_x.transform.basis = Basis.from_euler(Vector3(rot_x, 0, 0)) @@ -54,12 +55,12 @@ func _process(delta: float) -> void: func _on_previous_pressed() -> void: - tester_index = max(0, tester_index - 1) + tester_index = maxi(0, tester_index - 1) update_gui() func _on_next_pressed() -> void: - tester_index = min(tester_index + 1, testers.get_child_count() - 1) + tester_index = mini(tester_index + 1, testers.get_child_count() - 1) update_gui() diff --git a/3d/labels_and_texts/label_3d_layout.gd b/3d/labels_and_texts/label_3d_layout.gd index 11a131ba..47636426 100644 --- a/3d/labels_and_texts/label_3d_layout.gd +++ b/3d/labels_and_texts/label_3d_layout.gd @@ -56,8 +56,8 @@ func set_health(p_health: int) -> void: # Construct a health bar with `|` symbols brought very close to each other using # a custom FontVariation on the HealthBarForeground and HealthBarBackground nodes. - var bar_text := "" - var bar_text_bg := "" + var bar_text: String = "" + var bar_text_bg: String = "" for i in roundi((health / 100.0) * BAR_WIDTH): bar_text += "|" for i in BAR_WIDTH: diff --git a/3d/lights_and_shadows/tester.gd b/3d/lights_and_shadows/tester.gd index 409a0452..618930fe 100644 --- a/3d/lights_and_shadows/tester.gd +++ b/3d/lights_and_shadows/tester.gd @@ -1,5 +1,6 @@ extends WorldEnvironment + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE @@ -21,22 +22,22 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clamp(zoom, 1.5, 4) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clamp(rot_x, deg_to_rad(-90), 0) diff --git a/3d/material_testers/tester.gd b/3d/material_testers/tester.gd index 19e06318..e90fee9a 100644 --- a/3d/material_testers/tester.gd +++ b/3d/material_testers/tester.gd @@ -1,5 +1,6 @@ extends Node3D + const INTERP_SPEED = 2 const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.1 @@ -26,6 +27,7 @@ var backgrounds: Array[Dictionary] = [ @onready var rotation_x: Node3D = $CameraHolder/RotationX @onready var camera: Camera3D = $CameraHolder/RotationX/Camera + func _ready() -> void: if RenderingServer.get_current_rendering_method() == "gl_compatibility": # Tweak scene brightness to better match Forward+/Mobile. @@ -38,23 +40,23 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clamp(zoom, 2, 8) camera.position.z = zoom - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_y = clamp(rot_y, -1.95, 1.95) rot_x -= relative_motion.y * ROT_SPEED diff --git a/3d/navigation/character.gd b/3d/navigation/character.gd index d80f3212..21075b4c 100644 --- a/3d/navigation/character.gd +++ b/3d/navigation/character.gd @@ -1,7 +1,7 @@ extends Marker3D @export var character_speed := 10.0 -@export var show_path := true +@export var show_path: bool = true var _nav_path_line: Line3D @@ -33,7 +33,7 @@ func set_target_position(target_position: Vector3) -> void: # Get a full navigation path with the NavigationServer API. if show_path: var start_position := global_transform.origin - var optimize := true + var optimize: bool = true var navigation_map := get_world_3d().get_navigation_map() var path := NavigationServer3D.map_get_path( navigation_map, diff --git a/3d/navigation/navmesh.gd b/3d/navigation/navmesh.gd index f41aecdf..681700c1 100644 --- a/3d/navigation/navmesh.gd +++ b/3d/navigation/navmesh.gd @@ -1,5 +1,6 @@ extends Node3D + const Character = preload("res://character.gd") var _cam_rotation := 0.0 @@ -7,10 +8,11 @@ var _cam_rotation := 0.0 @onready var _camera := $CameraBase/Camera3D as Camera3D @onready var _robot := $RobotBase as Character -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: + +func _unhandled_input(input_event: InputEvent) -> void: + if input_event is InputEventMouseButton and input_event.button_index == MOUSE_BUTTON_LEFT and input_event.pressed: # Get closest point on navmesh for the current mouse cursor position. - var mouse_cursor_position: Vector2 = event.position + var mouse_cursor_position: Vector2 = input_event.position var camera_ray_length := 1000.0 var camera_ray_start := _camera.project_ray_origin(mouse_cursor_position) var camera_ray_end := camera_ray_start + _camera.project_ray_normal(mouse_cursor_position) * camera_ray_length @@ -22,7 +24,7 @@ func _unhandled_input(event: InputEvent) -> void: ) _robot.set_target_position(closest_point_on_navmesh) - elif event is InputEventMouseMotion: - if event.button_mask & (MOUSE_BUTTON_MASK_MIDDLE + MOUSE_BUTTON_MASK_RIGHT): - _cam_rotation -= event.screen_relative.x * 0.005 + elif input_event is InputEventMouseMotion: + if input_event.button_mask & (MOUSE_BUTTON_MASK_MIDDLE + MOUSE_BUTTON_MASK_RIGHT): + _cam_rotation -= input_event.screen_relative.x * 0.005 $CameraBase.set_rotation(Vector3.UP * _cam_rotation) diff --git a/3d/occlusion_culling_mesh_lod/camera.gd b/3d/occlusion_culling_mesh_lod/camera.gd index 062e48f9..7f83b8a8 100644 --- a/3d/occlusion_culling_mesh_lod/camera.gd +++ b/3d/occlusion_culling_mesh_lod/camera.gd @@ -1,25 +1,27 @@ extends Camera3D + const MOUSE_SENSITIVITY = 0.002 const MOVE_SPEED = 1.5 var rot := Vector3() var velocity := Vector3() + func _ready() -> void: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: # Mouse look (only if the mouse is captured). - if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + if input_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: # Horizontal mouse look. - rot.y -= event.screen_relative.x * MOUSE_SENSITIVITY + rot.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY # Vertical mouse look. - rot.x = clamp(rot.x - event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) + rot.x = clamp(rot.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) transform.basis = Basis.from_euler(rot) - if event.is_action_pressed(&"toggle_mouse_capture"): + if input_event.is_action_pressed(&"toggle_mouse_capture"): if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE else: diff --git a/3d/occlusion_culling_mesh_lod/door.gd b/3d/occlusion_culling_mesh_lod/door.gd index 587b9dad..6054f127 100644 --- a/3d/occlusion_culling_mesh_lod/door.gd +++ b/3d/occlusion_culling_mesh_lod/door.gd @@ -1,24 +1,25 @@ extends Node3D -var open := false +var open: bool = false -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_doors"): - if open: - # Close the door. - # The occluder will be re-enabled when the animation ends - # using `_on_animation_player_animation_finished()`. - $AnimationPlayer.play_backwards(&"open") - open = false - else: - # Open the door. - $AnimationPlayer.play(&"open") - open = true - # Disable the occluder as soon as the door starts opening. - # The occluder is not part of the pivot to prevent it from having its - # position changed every frame, which causes the occlusion culling BVH - # to be rebuilt each frame. This causes a CPU performance penalty. - $OccluderInstance3D.visible = false +func _input(input_event: InputEvent) -> void: + if not input_event.is_action_pressed(&"toggle_doors"): + return + if open: + # Close the door. + # The occluder will be re-enabled when the animation ends + # using `_on_animation_player_animation_finished()`. + $AnimationPlayer.play_backwards(&"open") + open = false + else: + # Open the door. + $AnimationPlayer.play(&"open") + open = true + # Disable the occluder as soon as the door starts opening. + # The occluder is not part of the pivot to prevent it from having its + # position changed every frame, which causes the occlusion culling BVH + # to be rebuilt each frame. This causes a CPU performance penalty. + $OccluderInstance3D.visible = false func _on_animation_player_animation_finished(_anim_name: StringName) -> void: diff --git a/3d/occlusion_culling_mesh_lod/node_3d.gd b/3d/occlusion_culling_mesh_lod/node_3d.gd index 7dac601c..ae042b67 100644 --- a/3d/occlusion_culling_mesh_lod/node_3d.gd +++ b/3d/occlusion_culling_mesh_lod/node_3d.gd @@ -1,16 +1,17 @@ extends Node3D -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_occlusion_culling"): + +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_occlusion_culling"): get_viewport().use_occlusion_culling = not get_viewport().use_occlusion_culling update_labels() - if event.is_action_pressed(&"toggle_mesh_lod"): + if input_event.is_action_pressed(&"toggle_mesh_lod"): get_viewport().mesh_lod_threshold = 1.0 if is_zero_approx(get_viewport().mesh_lod_threshold) else 0.0 update_labels() - if event.is_action_pressed(&"cycle_draw_mode"): + if input_event.is_action_pressed(&"cycle_draw_mode"): get_viewport().debug_draw = wrapi(get_viewport().debug_draw + 1, 0, 5) as Viewport.DebugDraw update_labels() - if event.is_action_pressed(&"toggle_vsync"): + if input_event.is_action_pressed(&"toggle_vsync"): if DisplayServer.window_get_vsync_mode() == DisplayServer.VSYNC_DISABLED: DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) else: diff --git a/3d/particles/tester.gd b/3d/particles/tester.gd index 59bdd160..dbe7d77a 100644 --- a/3d/particles/tester.gd +++ b/3d/particles/tester.gd @@ -20,22 +20,22 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clamp(zoom, 1.5, 4) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clamp(rot_x, deg_to_rad(-90), 0) diff --git a/3d/physical_light_camera_units/options.gd b/3d/physical_light_camera_units/options.gd index 2c1fabd1..0f5bc214 100644 --- a/3d/physical_light_camera_units/options.gd +++ b/3d/physical_light_camera_units/options.gd @@ -1,10 +1,12 @@ extends Control + @export var sun: DirectionalLight3D @export var lightbulb_1: OmniLight3D @export var lightbulb_2: OmniLight3D @export var world_environment: WorldEnvironment + ## Returns color from a given temperature in kelvins (6500K is nearly white). ## Valid range is [1000; 15000]. ## As explained in the Filament documentation: diff --git a/3d/physics_interpolation/player.gd b/3d/physics_interpolation/player.gd index 2645a51b..720a7e0c 100644 --- a/3d/physics_interpolation/player.gd +++ b/3d/physics_interpolation/player.gd @@ -45,10 +45,10 @@ func _ready() -> void: cycle_camera_type() -func _input(event: InputEvent) -> void: - if event is InputEventMouseMotion: - _yaw -= event.screen_relative.x * MOUSE_SENSITIVITY * 0.001 - _pitch += event.screen_relative.y * MOUSE_SENSITIVITY * 0.002 +func _input(input_event: InputEvent) -> void: + if input_event is InputEventMouseMotion: + _yaw -= input_event.screen_relative.x * MOUSE_SENSITIVITY * 0.001 + _pitch += input_event.screen_relative.y * MOUSE_SENSITIVITY * 0.002 _pitch = clamp(_pitch, -PI, PI) $Rig.rotation = Vector3(0, _yaw, 0) diff --git a/3d/physics_tests/project.godot b/3d/physics_tests/project.godot index a5656043..d461dc00 100644 --- a/3d/physics_tests/project.godot +++ b/3d/physics_tests/project.godot @@ -96,10 +96,10 @@ character_jump={ [physics] 3d/physics_engine="Jolt Physics" -jolt_physics_3d/limits/temporary_memory_buffer_size=128 +jolt_physics_3d/limits/temporary_memory_buffer_size=256 jolt_physics_3d/limits/max_bodies=262144 jolt_physics_3d/limits/max_body_pairs=262144 -jolt_physics_3d/limits/max_contact_constraints=262144 +jolt_physics_3d/limits/max_contact_constraints=524288 common/physics_interpolation=true [rendering] diff --git a/3d/physics_tests/test.gd b/3d/physics_tests/test.gd index 5756f7d1..40380b66 100644 --- a/3d/physics_tests/test.gd +++ b/3d/physics_tests/test.gd @@ -1,17 +1,19 @@ class_name Test extends Node + signal wait_done() -@export var _enable_debug_collision := true +@export var _enable_debug_collision: bool = true var _timer: Timer -var _timer_started := false +var _timer_started: bool = false -var _wait_physics_ticks_counter := 0 +var _wait_physics_ticks_counter: int = 0 var _drawn_nodes: Array[Node3D] = [] + func _enter_tree() -> void: if not _enable_debug_collision: get_tree().debug_collisions_hint = false diff --git a/3d/physics_tests/tests/functional/test_collision_pairs.gd b/3d/physics_tests/tests/functional/test_collision_pairs.gd index c2edc724..59716de0 100644 --- a/3d/physics_tests/tests/functional/test_collision_pairs.gd +++ b/3d/physics_tests/tests/functional/test_collision_pairs.gd @@ -1,5 +1,6 @@ extends Test + const OPTION_TYPE_BOX = "Collision type/Box (1)" const OPTION_TYPE_SPHERE = "Collision type/Sphere (2)" const OPTION_TYPE_CAPSULE = "Collision type/Capsule (3)" @@ -17,10 +18,11 @@ const OFFSET_RANGE = 3.0 @export var offset := Vector3.ZERO -var _update_collision := false -var _collision_test_index := 0 +var _update_collision: bool = false +var _collision_test_index: int = 0 var _collision_shapes: Array[Shape3D] = [] + func _ready() -> void: _initialize_collision_shapes() @@ -47,17 +49,17 @@ func _ready() -> void: _update_collision = true -func _input(event: InputEvent) -> void: - if event is InputEventKey and event.pressed: - if event.keycode == KEY_1: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey and input_event.pressed: + if input_event.keycode == KEY_1: _on_option_selected(OPTION_TYPE_BOX) - elif event.keycode == KEY_2: + elif input_event.keycode == KEY_2: _on_option_selected(OPTION_TYPE_SPHERE) - elif event.keycode == KEY_3: + elif input_event.keycode == KEY_3: _on_option_selected(OPTION_TYPE_CAPSULE) - elif event.keycode == KEY_4: + elif input_event.keycode == KEY_4: _on_option_selected(OPTION_TYPE_CYLINDER) - elif event.keycode == KEY_5: + elif input_event.keycode == KEY_5: _on_option_selected(OPTION_TYPE_CONVEX_POLYGON) diff --git a/3d/physics_tests/tests/functional/test_joints.gd b/3d/physics_tests/tests/functional/test_joints.gd index bdd94e7f..0f93ffb8 100644 --- a/3d/physics_tests/tests/functional/test_joints.gd +++ b/3d/physics_tests/tests/functional/test_joints.gd @@ -1,5 +1,6 @@ extends Test + const OPTION_JOINT_TYPE = "Joint Type/%s Joint (%d)" const OPTION_TEST_CASE_BODIES_COLLIDE = "Test case/Attached bodies collide" @@ -10,27 +11,28 @@ const OPTION_TEST_CASE_CHANGE_POSITIONS = "Test case/Set body positions after ad const BOX_SIZE = Vector3(1.0, 1.0, 1.0) -var _update_joint := false +var _update_joint: bool = false var _selected_joint: Joint3D -var _bodies_collide := false -var _world_attachement := false -var _dynamic_attachement := false -var _destroy_body := false -var _change_positions := false +var _bodies_collide: bool = false +var _world_attachement: bool = false +var _dynamic_attachement: bool = false +var _destroy_body: bool = false +var _change_positions: bool = false + +var _joint_types: Dictionary[String, Joint3D] = {} -var _joint_types := {} func _ready() -> void: var options: OptionMenu = $Options var joints: Node3D = $Joints for joint_index in joints.get_child_count(): - var joint_node := joints.get_child(joint_index) + var joint_node: Joint3D = joints.get_child(joint_index) joint_node.visible = false var joint_name := String(joint_node.name) - var joint_short := joint_name.substr(0, joint_name.length() - 5) - var option_name := OPTION_JOINT_TYPE % [joint_short, joint_index + 1] + var joint_short: String = joint_name.substr(0, joint_name.length() - 5) + var option_name: String = OPTION_JOINT_TYPE % [joint_short, joint_index + 1] options.add_menu_item(option_name) _joint_types[option_name] = joint_node @@ -54,9 +56,9 @@ func _process(_delta: float) -> void: $LabelJointType.text = "Joint Type: " + String(_selected_joint.name) -func _input(event: InputEvent) -> void: - if event is InputEventKey and event.pressed: - var joint_index: int = event.keycode - KEY_1 +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey and input_event.pressed: + var joint_index: int = input_event.keycode - KEY_1 if joint_index >= 0 and joint_index < _joint_types.size(): _selected_joint = _joint_types.values()[joint_index] _update_joint = true diff --git a/3d/physics_tests/tests/functional/test_moving_platform.gd b/3d/physics_tests/tests/functional/test_moving_platform.gd index 10e27700..a9e59a09 100644 --- a/3d/physics_tests/tests/functional/test_moving_platform.gd +++ b/3d/physics_tests/tests/functional/test_moving_platform.gd @@ -1,5 +1,6 @@ extends Test + const OPTION_BODY_TYPE = "Body Type/%s (%d)" const OPTION_SLOPE = "Physics options/Stop on slope (Character only)" @@ -14,21 +15,22 @@ const SHAPE_CYLINDER = "Collision shapes/Cylinder" const SHAPE_SPHERE = "Collision shapes/Sphere" const SHAPE_CONVEX = "Collision shapes/Convex" -var _slope := false -var _snap := false -var _friction := false -var _rough := false -var _animation_physics := false +var _slope: bool = false +var _snap: bool = false +var _friction: bool = false +var _rough: bool = false +var _animation_physics: bool = false var _body_scene := {} var _key_list := [] var _current_body_index := 0 -var _current_body_key := "" +var _current_body_key: String = "" var _current_body: PhysicsBody3D = null var _body_type := ["CharacterBody3D", "RigidBody"] var _shapes := {} -var _current_shape := "" +var _current_shape: String = "" + func _ready() -> void: var options: OptionMenu = $Options @@ -66,9 +68,9 @@ func _ready() -> void: spawn_body_index(_current_body_index) -func _input(event: InputEvent) -> void: - if event is InputEventKey and not event.pressed: - var _index: int = event.keycode - KEY_1 +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey and not input_event.pressed: + var _index: int = input_event.keycode - KEY_1 if _index >= 0 and _index < _key_list.size(): spawn_body_index(_index) diff --git a/3d/physics_tests/tests/functional/test_pyramid.gd b/3d/physics_tests/tests/functional/test_pyramid.gd index fcb8d267..c1bf4839 100644 --- a/3d/physics_tests/tests/functional/test_pyramid.gd +++ b/3d/physics_tests/tests/functional/test_pyramid.gd @@ -1,11 +1,13 @@ extends Test -@export_range(1, 100) var height := 10 -@export_range(1, 100) var width_max := 100 -@export_range(1, 100) var depth_max := 1 + +@export_range(1, 100) var height: int = 10 +@export_range(1, 100) var width_max: int = 100 +@export_range(1, 100) var depth_max: int = 1 @export var box_size := Vector3(1.0, 1.0, 1.0) @export var box_spacing := Vector3(0.0, 0.0, 0.0) + func _ready() -> void: _create_pyramid() diff --git a/3d/physics_tests/tests/functional/test_raycasting.gd b/3d/physics_tests/tests/functional/test_raycasting.gd index 78e8c0d6..22bc5af8 100644 --- a/3d/physics_tests/tests/functional/test_raycasting.gd +++ b/3d/physics_tests/tests/functional/test_raycasting.gd @@ -1,9 +1,10 @@ extends Test + const OPTION_TEST_CASE_HIT_FROM_INSIDE = "Test case/Hit from inside" -var _hit_from_inside := false -var _do_raycasts := false +var _hit_from_inside: bool = false +var _do_raycasts: bool = false @onready var _raycast_visuals := ImmediateMesh.new() @onready var _material := StandardMaterial3D.new() diff --git a/3d/physics_tests/tests/functional/test_rigidbody_ground_check.gd b/3d/physics_tests/tests/functional/test_rigidbody_ground_check.gd index 3bc2485d..eaa8fe97 100644 --- a/3d/physics_tests/tests/functional/test_rigidbody_ground_check.gd +++ b/3d/physics_tests/tests/functional/test_rigidbody_ground_check.gd @@ -1,5 +1,6 @@ extends Test + const OPTION_BIG = "Floor options/Big" const OPTION_SMALL = "Floor options/Small" @@ -8,13 +9,14 @@ const SHAPE_CONVEX = "Collision shapes/Convex" const SHAPE_BOX = "Collision shapes/Box" var _dynamic_shapes_scene: PackedScene -var _floor_shapes := {} -var _floor_size := "Small" +var _floor_shapes: Dictionary[String, PackedScene] = {} +var _floor_size: String = "Small" var _current_floor_name := SHAPE_CONCAVE var _current_bodies: Node3D var _current_floor: Node3D + func _ready() -> void: var options: OptionMenu = $Options _dynamic_shapes_scene = get_packed_scene($DynamicShapes/Bodies) diff --git a/3d/physics_tests/tests/functional/test_stack.gd b/3d/physics_tests/tests/functional/test_stack.gd index 9ca71802..f8ac3b12 100644 --- a/3d/physics_tests/tests/functional/test_stack.gd +++ b/3d/physics_tests/tests/functional/test_stack.gd @@ -1,11 +1,13 @@ extends Test -@export_range(1, 100) var height := 10 -@export_range(1, 100) var width := 1 -@export_range(1, 100) var depth := 1 + +@export_range(1, 100) var height: int = 10 +@export_range(1, 100) var width: int = 1 +@export_range(1, 100) var depth: int = 1 @export var box_size := Vector3(1.0, 1.0, 1.0) @export var box_spacing := Vector3(0.0, 0.0, 0.0) + func _ready() -> void: _create_stack() diff --git a/3d/physics_tests/tests/performance/test_perf_broadphase.gd b/3d/physics_tests/tests/performance/test_perf_broadphase.gd index 8a95865b..f63d63b4 100644 --- a/3d/physics_tests/tests/performance/test_perf_broadphase.gd +++ b/3d/physics_tests/tests/performance/test_perf_broadphase.gd @@ -1,17 +1,19 @@ extends Test + const BOX_SIZE = Vector3(0.8, 0.8, 0.8) const BOX_SPACE = Vector3(1.0, 1.0, 1.0) -@export_range(1, 1000) var row_size := 20 -@export_range(1, 1000) var column_size := 20 -@export_range(1, 1000) var depth_size := 20 +@export_range(1, 1000) var row_size: int = 20 +@export_range(1, 1000) var column_size: int = 20 +@export_range(1, 1000) var depth_size: int = 20 var _objects: Array[Node3D] = [] -var _log_physics := false -var _log_physics_time := 0 -var _log_physics_time_start := 0 +var _log_physics: bool = false +var _log_physics_time_usec: int = 0 +var _log_physics_time_usec_start: int = 0 + func _ready() -> void: await start_timer(1.0).timeout @@ -75,16 +77,16 @@ func _physics_process(delta: float) -> void: if _log_physics: var time := Time.get_ticks_usec() - var time_delta := time - _log_physics_time - var time_total := time - _log_physics_time_start - _log_physics_time = time + var time_delta := time - _log_physics_time_usec + var time_total := time - _log_physics_time_usec_start + _log_physics_time_usec = time Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total]) func _log_physics_start() -> void: _log_physics = true - _log_physics_time_start = Time.get_ticks_usec() - _log_physics_time = _log_physics_time_start + _log_physics_time_usec_start = Time.get_ticks_usec() + _log_physics_time_usec = _log_physics_time_usec_start func _log_physics_stop() -> void: diff --git a/3d/physics_tests/tests/performance/test_perf_contacts.gd b/3d/physics_tests/tests/performance/test_perf_contacts.gd index 6ec219e8..18021e1f 100644 --- a/3d/physics_tests/tests/performance/test_perf_contacts.gd +++ b/3d/physics_tests/tests/performance/test_perf_contacts.gd @@ -8,14 +8,14 @@ const OPTION_TYPE_CYLINDER = "Shape type/Cylinder" const OPTION_TYPE_CONVEX = "Shape type/Convex" @export var spawns: Array[NodePath] = [] -@export var spawn_count := 100 +@export var spawn_count: int = 100 @export var spawn_randomize := Vector3.ZERO var _object_templates: Array[Node3D] = [] -var _log_physics := false -var _log_physics_time := 0 -var _log_physics_time_start := 0 +var _log_physics: bool = false +var _log_physics_time_usec: int = 0 +var _log_physics_time_usec_start: int = 0 func _ready() -> void: await start_timer(0.5).timeout @@ -48,16 +48,16 @@ func _physics_process(delta: float) -> void: if _log_physics: var time := Time.get_ticks_usec() - var time_delta := time - _log_physics_time - var time_total := time - _log_physics_time_start - _log_physics_time = time + var time_delta := time - _log_physics_time_usec + var time_total := time - _log_physics_time_usec_start + _log_physics_time_usec = time Log.print_log(" Physics Tick: %.3f ms (total = %.3f ms)" % [0.001 * time_delta, 0.001 * time_total]) func _log_physics_start() -> void: _log_physics = true - _log_physics_time_start = Time.get_ticks_usec() - _log_physics_time = _log_physics_time_start + _log_physics_time_usec_start = Time.get_ticks_usec() + _log_physics_time_usec = _log_physics_time_usec_start func _log_physics_stop() -> void: diff --git a/3d/physics_tests/tests_menu.gd b/3d/physics_tests/tests_menu.gd index e4bffee4..ea6c17ce 100644 --- a/3d/physics_tests/tests_menu.gd +++ b/3d/physics_tests/tests_menu.gd @@ -2,8 +2,8 @@ extends OptionMenu class TestData: - var id := "" - var scene_path := "" + var id: String = "" + var scene_path: String = "" var _test_list: Array[TestData] = [] diff --git a/3d/physics_tests/utils/camera_orbit.gd b/3d/physics_tests/utils/camera_orbit.gd index 3c81840d..243dbad6 100644 --- a/3d/physics_tests/utils/camera_orbit.gd +++ b/3d/physics_tests/utils/camera_orbit.gd @@ -1,26 +1,28 @@ extends Camera3D + const ROTATION_COEFF = 0.02 -var _rotation_enabled := false +var _rotation_enabled: bool = false var _rotation_pivot: Node3D + func _ready() -> void: _initialize_pivot.call_deferred() -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_RIGHT: - _rotation_enabled = event.pressed +func _unhandled_input(input_event: InputEvent) -> void: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_RIGHT: + _rotation_enabled = input_event.pressed return if not _rotation_enabled: return - if event is InputEventMouseMotion: - var rotation_delta: float = event.screen_relative.x + if input_event is InputEventMouseMotion: + var rotation_delta: float = input_event.screen_relative.x _rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF) diff --git a/3d/physics_tests/utils/characterbody_physics.gd b/3d/physics_tests/utils/characterbody_physics.gd index 02a48c05..c0e75715 100644 --- a/3d/physics_tests/utils/characterbody_physics.gd +++ b/3d/physics_tests/utils/characterbody_physics.gd @@ -1,9 +1,11 @@ extends CharacterBody3D -@export var _stop_on_slopes := false -@export var use_snap := false -var _gravity := 20.0 +@export var _stop_on_slopes: bool = false +@export var use_snap: bool = false + +var _gravity: float = 20.0 + func _physics_process(delta: float) -> void: if is_on_floor(): diff --git a/3d/physics_tests/utils/container_log.gd b/3d/physics_tests/utils/container_log.gd index 0e43fc7e..21a01bf1 100644 --- a/3d/physics_tests/utils/container_log.gd +++ b/3d/physics_tests/utils/container_log.gd @@ -1,5 +1,6 @@ extends Control + const MAX_ENTRIES = 100 var _entry_template: Label diff --git a/3d/physics_tests/utils/control3d.gd b/3d/physics_tests/utils/control3d.gd index dffe1713..8b40bde9 100644 --- a/3d/physics_tests/utils/control3d.gd +++ b/3d/physics_tests/utils/control3d.gd @@ -1,10 +1,12 @@ extends Control + @export var world_offset := Vector3.ZERO var _pos_offset: Vector2 var _attachment: Node3D + func _ready() -> void: _pos_offset = position _attachment = get_parent() diff --git a/3d/physics_tests/utils/label_engine.gd b/3d/physics_tests/utils/label_engine.gd index 63346ffc..b8a6051a 100644 --- a/3d/physics_tests/utils/label_engine.gd +++ b/3d/physics_tests/utils/label_engine.gd @@ -1,7 +1,8 @@ extends Label + func _ready() -> void: - var engine_name := "" + var engine_name: String = "" match System.get_physics_engine(): System.PhysicsEngine.GODOT_PHYSICS: engine_name = "GodotPhysics 3D" diff --git a/3d/physics_tests/utils/label_fps.gd b/3d/physics_tests/utils/label_fps.gd index 8165e7f2..1360f27a 100644 --- a/3d/physics_tests/utils/label_fps.gd +++ b/3d/physics_tests/utils/label_fps.gd @@ -1,4 +1,5 @@ extends Label + func _process(_delta: float) -> void: text = "%d FPS (%.2f mspf)" % [Engine.get_frames_per_second(), 1000.0 / Engine.get_frames_per_second()] diff --git a/3d/physics_tests/utils/label_pause.gd b/3d/physics_tests/utils/label_pause.gd index 0171cdaa..02d5ab0a 100644 --- a/3d/physics_tests/utils/label_pause.gd +++ b/3d/physics_tests/utils/label_pause.gd @@ -1,4 +1,5 @@ extends Label + func _process(_delta: float) -> void: visible = get_tree().paused diff --git a/3d/physics_tests/utils/label_test.gd b/3d/physics_tests/utils/label_test.gd index 91bfe870..658643ba 100644 --- a/3d/physics_tests/utils/label_test.gd +++ b/3d/physics_tests/utils/label_test.gd @@ -1,6 +1,7 @@ extends Label -var test_name := "": + +var test_name: String = "": set(value): if (test_name != value): return diff --git a/3d/physics_tests/utils/label_version.gd b/3d/physics_tests/utils/label_version.gd index 944e135a..7cc1566c 100644 --- a/3d/physics_tests/utils/label_version.gd +++ b/3d/physics_tests/utils/label_version.gd @@ -1,4 +1,5 @@ extends Label + func _process(_delta: float) -> void: set_text("Godot Version: %s" % Engine.get_version_info().string) diff --git a/3d/physics_tests/utils/option_menu.gd b/3d/physics_tests/utils/option_menu.gd index 5933cb93..9edd27c1 100644 --- a/3d/physics_tests/utils/option_menu.gd +++ b/3d/physics_tests/utils/option_menu.gd @@ -1,15 +1,17 @@ class_name OptionMenu extends MenuButton + signal option_selected(item_path: String) signal option_changed(item_path: String, checked: bool) + func add_menu_item(item_path: String, checkbox: bool = false, checked: bool = false) -> void: var path_elements := item_path.split("/", false) var path_element_count := path_elements.size() assert(path_element_count > 0) - var path := "" + var path: String = "" var popup := get_popup() for element_index in path_element_count - 1: var popup_label := path_elements[element_index] diff --git a/3d/physics_tests/utils/rigidbody_ground_check.gd b/3d/physics_tests/utils/rigidbody_ground_check.gd index f8ea8934..b118a1c9 100644 --- a/3d/physics_tests/utils/rigidbody_ground_check.gd +++ b/3d/physics_tests/utils/rigidbody_ground_check.gd @@ -1,15 +1,17 @@ extends RigidBody3D -var _dir := 1.0 -var _distance := 10.0 -var _walk_spd := 100.0 -var _acceleration := 22.0 -var _is_on_floor := false + +var _dir: float = 1.0 # -1.0 or 1.0 +var _distance: float = 10.0 +var _walk_spd: float = 100.0 +var _acceleration: float = 22.0 +var _is_on_floor: bool = false @onready var _forward := -transform.basis.z @onready var _collision_shape := $CollisionShape @onready var _material: StandardMaterial3D = $CollisionShape/MeshInstance3D.get_active_material(0) + func _ready() -> void: if not _material: _material = StandardMaterial3D.new() @@ -24,20 +26,20 @@ func _process(_delta: float) -> void: func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: - var delta := state.step - var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP) + var delta: float = state.step + var velocity := (_forward * _dir * _walk_spd * delta) + (state.linear_velocity * Vector3.UP) state.linear_velocity = state.linear_velocity.move_toward(velocity, _acceleration * delta) if state.transform.origin.z < -_distance: - _dir = -1 + _dir = -1.0 if state.transform.origin.z > _distance: - _dir = 1 + _dir = 1.0 ground_check() func ground_check() -> void: - var space_state := get_world_3d().direct_space_state + var space_state: PhysicsDirectSpaceState3D = get_world_3d().direct_space_state var shape := PhysicsShapeQueryParameters3D.new() shape.transform = _collision_shape.global_transform shape.shape_rid = _collision_shape.shape.get_rid() diff --git a/3d/physics_tests/utils/rigidbody_pick.gd b/3d/physics_tests/utils/rigidbody_pick.gd index 57559461..77c3ed09 100644 --- a/3d/physics_tests/utils/rigidbody_pick.gd +++ b/3d/physics_tests/utils/rigidbody_pick.gd @@ -1,30 +1,32 @@ extends RigidBody3D -const MOUSE_DELTA_COEFFICIENT = 0.01 -const CAMERA_DISTANCE_COEFFICIENT = 0.2 -var _picked := false +const MOUSE_DELTA_COEFFICIENT: float = 0.01 +const CAMERA_DISTANCE_COEFFICIENT: float = 0.2 + +var _picked: bool = false var _last_mouse_pos := Vector2.ZERO var _mouse_pos := Vector2.ZERO + func _ready() -> void: input_ray_pickable = true -func _input(event: InputEvent) -> void: - if event is InputEventMouseButton: - if not event.pressed and event.button_index == MOUSE_BUTTON_LEFT: +func _input(any_input_event: InputEvent) -> void: + if any_input_event is InputEventMouseButton: + if not any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT: _picked = false - if event is InputEventMouseMotion: - _mouse_pos = event.position + if any_input_event is InputEventMouseMotion: + _mouse_pos = any_input_event.position -func _input_event(_camera: Camera3D, event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void: - if event is InputEventMouseButton: - if event.pressed and event.button_index == MOUSE_BUTTON_LEFT: +func _input_event(_camera: Camera3D, any_input_event: InputEvent, _position: Vector3, _normal: Vector3, _shape_idx: int) -> void: + if any_input_event is InputEventMouseButton: + if any_input_event.pressed and any_input_event.button_index == MOUSE_BUTTON_LEFT: _picked = true - _mouse_pos = event.position + _mouse_pos = any_input_event.position _last_mouse_pos = _mouse_pos diff --git a/3d/physics_tests/utils/scroll_log.gd b/3d/physics_tests/utils/scroll_log.gd index 497738f0..83a8bfa5 100644 --- a/3d/physics_tests/utils/scroll_log.gd +++ b/3d/physics_tests/utils/scroll_log.gd @@ -1,6 +1,8 @@ extends ScrollContainer -@export var auto_scroll := false + +@export var auto_scroll: bool = false + func _process(_delta: float) -> void: if auto_scroll: diff --git a/3d/physics_tests/utils/system.gd b/3d/physics_tests/utils/system.gd index b5246233..314f640f 100644 --- a/3d/physics_tests/utils/system.gd +++ b/3d/physics_tests/utils/system.gd @@ -1,5 +1,6 @@ extends Node + enum PhysicsEngine { GODOT_PHYSICS, JOLT_PHYSICS, @@ -8,6 +9,7 @@ enum PhysicsEngine { var _engine := PhysicsEngine.OTHER + func _enter_tree() -> void: process_mode = Node.PROCESS_MODE_ALWAYS diff --git a/3d/physics_tests/utils/system_log.gd b/3d/physics_tests/utils/system_log.gd index 749e9089..55555e5c 100644 --- a/3d/physics_tests/utils/system_log.gd +++ b/3d/physics_tests/utils/system_log.gd @@ -1,5 +1,6 @@ extends Node + enum LogType { LOG, ERROR, @@ -7,6 +8,7 @@ enum LogType { signal entry_logged(message: String, type: LogType) + func print_log(message: String) -> void: print(message) entry_logged.emit(message, LogType.LOG) diff --git a/3d/platformer/coin/coin.gd b/3d/platformer/coin/coin.gd index 3dbce1bd..469a62f0 100644 --- a/3d/platformer/coin/coin.gd +++ b/3d/platformer/coin/coin.gd @@ -1,6 +1,8 @@ extends Area3D -var taken := false + +var taken: bool = false + func _on_coin_body_enter(body: Node) -> void: if not taken and body is Player: diff --git a/3d/platformer/enemy/enemy.gd b/3d/platformer/enemy/enemy.gd index bc5e4e91..7788dd3f 100644 --- a/3d/platformer/enemy/enemy.gd +++ b/3d/platformer/enemy/enemy.gd @@ -1,13 +1,14 @@ extends RigidBody3D -const ACCEL = 5.0 -const DEACCEL = 20.0 -const MAX_SPEED = 2.0 -const ROT_SPEED = 1.0 -var prev_advance := false -var dying := false -var rot_dir := 4 +const ACCEL: float = 5.0 +const DEACCEL: float = 20.0 +const MAX_SPEED: float = 2.0 +const ROT_SPEED: float = 1.0 + +var prev_advance: bool = false +var dying: bool = false +var rot_dir: float = 4.0 @onready var gravity := Vector3( ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector") @@ -17,6 +18,7 @@ var rot_dir := 4 @onready var _ray_floor := $Enemy/Skeleton/RayFloor as RayCast3D @onready var _ray_wall := $Enemy/Skeleton/RayWall as RayCast3D + func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: var delta := state.get_step() var lin_velocity := state.get_linear_velocity() @@ -51,10 +53,10 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: $SoundHit.play() return - var advance := _ray_floor.is_colliding() and not _ray_wall.is_colliding() + var advance: bool = _ray_floor.is_colliding() and not _ray_wall.is_colliding() - var dir := ($Enemy/Skeleton as Node3D).get_transform().basis[2].normalized() - var deaccel_dir := dir + var dir: Vector3 = ($Enemy/Skeleton as Node3D).get_transform().basis.z.normalized() + var deaccel_dir: Vector3 = dir if advance: if dir.dot(lin_velocity) < MAX_SPEED: @@ -67,7 +69,7 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: dir = Basis(up, rot_dir * ROT_SPEED * (delta)) * dir $Enemy/Skeleton.set_transform(Transform3D().looking_at(-dir, up)) - var dspeed := deaccel_dir.dot(lin_velocity) + var dspeed: float = deaccel_dir.dot(lin_velocity) dspeed -= DEACCEL * delta if dspeed < 0: dspeed = 0 diff --git a/3d/platformer/player/bullet/bullet.gd b/3d/platformer/player/bullet/bullet.gd index ff794395..00333b8f 100644 --- a/3d/platformer/player/bullet/bullet.gd +++ b/3d/platformer/player/bullet/bullet.gd @@ -3,4 +3,4 @@ extends RigidBody3D ## If `true`, the bullet can hit enemies. This is set to `false` when the bullet ## hits an enemy so it can't hit an enemy multiple times while the bullet is fading out. -var enabled := true +var enabled: bool = true diff --git a/3d/platformer/player/follow_camera.gd b/3d/platformer/player/follow_camera.gd index 7d7734e4..d8c0dbad 100644 --- a/3d/platformer/player/follow_camera.gd +++ b/3d/platformer/player/follow_camera.gd @@ -1,15 +1,17 @@ extends Camera3D + const MAX_HEIGHT = 2.0 const MIN_HEIGHT = 0.0 var collision_exception: Array[RID] = [] -@export var min_distance := 0.5 -@export var max_distance := 3.5 -@export var angle_v_adjust := 0.0 -@export var autoturn_ray_aperture := 25.0 -@export var autoturn_speed := 50.0 +@export var min_distance: float = 0.5 +@export var max_distance: float = 3.5 +@export var angle_v_adjust: float = 0.0 +@export var autoturn_ray_aperture: float = 25.0 +@export var autoturn_speed: float = 50.0 + func _ready() -> void: # Find collision exceptions for ray. diff --git a/3d/platformer/player/player.gd b/3d/platformer/player/player.gd index 55bfacad..a2367dcf 100644 --- a/3d/platformer/player/player.gd +++ b/3d/platformer/player/player.gd @@ -6,26 +6,26 @@ enum _Anim { AIR, } -const SHOOT_TIME = 1.5 -const SHOOT_SCALE = 2.0 -const CHAR_SCALE = Vector3(0.3, 0.3, 0.3) -const MAX_SPEED = 6.0 -const TURN_SPEED = 40.0 -const JUMP_VELOCITY = 12.5 -const BULLET_SPEED = 20.0 -const AIR_IDLE_DEACCEL = false -const ACCEL = 14.0 -const DEACCEL = 14.0 -const AIR_ACCEL_FACTOR = 0.5 -const SHARP_TURN_THRESHOLD = deg_to_rad(140.0) +const SHOOT_TIME: float = 1.5 +const SHOOT_SCALE: float = 2.0 +const CHAR_SCALE := Vector3(0.3, 0.3, 0.3) +const MAX_SPEED: float = 6.0 +const TURN_SPEED: float = 40.0 +const JUMP_VELOCITY: float = 12.5 +const BULLET_SPEED: float = 20.0 +const AIR_IDLE_DEACCEL: bool = false +const ACCEL: float = 14.0 +const DEACCEL: float = 14.0 +const AIR_ACCEL_FACTOR: float = 0.5 +const SHARP_TURN_THRESHOLD: float = deg_to_rad(140.0) var movement_dir := Vector3() -var jumping := false -var prev_shoot := false -var shoot_blend := 0.0 +var jumping: bool = false +var prev_shoot: bool = false +var shoot_blend: float = 0.0 # Number of coins collected. -var coins := 0 +var coins: int = 0 @onready var initial_position := position @onready var gravity: Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity") * \ diff --git a/3d/platformer/project.godot b/3d/platformer/project.godot index 12afb934..45de097f 100644 --- a/3d/platformer/project.godot +++ b/3d/platformer/project.godot @@ -154,6 +154,7 @@ common/physics_interpolation=true renderer/rendering_method="mobile" textures/vram_compression/import_s3tc_bptc=true +textures/vram_compression/import_etc2_astc=true lights_and_shadows/directional_shadow/size=8192 lights_and_shadows/directional_shadow/soft_shadow_filter_quality=3 textures/default_filters/anisotropic_filtering_level=4 diff --git a/3d/platformer/touch_screen_ui.gd b/3d/platformer/touch_screen_ui.gd index ba7b45dd..6a1468a1 100644 --- a/3d/platformer/touch_screen_ui.gd +++ b/3d/platformer/touch_screen_ui.gd @@ -1,5 +1,6 @@ extends CanvasLayer + func _ready() -> void: hide() if DisplayServer.is_touchscreen_available(): diff --git a/3d/platformer/touch_screen_ui/virtual_joystick/virtual_joystick.gd b/3d/platformer/touch_screen_ui/virtual_joystick/virtual_joystick.gd index 16dfeb00..93e739c3 100644 --- a/3d/platformer/touch_screen_ui/virtual_joystick/virtual_joystick.gd +++ b/3d/platformer/touch_screen_ui/virtual_joystick/virtual_joystick.gd @@ -1,5 +1,4 @@ class_name VirtualJoystick - extends Control ## A simple virtual joystick for touchscreens, with useful options. @@ -11,10 +10,10 @@ extends Control @export var pressed_color := Color.GRAY ## If the input is inside this range, the output is zero. -@export_range(0, 200, 1) var deadzone_size : float = 10 +@export_range(0, 200, 1) var deadzone_size: float = 10.0 ## The max distance the tip can reach. -@export_range(0, 500, 1) var clampzone_size : float = 75 +@export_range(0, 500, 1) var clampzone_size: float = 75.0 enum Joystick_mode { FIXED, ## The joystick doesn't move. @@ -35,30 +34,30 @@ enum Visibility_mode { @export var visibility_mode := Visibility_mode.ALWAYS ## If true, the joystick uses Input Actions. (Project -> Project Settings -> Input Map) -@export var use_input_actions := true +@export var use_input_actions: bool = true -@export var action_left := "move_left" -@export var action_right := "move_right" -@export var action_up := "move_forward" -@export var action_down := "move_back" +@export var action_left: String = "move_left" +@export var action_right: String = "move_right" +@export var action_up: String = "move_forward" +@export var action_down: String = "move_back" # PUBLIC VARIABLES ## If the joystick is receiving inputs. -var is_pressed := false +var is_pressed: bool = false # The joystick output. var output := Vector2.ZERO # PRIVATE VARIABLES -var _touch_index : int = -1 +var _touch_index: int = -1 -@onready var _base := $Base -@onready var _tip := $Base/Tip +@onready var _base: TextureRect = $Base +@onready var _tip: TextureRect = $Base/Tip -@onready var _base_default_position : Vector2 = _base.position -@onready var _tip_default_position : Vector2 = _tip.position +@onready var _base_default_position: Vector2 = _base.position +@onready var _tip_default_position: Vector2 = _tip.position @onready var _default_color : Color = _tip.modulate @@ -72,27 +71,28 @@ func _ready() -> void: hide() -func _input(event: InputEvent) -> void: - if event is InputEventScreenTouch: - if event.pressed: - if _is_point_inside_joystick_area(event.position) and _touch_index == -1: - if joystick_mode == Joystick_mode.DYNAMIC or joystick_mode == Joystick_mode.FOLLOWING or (joystick_mode == Joystick_mode.FIXED and _is_point_inside_base(event.position)): +func _input(input_event: InputEvent) -> void: + if input_event is InputEventScreenTouch: + if input_event.pressed: + if _is_point_inside_joystick_area(input_event.position) and _touch_index == -1: + if joystick_mode == Joystick_mode.DYNAMIC or joystick_mode == Joystick_mode.FOLLOWING or ( + joystick_mode == Joystick_mode.FIXED and _is_point_inside_base(input_event.position)): if joystick_mode == Joystick_mode.DYNAMIC or joystick_mode == Joystick_mode.FOLLOWING: - _move_base(event.position) + _move_base(input_event.position) if visibility_mode == Visibility_mode.WHEN_TOUCHED: show() - _touch_index = event.index + _touch_index = input_event.index _tip.modulate = pressed_color - _update_joystick(event.position) + _update_joystick(input_event.position) get_viewport().set_input_as_handled() - elif event.index == _touch_index: + elif input_event.index == _touch_index: _reset() if visibility_mode == Visibility_mode.WHEN_TOUCHED: hide() get_viewport().set_input_as_handled() - elif event is InputEventScreenDrag: - if event.index == _touch_index: - _update_joystick(event.position) + elif input_event is InputEventScreenDrag: + if input_event.index == _touch_index: + _update_joystick(input_event.position) get_viewport().set_input_as_handled() @@ -111,20 +111,20 @@ func _is_point_inside_joystick_area(point: Vector2) -> bool: func _get_base_radius() -> Vector2: - return _base.size * _base.get_global_transform_with_canvas().get_scale() / 2 + return _base.size * _base.get_global_transform_with_canvas().get_scale() / 2.0 func _is_point_inside_base(point: Vector2) -> bool: - var base_radius: = _get_base_radius() - var center : Vector2 = _base.global_position + base_radius - var vector : Vector2 = point - center + var base_radius: Vector2 = _get_base_radius() + var center: Vector2 = _base.global_position + base_radius + var vector: Vector2 = point - center return vector.length_squared() <= base_radius.x * base_radius.x func _update_joystick(touch_position: Vector2) -> void: - var base_radius: = _get_base_radius() - var center : Vector2 = _base.global_position + base_radius - var vector : Vector2 = touch_position - center + var base_radius: Vector2 = _get_base_radius() + var center: Vector2 = _base.global_position + base_radius + var vector: Vector2 = touch_position - center vector = vector.limit_length(clampzone_size) if joystick_mode == Joystick_mode.FOLLOWING and touch_position.distance_to(center) > clampzone_size: @@ -141,23 +141,23 @@ func _update_joystick(touch_position: Vector2) -> void: if use_input_actions: # Release actions. - if output.x >= 0 and Input.is_action_pressed(action_left): + if output.x >= 0.0 and Input.is_action_pressed(action_left): Input.action_release(action_left) - if output.x <= 0 and Input.is_action_pressed(action_right): + if output.x <= 0.0 and Input.is_action_pressed(action_right): Input.action_release(action_right) - if output.y >= 0 and Input.is_action_pressed(action_up): + if output.y >= 0.0 and Input.is_action_pressed(action_up): Input.action_release(action_up) - if output.y <= 0 and Input.is_action_pressed(action_down): + if output.y <= 0.0 and Input.is_action_pressed(action_down): Input.action_release(action_down) # Press actions. - if output.x < 0: + if output.x < 0.0: Input.action_press(action_left, -output.x) - if output.x > 0: + if output.x > 0.0: Input.action_press(action_right, output.x) - if output.y < 0: + if output.y < 0.0: Input.action_press(action_up, -output.y) - if output.y > 0: + if output.y > 0.0: Input.action_press(action_down, output.y) diff --git a/3d/procedural_materials/loading.gd b/3d/procedural_materials/loading.gd index 3884c42b..73a5a406 100644 --- a/3d/procedural_materials/loading.gd +++ b/3d/procedural_materials/loading.gd @@ -1,6 +1,7 @@ # This acts as a staging scene shown until the main scene is fully loaded. extends Control + func _ready() -> void: for i in 2: # Wait 2 frames before starting to change to the main scene, diff --git a/3d/procedural_materials/scripts/grid.gd b/3d/procedural_materials/scripts/grid.gd index 64a60088..5ada5188 100644 --- a/3d/procedural_materials/scripts/grid.gd +++ b/3d/procedural_materials/scripts/grid.gd @@ -3,10 +3,12 @@ # which would make it much larger. extends MeshInstance3D + const TEXTURE_SIZE = Vector2i(512, 512) const GRID_SIZE = 32 const GRID_THICKNESS = 4 + func _ready() -> void: var image := Image.create(TEXTURE_SIZE.x, TEXTURE_SIZE.y, false, Image.FORMAT_RGB8) # Use 1-dimensional loop as it's faster than a nested loop. diff --git a/3d/procedural_materials/tester.gd b/3d/procedural_materials/tester.gd index 04974797..c8ebe0e2 100644 --- a/3d/procedural_materials/tester.gd +++ b/3d/procedural_materials/tester.gd @@ -1,20 +1,22 @@ extends WorldEnvironment + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE -var tester_index := 0 -var rot_x := deg_to_rad(-22.5) # This must be kept in sync with RotationX. -var rot_y := deg_to_rad(90) # This must be kept in sync with CameraHolder. -var zoom := 2.5 -var is_compatibility := false +var tester_index: int = 0 +var rot_x: float = deg_to_rad(-22.5) # This must be kept in sync with RotationX. +var rot_y: float = deg_to_rad(90) # This must be kept in sync with CameraHolder. +var zoom: float = 2.5 +var is_compatibility: bool = false @onready var testers: Node3D = $Testers @onready var camera_holder: Node3D = $CameraHolder # Has a position and rotates on Y. @onready var rotation_x: Node3D = $CameraHolder/RotationX @onready var camera: Camera3D = $CameraHolder/RotationX/Camera3D + func _ready() -> void: if RenderingServer.get_current_rendering_method() == "gl_compatibility": # Use PCF13 shadow filtering to improve quality (Medium maps to PCF5 instead). @@ -32,22 +34,22 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clampf(zoom, 1.5, 4) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clampf(rot_x, deg_to_rad(-90), 0) diff --git a/3d/ragdoll_physics/ragdoll_physics.gd b/3d/ragdoll_physics/ragdoll_physics.gd index 0858d0e0..2ad86377 100644 --- a/3d/ragdoll_physics/ragdoll_physics.gd +++ b/3d/ragdoll_physics/ragdoll_physics.gd @@ -1,5 +1,6 @@ extends Node3D + const MOUSE_SENSITIVITY = 0.01 const INITIAL_VELOCITY_STRENGTH = 0.5 @@ -13,11 +14,11 @@ const DIRECTIONAL_SHADOW_MAX_DISTANCE_MARGIN = 9.0 @onready var directional_light: DirectionalLight3D = $DirectionalLight3D -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"reset_simulation"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"reset_simulation"): get_tree().reload_current_scene() - if event.is_action_pressed(&"place_ragdoll"): + if input_event.is_action_pressed(&"place_ragdoll"): var origin := camera.global_position var target := camera.project_position(get_viewport().get_mouse_position(), 100) @@ -33,27 +34,27 @@ func _unhandled_input(event: InputEvent) -> void: ragdoll.initial_velocity = Vector3.FORWARD.rotated(Vector3.UP, randf_range(0, TAU)) * INITIAL_VELOCITY_STRENGTH add_child(ragdoll) - if event.is_action_pressed(&"slow_motion"): + if input_event.is_action_pressed(&"slow_motion"): Engine.time_scale = 0.25 # Don't set pitch scale too low as it sounds strange. # `0.5` is the square root of `0.25` and gives a good result here. AudioServer.playback_speed_scale = 0.5 - if event.is_action_released(&"slow_motion"): + if input_event.is_action_released(&"slow_motion"): Engine.time_scale = 1.0 AudioServer.playback_speed_scale = 1.0 # Pan the camera with right mouse button. - if event is InputEventMouseMotion: - var mouse_motion := event as InputEventMouseMotion + if input_event is InputEventMouseMotion: + var mouse_motion := input_event as InputEventMouseMotion if mouse_motion.button_mask & MOUSE_BUTTON_RIGHT: - camera_pivot.global_rotation.x = clampf(camera_pivot.global_rotation.x - event.screen_relative.y * MOUSE_SENSITIVITY, -TAU * 0.249, TAU * 0.021) - camera_pivot.global_rotation.y -= event.screen_relative.x * MOUSE_SENSITIVITY + camera_pivot.global_rotation.x = clampf(camera_pivot.global_rotation.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -TAU * 0.249, TAU * 0.021) + camera_pivot.global_rotation.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY # Zoom with mouse wheel. # This also adjusts shadow maximum distance to always cover the scene regardless of zoom level. - if event is InputEventMouseButton: - var mouse_button := event as InputEventMouseButton + if input_event is InputEventMouseButton: + var mouse_button := input_event as InputEventMouseButton if mouse_button.button_index == MOUSE_BUTTON_WHEEL_UP: camera.translate_object_local(Vector3.FORWARD * 0.5) directional_light.directional_shadow_max_distance = camera.position.length() + DIRECTIONAL_SHADOW_MAX_DISTANCE_MARGIN diff --git a/3d/sky_shaders/main.gd b/3d/sky_shaders/main.gd index 8b70e79a..b61c0099 100644 --- a/3d/sky_shaders/main.gd +++ b/3d/sky_shaders/main.gd @@ -1,5 +1,6 @@ extends Node3D + const MOUSE_SENSITIVITY = 0.001 # The camera field of view to smoothly interpolate to. @@ -19,30 +20,30 @@ func _process(delta: float) -> void: -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_gui"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_gui"): $Panel.visible = not $Panel.visible $Help.visible = not $Help.visible - if event.is_action_pressed(&"toggle_spheres"): + if input_event.is_action_pressed(&"toggle_spheres"): $Spheres.visible = not $Spheres.visible - if event.is_action_pressed(&"toggle_mouse_capture"): + if input_event.is_action_pressed(&"toggle_mouse_capture"): if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE else: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED - if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion: + if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED and input_event is InputEventMouseMotion: # Mouselook. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative $YawCamera.rotation.x = clampf($YawCamera.rotation.x - relative_motion.y * MOUSE_SENSITIVITY, -TAU * 0.25, TAU * 0.25) $YawCamera.rotation.y -= relative_motion.x * MOUSE_SENSITIVITY # Mouse wheel currently doesn't work in input actions. Hardcode mouse wheel as a workaround. - if event.is_action_pressed(&"increase_camera_fov") or Input.is_mouse_button_pressed(MOUSE_BUTTON_WHEEL_DOWN): + if input_event.is_action_pressed(&"increase_camera_fov") or Input.is_mouse_button_pressed(MOUSE_BUTTON_WHEEL_DOWN): desired_fov = clampf(desired_fov + 5.0, 20.0, 120.0) - if event.is_action_pressed(&"decrease_camera_fov") or Input.is_mouse_button_pressed(MOUSE_BUTTON_WHEEL_UP): + if input_event.is_action_pressed(&"decrease_camera_fov") or Input.is_mouse_button_pressed(MOUSE_BUTTON_WHEEL_UP): desired_fov = clampf(desired_fov - 5.0, 20.0, 120.0) diff --git a/3d/soft_body_physics/tester.gd b/3d/soft_body_physics/tester.gd index 5dd21dd6..4f209e67 100644 --- a/3d/soft_body_physics/tester.gd +++ b/3d/soft_body_physics/tester.gd @@ -1,5 +1,6 @@ extends WorldEnvironment + const ROT_SPEED: float = 0.003 const ZOOM_SPEED: float = 0.125 const MAIN_BUTTONS: int = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE @@ -63,13 +64,13 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event.is_action_pressed(&"reset_physics_simulation"): + if input_event.is_action_pressed(&"reset_physics_simulation"): # Remove all additional (player-spawned) items. for additional_item in additional_items: additional_item.queue_free() @@ -92,9 +93,9 @@ func _unhandled_input(event: InputEvent) -> void: nodes_to_reset[idx].set_point_pinned(point, true) if ( - event.is_action_pressed(&"place_cloth") or - event.is_action_pressed(&"place_light_box") or - event.is_action_pressed(&"place_heavy_box") + input_event.is_action_pressed(&"place_cloth") or + input_event.is_action_pressed(&"place_light_box") or + input_event.is_action_pressed(&"place_heavy_box") ): # Place a new item and track it in an additional items array, so we can limit # the number of player-spawned items present in the scene at a given time. @@ -111,11 +112,11 @@ func _unhandled_input(event: InputEvent) -> void: additional_items.pop_front().queue_free() var node: Node3D - if event.is_action_pressed(&"place_cloth"): + if input_event.is_action_pressed(&"place_cloth"): node = Cloth.instantiate() # Make user-placed cloth translucent to distinguish from the scene's own cloths. node.transparency = 0.35 - elif event.is_action_pressed(&"place_light_box"): + elif input_event.is_action_pressed(&"place_light_box"): node = RigidBoxLight.instantiate() else: node = RigidBoxHeavy.instantiate() @@ -124,16 +125,16 @@ func _unhandled_input(event: InputEvent) -> void: add_child(node) additional_items.push_back(node) - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clampf(zoom, 1.5, 4) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Compensate motion speed to be resolution-independent (based on the window height). - var relative_motion: Vector2 = event.relative * DisplayServer.window_get_size().y / base_height + var relative_motion: Vector2 = input_event.relative * DisplayServer.window_get_size().y / base_height rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clampf(rot_x, deg_to_rad(-90), 0) diff --git a/3d/sprites/scripts/3d_sprites.gd b/3d/sprites/scripts/3d_sprites.gd index f2047b5b..edab4c1b 100644 --- a/3d/sprites/scripts/3d_sprites.gd +++ b/3d/sprites/scripts/3d_sprites.gd @@ -1,5 +1,6 @@ extends Node + const ROT_SPEED = 0.003 const ZOOM_SPEED = 0.125 const MAIN_BUTTONS = MOUSE_BUTTON_MASK_LEFT | MOUSE_BUTTON_MASK_RIGHT | MOUSE_BUTTON_MASK_MIDDLE @@ -21,22 +22,22 @@ func _ready() -> void: update_gui() -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): _on_previous_pressed() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): _on_next_pressed() - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: camera_distance -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: camera_distance += ZOOM_SPEED camera_distance = clamp(camera_distance, 1.5, 6) - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clamp(rot_x, -1.57, 0) diff --git a/3d/truck_town/town/town_scene.gd b/3d/truck_town/town/town_scene.gd index 25a6f4aa..b36e2fd8 100644 --- a/3d/truck_town/town/town_scene.gd +++ b/3d/truck_town/town/town_scene.gd @@ -28,8 +28,8 @@ func _ready() -> void: add_child(compatibility_light) -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"cycle_mood"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"cycle_mood"): mood = wrapi(mood + 1, 0, Mood.MAX) as Mood diff --git a/3d/truck_town/vehicles/follow_camera.gd b/3d/truck_town/vehicles/follow_camera.gd index 4c3646a1..e463ce6b 100644 --- a/3d/truck_town/vehicles/follow_camera.gd +++ b/3d/truck_town/vehicles/follow_camera.gd @@ -37,8 +37,8 @@ func _ready() -> void: update_camera() -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"cycle_camera"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"cycle_camera"): camera_type = wrapi(camera_type + 1, 0, CameraType.MAX) as CameraType update_camera() diff --git a/3d/variable_rate_shading/vrs.gd b/3d/variable_rate_shading/vrs.gd index 4c116442..ae3f9ae4 100644 --- a/3d/variable_rate_shading/vrs.gd +++ b/3d/variable_rate_shading/vrs.gd @@ -1,5 +1,6 @@ extends Node3D + @onready var option_button: OptionButton = $CanvasLayer/VBoxContainer/HBoxContainer/OptionButton @onready var texture_rect: TextureRect = $CanvasLayer/VBoxContainer/TextureRect @onready var camera: Camera3D = $Camera3D @@ -9,6 +10,7 @@ extends Node3D var xr_interface: MobileVRInterface + func _set_xr_mode() -> void: var vrs_mode := get_viewport().vrs_mode if vrs_mode == Viewport.VRS_XR: diff --git a/3d/volumetric_fog/camera.gd b/3d/volumetric_fog/camera.gd index 57ccef31..f88b4c82 100644 --- a/3d/volumetric_fog/camera.gd +++ b/3d/volumetric_fog/camera.gd @@ -32,42 +32,42 @@ func _process(delta: float) -> void: position += velocity -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: # Mouse look (only if the mouse is captured). - if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + if input_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: # Horizontal mouse look. - rot.y -= event.screen_relative.x * MOUSE_SENSITIVITY + rot.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY # Vertical mouse look. - rot.x = clamp(rot.x - event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) + rot.x = clamp(rot.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) transform.basis = Basis.from_euler(rot) - if event.is_action_pressed(&"toggle_mouse_capture"): + if input_event.is_action_pressed(&"toggle_mouse_capture"): if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) else: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) - if event.is_action_pressed(&"toggle_temporal_reprojection"): + if input_event.is_action_pressed(&"toggle_temporal_reprojection"): get_world_3d().environment.volumetric_fog_temporal_reprojection_enabled = not get_world_3d().environment.volumetric_fog_temporal_reprojection_enabled update_label() - elif event.is_action_pressed(&"increase_temporal_reprojection"): + elif input_event.is_action_pressed(&"increase_temporal_reprojection"): get_world_3d().environment.volumetric_fog_temporal_reprojection_amount = clamp(get_world_3d().environment.volumetric_fog_temporal_reprojection_amount + 0.01, 0.5, 0.99) update_label() - elif event.is_action_pressed(&"decrease_temporal_reprojection"): + elif input_event.is_action_pressed(&"decrease_temporal_reprojection"): get_world_3d().environment.volumetric_fog_temporal_reprojection_amount = clamp(get_world_3d().environment.volumetric_fog_temporal_reprojection_amount - 0.01, 0.5, 0.99) update_label() - elif event.is_action_pressed(&"increase_fog_density"): + elif input_event.is_action_pressed(&"increase_fog_density"): get_world_3d().environment.volumetric_fog_density = clamp(get_world_3d().environment.volumetric_fog_density + 0.01, 0.0, 1.0) update_label() - elif event.is_action_pressed(&"decrease_fog_density"): + elif input_event.is_action_pressed(&"decrease_fog_density"): get_world_3d().environment.volumetric_fog_density = clamp(get_world_3d().environment.volumetric_fog_density - 0.01, 0.0, 1.0) update_label() - elif event.is_action_pressed(&"increase_volumetric_fog_quality"): + elif input_event.is_action_pressed(&"increase_volumetric_fog_quality"): volumetric_fog_volume_size = clamp(volumetric_fog_volume_size + 16, 16, 384) volumetric_fog_volume_depth = clamp(volumetric_fog_volume_depth + 16, 16, 384) RenderingServer.environment_set_volumetric_fog_volume_size(volumetric_fog_volume_size, volumetric_fog_volume_depth) update_label() - elif event.is_action_pressed(&"decrease_volumetric_fog_quality"): + elif input_event.is_action_pressed(&"decrease_volumetric_fog_quality"): volumetric_fog_volume_size = clamp(volumetric_fog_volume_size - 16, 16, 384) volumetric_fog_volume_depth = clamp(volumetric_fog_volume_depth - 16, 16, 384) RenderingServer.environment_set_volumetric_fog_volume_size(volumetric_fog_volume_size, volumetric_fog_volume_depth) diff --git a/3d/voxel/player/player.gd b/3d/voxel/player/player.gd index 570a2168..242573cc 100644 --- a/3d/voxel/player/player.gd +++ b/3d/voxel/player/player.gd @@ -120,10 +120,10 @@ func _physics_process(delta: float) -> void: velocity.y = MOVEMENT_JUMP_VELOCITY -func _input(event: InputEvent) -> void: - if event is InputEventMouseMotion: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventMouseMotion: if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: - _mouse_motion += event.screen_relative + _mouse_motion += input_event.screen_relative func chunk_pos() -> Vector3i: diff --git a/3d/voxel/world/chunk.gd b/3d/voxel/world/chunk.gd index 0f2943e4..0a6d771c 100644 --- a/3d/voxel/world/chunk.gd +++ b/3d/voxel/world/chunk.gd @@ -13,7 +13,7 @@ const DIRECTIONS: Array[Vector3i] = [Vector3i.LEFT, Vector3i.RIGHT, Vector3i.DOW var data: Dictionary[Vector3i, int] = {} var chunk_position := Vector3i() -var is_initial_mesh_generated := false +var is_initial_mesh_generated: bool = false var mesh_task_id := 0 static var box_shape: BoxShape3D = null diff --git a/3d/voxel/world/voxel_world.gd b/3d/voxel/world/voxel_world.gd index 9c43956d..7a508639 100644 --- a/3d/voxel/world/voxel_world.gd +++ b/3d/voxel/world/voxel_world.gd @@ -15,8 +15,8 @@ var _delete_distance := 0 var effective_render_distance := 0 var _old_player_chunk := Vector3i() -var _generating := true -var _deleting := false +var _generating: bool = true +var _deleting: bool = false var _chunks: Dictionary[Vector3i, Chunk] = {} diff --git a/3d/waypoints/camera.gd b/3d/waypoints/camera.gd index cd3c9539..80d489ce 100644 --- a/3d/waypoints/camera.gd +++ b/3d/waypoints/camera.gd @@ -1,25 +1,27 @@ extends Camera3D + const MOUSE_SENSITIVITY = 0.002 const MOVE_SPEED = 0.65 var rot := Vector3() var velocity := Vector3() + func _ready() -> void: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: # Mouse look (only if the mouse is captured). - if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: + if input_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: # Horizontal mouse look. - rot.y -= event.screen_relative.x * MOUSE_SENSITIVITY + rot.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY # Vertical mouse look. - rot.x = clamp(rot.x - event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) + rot.x = clamp(rot.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57) transform.basis = Basis.from_euler(rot) - if event.is_action_pressed(&"toggle_mouse_capture"): + if input_event.is_action_pressed(&"toggle_mouse_capture"): if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) else: diff --git a/3d/waypoints/main.gd b/3d/waypoints/main.gd index a3f69a8e..93c16e7d 100644 --- a/3d/waypoints/main.gd +++ b/3d/waypoints/main.gd @@ -1,5 +1,6 @@ extends Node3D + func _ready() -> void: if RenderingServer.get_current_rendering_method() == "gl_compatibility": # Use PCF13 shadow filtering to improve quality (Medium maps to PCF5 instead). diff --git a/3d/waypoints/waypoint.gd b/3d/waypoints/waypoint.gd index 8a318fc7..24031cbd 100644 --- a/3d/waypoints/waypoint.gd +++ b/3d/waypoints/waypoint.gd @@ -1,10 +1,11 @@ extends Control + ## Some margin to keep the marker away from the screen's corners. const MARGIN = 8 ## The waypoint's text. -@export var text := "Waypoint": +@export var text: String = "Waypoint": set(value): text = value # The label's text can only be set once the node is ready. @@ -12,13 +13,14 @@ const MARGIN = 8 label.text = value ## If `true`, the waypoint sticks to the viewport's edges when moving off-screen. -@export var sticky := true +@export var sticky: bool = true @onready var camera := get_viewport().get_camera_3d() @onready var parent := get_parent() @onready var label: Label = $Label @onready var marker: TextureRect = $Marker + func _ready() -> void: self.text = text assert(parent is Node3D, "The waypoint's parent node must inherit from Node3D.") diff --git a/audio/bpm_sync/bpm_sync.gd b/audio/bpm_sync/bpm_sync.gd index f8efa653..a40de904 100644 --- a/audio/bpm_sync/bpm_sync.gd +++ b/audio/bpm_sync/bpm_sync.gd @@ -11,7 +11,7 @@ const BARS = 4 const COMPENSATE_FRAMES = 2 const COMPENSATE_HZ = 60.0 -var playing := false +var playing: bool = false var sync_source := SyncSource.SYSTEM_CLOCK # Used by system clock. diff --git a/audio/device_changer/Changer.gd b/audio/device_changer/Changer.gd index 68b4ae21..114e78e9 100644 --- a/audio/device_changer/Changer.gd +++ b/audio/device_changer/Changer.gd @@ -14,7 +14,7 @@ func _ready() -> void: func _process(_delta: float) -> void: - var speaker_mode_text := "Stereo" + var speaker_mode_text: String = "Stereo" var speaker_mode := AudioServer.get_speaker_mode() if speaker_mode == AudioServer.SPEAKER_SURROUND_31: diff --git a/audio/mic_record/MicRecord.gd b/audio/mic_record/MicRecord.gd index d118be2c..8829912b 100644 --- a/audio/mic_record/MicRecord.gd +++ b/audio/mic_record/MicRecord.gd @@ -3,7 +3,7 @@ extends Control var effect: AudioEffect var recording: AudioStreamWAV -var stereo := true +var stereo: bool = true var mix_rate := 44100 # This is the default mix rate on recordings. var format := AudioStreamWAV.FORMAT_16_BITS # This is the default format on recordings. diff --git a/compute/post_shader/main.gd b/compute/post_shader/main.gd index 5a39b20a..c159b817 100644 --- a/compute/post_shader/main.gd +++ b/compute/post_shader/main.gd @@ -3,12 +3,12 @@ extends Node3D @onready var compositor: Compositor = $WorldEnvironment.compositor -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_grayscale_effect"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_grayscale_effect"): compositor.compositor_effects[0].enabled = not compositor.compositor_effects[0].enabled update_info_text() - if event.is_action_pressed(&"toggle_shader_effect"): + if input_event.is_action_pressed(&"toggle_shader_effect"): compositor.compositor_effects[1].enabled = not compositor.compositor_effects[1].enabled update_info_text() diff --git a/compute/post_shader/post_process_shader.gd b/compute/post_shader/post_process_shader.gd index 7d01250e..759ab709 100644 --- a/compute/post_shader/post_process_shader.gd +++ b/compute/post_shader/post_process_shader.gd @@ -48,7 +48,7 @@ void main() { imageStore(color_image, uv, color); }""" -@export_multiline var shader_code := "": +@export_multiline var shader_code: String = "": set(value): mutex.lock() shader_code = value diff --git a/compute/texture/water_plane/water_plane.gd b/compute/texture/water_plane/water_plane.gd index 72c624f0..ee5578a9 100644 --- a/compute/texture/water_plane/water_plane.gd +++ b/compute/texture/water_plane/water_plane.gd @@ -55,16 +55,16 @@ func _exit_tree() -> void: RenderingServer.call_on_render_thread(_free_compute_resources) -func _unhandled_input(event: InputEvent) -> void: +func _unhandled_input(input_event: InputEvent) -> void: # If tool enabled, we don't want to handle our input in the editor. if Engine.is_editor_hint(): return - if event is InputEventMouseMotion or event is InputEventMouseButton: - mouse_pos = event.global_position + if input_event is InputEventMouseMotion or input_event is InputEventMouseButton: + mouse_pos = input_event.global_position - if event is InputEventMouseButton and event.button_index == MouseButton.MOUSE_BUTTON_LEFT: - mouse_pressed = event.pressed + if input_event is InputEventMouseButton and input_event.button_index == MouseButton.MOUSE_BUTTON_LEFT: + mouse_pressed = input_event.pressed func _check_mouse_pos() -> void: diff --git a/gui/accessibility/custom_control.gd b/gui/accessibility/custom_control.gd index c456fea1..db9dbdd1 100644 --- a/gui/accessibility/custom_control.gd +++ b/gui/accessibility/custom_control.gd @@ -8,26 +8,26 @@ var selected: int = 0 # Input: -func _gui_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ui_left"): +func _gui_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ui_left"): selected = (selected - 1) % item_aes.size() queue_redraw() queue_accessibility_update() # Request node accessibility information update. Similar to "queue_redraw" for drawing. accept_event() - if event.is_action_pressed(&"ui_right"): + if input_event.is_action_pressed(&"ui_right"): selected = (selected + 1) % item_aes.size() queue_redraw() queue_accessibility_update() accept_event() - if event.is_action_pressed(&"ui_up"): + if input_event.is_action_pressed(&"ui_up"): item_values[selected] = clampi(item_values[selected] - 1, -100, 100) queue_redraw() queue_accessibility_update() accept_event() - if event.is_action_pressed(&"ui_down"): + if input_event.is_action_pressed(&"ui_down"): item_values[selected] = clampi(item_values[selected] + 1, -100, 100) queue_redraw() queue_accessibility_update() diff --git a/gui/bidi_and_font_features/bidi.gd b/gui/bidi_and_font_features/bidi.gd index 4025fc4f..226e0719 100644 --- a/gui/bidi_and_font_features/bidi.gd +++ b/gui/bidi_and_font_features/bidi.gd @@ -26,7 +26,7 @@ func _ready() -> void: func _on_Tree_item_selected() -> void: var tree: Tree = $"TabContainer/Text direction/Tree" - var path := "" + var path: String = "" var item := tree.get_selected() while item != null: path = item.get_text(0) + "/" + path diff --git a/gui/gd_paint/paint_control.gd b/gui/gd_paint/paint_control.gd index 265e49cb..590c652d 100644 --- a/gui/gd_paint/paint_control.gd +++ b/gui/gd_paint/paint_control.gd @@ -23,14 +23,14 @@ var brush_data_list: Array[Dictionary] = [] # A boolean to hold whether or not the mouse is inside the drawing area, the mouse position last _process call # and the position of the mouse when the left mouse button was pressed. -var is_mouse_in_drawing_area := false +var is_mouse_in_drawing_area: bool = false var last_mouse_pos := Vector2() var mouse_click_start_pos := Vector2.INF # A boolean to tell whether we've set undo_elements_list_num, which holds the size of draw_elements_list # before a new stroke is added (unless the current brush mode is 'rectangle shape' or 'circle shape', in # which case we do things a little differently. See the undo_stroke function for more details). -var undo_set := false +var undo_set: bool = false var undo_element_list_num := -1 # The current brush settings: The mode, size, color, and shape we have currently selected. diff --git a/gui/gd_paint/tools_panel.gd b/gui/gd_paint/tools_panel.gd index 221f1014..ee0f880e 100644 --- a/gui/gd_paint/tools_panel.gd +++ b/gui/gd_paint/tools_panel.gd @@ -40,8 +40,8 @@ func _physics_process(_delta: float) -> void: func button_pressed(button_name: String) -> void: # If a brush mode button is pressed. - var tool_name := "" - var shape_name := "" + var tool_name: String = "" + var shape_name: String = "" if button_name == "mode_pencil": paint_control.brush_mode = paint_control.BrushMode.PENCIL diff --git a/gui/input_mapping/ActionRemapButton.gd b/gui/input_mapping/ActionRemapButton.gd index e8fb7124..f2598d8f 100644 --- a/gui/input_mapping/ActionRemapButton.gd +++ b/gui/input_mapping/ActionRemapButton.gd @@ -1,6 +1,8 @@ extends Button -@export var action := "ui_up" + +@export var action: String = "ui_up" + func _ready() -> void: assert(InputMap.has_action(action)) @@ -24,23 +26,23 @@ func _toggled(is_button_pressed: bool) -> void: # NOTE: You can use the `_input()` callback instead, especially if # you want to work with gamepads. -func _unhandled_key_input(event: InputEvent) -> void: +func _unhandled_key_input(input_event: InputEvent) -> void: # Skip if pressing Enter, so that the input mapping GUI can be navigated # with the keyboard. The downside of this approach is that the Enter # key can't be bound to actions. - if event is InputEventKey and event.keycode != KEY_ENTER: - remap_action_to(event) + if input_event is InputEventKey and input_event.keycode != KEY_ENTER: + remap_action_to(input_event) button_pressed = false -func remap_action_to(event: InputEvent) -> void: +func remap_action_to(input_event: InputEvent) -> void: # We first change the event in this game instance. InputMap.action_erase_events(action) - InputMap.action_add_event(action, event) + InputMap.action_add_event(action, input_event) # And then save it to the keymaps file. - KeyPersistence.keymaps[action] = event + KeyPersistence.keymaps[action] = input_event KeyPersistence.save_keymap() - text = event.as_text() + text = input_event.as_text() func display_current_key() -> void: diff --git a/gui/input_mapping/KeyPersistence.gd b/gui/input_mapping/KeyPersistence.gd index 45b79ad1..0c22d0d2 100644 --- a/gui/input_mapping/KeyPersistence.gd +++ b/gui/input_mapping/KeyPersistence.gd @@ -2,7 +2,7 @@ # the key maps in a simple way through a dictionary. extends Node -const keymaps_path := "user://keymaps.dat" +const keymaps_path: String = "user://keymaps.dat" var keymaps: Dictionary diff --git a/gui/msdf_font/sdf_font_demo.gd b/gui/msdf_font/sdf_font_demo.gd index 578dab17..d2fd8a2c 100644 --- a/gui/msdf_font/sdf_font_demo.gd +++ b/gui/msdf_font/sdf_font_demo.gd @@ -1,7 +1,7 @@ extends Control -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_msdf_font"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_msdf_font"): if %FontLabel.get_theme_font(&"font").multichannel_signed_distance_field: %FontLabel.add_theme_font_override(&"font", preload("res://montserrat_semibold.ttf")) else: diff --git a/loading/serialization/player.gd b/loading/serialization/player.gd index c1c0020f..00cf6b86 100644 --- a/loading/serialization/player.gd +++ b/loading/serialization/player.gd @@ -26,12 +26,12 @@ func _process(_delta: float) -> void: move_and_slide() -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"move_left"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"move_left"): sprite.rotation = PI / 2 - elif event.is_action_pressed(&"move_right"): + elif input_event.is_action_pressed(&"move_right"): sprite.rotation = -PI / 2 - elif event.is_action_pressed(&"move_up"): + elif input_event.is_action_pressed(&"move_up"): sprite.rotation = PI - elif event.is_action_pressed(&"move_down"): + elif input_event.is_action_pressed(&"move_down"): sprite.rotation = 0.0 diff --git a/misc/2.5d/addons/node25d/main_screen/gizmo_25d.gd b/misc/2.5d/addons/node25d/main_screen/gizmo_25d.gd index dfb46299..12a0791a 100644 --- a/misc/2.5d/addons/node25d/main_screen/gizmo_25d.gd +++ b/misc/2.5d/addons/node25d/main_screen/gizmo_25d.gd @@ -1,6 +1,7 @@ @tool extends Node2D + # If the mouse is farther than this many pixels, it won't grab anything. const DEADZONE_RADIUS = 20.0 const DEADZONE_RADIUS_SQ = DEADZONE_RADIUS * DEADZONE_RADIUS @@ -13,21 +14,21 @@ var node_25d: Node25D var _spatial_node: Node3D # Input from Viewport25D, represents if the mouse is clicked. -var wants_to_move = false +var wants_to_move: bool = false # Used to control the state of movement. -var _moving = false +var _moving: bool = false var _start_mouse_position := Vector2.ZERO # Stores state of closest or currently used axis. -var _dominant_axis +var _dominant_axis: int = -1 @onready var _lines = [$X, $Y, $Z] @onready var _viewport_overlay: SubViewport = get_parent() @onready var _viewport_25d_bg: ColorRect = _viewport_overlay.get_parent() -func _process(_delta): +func _process(_delta: float) -> void: if not _lines: return # Somehow this node hasn't been set up yet. if not node_25d or not _viewport_25d_bg: diff --git a/misc/2.5d/addons/node25d/main_screen/viewport_25d.gd b/misc/2.5d/addons/node25d/main_screen/viewport_25d.gd index 46f8208d..c780c668 100644 --- a/misc/2.5d/addons/node25d/main_screen/viewport_25d.gd +++ b/misc/2.5d/addons/node25d/main_screen/viewport_25d.gd @@ -1,11 +1,12 @@ @tool extends Control -var zoom_level := 0 -var is_panning = false + +var zoom_level: int = 0 +var is_panning: bool = false var pan_center: Vector2 var viewport_center: Vector2 -var view_mode_index := 0 +var view_mode_index: int = 0 var editor_interface: EditorInterface # Set in node25d_plugin.gd var moving = false @@ -40,7 +41,7 @@ func _process(_delta: float) -> void: return # View mode polling. - var view_mode_changed_this_frame := false + var view_mode_changed_this_frame: bool = false var new_view_mode := -1 if view_mode_button_group.get_pressed_button(): new_view_mode = view_mode_button_group.get_pressed_button().get_index() @@ -73,7 +74,7 @@ func _process(_delta: float) -> void: var selection := editor_interface.get_selection().get_selected_nodes() var gizmos := viewport_overlay.get_children() for gizmo in gizmos: - var contains := false + var contains: bool = false for selected in selection: if selected == gizmo.node_25d and not view_mode_changed_this_frame: contains = true @@ -99,35 +100,35 @@ func _ensure_node25d_has_gizmo(node: Node25D, gizmos: Array[Node]) -> void: # This only accepts input when the mouse is inside of the 2.5D viewport. -func _gui_input(event: InputEvent) -> void: - if event is InputEventMouseButton: - if event.is_pressed(): - if event.button_index == MOUSE_BUTTON_WHEEL_UP: +func _gui_input(input_event: InputEvent) -> void: + if input_event is InputEventMouseButton: + if input_event.is_pressed(): + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom_level += 1 accept_event() - elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + elif input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom_level -= 1 accept_event() - elif event.button_index == MOUSE_BUTTON_MIDDLE: + elif input_event.button_index == MOUSE_BUTTON_MIDDLE: is_panning = true - pan_center = viewport_center - event.position / _get_zoom_amount() + pan_center = viewport_center - input_event.position / _get_zoom_amount() accept_event() - elif event.button_index == MOUSE_BUTTON_LEFT: + elif input_event.button_index == MOUSE_BUTTON_LEFT: var overlay_children := viewport_overlay.get_children() for overlay_child in overlay_children: overlay_child.wants_to_move = true accept_event() - elif event.button_index == MOUSE_BUTTON_MIDDLE: + elif input_event.button_index == MOUSE_BUTTON_MIDDLE: is_panning = false accept_event() - elif event.button_index == MOUSE_BUTTON_LEFT: + elif input_event.button_index == MOUSE_BUTTON_LEFT: var overlay_children := viewport_overlay.get_children() for overlay_child in overlay_children: overlay_child.wants_to_move = false accept_event() - elif event is InputEventMouseMotion: + elif input_event is InputEventMouseMotion: if is_panning: - viewport_center = pan_center + event.position / _get_zoom_amount() + viewport_center = pan_center + input_event.position / _get_zoom_amount() accept_event() diff --git a/misc/2.5d/addons/node25d/node25d_plugin.gd b/misc/2.5d/addons/node25d/node25d_plugin.gd index 17db8b49..68b3386b 100644 --- a/misc/2.5d/addons/node25d/node25d_plugin.gd +++ b/misc/2.5d/addons/node25d/node25d_plugin.gd @@ -1,6 +1,7 @@ @tool extends EditorPlugin + const MainPanel = preload("res://addons/node25d/main_screen/main_screen_25d.tscn") var main_panel_instance: VBoxContainer diff --git a/misc/2.5d/addons/node25d/shadow_math_25d.gd b/misc/2.5d/addons/node25d/shadow_math_25d.gd index e0047d43..028582fe 100644 --- a/misc/2.5d/addons/node25d/shadow_math_25d.gd +++ b/misc/2.5d/addons/node25d/shadow_math_25d.gd @@ -6,6 +6,7 @@ class_name ShadowMath25D extends ShapeCast3D + var _shadow_root: Node25D var _target_math: Node3D diff --git a/misc/2.5d/addons/node25d/y_sort_25d.gd b/misc/2.5d/addons/node25d/y_sort_25d.gd index 6211bd8d..b7890f71 100644 --- a/misc/2.5d/addons/node25d/y_sort_25d.gd +++ b/misc/2.5d/addons/node25d/y_sort_25d.gd @@ -9,7 +9,7 @@ extends Node # NOTE: NOT Node2D or Node25D. # Whether or not to automatically call sort() in _process(). -@export var sort_enabled := true +@export var sort_enabled: bool = true var _parent_node: Node2D # NOT Node25D diff --git a/misc/2.5d/assets/cube/cube_math.gd b/misc/2.5d/assets/cube/cube_math.gd index 1c564cbe..b26365ae 100644 --- a/misc/2.5d/assets/cube/cube_math.gd +++ b/misc/2.5d/assets/cube/cube_math.gd @@ -1,6 +1,7 @@ extends Node3D -var _is_parent_ready := false + +var _is_parent_ready: bool = false var _cube_points_math: Array[Node3D] = [] var _cube_math_spatials: Array[Node3D] = [] diff --git a/misc/2.5d/assets/platform/platform_sprite.gd b/misc/2.5d/assets/platform/platform_sprite.gd index 51b3566c..865a7ba6 100644 --- a/misc/2.5d/assets/platform/platform_sprite.gd +++ b/misc/2.5d/assets/platform/platform_sprite.gd @@ -1,6 +1,7 @@ @tool extends Sprite2D + @onready var _forty_five: Texture2D = preload("res://assets/platform/textures/forty_five.png") @onready var _isometric: Texture2D = preload("res://assets/platform/textures/isometric.png") @onready var _top_down: Texture2D = preload("res://assets/platform/textures/top_down.png") @@ -8,6 +9,7 @@ extends Sprite2D @onready var _oblique_y: Texture2D = preload("res://assets/platform/textures/oblique_y.png") @onready var _oblique_z: Texture2D = preload("res://assets/platform/textures/oblique_z.png") + func _process(_delta: float) -> void: if not Engine.is_editor_hint(): if Input.is_action_pressed(&"forty_five_mode"): diff --git a/misc/2.5d/assets/player/player_math_25d.gd b/misc/2.5d/assets/player/player_math_25d.gd index 86cecd2d..b2cd712b 100644 --- a/misc/2.5d/assets/player/player_math_25d.gd +++ b/misc/2.5d/assets/player/player_math_25d.gd @@ -2,8 +2,9 @@ class_name PlayerMath25D # No icon necessary extends CharacterBody3D -var vertical_speed := 0.0 -var isometric_controls := true + +var vertical_speed: float = 0.0 +var isometric_controls: bool = true @onready var _parent_node25d: Node25D = get_parent() diff --git a/misc/2.5d/assets/player/player_sprite.gd b/misc/2.5d/assets/player/player_sprite.gd index 69ecb3c0..800b83a7 100644 --- a/misc/2.5d/assets/player/player_sprite.gd +++ b/misc/2.5d/assets/player/player_sprite.gd @@ -1,10 +1,11 @@ @tool extends Sprite2D + const ANIMATION_FRAMERATE = 15 -var _direction := 0 -var _progress := 0.0 +var _direction: int = 0 +var _progress: float = 0.0 var _parent_node25d: Node25D var _parent_math: PlayerMath25D @@ -12,6 +13,7 @@ var _parent_math: PlayerMath25D @onready var _jump: Texture2D = preload("res://assets/player/textures/jump.png") @onready var _run: Texture2D = preload("res://assets/player/textures/run.png") + func _ready() -> void: _parent_node25d = get_parent() _parent_math = _parent_node25d.get_child(0) diff --git a/misc/2.5d/assets/ui/control_hints.gd b/misc/2.5d/assets/ui/control_hints.gd index bf87ba15..1bc839b5 100644 --- a/misc/2.5d/assets/ui/control_hints.gd +++ b/misc/2.5d/assets/ui/control_hints.gd @@ -1,6 +1,6 @@ extends Control -func _input(event: InputEvent) -> void: - if event.is_action_pressed(&"toggle_control_hints"): +func _input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"toggle_control_hints"): visible = not visible diff --git a/misc/custom_logging/custom_logger_ui.gd b/misc/custom_logging/custom_logger_ui.gd index 955a0e04..e62cb695 100644 --- a/misc/custom_logging/custom_logger_ui.gd +++ b/misc/custom_logging/custom_logger_ui.gd @@ -22,7 +22,7 @@ class CustomLogger extends Logger: error_type: int, script_backtraces: Array[ScriptBacktrace] ) -> void: - var prefix := "" + var prefix: String = "" # The column at which to print the trace. Should match the length of the # unformatted text above it. var trace_indent := 0 @@ -41,8 +41,8 @@ class CustomLogger extends Logger: prefix = "[color=#4bf][b]SHADER ERROR:[/b]" trace_indent = 13 - var trace := "%*s %s (%s:%s)" % [trace_indent, "at:", function, file, line] - var script_backtraces_text := "" + var trace: String = "%*s %s (%s:%s)" % [trace_indent, "at:", function, file, line] + var script_backtraces_text: String = "" for backtrace in script_backtraces: script_backtraces_text += backtrace.format(trace_indent - 3) + "\n" diff --git a/misc/custom_logging/main.gd b/misc/custom_logging/main.gd index b515bbe8..35bbc1eb 100644 --- a/misc/custom_logging/main.gd +++ b/misc/custom_logging/main.gd @@ -1,10 +1,11 @@ extends Control -var message_counter := 0 -var message_raw_counter := 0 -var message_stderr_counter := 0 -var warning_counter := 0 -var error_counter := 0 + +var message_counter: int = 0 +var message_raw_counter: int = 0 +var message_stderr_counter: int = 0 +var warning_counter: int = 0 +var error_counter: int = 0 func _ready() -> void: diff --git a/misc/graphics_tablet_input/graphics_tablet_input.gd b/misc/graphics_tablet_input/graphics_tablet_input.gd index e10318ca..2d8aa9d6 100644 --- a/misc/graphics_tablet_input/graphics_tablet_input.gd +++ b/misc/graphics_tablet_input/graphics_tablet_input.gd @@ -35,8 +35,8 @@ func _ready() -> void: %TabletDriver.text = "Tablet driver: %s" % DisplayServer.tablet_get_current_driver() -func _input(event: InputEvent) -> void: - if event is InputEventKey: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventKey: if Input.is_action_pressed(&"increase_line_width"): $CanvasLayer/PanelContainer/Options/LineWidth/HSlider.value += 0.5 #_on_line_width_value_changed(line_width) @@ -47,8 +47,8 @@ func _input(event: InputEvent) -> void: if not stroke: return - if event is InputEventMouseMotion: - var event_mouse_motion := event as InputEventMouseMotion + if input_event is InputEventMouseMotion: + var event_mouse_motion := input_event as InputEventMouseMotion tablet_info.text = "Pressure: %.3f\nTilt: %.3v\nInverted pen: %s" % [ event_mouse_motion.pressure, event_mouse_motion.tilt, diff --git a/misc/joypads/remap/joy_mapping.gd b/misc/joypads/remap/joy_mapping.gd index 7a91c455..c20e2a3c 100644 --- a/misc/joypads/remap/joy_mapping.gd +++ b/misc/joypads/remap/joy_mapping.gd @@ -107,7 +107,7 @@ const XBOX_OSX = { var type := Type.NONE var idx := -1 var axis := Axis.FULL -var inverted := false +var inverted: bool = false func _init(p_type: Type = Type.NONE, p_idx: int = -1, p_axis: Axis = Axis.FULL) -> void: type = p_type @@ -119,9 +119,9 @@ func _to_string() -> String: if type == Type.NONE: return "" - var ts := "b" if type == Type.BTN else "a" - var prefix := "" - var suffix := "~" if inverted else "" + var ts: String = "b" if type == Type.BTN else "a" + var prefix: String = "" + var suffix: String = "~" if inverted else "" match axis: Axis.HALF_PLUS: @@ -137,13 +137,13 @@ func to_human_string() -> String: return "Button %d" % idx if type == Type.AXIS: - var prefix := "" + var prefix: String = "" match axis: Axis.HALF_PLUS: prefix = "(+) " Axis.HALF_MINUS: prefix = "(-) " - var suffix := " (inverted)" if inverted else "" + var suffix: String = " (inverted)" if inverted else "" return "Axis %s%d%s" % [prefix, idx, suffix] return "" diff --git a/misc/joypads/remap/remap_wizard.gd b/misc/joypads/remap/remap_wizard.gd index aede326c..3f9a7e4a 100644 --- a/misc/joypads/remap/remap_wizard.gd +++ b/misc/joypads/remap/remap_wizard.gd @@ -1,5 +1,6 @@ extends Node + const DEADZONE = 0.3 var joy_index: int = -1 @@ -17,23 +18,24 @@ var last_mapping: String = "" @onready var joy_mapping_full_axis: CheckBox = $Mapping/Margin/VBox/Info/Extra/FullAxis @onready var joy_mapping_axis_invert: CheckBox = $Mapping/Margin/VBox/Info/Extra/InvertAxis + # Connected to Mapping.window_input, otherwise no gamepad events # will be received when the subwindow is focused. -func _input(event: InputEvent) -> void: +func _input(input_event: InputEvent) -> void: if cur_step == -1: return # Ignore events not related to gamepads. - if event is not InputEventJoypadButton and event is not InputEventJoypadMotion: + if input_event is not InputEventJoypadButton and input_event is not InputEventJoypadMotion: return # Ignore devices other than the one being remapped. Handles accidental input and analog drift. - if event.device != joy_index: + if input_event.device != joy_index: return - if event is InputEventJoypadMotion: + if input_event is InputEventJoypadMotion: get_viewport().set_input_as_handled() - var motion := event as InputEventJoypadMotion + var motion := input_event as InputEventJoypadMotion if abs(motion.axis_value) > DEADZONE: var idx := motion.axis var map := JoyMapping.new(JoyMapping.Type.AXIS, idx) @@ -46,16 +48,16 @@ func _input(event: InputEvent) -> void: map.axis = JoyMapping.Axis.HALF_MINUS joy_mapping_text.text = map.to_human_string() cur_mapping[steps[cur_step]] = map - elif event is InputEventJoypadButton and event.pressed: + elif input_event is InputEventJoypadButton and input_event.pressed: get_viewport().set_input_as_handled() - var btn := event as InputEventJoypadButton + var btn := input_event as InputEventJoypadButton var map := JoyMapping.new(JoyMapping.Type.BTN, btn.button_index) joy_mapping_text.text = map.to_human_string() cur_mapping[steps[cur_step]] = map func create_mapping_string(mapping: Dictionary) -> String: - var string := "%s,%s," % [joy_guid, joy_name] + var string: String = "%s,%s," % [joy_guid, joy_name] for k: String in mapping: var m: Variant = mapping[k] @@ -63,7 +65,7 @@ func create_mapping_string(mapping: Dictionary) -> String: continue string += "%s:%s," % [k, str(m)] - var platform := "Unknown" + var platform: String = "Unknown" if JoyMapping.PLATFORMS.keys().has(OS.get_name()): platform = JoyMapping.PLATFORMS[OS.get_name()] diff --git a/misc/joypads/remap/remap_wizard.tscn b/misc/joypads/remap/remap_wizard.tscn index 700c1f86..3a080c38 100644 --- a/misc/joypads/remap/remap_wizard.tscn +++ b/misc/joypads/remap/remap_wizard.tscn @@ -62,6 +62,7 @@ layout_mode = 2 text = "Wizard" [node name="Mapping" type="Window" parent="."] +oversampling_override = 1.0 position = Vector2i(130, 100) size = Vector2i(340, 400) visible = false diff --git a/misc/large_world_coordinates/controls.gd b/misc/large_world_coordinates/controls.gd index c526c38f..eb1fd8ed 100644 --- a/misc/large_world_coordinates/controls.gd +++ b/misc/large_world_coordinates/controls.gd @@ -30,18 +30,18 @@ func _process(delta: float) -> void: node_to_move.position.z += 1_000_000 * delta -func _input(event: InputEvent) -> void: - if event is InputEventMouseButton: - if event.button_index == MOUSE_BUTTON_WHEEL_UP: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventMouseButton: + if input_event.button_index == MOUSE_BUTTON_WHEEL_UP: zoom -= ZOOM_SPEED - if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + if input_event.button_index == MOUSE_BUTTON_WHEEL_DOWN: zoom += ZOOM_SPEED zoom = clampf(zoom, 4, 15) camera.position.z = zoom - if event is InputEventMouseMotion and event.button_mask & MAIN_BUTTONS: + if input_event is InputEventMouseMotion and input_event.button_mask & MAIN_BUTTONS: # Use `screen_relative` to make mouse sensitivity independent of viewport resolution. - var relative_motion: Vector2 = event.screen_relative + var relative_motion: Vector2 = input_event.screen_relative rot_y -= relative_motion.x * ROT_SPEED rot_x -= relative_motion.y * ROT_SPEED rot_x = clampf(rot_x, -1.4, 0.16) diff --git a/misc/matrix_transform/marker/AxisMarker2D.svg.import b/misc/matrix_transform/marker/AxisMarker2D.svg.import index 1af9a156..59cd672b 100644 --- a/misc/matrix_transform/marker/AxisMarker2D.svg.import +++ b/misc/matrix_transform/marker/AxisMarker2D.svg.import @@ -38,6 +38,6 @@ process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 detect_3d/compress_to=1 -svg/scale=1.0 +svg/scale=2.0 editor/scale_with_editor_scale=false editor/convert_colors_with_editor_theme=false diff --git a/misc/matrix_transform/marker/AxisMarker3D.svg.import b/misc/matrix_transform/marker/AxisMarker3D.svg.import index a943a1b6..f24ecb4c 100644 --- a/misc/matrix_transform/marker/AxisMarker3D.svg.import +++ b/misc/matrix_transform/marker/AxisMarker3D.svg.import @@ -38,6 +38,6 @@ process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 detect_3d/compress_to=1 -svg/scale=1.0 +svg/scale=2.0 editor/scale_with_editor_scale=false editor/convert_colors_with_editor_theme=false diff --git a/misc/multiple_windows/scenes/draggable_window/draggable_region.gd b/misc/multiple_windows/scenes/draggable_window/draggable_region.gd index b8dd6c28..d17f5daa 100644 --- a/misc/multiple_windows/scenes/draggable_window/draggable_region.gd +++ b/misc/multiple_windows/scenes/draggable_window/draggable_region.gd @@ -1,6 +1,7 @@ extends Area2D -func _input_event(_viewport: Viewport, event: InputEvent, _shape_index: int) -> void: - if event is InputEventMouseButton: - if event.pressed: + +func _input_event(_viewport: Viewport, input_event: InputEvent, _shape_index: int) -> void: + if input_event is InputEventMouseButton: + if input_event.pressed: get_window().start_drag() diff --git a/misc/noise_viewer/noise_viewer.gd b/misc/noise_viewer/noise_viewer.gd index 6b715ae5..69fbaf9c 100644 --- a/misc/noise_viewer/noise_viewer.gd +++ b/misc/noise_viewer/noise_viewer.gd @@ -1,11 +1,13 @@ extends Control + ## The FastNoiseLite object. @onready var noise: FastNoiseLite = $SeamlessNoiseTexture.texture.noise # Various noise parameters. -var min_noise := -1.0 -var max_noise := 1.0 +var min_noise: float = -1.0 +var max_noise: float = 1.0 + func _ready() -> void: # Set up noise with basic info. diff --git a/misc/os_test/actions.gd b/misc/os_test/actions.gd index 13679dcb..04e1d3a2 100644 --- a/misc/os_test/actions.gd +++ b/misc/os_test/actions.gd @@ -1,5 +1,6 @@ extends Node + func _ready() -> void: if OS.has_feature("web"): for button: Button in [ diff --git a/misc/os_test/os_test.gd b/misc/os_test/os_test.gd index 99ee69af..4cb5ce7c 100644 --- a/misc/os_test/os_test.gd +++ b/misc/os_test/os_test.gd @@ -1,11 +1,13 @@ extends Node + @onready var rtl: RichTextLabel = $HBoxContainer/Features @onready var csharp_test: Node = $CSharpTest # Line number for alternate line coloring. Incremented by 1 each time a line is added # (ignoring headers). -var line_count := 0 +var line_count: int = 0 + # Returns a human-readable string from a date and time, date, or time dictionary. func datetime_to_string(date: Dictionary) -> void: @@ -48,7 +50,7 @@ func scan_midi_inputs() -> String: return "" OS.open_midi_inputs() - var devices := ", ".join(OS.get_connected_midi_inputs()) + var devices: String = ", ".join(OS.get_connected_midi_inputs()) OS.close_midi_inputs() return devices diff --git a/misc/pause/pause_button.gd b/misc/pause/pause_button.gd index 3a7ff93f..a5eb03f6 100644 --- a/misc/pause/pause_button.gd +++ b/misc/pause/pause_button.gd @@ -1,5 +1,6 @@ extends Button + func _ready() -> void: # This ensures that this Node won't be paused, allowing it to # process even when the SceneTree is paused. Without that it would diff --git a/misc/pause/process_mode.gd b/misc/pause/process_mode.gd index 86ec777f..ad22a783 100644 --- a/misc/pause/process_mode.gd +++ b/misc/pause/process_mode.gd @@ -1,5 +1,6 @@ extends OptionButton + @onready var cube_animation: AnimationPlayer = $"../../AnimationPlayer" diff --git a/misc/window_management/control.gd b/misc/window_management/control.gd index 79b37f33..87abff55 100644 --- a/misc/window_management/control.gd +++ b/misc/window_management/control.gd @@ -31,7 +31,7 @@ func _ready() -> void: func _physics_process(_delta: float) -> void: - var modetext := "Mode: " + var modetext: String = "Mode: " if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: modetext += "Fullscreen\n" else: @@ -85,11 +85,11 @@ func _physics_process(_delta: float) -> void: $Buttons/Button_MouseModeCaptured.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED) -func _input(event: InputEvent) -> void: - if event is InputEventMouseMotion: - mouse_position = event.position +func _input(input_event: InputEvent) -> void: + if input_event is InputEventMouseMotion: + mouse_position = input_event.position - if event is InputEventKey: + if input_event is InputEventKey: if Input.is_action_pressed(&"mouse_mode_visible"): observer.state = observer.State.MENU _on_button_mouse_mode_visible_pressed() @@ -111,7 +111,7 @@ func _input(event: InputEvent) -> void: func check_wm_api() -> bool: - var s := "" + var s: String = "" if not DisplayServer.has_method(&"get_screen_count"): s += " - get_screen_count()\n" if not DisplayServer.has_method(&"window_get_current_screen"): diff --git a/misc/window_management/observer/observer.gd b/misc/window_management/observer/observer.gd index aed0779c..28b8abbd 100644 --- a/misc/window_management/observer/observer.gd +++ b/misc/window_management/observer/observer.gd @@ -31,12 +31,12 @@ func _process(delta: float) -> void: r_pos = Vector2.ZERO -func _input(event: InputEvent) -> void: - if event is InputEventMouseMotion: +func _input(input_event: InputEvent) -> void: + if input_event is InputEventMouseMotion: # Use `screen_relative` to make sensitivity independent of the viewport resolution. - r_pos = -event.screen_relative * MOUSE_SENSITIVITY + r_pos = -input_event.screen_relative * MOUSE_SENSITIVITY - if event.is_action(&"ui_cancel") and event.is_pressed() and not event.is_echo(): + if input_event.is_action(&"ui_cancel") and input_event.is_pressed() and not input_event.is_echo(): if state == State.GRAB: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) state = State.MENU diff --git a/misc/window_management/window_management.tscn b/misc/window_management/window_management.tscn index f441f3cf..3e88d715 100644 --- a/misc/window_management/window_management.tscn +++ b/misc/window_management/window_management.tscn @@ -200,7 +200,7 @@ anchors_preset = 11 anchor_left = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -241.0 +offset_left = -310.0 offset_top = 10.0 offset_right = -10.0 offset_bottom = -10.0 diff --git a/mobile/android_iap/iap_demo.gd b/mobile/android_iap/iap_demo.gd index 882e36d4..3fcf0c73 100644 --- a/mobile/android_iap/iap_demo.gd +++ b/mobile/android_iap/iap_demo.gd @@ -6,7 +6,7 @@ const TEST_ITEM_SKU = "my_in_app_purchase_sku" @onready var label: Label = $Label var payment: Object = null -var test_item_purchase_token := "" +var test_item_purchase_token: String = "" func _ready() -> void: diff --git a/mobile/multitouch_cubes/CubeScene.tscn b/mobile/multitouch_cubes/cube_scene.tscn similarity index 100% rename from mobile/multitouch_cubes/CubeScene.tscn rename to mobile/multitouch_cubes/cube_scene.tscn diff --git a/mobile/multitouch_cubes/GestureArea.gd b/mobile/multitouch_cubes/gesture_area.gd similarity index 72% rename from mobile/multitouch_cubes/GestureArea.gd rename to mobile/multitouch_cubes/gesture_area.gd index a057f5a3..8c99f1af 100644 --- a/mobile/multitouch_cubes/GestureArea.gd +++ b/mobile/multitouch_cubes/gesture_area.gd @@ -3,10 +3,10 @@ extends Control @export var target: NodePath @export var min_scale := 0.1 @export var max_scale := 3.0 -@export var one_finger_rot_x := true -@export var one_finger_rot_y := true -@export var two_fingers_rot_z := true -@export var two_fingers_zoom := true +@export var one_finger_rot_x: bool = true +@export var one_finger_rot_y: bool = true +@export var two_fingers_rot_z: bool = true +@export var two_fingers_zoom: bool = true var base_state := {} var curr_state := {} @@ -16,69 +16,70 @@ var base_xform: Transform3D @onready var target_node: Node = get_node(target) -func _gui_input(event: InputEvent) -> void: + +func _gui_input(input_event: InputEvent) -> void: # We must start touching inside, but we can drag or unpress outside. -# if not (event is InputEventScreenDrag or -# (event is InputEventScreenTouch and (not event.pressed or get_global_rect().has_point(event.position)))): +# if not (input_event is InputEventScreenDrag or +# (input_event is InputEventScreenTouch and (not input_event.pressed or get_global_rect().has_point(input_event.position)))): # return var finger_count := base_state.size() if finger_count == 0: # No fingers => Accept press. - if event is InputEventScreenTouch: - if event.pressed: + if input_event is InputEventScreenTouch: + if input_event.pressed: # A finger started touching. base_state = { - event.index: event.position, + input_event.index: input_event.position, } elif finger_count == 1: # One finger => For rotating around X and Y. # Accept one more press, unpress, or drag. - if event is InputEventScreenTouch: - if event.pressed: + if input_event is InputEventScreenTouch: + if input_event.pressed: # One more finger started touching. # Reset the base state to the only current and the new fingers. base_state = { curr_state.keys()[0]: curr_state.values()[0], - event.index: event.position, + input_event.index: input_event.position, } else: - if base_state.has(event.index): + if base_state.has(input_event.index): # Only touching finger released. base_state.clear() - elif event is InputEventScreenDrag: - if curr_state.has(event.index): + elif input_event is InputEventScreenDrag: + if curr_state.has(input_event.index): # Touching finger dragged. - var unit_drag := _px2unit(base_state[base_state.keys()[0]] - event.position) + var unit_drag := _px2unit(base_state[base_state.keys()[0]] - input_event.position) if one_finger_rot_x: target_node.global_rotate(Vector3.UP, deg_to_rad(180.0 * unit_drag.x)) if one_finger_rot_y: target_node.global_rotate(Vector3.RIGHT, deg_to_rad(180.0 * unit_drag.y)) # Since rotating around two axes, we have to reset the base constantly. - curr_state[event.index] = event.position - base_state[event.index] = event.position + curr_state[input_event.index] = input_event.position + base_state[input_event.index] = input_event.position base_xform = target_node.get_transform() elif finger_count == 2: # Two fingers => To pinch-zoom and rotate around Z. # Accept unpress or drag. - if event is InputEventScreenTouch: - if not event.pressed and base_state.has(event.index): + if input_event is InputEventScreenTouch: + if not input_event.pressed and base_state.has(input_event.index): # Some known touching finger released. # Clear the base state base_state.clear() - elif event is InputEventScreenDrag: - if curr_state.has(event.index): + elif input_event is InputEventScreenDrag: + if curr_state.has(input_event.index): # Some known touching finger dragged. - curr_state[event.index] = event.position + curr_state[input_event.index] = input_event.position # Compute base and current inter-finger vectors. var base_segment: Vector3 = base_state[base_state.keys()[0]] - base_state[base_state.keys()[1]] diff --git a/mobile/multitouch_cubes/GestureArea.gd.uid b/mobile/multitouch_cubes/gesture_area.gd.uid similarity index 100% rename from mobile/multitouch_cubes/GestureArea.gd.uid rename to mobile/multitouch_cubes/gesture_area.gd.uid diff --git a/mobile/multitouch_cubes/Main.tscn b/mobile/multitouch_cubes/main.tscn similarity index 98% rename from mobile/multitouch_cubes/Main.tscn rename to mobile/multitouch_cubes/main.tscn index b16a6506..ae09f94f 100644 --- a/mobile/multitouch_cubes/Main.tscn +++ b/mobile/multitouch_cubes/main.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=3 uid="uid://584orsojewxv"] -[ext_resource type="Script" uid="uid://dsefg6y34mer7" path="res://GestureArea.gd" id="1"] -[ext_resource type="PackedScene" uid="uid://cv4h5vfwnpj63" path="res://CubeScene.tscn" id="2"] +[ext_resource type="Script" uid="uid://dsefg6y34mer7" path="res://gesture_area.gd" id="1"] +[ext_resource type="PackedScene" uid="uid://cv4h5vfwnpj63" path="res://cube_scene.tscn" id="2"] [node name="VBoxContainer" type="VBoxContainer"] anchors_preset = 15 diff --git a/mobile/multitouch_cubes/project.godot b/mobile/multitouch_cubes/project.godot index 5f1dfe9b..0689d22a 100644 --- a/mobile/multitouch_cubes/project.godot +++ b/mobile/multitouch_cubes/project.godot @@ -10,10 +10,10 @@ config_version=5 [application] -config/name="Multitouch Cubes Demo " +config/name="Multitouch Cubes Demo" config/description="Demo of multitouch input and different gestures using the touch API. This demo is meant to be used with a touch-enabled device such as a phone or tablet." config/tags=PackedStringArray("demo", "input", "mobile", "official") -run/main_scene="res://Main.tscn" +run/main_scene="res://main.tscn" config/features=PackedStringArray("4.5") config/icon="res://icon.webp" diff --git a/mobile/multitouch_view/Main.gd b/mobile/multitouch_view/main.gd similarity index 99% rename from mobile/multitouch_view/Main.gd rename to mobile/multitouch_view/main.gd index 32979b96..f76e3fb2 100644 --- a/mobile/multitouch_view/Main.gd +++ b/mobile/multitouch_view/main.gd @@ -1,5 +1,6 @@ extends Node2D + func _process(_delta: float) -> void: # Keep redrawing on every frame. queue_redraw() diff --git a/mobile/multitouch_view/Main.gd.uid b/mobile/multitouch_view/main.gd.uid similarity index 100% rename from mobile/multitouch_view/Main.gd.uid rename to mobile/multitouch_view/main.gd.uid diff --git a/mobile/multitouch_view/Main.tscn b/mobile/multitouch_view/main.tscn similarity index 73% rename from mobile/multitouch_view/Main.tscn rename to mobile/multitouch_view/main.tscn index 96530655..d887f36c 100644 --- a/mobile/multitouch_view/Main.tscn +++ b/mobile/multitouch_view/main.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://cdlf0y2e26ru7"] -[ext_resource type="Script" uid="uid://hgkdjcvnp704" path="res://Main.gd" id="1"] +[ext_resource type="Script" uid="uid://hgkdjcvnp704" path="res://main.gd" id="1_ig7tw"] [node name="Main" type="Node2D"] -script = ExtResource("1") +script = ExtResource("1_ig7tw") diff --git a/mobile/multitouch_view/project.godot b/mobile/multitouch_view/project.godot index aff36b70..c616bd16 100644 --- a/mobile/multitouch_view/project.godot +++ b/mobile/multitouch_view/project.godot @@ -13,13 +13,13 @@ config_version=5 config/name="Multitouch View" config/description="Simple debugger for multitouch input. Shows red dots everywhere you press." config/tags=PackedStringArray("demo", "input", "mobile", "official") -run/main_scene="res://Main.tscn" +run/main_scene="res://main.tscn" config/features=PackedStringArray("4.5") config/icon="res://icon.webp" [autoload] -TouchHelper="*res://TouchHelper.gd" +TouchHelper="*res://touch_helper.gd" [debug] diff --git a/mobile/multitouch_view/TouchHelper.gd b/mobile/multitouch_view/touch_helper.gd similarity index 61% rename from mobile/multitouch_view/TouchHelper.gd rename to mobile/multitouch_view/touch_helper.gd index 933fa763..3d1685d0 100644 --- a/mobile/multitouch_view/TouchHelper.gd +++ b/mobile/multitouch_view/touch_helper.gd @@ -1,23 +1,25 @@ -extends Node # This will track the position of every pointer in its public `state` property, which is a # Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2). # It works by listening to input events not handled by other means. # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier. # It can be conveniently setup as a singleton. +extends Node -var state := {} -func _unhandled_input(event: InputEvent) -> void: - if event is InputEventScreenTouch: - if event.pressed: +var state: Dictionary[int, Vector2] = {} + + +func _unhandled_input(input_event: InputEvent) -> void: + if input_event is InputEventScreenTouch: + if input_event.pressed: # Down. - state[event.index] = event.position + state[input_event.index] = input_event.position else: # Up. - state.erase(event.index) + state.erase(input_event.index) get_viewport().set_input_as_handled() - elif event is InputEventScreenDrag: + elif input_event is InputEventScreenDrag: # Movement. - state[event.index] = event.position + state[input_event.index] = input_event.position get_viewport().set_input_as_handled() diff --git a/mobile/multitouch_view/TouchHelper.gd.uid b/mobile/multitouch_view/touch_helper.gd.uid similarity index 100% rename from mobile/multitouch_view/TouchHelper.gd.uid rename to mobile/multitouch_view/touch_helper.gd.uid diff --git a/mobile/sensors/main.gd b/mobile/sensors/main.gd index e4edc90a..cb6f819a 100644 --- a/mobile/sensors/main.gd +++ b/mobile/sensors/main.gd @@ -103,7 +103,7 @@ func _process(delta: float) -> void: var gyro := Input.get_gyroscope() # Show our base values. - var format := "%.05f" + var format: String = "%.05f" %AccX.text = format % acc.x %AccY.text = format % acc.y diff --git a/networking/multiplayer_bomber/gamestate.gd b/networking/multiplayer_bomber/gamestate.gd index 891f9c57..b1143b9f 100644 --- a/networking/multiplayer_bomber/gamestate.gd +++ b/networking/multiplayer_bomber/gamestate.gd @@ -11,7 +11,7 @@ const MAX_PEERS = 12 var peer: ENetMultiplayerPeer ## Our local player's name. -var player_name := "The Warrior" +var player_name: String = "The Warrior" # Names for remote players in id:name format. var players := {} diff --git a/networking/multiplayer_bomber/player.gd b/networking/multiplayer_bomber/player.gd index 9e333d12..7e452d06 100644 --- a/networking/multiplayer_bomber/player.gd +++ b/networking/multiplayer_bomber/player.gd @@ -8,10 +8,10 @@ const BOMB_RATE = 0.5 @export var synced_position := Vector2() -@export var stunned := false +@export var stunned: bool = false var last_bomb_time := BOMB_RATE -var current_anim := "" +var current_anim: String = "" @onready var inputs: Node = $Inputs diff --git a/networking/multiplayer_bomber/player_controls.gd b/networking/multiplayer_bomber/player_controls.gd index f5724d14..c14cd1e7 100644 --- a/networking/multiplayer_bomber/player_controls.gd +++ b/networking/multiplayer_bomber/player_controls.gd @@ -5,7 +5,7 @@ extends Node # This will be sent by players, make sure values are within limits. motion = clamp(value, Vector2(-1, -1), Vector2(1, 1)) -@export var bombing := false +@export var bombing: bool = false func update() -> void: var m := Vector2() diff --git a/networking/multiplayer_bomber/score.gd b/networking/multiplayer_bomber/score.gd index 90ea4cbc..f4c2f3ad 100644 --- a/networking/multiplayer_bomber/score.gd +++ b/networking/multiplayer_bomber/score.gd @@ -5,7 +5,7 @@ var player_labels := {} func _process(_delta: float) -> void: var rocks_left := $"../Rocks".get_child_count() if rocks_left == 0: - var winner_name := "" + var winner_name: String = "" var winner_score := 0 for p: int in player_labels: if player_labels[p].score > winner_score: diff --git a/networking/multiplayer_pong/logic/ball.gd b/networking/multiplayer_pong/logic/ball.gd index 714c2a28..1e4c2db7 100644 --- a/networking/multiplayer_pong/logic/ball.gd +++ b/networking/multiplayer_pong/logic/ball.gd @@ -3,7 +3,7 @@ extends Area2D const DEFAULT_SPEED = 100.0 var direction := Vector2.LEFT -var stopped := false +var stopped: bool = false var _speed := DEFAULT_SPEED @onready var _screen_size := get_viewport_rect().size diff --git a/networking/multiplayer_pong/logic/paddle.gd b/networking/multiplayer_pong/logic/paddle.gd index 622ad781..493ffb34 100644 --- a/networking/multiplayer_pong/logic/paddle.gd +++ b/networking/multiplayer_pong/logic/paddle.gd @@ -2,10 +2,10 @@ extends Area2D const MOTION_SPEED = 150 -@export var left := false +@export var left: bool = false var _motion := 0.0 -var _you_hidden := false +var _you_hidden: bool = false @onready var _screen_size_y := get_viewport_rect().size.y diff --git a/networking/multiplayer_pong/logic/pong.gd b/networking/multiplayer_pong/logic/pong.gd index 988fac91..089acc96 100644 --- a/networking/multiplayer_pong/logic/pong.gd +++ b/networking/multiplayer_pong/logic/pong.gd @@ -36,7 +36,7 @@ func update_score(add_to_left: int) -> void: score_right += 1 score_right_node.set_text(str(score_right)) - var game_ended := false + var game_ended: bool = false if score_left == SCORE_TO_WIN: winner_left.show() game_ended = true diff --git a/networking/webrtc_signaling/client/multiplayer_client.gd b/networking/webrtc_signaling/client/multiplayer_client.gd index 88c8bcbb..48e92279 100644 --- a/networking/webrtc_signaling/client/multiplayer_client.gd +++ b/networking/webrtc_signaling/client/multiplayer_client.gd @@ -1,7 +1,7 @@ extends "ws_webrtc_client.gd" var rtc_mp := WebRTCMultiplayerPeer.new() -var sealed := false +var sealed: bool = false func _init() -> void: connected.connect(_connected) diff --git a/networking/webrtc_signaling/client/ws_webrtc_client.gd b/networking/webrtc_signaling/client/ws_webrtc_client.gd index 4882f26f..bf95e1dc 100644 --- a/networking/webrtc_signaling/client/ws_webrtc_client.gd +++ b/networking/webrtc_signaling/client/ws_webrtc_client.gd @@ -11,13 +11,13 @@ enum Message { SEAL, } -@export var autojoin := true -@export var lobby := "" # Will create a new lobby if empty. -@export var mesh := true # Will use the lobby host as relay otherwise. +@export var autojoin: bool = true +@export var lobby: String = "" # Will create a new lobby if empty. +@export var mesh: bool = true # Will use the lobby host as relay otherwise. var ws := WebSocketPeer.new() var code := 1000 -var reason := "Unknown" +var reason: String = "Unknown" var old_state := WebSocketPeer.STATE_CLOSED signal lobby_joined(lobby: String) diff --git a/networking/webrtc_signaling/server/ws_webrtc_server.gd b/networking/webrtc_signaling/server/ws_webrtc_server.gd index 759c90d8..91a7fd94 100644 --- a/networking/webrtc_signaling/server/ws_webrtc_server.gd +++ b/networking/webrtc_signaling/server/ws_webrtc_server.gd @@ -29,7 +29,7 @@ var peers: Dictionary = {} class Peer extends RefCounted: var id := -1 - var lobby := "" + var lobby: String = "" var time := Time.get_ticks_msec() var ws := WebSocketPeer.new() @@ -54,9 +54,9 @@ class Peer extends RefCounted: class Lobby extends RefCounted: var peers := {} var host := -1 - var sealed := false + var sealed: bool = false var time := 0 # Value is in milliseconds. - var mesh := true + var mesh: bool = true func _init(host_id: int, use_mesh: bool) -> void: host = host_id @@ -83,7 +83,7 @@ class Lobby extends RefCounted: return false peers.erase(peer.id) - var close := false + var close: bool = false if peer.id == host: # The room host disconnected, will disconnect all peers. close = true diff --git a/networking/websocket_chat/websocket/WebSocketServer.gd b/networking/websocket_chat/websocket/WebSocketServer.gd index 2cee494d..41f32eb1 100644 --- a/networking/websocket_chat/websocket/WebSocketServer.gd +++ b/networking/websocket_chat/websocket/WebSocketServer.gd @@ -8,10 +8,10 @@ signal client_disconnected(peer_id: int) @export var handshake_headers := PackedStringArray() @export var supported_protocols := PackedStringArray() @export var handshake_timout := 3000 -@export var use_tls := false +@export var use_tls: bool = false @export var tls_cert: X509Certificate @export var tls_key: CryptoKey -@export var refuse_new_connections := false: +@export var refuse_new_connections: bool = false: set(refuse): if refuse: pending_peers.clear() diff --git a/networking/websocket_minimal/client.gd b/networking/websocket_minimal/client.gd index 5f67ebf7..e098c22a 100644 --- a/networking/websocket_minimal/client.gd +++ b/networking/websocket_minimal/client.gd @@ -1,12 +1,12 @@ extends Node ## The URL we will connect to. -var websocket_url := "ws://localhost:9080" +var websocket_url: String = "ws://localhost:9080" var socket := WebSocketPeer.new() func log_message(message: String) -> void: - var time := "[color=#aaaaaa] %s |[/color] " % Time.get_time_string_from_system() + var time: String = "[color=#aaaaaa] %s |[/color] " % Time.get_time_string_from_system() %TextClient.text += time + message + "\n" diff --git a/networking/websocket_minimal/server.gd b/networking/websocket_minimal/server.gd index 9f019df0..90df2032 100644 --- a/networking/websocket_minimal/server.gd +++ b/networking/websocket_minimal/server.gd @@ -7,7 +7,7 @@ var tcp_server := TCPServer.new() var socket := WebSocketPeer.new() func log_message(message: String) -> void: - var time := "[color=#aaaaaa] %s |[/color] " % Time.get_time_string_from_system() + var time: String = "[color=#aaaaaa] %s |[/color] " % Time.get_time_string_from_system() %TextServer.text += time + message + "\n" diff --git a/viewport/3d_scaling/hud.gd b/viewport/3d_scaling/hud.gd index 5a5b90d9..52618d55 100644 --- a/viewport/3d_scaling/hud.gd +++ b/viewport/3d_scaling/hud.gd @@ -3,7 +3,7 @@ extends Control ## The 3D viewport's shrink factor. For instance, 1 is full resolution, ## 2 is half resolution and 4 is quarter resolution. Lower values look ## sharper but are slower to render. -var scale_factor := 1 +var scale_factor: int = 1 var filter_mode := Viewport.SCALING_3D_MODE_BILINEAR @@ -16,13 +16,13 @@ func _ready() -> void: viewport.scaling_3d_mode = filter_mode -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"cycle_viewport_resolution"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"cycle_viewport_resolution"): scale_factor = wrapi(scale_factor + 1, 1, 5) viewport.scaling_3d_scale = 1.0 / scale_factor scale_label.text = "Scale: %3.0f%%" % (100.0 / scale_factor) - if event.is_action_pressed(&"toggle_filtering"): + if input_event.is_action_pressed(&"toggle_filtering"): filter_mode = wrapi(filter_mode + 1, Viewport.SCALING_3D_MODE_BILINEAR, Viewport.SCALING_3D_MODE_MAX) as Viewport.Scaling3DMode viewport.scaling_3d_mode = filter_mode filter_label.text = ( diff --git a/viewport/dynamic_split_screen/camera_controller.gd b/viewport/dynamic_split_screen/camera_controller.gd index ae330990..0b3c1309 100644 --- a/viewport/dynamic_split_screen/camera_controller.gd +++ b/viewport/dynamic_split_screen/camera_controller.gd @@ -21,7 +21,7 @@ extends Node3D @export var max_separation := 20.0 @export var split_line_thickness := 3.0 @export var split_line_color := Color.BLACK -@export var adaptive_split_line_thickness := true +@export var adaptive_split_line_thickness: bool = true @onready var player1: CharacterBody3D = $"../Player1" @onready var player2: CharacterBody3D = $"../Player2" diff --git a/viewport/gui_in_3d/gui_3d.gd b/viewport/gui_in_3d/gui_3d.gd index ab66f36d..be66af7b 100644 --- a/viewport/gui_in_3d/gui_3d.gd +++ b/viewport/gui_in_3d/gui_3d.gd @@ -1,7 +1,8 @@ extends Node3D + ## Used for checking if the mouse is inside the Area3D. -var is_mouse_inside := false +var is_mouse_inside: bool = false ## The last processed input touch/mouse event. Used to calculate relative movement. var last_event_pos2D := Vector2() @@ -13,6 +14,7 @@ var last_event_time := -1.0 @onready var node_quad: MeshInstance3D = $Quad @onready var node_area: Area3D = $Quad/Area3D + func _ready() -> void: node_area.mouse_entered.connect(_mouse_entered_area) node_area.mouse_exited.connect(_mouse_exited_area) @@ -40,17 +42,17 @@ func _mouse_exited_area() -> void: is_mouse_inside = false -func _unhandled_input(event: InputEvent) -> void: +func _unhandled_input(input_event: InputEvent) -> void: # Check if the event is a non-mouse/non-touch event for mouse_event in [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]: - if is_instance_of(event, mouse_event): + if is_instance_of(input_event, mouse_event): # If the event is a mouse/touch event, then we can ignore it here, because it will be # handled via Physics Picking. return - node_viewport.push_input(event) + node_viewport.push_input(input_event) -func _mouse_input_event(_camera: Camera3D, event: InputEvent, event_position: Vector3, _normal: Vector3, _shape_idx: int) -> void: +func _mouse_input_event(_camera: Camera3D, input_event: InputEvent, event_position: Vector3, _normal: Vector3, _shape_idx: int) -> void: # Get mesh size to detect edges and make conversions. This code only supports PlaneMesh and QuadMesh. var quad_mesh_size: Vector2 = node_quad.mesh.size @@ -90,20 +92,20 @@ func _mouse_input_event(_camera: Camera3D, event: InputEvent, event_position: Ve event_pos2D = last_event_pos2D # Set the event's position and global position. - event.position = event_pos2D - if event is InputEventMouse: - event.global_position = event_pos2D + input_event.position = event_pos2D + if input_event is InputEventMouse: + input_event.global_position = event_pos2D # Calculate the relative event distance. - if event is InputEventMouseMotion or event is InputEventScreenDrag: + if input_event is InputEventMouseMotion or input_event is InputEventScreenDrag: # If there is not a stored previous position, then we'll assume there is no relative motion. if last_event_pos2D == null: - event.relative = Vector2(0, 0) + input_event.relative = Vector2(0, 0) # If there is a stored previous position, then we'll calculate the relative position by subtracting # the previous position from the new position. This will give us the distance the event traveled from prev_pos. else: - event.relative = event_pos2D - last_event_pos2D - event.velocity = event.relative / (now - last_event_time) + input_event.relative = event_pos2D - last_event_pos2D + input_event.velocity = input_event.relative / (now - last_event_time) # Update last_event_pos2D with the position we just calculated. last_event_pos2D = event_pos2D @@ -112,7 +114,7 @@ func _mouse_input_event(_camera: Camera3D, event: InputEvent, event_position: Ve last_event_time = now # Finally, send the processed input event to the viewport. - node_viewport.push_input(event) + node_viewport.push_input(input_event) func rotate_area_to_billboard() -> void: diff --git a/viewport/split_screen_input/player.gd b/viewport/split_screen_input/player.gd index 0ae2a2b5..a85c7a4d 100644 --- a/viewport/split_screen_input/player.gd +++ b/viewport/split_screen_input/player.gd @@ -1,6 +1,7 @@ +## Player implementation. class_name Player extends CharacterBody2D -## Player implementation. + const factor: float = 200.0 # Factor to multiply the movement. @@ -8,17 +9,17 @@ var _movement: Vector2 = Vector2(0, 0) # Current movement rate of node. # Update movement variable based on input that reaches this SubViewport. -func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed(&"ux_up") or event.is_action_released(&"ux_down"): +func _unhandled_input(input_event: InputEvent) -> void: + if input_event.is_action_pressed(&"ux_up") or input_event.is_action_released(&"ux_down"): _movement.y -= 1 get_viewport().set_input_as_handled() - elif event.is_action_pressed(&"ux_down") or event.is_action_released(&"ux_up"): + elif input_event.is_action_pressed(&"ux_down") or input_event.is_action_released(&"ux_up"): _movement.y += 1 get_viewport().set_input_as_handled() - elif event.is_action_pressed(&"ux_left") or event.is_action_released(&"ux_right"): + elif input_event.is_action_pressed(&"ux_left") or input_event.is_action_released(&"ux_right"): _movement.x -= 1 get_viewport().set_input_as_handled() - elif event.is_action_pressed(&"ux_right") or event.is_action_released(&"ux_left"): + elif input_event.is_action_pressed(&"ux_right") or input_event.is_action_released(&"ux_left"): _movement.x += 1 get_viewport().set_input_as_handled() diff --git a/xr/openxr_character_centric_movement/start_vr.gd b/xr/openxr_character_centric_movement/start_vr.gd index c610b4c2..2320772b 100644 --- a/xr/openxr_character_centric_movement/start_vr.gd +++ b/xr/openxr_character_centric_movement/start_vr.gd @@ -7,7 +7,7 @@ signal pose_recentered @export var maximum_refresh_rate : int = 90 var xr_interface : OpenXRInterface -var xr_is_focused := false +var xr_is_focused: bool = false func _ready() -> void: diff --git a/xr/openxr_composition_layers/start_vr.gd b/xr/openxr_composition_layers/start_vr.gd index 3aa78712..2991d916 100644 --- a/xr/openxr_composition_layers/start_vr.gd +++ b/xr/openxr_composition_layers/start_vr.gd @@ -7,7 +7,7 @@ signal pose_recentered @export var maximum_refresh_rate : int = 90 var xr_interface : OpenXRInterface -var xr_is_focused := false +var xr_is_focused: bool = false # Called when the node enters the scene tree for the first time. diff --git a/xr/openxr_hand_tracking_demo/start_vr.gd b/xr/openxr_hand_tracking_demo/start_vr.gd index c610b4c2..2320772b 100644 --- a/xr/openxr_hand_tracking_demo/start_vr.gd +++ b/xr/openxr_hand_tracking_demo/start_vr.gd @@ -7,7 +7,7 @@ signal pose_recentered @export var maximum_refresh_rate : int = 90 var xr_interface : OpenXRInterface -var xr_is_focused := false +var xr_is_focused: bool = false func _ready() -> void: diff --git a/xr/openxr_origin_centric_movement/start_vr.gd b/xr/openxr_origin_centric_movement/start_vr.gd index 02cdc2ca..e2eae38d 100644 --- a/xr/openxr_origin_centric_movement/start_vr.gd +++ b/xr/openxr_origin_centric_movement/start_vr.gd @@ -7,7 +7,7 @@ signal pose_recentered @export var maximum_refresh_rate: int = 90 var xr_interface: OpenXRInterface -var xr_is_focused := false +var xr_is_focused: bool = false func _ready() -> void: diff --git a/xr/openxr_render_models/start_vr.gd b/xr/openxr_render_models/start_vr.gd index c610b4c2..2320772b 100644 --- a/xr/openxr_render_models/start_vr.gd +++ b/xr/openxr_render_models/start_vr.gd @@ -7,7 +7,7 @@ signal pose_recentered @export var maximum_refresh_rate : int = 90 var xr_interface : OpenXRInterface -var xr_is_focused := false +var xr_is_focused: bool = false func _ready() -> void: