From fcac74277d31c96b04a70dce39acef7f2dc1f9d1 Mon Sep 17 00:00:00 2001 From: Scott Anderson <662325+scottanderson@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:49:23 -0400 Subject: [PATCH] Support more frame and industry names --- railroad.studio/style.css | 27 ++++++------ ts/RailroadMap.ts | 12 +++--- ts/frames.ts | 88 ++++++++++++++++++++++++++------------- ts/industries.ts | 31 +++++++++++--- 4 files changed, 102 insertions(+), 56 deletions(-) diff --git a/railroad.studio/style.css b/railroad.studio/style.css index 248538b..844f548 100644 --- a/railroad.studio/style.css +++ b/railroad.studio/style.css @@ -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; @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/ts/RailroadMap.ts b/ts/RailroadMap.ts index 9db9c5f..169f4dd 100644 --- a/ts/RailroadMap.ts +++ b/ts/RailroadMap.ts @@ -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'; @@ -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 @@ -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'); } diff --git a/ts/frames.ts b/ts/frames.ts index cadb77c..4df0ed4 100644 --- a/ts/frames.ts +++ b/ts/frames.ts @@ -12,7 +12,7 @@ export const frameTypes = [ 'class70', 'class70_tender', 'climax', - 'coach_dsprr_1', + 'Coach_DSPRR_1', 'cooke260', 'cooke260_new', 'cooke260_new_tender', @@ -20,19 +20,19 @@ export const frameTypes = [ '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', @@ -51,15 +51,15 @@ 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', @@ -67,11 +67,39 @@ export const frameTypes = [ 'waycar', ] as const satisfies ReadonlyArray; +/** + * Lookup table for legacy frame types. + */ +const legacyFrameMap: Record = { + '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 = Partial>>; @@ -390,7 +418,7 @@ export const frameDefinitions: Record = { name: 'Climax', }, - 'coach_dsprr_1': { + 'Coach_DSPRR_1': { length: 1420, max: { brakeValue: 1, @@ -582,7 +610,7 @@ export const frameDefinitions: Record = { name: 'D&RGW 33FT Gondola', }, - 'dspp_baggage': { + 'DSPP_baggage': { freight: true, length: 1400, max: { @@ -712,7 +740,7 @@ export const frameDefinitions: Record = { name: 'Hopper', }, - 'flatcar_logs': { + 'FlatCar_Logs': { freight: true, length: 818, max: { @@ -729,7 +757,7 @@ export const frameDefinitions: Record = { name: 'Flatcar Tier 1', }, - 'flatcar_stakes': { + 'FlatCar_Stakes': { freight: true, length: 785.6, max: { @@ -746,7 +774,7 @@ export const frameDefinitions: Record = { name: 'Flatcar Tier 2', }, - 'flatcar_tanker': { + 'FlatCar_Tanker': { freight: true, length: 804, max: { @@ -834,7 +862,7 @@ export const frameDefinitions: Record = { name: 'Handcar', }, - 'heisler': { + 'Heisler': { engine: true, length: 913.73, max: { @@ -1207,7 +1235,7 @@ export const frameDefinitions: Record = { name: 'Snow Plow', }, - 'porter_040': { + 'Porter_040': { engine: true, length: 391.2, max: { @@ -1235,7 +1263,7 @@ export const frameDefinitions: Record = { name: 'Porter', }, - 'porter_042': { + 'Porter_042': { engine: true, length: 461.35, max: { @@ -1261,7 +1289,7 @@ export const frameDefinitions: Record = { name: 'Porter 2', }, - 'rubybasin': { + 'Rubybasin': { coal: true, engine: true, length: 1029, @@ -1336,7 +1364,7 @@ export const frameDefinitions: Record = { name: 'Westside Lumber Co. Side Dump car', }, - 'skeletoncar': { + 'SkeletonCar': { freight: true, length: 635, max: { @@ -1353,7 +1381,7 @@ export const frameDefinitions: Record = { name: 'Skeleton Car', }, - 'stockcar': { + 'StockCar': { freight: true, length: 932, max: { @@ -1387,7 +1415,7 @@ export const frameDefinitions: Record = { name: 'Coffin Tank Car', }, - 'tenmile': { + 'Tenmile': { engine: true, length: 1174, max: { @@ -1647,7 +1675,7 @@ export const cargoLimits = { ['EFreightType::GoldOre']: 22, ['EFreightType::IronOre']: 22, }, - dspp_baggage: { + DSPP_baggage: { ['EFreightType::GoldIngot']: 5, ['EFreightType::RefinedGold']: 16, }, @@ -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, }, @@ -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, diff --git a/ts/industries.ts b/ts/industries.ts index 7fb34a4..6b8aad4 100644 --- a/ts/industries.ts +++ b/ts/industries.ts @@ -136,8 +136,15 @@ const legacyIndustryMap: Record = { 'logcamp': 'LogCamp', 'SandHouse': 'Sandhouse', 'sawmill': 'Sawmill', + 'telegraphoffice_foundation': 'telegraphoffice', + 'watertower_1870_style2_foundation': 'watertower_1870_style2', + 'watertower_1870_style3_foundation': 'watertower_1870_style3', + 'watertower_1870_style4_foundation': 'watertower_1870_style4', 'watertower_drgw': 'WaterTower_DRGW', + 'watertower_kanaskat_style1_foundation': 'watertower_kanaskat_style1', + 'watertower_kanaskat_style2_foundation': 'watertower_kanaskat_style2', 'watertower_small': 'WaterTower_Small', + 'watertower_small_foundation': 'WaterTower_Small', 'Waterwell': 'WaterWell', }; @@ -276,6 +283,18 @@ const waterTower = { 'building': rect(250, 250, 500, -500), }; +const waterTowerSmall = { + 'building': rect(200, 200, 400, -400), +}; + +const waterTowerKanaskat = { + 'building': rect(250, 150, 500, -300), +}; + +const waterTowerDrgw = { + 'building': circle(550, 0, 400), +}; + export const industrySvgPaths: Partial>> = { 'CattleFarm': { 'building': combine( @@ -534,12 +553,12 @@ export const industrySvgPaths: Partial