Fix vibration
This commit is contained in:
parent
f7420777f0
commit
b48bf076ad
3 changed files with 24 additions and 11 deletions
|
|
@ -63,15 +63,6 @@
|
||||||
|
|
||||||
<div id="settings-container">
|
<div id="settings-container">
|
||||||
<section id="settings">
|
<section id="settings">
|
||||||
<label for="enable-vibration">
|
|
||||||
<input id="enable-vibration" type="checkbox" />
|
|
||||||
<img
|
|
||||||
title="Enable vibration on mobile"
|
|
||||||
alt="vibrating mobile"
|
|
||||||
src="../static/vibrate.svg"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label for="enable-sounds">
|
<label for="enable-sounds">
|
||||||
<input id="enable-sounds" type="checkbox" />
|
<input id="enable-sounds" type="checkbox" />
|
||||||
<img
|
<img
|
||||||
|
|
@ -86,6 +77,15 @@
|
||||||
<img title="Enable music" alt="music note" src="../static/music.svg" />
|
<img title="Enable music" alt="music note" src="../static/music.svg" />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label for="enable-vibration">
|
||||||
|
<input id="enable-vibration" type="checkbox" />
|
||||||
|
<img
|
||||||
|
title="Enable vibration on mobile"
|
||||||
|
alt="vibrating mobile"
|
||||||
|
src="../static/vibrate.svg"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
title="Exit from current game"
|
title="Exit from current game"
|
||||||
id="logout"
|
id="logout"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import { OptionsHandler } from './scripts/options-handler';
|
||||||
import { hide } from './scripts/helper/hide';
|
import { hide } from './scripts/helper/hide';
|
||||||
import { show } from './scripts/helper/show';
|
import { show } from './scripts/helper/show';
|
||||||
import { SoundHandler, Sounds } from './scripts/sound-handler';
|
import { SoundHandler, Sounds } from './scripts/sound-handler';
|
||||||
|
import { VibrationHandler } from './scripts/vibration-handler';
|
||||||
|
|
||||||
glMatrix.setMatrixArrayType(Array);
|
glMatrix.setMatrixArrayType(Array);
|
||||||
|
|
||||||
|
|
@ -122,6 +123,10 @@ const main = async () => {
|
||||||
};
|
};
|
||||||
document.addEventListener('click', firstClickListener);
|
document.addEventListener('click', firstClickListener);
|
||||||
|
|
||||||
|
if (!VibrationHandler.isVibrationEnabledHeuristics) {
|
||||||
|
hide(document.querySelector("label[for='enable-vibration']") as HTMLElement, true);
|
||||||
|
}
|
||||||
|
|
||||||
handleFullScreen(minimize, maximize);
|
handleFullScreen(minimize, maximize);
|
||||||
toggleSettingsButton.addEventListener('click', toggleSettings);
|
toggleSettingsButton.addEventListener('click', toggleSettings);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,16 @@ import { OptionsHandler } from './options-handler';
|
||||||
|
|
||||||
export abstract class VibrationHandler {
|
export abstract class VibrationHandler {
|
||||||
public static vibrate(time: number): void {
|
public static vibrate(time: number): void {
|
||||||
if (OptionsHandler.options.vibrationEnabled) {
|
if (OptionsHandler.options.vibrationEnabled && this.isVibrationEnabled) {
|
||||||
navigator?.vibrate(time);
|
navigator.vibrate(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static get isVibrationEnabled(): boolean {
|
||||||
|
return 'vibrate' in navigator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static get isVibrationEnabledHeuristics(): boolean {
|
||||||
|
return this.isVibrationEnabled && 'ontouchstart' in window;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue