[client] screen gamepad as default on mobile devices

This commit is contained in:
2019-08-07 17:47:11 +03:00
parent 883f14fb76
commit 46f2abab05
4 changed files with 33 additions and 7 deletions

View 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;
}
}

View File

@@ -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)},