Fix vibration on iphone
This commit is contained in:
parent
7162dc69b9
commit
45b6588701
4 changed files with 16 additions and 10 deletions
|
|
@ -29,6 +29,7 @@ import { PlayerDecision } from './join-form-handler';
|
|||
import { GameObjectContainer } from './objects/game-object-container';
|
||||
import { OptionsHandler } from './options-handler';
|
||||
import parser from 'socket.io-msgpack-parser';
|
||||
import { VibrationHandler } from './vibration-handler';
|
||||
|
||||
export class Game extends CommandReceiver {
|
||||
public gameObjects = new GameObjectContainer(this);
|
||||
|
|
@ -123,11 +124,7 @@ export class Game extends CommandReceiver {
|
|||
protected commandExecutors: CommandExecutors = {
|
||||
[ServerAnnouncement.type]: (c: ServerAnnouncement) =>
|
||||
(this.lastAnnouncementText = c.text),
|
||||
[PlayerDiedCommand.type]: (c: PlayerDiedCommand) => {
|
||||
if (OptionsHandler.options.vibrationEnabled) {
|
||||
navigator.vibrate(150);
|
||||
}
|
||||
},
|
||||
[PlayerDiedCommand.type]: (c: PlayerDiedCommand) => VibrationHandler.vibrate(150),
|
||||
[UpdateGameState.type]: (c: UpdateGameState) => (this.lastGameState = c),
|
||||
[GameEnd.type]: (c: GameEnd) => {
|
||||
const team =
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Renderer } from 'sdf-2d';
|
||||
import { Circle, Id, PlayerCharacterBase, CharacterTeam, settings } from 'shared';
|
||||
import { OptionsHandler } from '../options-handler';
|
||||
|
||||
import { BlobShape } from '../shapes/blob-shape';
|
||||
import { SoundHandler, Sounds } from '../sound-handler';
|
||||
import { VibrationHandler } from '../vibration-handler';
|
||||
import { ViewObject } from './view-object';
|
||||
|
||||
export class PlayerCharacterView extends PlayerCharacterBase implements ViewObject {
|
||||
|
|
@ -52,8 +51,8 @@ export class PlayerCharacterView extends PlayerCharacterBase implements ViewObje
|
|||
|
||||
public step(deltaTimeInSeconds: number): void {
|
||||
if (this.previousHealth > this.health) {
|
||||
if (this.isMainCharacter && OptionsHandler.options.vibrationEnabled) {
|
||||
navigator.vibrate(Math.min(200, (this.previousHealth - this.health) * 4));
|
||||
if (this.isMainCharacter) {
|
||||
VibrationHandler.vibrate(Math.min(200, (this.previousHealth - this.health) * 4));
|
||||
}
|
||||
|
||||
this.previousHealth = this.health;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { SoundHandler, Sounds } from './sound-handler';
|
||||
import { VibrationHandler } from './vibration-handler';
|
||||
|
||||
interface Options {
|
||||
vibrationEnabled: boolean;
|
||||
|
|
@ -47,7 +48,7 @@ export abstract class OptionsHandler {
|
|||
}
|
||||
|
||||
if (this.checked && k === 'vibrationEnabled') {
|
||||
navigator.vibrate(100);
|
||||
VibrationHandler.vibrate(100);
|
||||
}
|
||||
|
||||
SoundHandler.play(Sounds.click);
|
||||
|
|
|
|||
9
frontend/src/scripts/vibration-handler.ts
Normal file
9
frontend/src/scripts/vibration-handler.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { OptionsHandler } from './options-handler';
|
||||
|
||||
export abstract class VibrationHandler {
|
||||
public static vibrate(time: number): void {
|
||||
if (OptionsHandler.options.vibrationEnabled) {
|
||||
navigator?.vibrate(time);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue