diff --git a/WORK.md b/WORK.md index 23b8700..69427ab 100644 --- a/WORK.md +++ b/WORK.md @@ -4,5 +4,3 @@ * map packs (create in editor, import in game, save imported in local storage) * improve bots * save human state in classic game -* [engine] process ice brick -* screen gamepad as default on mobile diff --git a/src/client/haxe/ru/m/Device.hx b/src/client/haxe/ru/m/Device.hx new file mode 100644 index 0000000..50d67d3 --- /dev/null +++ b/src/client/haxe/ru/m/Device.hx @@ -0,0 +1,20 @@ +package ru.m; + +class Device { + + private static var MOBILES(default, never):Array = [ + "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; + } +} diff --git a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx index 785c37d..3a6eba4 100644 --- a/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx +++ b/src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx @@ -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 = [ - -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 = [ + 0 => buildDeviceBinding(SCREEN), + ]; + + private static var defaults:Map = [ 0 => [ MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)}, MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)}, diff --git a/src/common/resources/config/classic.yaml b/src/common/resources/config/classic.yaml index ce28b78..0432fab 100644 --- a/src/common/resources/config/classic.yaml +++ b/src/common/resources/config/classic.yaml @@ -151,7 +151,7 @@ bonuses: - {score: 500, factory: destroy.team, type: grenade} - {score: 500, factory: protect.tank, type: helmet, duration: 15} - {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: gun, value: 5}