Skip to content

Commit

Permalink
connect sensor signals deferred to fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Novakasa committed Sep 5, 2021
1 parent bd37e39 commit a7d8693
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion brickrail-gui/layout_route_leg.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func get_type():
func set_switches():
var last_track = get_start().obj.section.tracks[-1]
for edge in edges:
print(edge.type)
if edge.section == null:
continue
for dirtrack in edge.section.tracks:
Expand Down
1 change: 0 additions & 1 deletion brickrail-gui/layout_track.gd
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ func get_connection_to(track):
if track in connections[slot].values():
var turn = track.get_turn_from(get_neighbour_slot(slot))
return {"slot": slot, "turn": turn}
assert(false)
return null

func get_next_track(slot, segment=true):
Expand Down
7 changes: 5 additions & 2 deletions brickrail-gui/layout_train.gd
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ func start_leg():

func set_target(p_block):
if target!=null:
# prints("disconnecting target:", target.id)
target.disconnect("train_entered", self, "_on_target_train_entered")
target.disconnect("train_in", self, "_on_target_train_in")
target = p_block
if target != null:
target.connect("train_entered", self, "_on_target_train_entered")
target.connect("train_in", self, "_on_target_train_in")
# prints("connecting target:", target.id)
# connect signals deferred, so they don't get retriggered within this frame if it happens to be the same sensor as the one that triggered this method call
target.call_deferred("connect", "train_entered", self, "_on_target_train_entered")
target.call_deferred("connect", "train_in", self, "_on_target_train_in")

func _on_target_train_entered(p_train):
if p_train != null:
Expand Down

0 comments on commit a7d8693

Please sign in to comment.