@@ -21,24 +21,42 @@ export const PitMessage = (se, oldCar, newCar, cache) => {
2121
2222 const driverText = driver ? ` (${ driver } )` : '' ;
2323
24+ if ( oldState !== 'FUEL' && newState === 'FUEL' ) {
25+ cache [ 'PitMessage' ] [ carNum ] . lastFuelIn = cache . lastUpdated ;
26+ }
27+
28+ if ( oldState === 'FUEL' && newState !== 'FUEL' ) {
29+ cache [ 'PitMessage' ] [ carNum ] . lastFuelOut = cache . lastUpdated ;
30+ }
31+
32+ if ( oldState !== 'PIT' && newState === 'PIT' ) {
33+ cache [ 'PitMessage' ] [ carNum ] . lastPitIn = cache . lastUpdated ;
34+ }
35+
36+ if ( oldState === 'PIT' && newState !== 'PIT' ) {
37+ cache [ 'PitMessage' ] [ carNum ] . lastPitOut = cache . lastUpdated ;
38+ }
39+
2440 if ( ( oldState !== 'RUN' && oldState !== 'STOP' && newState === 'OUT' ) || ( ( oldState === 'PIT' || oldState === 'FUEL' ) && newState === 'RUN' ) ) {
25- const lastPitIn = cache [ 'PitMessage' ] [ carNum ] . lastPitIn ;
41+ const { lastFuelIn , lastFuelOut , lastPitIn, lastPitOut } = cache [ 'PitMessage' ] [ carNum ] ;
2642 let pitTimeMsg = '' ;
27- if ( Number . isInteger ( lastPitIn ) ) {
28- const pitTime = cache . lastUpdated - lastPitIn ;
29- pitTimeMsg = `(pit time: ${ timeInSeconds ( pitTime , 0 ) } )` ;
30- delete cache [ 'PitMessage' ] [ carNum ] . lastPitIn ;
43+ if ( Number . isInteger ( lastPitIn ) && Number . isInteger ( lastPitOut ) ) {
44+ const pitTime = lastPitOut - lastPitIn ;
45+
46+ const fuelTime = ( lastFuelOut || 0 ) - ( lastFuelIn || 0 ) ;
47+ if ( fuelTime > 0 ) {
48+ pitTimeMsg = `(total pit time: ${ timeInSeconds ( pitTime + fuelTime , 0 ) } , ${ timeInSeconds ( fuelTime , 0 ) } fuel)` ;
49+ }
50+ else {
51+ pitTimeMsg = `(pit time: ${ timeInSeconds ( pitTime , 0 ) } )` ;
52+ }
53+
54+ delete cache [ 'PitMessage' ] [ carNum ] ;
3155 }
3256 return new Message ( clazz , `#${ carNum } ${ driverText } has left the pits ${ pitTimeMsg } ` . trim ( ) , 'out' , carNum ) ;
3357 }
3458 else if ( newState === 'PIT' ) {
35- if ( oldState !== 'FUEL' ) {
36- cache [ 'PitMessage' ] [ carNum ] . lastPitIn = cache . lastUpdated ;
37- }
3859 return new Message ( clazz , `#${ carNum } ${ driverText } has entered the pits` , 'pit' , carNum ) ;
3960 }
40- else if ( newState === 'FUEL' && oldState !== 'PIT' ) {
41- cache [ 'PitMessage' ] [ carNum ] . lastPitIn = cache . lastUpdated ;
42- }
4361 }
4462} ;
0 commit comments