udpate
This commit is contained in:
@@ -12,10 +12,8 @@ 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;
|
||||
@@ -49,7 +47,6 @@ class Client implements IConnectionHandler {
|
||||
|
||||
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");
|
||||
@@ -66,7 +63,7 @@ class Client implements IConnectionHandler {
|
||||
view = new MainView();
|
||||
Provider.set(IFrameSwitcher, view.switcher);
|
||||
Root.bind(view);
|
||||
view.logout.onPress = this;
|
||||
//view.logout.onPress = this;
|
||||
view.switcher.change(StartFrame.ID);
|
||||
}
|
||||
|
||||
@@ -80,11 +77,11 @@ class Client implements IConnectionHandler {
|
||||
public function onConnected():Void {}
|
||||
|
||||
public function onDisconnected():Void {
|
||||
view.switcher.change(AuthFrame.ID);
|
||||
//view.switcher.change(AuthFrame.ID);
|
||||
}
|
||||
|
||||
public function onError(error:Dynamic):Void {
|
||||
L.e(TAG, "", error);
|
||||
view.switcher.change(AuthFrame.ID);
|
||||
//view.switcher.change(AuthFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package ru.m.tankz.data;
|
||||
|
||||
import ru.m.tankz.proto.Game;
|
||||
import ru.m.tankz.proto.Person;
|
||||
import ru.m.tankz.proto.Account;
|
||||
|
||||
class GameData {
|
||||
public var account:Account;
|
||||
public var person:Person;
|
||||
public var players:Array<Person>;
|
||||
public var game:Game;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import haxework.resources.IResources;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import flash.net.SharedObject;
|
||||
import ru.m.tankz.proto.ErrorResponse;
|
||||
import protohx.Message;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import ru.m.tankz.proto.LoginRequest;
|
||||
import ru.m.tankz.proto.LoginResponse;
|
||||
import haxework.provider.Provider;
|
||||
import haxe.crypto.Md5;
|
||||
import haxework.gui.InputView;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@:template("layout/frames/auth.json", "layout/styles.json")
|
||||
class AuthFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements IConnectionHandler {
|
||||
|
||||
private static inline var TAG = "AuthFrame";
|
||||
|
||||
public static inline var ID = "auth";
|
||||
|
||||
private var so:SharedObject;
|
||||
|
||||
public function init() {
|
||||
so = SharedObject.getLocal("auth", "/");
|
||||
authButton.onPress = this;
|
||||
passwordInput.textField.displayAsPassword = true;
|
||||
if (so.data.login != null && so.data.password != null) {
|
||||
loginInput.text = so.data.login;
|
||||
passwordInput.text = so.data.password;
|
||||
}
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
Provider.get(IConnection).handler.addListener(this);
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
if (so.data.login != null && so.data.password != null) {
|
||||
loginInput.text = so.data.login;
|
||||
passwordInput.text = so.data.password;
|
||||
//onPress(null);
|
||||
} else {
|
||||
loginInput.text = "shmyga";
|
||||
passwordInput.text = "xkbp8jh9z2";
|
||||
}
|
||||
}
|
||||
|
||||
public function onHide() {
|
||||
Provider.get(IConnection).handler.removeListener(this);
|
||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||
}
|
||||
|
||||
public function onPress(_) {
|
||||
Provider.get(IConnection).connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* IPacketHandler
|
||||
**/
|
||||
public function onLoginResponse(packet:LoginResponse):Void {
|
||||
so.setProperty("login", loginInput.text);
|
||||
so.setProperty("password", passwordInput.text);
|
||||
so.flush();
|
||||
Provider.get(IResources).text.put("userName", packet.account.login);
|
||||
Provider.get(GameData).account = packet.account;
|
||||
Provider.get(IFrameSwitcher).change(PersonListFrame.ID);
|
||||
}
|
||||
|
||||
public function onErrorResponse(packet:ErrorResponse):Void {
|
||||
L.e(TAG, packet.message);
|
||||
}
|
||||
|
||||
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,16 +1,17 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.proto.core.GameType;
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import ru.m.tankz.core.PlayerControl;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.GameUpdateResponse;
|
||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.tankz.config.TankzConfig;
|
||||
import flash.events.Event;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@:template("layout/frames/game.json", "layout/styles.json")
|
||||
@@ -29,12 +30,12 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
var data:GameData = Provider.get(GameData);
|
||||
engine.init(DEFAULT.CONFIG);
|
||||
engine.initTanks(data.game.persons); // ToDo:
|
||||
var game:Game = Provider.get(Game);
|
||||
engine.init(ConfigData.get(GameType.CLASSIC));
|
||||
engine.initTanks(game.players);
|
||||
content.addEventListener(Event.ENTER_FRAME, updateGame);
|
||||
for (index in 0...data.players.length) {
|
||||
var playerId:Int = data.players[index].id;
|
||||
for (index in 0...game.players.length) {
|
||||
var playerId:Int = game.players[index].id;
|
||||
controls.set(playerId, PlayerControl.forPlayer(index, playerId, engine));
|
||||
}
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
@@ -53,7 +54,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
|
||||
}
|
||||
|
||||
public function onGameUpdateResponse(packet:GameUpdateResponse):Void {
|
||||
engine.updateFromChanges(packet.changes);
|
||||
//engine.updateFromChanges(packet.changes);
|
||||
render.draw(engine);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.proto.GamesUnSubscribeRequest;
|
||||
import ru.m.tankz.proto.GamesSubscribeRequest;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.tankz.proto.JoinGameResponse;
|
||||
import ru.m.tankz.proto.JoinGameRequest;
|
||||
import ru.m.tankz.proto.CreateGameResponse;
|
||||
import ru.m.tankz.proto.CreateGameRequest;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.LabelView;
|
||||
import ru.m.tankz.proto.GamesResponse;
|
||||
import ru.m.tankz.proto.Game;
|
||||
import haxework.gui.list.ListView;
|
||||
import protohx.Message;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@: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";
|
||||
|
||||
public static inline var ID = "game_list";
|
||||
|
||||
public function init() {
|
||||
list.dispatcher.addListener(this);
|
||||
findViewById("create", ButtonView).onPress = this;
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
Provider.get(IConnection).send(new GamesSubscribeRequest());
|
||||
}
|
||||
|
||||
public function onHide() {
|
||||
Provider.get(IConnection).send(new GamesUnSubscribeRequest());
|
||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||
}
|
||||
|
||||
public function onListItemClick(item:IListItemView<Game>):Void {
|
||||
L.d(TAG, "game selected: ", item.data.id);
|
||||
Provider.get(IConnection).send(new JoinGameRequest().setGameId(item.data.id));
|
||||
}
|
||||
|
||||
public function onGamesResponse(packet:GamesResponse):Void {
|
||||
list.data = packet.games;
|
||||
}
|
||||
|
||||
public function onCreateGameResponse(packet:CreateGameResponse):Void {
|
||||
//list.data.push(packet.game);
|
||||
//list.update();
|
||||
Provider.get(GameData).game = packet.game;
|
||||
Provider.get(IFrameSwitcher).change(GameReadyFrame.ID);
|
||||
}
|
||||
|
||||
public function onJoinGameResponse(packet:JoinGameResponse):Void {
|
||||
Provider.get(GameData).game = packet.game;
|
||||
Provider.get(IFrameSwitcher).change(GameReadyFrame.ID);
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case "create":
|
||||
Provider.get(IConnection).send(new CreateGameRequest());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.proto.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.LeaveGameResponse;
|
||||
import ru.m.tankz.proto.JoinGameResponse;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import ru.m.tankz.proto.StartGameResponse;
|
||||
import ru.m.tankz.proto.StartGameRequest;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import protohx.Message;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.VGroupView;
|
||||
import ru.m.core.connect.IConnection;
|
||||
|
||||
@:template("layout/frames/game_ready.json", "layout/styles.json")
|
||||
class GameReadyFrame extends VGroupView implements ViewBuilder implements IPacketHandler {
|
||||
|
||||
private static inline var TAG = "GameReadyFrame";
|
||||
|
||||
public static inline var ID = "game_ready";
|
||||
|
||||
public function init() {
|
||||
//list.dispatcher.addListener(this);
|
||||
findViewById("start", ButtonView).onPress = this;
|
||||
findViewById("exit", ButtonView).onPress = this;
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
list.data = Provider.get(GameData).game.persons;
|
||||
}
|
||||
|
||||
public function onHide() {
|
||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||
}
|
||||
|
||||
public function onStartGameResponse(packet:StartGameResponse):Void {
|
||||
Provider.get(GameData).game = packet.game;
|
||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||
}
|
||||
|
||||
public function onJoinGameResponse(packet:JoinGameResponse):Void {
|
||||
Provider.get(GameData).game = packet.game;
|
||||
list.data = Provider.get(GameData).game.persons;
|
||||
}
|
||||
|
||||
public function onLeaveGameResponse(packet:LeaveGameResponse):Void {
|
||||
Provider.get(GameData).game = packet.game;
|
||||
list.data = Provider.get(GameData).game.persons;
|
||||
var person = Provider.get(GameData).person;
|
||||
if (!Lambda.exists(packet.game.persons, function(person) return person.id == person.id)) {
|
||||
Provider.get(GameData).game = null;
|
||||
Provider.get(IFrameSwitcher).change(GameListFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case "start":
|
||||
Provider.get(IConnection).send(new StartGameRequest());
|
||||
case "exit":
|
||||
Provider.get(IConnection).send(new LeaveGameRequest());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.tankz.view.frames.GameListFrame;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import ru.m.tankz.proto.PersonSelectResponse;
|
||||
import ru.m.tankz.proto.PersonSelectRequest;
|
||||
import haxework.gui.list.ListView;
|
||||
import protohx.Message;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.proto.Person;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@:template("layout/frames/person_list.json", "layout/styles.json")
|
||||
class PersonListFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener<Person> {
|
||||
|
||||
private static inline var TAG = "PersonListFrame";
|
||||
|
||||
public static inline var ID = "person_list";
|
||||
|
||||
public function init() {
|
||||
list = findViewById("list");
|
||||
list.dispatcher.addListener(this);
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
list.data = Provider.get(GameData).account.persons;
|
||||
Provider.get(IConnection).packetHandler.addListener(this);
|
||||
}
|
||||
|
||||
public function onHide() {
|
||||
Provider.get(IConnection).packetHandler.removeListener(this);
|
||||
}
|
||||
|
||||
public function onListItemClick(item:IListItemView<Person>):Void {
|
||||
Provider.get(IConnection).send(new PersonSelectRequest().setPersonId(item.data.id));
|
||||
}
|
||||
|
||||
public function onPersonSelectResponse(packet:PersonSelectResponse):Void {
|
||||
Provider.get(GameData).person = packet.person;
|
||||
Provider.get(IFrameSwitcher).change(GameListFrame.ID);
|
||||
}
|
||||
|
||||
public function onPacket(packet:Message):Void {}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package ru.m.tankz.view.frames;
|
||||
|
||||
import ru.m.tankz.proto.Person;
|
||||
import ru.m.tankz.proto.Game;
|
||||
import ru.m.tankz.proto.core.GameType;
|
||||
import ru.m.tankz.proto.core.Player;
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import ru.m.tankz.data.GameData;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.ViewBuilder;
|
||||
@@ -30,14 +30,14 @@ class StartFrame extends VGroupView implements ViewBuilder {
|
||||
|
||||
private function startGame(playersCount:Int):Void {
|
||||
var game = new Game();
|
||||
game.type = GameType.CLASSIC;
|
||||
for (i in 0...playersCount) {
|
||||
var player = new Person();
|
||||
var player = new Player();
|
||||
player.id = i;
|
||||
game.persons.push(player);
|
||||
game.players.push(player);
|
||||
}
|
||||
game.id = 1;
|
||||
Provider.get(GameData).players = game.persons;
|
||||
Provider.get(GameData).game = game;
|
||||
Provider.set(Game, game);
|
||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user