Skip to content

Commit 6f5a943

Browse files
committed
docs: clean up docstrings
1 parent 1fbe02c commit 6f5a943

File tree

5 files changed

+69
-59
lines changed

5 files changed

+69
-59
lines changed

src/field/gameboard/gameboard.gd

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Defines the playable area of the game and where everything on it lies.
22
##
33
## The gameboard is defined, essentially, as a grid of [Vector2i] cells. Anything may be
4-
## placed on one of these cells, so the gameboard determines where each cell is located. In this
4+
## placed on one of these cells, so the gameboard determines where each cell is located. In this
55
## case, we are using a simple orthographic (square) projection.
66
## [br][br]The grid is contained within the playable [member boundaries] and its constituent cells.
77
extends Node
@@ -12,12 +12,13 @@ signal properties_set
1212

1313
## Emitted whenever the [member pathfinder] state changes.
1414
## This signal is emitted automatically in response to changed [GameboardLayer]s.
15-
##[/br][/br]Note: This signal is only emitted when the actual movement state of the Gameboard
15+
##
16+
## Note: This signal is only emitted when the actual movement state of the Gameboard
1617
## changes. [GameboardLayer]s may change their cells without actually changing the pathfinder's
1718
## state (i.e. a visual update only), in which case this signal is not emitted.
1819
signal pathfinder_changed(added_cells: Array[Vector2i], removed_cells: Array[Vector2i])
1920

20-
## An invalid cell is not part of the gameboard. Note that this requires positive
21+
## An invalid cell is not part of the gameboard. Note that this requires positive
2122
## [member boundaries].
2223
const INVALID_CELL: = Vector2i(-1, -1)
2324

@@ -43,7 +44,7 @@ func cell_to_pixel(cell_coordinates: Vector2i) -> Vector2:
4344
func pixel_to_cell(pixel_coordinates: Vector2) -> Vector2i:
4445
@warning_ignore("integer_division")
4546
return Vector2i(
46-
floori(pixel_coordinates.x / properties.cell_size.x),
47+
floori(pixel_coordinates.x / properties.cell_size.x),
4748
floori(pixel_coordinates.y / properties.cell_size.y)
4849
)
4950

@@ -73,9 +74,9 @@ func index_to_cell(index: int) -> Vector2i:
7374
index % properties.extents.size.x + properties.extents.position.x,
7475
index / properties.extents.size.x + properties.extents.position.y
7576
)
76-
77+
7778
if properties.extents.has_point(cell):
78-
return cell
79+
return cell
7980
return INVALID_CELL
8081

8182

@@ -94,7 +95,7 @@ func get_adjacent_cells(cell: Vector2i) -> Array[Vector2i]:
9495
var neighbour = get_adjacent_cell(cell, direction)
9596
if not neighbour == INVALID_CELL and not neighbour == cell:
9697
neighbours.append(neighbour)
97-
98+
9899
return neighbours
99100

100101

