|
1 | 1 | import { |
| 2 | + CubePrimitive, |
2 | 3 | LineType, |
3 | 4 | SceneEntityDeletionType, |
4 | 5 | SceneUpdate, |
@@ -154,19 +155,34 @@ function buildObjectEntity( |
154 | 155 | ]; |
155 | 156 | } |
156 | 157 |
|
| 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 | + |
157 | 172 | 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)); |
169 | 184 | } |
| 185 | + return lights; |
170 | 186 | } |
171 | 187 |
|
172 | 188 | return { |
|
0 commit comments