@@ -19,10 +19,9 @@ static var fallback_puzzle_scene: String = "res://src/puzzle/PuzzleScene.tscn"
19
19
# for testing just the game logic (without loading a full DotHopGame)
20
20
static func build_puzzle_node (opts : Dictionary ) -> Node2D :
21
21
# parse the puzzle script game, set game_def
22
- var game_def_p : String = opts .get ("game_def_path" )
23
22
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" )) )
26
25
27
26
if _game_def == null :
28
27
Log .warn ("No game_def passed, cannot build_puzzle_node()" , opts )
@@ -253,7 +252,7 @@ var block_move: bool
253
252
var last_move : Vector2
254
253
255
254
func check_move_input (event : InputEvent = null , move_vec : Vector2 = Vector2 .ZERO ) -> void :
256
- if move_vec == null :
255
+ if move_vec == Vector2 . ZERO :
257
256
move_vec = Trolls .grid_move_vector (event )
258
257
259
258
if move_vec != last_move :
@@ -279,7 +278,7 @@ func restart_block_move_timer(t: float = 0.2) -> void:
279
278
280
279
func on_dot_pressed (_type : DHData .dotType , node : DotHopDot ) -> void :
281
280
# calc move_vec for tapped dot with first player
282
- var first_player_coord : Vector2
281
+ var first_player_coord : Variant
283
282
for p : Dictionary in state .players :
284
283
if p .coord != null :
285
284
first_player_coord = p .coord
@@ -309,8 +308,8 @@ func init_game_state() -> void:
309
308
var row : Array = puzzle_def .shape [y ]
310
309
var r : Array = []
311
310
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 )
314
313
r .append (objs )
315
314
grid .append (r )
316
315
@@ -325,7 +324,7 @@ func init_player(coord: Vector2, node: Node) -> Dictionary:
325
324
return {coord = coord , stuck = false , move_history = [], node = node }
326
325
327
326
func clear_nodes () -> void :
328
- for ch : Node2D in get_children ():
327
+ for ch : Node in get_children ():
329
328
if ch .is_in_group ("generated" ):
330
329
# hide flicker while we wait for queue_free
331
330
ch .set_visible (false )
@@ -351,9 +350,9 @@ func coord_pos(node: Node2D) -> Vector2:
351
350
return node .position
352
351
353
352
func puzzle_rect (opts : Dictionary = {}) -> Rect2 :
354
- var nodes : Array [ Node2D ] = puzzle_cam_nodes (opts )
353
+ var nodes : Array = puzzle_cam_nodes (opts )
355
354
var rect : Rect2 = Rect2 (coord_pos (nodes [0 ]), Vector2 .ZERO )
356
- for node : DotHopDot in nodes :
355
+ for node : Variant in nodes :
357
356
if "square_size" in node :
358
357
# scale might also be a factor
359
358
var bot_right : Vector2 = coord_pos (node ) + node .square_size * Vector2 .ONE * 1.0
@@ -389,7 +388,7 @@ func rebuild_nodes() -> void:
389
388
var players : Array = []
390
389
for y : int in len (state .grid ):
391
390
for x : int in len (state .grid [y ]):
392
- var objs : Array = state .grid [y ][x ]
391
+ var objs : Variant = state .grid [y ][x ]
393
392
if objs == null :
394
393
continue
395
394
for obj_name : String in objs :
@@ -434,7 +433,7 @@ func node_for_object_name(obj_name: String) -> Node2D:
434
433
return
435
434
var node : Node2D = scene .instantiate ()
436
435
node .display_name = obj_name
437
- var t : DHData . dotType = obj_type .get (obj_name )
436
+ var t : Variant = obj_type .get (obj_name )
438
437
if t != null and "type" in node :
439
438
node .type = t
440
439
if node .has_signal ("dot_pressed" ):
@@ -481,7 +480,7 @@ func coord_in_grid(coord: Vector2) -> bool:
481
480
coord .x < state .grid_xs and coord .y < state .grid_ys
482
481
483
482
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 )
485
484
return {objs = state .grid [coord .y ][coord .x ], coord = coord , nodes = nodes }
486
485
487
486
# 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:
491
490
return []
492
491
var cells : Array = []
493
492
var cursor : Vector2 = coord + dir
494
- var last_cursor : Vector2
493
+ var last_cursor : Variant = null
495
494
while coord_in_grid (cursor ) and last_cursor != cursor :
496
495
cells .append (cell_at_coord (cursor ))
497
496
last_cursor = cursor
498
497
cursor += dir
499
498
return cells
500
499
501
500
# Returns a list of cell object names
502
- func all_cells () -> Array [ Variant ] :
501
+ func all_cells () -> Array :
503
502
if state == null :
504
503
return []
505
504
var cs : Array = []
506
505
for row : Array in state .grid :
507
- for cell : Array in row :
506
+ for cell : Variant in row :
508
507
cs .append (cell )
509
508
return cs
510
509
511
510
# Returns true if there are no "dot" objects in the state grid
512
511
func all_dotted () -> bool :
513
- return all_cells ().all (func (c : Array ) -> bool :
512
+ return all_cells ().all (func (c : Variant ) -> bool :
514
513
if c == null :
515
514
return true
516
515
for obj_name : String in c :
@@ -519,7 +518,7 @@ func all_dotted() -> bool:
519
518
return true )
520
519
521
520
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 :
523
522
if c == null :
524
523
return false
525
524
for obj_name : String in c :
@@ -531,9 +530,9 @@ func dot_count(only_undotted: bool = false) -> int:
531
530
532
531
533
532
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 :
535
534
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 )
537
536
538
537
func all_cell_nodes (opts : Dictionary = {}) -> Array [Node2D ]:
539
538
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]:
548
547
549
548
## move/state-updates ##############################################################
550
549
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 :
552
551
# pulls the first coord from player history that does not match `skip_coord`,
553
552
# starting after `start_at`
554
553
for m : Vector2 in player .move_history .slice (start_at ):
555
554
if m != skip_coord :
556
555
return m
557
- return Vector2 . ZERO
556
+ return
558
557
559
558
# Move the player to the passed cell's coordinate.
560
559
# also updates the game state
@@ -574,7 +573,7 @@ func move_player_to_cell(player: Dictionary, cell: Dictionary) -> Signal:
574
573
575
574
# remove previous undo marker
576
575
# NOTE start_at 1 b/c history has already been updated
577
- var prev_undo_coord : Vector2
576
+ var prev_undo_coord : Variant
578
577
if len (player .move_history ) > 1 :
579
578
prev_undo_coord = previous_undo_coord (player , player .coord , 1 )
580
579
if prev_undo_coord != null :
@@ -659,7 +658,7 @@ func undo_last_move(player: Dictionary) -> void:
659
658
var dest_cell : Dictionary = cell_at_coord (last_pos )
660
659
661
660
# 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 )
663
662
if prev_undo_coord != null :
664
663
if not "Undo" in state .grid [prev_undo_coord .y ][prev_undo_coord .x ]:
665
664
state .grid [prev_undo_coord .y ][prev_undo_coord .x ].append ("Undo" )
@@ -729,7 +728,7 @@ func move(move_dir: Vector2) -> bool:
729
728
continue
730
729
731
730
# 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 ))
733
732
734
733
if undo_cell_in_dir != null :
735
734
moves_to_make .append (["undo" , undo_last_move , p , undo_cell_in_dir ])
0 commit comments