v2.3.1: added a setting for vibration & improved vibration support logic

This commit is contained in:
Evan Debenham
2024-01-25 13:09:00 -05:00
parent b849ca58f0
commit f36dda3064
9 changed files with 147 additions and 72 deletions

View File

@@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ios;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.backends.iosrobovm.custom.HWMachine;
import com.badlogic.gdx.backends.iosrobovm.objectal.OALSimpleAudio;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
@@ -82,16 +83,39 @@ public class IOSPlatformSupport extends PlatformSupport {
return !test.getFlags().contains(SCNetworkReachabilityFlags.IsWWAN);
}
public void vibrate( int millis ){
@Override
public boolean supportsVibration() {
//Devices with haptics...
if (Gdx.input.isPeripheralAvailable(Input.Peripheral.HapticFeedback)){
return true;
};
//...or with a supported controller connected
if (ControllerHandler.vibrationSupported()){
return true;
}
//...or with 3d touch
String machineString = HWMachine.getMachineString();
if (machineString.equals("iPhone8,4")){ //1st gen SE has no 3D touch specifically
return false;
} else { // 6s/7/8/X/XR have 3D touch
return machineString.contains("iphone8") //6s
|| machineString.contains("iphone9") //7
|| machineString.contains("iphone10") //8, and X
|| machineString.contains("iphone11"); //XS (also XR but that has haptic)
}
}
public void vibrate(int millis ){
if (ControllerHandler.isControllerConnected()){
if (ControllerHandler.isControllerConnected()) {
ControllerHandler.vibrate(millis);
}
ControllerHandler.vibrate(millis);
} else if (Gdx.input.isPeripheralAvailable(Input.Peripheral.HapticFeedback)){
Gdx.input.vibrate( millis );
} else {
//devices without haptics support use a short vibrate on iPhone 6+, no vibration otherwise
//devices without haptics but with 3d touch use a short vibrate
AudioServices.playSystemSound(1520);
// no vibration otherwise
}
}