From b20f61105812fa03945cf517a5d613aa2af8b484 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 20 Dec 2020 20:25:18 +0900 Subject: [PATCH] uidriver/js: Implement touches on go2cpp --- internal/uidriver/js/input_js.go | 20 ++++++++++++++++++++ internal/uidriver/js/ui_js.go | 1 + 2 files changed, 21 insertions(+) diff --git a/internal/uidriver/js/input_js.go b/internal/uidriver/js/input_js.go index a56d2905f..fa245cfd5 100644 --- a/internal/uidriver/js/input_js.go +++ b/internal/uidriver/js/input_js.go @@ -395,3 +395,23 @@ func (i *Input) updateTouchesFromEvent(e js.Value) { } i.touches = ts } + +func (i *Input) updateForGo2Cpp() { + if !go2cpp.Truthy() { + return + } + + i.touches = map[driver.TouchID]pos{} + maxID := go2cpp.Get("maxTouchId").Int() + for id := 0; id < maxID; id++ { + x := go2cpp.Call("getTouchPositionX", id) + y := go2cpp.Call("getTouchPositionY", id) + if x.Type() != js.TypeNumber || y.Type() != js.TypeNumber { + continue + } + i.touches[driver.TouchID(id)] = pos{ + X: x.Int(), + Y: y.Int(), + } + } +} diff --git a/internal/uidriver/js/ui_js.go b/internal/uidriver/js/ui_js.go index 73c8c03db..3a52baaf0 100644 --- a/internal/uidriver/js/ui_js.go +++ b/internal/uidriver/js/ui_js.go @@ -182,6 +182,7 @@ func (u *UserInterface) update() error { hooks.ResumeAudio() u.input.updateGamepads() + u.input.updateForGo2Cpp() u.updateSize() if err := u.context.Update(); err != nil { return err