Skip to content

Commit

Permalink
Support more frame and industry names
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson committed Oct 5, 2024
1 parent 78f75b3 commit fcac742
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 56 deletions.
27 changes: 14 additions & 13 deletions railroad.studio/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
--telegraph-office: #fc0;
--coaling-tower: #fc0;
--building-beige: #cc9;
--building-old: #663;
--building-old: #669;
--fence-fill: transparent;
--fence-stroke: black;
--walkway-stroke: black;
Expand Down Expand Up @@ -362,17 +362,17 @@ body {

.frame.boxcar { fill: var(--boxcar); }
.frame.boxcar.cargo-loaded { fill: var(--boxcar-loaded); }
.frame.coach_dsprr_1 { fill: var(--coach); }
.frame.Coach_DSPRR_1 { fill: var(--coach); }
.frame.flatcar_cordwood { fill: var(--flatcar-cordwood); }
.frame.flatcar_cordwood.cargo-loaded { fill: var(--flatcar-cordwood-loaded); }
.frame.flatcar_hopper { fill: var(--flatcar-hopper); }
.frame.flatcar_hopper.cargo-loaded { fill: var(--flatcar-hopper-loaded); }
.frame.flatcar_logs { fill: var(--flatcar-logs); }
.frame.flatcar_logs.cargo-loaded { fill: var(--flatcar-logs-loaded); }
.frame.flatcar_stakes { fill: var(--flatcar-stakes); }
.frame.flatcar_stakes.cargo-loaded { fill: var(--flatcar-stakes-loaded); }
.frame.flatcar_tanker { fill: var(--flatcar-tanker); }
.frame.flatcar_tanker.cargo-loaded { fill: var(--flatcar-tanker-loaded); }
.frame.FlatCar_Logs { fill: var(--flatcar-logs); }
.frame.FlatCar_Logs.cargo-loaded { fill: var(--flatcar-logs-loaded); }
.frame.FlatCar_Stakes { fill: var(--flatcar-stakes); }
.frame.FlatCar_Stakes.cargo-loaded { fill: var(--flatcar-stakes-loaded); }
.frame.FlatCar_Tanker { fill: var(--flatcar-tanker); }
.frame.FlatCar_Tanker.cargo-loaded { fill: var(--flatcar-tanker-loaded); }
.frame.hopperBB { fill: var(--flatcar-hopper); }
.frame.hopperBB.cargo-loaded { fill: var(--flatcar-hopper-loaded); }
.frame.OahuWaterCar { fill: var(--flatcar-tanker); }
Expand All @@ -396,10 +396,10 @@ body {
.frame.plantationcar_tanker { fill: var(--flatcar-tanker); }
.frame.plantationcar_tanker.cargo-loaded { fill: var(--flatcar-tanker-loaded); }
.frame.plow { fill: var(--plow); }
.frame.skeletoncar { fill: var(--flatcar-logs); }
.frame.skeletoncar.cargo-loaded { fill: var(--flatcar-logs-loaded); }
.frame.stockcar { fill: var(--boxcar); }
.frame.stockcar.cargo-loaded { fill: var(--boxcar-loaded); }
.frame.SkeletonCar { fill: var(--flatcar-logs); }
.frame.SkeletonCar.cargo-loaded { fill: var(--flatcar-logs-loaded); }
.frame.StockCar { fill: var(--boxcar); }
.frame.StockCar.cargo-loaded { fill: var(--boxcar-loaded); }
.frame.tankcarNCO { fill: var(--flatcar-tanker); }
.frame.tankcarNCO.cargo-loaded { fill: var(--flatcar-tanker-loaded); }
.frame.VentilatedBoxcarCC { fill: var(--boxcar); }
Expand Down Expand Up @@ -469,7 +469,7 @@ body {
stroke: var(--pond-stroke);
}

.industry.coaltower .building { fill: var(--coaling-tower); }
.industry.CoalTower .building { fill: var(--coaling-tower); }
.industry.enginehouse_alpine .building { fill: var(--engine-house-lightblue); }
.industry.enginehouse_aspen .building { fill: var(--engine-house-gold); }
.industry.enginehouse_barn .building { fill: var(--engine-house-red); }
Expand All @@ -488,6 +488,7 @@ body {
.industry.watertower_kanaskat_style2 .building { fill: var(--engine-house-brown); }
.industry.watertower_kanaskat_style3 .building { fill: var(--building-beige); }
.industry.watertower_kanaskat_style4 .building { fill: var(--building-old); }
.industry.WaterTower_Small .building { fill: var(--building-beige); }

.gizmo .x { fill: var(--engine-house-red); }
.gizmo .y { fill: var(--boxcar); }
Expand Down
12 changes: 5 additions & 7 deletions ts/RailroadMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {gvasToString} from './Gvas';
import {Vector, scaleVector, vectorSum, distanceSquared, normalizeVector, distance} from './Vector';
import {MergeLimits, normalizeAngle, splineHeading, vectorHeading} from './splines';
import {flattenSpline} from './tool-flatten';
import {CargoType, cargoLimits, frameDefinitions, hasCargoLimits, isCargoType, isFrameType} from './frames';
import {CargoType, cargoLimits, frameDefinitions, getFrameType, hasCargoLimits, isCargoType} from './frames';
import {handleError} from './index';
import {parallelSpline, parallelSplineTrack} from './tool-parallel';
import {asyncForEach} from './util-async';
Expand Down Expand Up @@ -946,11 +946,9 @@ export class RailroadMap {
}

private renderFrame(frame: Frame) {
if (!isFrameType(frame.type)) {
console.log(`Unknown frame type ${frame.type}`);
return;
}
const definition = frameDefinitions[frame.type];
const frameType = getFrameType(frame.type);
if (frameType === null) return;
const definition = frameDefinitions[frameType];
const g = this.layers.frames.group()
.attr('transform', makeTransform(frame.location.x, frame.location.y, frame.rotation.yaw));
// Frame outline
Expand All @@ -960,7 +958,7 @@ export class RailroadMap {
.center(0, 0)
.on('click', onClick)
.addClass('frame')
.addClass(frame.type);
.addClass(frameType);
if (frame.state.brakeValue > 0) {
f.addClass('brakes-applied');
}
Expand Down
88 changes: 58 additions & 30 deletions ts/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ export const frameTypes = [
'class70',
'class70_tender',
'climax',
'coach_dsprr_1',
'Coach_DSPRR_1',
'cooke260',
'cooke260_new',
'cooke260_new_tender',
'cooke260_tender',
'cooke280',
'cooke280_tender',
'DRGW_Gondola_33FT',
'dspp_baggage',
'DSPP_baggage',
'eureka',
'eureka_tender',
'Ferries242T',
'flatcar_cordwood',
'flatcar_hopper',
'flatcar_logs',
'flatcar_stakes',
'flatcar_tanker',
'FlatCar_Logs',
'FlatCar_Stakes',
'FlatCar_Tanker',
'glenbrook',
'glenbrook_tender',
'handcar',
'heisler',
'Heisler',
'hopperBB',
'lima280',
'lima280_tender',
Expand All @@ -51,27 +51,55 @@ export const frameTypes = [
'plantationcar_hopper_small',
'plantationcar_tanker',
'plow',
'porter_040',
'porter_042',
'rubybasin',
'Porter_040',
'Porter_042',
'Rubybasin',
'shay',
'SideDumpCar',
'skeletoncar',
'stockcar',
'SkeletonCar',
'StockCar',
'tankcarNCO',
'tenmile',
'Tenmile',
'tweetsie280',
'tweetsie280_tender',
'VentilatedBoxcarCC',
'WaterCar',
'waycar',
] as const satisfies ReadonlyArray<string>;

/**
* Lookup table for legacy frame types.
*/
const legacyFrameMap: Record<string, FrameType> = {
'class47_tender': 'Class47_Tender',
'coach_dsprr_1': 'Coach_DSPRR_1',
'drgw_gondola_33ft': 'DRGW_Gondola_33FT',
'dspp_baggage': 'DSPP_baggage',
'flatcar_logs': 'FlatCar_Logs',
'flatcar_stakes': 'FlatCar_Stakes',
'flatcar_tanker': 'FlatCar_Tanker',
'heisler': 'Heisler',
'porter_040': 'Porter_040',
'porter_042': 'Porter_042',
'rubybasin': 'Rubybasin',
'skeletoncar': 'SkeletonCar',
'stockcar': 'StockCar',
'tenmile': 'Tenmile',
};

type FrameType = typeof frameTypes[number];

export const isFrameType = (type: GvasString): type is FrameType =>
type ? frameTypes.includes(type) : false;

export function getFrameType(type: GvasString): FrameType | null {
if (isFrameType(type)) return type;
if (type === null) return null;
if (type in legacyFrameMap) return legacyFrameMap[type];
console.warn(`Unrecognized frame type ${type}`);
return null;
}

export const frameCategories = ['engine', 'tender', 'freight', 'passenger', 'mow', 'handcar'] as const;

type PRO<K extends string | number | symbol, T> = Partial<Readonly<Record<K, T>>>;
Expand Down Expand Up @@ -390,7 +418,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Climax',
},

'coach_dsprr_1': {
'Coach_DSPRR_1': {
length: 1420,
max: {
brakeValue: 1,
Expand Down Expand Up @@ -582,7 +610,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'D&RGW 33FT Gondola',
},

'dspp_baggage': {
'DSPP_baggage': {
freight: true,
length: 1400,
max: {
Expand Down Expand Up @@ -712,7 +740,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Hopper',
},

'flatcar_logs': {
'FlatCar_Logs': {
freight: true,
length: 818,
max: {
Expand All @@ -729,7 +757,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Flatcar Tier 1',
},

'flatcar_stakes': {
'FlatCar_Stakes': {
freight: true,
length: 785.6,
max: {
Expand All @@ -746,7 +774,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Flatcar Tier 2',
},

'flatcar_tanker': {
'FlatCar_Tanker': {
freight: true,
length: 804,
max: {
Expand Down Expand Up @@ -834,7 +862,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Handcar',
},

'heisler': {
'Heisler': {
engine: true,
length: 913.73,
max: {
Expand Down Expand Up @@ -1207,7 +1235,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Snow Plow',
},

'porter_040': {
'Porter_040': {
engine: true,
length: 391.2,
max: {
Expand Down Expand Up @@ -1235,7 +1263,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Porter',
},

'porter_042': {
'Porter_042': {
engine: true,
length: 461.35,
max: {
Expand All @@ -1261,7 +1289,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Porter 2',
},

'rubybasin': {
'Rubybasin': {
coal: true,
engine: true,
length: 1029,
Expand Down Expand Up @@ -1336,7 +1364,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Westside Lumber Co. Side Dump car',
},

'skeletoncar': {
'SkeletonCar': {
freight: true,
length: 635,
max: {
Expand All @@ -1353,7 +1381,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Skeleton Car',
},

'stockcar': {
'StockCar': {
freight: true,
length: 932,
max: {
Expand Down Expand Up @@ -1387,7 +1415,7 @@ export const frameDefinitions: Record<FrameType, FrameDefinition> = {
name: 'Coffin Tank Car',
},

'tenmile': {
'Tenmile': {
engine: true,
length: 1174,
max: {
Expand Down Expand Up @@ -1647,7 +1675,7 @@ export const cargoLimits = {
['EFreightType::GoldOre']: 22,
['EFreightType::IronOre']: 22,
},
dspp_baggage: {
DSPP_baggage: {
['EFreightType::GoldIngot']: 5,
['EFreightType::RefinedGold']: 16,
},
Expand All @@ -1662,19 +1690,19 @@ export const cargoLimits = {
['EFreightType::IronOre']: 10,
['EFreightType::None']: 0,
},
flatcar_logs: {
FlatCar_Logs: {
['EFreightType::Log']: 6,
['EFreightType::None']: 0,
['EFreightType::SteelPipe']: 9,
},
flatcar_stakes: {
FlatCar_Stakes: {
['EFreightType::Beam']: 3,
['EFreightType::Lumber']: 6,
['EFreightType::None']: 0,
['EFreightType::Rail']: 10,
['EFreightType::RawIron']: 3,
},
flatcar_tanker: {
FlatCar_Tanker: {
['EFreightType::CrudeOil']: 12,
['EFreightType::None']: 0,
},
Expand Down Expand Up @@ -1740,11 +1768,11 @@ export const cargoLimits = {
['EFreightType::GoldOre']: 6,
['EFreightType::IronOre']: 6,
},
skeletoncar: {
SkeletonCar: {
['EFreightType::Log']: 5,
['EFreightType::None']: 0,
},
stockcar: {
StockCar: {
['EFreightType::Cattle']: 6,
['EFreightType::CrateTools']: 32,
['EFreightType::None']: 0,
Expand Down
Loading

0 comments on commit fcac742

Please sign in to comment.