TODO: The JavaScript contract is such that the constructor takes an Engine, but really it should take some kind of view id, which should be passed through to NativeInput::GetFromJavaScript. See https://github.com/BabylonJS/BabylonNative/issues/147
| 27 | // TODO: The JavaScript contract is such that the constructor takes an Engine, but really it should take some kind of view id, which should be passed through to NativeInput::GetFromJavaScript. |
| 28 | // See https://github.com/BabylonJS/BabylonNative/issues/147 |
| 29 | NativeInput::Impl::DeviceInputSystem::DeviceInputSystem(const Napi::CallbackInfo& info) |
| 30 | : Napi::ObjectWrap<DeviceInputSystem>{info} |
| 31 | , m_nativeInput{*NativeInput::GetFromJavaScript(info.Env()).m_impl} |
| 32 | , m_deviceConnectedTicket{m_nativeInput.AddDeviceConnectedCallback([this](DeviceType deviceType, int32_t deviceSlot) { |
| 33 | if (!m_onDeviceConnected.IsEmpty()) |
| 34 | { |
| 35 | m_onDeviceConnected({ |
| 36 | Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)), |
| 37 | Napi::Value::From(Env(), deviceSlot) |
| 38 | }); |
| 39 | } |
| 40 | })} |
| 41 | , m_deviceDisconnectedTicket{m_nativeInput.AddDeviceDisconnectedCallback([this](DeviceType deviceType, int32_t deviceSlot) { |
| 42 | if (!m_onDeviceDisconnected.IsEmpty()) |
| 43 | { |
| 44 | m_onDeviceDisconnected({ |
| 45 | Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)), |
| 46 | Napi::Value::From(Env(), deviceSlot) |
| 47 | }); |
| 48 | } |
| 49 | })} |
| 50 | , m_InputChangedTicket{m_nativeInput.AddInputChangedCallback([this](DeviceType deviceType, int32_t deviceSlot, uint32_t inputIndex, std::optional<int32_t> previousState, std::optional<int32_t> currentState) { |
| 51 | if (!m_onInputChanged.IsEmpty()) |
| 52 | { |
| 53 | m_onInputChanged({ |
| 54 | Napi::Value::From(Env(), static_cast<uint32_t>(deviceType)), |
| 55 | Napi::Value::From(Env(), deviceSlot), |
| 56 | Napi::Value::From(Env(), inputIndex), |
| 57 | previousState ? Napi::Value::From(Env(), *previousState) : Env().Null(), |
| 58 | currentState ? Napi::Value::From(Env(), *currentState) : Env().Null() |
| 59 | }); |
| 60 | } |
| 61 | })} |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | Napi::Value NativeInput::Impl::DeviceInputSystem::GetOnDeviceConnected(const Napi::CallbackInfo&) |
| 66 | { |
nothing calls this directly
no test coverage detected