@willcgage/module-schematic 0.17.0 → 0.18.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 CHANGED
@@ -149,6 +149,11 @@ function inchesToScaleFeet(inches, ratio = N_SCALE_RATIO) {
149
149
  function scaleFeetToInches(feet, ratio = N_SCALE_RATIO) {
150
150
  return feet * 12 / ratio;
151
151
  }
152
+ var N_CAR_LENGTH_INCHES = 3.3;
153
+ function carCapacity(fromPos, toPos, carLengthInches = N_CAR_LENGTH_INCHES) {
154
+ if (!(carLengthInches > 0)) return 0;
155
+ return Math.max(0, Math.floor(Math.abs(toPos - fromPos) / carLengthInches));
156
+ }
152
157
  function asModuleSchematic(x) {
153
158
  if (!x || typeof x !== "object") return null;
154
159
  const d = x;
@@ -170,7 +175,8 @@ function emptyEditorState(lengthInches) {
170
175
  poseOverrides: {},
171
176
  endplateWidths: {},
172
177
  outline: [],
173
- controlPoints: []
178
+ controlPoints: [],
179
+ industries: []
174
180
  };
175
181
  }
176
182
  function isTransitionTurnout(t) {
@@ -340,6 +346,21 @@ function stateToDoc(state, recordNumber) {
340
346
  side: s.side
341
347
  }))
342
348
  })),
349
+ // Industries — car-spot spans on a track; only when any are authored.
350
+ ...state.industries.length > 0 ? {
351
+ industries: state.industries.map((ind) => ({
352
+ id: ind.id,
353
+ name: ind.name,
354
+ ...ind.type ? { type: ind.type } : {},
355
+ track: ind.track,
356
+ fromPos: ind.fromPos,
357
+ toPos: ind.toPos,
358
+ side: ind.side,
359
+ ...ind.labelMode && ind.labelMode !== "none" ? { labelMode: ind.labelMode } : {},
360
+ ...ind.carTypes.length ? { carTypes: ind.carTypes } : {},
361
+ moduleIndustryId: ind.moduleIndustryId
362
+ }))
363
+ } : {},
343
364
  // Benchwork footprint outline (module-local inches); only when it's a real
344
365
  // ring (≥ 3 vertices).
345
366
  ...state.outline.length >= 3 ? { outline: state.outline } : {}
@@ -453,7 +474,19 @@ function docToState(doc, fallbackLength, moduleTracks = []) {
453
474
  divergeTrack: t.divergeTrack,
454
475
  kind: t.kind ?? "right"
455
476
  })),
456
- controlPoints: readControlPoints(d, sc)
477
+ controlPoints: readControlPoints(d, sc),
478
+ industries: (d.industries ?? []).map((ind) => ({
479
+ id: ind.id,
480
+ name: ind.name ?? "",
481
+ type: ind.type ?? "",
482
+ track: ind.track,
483
+ fromPos: sc(ind.fromPos ?? 0),
484
+ toPos: ind.toPos != null ? sc(ind.toPos) : len,
485
+ side: ind.side ?? "above",
486
+ labelMode: ind.labelMode ?? "none",
487
+ carTypes: Array.isArray(ind.carTypes) ? ind.carTypes : [],
488
+ moduleIndustryId: ind.moduleIndustryId ?? null
489
+ }))
457
490
  };
458
491
  }
459
492
  function readControlPoints(d, sc = (p) => p) {
@@ -752,6 +785,22 @@ function moduleFeatures(doc) {
752
785
  posFrac: clampFrac(e.at.pos),
753
786
  side: e.at.side === "down" ? "down" : "up"
754
787
  }));
788
+ const industries = (doc.industries ?? []).map((ind) => {
789
+ const from = ind.fromPos ?? 0;
790
+ const to = ind.toPos ?? len;
791
+ return {
792
+ id: ind.id,
793
+ name: ind.name ?? "",
794
+ type: ind.type ?? null,
795
+ fromFrac: clampFrac(Math.min(from, to)),
796
+ toFrac: clampFrac(Math.max(from, to)),
797
+ lane: trackLane.get(ind.track) ?? 0,
798
+ side: ind.side ?? "above",
799
+ labelMode: ind.labelMode ?? "none",
800
+ cars: carCapacity(from, to),
801
+ carTypes: Array.isArray(ind.carTypes) ? ind.carTypes : []
802
+ };
803
+ });
755
804
  const allLanes = [
756
805
  0,
757
806
  doubleMain ? 1 : 0,
@@ -792,6 +841,7 @@ function moduleFeatures(doc) {
792
841
  crossings,
793
842
  crossovers,
794
843
  branchConnectors,
844
+ industries,
795
845
  laneMin: Math.min(...allLanes),
796
846
  laneMax: Math.max(...allLanes)
797
847
  };
@@ -898,6 +948,7 @@ exports.FREEMO_ENDPLATE_WIDTH_MIN_INCHES = FREEMO_ENDPLATE_WIDTH_MIN_INCHES;
898
948
  exports.FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES = FREEMO_ENDPLATE_WIDTH_RECOMMENDED_INCHES;
899
949
  exports.MAIN2_TRACK_ID = MAIN2_TRACK_ID;
900
950
  exports.MAIN_TRACK_ID = MAIN_TRACK_ID;
951
+ exports.N_CAR_LENGTH_INCHES = N_CAR_LENGTH_INCHES;
901
952
  exports.N_SCALE_RATIO = N_SCALE_RATIO;
902
953
  exports.asModuleSchematic = asModuleSchematic;
903
954
  exports.benchworkBand = benchworkBand;
@@ -905,6 +956,7 @@ exports.benchworkOutline = benchworkOutline;
905
956
  exports.buildCrossover = buildCrossover;
906
957
  exports.buildPassingSiding = buildPassingSiding;
907
958
  exports.buildTransition = buildTransition;
959
+ exports.carCapacity = carCapacity;
908
960
  exports.deriveEndplatePoses = deriveEndplatePoses;
909
961
  exports.divergeSideForHand = divergeSideForHand;
910
962
  exports.docToState = docToState;