mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
Zmiana API z danymi scenerii
This commit is contained in:
@@ -25,29 +25,29 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
v-if="station.generalInfo.default"
|
|
||||||
class="icon-info"
|
class="icon-info"
|
||||||
:src="icons.td2"
|
v-if="station.generalInfo.availability == 'nonPublic'"
|
||||||
alt="default scenery"
|
|
||||||
:title="$t('desc.default')"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<img
|
|
||||||
class="icon-info"
|
|
||||||
v-if="station.generalInfo.nonPublic"
|
|
||||||
:src="icons.lock"
|
:src="icons.lock"
|
||||||
alt="non public scenery"
|
alt="Non-public scenery"
|
||||||
:title="$t('desc.non-public')"
|
:title="$t('desc.non-public')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
class="icon-info"
|
class="icon-info"
|
||||||
v-if="station.generalInfo.unavailable"
|
v-if="station.generalInfo.availability == 'unavailable'"
|
||||||
:src="icons.unavailable"
|
:src="icons.unavailable"
|
||||||
alt="icon unavailable"
|
alt="Unavailable scenery"
|
||||||
:title="$t('desc.unavailable')"
|
:title="$t('desc.unavailable')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<img
|
||||||
|
class="icon-info"
|
||||||
|
v-if="station.generalInfo.availability == 'abandoned'"
|
||||||
|
:src="icons.abandoned"
|
||||||
|
alt="Abandoned scenery"
|
||||||
|
:title="$t('desc.abandoned')"
|
||||||
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
class="icon-info"
|
class="icon-info"
|
||||||
v-if="station.generalInfo && station.generalInfo.lines != ''"
|
v-if="station.generalInfo && station.generalInfo.lines != ''"
|
||||||
@@ -81,6 +81,7 @@ export default defineComponent({
|
|||||||
lock: require('@/assets/icon-lock.svg'),
|
lock: require('@/assets/icon-lock.svg'),
|
||||||
unavailable: require('@/assets/icon-unavailable.svg'),
|
unavailable: require('@/assets/icon-unavailable.svg'),
|
||||||
unknown: require('@/assets/icon-unknown.svg'),
|
unknown: require('@/assets/icon-unknown.svg'),
|
||||||
|
abandoned: require('@/assets/icon-abandoned.svg'),
|
||||||
|
|
||||||
real: require('@/assets/icon-real.svg'),
|
real: require('@/assets/icon-real.svg'),
|
||||||
},
|
},
|
||||||
@@ -89,7 +90,7 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "../../../styles/icons.scss";
|
@import '../../../styles/icons.scss';
|
||||||
.info-icons {
|
.info-icons {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -50,12 +50,7 @@
|
|||||||
>
|
>
|
||||||
<td
|
<td
|
||||||
class="station_name"
|
class="station_name"
|
||||||
:class="{
|
:class="station.generalInfo?.availability"
|
||||||
default: station.generalInfo?.default,
|
|
||||||
'non-public': station.generalInfo?.nonPublic,
|
|
||||||
online: station.onlineInfo,
|
|
||||||
unavailable: station.generalInfo?.unavailable,
|
|
||||||
}"
|
|
||||||
>
|
>
|
||||||
<b v-if="station.generalInfo?.project" style="color: salmon">{{ station.generalInfo.project }}</b>
|
<b v-if="station.generalInfo?.project" style="color: salmon">{{ station.generalInfo.project }}</b>
|
||||||
{{ station.name }}
|
{{ station.name }}
|
||||||
@@ -66,19 +61,19 @@
|
|||||||
<span
|
<span
|
||||||
v-if="
|
v-if="
|
||||||
station.generalInfo.reqLevel > -1 &&
|
station.generalInfo.reqLevel > -1 &&
|
||||||
!station.generalInfo.nonPublic &&
|
station.generalInfo.availability != 'nonPublic' &&
|
||||||
!station.generalInfo.unavailable
|
station.generalInfo.availability != 'unavailable'
|
||||||
"
|
"
|
||||||
:style="calculateExpStyle(station.generalInfo.reqLevel)"
|
:style="calculateExpStyle(station.generalInfo.reqLevel)"
|
||||||
>
|
>
|
||||||
{{ station.generalInfo.reqLevel >= 2 ? station.generalInfo.reqLevel : 'L' }}
|
{{ station.generalInfo.reqLevel >= 2 ? station.generalInfo.reqLevel : 'L' }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span v-else-if="station.generalInfo.abandoned">
|
<span v-else-if="station.generalInfo.availability == 'abandoned'">
|
||||||
<img :src="abandonedIcon" alt="non-public" :title="$t('desc.abandoned')" />
|
<img :src="abandonedIcon" alt="non-public" :title="$t('desc.abandoned')" />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span v-else-if="station.generalInfo.nonPublic">
|
<span v-else-if="station.generalInfo.availability == 'nonPublic'">
|
||||||
<img :src="lockIcon" alt="non-public" :title="$t('desc.non-public')" />
|
<img :src="lockIcon" alt="non-public" :title="$t('desc.non-public')" />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -432,7 +427,7 @@ td.station {
|
|||||||
color: $accentCol;
|
color: $accentCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.non-public {
|
&.nonPublic {
|
||||||
color: #bebebe;
|
color: #bebebe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Availability } from "@/store/types";
|
||||||
import ScheduledTrain from "./ScheduledTrain";
|
import ScheduledTrain from "./ScheduledTrain";
|
||||||
import StationRoutes from "./StationRoutes";
|
import StationRoutes from "./StationRoutes";
|
||||||
|
|
||||||
@@ -19,11 +20,7 @@ export default interface Station {
|
|||||||
|
|
||||||
SUP: boolean;
|
SUP: boolean;
|
||||||
|
|
||||||
default: boolean;
|
availability: Availability;
|
||||||
nonPublic: boolean;
|
|
||||||
unavailable: boolean;
|
|
||||||
abandoned?: boolean;
|
|
||||||
|
|
||||||
routes: StationRoutes;
|
routes: StationRoutes;
|
||||||
|
|
||||||
checkpoints: {
|
checkpoints: {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const sortStations = (a: Station, b: Station, sorter: { index: number; dir: numb
|
|||||||
const filterStations = (station: Station, filters: Filter) => {
|
const filterStations = (station: Station, filters: Filter) => {
|
||||||
const returnMode = false;
|
const returnMode = false;
|
||||||
|
|
||||||
if ((station.generalInfo?.nonPublic || !station.generalInfo) && filters['nonPublic']) return returnMode;
|
if ((station.generalInfo?.availability == 'nonPublic' || !station.generalInfo) && filters['nonPublic']) return returnMode;
|
||||||
|
|
||||||
if (station.onlineInfo?.statusID == 'ending' && filters['ending']) return returnMode;
|
if (station.onlineInfo?.statusID == 'ending' && filters['ending']) return returnMode;
|
||||||
|
|
||||||
@@ -74,22 +74,28 @@ const filterStations = (station: Station, filters: Filter) => {
|
|||||||
|
|
||||||
if (station.onlineInfo && filters['occupied']) return returnMode;
|
if (station.onlineInfo && filters['occupied']) return returnMode;
|
||||||
if (!station.onlineInfo && filters['free']) return returnMode;
|
if (!station.onlineInfo && filters['free']) return returnMode;
|
||||||
if (station.generalInfo?.unavailable && filters['unavailable'] && !station.onlineInfo) return returnMode;
|
if (station.generalInfo?.availability == 'unavailable' && filters['unavailable'] && !station.onlineInfo) return returnMode;
|
||||||
|
|
||||||
if (station.generalInfo) {
|
if (station.generalInfo) {
|
||||||
const routes = station.generalInfo.routes;
|
const routes = station.generalInfo.routes;
|
||||||
|
const availability = station.generalInfo.availability;
|
||||||
|
|
||||||
if (filters['abandoned'] && station.generalInfo.abandoned) return returnMode;
|
if (filters['abandoned'] && availability == 'abandoned') return returnMode;
|
||||||
|
|
||||||
if (station.generalInfo.default && filters['default']) return returnMode;
|
if (availability == 'default' && filters['default']) return returnMode;
|
||||||
if (!station.generalInfo.default && filters['notDefault'] && (!station.generalInfo.abandoned && !station.generalInfo.unavailable)) return returnMode;
|
if (availability != 'default' && filters['notDefault'] && !(availability == 'abandoned' || availability == 'unavailable')) return returnMode;
|
||||||
|
|
||||||
if (filters['real'] && station.generalInfo.lines != '') return returnMode;
|
if (filters['real'] && station.generalInfo.lines != '') return returnMode;
|
||||||
if (filters['fictional'] && station.generalInfo.lines == '' && (!station.generalInfo.abandoned && !station.generalInfo.unavailable)) return returnMode;
|
if (filters['fictional'] && station.generalInfo.lines == '' && (availability != 'abandoned' && availability != 'unavailable')) return returnMode;
|
||||||
|
|
||||||
|
|
||||||
if (station.generalInfo.reqLevel + ((station.generalInfo.nonPublic || station.generalInfo.unavailable || station.generalInfo.abandoned) ? 1 : 0) < filters['minLevel']) return returnMode;
|
if (station.generalInfo.reqLevel + ((availability == 'nonPublic' || availability == 'unavailable' || availability == 'abandoned') ? 1 : 0) < filters['minLevel']) return returnMode;
|
||||||
if (station.generalInfo.reqLevel + ((station.generalInfo.nonPublic || station.generalInfo.unavailable || station.generalInfo.abandoned) ? 1 : 0) > filters['maxLevel']) return returnMode;
|
if (
|
||||||
|
station.generalInfo.reqLevel +
|
||||||
|
(availability == 'nonPublic' || availability == 'unavailable' || availability == 'abandoned' ? 1 : 0) >
|
||||||
|
filters['maxLevel']
|
||||||
|
)
|
||||||
|
return returnMode;
|
||||||
|
|
||||||
if (filters['no-1track'] && (routes.oneWayCatenaryRouteNames.length != 0 || routes.oneWayNoCatenaryRouteNames.length != 0)) return returnMode;
|
if (filters['no-1track'] && (routes.oneWayCatenaryRouteNames.length != 0 || routes.oneWayNoCatenaryRouteNames.length != 0)) return returnMode;
|
||||||
if (filters['no-2track'] && (routes.twoWayCatenaryRouteNames.length != 0 || routes.twoWayNoCatenaryRouteNames.length != 0)) return returnMode;
|
if (filters['no-2track'] && (routes.twoWayCatenaryRouteNames.length != 0 || routes.twoWayNoCatenaryRouteNames.length != 0)) return returnMode;
|
||||||
|
|||||||
+159
-109
@@ -1,19 +1,24 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
import { InjectionKey } from 'vue'
|
import { InjectionKey } from 'vue';
|
||||||
import { createStore, useStore as baseUseStore, Store } from 'vuex'
|
import { createStore, useStore as baseUseStore, Store } from 'vuex';
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
|
|
||||||
import Train from "@/scripts/interfaces/Train";
|
import Train from '@/scripts/interfaces/Train';
|
||||||
|
|
||||||
import { StoreData } from "@/scripts/interfaces/StoreData";
|
import { StoreData } from '@/scripts/interfaces/StoreData';
|
||||||
|
|
||||||
|
import { ACTIONS, MUTATIONS } from '@/constants/storeConstants';
|
||||||
|
import { DataStatus } from '@/scripts/enums/DataStatus';
|
||||||
|
|
||||||
import { ACTIONS, MUTATIONS } from "@/constants/storeConstants";
|
import {
|
||||||
import { DataStatus } from "@/scripts/enums/DataStatus";
|
getLocoURL,
|
||||||
|
getScheduledTrain,
|
||||||
import { getLocoURL, getScheduledTrain, getStatusID, getStatusTimestamp, parseSpawns } from "@/scripts/utils/storeUtils";
|
getStatusID,
|
||||||
|
getStatusTimestamp,
|
||||||
|
parseSpawns,
|
||||||
|
} from '@/scripts/utils/storeUtils';
|
||||||
import { URLs } from '@/scripts/utils/apiURLs';
|
import { URLs } from '@/scripts/utils/apiURLs';
|
||||||
import ScheduledTrain from '@/scripts/interfaces/ScheduledTrain';
|
import ScheduledTrain from '@/scripts/interfaces/ScheduledTrain';
|
||||||
import StationRoutes from '@/scripts/interfaces/StationRoutes';
|
import StationRoutes from '@/scripts/interfaces/StationRoutes';
|
||||||
@@ -22,7 +27,7 @@ import { APIData, State, StationJSONData } from './types';
|
|||||||
|
|
||||||
const connectToDevAPI = false;
|
const connectToDevAPI = false;
|
||||||
|
|
||||||
export const key: InjectionKey<Store<State>> = Symbol()
|
export const key: InjectionKey<Store<State>> = Symbol();
|
||||||
|
|
||||||
export const store = createStore<State>({
|
export const store = createStore<State>({
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -33,7 +38,7 @@ export const store = createStore<State>({
|
|||||||
sceneryData: [],
|
sceneryData: [],
|
||||||
lastDispatcherStatuses: [],
|
lastDispatcherStatuses: [],
|
||||||
|
|
||||||
region: { id: "eu", value: "PL1" },
|
region: { id: 'eu', value: 'PL1' },
|
||||||
|
|
||||||
trainCount: 0,
|
trainCount: 0,
|
||||||
stationCount: 0,
|
stationCount: 0,
|
||||||
@@ -47,7 +52,7 @@ export const store = createStore<State>({
|
|||||||
dispatcherDataStatus: DataStatus.Loading,
|
dispatcherDataStatus: DataStatus.Loading,
|
||||||
trainsDataStatus: DataStatus.Loading,
|
trainsDataStatus: DataStatus.Loading,
|
||||||
|
|
||||||
listenerLaunched: false
|
listenerLaunched: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
@@ -59,7 +64,7 @@ export const store = createStore<State>({
|
|||||||
|
|
||||||
sceneryDataStatus: state.sceneryDataStatus,
|
sceneryDataStatus: state.sceneryDataStatus,
|
||||||
dispatcherDataStatus: state.dispatcherDataStatus,
|
dispatcherDataStatus: state.dispatcherDataStatus,
|
||||||
trainsDataStatus: state.trainsDataStatus
|
trainsDataStatus: state.trainsDataStatus,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
sceneryDataStatus: (state): DataStatus => state.sceneryDataStatus,
|
sceneryDataStatus: (state): DataStatus => state.sceneryDataStatus,
|
||||||
@@ -68,7 +73,7 @@ export const store = createStore<State>({
|
|||||||
|
|
||||||
currentRegion: (state): { id: string; value: string } => state.region,
|
currentRegion: (state): { id: string; value: string } => state.region,
|
||||||
|
|
||||||
webSocket: (state): Socket | undefined => state.webSocket
|
webSocket: (state): Socket | undefined => state.webSocket,
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
@@ -76,12 +81,14 @@ export const store = createStore<State>({
|
|||||||
await dispatch(ACTIONS.loadStaticStationData);
|
await dispatch(ACTIONS.loadStaticStationData);
|
||||||
|
|
||||||
// Websocket config
|
// Websocket config
|
||||||
const socket = io(process.env.NODE_ENV !== 'production' && connectToDevAPI ? URLs.stacjownikAPIDev : URLs.stacjownikAPI,
|
const socket = io(
|
||||||
|
process.env.NODE_ENV !== 'production' && connectToDevAPI ? URLs.stacjownikAPIDev : URLs.stacjownikAPI,
|
||||||
{
|
{
|
||||||
transports: ["websocket", "polling"],
|
transports: ['websocket', 'polling'],
|
||||||
rememberUpgrade: true,
|
rememberUpgrade: true,
|
||||||
reconnection: true
|
reconnection: true,
|
||||||
})
|
}
|
||||||
|
);
|
||||||
|
|
||||||
socket.on('UPDATE', (data: APIData) => {
|
socket.on('UPDATE', (data: APIData) => {
|
||||||
this.dispatch(ACTIONS.fetchOnlineData, data);
|
this.dispatch(ACTIONS.fetchOnlineData, data);
|
||||||
@@ -92,12 +99,14 @@ export const store = createStore<State>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadStaticStationData({ commit }) {
|
async loadStaticStationData({ commit }) {
|
||||||
const sceneryData: StationJSONData = await (await axios.get(`${URLs.sceneryData}?timestamp=${Math.floor(Date.now() / 1800000)}`)).data;
|
const sceneryData: StationJSONData = await (
|
||||||
|
await axios.get(`${URLs.stacjownikAPI}/api/getSceneryData?timestamp=${Math.floor(Date.now() / 1800000)}`)
|
||||||
|
).data.response;
|
||||||
|
|
||||||
if (!sceneryData)
|
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Error);
|
|
||||||
else
|
if (!sceneryData) commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Error);
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA, sceneryData);
|
else commit(MUTATIONS.SET_SCENERY_DATA, sceneryData);
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetchOnlineData({ commit }, data: APIData) {
|
async fetchOnlineData({ commit }, data: APIData) {
|
||||||
@@ -110,15 +119,15 @@ export const store = createStore<State>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
|
||||||
commit(MUTATIONS.SET_DISPATCHER_DATA_STATUS, !data.dispatchers ? DataStatus.Warning : DataStatus.Loaded)
|
commit(MUTATIONS.SET_DISPATCHER_DATA_STATUS, !data.dispatchers ? DataStatus.Warning : DataStatus.Loaded);
|
||||||
commit(MUTATIONS.SET_TRAINS_DATA_STATUS, !data.trains ? DataStatus.Warning : DataStatus.Loaded);
|
commit(MUTATIONS.SET_TRAINS_DATA_STATUS, !data.trains ? DataStatus.Warning : DataStatus.Loaded);
|
||||||
|
|
||||||
// Zaktualizuj listę pociągów
|
// Zaktualizuj listę pociągów
|
||||||
const updatedTrainList: Train[] =
|
const updatedTrainList: Train[] =
|
||||||
data.trains
|
data.trains
|
||||||
?.filter(train => train.region === this.state.region.id && train.online)
|
?.filter((train) => train.region === this.state.region.id && train.online)
|
||||||
.map(train => {
|
.map((train) => {
|
||||||
const stock = train.stockString.split(";");
|
const stock = train.stockString.split(';');
|
||||||
const locoType = stock ? stock[0] : train.stockString;
|
const locoType = stock ? stock[0] : train.stockString;
|
||||||
|
|
||||||
const timetable = train.timetable;
|
const timetable = train.timetable;
|
||||||
@@ -142,18 +151,20 @@ export const store = createStore<State>({
|
|||||||
locoURL: getLocoURL(locoType),
|
locoURL: getLocoURL(locoType),
|
||||||
cars: stock.slice(1),
|
cars: stock.slice(1),
|
||||||
|
|
||||||
timetableData: timetable ? {
|
timetableData: timetable
|
||||||
timetableId: timetable.timetableId,
|
? {
|
||||||
SKR: timetable.SKR,
|
timetableId: timetable.timetableId,
|
||||||
TWR: timetable.TWR,
|
SKR: timetable.SKR,
|
||||||
route: timetable.route,
|
TWR: timetable.TWR,
|
||||||
category: timetable.category,
|
route: timetable.route,
|
||||||
followingStops: timetable.stopList,
|
category: timetable.category,
|
||||||
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
followingStops: timetable.stopList,
|
||||||
sceneries: timetable.sceneries
|
routeDistance: timetable.stopList[timetable.stopList.length - 1].stopDistance,
|
||||||
} : undefined
|
sceneries: timetable.sceneries,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}) || []
|
}) || [];
|
||||||
|
|
||||||
const onlineStationNames: string[] = [];
|
const onlineStationNames: string[] = [];
|
||||||
const prevDispatcherStatuses: State['lastDispatcherStatuses'] = [];
|
const prevDispatcherStatuses: State['lastDispatcherStatuses'] = [];
|
||||||
@@ -164,25 +175,40 @@ export const store = createStore<State>({
|
|||||||
onlineStationNames.push(stationAPI.stationName);
|
onlineStationNames.push(stationAPI.stationName);
|
||||||
|
|
||||||
const stationName = stationAPI.stationName.toLowerCase();
|
const stationName = stationAPI.stationName.toLowerCase();
|
||||||
const station = this.state.stationList.find(s => s.name == stationAPI.stationName);
|
const station = this.state.stationList.find((s) => s.name == stationAPI.stationName);
|
||||||
|
|
||||||
const prevDispatcherStatus = this.state.lastDispatcherStatuses.find(dispatcher => dispatcher.hash === stationAPI.stationHash);
|
const prevDispatcherStatus = this.state.lastDispatcherStatuses.find(
|
||||||
const stationStatus = !data.dispatchers ? undefined : data.dispatchers.find((status: string[]) => status[0] == stationAPI.stationHash && status[1] == this.state.region.id) || -1;
|
(dispatcher) => dispatcher.hash === stationAPI.stationHash
|
||||||
|
);
|
||||||
const statusTimestamp = prevDispatcherStatus && !data.dispatchers ? prevDispatcherStatus.statusTimestamp : getStatusTimestamp(stationStatus);
|
const stationStatus = !data.dispatchers
|
||||||
const statusID = prevDispatcherStatus && !data.dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
? undefined
|
||||||
|
: data.dispatchers.find(
|
||||||
|
(status: string[]) => status[0] == stationAPI.stationHash && status[1] == this.state.region.id
|
||||||
|
) || -1;
|
||||||
|
|
||||||
|
const statusTimestamp =
|
||||||
|
prevDispatcherStatus && !data.dispatchers
|
||||||
|
? prevDispatcherStatus.statusTimestamp
|
||||||
|
: getStatusTimestamp(stationStatus);
|
||||||
|
const statusID =
|
||||||
|
prevDispatcherStatus && !data.dispatchers ? prevDispatcherStatus.statusID : getStatusID(stationStatus);
|
||||||
|
|
||||||
prevDispatcherStatuses.push({
|
prevDispatcherStatuses.push({
|
||||||
hash: stationAPI.stationHash,
|
hash: stationAPI.stationHash,
|
||||||
statusID,
|
statusID,
|
||||||
statusTimestamp
|
statusTimestamp,
|
||||||
});
|
});
|
||||||
|
|
||||||
const stationTrains = data.trains
|
const stationTrains = data.trains
|
||||||
?.filter(train => train?.region === this.state.region.id && train.online && train.currentStationName === stationAPI.stationName)
|
?.filter(
|
||||||
.map(train => ({ driverName: train.driverName, driverId: train.driverId, trainNo: train.trainNo }));
|
(train) =>
|
||||||
|
train?.region === this.state.region.id &&
|
||||||
|
train.online &&
|
||||||
|
train.currentStationName === stationAPI.stationName
|
||||||
|
)
|
||||||
|
.map((train) => ({ driverName: train.driverName, driverId: train.driverId, trainNo: train.trainNo }));
|
||||||
|
|
||||||
station?.generalInfo?.checkpoints.forEach(cp => cp.scheduledTrains.length = 0);
|
station?.generalInfo?.checkpoints.forEach((cp) => (cp.scheduledTrains.length = 0));
|
||||||
|
|
||||||
const scheduledTrains: ScheduledTrain[] = updatedTrainList.reduce((acc: ScheduledTrain[], train) => {
|
const scheduledTrains: ScheduledTrain[] = updatedTrainList.reduce((acc: ScheduledTrain[], train) => {
|
||||||
if (!train.timetableData) return acc;
|
if (!train.timetableData) return acc;
|
||||||
@@ -190,22 +216,32 @@ export const store = createStore<State>({
|
|||||||
const timetable = train.timetableData;
|
const timetable = train.timetableData;
|
||||||
if (!timetable.sceneries.includes(stationAPI.stationHash)) return acc;
|
if (!timetable.sceneries.includes(stationAPI.stationHash)) return acc;
|
||||||
|
|
||||||
const stopInfoIndex = timetable.followingStops.findIndex(stop => {
|
const stopInfoIndex = timetable.followingStops.findIndex((stop) => {
|
||||||
const stopName = stop.stopNameRAW.toLowerCase();
|
const stopName = stop.stopNameRAW.toLowerCase();
|
||||||
|
|
||||||
// if (stop.stopName == "ARKADIA ZDRÓJ" && station.name == "Arkadia Zdrój 2019" && stop.pointId != "1583014379097") return false;
|
// if (stop.stopName == "ARKADIA ZDRÓJ" && station.name == "Arkadia Zdrój 2019" && stop.pointId != "1583014379097") return false;
|
||||||
// if (stop.stopName == "ARKADIA ZDRÓJ" && station.name == "Arkadia Zdrój 2012" && stop.pointId != "1519258642187") return false;
|
// if (stop.stopName == "ARKADIA ZDRÓJ" && station.name == "Arkadia Zdrój 2012" && stop.pointId != "1519258642187") return false;
|
||||||
|
|
||||||
if (stationName === stopName) return true;
|
if (stationName === stopName) return true;
|
||||||
if (stopName.includes(stationName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
if (stopName.includes(stationName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
||||||
if (stationName.includes(stopName) && !stop.stopName.includes("po.") && !stop.stopName.includes("podg.")) return true;
|
return true;
|
||||||
if (stopName.includes("podg.") && stopName.split(", podg.")[0] && stationName.includes(stopName.split(", podg.")[0])) return true;
|
if (stationName.includes(stopName) && !stop.stopName.includes('po.') && !stop.stopName.includes('podg.'))
|
||||||
|
return true;
|
||||||
if (station?.generalInfo
|
if (
|
||||||
&& station.generalInfo.checkpoints
|
stopName.includes('podg.') &&
|
||||||
&& station.generalInfo.checkpoints.length > 0
|
stopName.split(', podg.')[0] &&
|
||||||
&& station.generalInfo.checkpoints.some(cp => cp.checkpointName.toLowerCase().includes(stop.stopNameRAW.toLowerCase())))
|
stationName.includes(stopName.split(', podg.')[0])
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (
|
||||||
|
station?.generalInfo &&
|
||||||
|
station.generalInfo.checkpoints &&
|
||||||
|
station.generalInfo.checkpoints.length > 0 &&
|
||||||
|
station.generalInfo.checkpoints.some((cp) =>
|
||||||
|
cp.checkpointName.toLowerCase().includes(stop.stopNameRAW.toLowerCase())
|
||||||
|
)
|
||||||
|
)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -217,18 +253,20 @@ export const store = createStore<State>({
|
|||||||
|
|
||||||
if (station && station.generalInfo?.checkpoints && station.generalInfo.checkpoints.length > 0) {
|
if (station && station.generalInfo?.checkpoints && station.generalInfo.checkpoints.length > 0) {
|
||||||
for (const checkpoint of station.generalInfo.checkpoints) {
|
for (const checkpoint of station.generalInfo.checkpoints) {
|
||||||
const index = timetable.followingStops.findIndex(stop => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase());
|
const index = timetable.followingStops.findIndex(
|
||||||
|
(stop) => stop.stopNameRAW.toLowerCase() == checkpoint.checkpointName.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
if (index == -1) continue;
|
if (index == -1) continue;
|
||||||
|
|
||||||
const scheduledCheckpointTrain = getScheduledTrain(train, index, stationAPI.stationName);
|
const scheduledCheckpointTrain = getScheduledTrain(train, index, stationAPI.stationName);
|
||||||
checkpoint.scheduledTrains.push(scheduledCheckpointTrain);
|
checkpoint.scheduledTrains.push(scheduledCheckpointTrain);
|
||||||
|
|
||||||
// timetable.followingStops
|
// timetable.followingStops
|
||||||
// .filter(trainStop => trainStop.stopNameRAW.toLowerCase() === checkpoint.checkpointName.toLowerCase())
|
// .filter(trainStop => trainStop.stopNameRAW.toLowerCase() === checkpoint.checkpointName.toLowerCase())
|
||||||
// .forEach((trainCheckpointStop, i) => {
|
// .forEach((trainCheckpointStop, i) => {
|
||||||
|
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,80 +289,93 @@ export const store = createStore<State>({
|
|||||||
statusTimestamp,
|
statusTimestamp,
|
||||||
statusID,
|
statusID,
|
||||||
scheduledTrains,
|
scheduledTrains,
|
||||||
}
|
};
|
||||||
|
|
||||||
if (!station) {
|
if (!station) {
|
||||||
this.state.stationList.push({
|
this.state.stationList.push({
|
||||||
name: stationAPI.stationName,
|
name: stationAPI.stationName,
|
||||||
onlineInfo
|
onlineInfo,
|
||||||
})
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
station.onlineInfo = { ...onlineInfo };
|
station.onlineInfo = { ...onlineInfo };
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.state.stationList
|
this.state.stationList
|
||||||
.filter(station => !onlineStationNames.includes(station.name) && station.onlineInfo)
|
.filter((station) => !onlineStationNames.includes(station.name) && station.onlineInfo)
|
||||||
.forEach(offlineStation => {
|
.forEach((offlineStation) => {
|
||||||
offlineStation.onlineInfo = undefined;
|
offlineStation.onlineInfo = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.state.trainList = updatedTrainList;
|
this.state.trainList = updatedTrainList;
|
||||||
this.state.trainsDataStatus = DataStatus.Loaded;
|
this.state.trainsDataStatus = DataStatus.Loaded;
|
||||||
|
|
||||||
if (data.dispatchers != null)
|
if (data.dispatchers != null) this.state.lastDispatcherStatuses = prevDispatcherStatuses;
|
||||||
this.state.lastDispatcherStatuses = prevDispatcherStatuses;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_SCENERY_DATA(state, data: StationJSONData[]) {
|
SET_SCENERY_DATA(state, data: StationJSONData[]) {
|
||||||
state.stationList = data.map(stationData => ({
|
state.stationList = data.map((stationData) => ({
|
||||||
name: stationData.name,
|
name: stationData.name,
|
||||||
|
|
||||||
generalInfo: {
|
generalInfo: {
|
||||||
...stationData,
|
...stationData,
|
||||||
routes: stationData.routes?.split(";").filter(routeString => routeString).reduce((acc, routeString) => {
|
routes:
|
||||||
const specs1 = routeString.split("_")[0];
|
stationData.routes
|
||||||
const isInternal = specs1.startsWith('!');
|
?.split(';')
|
||||||
const name = isInternal ? specs1.replace("!", "") : specs1;
|
.filter((routeString) => routeString)
|
||||||
|
.reduce(
|
||||||
|
(acc, routeString) => {
|
||||||
|
const specs1 = routeString.split('_')[0];
|
||||||
|
const isInternal = specs1.startsWith('!');
|
||||||
|
const name = isInternal ? specs1.replace('!', '') : specs1;
|
||||||
|
|
||||||
const specs2 = routeString.split("_")[1].split("");
|
const specs2 = routeString.split('_')[1].split('');
|
||||||
const twoWay = specs2[0] == "2";
|
const twoWay = specs2[0] == '2';
|
||||||
const catenary = specs2[1] == "E";
|
const catenary = specs2[1] == 'E';
|
||||||
const SBL = specs2[2] == "S";
|
const SBL = specs2[2] == 'S';
|
||||||
const TWB = specs2[3] ? true : false;
|
const TWB = specs2[3] ? true : false;
|
||||||
|
|
||||||
const propName = twoWay
|
const propName = twoWay
|
||||||
? catenary
|
? catenary
|
||||||
? 'twoWayCatenaryRouteNames'
|
? 'twoWayCatenaryRouteNames'
|
||||||
: 'twoWayNoCatenaryRouteNames'
|
: 'twoWayNoCatenaryRouteNames'
|
||||||
: catenary
|
: catenary
|
||||||
? 'oneWayCatenaryRouteNames'
|
? 'oneWayCatenaryRouteNames'
|
||||||
: 'oneWayNoCatenaryRouteNames';
|
: 'oneWayNoCatenaryRouteNames';
|
||||||
|
|
||||||
acc[twoWay ? 'twoWay' : 'oneWay'].push({ name, SBL, TWB, catenary, isInternal, tracks: twoWay ? 2 : 1 });
|
acc[twoWay ? 'twoWay' : 'oneWay'].push({
|
||||||
if (!isInternal) acc[propName].push(name);
|
name,
|
||||||
|
SBL,
|
||||||
|
TWB,
|
||||||
|
catenary,
|
||||||
|
isInternal,
|
||||||
|
tracks: twoWay ? 2 : 1,
|
||||||
|
});
|
||||||
|
if (!isInternal) acc[propName].push(name);
|
||||||
|
|
||||||
if (SBL) acc['sblRouteNames'].push(name);
|
if (SBL) acc['sblRouteNames'].push(name);
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {
|
},
|
||||||
oneWay: [],
|
{
|
||||||
twoWay: [],
|
oneWay: [],
|
||||||
sblRouteNames: [],
|
twoWay: [],
|
||||||
oneWayCatenaryRouteNames: [],
|
sblRouteNames: [],
|
||||||
oneWayNoCatenaryRouteNames: [],
|
oneWayCatenaryRouteNames: [],
|
||||||
twoWayCatenaryRouteNames: [],
|
oneWayNoCatenaryRouteNames: [],
|
||||||
twoWayNoCatenaryRouteNames: []
|
twoWayCatenaryRouteNames: [],
|
||||||
} as StationRoutes) || {},
|
twoWayNoCatenaryRouteNames: [],
|
||||||
checkpoints: stationData.checkpoints ? stationData.checkpoints.split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
|
} as StationRoutes
|
||||||
}
|
) || {},
|
||||||
|
checkpoints: stationData.checkpoints
|
||||||
|
? stationData.checkpoints.split(';').map((sub) => ({ checkpointName: sub, scheduledTrains: [] }))
|
||||||
|
: [],
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
|
||||||
@@ -343,10 +394,9 @@ export const store = createStore<State>({
|
|||||||
state.region = region;
|
state.region = region;
|
||||||
state.webSocket?.emit('FETCH_DATA');
|
state.webSocket?.emit('FETCH_DATA');
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
});
|
||||||
})
|
|
||||||
|
|
||||||
export function useStore(): Store<State> {
|
export function useStore(): Store<State> {
|
||||||
return baseUseStore(key)
|
return baseUseStore(key);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -5,6 +5,8 @@ import Station from "@/scripts/interfaces/Station";
|
|||||||
import Train from "@/scripts/interfaces/Train";
|
import Train from "@/scripts/interfaces/Train";
|
||||||
import { Socket } from "socket.io-client";
|
import { Socket } from "socket.io-client";
|
||||||
|
|
||||||
|
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
stationList: Station[],
|
stationList: Station[],
|
||||||
trainList: Train[],
|
trainList: Train[],
|
||||||
@@ -46,8 +48,6 @@ export interface StationJSONData {
|
|||||||
|
|
||||||
reqLevel: number;
|
reqLevel: number;
|
||||||
|
|
||||||
// supportersOnly: boolean;
|
|
||||||
|
|
||||||
signalType: string;
|
signalType: string;
|
||||||
controlType: string;
|
controlType: string;
|
||||||
|
|
||||||
@@ -56,7 +56,5 @@ export interface StationJSONData {
|
|||||||
routes: string;
|
routes: string;
|
||||||
checkpoints: string | null;
|
checkpoints: string | null;
|
||||||
|
|
||||||
default: boolean;
|
availability: Availability;
|
||||||
nonPublic: boolean;
|
|
||||||
unavailable: boolean;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user