From: Eduardo Date: Sun, 18 Feb 2024 01:28:03 +0000 (+0100) Subject: embrace static typing X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=1d83a681bc8f7b91f48b415b99fa008bd5784c16;p=ScaryGame.git embrace static typing --- diff --git a/enemies/base_enemy.gd b/enemies/base_enemy.gd index 4df2b35..a15bc9b 100644 --- a/enemies/base_enemy.gd +++ b/enemies/base_enemy.gd @@ -9,7 +9,7 @@ extends CharacterBody3D @onready var pivot := $Pivot -func _physics_process(delta): +func _physics_process(delta) -> void: var distance_to_player := global_position.distance_to(player.global_position) if player.get_meta("noise") > noise_threshold: @@ -31,7 +31,7 @@ func _physics_process(delta): rotate_y(deg_to_rad(pivot.rotation.y * turn_speed)) -func can_see_player(): +func can_see_player() -> bool: var space_state = get_world_3d().get_direct_space_state() var params = PhysicsRayQueryParameters3D.new() params.from = global_transform.origin + Vector3.UP diff --git a/levels/ui.gd b/levels/ui.gd index 2a6eb66..db4653a 100644 --- a/levels/ui.gd +++ b/levels/ui.gd @@ -20,7 +20,7 @@ func _ready() -> void: player.connect("recharge_battery", _on_recharge_battery_command) -func _on_object_detected(ob: Object): +func _on_object_detected(ob: Object) -> void: if !ob: actionTextLabel.set_text("") @@ -37,19 +37,19 @@ func _on_object_detected(ob: Object): actionTextLabel.set_text(ob.name) -func _on_recharge_battery_command(): +func _on_recharge_battery_command() -> void: battery = 100 batteryLabel.set_text(format_battery_text(battery)) # each 1 seconds -func _on_timer_1_timeout(): +func _on_timer_1_timeout() -> void: battery = set_battery_percentage(battery) batteryLabel.set_text(format_battery_text(battery)) # each 0.25 seconds -func _on_timer_0_25_timeout(): +func _on_timer_0_25_timeout() -> void: timeLabel.set_text(set_rand_timer(timeLabel.get_text())) diff --git a/menus/main_menu/MainMenu.gd b/menus/main_menu/MainMenu.gd index e08984f..8701158 100644 --- a/menus/main_menu/MainMenu.gd +++ b/menus/main_menu/MainMenu.gd @@ -1,32 +1,33 @@ extends Control -@export var playBtnSscene : String -@export var settingsBtnScene : String -@export var creditsBtnScene : String +@export var playBtnSscene: String +@export var settingsBtnScene: String +@export var creditsBtnScene: String @onready var fade_out_options = SceneManager.create_options() @onready var fade_in_options = SceneManager.create_options() @onready var general_options = SceneManager.create_general_options() + # Called when the node enters the scene tree for the first time. -func _ready(): +func _ready() -> void: SceneManager.process_mode = Node.PROCESS_MODE_ALWAYS SceneManager.validate_scene(playBtnSscene) SceneManager.validate_scene(settingsBtnScene) SceneManager.validate_scene(creditsBtnScene) -func _on_play_button_pressed(): +func _on_play_button_pressed() -> void: SceneManager.change_scene(playBtnSscene, fade_out_options, fade_in_options, general_options) -func _on_settings_button_pressed(): +func _on_settings_button_pressed() -> void: SceneManager.change_scene(settingsBtnScene, fade_out_options, fade_in_options, general_options) -func _on_credits_button_pressed(): +func _on_credits_button_pressed() -> void: SceneManager.change_scene(creditsBtnScene, fade_out_options, fade_in_options, general_options) -func _on_exit_button_pressed(): +func _on_exit_button_pressed() -> void: get_tree().quit() diff --git a/menus/pause/Pause.gd b/menus/pause/Pause.gd index ff44267..8d820cc 100644 --- a/menus/pause/Pause.gd +++ b/menus/pause/Pause.gd @@ -1,18 +1,19 @@ extends Control -@export var settingsBtnScene : String -@export var exitBtnScene : String +@export var settingsBtnScene: String +@export var exitBtnScene: String @onready var fade_out_options = SceneManager.create_options() @onready var fade_in_options = SceneManager.create_options() @onready var general_options = SceneManager.create_general_options() -func _init(): + +func _init() -> void: SceneManager.validate_scene(settingsBtnScene) SceneManager.validate_scene(exitBtnScene) -func _input(event): +func _input(event) -> void: if event.is_action_pressed("ui_cancel"): print(get_tree().paused) if not get_tree().paused: @@ -21,22 +22,22 @@ func _input(event): unpause() -func _on_unpause_button_pressed(): +func _on_unpause_button_pressed() -> void: unpause() -func _on_exit_button_pressed(): +func _on_exit_button_pressed() -> void: get_tree().paused = false SceneManager.change_scene(exitBtnScene, fade_out_options, fade_in_options, general_options) -func pause(): +func pause() -> void: get_tree().paused = true Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) show() -func unpause(): +func unpause() -> void: hide() Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) get_tree().paused = false diff --git a/player/Camera3D.gd b/player/Camera3D.gd index bbafc3f..8a39c16 100644 --- a/player/Camera3D.gd +++ b/player/Camera3D.gd @@ -16,14 +16,14 @@ var pitch: float = 0.0 # Called when the node enters the scene tree for the first time. -func _ready(): +func _ready() -> void: yaw = 0.0 pitch = 0.0 Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) -func _input(event): +func _input(event) -> void: # release the mouse on esc if event.is_action_pressed("ui_cancel"): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) @@ -49,7 +49,7 @@ func _input(event): # Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): +func _process(delta) -> void: if Input.is_action_pressed("ui_up"): translate(position - global_basis * Vector3(0, 0, 1) * delta * flyspeed * .01) if Input.is_action_pressed("ui_down"): @@ -62,7 +62,7 @@ func _process(delta): change_object_detected_status(ray.get_collider()) -func change_object_detected_status(ob: Object): +func change_object_detected_status(ob: Object) -> void: var new_object_status := false if ob: # is not null new_object_status = true diff --git a/player/Player.gd b/player/Player.gd index 8d93bd6..3967dae 100644 --- a/player/Player.gd +++ b/player/Player.gd @@ -33,7 +33,7 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. -func _physics_process(delta): +func _physics_process(delta) -> void: var direction := Vector3.ZERO var speed_mod: float = 1 var noise_mod: float = 1 @@ -96,12 +96,12 @@ func _physics_process(delta): # each second -func _on_timer_timeout(): +func _on_timer_timeout() -> void: noise = clamp(noise - 1, 0, 9) set_meta("noise", noise) print(noise) # whenever the detection changes it emits an object (or null if nothing detected) -func _on_object_detected(ob: Object): +func _on_object_detected(ob: Object) -> void: object_detected = ob