@willcgage/module-schematic 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -553,18 +553,22 @@ function main1Track(state) {
553
553
  }
554
554
  function main2Track(state) {
555
555
  const bothDouble = state.configA === "double" && state.configB === "double";
556
- const sw = state.turnouts.find(isTransitionTurnout);
556
+ const sws = state.turnouts.filter((t) => isTransitionTurnout(t) && t.divergeTrack === MAIN2_TRACK_ID).sort((a, b) => a.pos - b.pos);
557
557
  const lane = state.mainsSwapped ? 0 : 1;
558
- if (bothDouble || !sw || sw.divergeTrack !== MAIN2_TRACK_ID) {
558
+ if (bothDouble || !sws.length) {
559
559
  return { id: MAIN2_TRACK_ID, role: "main", lane, from: "A", to: "B" };
560
560
  }
561
- return state.configA === "double" ? (
562
- // Double at A: Main 2 runs from A and ends at the turnout.
563
- { id: MAIN2_TRACK_ID, role: "main", lane, fromPos: 0, toPos: sw.pos }
564
- ) : (
565
- // Double at B: Main 2 begins at the turnout and runs to B.
566
- { id: MAIN2_TRACK_ID, role: "main", lane, fromPos: sw.pos, toPos: state.lengthInches }
567
- );
561
+ const track = (fromPos, toPos) => ({
562
+ id: MAIN2_TRACK_ID,
563
+ role: "main",
564
+ lane,
565
+ fromPos,
566
+ toPos
567
+ });
568
+ if (state.configA === "double") return track(0, sws[0].pos);
569
+ if (state.configB === "double") return track(sws[0].pos, state.lengthInches);
570
+ if (sws.length >= 2) return track(sws[0].pos, sws[sws.length - 1].pos);
571
+ return track(sws[0].pos, state.lengthInches);
568
572
  }
569
573
  function buildTransition(state) {
570
574
  const aDouble = state.configA === "double";
@@ -682,7 +686,12 @@ function stateToDoc(state, recordNumber) {
682
686
  // double) Main 2 only runs from the mainline turnout to the double end —
683
687
  // the turnout that diverges to main2 is the single source of truth for
684
688
  // where the transition sits (fd#175 / FMN-0038).
685
- ...!state.loop && (state.configA === "double" || state.configB === "double") ? [main2Track(state)] : [],
689
+ // …and on a module that's SINGLE at both ends but goes double in the
690
+ // middle to form a siding: the turnouts are what make Main 2 exist, so a
691
+ // pair of them is reason enough to emit it (#118). Without this the
692
+ // second main simply wasn't in the doc, and neither the board nor the
693
+ // dispatcher panel could draw it.
694
+ ...!state.loop && (state.configA === "double" || state.configB === "double" || state.turnouts.some((t) => isTransitionTurnout(t) && t.divergeTrack === MAIN2_TRACK_ID)) ? [main2Track(state)] : [],
686
695
  ...state.loop && state.loopReturn === "main2" ? [{ id: MAIN2_TRACK_ID, role: "main", lane: 1, fromPos: 0, toPos: state.lengthInches }] : [],
687
696
  ...state.extraTracks.map((t) => ({
688
697
  id: t.id,