Files
tankz/src/client/haxe/ru/m/tankz/Client.hx
2014-08-26 12:08:45 +04:00

72 lines
1.9 KiB
Haxe
Executable File

package ru.m.tankz;
import ru.m.tankz.PacketBuilder;
import flash.text.TextFieldType;
import flash.Lib;
import flash.text.TextField;
import haxework.log.JSLogger;
import ru.m.tankz.data.GameData;
import haxework.frame.IFrameSwitcher;
import haxework.provider.Provider;
import ru.m.tankz.view.frames.AuthFrame;
import haxework.frame.FrameSwitcher;
import haxework.gui.Root;
import haxework.gui.GuiBuilder;
import haxe.Json;
import openfl.Assets;
import ru.m.core.connect.IConnection;
import haxework.log.TraceLogger;
class Client implements IConnectionHandler {
private static inline var TAG = "Tankz";
public static function main() {
L.push(new TraceLogger());
#if flash
L.push(new JSLogger());
#end
L.d(TAG, Meta.getVersion());
new Client();
}
private var switcher:FrameSwitcher;
public function new() {
var bytes = Assets.getBytes("res/layout/main.json");
var form:Dynamic = Json.parse(bytes.readUTFBytes(bytes.bytesAvailable));
switcher = GuiBuilder.build(form, {listener:this});
new Root(switcher);
Provider.setFactory(GameData, GameData);
Provider.set(IFrameSwitcher, switcher);
Provider.set(IPacketBuilder, new PacketBuilder());
#if flash
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001, this));
#elseif html5
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001, this));
#end
switcher.change(AuthFrame.ID);
/*var tf = new TextField();
tf.type = TextFieldType.INPUT;
tf.text = "Azaza";
tf.border = true;
tf.borderColor = 0xff0000;
Lib.current.addChild(tf);*/
}
public function onConnected():Void {}
public function onDisconnected():Void {
switcher.change(AuthFrame.ID);
}
public function onError(error:Dynamic):Void {
L.e(TAG, "", error);
switcher.change(AuthFrame.ID);
}
}