Skip to content

Commit 3930b26

Browse files
committed
fix: static type fixes - tests passing again!
1 parent 84309b3 commit 3930b26

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

plug.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extends "res://addons/gd-plug/plug.gd"
22

3-
func _plugging():
3+
func _plugging() -> void:
44
plug("MikeSchulze/gdUnit4", {exclude=["addons/gdUnit4/test"]})
55
plug("bitbrain/pandora", {include=["addons/pandora"]})
66
plug("nathanhoad/godot_input_helper", {include=["addons/input_helper"]})

src/parse/ParsedGame.gd

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ func parse_prelude(chunks: Array) -> Dictionary:
7474

7575
func parse_objects(chunks: Array) -> Dictionary:
7676
var objs := {}
77-
for lines: Array[String] in chunks:
77+
for lines: Array in chunks:
7878
var obj := {}
79-
var nm_parts := lines[0].split(" ")
79+
var line: String = lines[0]
80+
var nm_parts := line.split(" ")
8081
obj.name = nm_parts[0]
8182
if nm_parts.size() > 1:
8283
obj.symbol = nm_parts[1]
83-
obj.colors = Array(lines[1].split(" "))
84+
var line2: String = lines[1]
85+
obj.colors = Array(line2.split(" "))
8486
if lines.size() > 2:
8587
lines.remove_at(0)
8688
lines.remove_at(0)

src/parse/Puzz.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static func parse_game_def(path: Variant, opts: Dictionary = {}) -> GameDef:
1212
contents = file.get_as_text()
1313

1414
var parsed: Dictionary = ParsedGame.new().parse(contents)
15-
return GameDef.new(path as String, parsed)
15+
return GameDef.new(path, parsed)
1616

1717
# helpful for supporting some tests
1818
static func parse_puzzle_def(lines: Array) -> PuzzleDef:

src/puzzle/GameDef.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var path: String
1212

1313
## init ########################################3333
1414

15-
func _init(_path: String, parsed: Dictionary) -> void:
16-
if _path:
15+
func _init(_path: Variant, parsed: Dictionary) -> void:
16+
if _path != null:
1717
path = _path
1818
raw = parsed
1919
legend = parsed.legend

src/puzzle/PuzzleScene.gd

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static var fallback_puzzle_scene: String = "res://src/puzzle/PuzzleScene.tscn"
1717
#
1818
# This func could live on the DotHopGame script, but a function like this is useful
1919
# for testing just the game logic (without loading a full DotHopGame)
20-
static func build_puzzle_node(opts: Dictionary) -> Node2D:
20+
static func build_puzzle_node(opts: Dictionary) -> DotHopPuzzle:
2121
# parse the puzzle script game, set game_def
2222
var _game_def: GameDef = opts.get("game_def")
2323
if not _game_def and opts.get("game_def_path"):
@@ -47,10 +47,10 @@ static func build_puzzle_node(opts: Dictionary) -> Node2D:
4747
var _theme: PuzzleTheme = opts.get("puzzle_theme")
4848
var _theme_data: PuzzleThemeData = opts.get("puzzle_theme_data")
4949
var scene: PackedScene = opts.get("puzzle_scene", _theme_data.puzzle_scene if _theme_data else null)
50-
if scene == null:
50+
if scene == null and opts.get("puzzle_scene_path") != null:
5151
# TODO Drop support for this unless we use it (maybe in tests?)
5252
scene = load(str(opts.get("puzzle_scene_path")))
53-
elif scene == null:
53+
if scene == null:
5454
scene = load(fallback_puzzle_scene)
5555

5656
var node: DotHopPuzzle = scene.instantiate()
@@ -574,7 +574,9 @@ func move_player_to_cell(player: Dictionary, cell: Dictionary) -> Signal:
574574
@warning_ignore("unsafe_method_access")
575575
if player.node.has_method("move_to_coord"):
576576
@warning_ignore("unsafe_method_access")
577-
move_finished_sig = player.node.move_to_coord(cell.coord)
577+
var res: Variant = player.node.move_to_coord(cell.coord)
578+
if res != null:
579+
move_finished_sig = res
578580
else:
579581
player.node.position = cell.coord * square_size
580582

test/dotHop/puzzle_analysis_test.gd

+19-17
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ extends GdUnitTestSuite
22
class_name PuzzleAnalysisTest
33

44

