@@ -13,12 +13,12 @@ import { FaiSectors } from '../../gm/fai-sectors';
13
13
import { addAltitude } from '../../logic/elevation' ;
14
14
import { getCurrentUrl , pushCurrentState } from '../../logic/history' ;
15
15
import { drawRoute } from '../../logic/messages' ;
16
- import { CircuitType , Score } from '../../logic/score/scorer' ;
16
+ import { CircuitType , getCircuitType , Score } from '../../logic/score/scorer' ;
17
17
import { setDistance , setEnabled , setRoute , setScore } from '../../redux/planner-slice' ;
18
18
import { RootState , store } from '../../redux/store' ;
19
19
import { PlannerElement } from './planner-element' ;
20
- import { OptimizationResult , optimize , ScoringRules , ScoringTrack } from 'optimizer' ;
21
- import { LeagueCode } from '../../logic/score/league/leagues' ;
20
+ import { getOptimizer , ScoringTrack } from 'optimizer' ;
21
+ import { getScoringRules } from '../../logic/score/league/leagues' ;
22
22
23
23
// Route color by circuit type.
24
24
const ROUTE_STROKE_COLORS = {
@@ -225,10 +225,10 @@ export class PathElement extends connect(store)(LitElement) {
225
225
this . closingSector . addListener ( 'rightclick' , ( e ) => this . appendToPath ( e . latLng ) ) ;
226
226
}
227
227
228
- if ( score . closingRadius ) {
228
+ if ( score . closingRadiusM ) {
229
229
const center = points [ score . indexes [ 0 ] ] ;
230
230
this . closingSector . center = center ;
231
- this . closingSector . radius = score . closingRadius ;
231
+ this . closingSector . radius = score . closingRadiusM ;
232
232
this . closingSector . update ( ) ;
233
233
this . closingSector . setMap ( this . map ) ;
234
234
} else {
@@ -252,67 +252,26 @@ export class PathElement extends connect(store)(LitElement) {
252
252
253
253
private computeScore ( points : LatLon [ ] ) : Score {
254
254
const track : ScoringTrack = {
255
- points : points . map ( ( point , i ) => {
256
- return {
257
- ...point ,
258
- alt : 0 ,
259
- timeSec : i * 60 ,
260
- } ;
261
- } ) ,
262
- minTimeSec : new Date ( ) . getTime ( ) / 1000 ,
255
+ points : points . map ( ( point , i ) => ( { ...point , alt : 0 , timeSec : i * 60 } ) ) ,
256
+ startTimeSec : new Date ( ) . getTime ( ) / 1000 ,
263
257
} ;
264
- const result = optimize ( { track } , this . getLeague ( ) ) . next ( ) . value ;
265
- const score = new Score ( {
266
- circuit : this . getCircuitType ( result ) ,
267
- distance : result . lengthKm * 1000 ,
258
+ const result = getOptimizer ( { track } , getScoringRules ( this . league ) ) . next ( ) . value ;
259
+ return new Score ( {
260
+ circuit : getCircuitType ( result . circuit ) ,
261
+ distanceM : result . lengthKm * 1000 ,
268
262
multiplier : result . multiplier ,
269
- closingRadius : result . closingRadius ? result . closingRadius * 1000 : null ,
263
+ closingRadiusM : result . closingRadius ? result . closingRadius * 1000 : null ,
270
264
indexes : result . solutionIndices ,
265
+ points : result . score ,
271
266
} ) ;
272
- // force the score as computed because of an unwanted side effect in constructor.
273
- score . forcePoints ( result . score ) ;
274
- return score ;
275
- }
276
-
277
- private getLeague ( ) : ScoringRules {
278
- switch ( this . league as LeagueCode ) {
279
- case 'czl' :
280
- return ScoringRules . CzechLocal ;
281
- case 'cze' :
282
- return ScoringRules . CzechEuropean ;
283
- case 'czo' :
284
- return ScoringRules . CzechOutsideEurope ;
285
- case 'fr' :
286
- return ScoringRules . FederationFrancaiseVolLibre ;
287
- case 'leo' :
288
- return ScoringRules . Leonardo ;
289
- case 'nor' :
290
- return ScoringRules . Norway ;
291
- case 'ukc' :
292
- return ScoringRules . UnitedKingdomClub ;
293
- case 'uki' :
294
- return ScoringRules . UnitedKingdomInternational ;
295
- case 'ukn' :
296
- return ScoringRules . UnitedKingdomNational ;
297
- case 'xc' :
298
- return ScoringRules . XContest ;
299
- case 'xcppg' :
300
- return ScoringRules . XContestPPG ;
301
- case 'wxc' :
302
- return ScoringRules . WorldXC ;
303
- }
304
- }
305
-
306
- private getCircuitType ( result : OptimizationResult ) {
307
- return result . circuit as unknown as CircuitType ;
308
267
}
309
268
310
269
// Sends a message to the iframe host with the changes.
311
270
private postScoreToHost ( score : Score ) {
312
271
let kms = '' ;
313
272
let circuit = '' ;
314
- if ( score . distance && window . parent ) {
315
- kms = ( score . distance / 1000 ) . toFixed ( 1 ) ;
273
+ if ( score . distanceM && window . parent ) {
274
+ kms = ( score . distanceM / 1000 ) . toFixed ( 1 ) ;
316
275
circuit = CIRCUIT_SHORT_NAME [ score . circuit ] ;
317
276
if ( score . circuit == CircuitType . OpenDistance ) {
318
277
circuit += score . indexes . length - 2 ;
0 commit comments