@willcgage/module-schematic 0.24.0 → 0.26.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 +28 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +28 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -210,6 +210,7 @@ function emptyEditorState(lengthInches) {
|
|
|
210
210
|
loopReturn: "same",
|
|
211
211
|
configA: "single",
|
|
212
212
|
configB: "single",
|
|
213
|
+
mainsSwapped: false,
|
|
213
214
|
extraTracks: [],
|
|
214
215
|
turnouts: [],
|
|
215
216
|
crossings: [],
|
|
@@ -226,18 +227,35 @@ function emptyEditorState(lengthInches) {
|
|
|
226
227
|
function isTransitionTurnout(t) {
|
|
227
228
|
return t.onTrack === MAIN_TRACK_ID && t.divergeTrack === MAIN2_TRACK_ID || t.onTrack === MAIN2_TRACK_ID && t.divergeTrack === MAIN_TRACK_ID;
|
|
228
229
|
}
|
|
230
|
+
function main1Track(state) {
|
|
231
|
+
const bothDouble = state.configA === "double" && state.configB === "double";
|
|
232
|
+
const isDouble = state.configA === "double" || state.configB === "double";
|
|
233
|
+
const sw = state.turnouts.find(isTransitionTurnout);
|
|
234
|
+
const lane = state.mainsSwapped && isDouble ? 1 : 0;
|
|
235
|
+
if (!isDouble || bothDouble || !sw || sw.onTrack !== MAIN2_TRACK_ID) {
|
|
236
|
+
return { id: MAIN_TRACK_ID, role: "main", lane, from: "A", to: "B" };
|
|
237
|
+
}
|
|
238
|
+
return state.configA === "double" ? (
|
|
239
|
+
// Double at A: Main 1 runs from A and ends at the turnout.
|
|
240
|
+
{ id: MAIN_TRACK_ID, role: "main", lane, fromPos: 0, toPos: sw.pos }
|
|
241
|
+
) : (
|
|
242
|
+
// Double at B: Main 1 begins at the turnout and runs to B.
|
|
243
|
+
{ id: MAIN_TRACK_ID, role: "main", lane, fromPos: sw.pos, toPos: state.lengthInches }
|
|
244
|
+
);
|
|
245
|
+
}
|
|
229
246
|
function main2Track(state) {
|
|
230
247
|
const bothDouble = state.configA === "double" && state.configB === "double";
|
|
231
248
|
const sw = state.turnouts.find(isTransitionTurnout);
|
|
249
|
+
const lane = state.mainsSwapped ? 0 : 1;
|
|
232
250
|
if (bothDouble || !sw || sw.divergeTrack !== MAIN2_TRACK_ID) {
|
|
233
|
-
return { id: MAIN2_TRACK_ID, role: "main", lane
|
|
251
|
+
return { id: MAIN2_TRACK_ID, role: "main", lane, from: "A", to: "B" };
|
|
234
252
|
}
|
|
235
253
|
return state.configA === "double" ? (
|
|
236
254
|
// Double at A: Main 2 runs from A and ends at the turnout.
|
|
237
|
-
{ id: MAIN2_TRACK_ID, role: "main", lane
|
|
255
|
+
{ id: MAIN2_TRACK_ID, role: "main", lane, fromPos: 0, toPos: sw.pos }
|
|
238
256
|
) : (
|
|
239
257
|
// Double at B: Main 2 begins at the turnout and runs to B.
|
|
240
|
-
{ id: MAIN2_TRACK_ID, role: "main", lane
|
|
258
|
+
{ id: MAIN2_TRACK_ID, role: "main", lane, fromPos: sw.pos, toPos: state.lengthInches }
|
|
241
259
|
);
|
|
242
260
|
}
|
|
243
261
|
function buildTransition(state) {
|
|
@@ -294,6 +312,7 @@ function stateToDoc(state, recordNumber) {
|
|
|
294
312
|
lengthInches: state.lengthInches,
|
|
295
313
|
...state.loop ? { loop: true } : {},
|
|
296
314
|
...state.loop && state.loopReturn === "main2" ? { loopReturn: "main2" } : {},
|
|
315
|
+
...state.mainsSwapped ? { mainsSwapped: true } : {},
|
|
297
316
|
endplates: withWidths(
|
|
298
317
|
withPoses(
|
|
299
318
|
[
|
|
@@ -338,7 +357,11 @@ function stateToDoc(state, recordNumber) {
|
|
|
338
357
|
state.loop ? (
|
|
339
358
|
// The main runs the lead from A and turns back at the balloon.
|
|
340
359
|
{ id: MAIN_TRACK_ID, role: "main", lane: 0, fromPos: 0, toPos: state.lengthInches }
|
|
341
|
-
) :
|
|
360
|
+
) : (
|
|
361
|
+
// Normally A→B; partial when MAIN 2 is the through main and Main 1 is
|
|
362
|
+
// the one that ends at the transition turnout (#FMN-0043).
|
|
363
|
+
main1Track(state)
|
|
364
|
+
),
|
|
342
365
|
// Double track: Main 2 is a real entity so turnouts/signals can attach.
|
|
343
366
|
// On a loop it exists only for a Main 2 directional return (the U joins
|
|
344
367
|
// the two lanes at the balloon); a same-main loop's parallel lead legs
|
|
@@ -501,6 +524,7 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
|
|
|
501
524
|
lengthInches: len,
|
|
502
525
|
loop,
|
|
503
526
|
loopReturn: loop && d.loopReturn === "main2" ? "main2" : "same",
|
|
527
|
+
mainsSwapped: d.mainsSwapped === true,
|
|
504
528
|
configA: configOf("A"),
|
|
505
529
|
// On a loop, a missing B means pure turnback; present = interchange loop.
|
|
506
530
|
configB: loop && !hasB ? "none" : configOf("B"),
|