Skip to content

Commit a5c521d

Browse files
buraktiryakijdsika
andauthored
fix: the type error after vehicle lights implementation (#119)
* fix the type issue for movingObjects without light states --------- Co-authored-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
1 parent 0592bd5 commit a5c521d

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

src/index.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CubePrimitive,
23
LineType,
34
SceneEntityDeletionType,
45
SceneUpdate,
@@ -154,19 +155,34 @@ function buildObjectEntity(
154155
];
155156
}
156157

158+
function hasBrakeLightState(obj: MovingObject | StationaryObject): obj is MovingObject {
159+
return (
160+
"vehicle_classification" in obj &&
161+
obj.vehicle_classification?.light_state?.brake_light_state != undefined
162+
);
163+
}
164+
165+
function hasIndicatorState(obj: MovingObject | StationaryObject): obj is MovingObject {
166+
return (
167+
"vehicle_classification" in obj &&
168+
obj.vehicle_classification?.light_state?.indicator_state != undefined
169+
);
170+
}
171+
157172
function buildVehicleLights() {
158-
if ("vehicle_classification" in osiObject) {
159-
return [
160-
buildBrakeLight(osiObject, BrakeLightSide.Left),
161-
buildBrakeLight(osiObject, BrakeLightSide.Right),
162-
buildIndicatorLight(osiObject, IndicatorLightSide.FrontLeft),
163-
buildIndicatorLight(osiObject, IndicatorLightSide.FrontRight),
164-
buildIndicatorLight(osiObject, IndicatorLightSide.RearLeft),
165-
buildIndicatorLight(osiObject, IndicatorLightSide.RearRight),
166-
];
167-
} else {
168-
return [];
173+
const lights: CubePrimitive[] = [];
174+
175+
if (hasBrakeLightState(osiObject)) {
176+
lights.push(buildBrakeLight(osiObject, BrakeLightSide.Left));
177+
lights.push(buildBrakeLight(osiObject, BrakeLightSide.Right));
178+
}
179+
if (hasIndicatorState(osiObject)) {
180+
lights.push(buildIndicatorLight(osiObject, IndicatorLightSide.FrontLeft));
181+
lights.push(buildIndicatorLight(osiObject, IndicatorLightSide.FrontRight));
182+
lights.push(buildIndicatorLight(osiObject, IndicatorLightSide.RearLeft));
183+
lights.push(buildIndicatorLight(osiObject, IndicatorLightSide.RearRight));
169184
}
185+
return lights;
170186
}
171187

172188
return {

0 commit comments

Comments
 (0)