Zmiany w wyglądzie list graczy online i spawnów

This commit is contained in:
2020-12-02 20:59:35 +01:00
parent 6ae89c9953
commit 93f2d7e526
7 changed files with 146 additions and 499 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ export default class App extends Vue {
@Action("synchronizeData") synchronizeData; @Action("synchronizeData") synchronizeData;
@Getter("getAllData") data; @Getter("getAllData") data;
private VERSION = "1.3.2"; private VERSION = "1.3.3";
get dataStatusClass() { get dataStatusClass() {
if (this.data.dataConnectionStatus == 0) return "loading"; if (this.data.dataConnectionStatus == 0) return "loading";
+110 -25
View File
@@ -28,7 +28,7 @@
</span> </span>
<span class="spawns"> <span class="spawns">
<img :src="spawnIcon" alt="icon-spawn" /> <img :src="spawnIcon" alt="icon-spawn" />
<span>{{ stationInfo.spawnString.length }}</span> <span>{{ stationInfo.spawns.length }}</span>
</span> </span>
<span class="schedules"> <span class="schedules">
<img :src="timetableIcon" alt="icon-timetable" /> <img :src="timetableIcon" alt="icon-timetable" />
@@ -108,13 +108,25 @@
GRACZE ONLINE GRACZE ONLINE
<img :src="userIcon" alt="icon-user" /> <img :src="userIcon" alt="icon-user" />
</h3> </h3>
<ul>
<li <div
class="user user-badge" v-for="(train, i) in computedStationTrains"
:class="train.stopStatus" class="user"
v-for="train in computedStationTrains" :class="train.stopStatus"
:key="train.trainNo + train.driverName" :key="train.trainNo + i"
> @click="() => navigateToTrain(train.trainNo)"
>
<span class="user_train">{{ train.trainNo }}</span>
<span class="user_name">{{ train.driverName}}</span>
</div>
<div
class="user offline"
v-if="!computedStationTrains || computedStationTrains.length == 0"
>BRAK AKTYWNYCH GRACZY</div>
<!-- <ul>
<li class="user user-badge">
<router-link <router-link
:to="{ :to="{
name: 'TrainsView', name: 'TrainsView',
@@ -134,22 +146,28 @@
!stationInfo.stationTrains || !stationInfo.stationTrains ||
stationInfo.stationTrains.length == 0 stationInfo.stationTrains.length == 0
" "
>BRAK</span> >BRAK</span>-->
</div> </div>
<div class="spawn-list"> <div class="spawn-list">
<h3 class="spawn-header"> <h3 class="spawn-header">
OTWARTE SPAWNY OTWARTE SPAWNY
<img :src="spawnIcon" alt="icon-spawn" /> <img :src="spawnIcon" alt="icon-spawn" />
</h3> </h3>
<div> <span
<span class="spawn"
class="spawn" v-for="(spawn, i) in stationInfo.spawns"
v-for="(spawn, i) in stationInfo.spawnString" :key="spawn.spawnName + stationInfo.dispatcherName + i"
:key="spawn + stationInfo.dispatcherName + i" >
>{{ spawn }}</span> <span class="spawn_name">{{ spawn.spawnName }}</span>
</div> <span class="spawn_length">{{ spawn.spawnLength }}</span>
<span class="spawn" v-if="!stationInfo.spawnString">BRAK</span> </span>
<span
class="spawn none"
v-if="!stationInfo.spawns || stationInfo.spawns.length == 0"
>BRAK OTWARTYCH SPAWNÓW</span>
</div> </div>
</div> </div>
</section> </section>
@@ -188,6 +206,13 @@ export default class SceneryInfo extends styleMixin {
}; };
}); });
} }
navigateToTrain(trainNo: number) {
this.$router.push({
name: "TrainsView",
params: { passedSearchedTrain: trainNo.toString() },
});
}
} }
</script> </script>
@@ -311,23 +336,83 @@ h3 {
} }
} }
.user { .user,
font-size: 0.85em; .spawn {
font-weight: 600;
font-size: 0.9em;
display: inline-block;
padding: 0;
background: #585858;
margin: 0.25em;
span {
display: inline-block;
padding: 0.2em 0.4em;
}
@include smallScreen() { @include smallScreen() {
font-size: 1em; font-size: 1em;
} }
} }
.spawn, .user {
cursor: pointer;
&_train {
color: black;
}
&.no-timetable {
pointer-events: none;
& > .user_train {
background-color: $no-timetable;
}
}
&.departed > &_train {
background-color: $departed;
}
&.stopped > &_train {
background-color: $stopped;
}
&.online > &_train {
background-color: $online;
}
&.terminated > &_train {
background-color: $terminated;
}
&.disconnected > &_train {
background-color: $disconnected;
}
&.offline {
background: firebrick;
pointer-events: none;
}
}
.spawn {
&_length {
background: $accentCol;
color: black;
}
}
.spawn.none,
.user.offline { .user.offline {
padding: 0.3em 0.4em; font-weight: 600;
background: #585858;
margin-right: 0.5rem; padding: 0.2em 0.4em;
margin-top: 0.5rem; background: firebrick;
font-size: 0.8em;
text-align: center; text-align: center;
@include smallScreen() { @include smallScreen() {
+1
View File
@@ -0,0 +1 @@
{"success":true,"respCode":10,"message":[{"dispatcherId":13983,"dispatcherName":"Don350","dispatcherIsSupporter":true,"stationName":"Hetmanice","stationHash":"f7389af5","region":"eu","maxUsers":8,"currentUsers":0,"spawn":1,"lastSeen":1606776450625,"dispatcherExp":14,"nameFromHeader":"Hetmanice","spawnString":"He_Tm1,1,550,True,False,False,ALL","networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":22},{"dispatcherId":22620,"dispatcherName":"Calleman","dispatcherIsSupporter":true,"stationName":"Wielichowo","stationHash":"e4f61c89","region":"ru","maxUsers":29,"currentUsers":1,"spawn":0,"lastSeen":1606776448323,"dispatcherExp":11,"nameFromHeader":"Wielichowo","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0},{"dispatcherId":10048,"dispatcherName":"Sprytny_Zbys","dispatcherIsSupporter":false,"stationName":"Piaskowo","stationHash":"74a6c5ba","region":"eu","maxUsers":29,"currentUsers":0,"spawn":1,"lastSeen":1606776447873,"dispatcherExp":11,"nameFromHeader":"Piaskowo","spawnString":"Ps_G3,1,650,True,False,False,ALL;Ps_G4,1,650,True,False,False,ALL;Ps_N,-1,185,True,False,False,PAS","networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":23},{"dispatcherId":4310,"dispatcherName":"jedrek386","dispatcherIsSupporter":true,"stationName":"Niedoradz","stationHash":"2a7a048e","region":"eu","maxUsers":7,"currentUsers":0,"spawn":1,"lastSeen":1606776454351,"dispatcherExp":1,"nameFromHeader":"Niedoradz","spawnString":"Ne_H,1,200,True,False,False,H","networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":2},{"dispatcherId":10048,"dispatcherName":"Sprytny_Zbys","dispatcherIsSupporter":false,"stationName":"LCS Skrzynki","stationHash":"c9d5dc18","region":"eu","maxUsers":10,"currentUsers":1,"spawn":0,"lastSeen":1606776460199,"dispatcherExp":11,"nameFromHeader":"LCS Skrzynki","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0},{"dispatcherId":6975,"dispatcherName":"ziolek","dispatcherIsSupporter":false,"stationName":"Kcynia","stationHash":"64f1a3ba","region":"ru","maxUsers":9,"currentUsers":0,"spawn":0,"lastSeen":1606775846330,"dispatcherExp":4,"nameFromHeader":"Kcynia","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":0,"dispatcherRate":0},{"dispatcherId":7240,"dispatcherName":"ASkier","dispatcherIsSupporter":false,"stationName":"Głębce","stationHash":"3f7e4639","region":"ru","maxUsers":4,"currentUsers":0,"spawn":0,"lastSeen":1606775877861,"dispatcherExp":1,"nameFromHeader":"Głębce","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":0,"dispatcherRate":0},{"dispatcherId":16658,"dispatcherName":"NIEMIEC141","dispatcherIsSupporter":false,"stationName":"Buk 2018","stationHash":"4c831fc3","region":"eu","maxUsers":4,"currentUsers":0,"spawn":0,"lastSeen":1606775836686,"dispatcherExp":7,"nameFromHeader":"Buk 2018","spawnString":"NO_SPAWN","networkConnectionString":"2020.1.1Stable004","isOnline":0,"dispatcherRate":0},{"dispatcherId":6975,"dispatcherName":"ziolek","dispatcherIsSupporter":false,"stationName":"Kolsko","stationHash":"687dcf5b","region":"ru","maxUsers":6,"currentUsers":0,"spawn":0,"lastSeen":1606776448954,"dispatcherExp":4,"nameFromHeader":"Kolsko","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0},{"dispatcherId":7240,"dispatcherName":"ASkier","dispatcherIsSupporter":false,"stationName":"Karszynek","stationHash":"c0e19184","region":"ru","maxUsers":5,"currentUsers":0,"spawn":0,"lastSeen":1606776456733,"dispatcherExp":1,"nameFromHeader":"Karszynek","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0},{"dispatcherId":3619,"dispatcherName":"SzybkiWiewiór","dispatcherIsSupporter":false,"stationName":"Knot","stationHash":"cbaad885","region":"ru","maxUsers":14,"currentUsers":1,"spawn":0,"lastSeen":1606776460872,"dispatcherExp":7,"nameFromHeader":"Knot","spawnString":null,"networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0},{"dispatcherId":16658,"dispatcherName":"NIEMIEC141","dispatcherIsSupporter":false,"stationName":"Parzęczewo","stationHash":"325b1a74","region":"eu","maxUsers":29,"currentUsers":0,"spawn":1,"lastSeen":1606776392453,"dispatcherExp":7,"nameFromHeader":"Parzęczewo","spawnString":"LUZ1,-1,50,True,False,True,;LUZ2,-1,50,True,False,True,;POSP1,-1,200,True,False,False,;POSP2,-1,300,True,False,False,;POSP3,-1,200,True,False,False,;Pr_P20,1,200,True,True,False,;Pr_T28,1,750,True,False,False,;Pr_T34,1,750,True,False,False,;Pr_U38,-1,750,True,False,False,","networkConnectionString":"2020.1.1Stable004","isOnline":1,"dispatcherRate":0}]}
+17 -5
View File
@@ -4,33 +4,45 @@ import ScheduledTrain from './ScheduledTrain';
export default interface Station { export default interface Station {
stationName: string; stationName: string;
stationHash: string; stationHash: string;
maxUsers: number; maxUsers: number;
currentUsers: number; currentUsers: number;
spawnString: string;
spawns: { spawnName: string; spawnLength: number }[];
dispatcherRate: number; dispatcherRate: number;
dispatcherName: string; dispatcherName: string;
dispatcherExp: number; dispatcherExp: number;
dispatcherId: number; dispatcherId: number;
dispatcherIsSupporter: boolean; dispatcherIsSupporter: boolean;
stationLines: string; stationLines: string;
stationProject: string; stationProject: string;
reqLevel: string; reqLevel: string;
supportersOnly: string; supportersOnly: string;
signalType: string; signalType: string;
controlType: string; controlType: string;
default: boolean; default: boolean;
nonPublic: boolean; nonPublic: boolean;
routes: { routes: {
oneWay: { catenary: number; noCatenary: number }; oneWay: { catenary: number; noCatenary: number };
twoWay: { catenary: number; noCatenary: number }; twoWay: { catenary: number; noCatenary: number };
}; };
checkpoints: {
checkpointName: string; checkpoints:
scheduledTrains: ScheduledTrain[], | {
}[] | null; checkpointName: string;
scheduledTrains: ScheduledTrain[];
}[]
| null;
online: boolean; online: boolean;
occupiedTo: string; occupiedTo: string;
statusTimestamp: number; statusTimestamp: number;
stationTrains: Train[]; stationTrains: Train[];
scheduledTrains: ScheduledTrain[]; scheduledTrains: ScheduledTrain[];
} }
-264
View File
@@ -1,264 +0,0 @@
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators';
import axios from 'axios';
import data from '@/data/stations.json';
import Station from '@/scripts/interfaces/Station';
const stationsOnlineURL = 'https://api.td2.info.pl:9640/?method=getStationsOnline';
const trainsOnlineURL = 'https://api.td2.info.pl:9640/?method=getTrainsOnline';
const dispatchersOnlineURL = 'https://api.td2.info.pl:9640/?method=readFromSWDR&value=getDispatcherStatusList%3B1';
enum ConnState {
Loading = 0,
Error = 1,
Connected = 2,
}
interface TimetableResponseData {
stopPoints: {
arrivalTime: string;
arrivalDelay: number;
departureTime: string;
departureDelay: number;
pointNameRAW: string;
}[];
trainInfo: {
timetableId: number;
trainCategoryCode: string;
};
}
interface OnlineStationsResponseData {
stationName: string;
stationHash: string;
maxUsers: number;
currentUsers: number;
spawnString: string;
dispatcherRate: number;
dispatcherName: string;
dispatcherExp: number;
dispatcherId: number;
region: string;
isOnline: number;
}
let onlineDispatchersData: [string, string, number, number][];
let onlineStationsData: OnlineStationsResponseData[];
let onlineTrainsData: {
isOnline: number;
region: string;
trainNo: number;
station: {
stationName: string;
};
}[];
const getStationLabel = (stationStatus: any) => {
if (!stationStatus) return 'NIEZALOGOWANY';
const statusCode = stationStatus[2];
const statusTimestamp = stationStatus[3];
switch (statusCode) {
case 0:
if (statusTimestamp - Date.now() > 21000000) return 'BEZ LIMITU';
return `DO ${new Date(statusTimestamp).toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
})}`;
case 1:
return 'Z/W';
case 2:
if (statusTimestamp == 0) return 'KOŃCZY';
break;
case 3:
return 'BRAK MIEJSCA';
default:
break;
}
return 'NIEDOSTĘPNY';
};
const getOpenSpawns = (spawnString: string) => {
if (!spawnString) return '';
return spawnString.split(';').map(v => (v.split(',')[6] ? v.split(',')[6] : v.split(',')[0]));
};
@Module
export default class StationsModule extends VuexModule {
private trainCount: number = 0;
private stationCount: number = 0;
private stationsConnectionState: ConnState = ConnState.Loading;
private stations: Station[] = [];
get getConnectionState() {
return this.stationsConnectionState;
}
get getOnlineInfo() {
return {
trainCount: this.trainCount,
stationCount: this.stationCount,
};
}
get getStationList() {
return this.stations;
}
@Mutation
private setConnectionState(state: ConnState) {
this.stationsConnectionState = state;
}
@Mutation
private updateStations(updatedStations) {
this.stations = this.stations.reduce((acc, station) => {
const onlineStationData = updatedStations.find(uStation => uStation.stationName === station.stationName);
if (!onlineStationData) {
acc.push({
...station,
stationProject: '',
spawnString: '',
stationHash: '',
maxUsers: 0,
currentUsers: 0,
dispatcherName: '',
dispatcherRate: 0,
dispatcherExp: -1,
dispatcherId: 0,
occupiedTo: 'WOLNA',
statusTimestamp: 0,
online: false,
});
return acc;
}
acc.push({
...station,
...onlineStationData,
online: true,
});
// updatedStations = updatedStations.filter(
// (updated: any) => updated.stationName !== station.stationName
// );
return acc;
}, [] as Station[]);
// Dodawanie do listy online potencjalnych scenerii niewpisanych do bazy
updatedStations.forEach((updated: any) => {
const alreadyInList: any = this.stations.find(station => station.stationName === updated.stationName);
if (!alreadyInList) {
this.stations.push({
...updated,
online: true,
reqLevel: '-1',
});
}
});
this.stationCount = this.stations.filter(station => station.online).length;
this.trainCount = onlineTrainsData.filter(train => train.isOnline && train.region === 'eu').length;
this.stationsConnectionState = ConnState.Connected;
}
@Mutation
private mutateStations(stations) {
this.stations = stations;
}
@Action({
commit: 'mutateStations',
})
async loadStations() {
return await data.map(stationData => ({
stationProject: '',
spawnString: '',
stationHash: '',
maxUsers: 0,
currentUsers: 0,
dispatcherName: '',
dispatcherRate: 0,
dispatcherExp: -1,
dispatcherId: 0,
online: false,
occupiedTo: 'WOLNA',
statusTimestamp: 0,
scheduledTrains: [],
...stationData,
}));
}
@Action
async initStations() {
this.context.dispatch('loadStations');
this.context.dispatch('fetchOnlineStations');
}
@Action({
commit: 'updateStations',
})
async fetchOnlineStations() {
return await Promise.all([axios.get(stationsOnlineURL), axios.get(trainsOnlineURL), axios.get(dispatchersOnlineURL)])
.then(async response => {
onlineStationsData = response[0].data.message;
onlineTrainsData = await response[1].data.message;
onlineDispatchersData = await response[2].data.message;
const updatedStations = await Promise.all(
onlineStationsData
.filter(station => station.region === 'eu' && station.isOnline)
.map(async station => {
const stationStatus = onlineDispatchersData.find(status => status[0] == station.stationHash && status[1] == 'eu');
const statusLabel = getStationLabel(stationStatus);
const statusTimestamp = stationStatus ? stationStatus[3] : -1;
const trains = onlineTrainsData.filter(train => train.region === 'eu' && train.isOnline && train.station.stationName === station.stationName);
const stationData = data.find(s => s.stationName === station.stationName) || {
stationName: station.stationName,
stationURL: '',
};
return {
...stationData,
stationHash: station.stationHash,
maxUsers: station.maxUsers,
currentUsers: station.currentUsers,
spawnString: getOpenSpawns(station.spawnString),
dispatcherName: station.dispatcherName,
dispatcherRate: station.dispatcherRate,
dispatcherId: station.dispatcherId,
dispatcherExp: station.dispatcherExp,
occupiedTo: statusLabel,
statusTimestamp,
trains,
};
})
);
return updatedStations;
})
.catch(err => {
this.context.commit('setConnectionState', ConnState.Error);
console.log(err);
});
}
}
-198
View File
@@ -1,198 +0,0 @@
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators';
import Train from '@/scripts/interfaces/Train';
import axios from 'axios';
const API_URL = 'https://api.td2.info.pl:9640/?method=getTrainsOnline';
enum ConnState {
Loading = 0,
Error = 1,
Connected = 2,
}
interface TrainData {
driverId: number;
driverName: string;
trainNo: number;
station: { stationName: string };
dataMass: number;
dataLength: number;
dataSpeed: number;
dataDistance: number;
dataSignal: string;
dataCon: string;
dataSceneryConnection: string;
isOnline: boolean;
}
interface TimetableResponseData {
stopPoints: {
pointDistance: number;
pointNameRAW: string;
pointName: string;
pointStopType: string;
arrivalLine: string;
departureLine: string;
arrivalTime: string;
arrivalDelay: number;
departureTime: string;
departureDelay: number;
confirmed: boolean;
stopped: boolean;
pointStopTime: number;
}[];
trainInfo: {
timetableId: number;
trainCategoryCode: string;
route: string;
twr: boolean;
skr: boolean;
sceneries: string[];
};
}
interface TimetableData {
timetableId: number;
trainCategoryCode: string;
route: string;
twr: boolean;
skr: boolean;
sceneries: string[];
routeDistance: number;
stopPoints?: {}[];
}
const getTimestamp = (date: string) => (date ? new Date(date).getTime() : 0);
const getTimetableURL = (trainNo: number) => `https://api.td2.info.pl:9640/?method=readFromSWDR&value=getTimetable%3B${trainNo}%3Beu`;
const getLocoURL = (locoType: string) => `https://rj.td2.info.pl/dist/img/thumbnails/${locoType.includes('EN') ? locoType + 'rb' : locoType}.png`;
@Module
export default class TrainsModule extends VuexModule {
onlineTrainsData: Train[] = [];
onlineTrainsState: ConnState = ConnState.Loading;
@Action({ commit: 'loadTrainsData' })
async fetchTrainsData() {
let trainDataResponse;
try {
trainDataResponse = await axios.get(API_URL);
} catch (error) {
this.context.commit('setConnectionState', ConnState.Error);
return null;
}
let onlineTrainsData: TrainData[] = trainDataResponse.data.message;
return await Promise.all(
onlineTrainsData.map(async train => {
const timetableResponseData: TimetableResponseData | null = (await axios.get(getTimetableURL(train.trainNo))).data.message;
let timetableData: TimetableData | null = null;
if (timetableResponseData && timetableResponseData.trainInfo) {
const routeDistance: number = timetableResponseData.stopPoints[timetableResponseData.stopPoints.length - 1].pointDistance;
timetableData = {
...timetableResponseData.trainInfo,
routeDistance,
stopPoints: timetableResponseData.stopPoints,
};
}
const locoType = train.dataCon.split(';') ? train.dataCon.split(';')[0] : train.dataCon;
const followingStops = timetableResponseData?.stopPoints.reduce(
(acc, point) => {
const stopObj: any = {};
if (!point.pointName.includes('Południowy') && (point.pointName.includes('strong') || point.pointName.includes('podg.'))) {
if (point.pointName.includes('strong')) {
stopObj.stopName = point.pointNameRAW;
stopObj.stopType = point.pointStopType;
} else {
stopObj.stopName = point.pointNameRAW.split(',')[0];
stopObj.stopType = 'podg.';
}
stopObj.arrivalTime = getTimestamp(point.arrivalTime);
stopObj.departureTime = getTimestamp(point.departureTime);
stopObj.arrivalDelay = point.arrivalDelay;
stopObj.departureDelay = point.departureDelay;
stopObj.beginsHere = getTimestamp(point.arrivalTime) == 0 ? true : false;
stopObj.terminatesHere = getTimestamp(point.departureTime) == 0 ? true : false;
stopObj.confirmed = point.confirmed;
stopObj.stopped = point.stopped;
stopObj.currentStationName = train.station.stationName;
acc.push(stopObj);
}
return acc;
},
[] as {
stopName: string;
stopType: string;
arrivalTime: number;
arrivalDelay: number;
departureTime: number;
departureDelay: number;
confirmed: boolean;
stopped: boolean;
stopTime: number;
beginsHere: boolean;
terminatesHere: boolean;
}[]
);
return {
online: train.isOnline,
driverId: train.driverId,
driverName: train.driverName,
trainNo: train.trainNo,
currentStationName: train.station.stationName,
mass: train.dataMass,
length: train.dataLength,
speed: train.dataSpeed,
distance: train.dataDistance,
signal: train.dataSignal,
connectedTrack: train.dataSceneryConnection,
locoType,
locoURL: getLocoURL(locoType),
noTimetable: timetableData == null,
route: timetableData?.route,
timetableId: timetableData?.timetableId,
category: timetableData?.trainCategoryCode,
routeDistance: timetableData?.routeDistance || 0,
followingStops,
TWR: timetableData?.twr,
SKR: timetableData?.skr,
};
})
);
}
@Mutation
private loadTrainsData(data: Train[] | null) {
if (data) {
this.onlineTrainsData = data;
this.onlineTrainsState = ConnState.Connected;
}
}
@Mutation
private setConnectionState(state: ConnState) {
this.onlineTrainsState = state;
}
get trainsDataList() {
return this.onlineTrainsData;
}
get trainsDataState() {
return this.onlineTrainsState;
}
}
+17 -6
View File
@@ -30,6 +30,8 @@ interface TimetableData {
followingSceneries: string[]; followingSceneries: string[];
} }
// const devEnv = true;
const URLs = { const URLs = {
stations: 'https://api.td2.info.pl:9640/?method=getStationsOnline', stations: 'https://api.td2.info.pl:9640/?method=getStationsOnline',
trains: 'https://api.td2.info.pl:9640/?method=getTrainsOnline', trains: 'https://api.td2.info.pl:9640/?method=getTrainsOnline',
@@ -95,7 +97,19 @@ const getStatusTimestamp = (stationStatus: any) => {
return -1; return -1;
}; };
const getOpenSpawns = (spawnString: string) => (spawnString ? spawnString.split(';').map(v => (v.split(',')[6] ? v.split(',')[6] : v.split(',')[0])) : ''); const parseSpawns = (spawnString: string) => {
if (!spawnString) return [];
if (spawnString === 'NO_SPAWN') return [];
return spawnString.split(';').map(spawn => {
const spawnArray = spawn.split(',');
const spawnName = spawnArray[6] ? spawnArray[6] : spawnArray[0];
const spawnLength = parseInt(spawnArray[2]);
return { spawnName, spawnLength };
});
};
const getTimestamp = (date: string) => (date ? new Date(date).getTime() : 0); const getTimestamp = (date: string) => (date ? new Date(date).getTime() : 0);
const timestampToTime = (timestamp: number) => const timestampToTime = (timestamp: number) =>
new Date(timestamp).toLocaleTimeString('pl-PL', { new Date(timestamp).toLocaleTimeString('pl-PL', {
@@ -113,7 +127,6 @@ export default class Store extends VuexModule {
private stationList: Station[] = []; private stationList: Station[] = [];
private trainList: Train[] = []; private trainList: Train[] = [];
private spawnList: { spawnName: string; spawnLength: number }[] = [];
//GETTERS //GETTERS
get getAllData() { get getAllData() {
@@ -232,7 +245,6 @@ export default class Store extends VuexModule {
const stationStatus = onlineDispatchersData.find(status => status[0] == station.stationHash && status[1] == 'eu'); const stationStatus = onlineDispatchersData.find(status => status[0] == station.stationHash && status[1] == 'eu');
const statusLabel = getStatusLabel(stationStatus); const statusLabel = getStatusLabel(stationStatus);
// let statusTimestamp = stationStatus ? stationStatus[3] : -1;
const statusTimestamp = getStatusTimestamp(stationStatus); const statusTimestamp = getStatusTimestamp(stationStatus);
const stationTrains = onlineTrainsData.filter(train => train.region === 'eu' && train.isOnline && train.station.stationName === station.stationName); const stationTrains = onlineTrainsData.filter(train => train.region === 'eu' && train.isOnline && train.station.stationName === station.stationName);
@@ -242,7 +254,7 @@ export default class Store extends VuexModule {
stationHash: station.stationHash, stationHash: station.stationHash,
maxUsers: station.maxUsers, maxUsers: station.maxUsers,
currentUsers: station.currentUsers, currentUsers: station.currentUsers,
spawnString: getOpenSpawns(station.spawnString), spawns: parseSpawns(station.spawnString),
dispatcherName: station.dispatcherName, dispatcherName: station.dispatcherName,
dispatcherRate: station.dispatcherRate, dispatcherRate: station.dispatcherRate,
dispatcherId: station.dispatcherId, dispatcherId: station.dispatcherId,
@@ -301,7 +313,6 @@ export default class Store extends VuexModule {
this.stationList = JSONStationData.map(stationData => ({ this.stationList = JSONStationData.map(stationData => ({
...stationData, ...stationData,
stationProject: '', stationProject: '',
spawnString: '',
stationHash: '', stationHash: '',
maxUsers: 0, maxUsers: 0,
currentUsers: 0, currentUsers: 0,
@@ -315,6 +326,7 @@ export default class Store extends VuexModule {
statusTimestamp: -3, statusTimestamp: -3,
stationTrains: [], stationTrains: [],
scheduledTrains: [], scheduledTrains: [],
spawns: [],
checkpoints: stationData.subStations ? stationData.subStations.map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : null, checkpoints: stationData.subStations ? stationData.subStations.map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : null,
})); }));
} }
@@ -335,7 +347,6 @@ export default class Store extends VuexModule {
acc.push({ acc.push({
...station, ...station,
stationProject: '', stationProject: '',
spawnString: '',
stationHash: '', stationHash: '',
maxUsers: 0, maxUsers: 0,
currentUsers: 0, currentUsers: 0,