aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/RenderUtil.ts
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar 7222e800-c703-472d-a787-71b6b5cba4ef <memestrogenzone>2025-09-14 17:20:55 +0000
committerLibravatarLarge Libravatar 7222e800-c703-472d-a787-71b6b5cba4ef <memestrogenzone>2025-09-14 17:20:55 +0000
commitea68e415925946b44fa645bbf3f6087f48fe63cf (patch)
tree0a2c486a344a0db366e77339ef9f39f754c0aa12 /src/lib/RenderUtil.ts
parent75c9e412287ace0801d752ce731824243d7c8b53 (diff)
downloadfahrplan-ea68e415925946b44fa645bbf3f6087f48fe63cf.tar.gz
fahrplan-ea68e415925946b44fa645bbf3f6087f48fe63cf.tar.bz2
fahrplan-ea68e415925946b44fa645bbf3f6087f48fe63cf.tar.lz
fahrplan-ea68e415925946b44fa645bbf3f6087f48fe63cf.zip

refactor: Move a lot of inline shit out of Timetable.svelte

Diffstat (limited to 'src/lib/RenderUtil.ts')
-rw-r--r--src/lib/RenderUtil.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/lib/RenderUtil.ts b/src/lib/RenderUtil.ts
new file mode 100644
index 0000000..c6963bc
--- /dev/null
+++ b/src/lib/RenderUtil.ts
@@ -0,0 +1,85 @@
+import { Mode, type StopTime } from './motis-types';
+import { m } from './paraglide/messages';
+
+export const getPictogram = (mode: Mode) => {
+ switch (true) {
+ case mode === Mode.Bike:
+ return 'Velo_l';
+ case mode === Mode.ODM:
+ case mode === Mode.Rental:
+ return 'Taxi_l';
+ case mode === Mode.Car:
+ case mode === Mode.CarDropoff:
+ case mode === Mode.CarParking:
+ return 'Auto_l';
+
+ // Transit //
+ case mode === Mode.Airplane:
+ return 'Abflug_l';
+ case mode === Mode.LongDistanceRail:
+ case mode === Mode.RegionalFastRail:
+ case mode === Mode.RegionalRail:
+ case mode === Mode.Metro:
+ case mode === Mode.HighspeedRail:
+ return 'Zug_l';
+ case mode === Mode.NightRail:
+ return 'Schlafwagen';
+ case mode === Mode.Subway:
+ return 'Metro_l_' + (m.lang_short() === 'en' ? 'de' : m.lang_short());
+ case mode === Mode.Bus:
+ return 'Bus_l';
+ case mode === Mode.Coach:
+ return 'Fernbus_l';
+ case mode === Mode.Tram:
+ case mode === Mode.CableTram:
+ return 'Tram_l';
+ case mode === Mode.Funicular:
+ return 'Zahnradbahn_l';
+ case mode === Mode.AerialLift:
+ // return 'Gondelbahn_l';
+ return 'Luftseilbahn_l';
+ case mode === Mode.Ferry:
+ return 'Schiff_l';
+ case mode === Mode.Other:
+ default:
+ return 'Licht';
+ }
+};
+export const stopTimeToShortName = (stopTime: StopTime) => {
+ let n = stopTime.routeShortName;
+ if (n.startsWith('EC ')) n = n.replace('EC ', 'EC');
+ if (stopTime.mode === 'TRAM' && !isNaN(parseInt(n))) n = 'T ' + n;
+ if (stopTime.mode === 'BUS' && !isNaN(parseInt(n))) n = 'B ' + n;
+ if (
+ stopTime.routeShortName === 'European Sleeper' &&
+ stopTime.agencyName === 'Eu Sleeper'
+ )
+ n = 'EN'; // TODO: validate these are real euronights
+ if (n === '?') n = '';
+ if (n.startsWith('FlixTrain ')) n = n.substring(10);
+ // Note: may also catch ECs/ICs/EXTs operated by DB
+ if (
+ stopTime.agencyId === '12681' &&
+ stopTime.agencyName === 'DB Fernverkehr AG' &&
+ stopTime.mode === 'HIGHSPEED_RAIL' &&
+ stopTime.source.startsWith('de_DELFI.gtfs.zip/') &&
+ !isNaN(parseInt(n))
+ )
+ n = `ICE ${n}`;
+ return n;
+};
+export const stopTimeShouldRenderGlyph = (
+ stopTime: StopTime,
+ routeShortName: string
+) =>
+ ([
+ Mode.NightRail,
+ Mode.HighspeedRail,
+ Mode.LongDistanceRail,
+ Mode.RegionalFastRail,
+ Mode.RegionalRail,
+ ].includes(stopTime.mode) ||
+ (stopTime.mode === 'BUS' && routeShortName.startsWith('EV')) ||
+ (stopTime.mode === 'METRO' && stopTime.routeShortName.startsWith('S'))) &&
+ !stopTime.routeShortName.startsWith('FlixTrain');
+export const blacklistedAgencyURLs = ['http://www.rta.ae'];