Dodano wersję developerską; dodano nowy JSON z danymi scenerii

This commit is contained in:
2022-02-14 23:06:04 +01:00
parent d44c3ea8d0
commit 7beebee235
3 changed files with 54 additions and 44 deletions
+2 -1
View File
@@ -5,7 +5,8 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"deploy": "npm run build && firebase deploy --only hosting"
"deploy-prod": "npm run build && firebase deploy --only hosting:prod",
"deploy-dev": "npm run build && firebase deploy --only hosting:dev"
},
"dependencies": {
"core-js": "^3.12.1",
+1 -1
View File
@@ -1,5 +1,5 @@
export const URLs = {
sceneryData: "https://spythere.github.io/api/stationData.json",
sceneryData: "https://spythere.github.io/api/stationDataDev.json",
sceneryDataDev: "http://127.0.0.1:8000/data",
stations: "https://api.td2.info.pl:9640/?method=getStationsOnline",
trains: "https://api.td2.info.pl:9640/?method=getTrainsOnline",
+51 -42
View File
@@ -43,7 +43,41 @@ export interface State {
listenerLaunched: boolean;
}
type StationJSONData = [string, string, string, string, string, string, string, string, boolean, string, string, number, number, number, number, string | null, boolean, boolean, boolean];
interface StationJSONData {
name: string;
url: string;
lines: string;
project: string;
reqLevel: number;
supportersOnly: boolean;
signalType: string;
controlType: string;
SUP: boolean;
SBL: string;
TWB: string;
routes: {
oneWay: {
catenary: number;
noCatenary: number;
};
twoWay: {
catenary: number;
noCatenary: number;
}
};
checkpoints: string | null;
default: boolean;
nonPublic: boolean;
unavailable: boolean;
}
export const key: InjectionKey<Store<State>> = Symbol()
@@ -121,16 +155,16 @@ export const store = createStore<State>({
// commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Error);
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Error);
return;
}
}
commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded);
commit(MUTATIONS.SET_DISPATCHER_DATA_STATUS, onlineDispatchersData.success ? DataStatus.Loaded : DataStatus.Warning);
commit(MUTATIONS.SET_DISPATCHER_DATA_STATUS, onlineDispatchersData.success ? DataStatus.Loaded : DataStatus.Warning);
commit(MUTATIONS.SET_TRAINS_DATA_STATUS, onlineTrainsData.success ? DataStatus.Loaded : DataStatus.Warning);
const updatedStationList: Station['onlineInfo'][] = onlineStationsData.message.reduce((acc, station) => {
if (station.region !== this.state.region.id || !station.isOnline) return acc;
const stationStatus = onlineDispatchersData.success ? onlineDispatchersData.message.find((status: string[]) => status[0] == station.stationHash && status[1] == this.state.region.id) : -1;
const stationStatus = onlineDispatchersData.success ? onlineDispatchersData.message.find((status: string[]) => status[0] == station.stationHash && status[1] == this.state.region.id) : -1;
const statusTimestamp = getStatusTimestamp(stationStatus);
const statusID = getStatusID(stationStatus);
@@ -188,10 +222,10 @@ export const store = createStore<State>({
// Pass reduced lists to mutations
commit(MUTATIONS.UPDATE_STATIONS, updatedStationList);
commit(MUTATIONS.UPDATE_TRAINS, updatedTrainList);
// Statuses
commit(MUTATIONS.SET_DATA_CONNECTION_STATUS, DataStatus.Loaded);
// commit(MUTATIONS.SET_TIMETABLE_DATA_STATUS, DataStatus.Loading);
dispatch(ACTIONS.fetchTimetableData);
})
@@ -207,7 +241,7 @@ export const store = createStore<State>({
const data: { success: boolean; message: TimetableAPIData } = await (await axios.get(URLs.getTimetableURL(train.trainNo, this.state.region.id))).data;
if (!data.success) {
warnings++;
warnings++;
return acc;
}
@@ -304,49 +338,24 @@ export const store = createStore<State>({
mutations: {
SET_SCENERY_DATA(state, data: StationJSONData[]) {
state.stationList = data.map(station => ({
name: station[0],
state.stationList = data.map(stationData => ({
name: stationData.name,
generalInfo: {
name: station[0],
url: station[1],
lines: station[2],
project: station[3],
reqLevel: station[4] == "" || station[4] === null ? -1 : Number(station[4]),
supportersOnly: station[5] == "TAK",
signalType: station[6],
controlType: station[7],
SUP: station[8],
SBL: station[9],
TWB: station[10],
routes: {
oneWay: {
catenary: station[11],
noCatenary: station[12]
},
twoWay: {
catenary: station[13],
noCatenary: station[14]
}
},
checkpoints: station[15] ? (station[15]).split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
default: station[16],
nonPublic: station[17],
unavailable: station[18],
...stationData,
checkpoints: stationData.checkpoints ? stationData.checkpoints.split(";").map(sub => ({ checkpointName: sub, scheduledTrains: [] })) : [],
}
}));
console.log(state.stationList);
},
SET_DATA_CONNECTION_STATUS(state, status: DataStatus) {
state.dataConnectionStatus = status;
},
SET_SCENERY_DATA_STATUS(state, status: DataStatus) {
state.sceneryDataStatus = status;
},