@@ -107,13 +108,13 @@ func register_gameboard_layer(board_map: GameboardLayer) -> void:
107108
# Compare the changed cells with those already in the pathfinder. Any changes will cause the
108109
# Pathfinder to be updated.
109110
board_map.cells_changed.connect(
110-
func _on_gameboard_layer_cells_changed(cleared_cells: Array[Vector2i],
111+
func _on_gameboard_layer_cells_changed(cleared_cells: Array[Vector2i],
111112
blocked_cells: Array[Vector2i]):
112113
if board_map.name == "DoorGameboardLayer":
113114
print("Door layer ", cleared_cells, " ", blocked_cells)
114115
var added_cells: = _add_cells_to_pathfinder(cleared_cells)
115116
var removed_cells: = _remove_cells_from_pathfinder(blocked_cells)
116-
117+
117118
_connect_new_pathfinder_cells(added_cells)
118119
if not added_cells.is_empty() or not removed_cells.is_empty():
119120
pathfinder_changed.emit(added_cells.values(), removed_cells)
@@ -125,7 +126,7 @@ func register_gameboard_layer(board_map: GameboardLayer) -> void:
125126
# from cleared_cells). Key = cell id (int, see cell_to_index), value = coordinate (Vector2i)
126127
func _add_cells_to_pathfinder(cleared_cells: Array[Vector2i]) -> Dictionary[int, Vector2i]:
127128
var added_cells: Dictionary[int, Vector2i] = {}
128-
129+
129130
# Verify whether or not cleared/blocked cells will change the state of the pathfinder.
130131
# If there is no change in state, we will not pass along the cell to other systems and
131132
# the pathfinder won't actually be changed.
@@ -136,15 +137,15 @@ func _add_cells_to_pathfinder(cleared_cells: Array[Vector2i]) -> Dictionary[int,
136137
var uid: = cell_to_index(cell)
137138
pathfinder.add_point(uid, cell)
138139
added_cells[uid] = cell
139-
140+
140141
# Flag the cell as disabled if it is occupied.
141142
if GamepieceRegistry.get_gamepiece(cell):
142143
pathfinder.set_point_disabled(uid)
143144
return added_cells
144145

145146

146-
# Remove cells from the pathfinder so that Gamepieces can no longer move through them.
147-
# Only one Gameboard layer needs to block a cell for it to be considered blocked.
147+
# Remove cells from the pathfinder so that Gamepieces can no longer move through them.
148+
# Only one Gameboard layer needs to block a cell for it to be considered blocked.
148149
# Returns an array of cell coordinates that have been blocked. Cells that were already not in the
149150
# pathfinder will be excluded from this array.
150151
func _remove_cells_from_pathfinder(blocked_cells: Array[Vector2i]) -> Array[Vector2i]:
@@ -170,23 +171,25 @@ func _connect_new_pathfinder_cells(added_cells: Dictionary[int, Vector2i]) -> vo
170171
pathfinder.connect_points(uid, neighbor_id)
171172

172173

173-
# Checks all [TileMapLayers] in the [constant GameboardLayer.GROUP] to see if the cell is clear
174-
# (returns true) or blocked (returns false).
175-
# [/br][/br]A clear cell must fulfill two criteria:
176-
# [/br]- Exists in at least one of the [GameboardLayer]s.
177-
# [/br]- None of the layers block movement at this cell, as defined by the
178-
# [constant GameboardLayer.BLOCKED_CELL_DATA_LAYER] custom data layer (see
179-
# [method TileData.get_custom_data])
174+
## Checks all [TileMapLayers] in the [constant GameboardLayer.GROUP] to see if the cell is clear
175+
## (returns true) or blocked (returns false).
176+
##
177+
## A clear cell must fulfill two criteria:
178+
##
179+
## - Exists in at least one of the [GameboardLayer]s.[br]
180+
## - None of the layers block movement at this cell, as defined by the
181+
## [constant GameboardLayer.BLOCKED_CELL_DATA_LAYER] custom data layer (see
182+
## [method TileData.get_custom_data])
180183
func _is_cell_clear(coord: Vector2i) -> bool:
181184
# Check to make sure that cell exists.
182185
var cell_exists: = false
183-
186+
184187
for tilemap: GameboardLayer in get_tree().get_nodes_in_group(GameboardLayer.GROUP):
185188
if tilemap and coord in tilemap.get_used_cells():
186189
cell_exists = true
187190
if not tilemap.is_cell_clear(coord):
188191
return false
189-
192+
190193
# There is no terrain blocking cell movement. However we only want to allow movement if the cell
191194
# actually exists in one of the tilemap layers.
192195
return cell_exists

src/field/gameboard/gameboard_layer.gd

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
## Comes setup with a few tools used by designers to setup maps, specifying which cells may be
44
## moved to or from. Multiple GameboardLayers may exist simultaneously to allow developers to
55
## affect the gameboard with more than one layer.
6-
##[/br][/br] These collision layers may also dynamically change, with the changes being reflected
6+
##
7+
## These collision layers may also dynamically change, with the changes being reflected
78
## by the gameboard and pathfinder.
89
class_name GameboardLayer extends TileMapLayer
910

1011
## Emitted whenever the collision state of the tile map changes.
11-
##[/br][/br] The GameboardLayer's tile map may change without changing which cells are blocked or
12+
##
13+
## The GameboardLayer's tile map may change without changing which cells are blocked or
1214
## are open for movement. In this case, the signal is not emitted. However, it is emitted whenever
1315
## the map is added or removed from the game, in addition to when there is a change in blocked/clear
1416
## cells.
@@ -19,7 +21,8 @@ const GROUP: = "GameboardTileMapLayers"
1921

2022
## The name of the "custom data layer" that determines whether or not a cell is blocked/walkable.
2123
## The returned value will be a boolean reflecting if a cell is blocked or not. Fetches the value
22-
## via [method TileData.get_custom_data].[/br][/br]
24+
## via [method TileData.get_custom_data].
25+
##
2326
## If the data layer is not present in the [Tileset], then all cells in this [TileMapLayer] will,
2427
## by default, block movement.
2528
const BLOCKED_CELL_DATA_LAYER: = "IsCellBlocked"
@@ -32,11 +35,11 @@ var _affects_collision: = true
3235
func _ready() -> void:
3336
add_to_group(GROUP)
3437
Gameboard.register_gameboard_layer(self)
35-
38+
3639
tree_exiting.connect(
3740
func _on_tree_exiting() -> void:
3841
_affects_collision = false
39-
42+
4043
var blocked_cells: Array[Vector2i] = []
4144
cells_changed.emit(get_used_cells(), blocked_cells)
4245
)
@@ -53,7 +56,7 @@ func is_cell_clear(coord: Vector2i) -> bool:
5356
if tile_data:
5457
var is_cell_blocked: = tile_data.get_custom_data(BLOCKED_CELL_DATA_LAYER) as bool
5558
return not is_cell_blocked
56-
59+
5760
# If the above conditions have not been met, the cell is blocked.
5861
return false
5962

@@ -70,18 +73,18 @@ func _update_cells(coords: Array[Vector2i], forced_cleanup: bool) -> void:
7073
# layer that we need to specify whether or not a tile blocks movement.
7174
if not tile_set or not tile_set.has_custom_data_layer_by_name(BLOCKED_CELL_DATA_LAYER):
7275
return
73-
76+
7477
# Go through the specified coords, checking to see if any moveable cells (those that are NOT
7578
# blocked) have been added or removed.
7679
var cleared_cells: Array[Vector2i] = []
7780
var blocked_cells: Array[Vector2i] = []
78-
81+
7982
if not forced_cleanup:
8083
for coord in coords:
8184
if is_cell_clear(coord):
8285
cleared_cells.append(coord)
8386
else:
8487
blocked_cells.append(coord)
85-
88+
8689
if not (cleared_cells.is_empty() and blocked_cells.is_empty()):
8790
cells_changed.emit(cleared_cells, blocked_cells)

src/field/gameboard/pathfinder.gd

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
class_name Pathfinder
55
extends AStar2D
66

7-
# When finding a path, we may want to ignore certain cells that are occupied by Gamepeices.
8-
# These flags specify which disabled cells will still allow the path through.
9-
## Ignore the pccupant of the source cell when searching for a path via [method path_to_cell].
7+
## When finding a path, we may want to ignore certain cells that are occupied by Gamepeices.
8+
## These flags specify which disabled cells will still allow the path through.
9+
##
10+
## Ignore the occupant of the source cell when searching for a path via [method path_to_cell].
1011
## This is especially useful when wanting to find a path for a gamepiece from their current cell.
1112
const FLAG_ALLOW_SOURCE_OCCUPANT = 1 << 0
1213
## Ignore the occupant of the target cell when searching for a path via [method path_to_cell].
@@ -23,12 +24,12 @@ func _init() -> void:
2324
var new_cell_id: = Gameboard.cell_to_index(new_cell)
2425
if has_point(new_cell_id):
2526
set_point_disabled(new_cell_id, true)
26-
27+
2728
var old_cell_id: = Gameboard.cell_to_index(old_cell)
2829
if has_point(old_cell_id):
2930
set_point_disabled(old_cell_id, false)
3031
)
31-
32+
3233
GamepieceRegistry.gamepiece_freed.connect(
3334
func _on_gamepiece_free(_gp: Gamepiece, coord: Vector2i) -> void:
3435
var cell_id: = Gameboard.cell_to_index(coord)
@@ -51,15 +52,15 @@ func can_move_to(coord: Vector2i) -> bool:
5152
## Find a path between two cells. Returns an empty array if no path is available.
5253
## If allow_blocked_source or allow_blocked_target are false, the pathinder wlil fail if a gamepiece
5354
## occupies the source or target cells, respectively.
54-
func get_path_to_cell(source_coord: Vector2i, target_coord: Vector2i,
55+
func get_path_to_cell(source_coord: Vector2i, target_coord: Vector2i,
5556
occupancy_flags: int = 1) -> Array[Vector2i]:
5657
# Store the return value in a variable.
5758
var move_path: Array[Vector2i] = []
58-
59+
5960
# Find the source/target IDs and keep track of whether or not the cells are occupied.
6061
var source_id: = Gameboard.cell_to_index(source_coord)
6162
var target_id: = Gameboard.cell_to_index(target_coord)
62-
63+
6364
# The pathfinder has several flags to ignore cell occupancy. We'll need to track which occupants
6465
# are temporarily ignored and then re-disable their pathfinder points once a path is found.
6566
# Key is point id, value is whether or not the point is disabled.
@@ -69,7 +70,7 @@ func get_path_to_cell(source_coord: Vector2i, target_coord: Vector2i,
6970
if is_point_disabled(id):
7071
ignored_points[id] = true
7172
set_point_disabled(id, false)
72-
73+
7374
if has_point(source_id) and has_point(target_id):
7475
# Check to see if we want to un-disable the source/target cells.
7576
if (occupancy_flags & FLAG_ALLOW_SOURCE_OCCUPANT) != 0:
@@ -78,15 +79,15 @@ func get_path_to_cell(source_coord: Vector2i, target_coord: Vector2i,
7879
if (occupancy_flags & FLAG_ALLOW_TARGET_OCCUPANT) != 0:
7980
ignored_points[target_id] = is_point_disabled(target_id)
8081
set_point_disabled(target_id, false)
81-
82+
8283
for path_coord: Vector2i in get_point_path(source_id, target_id):
8384
if path_coord != source_coord: # Don't include the source as the first path element.
8485
move_path.append(path_coord)
85-
86+
8687
# Change any enabled cells back to their previous state.
8788
for id in ignored_points:
8889
set_point_disabled(id, ignored_points[id])
89-
90+
9091
return move_path
9192

9293

@@ -96,13 +97,13 @@ func get_path_cells_to_adjacent_cell(source_coord: Vector2i,
9697
target_coord: Vector2i, occupancy_flags: int = 1) -> Array[Vector2i]:
9798
var shortest_path: Array[Vector2i] = []
9899
var shortest_path_length: = INF
99-
100+
100101
for cell in Gameboard.get_adjacent_cells(target_coord):
101102
var cell_path: = get_path_to_cell(source_coord, cell, occupancy_flags)
102103
if not cell_path.is_empty() and cell_path.size() < shortest_path_length:
103104
shortest_path_length = cell_path.size()
104105
shortest_path = cell_path
105-
106+
106107
return shortest_path
107108

108109

@@ -111,10 +112,10 @@ func _to_string() -> String:
111112
var value: = "\nPathfinder:"
112113
for index in get_point_ids():
113114
var cell_header: = "\n%s - Id: %d;" % [str(Gameboard.index_to_cell(index)), index]
114-
115+
115116
var is_disabled: = "\t\t\t"
116117
if is_point_disabled(index):
117118
is_disabled = " (disabled)\t"
118-
119+
119120
value += (cell_header + is_disabled + "Linked to: %s" % get_point_connections(index))
120121
return value + "\n"

src/field/gamepieces/gamepiece.gd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ signal direction_changed(new_direction: Directions.Points)
5252
follower.add_child(animation)
5353

5454
## The gamepiece will traverse a movement path at [code]move_speed[/code] pixels per second.
55-
##[/br][/br]Note that extremely high speeds (finish a long path in a single frame) will produce
55+
##
56+
## Note that extremely high speeds (finish a long path in a single frame) will produce
5657
## unexpected results.
5758
@export var move_speed: = 64.0
5859

@@ -88,7 +89,8 @@ var destination: Vector2
8889

8990
## Node2Ds may want to follow the gamepiece's animation, rather than position (which updates only at
9091
## the end of a path). Nodes may follow a travelling gamepiece by receiving the path follower's
91-
## transform.[/br][/br]
92+
## transform.
93+
##
9294
## The [member RemoteTransform2D.remote_path] is reserved for the player camera, but other nodes
9395
## may access the anchor's position directly.
9496
@onready var animation_transform: = $PathFollow2D/CameraAnchor as RemoteTransform2D

src/field/gamepieces/gamepiece_registry.gd

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## Since player movement is locked to gameboard cells (rather than physics-based movement), this
44
## allows UI elements, cutscenes, and other systems to quickly lookup gamepieces by name or
55
## location. Additionally, it allows pathfinders to see which cells are occupied or unoccupied.
6-
## [/br][/br]Note that only ONE gamepiece may occupy a cell and will block the movement of other
7-
## gamepieces.
6+
##
7+
## Note that only ONE gamepiece may occupy a cell and will block the movement of other
8+
## gamepieces.
89
extends Node
910

1011
signal gamepiece_moved(gp: Gamepiece, new_cell: Vector2i, old_cell: Vector2i)
@@ -20,20 +21,20 @@ func register(gamepiece: Gamepiece, cell: Vector2i) -> bool:
2021
printerr("Failed to register Gamepiece '%s' at cell '%s'. " % [gamepiece.name, str(cell)],
2122
"A gamepiece already exists at that cell!")
2223
return false
23-
24+
2425
#...or if it has already been registered, for some reason.
2526
if gamepiece in _gamepieces.values():
2627
printerr("Refused to register Gamepiece '%s' at cell '%s'. " % [gamepiece.name, str(cell)],
2728
"The gamepiece has already been registered!")
2829
return true
29-
30+
3031
# We want to know when the gamepiece leaves the scene tree, as it is no longer on the gameboard.
3132
# This probably means that the gamepiece has been freed.
3233
gamepiece.tree_exiting.connect(_on_gamepiece_tree_exiting.bind(gamepiece))
33-
34+
3435
_gamepieces[cell] = gamepiece
3536
gamepiece_moved.emit(gamepiece, cell, Gameboard.INVALID_CELL)
36-
37+
3738
return true
3839

3940

@@ -45,14 +46,14 @@ func move_gamepiece(gp: Gamepiece, new_cell: Vector2i) -> bool:
4546
if _gamepieces.has(new_cell):
4647
print("Cell %s is already occupied, cannot move gamepiece '%s'!" % [str(new_cell), gp.name])
4748
return false
48-
49+
4950
var old_cell: = get_cell(gp)
5051
if old_cell == new_cell:
5152
return false
52-
53+
5354
_gamepieces.erase(old_cell)
5455
_gamepieces[new_cell] = gp
55-
56+
5657
gamepiece_moved.emit(gp, new_cell, old_cell)
5758
return true
5859

@@ -94,7 +95,7 @@ func _on_gamepiece_tree_exiting(gp: Gamepiece) -> void:
9495
if _gamepieces.has(cell):
9596
_gamepieces.erase(cell)
9697
gamepiece_freed.emit(gp, cell)
97-
98+
9899
#if cell != null:
99100
#Events.gamepiece_exiting_tree.emit(gp, cell)
100101

0 commit comments

Comments
 (0)