chore: added extra data to vehicles tooltip

This commit is contained in:
2024-06-03 18:10:45 +02:00
parent 8190dfa2cb
commit 26b1ec246d
2 changed files with 42 additions and 6 deletions
+3 -3
View File
@@ -23,15 +23,15 @@
<ul v-else> <ul v-else>
<li v-for="(stockName, i) in computedStockList" :key="i"> <li v-for="(stockName, i) in computedStockList" :key="i">
<p> <p>
{{ stockName.split(':')[0].split('_').splice(0, 2).join(' ') }} {{ stockName.split(':')[0].split('_').splice(0, 3).join(' ') }}
{{ stockName.split(':')[1] }} <div v-if="stockName.split(':')[1]">({{ stockName.split(':')[1] }})</div>
</p> </p>
<span> <span>
<img <img
:data-mouseover="stockName" :data-mouseover="stockName"
data-tooltip-type="VehiclePreviewTooltip" data-tooltip-type="VehiclePreviewTooltip"
:data-tooltip-content="stockName.split(':')[0]" :data-tooltip-content="stockName"
:src=" :src="
getVehicleThumbnailURL(stockName.split(':')[0], /^EN/.test(stockName) ? 'rb' : '') getVehicleThumbnailURL(stockName.split(':')[0], /^EN/.test(stockName) ? 'rb' : '')
" "
@@ -13,13 +13,20 @@
width="300" width="300"
height="176" height="176"
class="rounded-md w-full h-auto" class="rounded-md w-full h-auto"
:src="`https://static.spythere.eu/images/${tooltipStore.content}--300px.jpg`" :src="`https://static.spythere.eu/images/${vehicleName}--300px.jpg`"
/> />
<div v-if="imageState == 'error'" class="error-placeholder"></div> <div v-if="imageState == 'error'" class="error-placeholder"></div>
<div class="vehicle-name"> <div class="vehicle-name">
{{ tooltipStore.content.replace(/_/g, ' ') }} {{ vehicleName.replace(/_/g, ' ') }}
<span v-if="vehicleCargo">({{ vehicleCargo.id }})</span>
</div>
<div class="vehicle-props" v-if="vehicleProps">
{{ vehicleProps.speed }}km/h &bull; {{ vehicleProps.length }}m &bull;
{{ (vehicleProps.weight / 1000).toFixed(1) }}t
<span v-if="vehicleCargo">(+{{ (vehicleCargo.weight / 1000).toFixed(1) }}t)</span>
</div> </div>
</div> </div>
</template> </template>
@@ -27,11 +34,13 @@
<script lang="ts"> <script lang="ts">
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useTooltipStore } from '../../store/tooltipStore'; import { useTooltipStore } from '../../store/tooltipStore';
import { useApiStore } from '../../store/apiStore';
export default defineComponent({ export default defineComponent({
data() { data() {
return { return {
tooltipStore: useTooltipStore(), tooltipStore: useTooltipStore(),
apiStore: useApiStore(),
imageState: 'loading' imageState: 'loading'
}; };
}, },
@@ -56,6 +65,30 @@ export default defineComponent({
(e.target as HTMLElement).style.display = 'none'; (e.target as HTMLElement).style.display = 'none';
} }
},
computed: {
vehicleName() {
return this.tooltipStore.content.split(':')[0];
},
vehicleCargo() {
return this.vehicleProps?.cargoTypes?.find(
(c) => c.id == this.tooltipStore.content.split(':')[1]
);
},
vehicleProps() {
const vehicleDataArray = this.apiStore.vehiclesData?.vehicleList.find(
([name]) => name === this.vehicleName
);
if (!vehicleDataArray) return null;
return (
this.apiStore.vehiclesData!.vehicleProps.find((v) => v.type == vehicleDataArray[1]) ?? null
);
}
} }
}); });
</script> </script>
@@ -85,10 +118,13 @@ img {
.vehicle-name { .vehicle-name {
text-align: center; text-align: center;
margin-top: 0.5em; margin-top: 0.5em;
color: #ccc;
text-wrap: wrap; text-wrap: wrap;
} }
.vehicle-props {
color: #ccc;
}
.error-placeholder { .error-placeholder {
height: 176px; height: 176px;
} }