Skip to content

Commit b12b9ff

Browse files
committed
fix: bunch of runtime bugs caused by our type "safety"
:smh:
1 parent b0e3fbc commit b12b9ff

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

src/puzzle/Player.gd

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class_name DotHopPlayer
1111

1212
var display_name: String = "Player"
1313

14-
var label : Label
14+
var label : RichTextLabel
1515
var color_rect : ColorRect
1616
var current_coord: Vector2
1717

src/puzzle/PuzzleScene.gd

+24-25
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ static var fallback_puzzle_scene: String = "res://src/puzzle/PuzzleScene.tscn"
1919
# for testing just the game logic (without loading a full DotHopGame)
2020
static func build_puzzle_node(opts: Dictionary) -> Node2D:
2121
# parse the puzzle script game, set game_def
22-
var game_def_p: String = opts.get("game_def_path")
2322
var _game_def: GameDef = opts.get("game_def")
24-
if not _game_def and game_def_p:
25-
_game_def = Puzz.parse_game_def(game_def_p)
23+
if not _game_def and opts.get("game_def_path"):
24+
_game_def = Puzz.parse_game_def(str(opts.get("game_def_path")))
2625

2726
if _game_def == null:
2827
Log.warn("No game_def passed, cannot build_puzzle_node()", opts)
@@ -253,7 +252,7 @@ var block_move: bool
253252
var last_move: Vector2
254253

255254
func check_move_input(event: InputEvent = null, move_vec: Vector2 = Vector2.ZERO) -> void:
256-
if move_vec == null:
255+
if move_vec == Vector2.ZERO:
257256
move_vec = Trolls.grid_move_vector(event)
258257

259258
if move_vec != last_move:
@@ -279,7 +278,7 @@ func restart_block_move_timer(t: float = 0.2) -> void:
279278

280279
func on_dot_pressed(_type: DHData.dotType, node: DotHopDot) -> void:
281280
# calc move_vec for tapped dot with first player
282-
var first_player_coord: Vector2
281+
var first_player_coord: Variant
283282
for p: Dictionary in state.players:
284283
if p.coord != null:
285284
first_player_coord = p.coord
@@ -309,8 +308,8 @@ func init_game_state() -> void:
309308
var row: Array = puzzle_def.shape[y]
310309
var r: Array = []
311310
for x: int in len(row):
312-
var cell: Array = puzzle_def.shape[y][x]
313-
var objs: Array = game_def.get_cell_objects(cell)
311+
var cell: Variant = puzzle_def.shape[y][x]
312+
var objs: Variant = game_def.get_cell_objects(cell)
314313
r.append(objs)
315314
grid.append(r)
316315

@@ -325,7 +324,7 @@ func init_player(coord: Vector2, node: Node) -> Dictionary:
325324
return {coord=coord, stuck=false, move_history=[], node=node}
326325

327326
func clear_nodes() -> void:
328-
for ch: Node2D in get_children():
327+
for ch: Node in get_children():
329328
if ch.is_in_group("generated"):
330329
# hide flicker while we wait for queue_free
331330
ch.set_visible(false)
@@ -351,9 +350,9 @@ func coord_pos(node: Node2D) -> Vector2:
351350
return node.position
352351

