From c9d6e384a9c9837d4951d0d169e881511a88b3c0 Mon Sep 17 00:00:00 2001 From: Martin Beaussart Date: Thu, 30 Oct 2025 22:23:51 +0100 Subject: [PATCH] Add type hints to sample project scripts --- SampleProject/Game.tscn | 6 +++--- SampleProject/Maps/DiceRoom.tscn | 2 +- SampleProject/Maps/Junction.tscn | 2 +- SampleProject/Maps/LeftStaircase.tscn | 2 +- SampleProject/Objects/CollectionGridItem.tscn | 2 +- SampleProject/Objects/Elevator.tscn | 2 +- SampleProject/Objects/MiniPortal.tscn | 2 +- SampleProject/Objects/Pipe.tscn | 2 +- SampleProject/Scripts/CustomElements.gd | 4 ++-- SampleProject/Scripts/Game.gd | 6 +++--- SampleProject/Scripts/Player.gd | 6 +++--- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/SampleProject/Game.tscn b/SampleProject/Game.tscn index 0966e64..2e509c1 100644 --- a/SampleProject/Game.tscn +++ b/SampleProject/Game.tscn @@ -96,7 +96,7 @@ func _input(event: InputEvent) -> void: top_draw.queue_redraw() # Assigns the initial offset when the map is opened. It centers on the player position. -func update_offset(): +func update_offset() -> void: offset = MetSys.get_current_flat_coords() - SIZE / 2 # Player position node needs to be moved accordingly. player_location.offset = -Vector2(offset) * MetSys.CELL_SIZE @@ -105,7 +105,7 @@ func update_offset(): # Update all cells of MapView to reflect the current state. map_view.update_all() -func reset_starting_coords(): +func reset_starting_coords() -> void: # Starting position for the delta vector. var coords := MetSys.get_current_flat_coords() starting_coords = Vector2i(coords.x, coords.y) @@ -126,7 +126,7 @@ func _notification(what: int) -> void: if what == NOTIFICATION_VISIBILITY_CHANGED: update() -func update(): +func update() -> void: # Only update when visible. if is_visible_in_tree(): # Show the percentage. diff --git a/SampleProject/Maps/DiceRoom.tscn b/SampleProject/Maps/DiceRoom.tscn index 90bad68..4435e0f 100644 --- a/SampleProject/Maps/DiceRoom.tscn +++ b/SampleProject/Maps/DiceRoom.tscn @@ -53,7 +53,7 @@ func _on_body_entered(body: Node2D) -> void: %Gate.enabled = false # The thread method for generating maps. The algorithm is simple: pick random cell and direction and make an adjacent cell if it doesn't exist. -func generate_map(): +func generate_map() -> void: # Gets rid of errors. This method is thread-safe, trust me. Thread.set_thread_safety_checks_enabled(false) # The grid of generated cells. The key is cell coordinates relative to the first generated cell, the value is a bitmask of exits. diff --git a/SampleProject/Maps/Junction.tscn b/SampleProject/Maps/Junction.tscn index 93bee03..b1057e1 100644 --- a/SampleProject/Maps/Junction.tscn +++ b/SampleProject/Maps/Junction.tscn @@ -12,7 +12,7 @@ var exits: int var has_collectible: bool # Remove the walls and collectible, based on the config values. -func apply_config(): +func apply_config() -> void: for i in 4: %TileMap.get_child(i + 2).enabled = not bool(exits & 1 << i) diff --git a/SampleProject/Maps/LeftStaircase.tscn b/SampleProject/Maps/LeftStaircase.tscn index 2d58c88..dc73d25 100644 --- a/SampleProject/Maps/LeftStaircase.tscn +++ b/SampleProject/Maps/LeftStaircase.tscn @@ -12,7 +12,7 @@ extends Node # Gate layer index. @export var layer: int -func open(): +func open() -> void: # Disable the Gate layer. %Gate.enabled = false " diff --git a/SampleProject/Objects/CollectionGridItem.tscn b/SampleProject/Objects/CollectionGridItem.tscn index 83ac229..81da5ed 100644 --- a/SampleProject/Objects/CollectionGridItem.tscn +++ b/SampleProject/Objects/CollectionGridItem.tscn @@ -6,7 +6,7 @@ script/source = "extends TextureRect # ID of the tracked object. @export var id: String -func update_collectible(): +func update_collectible() -> void: # Become visible if the tracked object was stored (collected). self_modulate.a = float(MetSys.is_object_id_stored(id)) " diff --git a/SampleProject/Objects/Elevator.tscn b/SampleProject/Objects/Elevator.tscn index ff52a7d..341baee 100644 --- a/SampleProject/Objects/Elevator.tscn +++ b/SampleProject/Objects/Elevator.tscn @@ -60,7 +60,7 @@ func _physics_process(delta: float) -> void: $Label.hide() # Called after being transported to the target room. -func enter(): +func enter() -> void: # Set initial position of the elevator. if up: position.y = -64 diff --git a/SampleProject/Objects/MiniPortal.tscn b/SampleProject/Objects/MiniPortal.tscn index a9f9035..388e1a8 100644 --- a/SampleProject/Objects/MiniPortal.tscn +++ b/SampleProject/Objects/MiniPortal.tscn @@ -18,7 +18,7 @@ func _on_body_entered(body: Node2D) -> void: Game.get_singleton().load_room(target_map) # Needs to be static, because the old portal disappears before the new scene is loaded. -static func move_to_portal(): +static func move_to_portal() -> void: var map := Game.get_singleton().map # Get the portal node. var portal: Node2D = map.get_node(^\"MiniPortal\") diff --git a/SampleProject/Objects/Pipe.tscn b/SampleProject/Objects/Pipe.tscn index 47ab5ae..e7602dd 100644 --- a/SampleProject/Objects/Pipe.tscn +++ b/SampleProject/Objects/Pipe.tscn @@ -20,7 +20,7 @@ func _ready() -> void: add_point(current_point) set_process(false) # Manually progresses the water (used to initialize pipes). -func flow(delta: float): +func flow(delta: float) -> void: _process(delta / FLOW_SPEED) func _process(delta: float) -> void: diff --git a/SampleProject/Scripts/CustomElements.gd b/SampleProject/Scripts/CustomElements.gd index 2113895..67087d0 100644 --- a/SampleProject/Scripts/CustomElements.gd +++ b/SampleProject/Scripts/CustomElements.gd @@ -8,7 +8,7 @@ func _init() -> void: # Some text that displays on the map. register_element("label", draw_label) -func draw_elevator(canvas_item: RID, coords: Vector3i, pos: Vector2, size: Vector2, data: String): +func draw_elevator(canvas_item: RID, coords: Vector3i, pos: Vector2, size: Vector2, data: String) -> void: # For elevator to display, both top and bottom cell must be discovered. if not MetSys.is_cell_discovered(coords + Vector3i(0, -1, 0)) and not MetSys.is_cell_discovered(coords + Vector3i(0, size.y, 0)): return @@ -19,7 +19,7 @@ func draw_elevator(canvas_item: RID, coords: Vector3i, pos: Vector2, size: Vecto pos + Vector2(MetSys.CELL_SIZE.x * 0.5 - elevator_texture.get_width() * 0.5, 0), Vector2(elevator_texture.get_width(), size.y)), true, MetSys.settings.theme.default_border_color) -func draw_label(canvas_item: RID, coords: Vector3i, pos: Vector2, size: Vector2, data: String): +func draw_label(canvas_item: RID, coords: Vector3i, pos: Vector2, size: Vector2, data: String) -> void: # The label is only visible if it's cell is discovered. if not MetSys.is_cell_discovered(coords): return diff --git a/SampleProject/Scripts/Game.gd b/SampleProject/Scripts/Game.gd index d567112..b5ab857 100644 --- a/SampleProject/Scripts/Game.gd +++ b/SampleProject/Scripts/Game.gd @@ -75,7 +75,7 @@ static func get_singleton() -> Game: return (Game as Script).get_meta(&"singleton") as Game # Save game using MetSys SaveManager. -func save_game(): +func save_game() -> void: var save_manager := SaveManager.new() save_manager.set_value("collectible_count", collectibles) save_manager.set_value("generated_rooms", generated_rooms) @@ -84,10 +84,10 @@ func save_game(): save_manager.set_value("abilities", player.abilities) save_manager.save_as_text(SAVE_PATH) -func reset_map_starting_coords(): +func reset_map_starting_coords() -> void: $UI/MapWindow.reset_starting_coords() -func init_room(): +func init_room() -> void: MetSys.get_current_room_instance().adjust_camera_limits($Player/Camera2D) player.on_enter() diff --git a/SampleProject/Scripts/Player.gd b/SampleProject/Scripts/Player.gd index ab48075..8783e01 100644 --- a/SampleProject/Scripts/Player.gd +++ b/SampleProject/Scripts/Player.gd @@ -66,7 +66,7 @@ func _physics_process(delta: float) -> void: prev_on_floor = is_on_floor() move_and_slide() - var new_animation = &"Idle" + var new_animation := &"Idle" if velocity.y < 0: new_animation = &"Jump" elif velocity.y >= 0 and not is_on_floor(): @@ -83,11 +83,11 @@ func _physics_process(delta: float) -> void: elif velocity.x < -1: $Sprite2D.flip_h = true -func kill(): +func kill() -> void: # Player dies, reset the position to the entrance. position = reset_position Game.get_singleton().load_room(MetSys.get_current_room_id()) -func on_enter(): +func on_enter() -> void: # Position for kill system. Assigned when entering new room (see Game.gd). reset_position = position