Skip to content

Commit

Permalink
Merge branch 'ulope-feature/haptics'
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Apr 14, 2022
2 parents a329d58 + 120423c commit 5eb9c08
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
26 changes: 18 additions & 8 deletions src/ui/shared/round/OnlineRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export default class OnlineRound implements OnlineRoundInterface {
this.vm.submitFeedback = undefined
if (playing) {
sound.confirmation()
vibrate.quick()
vibrate.tap()
}
redraw()
}, feebackDuration)
Expand All @@ -434,15 +434,19 @@ export default class OnlineRound implements OnlineRoundInterface {
d.game.winner = o.winner
}

if (o.check) {
vibrate.doubleTap()
}

const wDraw = white.offeringDraw
const bDraw = black.offeringDraw
if (!wDraw && o.wDraw) {
sound.dong()
vibrate.quick()
vibrate.warn()
}
if (!bDraw && o.bDraw) {
sound.dong()
vibrate.quick()
vibrate.warn()
}
white.offeringDraw = o.wDraw
black.offeringDraw = o.bDraw
Expand Down Expand Up @@ -631,7 +635,11 @@ export default class OnlineRound implements OnlineRoundInterface {

if (d.game.turns > 1) {
sound.dong()
vibrate.quick()
if (d.player.color === d.game.winner) {
vibrate.good()
} else {
vibrate.bad()
}
}
if (!this.data.player.spectator) {
session.backgroundRefresh()
Expand Down Expand Up @@ -742,12 +750,14 @@ export default class OnlineRound implements OnlineRoundInterface {
else {
sound.capture()
}
if (!this.data.player.spectator) {
vibrate.heavy()
}
} else {
sound.move()
}

if (!this.data.player.spectator) {
vibrate.quick()
if (!this.data.player.spectator) {
vibrate.tap()
}
}
}

Expand Down
67 changes: 64 additions & 3 deletions src/vibrate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,74 @@
import { Haptics } from '@capacitor/haptics'
import { Haptics, ImpactStyle, NotificationType } from '@capacitor/haptics'
import settings from './settings'

let shouldVibrate: boolean = settings.general.vibrateOnGameEvents()

export default {
quick() {
if (shouldVibrate) {
if (window.navigator.vibrate) window.navigator.vibrate(150)
else Haptics.vibrate()
if (window.navigator.vibrate) {
window.navigator.vibrate(150)
} else {
void Haptics.vibrate({ duration: 150 })
}
}
},
tap() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(50)
} else {
void Haptics.impact({ style: ImpactStyle.Medium })
}
}
},
heavy() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(100)
} else {
void Haptics.impact({ style: ImpactStyle.Heavy })
}
}
},
doubleTap() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(50)
} else {
void Haptics.impact({ style: ImpactStyle.Medium }).then(() => {
void new Promise(r => setTimeout(r, 150)).then(() => {
void Haptics.impact({ style: ImpactStyle.Medium })
})
})
}
}
},
warn() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(50)
} else {
void Haptics.notification({ type: NotificationType.Warning })
}
}
},
bad() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(50)
} else {
void Haptics.notification({ type: NotificationType.Error })
}
}
},
good() {
if (shouldVibrate) {
if (window.navigator.vibrate) {
window.navigator.vibrate(50)
} else {
void Haptics.notification({ type: NotificationType.Success })
}
}
},
onSettingChange(v: boolean) {
Expand Down

0 comments on commit 5eb9c08

Please sign in to comment.