From 2be44de710d17967a3acbbb37091c8413897d25e Mon Sep 17 00:00:00 2001 From: shmyga Date: Fri, 4 May 2018 16:45:37 +0300 Subject: [PATCH] fixes --- gulpfile.js | 5 +++-- package.json | 2 +- .../haxe/ru/m/tankz/network/NetworkManager.hx | 13 +++++++++---- .../haxe/ru/m/connect/js/JsConnection.hx | 19 ++++++++----------- .../tankz/server/bundle/ServerConfigBundle.hx | 2 +- .../tankz/server/bundle/ServerLevelBundle.hx | 2 +- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 031e97d..856ad58 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -39,6 +39,9 @@ const config = new Project.Config({ 'src/common/haxe', 'src-gen/haxe', ], + assets: [ + 'src/client/resources' + ], macros: [ `CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')` ] @@ -57,7 +60,6 @@ const client = new Project( config.branch({ name: 'client', sources: ['src/client/haxe'], - assets: ['src/client/resources'], main: 'ru.m.tankz.Client', }), module.exports.generate @@ -72,7 +74,6 @@ const editor = new Project( config.branch({ name: 'editor', sources: ['src/client/haxe', 'src/editor/haxe'], - assets: ['src/client/resources'], main: 'ru.m.tankz.editor.Editor', meta: {filename: 'editor'} }) diff --git a/package.json b/package.json index 8bae11d..689776d 100755 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dateformat": "^3.0.3", "gulp": "^4.0.0", "gulp-clean": "^0.4.0", - "gulp-haxetool": "^0.0.9" + "gulp-haxetool": "^0.0.10" }, "haxeDependencies": { "lime": "6.0.1", diff --git a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx index b94b951..a1733fd 100644 --- a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx +++ b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx @@ -97,11 +97,16 @@ class NetworkManager { } private function onConnectionEvent(event:ConnectionEvent):Void { - L.d('Network', '${event}'); updateState(switch (event) { - case ConnectionEvent.CONNECTED: 'connected'; - case ConnectionEvent.DISCONNECTED: 'offline'; - case ConnectionEvent.ERROR(error): 'error'; + case ConnectionEvent.CONNECTED: + L.d('Network', '$event'); + 'connected'; + case ConnectionEvent.DISCONNECTED: + L.d('Network', '$event'); + 'offline'; + case ConnectionEvent.ERROR(error): + L.e('Network', '$error'); + 'error'; }); } diff --git a/src/common/haxe/ru/m/connect/js/JsConnection.hx b/src/common/haxe/ru/m/connect/js/JsConnection.hx index db3edab..6315596 100644 --- a/src/common/haxe/ru/m/connect/js/JsConnection.hx +++ b/src/common/haxe/ru/m/connect/js/JsConnection.hx @@ -1,21 +1,13 @@ package ru.m.connect.js; +import js.Browser; +import js.html.WebSocket; import promhx.Promise; import protohx.Message; import ru.m.Base64; import ru.m.connect.IConnection.ConnectionEvent; -typedef WebSocket = { - var onopen:Dynamic -> Void; - var onclose:Dynamic -> Void; - var onmessage:Dynamic -> Void; - var onerror:Dynamic -> Void; - function send(message:String):Void; - function emit(a:String, b:String):Void; - function close():Void; -} - class JsConnection extends BaseConnection { private var host:String; @@ -30,7 +22,12 @@ class JsConnection extends BaseConnection { } private function buildSocket(host:String, port:Int):WebSocket { - return untyped __js__("new WebSocket('ws://'+host+':'+port);"); + var protocol = switch Browser.location.protocol { + case 'http:': 'ws:'; + case 'https:': 'wss:'; + case _: 'ws:'; + } + return new WebSocket('$protocol//$host:$port'); } override public function connect():Promise> { diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx index 3852c32..c774ea5 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx @@ -14,7 +14,7 @@ class ServerConfigBundle implements IConfigBundle { public function new() {} public function get(type:GameType):Config { - var path:String = FileSystem.absolutePath('./target/html5/resources/${type}/config.yaml'); + var path:String = FileSystem.absolutePath('./resources/${type}/config.yaml'); var data:String = File.getContent(path); var source:ConfigSource = Yaml.parse(data, Parser.options().useObjects()); return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses); diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx index 575ebac..cdb60e0 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx @@ -13,7 +13,7 @@ class ServerLevelBundle implements ILevelBundle { public function new() {} public function get(type:GameType, config:Config, level:Int):LevelConfig { - var path:String = FileSystem.absolutePath('./target/html5/resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt'); + var path:String = FileSystem.absolutePath('./resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt'); var data:String = File.getContent(path); return LevelUtil.loads(config, data); }