5-
func build_puzzle(puzzle):
6-
var puzzle_node = DotHopPuzzle.build_puzzle_node({puzzle=puzzle,
5+
func build_puzzle(puzzle: Array) -> DotHopPuzzle:
6+
var puzzle_node := DotHopPuzzle.build_puzzle_node({puzzle=puzzle,
77
game_def_path="res://src/puzzles/dothop.txt"})
88
puzzle_node.init_game_state()
99
return puzzle_node
1010

1111
## test the solver ##################################################
1212

13-
func test_puzzle_solver_basic(puzz, solvable, test_parameters=[
13+
@warning_ignore("unused_parameter")
14+
func test_puzzle_solver_basic(puzz: Array, solvable: bool, test_parameters: Array = [
1415
[["xot"], true],
1516
[[
1617
"x.",
@@ -31,15 +32,16 @@ func test_puzzle_solver_basic(puzz, solvable, test_parameters=[
3132
"ox.o.ot",
3233
"...o.o.",
3334
], true],
34-
]):
35-
var puzzle = build_puzzle(puzz)
36-
var result = PuzzleAnalysis.new(puzzle).analyze()
35+
]) -> void:
36+
var puzzle := build_puzzle(puzz)
37+
var result := PuzzleAnalysis.new(puzzle).analyze()
3738
assert_bool(result.solvable).is_equal(solvable)
3839

3940
puzzle.free()
4041

4142

42-
func test_puzzle_solver_analysis(puzz, expected_result, test_parameters=[
43+
@warning_ignore("unused_parameter")
44+
func test_puzzle_solver_analysis(puzz: Array, expected_result: Dictionary, test_parameters: Array = [
4345
[["xot"], {
4446
solvable=true,
4547
path_count=1, winning_path_count=1, stuck_path_count=0,
@@ -78,36 +80,36 @@ func test_puzzle_solver_analysis(puzz, expected_result, test_parameters=[
7880
solvable=true,
7981
path_count=22, winning_path_count=2, stuck_path_count=20,
8082
}],
81-
]):
82-
var puzzle = build_puzzle(puzz)
83+
]) -> void:
84+
var puzzle := build_puzzle(puzz)
8385

84-
var result = PuzzleAnalysis.new(puzzle).analyze()
86+
var result := PuzzleAnalysis.new(puzzle).analyze()
8587

86-
for k in expected_result:
88+
for k: String in expected_result:
8789
assert_that(expected_result[k]).is_equal(result.get(k))
8890

8991
puzzle.free()
9092

9193
## test in-game puzzles ##################################################
9294

93-
func test_all_puzzles_solvable():
94-
var sets = Store.get_puzzle_sets()
95+
func test_all_puzzles_solvable() -> void:
96+
var sets := Store.get_puzzle_sets()
9597
assert_int(len(sets)).is_greater(3) # make sure we get some
9698

9799
for puzzle_set in sets:
98-
var game_def = Puzz.parse_game_def(puzzle_set.get_puzzle_script_path())
99-
var puzzle_count = len(game_def.puzzles)
100+
var game_def := Puzz.parse_game_def(puzzle_set.get_puzzle_script_path())
101+
var puzzle_count := len(game_def.puzzles)
100102
assert_int(puzzle_count).is_greater(0)
101103
for i in puzzle_count:
102104
# requiring a node that is added to the scene to analyze is a damn shame here
103105
# (can the analysis be run without the node's _ready()?
104-
var puzz_node = DotHopPuzzle.build_puzzle_node({
106+
var puzz_node := DotHopPuzzle.build_puzzle_node({
105107
game_def=game_def,
106108
puzzle_num=i,
107109
})
108110
puzz_node.init_game_state()
109111

110-
var solve = PuzzleAnalysis.new(puzz_node).analyze()
112+
var solve := PuzzleAnalysis.new(puzz_node).analyze()
111113
Log.pr(["Puzzle:", puzzle_set.get_display_name(), "num:", i,
112114
"solvable?", solve.solvable,
113115
"dot count", solve.dot_count,

test/store/store_test.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func test_initial_store_theme_data() -> void:
3838
assert_that(len(themes)).is_equal(len(theme_ents))
3939

4040
# at least one theme unlocked
41-
var unlocked := themes.filter(func(ent: PuzzleSet) -> bool: return ent.is_unlocked())
41+
var unlocked := themes.filter(func(ent: PuzzleTheme) -> bool: return ent.is_unlocked())
4242
assert_int(len(unlocked)).is_greater(0)
4343

4444
#########################################################################

0 commit comments

Comments
 (0)