@willcgage/module-schematic 0.33.0 → 0.35.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.cjs +25 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +25 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -555,18 +555,22 @@ function main1Track(state) {
|
|
|
555
555
|
}
|
|
556
556
|
function main2Track(state) {
|
|
557
557
|
const bothDouble = state.configA === "double" && state.configB === "double";
|
|
558
|
-
const
|
|
558
|
+
const sws = state.turnouts.filter((t) => isTransitionTurnout(t) && t.divergeTrack === MAIN2_TRACK_ID).sort((a, b) => a.pos - b.pos);
|
|
559
559
|
const lane = state.mainsSwapped ? 0 : 1;
|
|
560
|
-
if (bothDouble || !
|
|
560
|
+
if (bothDouble || !sws.length) {
|
|
561
561
|
return { id: MAIN2_TRACK_ID, role: "main", lane, from: "A", to: "B" };
|
|
562
562
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
);
|
|
563
|
+
const track = (fromPos, toPos) => ({
|
|
564
|
+
id: MAIN2_TRACK_ID,
|
|
565
|
+
role: "main",
|
|
566
|
+
lane,
|
|
567
|
+
fromPos,
|
|
568
|
+
toPos
|
|
569
|
+
});
|
|
570
|
+
if (state.configA === "double") return track(0, sws[0].pos);
|
|
571
|
+
if (state.configB === "double") return track(sws[0].pos, state.lengthInches);
|
|
572
|
+
if (sws.length >= 2) return track(sws[0].pos, sws[sws.length - 1].pos);
|
|
573
|
+
return track(sws[0].pos, state.lengthInches);
|
|
570
574
|
}
|
|
571
575
|
function buildTransition(state) {
|
|
572
576
|
const aDouble = state.configA === "double";
|
|
@@ -684,7 +688,12 @@ function stateToDoc(state, recordNumber) {
|
|
|
684
688
|
// double) Main 2 only runs from the mainline turnout to the double end —
|
|
685
689
|
// the turnout that diverges to main2 is the single source of truth for
|
|
686
690
|
// where the transition sits (fd#175 / FMN-0038).
|
|
687
|
-
|
|
691
|
+
// …and on a module that's SINGLE at both ends but goes double in the
|
|
692
|
+
// middle to form a siding: the turnouts are what make Main 2 exist, so a
|
|
693
|
+
// pair of them is reason enough to emit it (#118). Without this the
|
|
694
|
+
// second main simply wasn't in the doc, and neither the board nor the
|
|
695
|
+
// dispatcher panel could draw it.
|
|
696
|
+
...!state.loop && (state.configA === "double" || state.configB === "double" || state.turnouts.some((t) => isTransitionTurnout(t) && t.divergeTrack === MAIN2_TRACK_ID)) ? [main2Track(state)] : [],
|
|
688
697
|
...state.loop && state.loopReturn === "main2" ? [{ id: MAIN2_TRACK_ID, role: "main", lane: 1, fromPos: 0, toPos: state.lengthInches }] : [],
|
|
689
698
|
...state.extraTracks.map((t) => ({
|
|
690
699
|
id: t.id,
|
|
@@ -707,7 +716,8 @@ function stateToDoc(state, recordNumber) {
|
|
|
707
716
|
kind: t.kind,
|
|
708
717
|
name: t.name || void 0,
|
|
709
718
|
...t.size ? { size: t.size } : {},
|
|
710
|
-
...t.curved ? { curved: true } : {}
|
|
719
|
+
...t.curved ? { curved: true } : {},
|
|
720
|
+
...t.flipped ? { flipped: true } : {}
|
|
711
721
|
})),
|
|
712
722
|
...state.crossings.length > 0 ? {
|
|
713
723
|
crossings: state.crossings.map((x) => ({
|
|
@@ -878,7 +888,8 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
|
|
|
878
888
|
divergeTrack: t.divergeTrack,
|
|
879
889
|
kind: t.kind ?? "right",
|
|
880
890
|
...t.size ? { size: t.size } : {},
|
|
881
|
-
...t.curved ? { curved: true } : {}
|
|
891
|
+
...t.curved ? { curved: true } : {},
|
|
892
|
+
...t.flipped ? { flipped: true } : {}
|
|
882
893
|
})),
|
|
883
894
|
controlPoints: readControlPoints(d, sc),
|
|
884
895
|
industries: (d.industries ?? []).map((ind) => ({
|
|
@@ -1011,9 +1022,9 @@ function buildCrossover(state) {
|
|
|
1011
1022
|
];
|
|
1012
1023
|
return { track, turnouts };
|
|
1013
1024
|
}
|
|
1014
|
-
function divergeSideForHand(kind, stubDir) {
|
|
1025
|
+
function divergeSideForHand(kind, stubDir, flipped) {
|
|
1015
1026
|
if (kind !== "left" && kind !== "right") return 0;
|
|
1016
|
-
const s = stubDir >= 0 ? 1 : -1;
|
|
1027
|
+
const s = (stubDir >= 0 ? 1 : -1) * (flipped ? -1 : 1);
|
|
1017
1028
|
return kind === "left" ? s : -s;
|
|
1018
1029
|
}
|
|
1019
1030
|
function moduleFeatures(doc) {
|