[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

@@ -4,5 +4,3 @@
* map packs (create in editor, import in game, save imported in local storage) * map packs (create in editor, import in game, save imported in local storage)
* improve bots * improve bots
* save human state in classic game * save human state in classic game
* [engine] process ice brick
* screen gamepad as default on mobile

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 { 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 { public static function buildDeviceBinding(device:DeviceType):Binding {
@@ -39,14 +40,21 @@ class SettingsStorage extends SharedObjectStorage {
]; ];
} }
private static var defaults:Map<Int, Binding> = [ public static function buildEmpty():Binding {
-1 => [ return [
MOVE(Direction.TOP) => null, MOVE(Direction.TOP) => null,
MOVE(Direction.LEFT) => null, MOVE(Direction.LEFT) => null,
MOVE(Direction.BOTTOM) => null, MOVE(Direction.BOTTOM) => null,
MOVE(Direction.RIGHT) => null, MOVE(Direction.RIGHT) => null,
SHOT => null, SHOT => null,
], ];
}
private static var mobileDefaults:Map<Int, Binding> = [
0 => buildDeviceBinding(SCREEN),
];
private static var defaults:Map<Int, Binding> = [
0 => [ 0 => [
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)}, MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)}, MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},

View File

@@ -151,7 +151,7 @@ bonuses:
- {score: 500, factory: destroy.team, type: grenade} - {score: 500, factory: destroy.team, type: grenade}
- {score: 500, factory: protect.tank, type: helmet, duration: 15} - {score: 500, factory: protect.tank, type: helmet, duration: 15}
- {score: 500, factory: life, type: life} - {score: 500, factory: life, type: life}
- {score: 500, factory: armor.eagle, type: shovel, duration: 10} - {score: 500, factory: armor.eagle, type: shovel, duration: 15}
- {score: 500, factory: upgrade.tank, type: star, value: 1} - {score: 500, factory: upgrade.tank, type: star, value: 1}
- {score: 500, factory: upgrade.tank, type: gun, value: 5} - {score: 500, factory: upgrade.tank, type: gun, value: 5}