ebiten: Vibrate takes time durations instead of the options

Android and browsers can specify only a time duration for vibration.

VibrateOptions is renamed to GamepadVibrateOptions for gamepads.

Updates #1452
This commit is contained in:
Hajime Hoshi 2021-10-24 05:02:12 +09:00
parent f96d0a97a8
commit 7c6f2fd799
6 changed files with 18 additions and 20 deletions

View File

@ -39,11 +39,7 @@ func (g *Game) Update() error {
g.touchIDs = g.touchIDs[:0]
g.touchIDs = inpututil.AppendJustPressedTouchIDs(g.touchIDs)
if len(g.touchIDs) > 0 {
op := &ebiten.VibrateOptions{
Duration: 200 * time.Millisecond,
StrongMagnitude: 1,
}
ebiten.Vibrate(op)
ebiten.Vibrate(200 * time.Millisecond)
}
return nil

View File

@ -63,7 +63,7 @@ type UI interface {
SetScreenTransparent(transparent bool)
SetInitFocused(focused bool)
Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64)
Vibrate(duration time.Duration)
Input() Input
Window() Window

View File

@ -1686,6 +1686,6 @@ func (u *UserInterface) setOrigPos(x, y int) {
u.origPosY = y
}
func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
func (u *UserInterface) Vibrate(duration time.Duration) {
// Do nothing.
}

View File

@ -648,7 +648,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
u.initFocused = focused
}
func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
func (u *UserInterface) Vibrate(duration time.Duration) {
if js.Global().Get("navigator").Get("vibrate").Truthy() {
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))
}

View File

@ -494,6 +494,6 @@ func (u *UserInterface) ScheduleFrame() {
}
}
func (u *UserInterface) Vibrate(duration time.Duration, strongMagnitude float64, weakMagnitude float64) {
func (u *UserInterface) Vibrate(duration time.Duration) {
// TODO: Implement this (#1452)
}

View File

@ -18,8 +18,18 @@ import (
"time"
)
// VibrateOptions represents the options to vibrate a device.
type VibrateOptions struct {
// Vibrate vibrates the device.
//
// Vibrate works on mobiles and browsers.
// On browsers, StrongManitude and WeakMagnitude might be ignored.
//
// Vibrate is concurrent-safe.
func Vibrate(duration time.Duration) {
uiDriver().Vibrate(duration)
}
// GamepadVibrateOptions represents the options to vibrate a gamepad.
type GamepadVibrateOptions struct {
// Duration is the time duration of the effect.
Duration time.Duration
@ -32,12 +42,4 @@ type VibrateOptions struct {
WeakMagnitude float64
}
// Vibrate vibrates the device.
//
// Vibrate works on mobiles and browsers.
// On browsers, StrongManitude and WeakMagnitude might be ignored.
//
// Vibrate is concurrent-safe.
func Vibrate(options *VibrateOptions) {
uiDriver().Vibrate(options.Duration, options.StrongMagnitude, options.WeakMagnitude)
}
// TODO: Add a function VibrateGamepad.