This commit is contained in:
2018-05-04 16:45:37 +03:00
parent 9269bde518
commit 2be44de710
6 changed files with 23 additions and 20 deletions

View File

@@ -39,6 +39,9 @@ const config = new Project.Config({
'src/common/haxe', 'src/common/haxe',
'src-gen/haxe', 'src-gen/haxe',
], ],
assets: [
'src/client/resources'
],
macros: [ macros: [
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')` `CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`
] ]
@@ -57,7 +60,6 @@ const client = new Project(
config.branch({ config.branch({
name: 'client', name: 'client',
sources: ['src/client/haxe'], sources: ['src/client/haxe'],
assets: ['src/client/resources'],
main: 'ru.m.tankz.Client', main: 'ru.m.tankz.Client',
}), }),
module.exports.generate module.exports.generate
@@ -72,7 +74,6 @@ const editor = new Project(
config.branch({ config.branch({
name: 'editor', name: 'editor',
sources: ['src/client/haxe', 'src/editor/haxe'], sources: ['src/client/haxe', 'src/editor/haxe'],
assets: ['src/client/resources'],
main: 'ru.m.tankz.editor.Editor', main: 'ru.m.tankz.editor.Editor',
meta: {filename: 'editor'} meta: {filename: 'editor'}
}) })

View File

@@ -6,7 +6,7 @@
"dateformat": "^3.0.3", "dateformat": "^3.0.3",
"gulp": "^4.0.0", "gulp": "^4.0.0",
"gulp-clean": "^0.4.0", "gulp-clean": "^0.4.0",
"gulp-haxetool": "^0.0.9" "gulp-haxetool": "^0.0.10"
}, },
"haxeDependencies": { "haxeDependencies": {
"lime": "6.0.1", "lime": "6.0.1",

View File

@@ -97,11 +97,16 @@ class NetworkManager {
} }
private function onConnectionEvent(event:ConnectionEvent):Void { private function onConnectionEvent(event:ConnectionEvent):Void {
L.d('Network', '${event}');
updateState(switch (event) { updateState(switch (event) {
case ConnectionEvent.CONNECTED: 'connected'; case ConnectionEvent.CONNECTED:
case ConnectionEvent.DISCONNECTED: 'offline'; L.d('Network', '$event');
case ConnectionEvent.ERROR(error): 'error'; 'connected';
case ConnectionEvent.DISCONNECTED:
L.d('Network', '$event');
'offline';
case ConnectionEvent.ERROR(error):
L.e('Network', '$error');
'error';
}); });
} }

View File

@@ -1,21 +1,13 @@
package ru.m.connect.js; package ru.m.connect.js;
import js.Browser;
import js.html.WebSocket;
import promhx.Promise; import promhx.Promise;
import protohx.Message; import protohx.Message;
import ru.m.Base64; import ru.m.Base64;
import ru.m.connect.IConnection.ConnectionEvent; 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<O:Message, I:Message> extends BaseConnection<O, I> { class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
private var host:String; private var host:String;
@@ -30,7 +22,12 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
} }
private function buildSocket(host:String, port:Int):WebSocket { 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<IConnection<O, I>> { override public function connect():Promise<IConnection<O, I>> {

View File

@@ -14,7 +14,7 @@ class ServerConfigBundle implements IConfigBundle {
public function new() {} public function new() {}
public function get(type:GameType):Config { 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 data:String = File.getContent(path);
var source:ConfigSource = Yaml.parse(data, Parser.options().useObjects()); 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); return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses);

View File

@@ -13,7 +13,7 @@ class ServerLevelBundle implements ILevelBundle {
public function new() {} public function new() {}
public function get(type:GameType, config:Config, level:Int):LevelConfig { 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); var data:String = File.getContent(path);
return LevelUtil.loads(config, data); return LevelUtil.loads(config, data);
} }