From 85ac14c7b6ad1322c498fd413800e4192d242b33 Mon Sep 17 00:00:00 2001 From: Lukas Radermacher <49586507+lukasrad02@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:22:21 +0100 Subject: [PATCH 1/5] Refactor nestedCoordinatesOf --- .../models/utils/position/position-helpers.ts | 33 +++++++++++++++++++ .../store/action-reducers/transfer-point.ts | 30 +---------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/shared/src/models/utils/position/position-helpers.ts b/shared/src/models/utils/position/position-helpers.ts index f9a743bc2..e6d99141e 100644 --- a/shared/src/models/utils/position/position-helpers.ts +++ b/shared/src/models/utils/position/position-helpers.ts @@ -1,3 +1,4 @@ +import { ExerciseState } from '../../../state'; import type { UUID } from '../../../utils'; import type { Transfer } from '../transfer'; import { MapCoordinates } from './map-coordinates'; @@ -180,3 +181,35 @@ export function lowerRightCornerOf(element: WithExtent): MapCoordinates { return MapCoordinates.create(corner.x, corner.y); } + +export function nestedCoordinatesOf( + withPosition: WithPosition, + state: ExerciseState +): MapCoordinates { + if (isOnMap(withPosition)) { + return currentCoordinatesOf(withPosition); + } + if (isInVehicle(withPosition)) { + const vehicleId = currentVehicleIdOf(withPosition); + const vehicle = state.vehicles[vehicleId]; + if (!vehicle) { + throw new Error( + `The vehicle with the id ${vehicleId} could not be found` + ); + } + return nestedCoordinatesOf(vehicle, state); + } + if (isInSimulatedRegion(withPosition)) { + const simulatedRegionId = currentSimulatedRegionIdOf(withPosition); + const simulatedRegion = state.simulatedRegions[simulatedRegionId]; + if (!simulatedRegion) { + throw new Error( + `The simulated region with the id ${simulatedRegionId} could not be found` + ); + } + return currentCoordinatesOf(simulatedRegion); + } + throw new Error( + `Expected element to have (nested) map position, but position was of type ${withPosition.position.type}` + ); +} diff --git a/shared/src/store/action-reducers/transfer-point.ts b/shared/src/store/action-reducers/transfer-point.ts index 3200c7b95..77054cbfb 100644 --- a/shared/src/store/action-reducers/transfer-point.ts +++ b/shared/src/store/action-reducers/transfer-point.ts @@ -7,7 +7,7 @@ import { ValidateNested, } from 'class-validator'; import { TransferPoint } from '../../models'; -import type { WithPosition } from '../../models/utils'; +import { nestedCoordinatesOf, WithPosition } from '../../models/utils'; import { currentCoordinatesOf, isInTransfer, @@ -365,31 +365,3 @@ function estimateDuration( const multipleOf = 1000 * 60 * 0.1; return Math.round(estimateTime / multipleOf) * multipleOf; } - -function nestedCoordinatesOf( - withPosition: WithPosition, - draftState: ExerciseState -): MapCoordinates { - if (isOnMap(withPosition)) { - return currentCoordinatesOf(withPosition); - } - if (isInVehicle(withPosition)) { - const vehicle = getElement( - draftState, - 'vehicle', - currentVehicleIdOf(withPosition) - ); - return nestedCoordinatesOf(vehicle, draftState); - } - if (isInSimulatedRegion(withPosition)) { - const simulatedRegion = getElement( - draftState, - 'simulatedRegion', - currentSimulatedRegionIdOf(withPosition) - ); - return currentCoordinatesOf(simulatedRegion); - } - throw new ReducerError( - `Expected element to have (nested) map position, but position was of type ${withPosition.position.type}` - ); -} From 09676c9e97ccfdf2c9eccb5b71260dbf09af41ce Mon Sep 17 00:00:00 2001 From: Lukas Radermacher <49586507+lukasrad02@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:22:42 +0100 Subject: [PATCH 2/5] Show transfer lines for simulated regions --- .../application/selectors/exercise.selectors.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/state/application/selectors/exercise.selectors.ts b/frontend/src/app/state/application/selectors/exercise.selectors.ts index 61c1f08c4..2d399925e 100644 --- a/frontend/src/app/state/application/selectors/exercise.selectors.ts +++ b/frontend/src/app/state/application/selectors/exercise.selectors.ts @@ -8,9 +8,9 @@ import type { WithPosition, } from 'digital-fuesim-manv-shared'; import { - currentCoordinatesOf, isInSpecificSimulatedRegion, isInTransfer, + nestedCoordinatesOf, } from 'digital-fuesim-manv-shared'; import type { TransferLine } from 'src/app/shared/types/transfer-line'; import type { AppState } from '../../app.state'; @@ -118,16 +118,21 @@ export const selectTileMapProperties = createSelector( ); export const selectTransferLines = createSelector( + selectExerciseState, selectTransferPoints, - (transferPoints) => + (state, transferPoints) => Object.values(transferPoints) .flatMap((transferPoint) => Object.entries(transferPoint.reachableTransferPoints).map( ([connectedId, { duration }]) => ({ id: `${transferPoint.id}:${connectedId}` as const, - startPosition: currentCoordinatesOf(transferPoint), - endPosition: currentCoordinatesOf( - transferPoints[connectedId]! + startPosition: nestedCoordinatesOf( + transferPoint, + state + ), + endPosition: nestedCoordinatesOf( + transferPoints[connectedId]!, + state ), duration, }) From 67054d1a9f6a3438417509fb9d0d41bbf318d428 Mon Sep 17 00:00:00 2001 From: Lukas Radermacher <49586507+lukasrad02@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:24:05 +0100 Subject: [PATCH 3/5] Draw transfer lines behind simulated regions --- .../exercise/shared/exercise-map/utility/ol-map-manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/pages/exercises/exercise/shared/exercise-map/utility/ol-map-manager.ts b/frontend/src/app/pages/exercises/exercise/shared/exercise-map/utility/ol-map-manager.ts index f1fb37470..b543e9ebc 100644 --- a/frontend/src/app/pages/exercises/exercise/shared/exercise-map/utility/ol-map-manager.ts +++ b/frontend/src/app/pages/exercises/exercise/shared/exercise-map/utility/ol-map-manager.ts @@ -293,9 +293,9 @@ export class OlMapManager { this.featureManagers = [ deleteFeatureManager, + transferLinesFeatureManager, simulatedRegionFeatureManager, mapImageFeatureManager, - transferLinesFeatureManager, transferPointFeatureManager, vehicleFeatureManager, cateringLinesFeatureManager, From 7514ccfd3ae7380d38ca71fef7b1a0c6d761159d Mon Sep 17 00:00:00 2001 From: Lukas Radermacher <49586507+lukasrad02@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:28:47 +0100 Subject: [PATCH 4/5] Fix linter --- shared/src/models/utils/position/position-helpers.ts | 2 +- shared/src/store/action-reducers/transfer-point.ts | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/shared/src/models/utils/position/position-helpers.ts b/shared/src/models/utils/position/position-helpers.ts index e6d99141e..ce7079b7c 100644 --- a/shared/src/models/utils/position/position-helpers.ts +++ b/shared/src/models/utils/position/position-helpers.ts @@ -1,4 +1,4 @@ -import { ExerciseState } from '../../../state'; +import type { ExerciseState } from '../../../state'; import type { UUID } from '../../../utils'; import type { Transfer } from '../transfer'; import { MapCoordinates } from './map-coordinates'; diff --git a/shared/src/store/action-reducers/transfer-point.ts b/shared/src/store/action-reducers/transfer-point.ts index 77054cbfb..2580777cc 100644 --- a/shared/src/store/action-reducers/transfer-point.ts +++ b/shared/src/store/action-reducers/transfer-point.ts @@ -7,21 +7,14 @@ import { ValidateNested, } from 'class-validator'; import { TransferPoint } from '../../models'; -import { nestedCoordinatesOf, WithPosition } from '../../models/utils'; import { - currentCoordinatesOf, + currentTransferOf, isInTransfer, MapCoordinates, MapPosition, - currentTransferOf, - isInSimulatedRegion, - currentSimulatedRegionIdOf, - isOnMap, - isInVehicle, - currentVehicleIdOf, + nestedCoordinatesOf, } from '../../models/utils'; import { changePositionWithId } from '../../models/utils/position/position-helpers-mutable'; -import type { ExerciseState } from '../../state'; import { cloneDeepMutable, UUID, uuidValidationOptions } from '../../utils'; import { IsValue } from '../../utils/validators'; import type { Action, ActionReducer } from '../action-reducer'; From 4a10072929c5041d46c2c702b3e60073fff105b9 Mon Sep 17 00:00:00 2001 From: Lukas Radermacher <49586507+lukasrad02@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:30:33 +0100 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee751f79f..e4b3fbdaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project does **not** adhere to [Semantic Versioning](https://semver.org - The _Behaviors_ tab allows adding and removing behaviors from simulated regions, inspect their current state and customize their settings - For the assign leader behavior, the type of the currently assigned leader is shown - Simulated Regions now act as transfer points, meaning that they can be start and destination of a transfer + - Connection lines will be shown for transfer connections from/to simulated regions, too ### Fixed