[client] screen gamepad as default on mobile devices
This commit is contained in:
20
src/client/haxe/ru/m/Device.hx
Normal file
20
src/client/haxe/ru/m/Device.hx
Normal file
@@ -0,0 +1,20 @@
|
||||
package ru.m;
|
||||
|
||||
class Device {
|
||||
|
||||
private static var MOBILES(default, never):Array<String> = [
|
||||
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
||||
];
|
||||
|
||||
public static function isMobile():Bool {
|
||||
#if js
|
||||
var userAgent = js.Browser.navigator.userAgent;
|
||||
for (mobile in MOBILES) {
|
||||
if (userAgent.indexOf(mobile) > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#end
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,8 @@ class SettingsStorage extends SharedObjectStorage {
|
||||
}
|
||||
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
||||
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||
}
|
||||
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
@@ -39,14 +40,21 @@ class SettingsStorage extends SharedObjectStorage {
|
||||
];
|
||||
}
|
||||
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
-1 => [
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => null,
|
||||
MOVE(Direction.RIGHT) => null,
|
||||
SHOT => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static var mobileDefaults:Map<Int, Binding> = [
|
||||
0 => buildDeviceBinding(SCREEN),
|
||||
];
|
||||
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
0 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||
|
||||
Reference in New Issue
Block a user