big update
This commit is contained in:
43
src/client/haxe/layout/frames/auth.json
Normal file
43
src/client/haxe/layout/frames/auth.json
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100, "layoutMargin": 3,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"@type": "haxework.gui.HGroupView",
|
||||||
|
"contentSize": true,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"@type": "haxework.gui.LabelView",
|
||||||
|
"width": 150, "height": 25, "text": "Login"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "loginInput", "@type": "haxework.gui.InputView",
|
||||||
|
"skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
|
||||||
|
"width": 200, "height": 25, "text": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "haxework.gui.HGroupView",
|
||||||
|
"contentSize": true,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"@type": "haxework.gui.LabelView",
|
||||||
|
"width": 150, "height": 25, "text": "Password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "passwordInput", "@type": "haxework.gui.InputView",
|
||||||
|
"skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
|
||||||
|
"width": 200, "height": 25, "text": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": "authButton",
|
||||||
|
"@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 45,
|
||||||
|
"text": "Auth",
|
||||||
|
"@style": "button_skin"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
19
src/client/haxe/layout/frames/game.json
Normal file
19
src/client/haxe/layout/frames/game.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "name", "@type": "haxework.gui.LabelView",
|
||||||
|
"pWidth": 100, "height": 25, "text": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "restart", "@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 45,
|
||||||
|
"text": "Restart",
|
||||||
|
"@style": "button_skin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "render", "@type": "ru.m.tankz.render.Render",
|
||||||
|
"contentSize": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
24
src/client/haxe/layout/frames/game_list.json
Normal file
24
src/client/haxe/layout/frames/game_list.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "name", "@type": "haxework.gui.LabelView",
|
||||||
|
"pWidth": 100, "height": 25, "text": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "create", "@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 45,
|
||||||
|
"text": "Create",
|
||||||
|
"@style": "button_skin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "list", "@type": "haxework.gui.list.VListView<ru.m.tankz.proto.Game>",
|
||||||
|
"factory": "@class:ru.m.tankz.view.frames.list.GameView",
|
||||||
|
"scroll": {
|
||||||
|
"@type": "haxework.gui.list.VScrollView",
|
||||||
|
"skin": {"@type": "haxework.gui.list.VScrollSkin"}
|
||||||
|
},
|
||||||
|
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
30
src/client/haxe/layout/frames/game_ready.json
Normal file
30
src/client/haxe/layout/frames/game_ready.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "name", "@type": "haxework.gui.LabelView",
|
||||||
|
"pWidth": 100, "height": 25, "text": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "start", "@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 45,
|
||||||
|
"text": "Start",
|
||||||
|
"@style": "button_skin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "exit", "@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 45,
|
||||||
|
"text": "Exit",
|
||||||
|
"@style": "button_skin"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "list", "@type": "haxework.gui.list.VListView<ru.m.tankz.proto.Person>",
|
||||||
|
"factory": "@class:ru.m.tankz.view.frames.list.PersonView",
|
||||||
|
"scroll": {
|
||||||
|
"@type": "haxework.gui.list.VScrollView",
|
||||||
|
"skin": {"@type": "haxework.gui.list.VScrollSkin"}
|
||||||
|
},
|
||||||
|
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/client/haxe/layout/frames/person_list.json
Normal file
14
src/client/haxe/layout/frames/person_list.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "list", "@type": "haxework.gui.list.VListView<ru.m.tankz.proto.Person>",
|
||||||
|
"factory": "@class:ru.m.tankz.view.frames.list.PersonView",
|
||||||
|
"scroll": {
|
||||||
|
"@type": "haxework.gui.list.VScrollView",
|
||||||
|
"skin": {"@type": "haxework.gui.list.VScrollSkin"}
|
||||||
|
},
|
||||||
|
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
46
src/client/haxe/layout/main.json
Executable file
46
src/client/haxe/layout/main.json
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"@type": "haxework.gui.VGroupView",
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id":"top", "@type": "haxework.gui.HGroupView",
|
||||||
|
"pWidth": 100, "height": 30,
|
||||||
|
"skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0x105000"},
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "logout", "@type": "haxework.gui.ButtonView",
|
||||||
|
"width": 100, "height": 30,
|
||||||
|
"text": "Logout",
|
||||||
|
"@style": "button_skin"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher",
|
||||||
|
"pWidth": 100, "pHeight": 100,
|
||||||
|
"skin": {"@type": "haxework.gui.skin.BitmapSkin", "image": "@asset:image:resources/images/background.png", "fillType": "REPEAT"},
|
||||||
|
"views": [
|
||||||
|
{
|
||||||
|
"id": "auth",
|
||||||
|
"@type": "ru.m.tankz.view.frames.AuthFrame"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "person_list",
|
||||||
|
"@type": "ru.m.tankz.view.frames.PersonListFrame"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "game_list",
|
||||||
|
"@type": "ru.m.tankz.view.frames.GameListFrame"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "game_ready",
|
||||||
|
"@type": "ru.m.tankz.view.frames.GameReadyFrame"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "game",
|
||||||
|
"@type": "ru.m.tankz.view.frames.GameFrame"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
12
src/client/haxe/layout/styles.json
Normal file
12
src/client/haxe/layout/styles.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"button_skin": {
|
||||||
|
"skin": {
|
||||||
|
"@type": "haxework.gui.skin.ButtonBitmapSkin",
|
||||||
|
"upImage": "@asset:image:resources/images/control/button_normal.png",
|
||||||
|
"downImage": "@asset:image:resources/images/control/button_down.png",
|
||||||
|
"overImage": "@asset:image:resources/images/control/button_over.png",
|
||||||
|
"fillType": "NINEPATH"
|
||||||
|
},
|
||||||
|
"fontColor": "0xffffff"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,25 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import haxework.gui.IGroupView;
|
import haxework.gui.IGroupView;
|
||||||
import ru.m.tankz.PacketBuilder;
|
import ru.m.tankz.PacketBuilder;
|
||||||
import haxework.log.JSLogger;
|
import haxework.log.JSLogger;
|
||||||
import ru.m.tankz.data.GameData;
|
import ru.m.tankz.data.GameData;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.tankz.view.frames.AuthFrame;
|
import ru.m.tankz.view.frames.AuthFrame;
|
||||||
import haxework.frame.FrameSwitcher;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import haxework.gui.Root;
|
import haxework.gui.Root;
|
||||||
import haxework.gui.GuiBuilder;
|
|
||||||
import haxe.Json;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
import haxework.log.TraceLogger;
|
import haxework.log.TraceLogger;
|
||||||
|
|
||||||
|
@:template("layout/main.json", "layout/styles.json")
|
||||||
|
class MainView extends VGroupView implements ViewBuilder {}
|
||||||
|
|
||||||
class Client implements IConnectionHandler {
|
class Client implements IConnectionHandler {
|
||||||
|
|
||||||
private static inline var TAG = "Tankz";
|
private static inline var TAG = "Tankz";
|
||||||
@@ -31,28 +34,25 @@ class Client implements IConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private var view:IGroupView<Sprite>;
|
private var view:MainView;
|
||||||
private var logout:ButtonView;
|
|
||||||
private var switcher:FrameSwitcher;
|
private var switcher:FrameSwitcher;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
var bytes = Assets.getBytes("resources/layout/main.json");
|
view = new MainView();
|
||||||
var form:Dynamic = Json.parse(bytes.readUTFBytes(bytes.bytesAvailable));
|
Root.bind(view);
|
||||||
view = GuiBuilder.build(form);
|
switcher = view.switcher;
|
||||||
new Root(view);
|
view.logout.onPress = this;
|
||||||
switcher = view.findViewById("switcher");
|
|
||||||
logout = view.findViewById("top:logout");
|
|
||||||
logout.onPress = this;
|
|
||||||
|
|
||||||
Provider.setFactory(GameData, GameData);
|
Provider.setFactory(GameData, GameData);
|
||||||
Provider.set(IFrameSwitcher, switcher);
|
Provider.set(IFrameSwitcher, switcher);
|
||||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
Provider.set(IPacketBuilder, new PacketBuilder());
|
||||||
#if flash
|
#if flash
|
||||||
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001, this));
|
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
|
||||||
#elseif html5
|
#elseif html5
|
||||||
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001, this));
|
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001));
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
Provider.get(IConnection).handler.addListener(this);
|
||||||
switcher.change(AuthFrame.ID);
|
switcher.change(AuthFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import haxework.gui.IView;
|
import haxework.gui.IView;
|
||||||
import ru.m.tankz.game.ITankz;
|
import ru.m.tankz.game.ITankz;
|
||||||
|
|
||||||
interface IRender extends IView<Sprite> {
|
interface IRender extends IView {
|
||||||
public function draw(game:ITankz):Void;
|
public function draw(game:ITankz):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ class Render extends SpriteView implements IRender {
|
|||||||
super();
|
super();
|
||||||
mapLayer = new Sprite();
|
mapLayer = new Sprite();
|
||||||
tankLayer = new Sprite();
|
tankLayer = new Sprite();
|
||||||
content.addChild(mapLayer);
|
contentAsSprite.addChild(mapLayer);
|
||||||
content.addChild(tankLayer);
|
contentAsSprite.addChild(tankLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:ITankz):Void {
|
public function draw(game:ITankz):Void {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
import ru.m.tankz.data.GameData;
|
import ru.m.tankz.data.GameData;
|
||||||
import flash.net.SharedObject;
|
import flash.net.SharedObject;
|
||||||
import ru.m.tankz.proto.ErrorResponse;
|
import ru.m.tankz.proto.ErrorResponse;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import ru.m.tankz.proto.LoginRequest;
|
import ru.m.tankz.proto.LoginRequest;
|
||||||
import ru.m.tankz.proto.LoginResponse;
|
import ru.m.tankz.proto.LoginResponse;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
@@ -14,7 +15,8 @@ import haxework.gui.InputView;
|
|||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
|
|
||||||
class AuthFrame extends VGroupView implements IPacketHandler {
|
@:template("layout/frames/auth.json", "layout/styles.json")
|
||||||
|
class AuthFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements IConnectionHandler {
|
||||||
|
|
||||||
private static inline var TAG = "AuthFrame";
|
private static inline var TAG = "AuthFrame";
|
||||||
|
|
||||||
@@ -22,18 +24,9 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
|
|
||||||
private var so:SharedObject;
|
private var so:SharedObject;
|
||||||
|
|
||||||
private var loginInput:InputView;
|
public function init() {
|
||||||
private var passwordInput:InputView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
so = SharedObject.getLocal("auth", "/");
|
so = SharedObject.getLocal("auth", "/");
|
||||||
}
|
authButton.onPress = this;
|
||||||
|
|
||||||
public function init():Void {
|
|
||||||
findViewById("auth", ButtonView).onPress = this;
|
|
||||||
loginInput = findViewById("login:input");
|
|
||||||
passwordInput = findViewById("password:input");
|
|
||||||
passwordInput.textField.displayAsPassword = true;
|
passwordInput.textField.displayAsPassword = true;
|
||||||
if (so.data.login != null && so.data.password != null) {
|
if (so.data.login != null && so.data.password != null) {
|
||||||
loginInput.text = so.data.login;
|
loginInput.text = so.data.login;
|
||||||
@@ -41,8 +34,9 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow() {
|
||||||
Provider.get(IConnection).packetHandler = this;
|
Provider.get(IConnection).handler.addListener(this);
|
||||||
|
Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
if (so.data.login != null && so.data.password != null) {
|
if (so.data.login != null && so.data.password != null) {
|
||||||
loginInput.text = so.data.login;
|
loginInput.text = so.data.login;
|
||||||
passwordInput.text = so.data.password;
|
passwordInput.text = so.data.password;
|
||||||
@@ -53,21 +47,18 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPress(_):Void {
|
public function onHide() {
|
||||||
var login:String = loginInput.text;
|
Provider.get(IConnection).handler.removeListener(this);
|
||||||
var password:String = Md5.encode(passwordInput.text);
|
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||||
var connection:IConnection = Provider.get(IConnection);
|
|
||||||
connection.connect()
|
|
||||||
.success(function(_) {
|
|
||||||
L.d(TAG, "Connected");
|
|
||||||
connection.send(new LoginRequest().setLogin(login).setPassword(password));
|
|
||||||
})
|
|
||||||
.fail(function(error) {
|
|
||||||
L.e(TAG, "Auth", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onPress(_) {
|
||||||
|
Provider.get(IConnection).connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IPacketHandler
|
||||||
|
**/
|
||||||
public function onLoginResponse(packet:LoginResponse):Void {
|
public function onLoginResponse(packet:LoginResponse):Void {
|
||||||
so.setProperty("login", loginInput.text);
|
so.setProperty("login", loginInput.text);
|
||||||
so.setProperty("password", passwordInput.text);
|
so.setProperty("password", passwordInput.text);
|
||||||
@@ -82,4 +73,20 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
|
|
||||||
public function onPacket(packet:Message):Void {}
|
public function onPacket(packet:Message):Void {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IConnectionHandler
|
||||||
|
**/
|
||||||
|
public function onConnected():Void {
|
||||||
|
Provider.get(IConnection).send(
|
||||||
|
new LoginRequest()
|
||||||
|
.setLogin(loginInput.text)
|
||||||
|
.setPassword(Md5.encode(passwordInput.text))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDisconnected():Void {}
|
||||||
|
|
||||||
|
public function onError(error:Dynamic):Void {
|
||||||
|
L.e(TAG, "Auth", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,28 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import ru.m.tankz.config.TankzConfig;
|
import ru.m.tankz.config.TankzConfig;
|
||||||
import ru.m.tankz.render.IRender;
|
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import ru.m.tankz.game.Tankz;
|
import ru.m.tankz.game.Tankz;
|
||||||
import ru.m.tankz.game.ITankz;
|
import ru.m.tankz.game.ITankz;
|
||||||
import ru.m.core.connect.IConnection;
|
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.tankz.data.GameData;
|
import ru.m.tankz.data.GameData;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import ru.m.tankz.render.Render;
|
|
||||||
|
|
||||||
class GameFrame extends VGroupView {
|
@:template("layout/frames/game.json", "layout/styles.json")
|
||||||
|
class GameFrame extends VGroupView implements ViewBuilder {
|
||||||
|
|
||||||
private static inline var TAG = "GameFrame";
|
private static inline var TAG = "GameFrame";
|
||||||
|
|
||||||
public static inline var ID = "game";
|
public static inline var ID = "game";
|
||||||
|
|
||||||
private var render:IRender;
|
|
||||||
private var game:ITankz;
|
private var game:ITankz;
|
||||||
|
|
||||||
private var config:TankzConfig;
|
private var config:TankzConfig;
|
||||||
|
|
||||||
public function new() {
|
public function init():Void {
|
||||||
super();
|
|
||||||
game = new Tankz();
|
game = new Tankz();
|
||||||
config = {
|
config = {
|
||||||
map: {
|
map: {
|
||||||
@@ -35,16 +32,12 @@ class GameFrame extends VGroupView {
|
|||||||
gridHeight: 26
|
gridHeight: 26
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
restart.onPress = this;
|
||||||
|
|
||||||
public function init():Void {
|
|
||||||
render = findViewById("render");
|
|
||||||
findViewById("restart", ButtonView).onPress = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
var person = Provider.get(GameData).person;
|
var person = Provider.get(GameData).person;
|
||||||
findViewById("name", LabelView).text = person.name;
|
name.text = person.name;
|
||||||
game.init(config);
|
game.init(config);
|
||||||
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import ru.m.tankz.proto.JoinGameResponse;
|
import ru.m.tankz.proto.JoinGameResponse;
|
||||||
import ru.m.tankz.proto.JoinGameRequest;
|
import ru.m.tankz.proto.JoinGameRequest;
|
||||||
import ru.m.tankz.proto.CreateGameResponse;
|
import ru.m.tankz.proto.CreateGameResponse;
|
||||||
import ru.m.tankz.proto.CreateGameRequest;
|
import ru.m.tankz.proto.CreateGameRequest;
|
||||||
import ru.m.tankz.view.frames.list.GameView;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.frame.IFrameSwitcher;
|
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import ru.m.tankz.proto.GamesResponse;
|
import ru.m.tankz.proto.GamesResponse;
|
||||||
@@ -19,18 +19,13 @@ import haxework.provider.Provider;
|
|||||||
import haxework.gui.list.VListView;
|
import haxework.gui.list.VListView;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
|
|
||||||
class GameListFrame extends VGroupView implements IPacketHandler implements ListViewListener<Game> {
|
@:template("layout/frames/game_list.json", "layout/styles.json")
|
||||||
|
class GameListFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener<Game> {
|
||||||
|
|
||||||
private static inline var TAG = "GameListFrame";
|
private static inline var TAG = "GameListFrame";
|
||||||
|
|
||||||
public static inline var ID = "game_list";
|
public static inline var ID = "game_list";
|
||||||
|
|
||||||
private var list:VListView<Game>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
list = findViewById("list");
|
list = findViewById("list");
|
||||||
list.dispatcher.addListener(this);
|
list.dispatcher.addListener(this);
|
||||||
@@ -39,10 +34,14 @@ class GameListFrame extends VGroupView implements IPacketHandler implements List
|
|||||||
|
|
||||||
public function onShow() {
|
public function onShow() {
|
||||||
findViewById("name", LabelView).text = Provider.get(GameData).person.name;
|
findViewById("name", LabelView).text = Provider.get(GameData).person.name;
|
||||||
Provider.get(IConnection).packetHandler = this;
|
Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
Provider.get(IConnection).send(new GamesRequest());
|
Provider.get(IConnection).send(new GamesRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onHide() {
|
||||||
|
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
public function onListItemClick(item:IListItemView<Game>):Void {
|
public function onListItemClick(item:IListItemView<Game>):Void {
|
||||||
L.d(TAG, "game selected: ", item.data.id);
|
L.d(TAG, "game selected: ", item.data.id);
|
||||||
Provider.get(IConnection).send(new JoinGameRequest().setGameId(item.data.id));
|
Provider.get(IConnection).send(new JoinGameRequest().setGameId(item.data.id));
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import ru.m.tankz.proto.ExitGameResponse;
|
import ru.m.tankz.proto.ExitGameResponse;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import ru.m.tankz.proto.GamesResponse;
|
import ru.m.tankz.proto.GamesResponse;
|
||||||
import ru.m.tankz.proto.ExitGameRequest;
|
import ru.m.tankz.proto.ExitGameRequest;
|
||||||
import ru.m.tankz.proto.StartGameResponse;
|
import ru.m.tankz.proto.StartGameResponse;
|
||||||
@@ -15,18 +16,13 @@ import haxework.provider.Provider;
|
|||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
|
|
||||||
class GameReadyFrame extends VGroupView implements IPacketHandler {
|
@:template("layout/frames/game_ready.json", "layout/styles.json")
|
||||||
|
class GameReadyFrame extends VGroupView implements ViewBuilder implements IPacketHandler {
|
||||||
|
|
||||||
private static inline var TAG = "GameReadyFrame";
|
private static inline var TAG = "GameReadyFrame";
|
||||||
|
|
||||||
public static inline var ID = "game_ready";
|
public static inline var ID = "game_ready";
|
||||||
|
|
||||||
private var list:VListView<Person>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
list = findViewById("list");
|
list = findViewById("list");
|
||||||
//list.dispatcher.addListener(this);
|
//list.dispatcher.addListener(this);
|
||||||
@@ -35,10 +31,14 @@ class GameReadyFrame extends VGroupView implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onShow() {
|
public function onShow() {
|
||||||
Provider.get(IConnection).packetHandler = this;
|
Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
list.data = Provider.get(GameData).game.persons;
|
list.data = Provider.get(GameData).game.persons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onHide() {
|
||||||
|
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
public function onStartGameResponse(packet:StartGameResponse):Void {
|
public function onStartGameResponse(packet:StartGameResponse):Void {
|
||||||
Provider.get(GameData).game = packet.game;
|
Provider.get(GameData).game = packet.game;
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||||
|
|||||||
@@ -1,31 +1,25 @@
|
|||||||
package ru.m.tankz.view.frames;
|
package ru.m.tankz.view.frames;
|
||||||
|
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
import ru.m.tankz.view.frames.GameListFrame;
|
import ru.m.tankz.view.frames.GameListFrame;
|
||||||
import haxework.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import ru.m.tankz.proto.PersonSelectResponse;
|
import ru.m.tankz.proto.PersonSelectResponse;
|
||||||
import ru.m.tankz.proto.PersonSelectRequest;
|
import ru.m.tankz.proto.PersonSelectRequest;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
import ru.m.tankz.view.frames.list.PersonView;
|
|
||||||
import ru.m.tankz.data.GameData;
|
import ru.m.tankz.data.GameData;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.tankz.proto.Person;
|
import ru.m.tankz.proto.Person;
|
||||||
import haxework.gui.list.VListView;
|
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
class PersonListFrame extends HGroupView implements IPacketHandler implements ListViewListener<Person> {
|
@:template("layout/frames/person_list.json", "layout/styles.json")
|
||||||
|
class PersonListFrame extends HGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener<Person> {
|
||||||
|
|
||||||
private static inline var TAG = "PersonListFrame";
|
private static inline var TAG = "PersonListFrame";
|
||||||
|
|
||||||
public static inline var ID = "person_list";
|
public static inline var ID = "person_list";
|
||||||
|
|
||||||
private var list:VListView<Person>;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
list = findViewById("list");
|
list = findViewById("list");
|
||||||
list.dispatcher.addListener(this);
|
list.dispatcher.addListener(this);
|
||||||
@@ -33,7 +27,11 @@ class PersonListFrame extends HGroupView implements IPacketHandler implements Li
|
|||||||
|
|
||||||
public function onShow() {
|
public function onShow() {
|
||||||
list.data = Provider.get(GameData).account.persons;
|
list.data = Provider.get(GameData).account.persons;
|
||||||
Provider.get(IConnection).packetHandler = this;
|
Provider.get(IConnection).packetHandler.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide() {
|
||||||
|
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onListItemClick(item:IListItemView<Person>):Void {
|
public function onListItemClick(item:IListItemView<Person>):Void {
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
{
|
|
||||||
"type":"haxework.frame.FrameSwitcher",
|
|
||||||
"skin":{"type":"haxework.gui.skin.BitmapSkin", "image":"@~image:resources/images/background.png", "fillType":"REPEAT"},
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"id":"menu", "type":"haxework.gui.VGroupView",
|
|
||||||
"pWidth":100, "pHeight":100,
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"id":"logo", "type":"haxework.gui.SpriteView", "contentSize":true,
|
|
||||||
"skin":{"type":"haxework.gui.skin.BitmapSkin", "image":"@~image:resources/images/logo/logo.png"}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type":"haxework.gui.VGroupView", "contentSize":true,
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"id":"start1", "type":"haxework.gui.ButtonView", "_include":"button",
|
|
||||||
"text":"1 Player", "onPress":"#listener"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"start2", "type":"haxework.gui.ButtonView", "_include":"button",
|
|
||||||
"text":"2 Player", "onPress":"#listener"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"options", "type":"haxework.gui.ButtonView", "_include":"button",
|
|
||||||
"text":"Options", "onPress":"#listener"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"about", "type":"haxework.gui.ButtonView", "_include":"button",
|
|
||||||
"text":"About", "onPress":"#listener"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"game", "type":"haxework.gui.HGroupView",
|
|
||||||
"pWidth":100, "pHeight":100,
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"id":"map", "type":"haxework.gui.SpriteView",
|
|
||||||
"pHeight":100, "r":1,
|
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type":"haxework.gui.VGroupView",
|
|
||||||
"pWidth":100, "pHeight":100,
|
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ff00"}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"about", "type":"haxework.gui.VGroupView",
|
|
||||||
"pWidth":100, "pHeight":100,
|
|
||||||
"views":[
|
|
||||||
{
|
|
||||||
"type":"haxework.gui.LabelView", "text":"@text:about",
|
|
||||||
"fontFamily":"@text:font", "fontEmbed":true, "fontSize":48, "contentSize":true
|
|
||||||
},
|
|
||||||
{"type":"haxework.gui.SpriteView", "height":400},
|
|
||||||
{
|
|
||||||
"id":"back", "type":"haxework.gui.ButtonView", "_include":"button",
|
|
||||||
"text":"Back", "onPress":"#listener"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
"_includes":{
|
|
||||||
"button":{
|
|
||||||
"width":250, "height":60,
|
|
||||||
"skin":{
|
|
||||||
"type":"haxework.gui.skin.ButtonBitmapSkin",
|
|
||||||
"upImage":"@~image:resources/images/control/button_normal.png",
|
|
||||||
"overImage":"@~image:resources/images/control/button_over.png",
|
|
||||||
"downImage":"@~image:resources/images/control/button_down.png",
|
|
||||||
"fillType":"NINEPATH"
|
|
||||||
},
|
|
||||||
"fontFamily":"@text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
{
|
|
||||||
"_includes": {
|
|
||||||
"button_skin": {
|
|
||||||
"skin": {
|
|
||||||
"type": "haxework.gui.skin.ButtonBitmapSkin",
|
|
||||||
"upImage": "@~image:resources/images/control/button_normal.png",
|
|
||||||
"downImage": "@~image:resources/images/control/button_down.png",
|
|
||||||
"overImage": "@~image:resources/images/control/button_over.png",
|
|
||||||
"fillType": "NINEPATH"
|
|
||||||
},
|
|
||||||
"fontColor": "0xffffff"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"type": "haxework.gui.VGroupView",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id":"top", "type": "haxework.gui.HGroupView",
|
|
||||||
"pWidth": 100, "height": 30,
|
|
||||||
"skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0x105000"},
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "logout", "type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 30,
|
|
||||||
"text": "Logout",
|
|
||||||
"_include": "button_skin"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "switcher", "type": "haxework.frame.FrameSwitcher",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"skin": {"type": "haxework.gui.skin.BitmapSkin", "image": "@~image:resources/images/background.png", "fillType": "REPEAT"},
|
|
||||||
"views": [
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "auth", "type": "ru.m.tankz.view.frames.AuthFrame",
|
|
||||||
"pWidth": 100, "pHeight": 100, "layoutMargin": 3,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "login", "type": "haxework.gui.HGroupView",
|
|
||||||
"contentSize": true,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"type": "haxework.gui.LabelView",
|
|
||||||
"width": 150, "height": 25, "text": "Login"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "input", "type": "haxework.gui.InputView",
|
|
||||||
"skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
|
|
||||||
"width": 200, "height": 25, "text": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "password", "type": "haxework.gui.HGroupView",
|
|
||||||
"contentSize": true,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"type": "haxework.gui.LabelView",
|
|
||||||
"width": 150, "height": 25, "text": "Password"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "input", "type": "haxework.gui.InputView",
|
|
||||||
"skin": {"type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"},
|
|
||||||
"width": 200, "height": 25, "text": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "auth",
|
|
||||||
"type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 45,
|
|
||||||
"text": "Auth",
|
|
||||||
"_include": "button_skin"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "person_list", "type": "ru.m.tankz.view.frames.PersonListFrame",
|
|
||||||
"pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "list", "type": "haxework.gui.list.VListView",
|
|
||||||
"factory": {
|
|
||||||
"type": "~ru.m.tankz.view.frames.list.PersonView"
|
|
||||||
},
|
|
||||||
"scroll": {
|
|
||||||
"type": "haxework.gui.list.VScrollView",
|
|
||||||
"skin": {"type": "haxework.gui.list.VScrollSkin"}
|
|
||||||
},
|
|
||||||
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "game_list", "type": "ru.m.tankz.view.frames.GameListFrame",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "name", "type": "haxework.gui.LabelView",
|
|
||||||
"pWidth": 100, "height": 25, "text": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "create", "type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 45,
|
|
||||||
"text": "Create",
|
|
||||||
"_include": "button_skin"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "list", "type": "haxework.gui.list.VListView",
|
|
||||||
"factory": {
|
|
||||||
"type": "~ru.m.tankz.view.frames.list.GameView"
|
|
||||||
},
|
|
||||||
"scroll": {
|
|
||||||
"type": "haxework.gui.list.VScrollView",
|
|
||||||
"skin": {"type": "haxework.gui.list.VScrollSkin"}
|
|
||||||
},
|
|
||||||
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "game_ready", "type": "ru.m.tankz.view.frames.GameReadyFrame",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "name", "type": "haxework.gui.LabelView",
|
|
||||||
"pWidth": 100, "height": 25, "text": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "start", "type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 45,
|
|
||||||
"text": "Start",
|
|
||||||
"_include": "button_skin"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "exit", "type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 45,
|
|
||||||
"text": "Exit",
|
|
||||||
"_include": "button_skin"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "list", "type": "haxework.gui.list.VListView",
|
|
||||||
"factory": {
|
|
||||||
"type": "~ru.m.tankz.view.frames.list.PersonView"
|
|
||||||
},
|
|
||||||
"scroll": {
|
|
||||||
"type": "haxework.gui.list.VScrollView",
|
|
||||||
"skin": {"type": "haxework.gui.list.VScrollSkin"}
|
|
||||||
},
|
|
||||||
"pWidth": 100, "pHeight": 100, "layoutMargin": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
"id": "game", "type": "ru.m.tankz.view.frames.GameFrame",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "name", "type": "haxework.gui.LabelView",
|
|
||||||
"pWidth": 100, "height": 25, "text": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "restart", "type": "haxework.gui.ButtonView",
|
|
||||||
"width": 100, "height": 45,
|
|
||||||
"text": "Restart",
|
|
||||||
"_include": "button_skin"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "render", "type": "ru.m.tankz.render.Render",
|
|
||||||
"contentSize": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,27 @@
|
|||||||
package ru.m.core.connect;
|
package ru.m.core.connect;
|
||||||
|
|
||||||
|
import haxework.dispath.Dispatcher;
|
||||||
|
import haxework.dispath.IDispatcher;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import haxework.net.callback.ICallback;
|
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.core.connect.IConnection;
|
import ru.m.core.connect.IConnection;
|
||||||
|
|
||||||
class BaseConnection implements IConnection {
|
class BaseConnection implements IConnection {
|
||||||
public var handler(default,default):IConnectionHandler;
|
public var handler(default,default):IDispatcher<IConnectionHandler>;
|
||||||
public var packetHandler(default,default):IPacketHandler;
|
public var packetHandler(default,default):IDispatcher<IPacketHandler>;
|
||||||
public var connected(default, null):Bool;
|
public var connected(default, null):Bool;
|
||||||
public var queue(default, null):PacketQueue;
|
public var queue(default, null):PacketQueue;
|
||||||
public var builder(default, null):IPacketBuilder;
|
public var builder(default, null):IPacketBuilder;
|
||||||
|
|
||||||
public function new(?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler) {
|
public function new() {
|
||||||
this.builder = Provider.get(IPacketBuilder);
|
this.builder = Provider.get(IPacketBuilder);
|
||||||
this.queue = new PacketQueue(builder);
|
this.queue = new PacketQueue(builder);
|
||||||
this.packetHandler = packetHandler;
|
this.handler = new Dispatcher<IConnectionHandler>();
|
||||||
this.handler = handler;
|
this.packetHandler = new Dispatcher<IPacketHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect():ICallback<Dynamic> {
|
public function connect():Void {
|
||||||
throw "Not implemented";
|
throw "Not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ class BaseConnection implements IConnection {
|
|||||||
receive(packet);
|
receive(packet);
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
trace(error);
|
trace(error);
|
||||||
handler.onError(error);
|
handler.dispatch(function(h) h.onError(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,13 +47,14 @@ class BaseConnection implements IConnection {
|
|||||||
|
|
||||||
public function receive(packet:Message):Void {
|
public function receive(packet:Message):Void {
|
||||||
L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop());
|
L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop());
|
||||||
if (packetHandler == null) return;
|
|
||||||
var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop();
|
var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop();
|
||||||
var method = Reflect.field(packetHandler, name);
|
packetHandler.dispatch(function(h) {
|
||||||
if (method != null && Reflect.isFunction(method)) {
|
var method = Reflect.field(h, name);
|
||||||
Reflect.callMethod(packetHandler, method, [packet]);
|
if (method != null && Reflect.isFunction(method)) {
|
||||||
} else {
|
Reflect.callMethod(h, method, [packet]);
|
||||||
packetHandler.onPacket(packet);
|
} else {
|
||||||
}
|
h.onPacket(packet);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package ru.m.core.connect;
|
package ru.m.core.connect;
|
||||||
|
|
||||||
import haxework.net.callback.ICallback;
|
import haxework.dispath.IDispatcher;
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
|
|
||||||
interface IConnection {
|
interface IConnection {
|
||||||
public var connected(default,null):Bool;
|
public var connected(default,null):Bool;
|
||||||
public var handler(default,default):IConnectionHandler;
|
public var handler(default,default):IDispatcher<IConnectionHandler>;
|
||||||
public var packetHandler(default,default):IPacketHandler;
|
public var packetHandler(default,default):IDispatcher<IPacketHandler>;
|
||||||
|
|
||||||
public var builder(default,null):IPacketBuilder;
|
public var builder(default,null):IPacketBuilder;
|
||||||
|
|
||||||
public function connect():ICallback<Dynamic>;
|
public function connect():Void;
|
||||||
public function disconnect():Void;
|
public function disconnect():Void;
|
||||||
public function send(packet:Message):Void;
|
public function send(packet:Message):Void;
|
||||||
public function pushData(bytes:Bytes):Void;
|
public function pushData(bytes:Bytes):Void;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package ru.m.core.connect.flash;
|
package ru.m.core.connect.flash;
|
||||||
|
|
||||||
import haxework.net.callback.Callback;
|
|
||||||
import haxework.net.callback.ICallback;
|
|
||||||
import ru.m.core.connect.IConnection.IConnectionHandler;
|
import ru.m.core.connect.IConnection.IConnectionHandler;
|
||||||
import flash.utils.Endian;
|
import flash.utils.Endian;
|
||||||
import haxe.io.BytesOutput;
|
import haxe.io.BytesOutput;
|
||||||
@@ -20,10 +18,8 @@ class FlashConnection extends BaseConnection {
|
|||||||
private var port:Int;
|
private var port:Int;
|
||||||
private var socket:Socket;
|
private var socket:Socket;
|
||||||
|
|
||||||
private var callback:ICallback<Dynamic>;
|
public function new(host:String, port:Int) {
|
||||||
|
super();
|
||||||
public function new(host:String, port:Int, ?handler:IConnectionHandler = null) {
|
|
||||||
super(handler);
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
connected = false;
|
connected = false;
|
||||||
@@ -36,55 +32,43 @@ class FlashConnection extends BaseConnection {
|
|||||||
socket.endian = Endian.LITTLE_ENDIAN;
|
socket.endian = Endian.LITTLE_ENDIAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function connect():ICallback<Dynamic> {
|
override public function connect():Void {
|
||||||
callback = Callback.build();
|
|
||||||
socket.connect(host, port);
|
socket.connect(host, port);
|
||||||
return callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function disconnect():Void {
|
override public function disconnect():Void {
|
||||||
if (socket.connected) {
|
if (socket.connected) {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onDisconnected();
|
handler.dispatch(function(h) h.onDisconnected());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onError(event:ErrorEvent):Void {
|
private function onError(event:ErrorEvent):Void {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onError(event);
|
handler.dispatch(function(h) h.onError(event));
|
||||||
if (callback != null) {
|
|
||||||
var c = callback;
|
|
||||||
callback = null;
|
|
||||||
c.callFail(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onConnect(_):Void {
|
private function onConnect(_):Void {
|
||||||
connected = true;
|
connected = true;
|
||||||
if (handler != null) handler.onConnected();
|
handler.dispatch(function(h) h.onConnected());
|
||||||
if (callback != null) {
|
|
||||||
var c = callback;
|
|
||||||
callback = null;
|
|
||||||
c.callSuccess(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onClose(_):Void {
|
private function onClose(_):Void {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onDisconnected();
|
handler.dispatch(function(h) h.onDisconnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onSocketData(_):Void {
|
private function onSocketData(_):Void {
|
||||||
try {
|
try {
|
||||||
var b = new flash.utils.ByteArray();
|
var b = new flash.utils.ByteArray();
|
||||||
socket.readBytes(b);
|
socket.readBytes(b);
|
||||||
var bs = Bytes.ofData(cast b);
|
var bs = Bytes.ofData(cast b);
|
||||||
pushData(bs);
|
pushData(bs);
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
handler.onError(error);
|
handler.dispatch(function(h) h.onError(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package ru.m.core.connect.js;
|
package ru.m.core.connect.js;
|
||||||
|
|
||||||
import ru.m.core.Base64;
|
import ru.m.core.Base64;
|
||||||
import haxework.net.callback.Callback;
|
|
||||||
import haxework.net.callback.ICallback;
|
|
||||||
import ru.m.core.connect.IConnection.IConnectionHandler;
|
import ru.m.core.connect.IConnection.IConnectionHandler;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
@@ -23,10 +21,8 @@ class JsConnection extends BaseConnection {
|
|||||||
private var port:Int;
|
private var port:Int;
|
||||||
private var socket:WebSocket;
|
private var socket:WebSocket;
|
||||||
|
|
||||||
private var callback:ICallback<Dynamic>;
|
public function new(host:String, port:Int) {
|
||||||
|
super();
|
||||||
public function new(host:String, port:Int, ?handler:IConnectionHandler = null) {
|
|
||||||
super(handler);
|
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
connected = false;
|
connected = false;
|
||||||
@@ -36,8 +32,7 @@ class JsConnection extends BaseConnection {
|
|||||||
return untyped __js__("self.socket = new WebSocket('ws://'+host+':'+port); ");
|
return untyped __js__("self.socket = new WebSocket('ws://'+host+':'+port); ");
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function connect():ICallback<Dynamic> {
|
override public function connect():Void {
|
||||||
callback = Callback.build();
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var decodeBytes = Base64.decodeBase64;
|
var decodeBytes = Base64.decodeBase64;
|
||||||
socket = buildSocket(host, port);
|
socket = buildSocket(host, port);
|
||||||
@@ -45,40 +40,29 @@ class JsConnection extends BaseConnection {
|
|||||||
socket.onclose = this.onClose;
|
socket.onclose = this.onClose;
|
||||||
socket.onerror = this.onError;
|
socket.onerror = this.onError;
|
||||||
socket.onmessage = this.onSocketData;
|
socket.onmessage = this.onSocketData;
|
||||||
return callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function disconnect():Void {
|
override public function disconnect():Void {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onDisconnected();
|
handler.dispatch(function(h) h.onDisconnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onError(event:Dynamic):Void {
|
private function onError(event:Dynamic):Void {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onError(event);
|
handler.dispatch(function(h) h.onError(event));
|
||||||
if (callback != null) {
|
|
||||||
var c = callback;
|
|
||||||
callback = null;
|
|
||||||
c.callFail(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onConnect(_):Void {
|
private function onConnect(_):Void {
|
||||||
connected = true;
|
connected = true;
|
||||||
if (handler != null) handler.onConnected();
|
handler.dispatch(function(h) h.onConnected());
|
||||||
if (callback != null) {
|
|
||||||
var c = callback;
|
|
||||||
callback = null;
|
|
||||||
c.callSuccess(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onClose(_):Void {
|
private function onClose(_):Void {
|
||||||
socket.close();
|
socket.close();
|
||||||
connected = false;
|
connected = false;
|
||||||
if (handler != null) handler.onDisconnected();
|
handler.dispatch(function(h) h.onDisconnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onSocketData(event:Dynamic):Void {
|
private function onSocketData(event:Dynamic):Void {
|
||||||
@@ -87,7 +71,7 @@ class JsConnection extends BaseConnection {
|
|||||||
var packet = WebSocketTools.string2packet(data, builder);
|
var packet = WebSocketTools.string2packet(data, builder);
|
||||||
receive(packet);
|
receive(packet);
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
handler.onError(error);
|
handler.dispatch(function(h) h.onError(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ class NekoConnection extends BaseConnection {
|
|||||||
|
|
||||||
public var socket(default, null):Socket;
|
public var socket(default, null):Socket;
|
||||||
|
|
||||||
public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) {
|
public function new(socket:Socket) {
|
||||||
super(handler, packetHandler);
|
super();
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
socket.setFastSend(true);
|
socket.setFastSend(true);
|
||||||
socket.output.bigEndian = false;
|
socket.output.bigEndian = false;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class NekoWebConnection extends NekoConnection {
|
|||||||
|
|
||||||
private var opened:Bool;
|
private var opened:Bool;
|
||||||
|
|
||||||
public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) {
|
public function new(socket:Socket) {
|
||||||
super(socket, handler, packetHandler);
|
super(socket);
|
||||||
opened = false;
|
opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,10 +105,12 @@ class Session implements IConnectionHandler implements IPacketHandler {
|
|||||||
} else {
|
} else {
|
||||||
var str:String = bytes.getString(0, bytes.length);
|
var str:String = bytes.getString(0, bytes.length);
|
||||||
if (StringTools.startsWith(str, "GET")) {
|
if (StringTools.startsWith(str, "GET")) {
|
||||||
connection = new NekoWebConnection(socket, this, this);
|
connection = new NekoWebConnection(socket);
|
||||||
} else {
|
} else {
|
||||||
connection = new NekoConnection(socket, this, this);
|
connection = new NekoConnection(socket);
|
||||||
}
|
}
|
||||||
|
connection.handler.addListener(this);
|
||||||
|
connection.packetHandler.addListener(this);
|
||||||
connection.pushData(bytes);
|
connection.pushData(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user