simple-godot-train icon indicating copy to clipboard operation
simple-godot-train copied to clipboard

Signals?

Open Violet-Scarelli opened this issue 11 months ago • 1 comments

Any chance we could get a native implementation of signals/chain signals?

Violet-Scarelli avatar Mar 13 '24 03:03 Violet-Scarelli

I'd support that idea. Honestly, it sounds like a lot of fun!

Hm, I think it'd be required to first implement multiple trains being able to exist on the same rail network (I've never really tested that with this project). Then there would need to be some sort of concept of "blocks" of track, and the ability to determine if there's a train within a block. Then signals could probably be added to have effects :thinking:

moonbench avatar Mar 13 '24 08:03 moonbench

Then there would need to be some sort of concept of "blocks" of track, and the ability to determine if there's a train within a block.

Each track object already is a block, only when 2 "simple" tracks are linked without a switch would it mean you need to handle some special "joining" the two (or more) paths into a single block. Each switch would separate (at least) two blocks.

  • Iterate Tracks
  • Call method Track.add_to_block(None)
  • If track has block: return
  • Create new block if argument was None
  • Add current track to array inside of block
  • Check if head has track or switch
    • if a switch, skip
    • if track call `Track.add_to_block(self.block)
  • same for tail connection

As for finding if a train is inside a block: From switch -> head/left_track/right_track -> block -> loop tracks -> track.get_children() (like you do in _has_bogies_on))

Edit: quick and dirty implementation: https://github.com/red15/simple-godot-train/tree/track_block

red15 avatar Oct 29 '24 20:10 red15