Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show connecting lines for transfers from/to simulated regions #727

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ export class OlMapManager {

this.featureManagers = [
deleteFeatureManager,
transferLinesFeatureManager,
simulatedRegionFeatureManager,
mapImageFeatureManager,
transferLinesFeatureManager,
transferPointFeatureManager,
vehicleFeatureManager,
cateringLinesFeatureManager,
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/app/state/application/selectors/exercise.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
})
Expand Down
33 changes: 33 additions & 0 deletions shared/src/models/utils/position/position-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ExerciseState } from '../../../state';
import type { UUID } from '../../../utils';
import type { Transfer } from '../transfer';
import { MapCoordinates } from './map-coordinates';
Expand Down Expand Up @@ -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}`
);
}
39 changes: 2 additions & 37 deletions shared/src/store/action-reducers/transfer-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@ import {
ValidateNested,
} from 'class-validator';
import { TransferPoint } from '../../models';
import type { 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';
Expand Down Expand Up @@ -365,31 +358,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}`
);
}