chore: added missing checkpoints data fallback for unknown sceneries

This commit is contained in:
2025-09-06 01:57:59 +02:00
parent fba335d0c7
commit bc1c446c37
4 changed files with 88 additions and 20 deletions
@@ -87,7 +87,8 @@ export default defineComponent({
const stop = train.timetableData?.followingStops.find( const stop = train.timetableData?.followingStops.find(
(stop) => (stop) =>
stop.stopNameRAW.toLowerCase() == name.toLowerCase() || stop.stopNameRAW.toLowerCase() == name.toLowerCase() ||
this.station?.generalInfo?.checkpoints.includes(stop.stopNameRAW) this.station?.generalInfo?.checkpoints.includes(stop.stopNameRAW) ||
this.onlineScenery?.missingCheckpoints.includes(stop.stopNameRAW)
); );
const sceneryName = const sceneryName =
+35 -13
View File
@@ -54,6 +54,18 @@
> >
</template> </template>
</div> </div>
<div class="timetable-checkpoints" v-else-if="onlineScenery">
<template v-for="(ch, i) in onlineScenery.missingCheckpoints" :key="i">
<template v-if="i > 0">&bull;</template>
<router-link
class="checkpoint-item"
:class="{ current: chosenCheckpoint === ch }"
:to="`/scenery?station=${onlineScenery.name}&checkpoint=${ch}`"
>{{ ch }}</router-link
>
</template>
</div>
</div> </div>
<div class="timetable-list"> <div class="timetable-list">
@@ -287,6 +299,7 @@ export default defineComponent({
const chosenCheckpoint = ref( const chosenCheckpoint = ref(
props.station?.generalInfo?.checkpoints[0] ?? props.station?.generalInfo?.checkpoints[0] ??
props.onlineScenery?.missingCheckpoints[0] ??
props.station?.name ?? props.station?.name ??
route.query['station']?.toString() ?? route.query['station']?.toString() ??
'' ''
@@ -365,21 +378,30 @@ export default defineComponent({
methods: { methods: {
loadSelectedOption() { loadSelectedOption() {
if (!this.station) return;
if (!this.station.generalInfo) {
this.chosenCheckpoint = this.station.name;
return;
}
const queryCheckpoint = this.$route.query['checkpoint']?.toString(); const queryCheckpoint = this.$route.query['checkpoint']?.toString();
this.chosenCheckpoint = let checkpointsListRef: string[] | null = null;
this.station.generalInfo.checkpoints.find( let sceneryName = '';
(ch) => ch.toLocaleLowerCase() === queryCheckpoint?.toLocaleLowerCase()
) ?? if (this.station && this.station.generalInfo) {
this.station.generalInfo.checkpoints[0] ?? checkpointsListRef = this.station.generalInfo.checkpoints;
this.station.name; sceneryName = this.station.name;
} else if (this.onlineScenery) {
checkpointsListRef = this.onlineScenery.missingCheckpoints;
sceneryName = this.onlineScenery.name;
} else if (this.station) {
this.chosenCheckpoint = this.station.name;
sceneryName = this.station.name;
}
if (checkpointsListRef) {
this.chosenCheckpoint =
checkpointsListRef.find(
(ch) => ch.toLocaleLowerCase() === queryCheckpoint?.toLocaleLowerCase()
) ??
checkpointsListRef[0] ??
sceneryName;
}
}, },
setCheckpoint(cp: string) { setCheckpoint(cp: string) {
+50 -6
View File
@@ -13,6 +13,7 @@ import { useApiStore } from './apiStore';
import { MainStoreState } from './typings'; import { MainStoreState } from './typings';
const checkpointsTrains: Map<string, CheckpointTrain[]> = new Map(); const checkpointsTrains: Map<string, CheckpointTrain[]> = new Map();
const unknownSceneryCheckpoints: Map<string, Set<string>> = new Map();
const sceneriesTrains: Map<string, Train[]> = new Map(); const sceneriesTrains: Map<string, Train[]> = new Map();
export const useMainStore = defineStore('mainStore', { export const useMainStore = defineStore('mainStore', {
@@ -42,6 +43,7 @@ export const useMainStore = defineStore('mainStore', {
checkpointsTrains.clear(); checkpointsTrains.clear();
sceneriesTrains.clear(); sceneriesTrains.clear();
unknownSceneryCheckpoints.clear();
const dateNow = new Date(); const dateNow = new Date();
@@ -133,8 +135,13 @@ export const useMainStore = defineStore('mainStore', {
// Checkpoints trains map // Checkpoints trains map
if (trainObj.timetableData) { if (trainObj.timetableData) {
let currentSceneryIndex = 0;
const timetablePath = trainObj.timetableData.timetablePath; const timetablePath = trainObj.timetableData.timetablePath;
let currentSceneryIndex = 0;
let currentSceneryData: Station | null =
this.stationList.find(
(s) => s.name == timetablePath[currentSceneryIndex].stationName
) ?? null;
trainObj.timetableData.followingStops.forEach((stop, i) => { trainObj.timetableData.followingStops.forEach((stop, i) => {
if (/strong|podg|pe/.test(stop.stopName)) { if (/strong|podg|pe/.test(stop.stopName)) {
@@ -153,16 +160,41 @@ export const useMainStore = defineStore('mainStore', {
timetablePathElement: timetablePath[currentSceneryIndex] timetablePathElement: timetablePath[currentSceneryIndex]
}; };
// Adding missing sceneries checkpoints as a fallback when scenery data is missing (and "generalInfo" is unavailable)
if (!currentSceneryData) {
const sceneryCheckpointsSet = unknownSceneryCheckpoints.get(
checkpointTrain.timetablePathElement.stationName
);
if (!sceneryCheckpointsSet) {
unknownSceneryCheckpoints.set(
checkpointTrain.timetablePathElement.stationName,
new Set([stop.stopNameRAW])
);
} else {
sceneryCheckpointsSet.add(stop.stopNameRAW);
}
}
// Adding trains to their corresponding checkpoints
if (checkpointsTrains.has(stop.stopNameRAW.toLowerCase())) { if (checkpointsTrains.has(stop.stopNameRAW.toLowerCase())) {
checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [ checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [
...checkpointsTrains.get(stop.stopNameRAW.toLowerCase())!, ...checkpointsTrains.get(stop.stopNameRAW.toLowerCase())!,
checkpointTrain checkpointTrain
]); ]);
} else checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [checkpointTrain]); } else {
checkpointsTrains.set(stop.stopNameRAW.toLowerCase(), [checkpointTrain]);
}
} }
if (timetablePath[currentSceneryIndex].departureRouteExt == stop.departureLine) if (timetablePath[currentSceneryIndex].departureRouteExt == stop.departureLine) {
currentSceneryIndex++; currentSceneryIndex++;
currentSceneryData =
this.stationList.find(
(s) => s.name == timetablePath[currentSceneryIndex].stationName
) ?? null;
}
}); });
} }
@@ -222,7 +254,9 @@ export const useMainStore = defineStore('mainStore', {
all: 0, all: 0,
confirmed: 0, confirmed: 0,
unconfirmed: 0 unconfirmed: 0
} },
missingCheckpoints: []
}); });
}); });
@@ -266,7 +300,9 @@ export const useMainStore = defineStore('mainStore', {
all: 0, all: 0,
confirmed: 0, confirmed: 0,
unconfirmed: 0 unconfirmed: 0
} },
missingCheckpoints: []
}); });
return list; return list;
@@ -277,7 +313,7 @@ export const useMainStore = defineStore('mainStore', {
for (let i = 0, n = allActiveSceneries.length; i < n; i++) { for (let i = 0, n = allActiveSceneries.length; i < n; i++) {
const scenery = allActiveSceneries[i]; const scenery = allActiveSceneries[i];
const station = this.stationList.find((s) => s.name === scenery.name); let station = this.stationList.find((s) => s.name === scenery.name);
let checkpointsSet: Set<string> = new Set(); let checkpointsSet: Set<string> = new Set();
@@ -293,6 +329,14 @@ export const useMainStore = defineStore('mainStore', {
scenery.stationTrains = scenery.stationTrains =
sceneriesTrains.get(scenery.name)?.filter((sc) => sc.region == this.region.id) ?? []; sceneriesTrains.get(scenery.name)?.filter((sc) => sc.region == this.region.id) ?? [];
// Missing checkpoints as a fallback for sceneries without generalInfo & checkpoints property
const missingCheckpointsToAdd = unknownSceneryCheckpoints.get(scenery.name);
if (missingCheckpointsToAdd) {
checkpoints.push(...missingCheckpointsToAdd);
scenery.missingCheckpoints.push(...missingCheckpointsToAdd);
}
const uniqueTrainIds: string[] = []; const uniqueTrainIds: string[] = [];
checkpoints.forEach((cp) => { checkpoints.forEach((cp) => {
const scheduledTrains = checkpointsTrains.get(cp.toLowerCase()); const scheduledTrains = checkpointsTrains.get(cp.toLowerCase());
+1
View File
@@ -170,6 +170,7 @@ export interface ActiveScenery {
confirmed: number; confirmed: number;
unconfirmed: number; unconfirmed: number;
}; };
missingCheckpoints: string[];
} }
export interface ScenerySpawn { export interface ScenerySpawn {