mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
refactor: types & performance
This commit is contained in:
+44
-12
@@ -1,18 +1,21 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import Train from '../scripts/interfaces/Train';
|
||||
import { parseSpawns, getScheduledTrains, getStationTrains } from './utils';
|
||||
|
||||
import { ActiveScenery, ScheduledTrain, StoreState } from './typings';
|
||||
|
||||
import { Status } from '../typings/common';
|
||||
import Station from '../scripts/interfaces/Station';
|
||||
import {
|
||||
ActiveScenery,
|
||||
ScheduledTrain,
|
||||
Station,
|
||||
StationRoutes,
|
||||
Status,
|
||||
Train
|
||||
} from '../typings/common';
|
||||
import { useApiStore } from './apiStore';
|
||||
import { StationRoutes } from '../scripts/interfaces/StationRoutes';
|
||||
import { MainStoreState } from './typings';
|
||||
|
||||
export const useMainStore = defineStore('store', {
|
||||
export const useMainStore = defineStore('mainStore', {
|
||||
state: () =>
|
||||
({
|
||||
region: { id: 'eu', value: 'PL1' },
|
||||
region: { id: 'eu', value: 'PL1', name: 'PL1' },
|
||||
|
||||
isOffline: false,
|
||||
isNewUpdate: false,
|
||||
@@ -29,8 +32,11 @@ export const useMainStore = defineStore('store', {
|
||||
modalLastClickedTarget: null,
|
||||
|
||||
mousePos: { x: 0, y: 0 },
|
||||
popUpData: { key: null, content: '' }
|
||||
}) as StoreState,
|
||||
popUpData: { key: null, content: '' },
|
||||
|
||||
stations: [] as Station[],
|
||||
trainsOnline: [] as Train[]
|
||||
}) as MainStoreState,
|
||||
|
||||
getters: {
|
||||
trainList(): Train[] {
|
||||
@@ -96,6 +102,7 @@ export const useMainStore = defineStore('store', {
|
||||
});
|
||||
},
|
||||
|
||||
// computed active sceneries
|
||||
activeSceneryList(state): ActiveScenery[] {
|
||||
const apiStore = useApiStore();
|
||||
|
||||
@@ -156,8 +163,8 @@ export const useMainStore = defineStore('store', {
|
||||
scenery.dispatcherStatus == Status.ActiveDispatcher.NO_LIMIT
|
||||
? Date.now() + 25500000
|
||||
: scenery.dispatcherStatus > 5
|
||||
? scenery.dispatcherStatus
|
||||
: null;
|
||||
? scenery.dispatcherStatus
|
||||
: null;
|
||||
|
||||
list.push({
|
||||
name: scenery.stationName,
|
||||
@@ -231,6 +238,7 @@ export const useMainStore = defineStore('store', {
|
||||
return allActiveSceneries;
|
||||
},
|
||||
|
||||
// computed station data
|
||||
stationList(): Station[] {
|
||||
const apiStore = useApiStore();
|
||||
|
||||
@@ -283,6 +291,30 @@ export const useMainStore = defineStore('store', {
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
allStationInfo(): Station[] {
|
||||
const onlineUnsavedStations = this.activeSceneryList
|
||||
.filter(
|
||||
(scenery) =>
|
||||
this.stationList.findIndex((st) => st.name == scenery.name) == -1 &&
|
||||
scenery.region == this.region.id
|
||||
)
|
||||
.map((os) => ({
|
||||
name: os.name,
|
||||
generalInfo: undefined,
|
||||
onlineInfo: os
|
||||
}));
|
||||
|
||||
return [
|
||||
...onlineUnsavedStations,
|
||||
...this.stationList.map((st) => ({
|
||||
...st,
|
||||
onlineInfo: this.activeSceneryList.find(
|
||||
(os) => os.name == st.name && os.region == this.region.id
|
||||
)
|
||||
}))
|
||||
];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,26 +77,8 @@ export const useStationFiltersStore = defineStore('stationFiltersStore', {
|
||||
|
||||
filteredStationList: (state) => {
|
||||
const store = useMainStore();
|
||||
const savedStationNames = store.stationList.map((s) => s.name);
|
||||
|
||||
const onlineUnsavedStations = store.activeSceneryList
|
||||
.filter((os) => !savedStationNames.includes(os.name) && os.region == store.region.id)
|
||||
.map((os) => ({
|
||||
name: os.name,
|
||||
generalInfo: undefined,
|
||||
onlineInfo: os
|
||||
}));
|
||||
|
||||
return [
|
||||
...onlineUnsavedStations,
|
||||
...store.stationList.map((station) => ({
|
||||
...station,
|
||||
// append to 'onlineInfo' object for filtering legacy reasons - to optimize later (hopefully)
|
||||
onlineInfo: store.activeSceneryList.find(
|
||||
(os) => os.name == station.name && os.region == store.region.id
|
||||
)
|
||||
}))
|
||||
]
|
||||
return store.allStationInfo
|
||||
.filter((station) => filterStations(station, state.filters))
|
||||
.sort((a, b) => sortStations(a, b, state.sorterActive));
|
||||
}
|
||||
|
||||
+5
-128
@@ -1,18 +1,11 @@
|
||||
import { API } from '../typings/api';
|
||||
import { Status } from '../typings/common';
|
||||
import { Availability, Station, StationRoutesInfo, Status, Train } from '../typings/common';
|
||||
|
||||
export const popupKeys = ['DonatorPopUp', 'TrainCommentsPopUp', 'VehiclePreviewPopUp'] as const;
|
||||
export type Availability = 'default' | 'unavailable' | 'nonPublic' | 'abandoned' | 'nonDefault';
|
||||
export type PopUpType = (typeof popupKeys)[number];
|
||||
|
||||
export interface RegionCounters {
|
||||
stationCount: number;
|
||||
trainsCount: number;
|
||||
timetablesCount: number;
|
||||
}
|
||||
|
||||
export interface StoreState {
|
||||
region: { id: string; value: string };
|
||||
export interface MainStoreState {
|
||||
region: { id: string; value: string; name: string };
|
||||
isOffline: boolean;
|
||||
isNewUpdate: boolean;
|
||||
dispatcherStatsName: string;
|
||||
@@ -24,17 +17,8 @@ export interface StoreState {
|
||||
modalLastClickedTarget: EventTarget | null;
|
||||
mousePos: { x: number; y: number };
|
||||
popUpData: { key: PopUpType | null; content: string };
|
||||
}
|
||||
|
||||
export interface StationRoutesInfo {
|
||||
routeName: string;
|
||||
isElectric: boolean;
|
||||
isInternal: boolean;
|
||||
isRouteSBL: boolean;
|
||||
routeLength: number;
|
||||
routeSpeed: number;
|
||||
routeTracks: number;
|
||||
hidden?: boolean;
|
||||
stations: Station[];
|
||||
trainsOnline: Train[];
|
||||
}
|
||||
|
||||
export interface StationJSONData {
|
||||
@@ -62,110 +46,3 @@ export interface StationJSONData {
|
||||
|
||||
availability: Availability;
|
||||
}
|
||||
|
||||
export interface ActiveScenery {
|
||||
name: string;
|
||||
hash: string;
|
||||
region: string;
|
||||
maxUsers: number;
|
||||
currentUsers: number;
|
||||
spawns: { spawnName: string; spawnLength: number; isElectrified: boolean }[];
|
||||
dispatcherName: string;
|
||||
dispatcherRate: number;
|
||||
dispatcherId: number;
|
||||
dispatcherExp: number;
|
||||
dispatcherIsSupporter: boolean;
|
||||
|
||||
dispatcherStatus: Status.ActiveDispatcher | number;
|
||||
dispatcherTimestamp: number | null;
|
||||
|
||||
isOnline: boolean;
|
||||
|
||||
stationTrains?: StationTrain[];
|
||||
scheduledTrains?: ScheduledTrain[];
|
||||
|
||||
scheduledTrainCount: {
|
||||
all: number;
|
||||
confirmed: number;
|
||||
unconfirmed: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface StationTrain {
|
||||
driverName: string;
|
||||
driverId: number;
|
||||
trainNo: number;
|
||||
trainId: string;
|
||||
stopStatus: string;
|
||||
}
|
||||
|
||||
export interface ScheduledTrain {
|
||||
checkpointName: string;
|
||||
|
||||
trainId: string;
|
||||
trainNo: number;
|
||||
|
||||
driverName: string;
|
||||
driverId: number;
|
||||
currentStationName: string;
|
||||
currentStationHash: string;
|
||||
category: string;
|
||||
stopInfo: TrainStop;
|
||||
|
||||
terminatesAt: string;
|
||||
beginsAt: string;
|
||||
|
||||
prevStationName: string;
|
||||
nextStationName: string;
|
||||
|
||||
arrivingLine: string | null;
|
||||
departureLine: string | null;
|
||||
|
||||
prevDepartureLine: string | null;
|
||||
nextArrivalLine: string | null;
|
||||
|
||||
signal: string;
|
||||
connectedTrack: string;
|
||||
|
||||
stopLabel: string;
|
||||
stopStatus: StopStatus;
|
||||
stopStatusID: number;
|
||||
|
||||
region: string;
|
||||
}
|
||||
|
||||
export enum StopStatus {
|
||||
ARRIVING = 'arriving',
|
||||
DEPARTED = 'departed',
|
||||
DEPARTED_AWAY = 'departed-away',
|
||||
ONLINE = 'online',
|
||||
STOPPED = 'stopped',
|
||||
TERMINATED = 'terminated'
|
||||
}
|
||||
|
||||
export interface TrainStop {
|
||||
stopName: string;
|
||||
stopNameRAW: string;
|
||||
stopType: string;
|
||||
stopDistance: number;
|
||||
mainStop: boolean;
|
||||
|
||||
arrivalLine: string | null;
|
||||
arrivalTimestamp: number;
|
||||
arrivalRealTimestamp: number;
|
||||
arrivalDelay: number;
|
||||
|
||||
departureLine: string | null;
|
||||
departureTimestamp: number;
|
||||
departureRealTimestamp: number;
|
||||
departureDelay: number;
|
||||
pointId: number;
|
||||
|
||||
comments?: string;
|
||||
|
||||
beginsHere: boolean;
|
||||
terminatesHere: boolean;
|
||||
confirmed: boolean;
|
||||
stopped: boolean;
|
||||
stopTime: number | null;
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,6 +1,11 @@
|
||||
import Station from '../scripts/interfaces/Station';
|
||||
import Train from '../scripts/interfaces/Train';
|
||||
import { ScheduledTrain, StationTrain, StopStatus, TrainStop } from './typings';
|
||||
import {
|
||||
TrainStop,
|
||||
StopStatus,
|
||||
Train,
|
||||
ScheduledTrain,
|
||||
Station,
|
||||
StationTrain
|
||||
} from '../typings/common';
|
||||
|
||||
export function getLocoURL(locoType: string): string {
|
||||
return `https://rj.td2.info.pl/dist/img/thumbnails/${
|
||||
|
||||
Reference in New Issue
Block a user