From 90b209995592216ce75365b3c5a06a0057822836 Mon Sep 17 00:00:00 2001 From: Spythere Date: Sat, 10 Feb 2024 22:42:35 +0100 Subject: [PATCH] checkpointy; hotfixy --- src/components/App/AppHeader.vue | 2 +- .../SceneryView/SceneryTimetable.vue | 15 ++-- src/components/StationsView/typings.ts | 5 +- src/data/options.json | 17 +++- src/locales/pl.json | 6 +- src/scripts/interfaces/Station.ts | 5 +- src/scripts/utils/filterUtils.ts | 7 +- src/store/mainStore.ts | 35 +++----- src/store/stationFiltersStore.ts | 2 + src/store/utils.ts | 89 ++++++------------- src/views/SceneryView.vue | 6 +- 11 files changed, 83 insertions(+), 106 deletions(-) diff --git a/src/components/App/AppHeader.vue b/src/components/App/AppHeader.vue index 4af3571..0bb6d90 100644 --- a/src/components/App/AppHeader.vue +++ b/src/components/App/AppHeader.vue @@ -101,7 +101,7 @@ export default defineComponent({ onlineDispatchersCount() { return this.store.activeSceneryList.filter( - (scenery) => scenery.region == this.store.region.id + (scenery) => scenery.region == this.store.region.id && scenery.dispatcherId != -1 ).length; }, diff --git a/src/components/SceneryView/SceneryTimetable.vue b/src/components/SceneryView/SceneryTimetable.vue index 662a37d..c9e0979 100644 --- a/src/components/SceneryView/SceneryTimetable.vue +++ b/src/components/SceneryView/SceneryTimetable.vue @@ -33,12 +33,12 @@ {{ (i > 0 && '•') || '' }} @@ -231,7 +231,7 @@ export default defineComponent({ const chosenCheckpoint = ref( props.station?.generalInfo?.checkpoints?.length == 0 ? '' - : props.station?.generalInfo?.checkpoints[0].checkpointName || null + : props.station?.generalInfo?.checkpoints[0] ?? null ); return { @@ -278,12 +278,11 @@ export default defineComponent({ loadSelectedOption() { if (!this.station) return; - this.chosenCheckpoint = - this.station.generalInfo?.checkpoints[0]?.checkpointName || this.station.name; + this.chosenCheckpoint = this.station.generalInfo?.checkpoints[0] ?? this.station.name; }, - setCheckpoint(cp: { checkpointName: string }) { - this.chosenCheckpoint = cp.checkpointName; + setCheckpoint(cp: string) { + this.chosenCheckpoint = cp; } } }); diff --git a/src/components/StationsView/typings.ts b/src/components/StationsView/typings.ts index f4848d0..d2192cd 100644 --- a/src/components/StationsView/typings.ts +++ b/src/components/StationsView/typings.ts @@ -42,14 +42,13 @@ export interface Filter { nonPublic: boolean; unavailable: boolean; abandoned: boolean; - endingStatus: boolean; afkStatus: boolean; noSpaceStatus: boolean; unavailableStatus: boolean; unsignedStatus: boolean; - authors: string; - onlineFromHours: number; + withActiveTimetables: boolean; + withoutActiveTimetables: boolean; } diff --git a/src/data/options.json b/src/data/options.json index 1b4a34a..87e654b 100644 --- a/src/data/options.json +++ b/src/data/options.json @@ -7,7 +7,8 @@ "addons", "blockades", "signals", - "status" + "status", + "timetables" ], "options": [ @@ -228,6 +229,20 @@ "section": "status", "value": true, "defaultValue": true + }, + { + "id": "withActiveTimetables", + "name": "withActiveTimetables", + "section": "timetables", + "value": true, + "defaultValue": true + }, + { + "id": "withoutActiveTimetables", + "name": "withoutActiveTimetables", + "section": "timetables", + "value": true, + "defaultValue": true } ], "sliders": [ diff --git a/src/locales/pl.json b/src/locales/pl.json index c54b56d..524017e 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -165,7 +165,8 @@ "signals": "TYP SYGNALIZACJI", "addons": "DODATKOWE PROGRAMY", "blockades": "BLOKADY LINIOWE", - "status": "STATUS ONLINE" + "status": "STATUS ONLINE", + "timetables": "AKTYWNE ROZKŁADY JAZDY" }, "all-available": "WSZYSTKIE DOSTĘPNE", @@ -209,6 +210,9 @@ "free": "WOLNA", "occupied": "ZAJĘTA", + "withActiveTimetables": "AKTYWNE RJ", + "withoutActiveTimetables": "BEZ AKTYWNYCH RJ", + "sliders": { "min-lvl": "MIN. WYMAGANY POZIOM DYŻURNEGO", "max-lvl": "MAKS. WYMAGANY POZIOM DYŻURNEGO", diff --git a/src/scripts/interfaces/Station.ts b/src/scripts/interfaces/Station.ts index 36e2dc4..ad34922 100644 --- a/src/scripts/interfaces/Station.ts +++ b/src/scripts/interfaces/Station.ts @@ -26,10 +26,7 @@ export default interface Station { availability: Availability; routes: StationRoutes; - checkpoints: { - checkpointName: string; - scheduledTrains: ScheduledTrain[]; - }[]; + checkpoints: string[]; }; onlineInfo?: ActiveScenery; diff --git a/src/scripts/utils/filterUtils.ts b/src/scripts/utils/filterUtils.ts index f669c9e..bcb6693 100644 --- a/src/scripts/utils/filterUtils.ts +++ b/src/scripts/utils/filterUtils.ts @@ -93,7 +93,7 @@ export const sortStations = ( }; export const filterStations = (station: Station, filters: Filter) => { - if (!station.onlineInfo && filters['free']) return false; + if (filters['free'] && !station.onlineInfo) return false; if (station.onlineInfo) { const { dispatcherStatus } = station.onlineInfo; @@ -112,7 +112,10 @@ export const filterStations = (station: Station, filters: Filter) => { const isOccupied = station.onlineInfo && filters['occupied']; - if (isEnding || isNotSigned || isAFK || isNoSpace || isOccupied) return false; + const isActiveFree = + dispatcherStatus == Status.ActiveDispatcher.FREE && filters['withActiveTimetables']; + + if (isEnding || isNotSigned || isAFK || isNoSpace || isOccupied || isActiveFree) return false; if ( filters['onlineFromHours'] > 0 && diff --git a/src/store/mainStore.ts b/src/store/mainStore.ts index dc93187..c9d7fd6 100644 --- a/src/store/mainStore.ts +++ b/src/store/mainStore.ts @@ -166,31 +166,28 @@ export const useMainStore = defineStore('store', { dispatcherId: scenery.dispatcherId, dispatcherExp: scenery.dispatcherExp, dispatcherIsSupporter: scenery.dispatcherIsSupporter, + dispatcherStatus: scenery.dispatcherStatus, + dispatcherTimestamp: dispatcherTimestamp, + + isOnline: scenery.isOnline == 1, + scheduledTrains: [], stationTrains: [], scheduledTrainCount: { all: 0, confirmed: 0, unconfirmed: 0 - }, - // scheduledTrains: scheduledTrains, - // stationTrains: stationTrains, - dispatcherStatus: scenery.dispatcherStatus, - dispatcherTimestamp: dispatcherTimestamp, - - isOnline: scenery.isOnline == 1 - - // scheduledTrainCount: { - // all: uniqueScheduledTrains.length, - // confirmed: uniqueScheduledTrains.filter((train) => train.stopInfo.confirmed).length, - // unconfirmed: uniqueScheduledTrains.filter((train) => !train.stopInfo.confirmed).length - // } + } }); return list; }, [] as ActiveScenery[]); - [...onlineActiveSceneries, ...offlineActiveSceneries].forEach((scenery) => { + const allActiveSceneries = [...onlineActiveSceneries, ...offlineActiveSceneries]; + + for (let i = 0, n = allActiveSceneries.length; i < n; i++) { + const scenery = allActiveSceneries[i]; + const station = this.stationList.find((s) => s.name === scenery.name); const scheduledTrains = getScheduledTrains( @@ -224,11 +221,11 @@ export const useMainStore = defineStore('store', { confirmed: uniqueScheduledTrains.filter((train) => train.stopInfo.confirmed).length, unconfirmed: uniqueScheduledTrains.filter((train) => !train.stopInfo.confirmed).length }; - }); + } console.timeEnd('d'); - return [...onlineActiveSceneries, ...offlineActiveSceneries]; + return allActiveSceneries; }, stationList(): Station[] { @@ -268,11 +265,7 @@ export const useMainStore = defineStore('store', { ...scenery, authors: scenery.authors?.split(',').map((a) => a.trim()), routes: routes, - checkpoints: scenery.checkpoints - ? scenery.checkpoints - .split(';') - .map((sub) => ({ checkpointName: sub, scheduledTrains: [] })) - : [] + checkpoints: scenery.checkpoints?.split(';') ?? [] } }; }); diff --git a/src/store/stationFiltersStore.ts b/src/store/stationFiltersStore.ts index 80399f3..cc9a253 100644 --- a/src/store/stationFiltersStore.ts +++ b/src/store/stationFiltersStore.ts @@ -48,6 +48,8 @@ const filterInitStates: Filter = { noSpaceStatus: false, unavailableStatus: false, unsignedStatus: false, + withActiveTimetables: false, + withoutActiveTimetables: false, authors: '', diff --git a/src/store/utils.ts b/src/store/utils.ts index 8cd25ab..b1db41c 100644 --- a/src/store/utils.ts +++ b/src/store/utils.ts @@ -102,51 +102,33 @@ export function getCheckpointTrain( let prevStationName = '', nextStationName = ''; - let prevDepartureLine: string | null = null, - nextArrivalLine: string | null = null; - - for (let i = trainStopIndex - 1; i >= 0; i--) { - if (/strong|podg/g.test(followingStops[i].stopName)) { - prevStationName = followingStops[i].stopNameRAW.replace(/,.*/g, ''); - - break; - } - } - - for (let i = trainStopIndex + 1; i < followingStops.length; i++) { - if (/strong|podg/g.test(followingStops[i].stopName)) { - nextStationName = followingStops[i].stopNameRAW.replace(/,.*/g, ''); - - break; - } - } - let departureLine: string | null = null; let arrivingLine: string | null = null; - for (let i = trainStopIndex; i < followingStops.length; i++) { - const currentStop = followingStops[i]; + let prevDepartureLine: string | null = null, + nextArrivalLine: string | null = null; - if (currentStop.departureLine == null) continue; + for (let i = trainStopIndex; i >= 0; i--) { + const stop = followingStops[i]; - if (!/-|_|it|sbl/gi.test(currentStop.departureLine)) { - departureLine = currentStop.departureLine; - nextArrivalLine = followingStops[i + 1]?.arrivalLine || null; + if (/strong|podg/g.test(stop.stopName) && !prevStationName && i <= trainStopIndex - 1) + prevStationName = stop.stopNameRAW.replace(/,.*/g, ''); - break; + if (stop.arrivalLine != null && !arrivingLine && !/-|_|it|sbl/gi.test(stop.arrivalLine)) { + arrivingLine = stop.arrivalLine; + prevDepartureLine = followingStops[i - 1]?.departureLine || null; } } - for (let i = trainStopIndex; i >= 0; i--) { - const currentStop = followingStops[i]; + for (let i = trainStopIndex; i < followingStops.length; i++) { + const stop = followingStops[i]; - if (currentStop.arrivalLine == null) continue; + if (/strong|podg/g.test(stop.stopName) && !nextStationName && i > trainStopIndex) + nextStationName = stop.stopNameRAW.replace(/,.*/g, ''); - if (!/-|_|it|sbl/gi.test(currentStop.arrivalLine)) { - arrivingLine = currentStop.arrivalLine; - prevDepartureLine = followingStops[i - 1]?.departureLine || null; - - break; + if (stop.departureLine && !departureLine && !/-|_|it|sbl/gi.test(stop.departureLine)) { + departureLine = stop.departureLine; + nextArrivalLine = followingStops[i + 1]?.arrivalLine || null; } } @@ -177,8 +159,8 @@ export function getCheckpointTrain( region: train.region, - arrivingLine, - departureLine, + arrivingLine: arrivingLine, + departureLine: departureLine, nextArrivalLine, prevDepartureLine @@ -192,7 +174,7 @@ export function getScheduledTrains( region: string // sceneryData: API.ActiveSceneries.Data, ): ScheduledTrain[] { - stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0)); + // stationGeneralInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0)); return trainList.reduce((acc: ScheduledTrain[], train) => { if (!train.timetableData) return acc; @@ -201,32 +183,19 @@ export function getScheduledTrains( const timetable = train.timetableData; if (!timetable.sceneryNames.includes(stationName)) return acc; - const stopInfoIndex = timetable.followingStops.findIndex((stop) => { - return stationName.toLocaleLowerCase() == stop.stopNameRAW.toLocaleLowerCase(); - }); + const checkpoints = [stationName]; + if (stationGeneralInfo?.checkpoints) checkpoints.push(...stationGeneralInfo.checkpoints); const checkpointScheduledTrains: ScheduledTrain[] = []; - - if (stopInfoIndex != -1) { - checkpointScheduledTrains.push(getCheckpointTrain(train, stopInfoIndex, stationName)); - } - - stationGeneralInfo?.checkpoints?.forEach((checkpoint) => { + for (let i = 0; i < timetable.followingStops.length; i++) { if ( - checkpointScheduledTrains.findIndex( - (cpTrain) => - cpTrain.checkpointName.toLocaleLowerCase() == - checkpoint.checkpointName.toLocaleLowerCase() - ) != -1 - ) - return; - - const index = timetable.followingStops.findIndex( - (stop) => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase() - ); - - if (index > -1) checkpointScheduledTrains.push(getCheckpointTrain(train, index, stationName)); - }); + new RegExp(`^(${checkpoints.join('|')})$`, 'i').test( + timetable.followingStops[i].stopNameRAW + ) + ) { + checkpointScheduledTrains.push(getCheckpointTrain(train, i, stationName)); + } + } acc.push(...checkpointScheduledTrains); return acc; diff --git a/src/views/SceneryView.vue b/src/views/SceneryView.vue index 90b6f43..36b275f 100644 --- a/src/views/SceneryView.vue +++ b/src/views/SceneryView.vue @@ -169,11 +169,7 @@ export default defineComponent({ loadSelectedCheckpoint() { if (!this.stationInfo?.generalInfo?.checkpoints) return; if (this.stationInfo.generalInfo.checkpoints.length == 0) return; - this.selectedCheckpoint = this.stationInfo.generalInfo.checkpoints[0].checkpointName; - }, - - selectCheckpoint(cp: { checkpointName: string }) { - this.selectedCheckpoint = cp.checkpointName; + this.selectedCheckpoint = this.stationInfo.generalInfo.checkpoints[0]; } } });