Skip to content

Commit

Permalink
🚧 #77 [feat/config] rework the loading config
Browse files Browse the repository at this point in the history
Signed-off-by: JAGFx <contact@jagfx.fr>
  • Loading branch information
JAGFx committed Nov 1, 2021
1 parent ccfc79e commit a53f05a
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 203 deletions.
103 changes: 53 additions & 50 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<main :class="`${Object.hasOwnProperty.apply( 'game', telemetry.game ) ? telemetry.game.game.name : ''}`">
<LoadingOverlay :display="gameConnected" />
<!-- <LoadingOverlay :display="!appReady || !gameConfigLoaded" />-->
<HistoryOverlay />
<Overlay v-if="gameConnected" />
<TelemetryEventOverlay v-if="gameConnected" />
<Header />
<Overlay />
<TelemetryEventOverlay v-if="appReady" />
<Header v-if="appReady" />
<component
:is="currentSkinComponent()"
v-if="gameConnected"
v-if="appReady"
v-show="!menuIsDisplayed"
/>
</main>
Expand All @@ -20,19 +20,24 @@ import JAGFxDashboard from '@/components/dashboards/JAGFxDashboard';
import ManTGXDashboard from '@/components/dashboards/ManTGXDashboard';
import MapDashboard from '@/components/dashboards/MapDashboard';
import MercedesAtegoDashboard from '@/components/dashboards/MercedesAtegoDashboard';
import RdInfoDashboard from '@/components/dashboards/RdInfoDashboard';
import ScaniaDashboard from '@/components/dashboards/ScaniaDashboard';
import TestDashboard from '@/components/dashboards/TestDashboard';
import VolvoFHDashboard from '@/components/dashboards/VolvoFHDashboard';
import Header from '@/components/header/Header';
import HistoryOverlay from '@/components/overlays/HistoryOverlay';
import LoadingOverlay from '@/components/overlays/LoadingOverlay';
import Overlay from '@/components/overlays/Overlay';
import TelemetryEventOverlay from '@/components/overlays/telemetry-event/TelemetryEventOverlay';
import TelemetryMixin from '@/mixins/TelemetryMixin';
import { changeLocale, fallbackLocale } from '@/utils/_i18n';
import { history } from '@/utils/utils';
import { mapGetters } from 'vuex';
import RdInfoDashboard from '@/components/dashboards/RdInfoDashboard';
import ScaniaDashboard from '@/components/dashboards/ScaniaDashboard';
import TestDashboard from '@/components/dashboards/TestDashboard';
import VolvoFHDashboard from '@/components/dashboards/VolvoFHDashboard';
import Header from '@/components/header/Header';
import HistoryOverlay from '@/components/overlays/HistoryOverlay';
import Overlay from '@/components/overlays/Overlay';
import TelemetryEventOverlay from '@/components/overlays/telemetry-event/TelemetryEventOverlay';
import TelemetryMixin from '@/mixins/TelemetryMixin';
import {
loadAppConfig,
loadGameConfig,
setConfigActive,
setLocale,
startTelemetryConnection
} from '@/utils/_splashScreen';
import { history } from '@/utils/utils';
import { mapGetters } from 'vuex';
export default {
name: 'App',
Expand All @@ -51,48 +56,46 @@ export default {
Overlay,
HistoryOverlay,
Header,
LoadingOverlay
},
mixins: [TelemetryMixin],
computed: {
...mapGetters( {
menuIsDisplayed: 'menu/isDisplayed',
currentSkin: 'skins/current',
getConfig: 'config/get',
configExist: 'config/exist'
configExist: 'config/exist',
gameConfigLoaded: 'config/gameConfigLoaded',
isLaunched: 'app/isLaunched'
} )
},
mounted() {
this.$pushALog( 'App launched', history.HTY_ZONE.MAIN );
this.$store
.dispatch( 'config/load' )
.then( () => {
this.$pushALog( 'Config loaded', history.HTY_ZONE.MAIN );
const skinToLoad = this.config( 'general_skin_on_load' );
try {
this.$store.commit( 'skins/setConfigActive', skinToLoad );
} catch ( e ) {
this.$pushALog( 'Value set in "general_skin_on_load" was not a valid skin: ' + skinToLoad,
history.HTY_ZONE.MAIN,
history.HTY_LEVEL.ERROR );
this.$store.dispatch( 'skins/setFirstActive' );
}
const locale = this.config( 'general_skin_locale' );
try {
changeLocale( locale )
} catch ( e ) {
this.$pushALog( `Value set in "general_skin_locale" was not a valid skin: ${locale}. Revert to fallback locale: ${fallbackLocale}`,
history.HTY_ZONE.MAIN,
history.HTY_LEVEL.ERROR );
changeLocale( fallbackLocale )
}
} );
this.$store.dispatch('app/showMessage', {
icon: null,
title: 'Launching'
} )
loadAppConfig()
.then( setConfigActive )
.then( setLocale )
.then( startTelemetryConnection )
.then( loadGameConfig )
.then(() => {
//this.$store.commit('app/setLaunched', true)
this.$pushALog( 'App launched', history.HTY_ZONE.MAIN );
//console.log( 'Launched' );
})
.catch( e => {
this.$store.dispatch( 'app/setError', {
message: {
icon: null,
title: 'Unable to launch',
message: 'An error occurred during the launching',
},
details: {
message: e.message,
code: 'APP_LAUNCH'
}
} )
} )
/*// HeaderGameInformation connected
setTimeout(()=> {
Expand Down
15 changes: 7 additions & 8 deletions src/components/dashboards/shared/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@
</template>

<script>
import testData from '@/data/scs_sdk_plugin_parsed_data.json';
import TelemetryMixin from '@/mixins/TelemetryMixin';
import { app, history, map } from '@/utils/utils';
import { mapGetters } from 'vuex';
import TelemetryMixin from '@/mixins/TelemetryMixin';
import { history, map } from '@/utils/utils';
import { mapGetters } from 'vuex';
export default {
name: 'Map',
Expand Down Expand Up @@ -318,10 +317,10 @@ export default {
this.rotateWithPlayer = map.d.gBehaviorRotateWithPlayer;
// --- Dev
if ( app.useFakeData )
setTimeout( () => {
this.$updateTelemetry( testData )
}, 1000 );
//if ( app.useFakeData )
// setTimeout( () => {
// this.$updateTelemetry( testData )
// }, 1000 );
// --- ./Dev
} )
.catch( e => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/header/Header.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div id="header">
<HeaderGameInformation
v-if="gameConnected"
v-if="appReady"
id="game"
/>
<div
v-if="gameConnected"
v-if="appReady"
v-show="menuIsDisplayed"
class="wrapper menu h-100"
>
Expand Down
1 change: 1 addition & 0 deletions src/components/menu/MenuTabConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
this.$pushALog( 'Config upload done', history.HTY_ZONE.MENU_CONFIG );
//console.log( data );
// TODO: Change it
this.$store.commit( 'config/setElms', data );
}, e => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/overlays/LoadingOverlay.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<b-overlay
:show="!display"
:show="display"
:variant="'dark'"
no-wrap
>
Expand All @@ -24,10 +24,10 @@
{{ $t(launching.text) }}
</h1>
<small class="mb-3">{{ $t(launching.subText) }}</small>
<b-spinner
:label="$t('Processing')"
type="grow"
/>
<!-- <b-spinner-->
<!-- :label="$t('Processing')"-->
<!-- type="grow"-->
<!-- />-->
</div>
</transition>
</div>
Expand Down
115 changes: 64 additions & 51 deletions src/components/overlays/Overlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,81 @@
<div class="overlay">
<b-overlay
:show="isOnProcessing"
:variant="message.type"
:variant="'dark'"
no-wrap
>
<template #overlay>
<div class="d-flex justify-content-center flex-column align-items-center">
<h1>{{ $t(message.title) }}</h1>
<small
v-show="message.message !== null"
class="mb-3"
>{{ $t(message.message) }}</small>
<b-spinner
v-if="!hasError"
:label="$t('Processing')"
type="grow"
/>
<button
v-if="hasError"
class="btn btn-sm btn-outline-ets"
@click="close"
>
OK
</button>

<div
v-if="hasError"
class="details mt-3"
>
<transition
mode="out-in"
name="slide-fade"
>
<div class="d-flex justify-content-center flex-column align-items-center">
<h1 v-if="message.icon">
<span
class="mb-3"
v-html="message.icon"
/>
</h1>
<h1 class="text-center">
{{ $t(message.title) }}
</h1>
<small
v-if="message.message !== null"
class="mb-3"
>{{ $t(message.message) }}</small>
<!-- <b-spinner-->
<!-- v-if="!hasError"-->
<!-- :label="$t('Processing')"-->
<!-- type="grow"-->
<!-- />-->
<button
v-if="hasError"
class="btn btn-sm btn-outline-ets"
@click="close"
>
OK
</button>

<div
class="d-flex w-100 flex-column justify-content-center align-items-center"
style="min-width:20rem"
v-if="hasError"
class="details mt-3"
>
<div @click="showDetails = !showDetails">
<small class="text-center px-3">{{ $t(( !showDetails ) ? 'Show' : 'Hide') }} {{ $t('more details') }}</small>
<i class="fas fa-caret-down" />
</div>

<div
v-if="showDetails"
class="d-flex flex-column justify-content-between"
class="d-flex w-100 flex-column justify-content-center align-items-center"
style="min-width:20rem"
>
<div class="h d-flex justify-content-between align-items-center mb-2">
<span>#{{ details.code }}</span>
<button
v-clipboard:copy="JSON.stringify( details, null, 2 )"
class="copy btn btn-sm btn-outline-ets d-flex justify-content-around align-items-center"
>
<i class="far fa-clipboard pr-1" />
{{ $t('Copy') }}
</button>
<div @click="showDetails = !showDetails">
<small class="text-center px-3">{{ $t(( !showDetails ) ? 'Show' : 'Hide') }} {{ $t('more details') }}</small>
<i class="fas fa-caret-down" />
</div>

<div
v-if="showDetails"
class="d-flex flex-column justify-content-between"
>
<div class="h d-flex justify-content-between align-items-center mb-2">
<span>#{{ details.code }}</span>
<button
v-clipboard:copy="JSON.stringify( details, null, 2 )"
class="copy btn btn-sm btn-outline-ets d-flex justify-content-around align-items-center"
>
<i class="far fa-clipboard pr-1" />
{{ $t('Copy') }}
</button>
</div>
<pre class="w-100 p-2">{{ JSON.stringify( details, null, 2 ) }}</pre>
<span>{{ $t('You can') }} <a
href="https://github.com/JAGFx/ets2-dashboard-skin/issues/new/choose"
target="_blank"
>{{ $t('create an issue') }}</a> {{ $t('and/or contact me at') }} <a
href="mailto:hey@emmanuel-smith.me"
target="_blank"
>hey@emmanuel-smith.me</a> {{ $t('with the above details') }}</span>
</div>
<pre class="w-100 p-2">{{ JSON.stringify( details, null, 2 ) }}</pre>
<span>{{ $t('You can') }} <a
href="https://github.com/JAGFx/ets2-dashboard-skin/issues/new/choose"
target="_blank"
>{{ $t('create an issue') }}</a> {{ $t('and/or contact me at') }} <a
href="mailto:hey@emmanuel-smith.me"
target="_blank"
>hey@emmanuel-smith.me</a> {{ $t('with the above details') }}</span>
</div>
</div>
</div>
</div>
</transition>
</template>
</b-overlay>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/data/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"general_unit_auto" : false,
"general_h-shift-layout" : "h-shifter",
"general_skin_locale" : "en-EN",
"general_job_remaining" : "due_date"
"general_job_remaining" : "due_date"
}
2 changes: 1 addition & 1 deletion src/mixins/ConfigFieldMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
computed: {
...mapGetters( {
current: 'config/get',
appGetProcessing: 'app/getProcessing'
appGetProcessing: 'app/isOnProcessing'
} )
},
mounted() {
Expand Down
16 changes: 9 additions & 7 deletions src/mixins/TelemetryMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
temperature as uc_temperature,
volume as uc_volume
} from 'units-converter';
import { store } from '@/store/telemetry.store';
import { store as telemetryStore } from '@/store/telemetry.store';
import store from '@/store';
export default {
name: 'TelemetryMixin',
Expand All @@ -20,12 +21,13 @@ export default {
}
},
computed: {
telemetry: () => store.telemetry,
gameConnected: () => (app.useFakeData
|| (store.receivedData && store.telemetry.game.sdkActive
&& (store.telemetry.truck.brand.id.length !== 0)))
&& this.config('unit_weight'),
receivedData: () => store.receivedData,
telemetry: () => telemetryStore.telemetry,
appReady: () => telemetryStore.receivedData
&& telemetryStore.telemetry.game.sdkActive
&& telemetryStore.telemetry.truck.brand.id.length !== 0
&& store.getters['app/isLaunched']
&& store.getters['config/gameConfigLoaded'],
receivedData: () => telemetryStore.receivedData,
jobDeliveryTime() {
return (this.telemetry.job.market.id === 'external_contracts')
? this.telemetry.job.expectedDeliveryTimestamp.value
Expand Down
Loading

0 comments on commit a53f05a

Please sign in to comment.