import { MiniGamePlatform } from '../platform/MiniGamePlatform'; /** * 设备震动相关 */ export default class Vibrate { /**开关 */ public static IsEnable = true; /**是否开始震动 */ public static IsStartVibrate = false; /**当前平台 API */ public static get Pf() { MiniGamePlatform.init(); return MiniGamePlatform.pf; } /** * 短震动 */ public static vibrateShort(): void { if (!this.IsEnable) return; this.Pf?.vibrateShort?.({ type: 'medium' }); } /** * 长震动 */ public static vibrateLong(): void { if (!this.IsEnable) return; this.Pf?.vibrateLong?.(); } /** * 开始持续震动 */ public static startVibrate() { this.IsStartVibrate = true; this.loopVibrate(); } /** * 结束持续震动 */ public static stopVibrate() { this.IsStartVibrate = false; } private static loopVibrate() { this.vibrateShort(); setTimeout(() => { if (this.IsStartVibrate) { this.loopVibrate(); } }, 30); } }