From e117f62fcba9616b39d9dc7f889403bd0c76c473 Mon Sep 17 00:00:00 2001 From: Spythere Date: Thu, 16 May 2024 19:59:43 +0200 Subject: [PATCH] chore: added station filters (scenery types); pwa adjustments --- src/components/Global/StockList.vue | 25 ++++++---- src/components/StationsView/StationStats.vue | 51 ++++++++++++++------ src/components/StationsView/typings.ts | 2 + src/data/options.json | 15 ++++++ src/locales/en.json | 6 ++- src/locales/pl.json | 6 ++- src/main.ts | 9 +++- src/mixins/useCustomSW.ts | 13 ----- src/scripts/utils/stationFilterUtils.ts | 7 +++ src/store/stationFiltersStore.ts | 18 ++++--- src/store/utils.ts | 6 --- vite.config.ts | 14 +----- 12 files changed, 104 insertions(+), 68 deletions(-) delete mode 100644 src/mixins/useCustomSW.ts diff --git a/src/components/Global/StockList.vue b/src/components/Global/StockList.vue index a2fbecc..f4ec337 100644 --- a/src/components/Global/StockList.vue +++ b/src/components/Global/StockList.vue @@ -8,9 +8,12 @@
- • {{ $t('station-stats.u-factor') }} • {{ $t('station-stats.single-track-count') }} - {{ trackCount.oneWayElectric }} {{ $t('station-stats.electrified') }} / - {{ trackCount.oneWayOther }} {{ $t('station-stats.not-electrified') }} + {{ trackCount.oneWay }} ({{ trackCount.oneWayElectric }} ⚡)
• {{ $t('station-stats.double-track-count') }} - {{ trackCount.twoWayElectric }} {{ $t('station-stats.electrified') }} / - {{ trackCount.twoWayOther }} - {{ $t('station-stats.not-electrified') }} + {{ trackCount.twoWay }} + ({{ trackCount.twoWayElectric }} ⚡)
-
• {{ $t('station-stats.cross-sceneries') }} test
+
+ • {{ $t('station-stats.cross-sceneries') }} {{ trackCount.crossTrack }} ({{ trackCount.crossTrackElectric }} ⚡) +
• @@ -101,15 +102,14 @@ export default defineComponent({ if (scheduledTrainsArr.length == 0) return 0; - let v1 = scheduledTrainsArr[scheduledTrainsArr.length / 2]; - if (scheduledTrainsArr.length % 2 == 0) { + let v1 = scheduledTrainsArr[scheduledTrainsArr.length / 2]; let v2 = scheduledTrainsArr[scheduledTrainsArr.length / 2 - 1]; return (v1 + v2) / 2; } - return v1; + return scheduledTrainsArr[~~(scheduledTrainsArr.length / 2)]; }, trackCount() { @@ -122,17 +122,38 @@ export default defineComponent({ ) .reduce( (acc, st) => { - [...st.generalInfo!.routes.single, ...st.generalInfo!.routes.double].forEach((r) => { + const { routes } = st.generalInfo!; + + if ( + routes.single.filter((r) => !r.isInternal).length > 0 && + routes.double.filter((r) => !r.isInternal).length > 0 + ) { + acc.crossTrack++; + + if ( + routes.single.some((r) => r.isElectric) && + routes.double.some((r) => r.isElectric) + ) + acc.crossTrackElectric++; + } + + [...routes.single, ...routes.double].forEach((r) => { if (r.isInternal) return; - const keyName: keyof typeof acc = `${r.routeTracks == 2 ? 'twoWay' : 'oneWay'}${r.isElectric ? 'Electric' : 'Other'}`; - - acc[keyName] += 1; + acc[r.routeTracks == 2 ? 'twoWay' : 'oneWay'] += 1; + if (r.isElectric) acc[r.routeTracks == 2 ? 'twoWayElectric' : 'oneWayElectric'] += 1; }); return acc; }, - { oneWayElectric: 0, oneWayOther: 0, twoWayElectric: 0, twoWayOther: 0 } + { + oneWay: 0, + oneWayElectric: 0, + twoWay: 0, + twoWayElectric: 0, + crossTrack: 0, + crossTrackElectric: 0 + } ); }, diff --git a/src/components/StationsView/typings.ts b/src/components/StationsView/typings.ts index 674ef11..aa23860 100644 --- a/src/components/StationsView/typings.ts +++ b/src/components/StationsView/typings.ts @@ -55,4 +55,6 @@ export interface Filter { onlineFromHours: number; withActiveTimetables: boolean; withoutActiveTimetables: boolean; + junction: boolean; + nonJunction: boolean; } diff --git a/src/data/options.json b/src/data/options.json index 64badce..be322e2 100644 --- a/src/data/options.json +++ b/src/data/options.json @@ -4,6 +4,7 @@ "timetables", "reality", "package-access", + "station-type", "access", "control", "blockades", @@ -61,6 +62,20 @@ "value": false, "defaultValue": false }, + { + "id": "junction", + "name": "junction", + "section": "station-type", + "value": true, + "defaultValue": true + }, + { + "id": "nonJunction", + "name": "nonJunction", + "section": "station-type", + "value": true, + "defaultValue": true + }, { "id": "SPK", "name": "SPK", diff --git a/src/locales/en.json b/src/locales/en.json index c30c1be..c0143cb 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -174,6 +174,7 @@ "sections": { "quick": "QUICK FILTERS", + "station-type": "STATION TYPE", "reality": "SCENERY REALITY", "package-access": "IN-GAME AVAILABILITY", "access": "GENERAL AVAILABILITY", @@ -233,6 +234,9 @@ "withActiveTimetables": "ACTIVE", "withoutActiveTimetables": "NO ACTIVE", + "junction": "JUNCTIONS", + "nonJunction": "OTHER", + "sliders": { "min-lvl": "MIN. REQUIRED DISPATCHER LEVEL", "max-lvl": "MAX. REQUIRED DISPATCHER LEVEL", @@ -303,8 +307,6 @@ "single-track-count": "Single track routes:", "double-track-count": "Double track routes:", "cross-sceneries": "Cross-track sceneries (1-track <-> 2-track)", - "electrified": "(electrified)", - "not-electrified": "(not electr.)", "open-spawns": "Open spawns:" }, "trains": { diff --git a/src/locales/pl.json b/src/locales/pl.json index 8a33007..9ad41ee 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -171,6 +171,7 @@ "sections": { "quick": "SZYBKIE FILTRY", + "station-type": "RODZAJ STACJI", "reality": "FIKCYJNOŚĆ SCENERII", "package-access": "DOSTĘPNOŚĆ W PACZCE", "access": "DOSTĘPNOŚĆ OGÓLNA", @@ -229,6 +230,9 @@ "withActiveTimetables": "AKTYWNE", "withoutActiveTimetables": "BEZ AKTYWNYCH", + "junction": "WĘZŁOWE", + "nonJunction": "INNE", + "sliders": { "min-lvl": "MIN. WYMAGANY POZIOM DYŻURNEGO", "max-lvl": "MAKS. WYMAGANY POZIOM DYŻURNEGO", @@ -296,8 +300,6 @@ "single-track-count": "Szlaki jednotorowe:", "double-track-count": "Szlaki dwutorowe:", "cross-sceneries": "Scenerie przejściowe (1-tor <-> 2-tor):", - "electrified": "(zelektr.)", - "not-electrified": "(niezelektr.)", "open-spawns": "Otwarte spawny:" }, "trains": { diff --git a/src/main.ts b/src/main.ts index d359bd7..a58eb39 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,10 +5,15 @@ import router from './router'; import i18n from './i18n'; import { createPinia } from 'pinia'; -import useCustomSW from './mixins/useCustomSW'; +import { registerSW } from 'virtual:pwa-register'; // Service worker -useCustomSW(); +registerSW({ + immediate: true, + onNeedRefresh() { + console.log('Needs refresh!'); + } +}); const clickOutsideDirective: Directive = { mounted(el, binding) { diff --git a/src/mixins/useCustomSW.ts b/src/mixins/useCustomSW.ts deleted file mode 100644 index a8d03d0..0000000 --- a/src/mixins/useCustomSW.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { useRegisterSW } from 'virtual:pwa-register/vue'; - -export default () => { - const { needRefresh, updateServiceWorker, offlineReady } = useRegisterSW({ - immediate: true - }); - - return { - needRefresh, - updateServiceWorker, - offlineReady - }; -}; diff --git a/src/scripts/utils/stationFilterUtils.ts b/src/scripts/utils/stationFilterUtils.ts index 1bc04a1..d483f89 100644 --- a/src/scripts/utils/stationFilterUtils.ts +++ b/src/scripts/utils/stationFilterUtils.ts @@ -229,6 +229,13 @@ export const filterStations = (station: Station, filters: Filter) => { !authors?.map((a) => a.toLocaleLowerCase()).includes(filters['authors'].toLocaleLowerCase()) ) return false; + + const singleTracks = routes.single.filter((r) => !r.isInternal); + const doubleTracks = routes.double.filter((r) => !r.isInternal); + + let isJunction = singleTracks.length > 0 && doubleTracks.length > 0; + if (filters['junction'] && isJunction) return false; + if (filters['nonJunction'] && !isJunction) return false; } return true; diff --git a/src/store/stationFiltersStore.ts b/src/store/stationFiltersStore.ts index f3b570b..191ddba 100644 --- a/src/store/stationFiltersStore.ts +++ b/src/store/stationFiltersStore.ts @@ -30,12 +30,6 @@ const filterInitStates: Filter = { mieszana: false, SBL: false, PBL: false, - minLevel: 0, - maxLevel: 20, - minOneWayCatenary: 0, - minOneWay: 0, - minTwoWayCatenary: 0, - minTwoWay: 0, 'include-selected': false, 'no-1track': false, 'no-2track': false, @@ -52,10 +46,20 @@ const filterInitStates: Filter = { unsignedStatus: false, withActiveTimetables: false, withoutActiveTimetables: false, + + junction: false, + nonJunction: false, + maxVmax: 200, minVmax: 0, authors: '', - onlineFromHours: 0 + onlineFromHours: 0, + minLevel: 0, + maxLevel: 20, + minOneWayCatenary: 0, + minOneWay: 0, + minTwoWayCatenary: 0, + minTwoWay: 0 }; export const useStationFiltersStore = defineStore('stationFiltersStore', { diff --git a/src/store/utils.ts b/src/store/utils.ts index 43c131c..36413e1 100644 --- a/src/store/utils.ts +++ b/src/store/utils.ts @@ -9,12 +9,6 @@ import { ScenerySpawnType } from '../typings/common'; -export function getLocoURL(locoType: string): string { - return `https://rj.td2.info.pl/dist/img/thumbnails/${ - locoType.includes('EN') ? locoType + 'rb' : locoType - }.png`; -} - export function getStatusTimestamp(stationStatus: any): number { if (!stationStatus) return -2; diff --git a/vite.config.ts b/vite.config.ts index 58c5daa..a8235d0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,20 +30,10 @@ export default defineConfig({ } }, { - urlPattern: new RegExp('^https://rj.td2.info.pl/dist/img/thumbnails/*', 'i'), + urlPattern: new RegExp('^https://static.spythere.eu/*', 'i'), handler: 'CacheFirst', options: { - cacheName: 'swdr-images-cache', - cacheableResponse: { - statuses: [0, 200, 404] - } - } - }, - { - urlPattern: new RegExp('^https://static.spythere.eu/images/*', 'i'), - handler: 'CacheFirst', - options: { - cacheName: 'spythere-images-cache', + cacheName: 'spythere-cache', cacheableResponse: { statuses: [0, 200] }