353352
func puzzle_rect(opts: Dictionary = {}) -> Rect2:
354-
var nodes: Array[Node2D] = puzzle_cam_nodes(opts)
353+
var nodes: Array = puzzle_cam_nodes(opts)
355354
var rect: Rect2 = Rect2(coord_pos(nodes[0]), Vector2.ZERO)
356-
for node: DotHopDot in nodes:
355+
for node: Variant in nodes:
357356
if "square_size" in node:
358357
# scale might also be a factor
359358
var bot_right: Vector2 = coord_pos(node) + node.square_size * Vector2.ONE * 1.0
@@ -389,7 +388,7 @@ func rebuild_nodes() -> void:
389388
var players: Array = []
390389
for y: int in len(state.grid):
391390
for x: int in len(state.grid[y]):
392-
var objs: Array = state.grid[y][x]
391+
var objs: Variant = state.grid[y][x]
393392
if objs == null:
394393
continue
395394
for obj_name: String in objs:
@@ -434,7 +433,7 @@ func node_for_object_name(obj_name: String) -> Node2D:
434433
return
435434
var node: Node2D = scene.instantiate()
436435
node.display_name = obj_name
437-
var t: DHData.dotType = obj_type.get(obj_name)
436+
var t: Variant = obj_type.get(obj_name)
438437
if t != null and "type" in node:
439438
node.type = t
440439
if node.has_signal("dot_pressed"):
@@ -481,7 +480,7 @@ func coord_in_grid(coord: Vector2) -> bool:
481480
coord.x < state.grid_xs and coord.y < state.grid_ys
482481

483482
func cell_at_coord(coord: Vector2) -> Dictionary:
484-
var nodes: Array = state.cell_nodes.get(coord)
483+
var nodes: Variant = state.cell_nodes.get(coord)
485484
return {objs=state.grid[coord.y][coord.x], coord=coord, nodes=nodes}
486485

487486
# returns a list of cells from the passed position in the passed direction
@@ -491,26 +490,26 @@ func cells_in_direction(coord:Vector2, dir:Vector2) -> Array:
491490
return []
492491
var cells: Array = []
493492
var cursor: Vector2 = coord + dir
494-
var last_cursor: Vector2
493+
var last_cursor: Variant = null
495494
while coord_in_grid(cursor) and last_cursor != cursor:
496495
cells.append(cell_at_coord(cursor))
497496
last_cursor = cursor
498497
cursor += dir
499498
return cells
500499

501500
# Returns a list of cell object names
502-
func all_cells() -> Array[Variant]:
501+
func all_cells() -> Array:
503502
if state == null:
504503
return []
505504
var cs: Array = []
506505
for row: Array in state.grid:
507-
for cell: Array in row:
506+
for cell: Variant in row:
508507
cs.append(cell)
509508
return cs
510509

