Files
tankz/src/client/haxe/ru/m/tankz/Client.hx
2017-12-22 17:10:46 +03:00

91 lines
2.5 KiB
Haxe
Executable File

package ru.m.tankz;
import flash.text.Font;
import ru.m.tankz.view.frames.StartFrame;
import haxework.log.SocketLogger;
import haxework.resources.Resources;
import haxework.resources.IResources;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.gui.ButtonView;
import flash.display.Sprite;
import haxework.gui.IGroupView;
import ru.m.tankz.PacketBuilder;
import haxework.log.JSLogger;
import ru.m.tankz.data.GameData;
import haxework.gui.frame.IFrameSwitcher;
import haxework.provider.Provider;
import ru.m.tankz.view.frames.AuthFrame;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.Root;
import openfl.Assets;
import ru.m.core.connect.IConnection;
import haxework.log.TraceLogger;
@:template("layout/main.json", "layout/styles.json")
class MainView extends VGroupView implements ViewBuilder {}
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
#if debug
L.push(new SocketLogger());
#end
Const.init();
L.d(TAG, "Debug: " + Const.DEBUG);
L.i(TAG, "Version: " + Const.VERSION);
L.i(TAG, "Build: " + Const.BUILD);
new Client();
}
private var view:MainView;
public function new() {
Provider.setFactory(IResources, Resources);
Provider.setFactory(GameData, GameData);
var font:Font = Font.enumerateFonts()[0];
Provider.get(IResources).text.put("font", "Bookman Old Style");
Provider.set(IPacketBuilder, new PacketBuilder());
#if flash
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
#elseif html5
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001));
#end
Provider.get(IConnection).handler.addListener(this);
view = new MainView();
Provider.set(IFrameSwitcher, view.switcher);
Root.bind(view);
view.logout.onPress = this;
view.switcher.change(StartFrame.ID);
}
public function onPress(view:ButtonView):Void {
switch (view.id) {
case "logout":
Provider.get(IConnection).disconnect();
}
}
public function onConnected():Void {}
public function onDisconnected():Void {
view.switcher.change(AuthFrame.ID);
}
public function onError(error:Dynamic):Void {
L.e(TAG, "", error);
view.switcher.change(AuthFrame.ID);
}
}