511510
# Returns true if there are no "dot" objects in the state grid
512511
func all_dotted() -> bool:
513-
return all_cells().all(func(c: Array) -> bool:
512+
return all_cells().all(func(c: Variant) -> bool:
514513
if c == null:
515514
return true
516515
for obj_name: String in c:
@@ -519,7 +518,7 @@ func all_dotted() -> bool:
519518
return true)
520519

521520
func dot_count(only_undotted: bool = false) -> int:
522-
return len(all_cells().filter(func(c: Array) -> bool:
521+
return len(all_cells().filter(func(c: Variant) -> bool:
523522
if c == null:
524523
return false
525524
for obj_name: String in c:
@@ -531,9 +530,9 @@ func dot_count(only_undotted: bool = false) -> int:
531530

532531

533532
func all_players_at_goal() -> bool:
534-
return all_cells().filter(func(c: Array[String]) -> bool:
533+
return all_cells().filter(func(c: Variant) -> bool:
535534
return c != null and "Goal" in c
536-
).all(func(c: Array[String]) -> bool: return "Player" in c)
535+
).all(func(c: Array) -> bool: return "Player" in c)
537536

538537
func all_cell_nodes(opts: Dictionary = {}) -> Array[Node2D]:
539538
var ns: Array = state.cell_nodes.values().reduce(func(agg: Array, nodes: Array) -> Array:
@@ -548,13 +547,13 @@ func all_cell_nodes(opts: Dictionary = {}) -> Array[Node2D]:
548547

549548
## move/state-updates ##############################################################
550549

551-
func previous_undo_coord(player: Dictionary, skip_coord: Vector2, start_at: int = 0) -> Vector2:
550+
func previous_undo_coord(player: Dictionary, skip_coord: Vector2, start_at: int = 0) -> Variant:
552551
# pulls the first coord from player history that does not match `skip_coord`,
553552
# starting after `start_at`
554553
for m: Vector2 in player.move_history.slice(start_at):
555554
if m != skip_coord:
556555
return m
557-
return Vector2.ZERO
556+
return
558557

559558
# Move the player to the passed cell's coordinate.
560559
# also updates the game state
@@ -574,7 +573,7 @@ func move_player_to_cell(player: Dictionary, cell: Dictionary) -> Signal:
574573

575574
# remove previous undo marker
576575
# NOTE start_at 1 b/c history has already been updated
577-
var prev_undo_coord: Vector2
576+
var prev_undo_coord: Variant
578577
if len(player.move_history) > 1:
579578
prev_undo_coord = previous_undo_coord(player, player.coord, 1)
580579
if prev_undo_coord != null:
@@ -659,7 +658,7 @@ func undo_last_move(player: Dictionary) -> void:
659658
var dest_cell: Dictionary = cell_at_coord(last_pos)
660659

661660
# need to walk back the grid's Undo markers
662-
var prev_undo_coord: Vector2 = previous_undo_coord(player, dest_cell.coord, 0)
661+
var prev_undo_coord: Variant = previous_undo_coord(player, dest_cell.coord, 0)
663662
if prev_undo_coord != null:
664663
if not "Undo" in state.grid[prev_undo_coord.y][prev_undo_coord.x]:
665664
state.grid[prev_undo_coord.y][prev_undo_coord.x].append("Undo")
@@ -729,7 +728,7 @@ func move(move_dir: Vector2) -> bool:
729728
continue
730729

731730
# instead of markers, read undo based on only the player move history?
732-
var undo_cell_in_dir: Dictionary = U.first(cells.filter(func(c: Dictionary) -> bool: return "Undo" in c.objs and c.coord in p.move_history))
731+
var undo_cell_in_dir: Variant = U.first(cells.filter(func(c: Dictionary) -> bool: return "Undo" in c.objs and c.coord in p.move_history))
733732

734733
if undo_cell_in_dir != null:
735734
moves_to_make.append(["undo", undo_last_move, p, undo_cell_in_dir])

src/themes/DebugThemeData.tres

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ player_scenes = Array[PackedScene]([null])
1111
dot_scenes = Array[PackedScene]([])
1212
goal_scenes = Array[PackedScene]([])
1313
music_tracks = Array[String]([])
14-
is_unlocked = null
14+
is_unlocked = false

src/themes/dots/DotsThemeData.tres

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ dot_icon = ExtResource("1_wotl1")
2121
dotted_icon = ExtResource("3_e6kct")
2222
goal_icon = ExtResource("4_l73ry")
2323
music_tracks = Array[String](["res://assets/songs/sulosounds/chill-electric-background.wav"])
24-
is_unlocked = null
24+
is_unlocked = false

src/themes/spring/SpringThemeData.tres

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ dot_icon = ExtResource("1_lyo2k")
2222
dotted_icon = ExtResource("3_nlqja")
2323
goal_icon = ExtResource("4_wif7w")
2424
music_tracks = Array[String](["res://assets/songs/benburnes/The Verdant Grove LOOP.wav"])
25-
is_unlocked = null
25+
is_unlocked = false

todo.org

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
handle save events (theme_id) across transition/refactor
55
* [ ] refactor puzzleSet into custom resources
66
handle save events (puzzle_id) across transition/refactor
7+
* [ ] enforce strict types everywhere
78
* [ ] animate (shake) available next-dots
89
* [ ] rewrite menu/world map
910
* bugs
1011
** [ ] restore pause
1112
** [ ] tap/click to advance on 'new-puzzle-unlocked scenes'
13+
** [ ] new undo/reset buttons are grabbing focus from the controller
1214
* [ ] v2 'Dots' theme art

0 commit comments

Comments
 (0)