diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 15a56ef..c6acef5 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -10,4 +10,4 @@ user = fetch(:user) server host, ssh_options: { port: 22, user: user, forward_agent: true } set :tmp_dir, "/home/#{user}/tmp" -set :branch, 'master' +set :branch, 'develop' diff --git a/protohx.json b/protohx.json index 31df606..b162cd2 100755 --- a/protohx.json +++ b/protohx.json @@ -1,7 +1,9 @@ { - "protoPath": ".", + "protoPath": "src/common/proto", "protoFiles": [ - "src/common/proto/base.proto" + "src/common/proto/core.proto", + "src/common/proto/game.proto", + "src/common/proto/pack.proto" ], "cleanOut": true, "haxeOut": "src-gen/haxe", diff --git a/src/client/haxe/layout/frames/auth.json b/src/client/haxe/layout/frames/auth.json deleted file mode 100644 index fceed27..0000000 --- a/src/client/haxe/layout/frames/auth.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "pWidth": 100, "pHeight": 100, "layoutMargin": 3, - "views": [ - { - "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 44, "text": "Authorization", - "@style": "label" - }, - { - "@type": "haxework.gui.HGroupView", - "contentSize": true, - "views": [ - { - "@type": "haxework.gui.LabelView", - "width": 150, "height": 44, "text": "Login", - "@style": "label" - }, - { - "id": "loginInput", "@type": "haxework.gui.InputView", - "width": 220, "height": 44, "text": "", - "@style": "input" - } - ] - }, - { - "@type": "haxework.gui.HGroupView", - "contentSize": true, - "views": [ - { - "@type": "haxework.gui.LabelView", - "width": 150, "height": 44, "text": "Password", - "@style": "label" - }, - { - "id": "passwordInput", "@type": "haxework.gui.InputView", - "width": 220, "height": 44, "text": "", - "@style": "input" - } - ] - }, - - { - "id": "authButton", - "@type": "haxework.gui.ButtonView", - "width": 132, "height": 44, - "text": "Submit", - "@style": "button_skin" - } - ] -} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/game_list.json b/src/client/haxe/layout/frames/game_list.json deleted file mode 100644 index dfdd8d5..0000000 --- a/src/client/haxe/layout/frames/game_list.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id": "create", "@type": "haxework.gui.ButtonView", - "width": 132, "height": 44, - "text": "Create", - "@style": "button_skin" - }, - { - "id": "list", "@type": "haxework.gui.list.VListView", - "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 - } - ] -} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/game_ready.json b/src/client/haxe/layout/frames/game_ready.json deleted file mode 100644 index 028dd28..0000000 --- a/src/client/haxe/layout/frames/game_ready.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "pWidth": 100, "pHeight": 100, - "views": [ - { - "id": "start", "@type": "haxework.gui.ButtonView", - "width": 132, "height": 44, - "text": "Start", - "@style": "button_skin" - }, - { - "id": "exit", "@type": "haxework.gui.ButtonView", - "width": 132, "height": 44, - "text": "Exit", - "@style": "button_skin" - }, - { - "id": "list", "@type": "haxework.gui.list.VListView", - "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 - } - ] -} \ No newline at end of file diff --git a/src/client/haxe/layout/frames/person_list.json b/src/client/haxe/layout/frames/person_list.json deleted file mode 100644 index 97e5f0f..0000000 --- a/src/client/haxe/layout/frames/person_list.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10, - "views": [ - { - "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 44, "text": "Person select", - "@style": "label" - }, - { - "id": "list", "@type": "haxework.gui.list.VListView", - "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 - } - ] -} \ No newline at end of file diff --git a/src/client/haxe/layout/main.json b/src/client/haxe/layout/main.json index 743b1e6..e850cff 100755 --- a/src/client/haxe/layout/main.json +++ b/src/client/haxe/layout/main.json @@ -2,30 +2,6 @@ "@type": "haxework.gui.VGroupView", "pWidth": 100, "pHeight": 100, "views": [ - { - "visible": false, "inLayout": false, - "id":"top", "@type": "haxework.gui.HGroupView", - "pWidth": 100, "height": 44, - "skin": { - "@type": "haxework.gui.skin.BitmapSkin", - "image": "@asset:image:resources/images/map/map_5.png", - "fillType": "REPEAT" - }, - "views": [ - { - "id": "name", "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 44, - "text": "@res:text:userName", - "@style": "label" - }, - { - "id": "logout", "@type": "haxework.gui.ButtonView", - "width": 132, "height": 44, - "text": "Logout", - "@style": "button_skin" - } - ] - }, { "id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher", "pWidth": 100, "pHeight": 100, @@ -39,22 +15,6 @@ "id": "start", "@type": "ru.m.tankz.view.frames.StartFrame" }, - { - "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" diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 7188cbf..6ccc820 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -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); } } diff --git a/src/client/haxe/ru/m/tankz/data/GameData.hx b/src/client/haxe/ru/m/tankz/data/GameData.hx deleted file mode 100755 index 310d0ba..0000000 --- a/src/client/haxe/ru/m/tankz/data/GameData.hx +++ /dev/null @@ -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; - public var game:Game; -} diff --git a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx deleted file mode 100755 index c0ebcf0..0000000 --- a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx index 61a29d1..217470d 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/GameFrame.hx @@ -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); } diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx deleted file mode 100755 index 64fb6c4..0000000 --- a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx +++ /dev/null @@ -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 { - - 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):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()); - } - } -} diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx deleted file mode 100755 index e722ac3..0000000 --- a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx +++ /dev/null @@ -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()); - } - } -} diff --git a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx deleted file mode 100755 index bf16293..0000000 --- a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx +++ /dev/null @@ -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 { - - 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):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 {} -} diff --git a/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx index 955b2cf..ebccba6 100644 --- a/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx @@ -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); } } diff --git a/src/common/haxe/ru/m/tankz/PacketBuilder.hx b/src/common/haxe/ru/m/tankz/PacketBuilder.hx index b344478..126d457 100755 --- a/src/common/haxe/ru/m/tankz/PacketBuilder.hx +++ b/src/common/haxe/ru/m/tankz/PacketBuilder.hx @@ -1,25 +1,20 @@ package ru.m.tankz; -import ru.m.tankz.proto.LeaveGameRequest; -import ru.m.tankz.proto.LeaveGameResponse; -import ru.m.tankz.proto.GameUpdateResponse; -import ru.m.tankz.proto.GameActionRequest; +import ru.m.tankz.proto.pack.LeaveGameRequest; +import ru.m.tankz.proto.pack.LeaveGameResponse; +import ru.m.tankz.proto.pack.GameUpdateResponse; +import ru.m.tankz.proto.pack.GameActionRequest; import ru.m.core.connect.IConnection; import protohx.Message; -import ru.m.tankz.proto.LoginRequest; -import ru.m.tankz.proto.LoginResponse; -import ru.m.tankz.proto.PersonSelectRequest; -import ru.m.tankz.proto.PersonSelectResponse; -import ru.m.tankz.proto.ErrorResponse; -import ru.m.tankz.proto.GamesSubscribeRequest; -import ru.m.tankz.proto.GamesUnSubscribeRequest; -import ru.m.tankz.proto.GamesResponse; -import ru.m.tankz.proto.CreateGameRequest; -import ru.m.tankz.proto.CreateGameResponse; -import ru.m.tankz.proto.JoinGameRequest; -import ru.m.tankz.proto.JoinGameResponse; -import ru.m.tankz.proto.StartGameRequest; -import ru.m.tankz.proto.StartGameResponse; +import ru.m.tankz.proto.pack.ErrorResponse; +import ru.m.tankz.proto.pack.GameListRequest; +import ru.m.tankz.proto.pack.GameListResponse; +import ru.m.tankz.proto.pack.CreateGameRequest; +import ru.m.tankz.proto.pack.CreateGameResponse; +import ru.m.tankz.proto.pack.JoinGameRequest; +import ru.m.tankz.proto.pack.JoinGameResponse; +import ru.m.tankz.proto.pack.StartGameRequest; +import ru.m.tankz.proto.pack.StartGameResponse; class PacketBuilder implements IPacketBuilder { @@ -27,24 +22,21 @@ class PacketBuilder implements IPacketBuilder { 0x00 => [ 0x0001 => ErrorResponse ], - 0x01 => [ - 0x0001 => LoginRequest, - 0x0002 => LoginResponse, - 0x0003 => PersonSelectRequest, - 0x0004 => PersonSelectResponse - ], + /*0x01 => [ + + ],*/ 0x02 => [ - 0x0001 => GamesSubscribeRequest, - 0x0002 => GamesResponse, + 0x0001 => GameListRequest, + 0x0002 => GameListResponse, 0x0003 => CreateGameRequest, 0x0004 => CreateGameResponse, - 0x0005 => JoinGameRequest, - 0x0006 => JoinGameResponse, - 0x0007 => StartGameRequest, - 0x0008 => StartGameResponse, - 0x0009 => LeaveGameRequest, - 0x000a => LeaveGameResponse, - 0x000b => GamesUnSubscribeRequest + 0x0005 => GameListResponse, + 0x0006 => JoinGameRequest, + 0x0007 => JoinGameResponse, + 0x0008 => StartGameRequest, + 0x0009 => StartGameResponse, + 0x000a => LeaveGameRequest, + 0x000b => LeaveGameResponse ], 0x03 => [ 0x0001 => GameActionRequest, diff --git a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx b/src/common/haxe/ru/m/tankz/config/TankzConfig.hx index 0dcbd11..69174c4 100644 --- a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx +++ b/src/common/haxe/ru/m/tankz/config/TankzConfig.hx @@ -1,23 +1,75 @@ package ru.m.tankz.config; +import ru.m.tankz.proto.core.GameType; +import ru.m.tankz.core.Direction; + typedef MapConfig = { - var cellWidth:Float; - var cellHeight:Float; - var gridWidth:Int; - var gridHeight:Int; + var cellWidth:Float; + var cellHeight:Float; + var gridWidth:Int; + var gridHeight:Int; +} + +enum SpawnPointType { + PLAYER; + BOT; + EAGLE; +} + +typedef SpawnPoint = { + var type:SpawnPointType; + var index:Int; + var x:Int; + var y:Int; + var direction:Direction; } typedef TankzConfig = { - var map:MapConfig; + var map:MapConfig; + var points:Array; } -class DEFAULT { - public static var CONFIG:TankzConfig = { - map: { - cellWidth: 22, - cellHeight: 22, - gridWidth: 26, - gridHeight: 26 +class ConfigData { + public static var CLASSIC:TankzConfig = { + map: { + cellWidth: 22, + cellHeight: 22, + gridWidth: 26, + gridHeight: 26 + }, + points: [ + { + type: SpawnPointType.PLAYER, + index: 0, + x: 8, + y: 24, + direction: Direction.TOP + }, + { + type: SpawnPointType.PLAYER, + index: 1, + x: 16, + y: 24, + direction: Direction.TOP + } + ] + }; + + public static function get(type:Int):TankzConfig { + switch (type) { + case GameType.CLASSIC: + return CLASSIC; + case _: + return null; + } + } + + public static function findSpawnPoint(config:TankzConfig, type:SpawnPointType, index:Int):SpawnPoint { + for (point in config.points) { + if (point.type == type && point.index == index) { + return point; + } + } + return null; } - }; } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index 6423417..820e092 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -1,10 +1,10 @@ package ru.m.tankz.engine; import ru.m.tankz.core.Bullet; -import ru.m.tankz.proto.GameObjectType; -import ru.m.tankz.proto.GameChangeType; -import ru.m.tankz.proto.GameChange; -import ru.m.tankz.proto.Person; +import ru.m.tankz.proto.game.GameObjectType; +import ru.m.tankz.proto.game.GameChangeType; +import ru.m.tankz.proto.game.GameChange; +import ru.m.tankz.proto.core.Player; import ru.m.tankz.core.Direction; import ru.m.tankz.core.IMobileEntity; //import flash.geom.Rectangle; @@ -30,8 +30,8 @@ class Engine implements IEngine { tanks = new Map(); } - private function buildTank(personId:Int, id:Int, x:Float, y:Float, direction:Direction):Tank { - return new Tank(personId, id, x, y, direction); + private function buildTank(personId:Int, id:Int, cellX:Float, cellY:Float, direction:Direction):Tank { + return new Tank(personId, id, cellX * map.cellWidth, cellY * map.cellHeight, direction); } public function init(config:TankzConfig):Void { @@ -43,18 +43,17 @@ class Engine implements IEngine { y_limit = map.gridHeight * map.cellHeight; } - public function initTanks(persons:Array):Array { + public function initTanks(players:Array):Array { var changes = new Array(); - for (person in persons) { - var x = 0; - var y = 100 * persons.indexOf(person); - var tank = buildTank(person.id, 0, x, y, Direction.BOTTOM); + for (index in 0...players.length) { + var player:Player = players[index]; + var point:SpawnPoint = ConfigData.findSpawnPoint(config, SpawnPointType.PLAYER, index); + var tank = buildTank(player.id, 0, point.x, point.y, point.direction); this.tanks.set(tank.personId, tank); this.mobileEntities.set(tank.id, tank); changes.push(new GameChange() .setType(GameChangeType.APPEND) .setObjectType(GameObjectType.TANK) - .setPersonId(tank.personId) .setObjectId(tank.id) .setX(tank.x) .setY(tank.y) @@ -94,7 +93,7 @@ class Engine implements IEngine { } } - public function updateFromChanges(changes:Array):Void { + /*public function updateFromChanges(changes:Array):Void { for (change in changes) { switch (change.type) { case GameChangeType.APPEND: @@ -117,10 +116,10 @@ class Engine implements IEngine { target.x = change.x; target.y = change.y; case GameChangeType.MODIFIED: - // + } } - } + }*/ public function update():Array { var changes = new Array(); @@ -173,7 +172,6 @@ class Engine implements IEngine { changes.push(new GameChange() .setType(GameChangeType.MOVED) .setObjectType(objectType) - .setPersonId(personId) .setObjectId(entiny.id) .setX(entiny.x) .setY(entiny.y) @@ -187,7 +185,6 @@ class Engine implements IEngine { changes.push(new GameChange() .setType(GameChangeType.DESTROED) .setObjectType(objectType) - .setPersonId(personId) .setObjectId(entiny.id) ); } diff --git a/src/common/haxe/ru/m/tankz/engine/IEngine.hx b/src/common/haxe/ru/m/tankz/engine/IEngine.hx index 5968138..3e05a11 100755 --- a/src/common/haxe/ru/m/tankz/engine/IEngine.hx +++ b/src/common/haxe/ru/m/tankz/engine/IEngine.hx @@ -1,9 +1,9 @@ package ru.m.tankz.engine; -import ru.m.tankz.proto.GameChange; +import ru.m.tankz.proto.game.GameChange; import ru.m.tankz.core.IMobileEntity; import ru.m.tankz.core.Tank; -import ru.m.tankz.proto.Person; +import ru.m.tankz.proto.core.Player; import ru.m.tankz.config.TankzConfig; import ru.m.tankz.map.ITankzMap; @@ -15,8 +15,8 @@ interface IEngine { public function clear():Void; public function init(config:TankzConfig):Void; - public function initTanks(persons:Array):Array; + public function initTanks(players:Array):Array; public function action(tankId:Int, action:TankAction):Void; - public function updateFromChanges(changes:Array):Void; + //public function updateFromChanges(changes:Array):Void; public function update():Array; } diff --git a/src/common/proto/base.proto b/src/common/proto/base.proto deleted file mode 100755 index 97e19e2..0000000 --- a/src/common/proto/base.proto +++ /dev/null @@ -1,135 +0,0 @@ -package ru.m.tankz.proto; - -message Person { - required int32 id = 1; - required string name = 2; -} - -message Account { - required int32 id = 1; - required string login = 2; - repeated Person persons = 3; -} - -message LoginRequest { - required string login = 1; - required string password = 2; -} - -message LoginResponse { - required Account account = 1; -} - -message PersonSelectRequest { - required int32 person_id = 1; -} - -message PersonSelectResponse { - required Person person = 1; -} - -message ErrorResponse { - required int32 code = 1; - required string message = 2; -} - - -enum GameState { - READY = 1; - STARTED = 2; - ENDED = 3; -} - -message Game { - required int32 id = 1; - required Person creator = 2; - repeated Person persons = 3; - required GameState state = 4; -} - -message GamesSubscribeRequest { - -} - -message GamesUnSubscribeRequest { - -} - -message GamesResponse { - repeated Game games = 1; -} - -message CreateGameRequest { - -} - -message CreateGameResponse { - required Game game = 1; -} - -message JoinGameRequest { - required int32 game_id = 1; -} - -message JoinGameResponse { - required Game game = 1; -} - -message LeaveGameRequest { - -} - -message LeaveGameResponse { - required Game game = 1; -} - -message StartGameRequest { - -} - -message StartGameResponse { - required Game game = 1; -} - -/** - Game - */ -enum GameActionType { - MOVE = 1; - SHOT = 2; - STOP = 3; -} - -message GameActionRequest { - required GameActionType type = 1; - optional int32 directionX = 2; - optional int32 directionY = 3; -} - -enum GameObjectType { - TANK = 1; - BULLET = 2; -} - -enum GameChangeType { - MOVED = 1; - DESTROED = 2; - MODIFIED = 3; - APPEND = 4; - DIRECTION = 5; -} - -message GameChange { - required GameChangeType type = 1; - required GameObjectType objectType = 2; - optional int32 personId = 3; - required int32 objectId = 4; - optional float x = 5; - optional float y = 6; - optional int32 directionX = 7; - optional int32 directionY = 8; -} - -message GameUpdateResponse { - repeated GameChange changes = 1; -} \ No newline at end of file diff --git a/src/common/proto/core.proto b/src/common/proto/core.proto new file mode 100644 index 0000000..41f3e28 --- /dev/null +++ b/src/common/proto/core.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package ru.m.tankz.proto.core; + + +message Player { + int32 id = 1; + string name = 2; +} + +enum GameType { + CLASSIC = 0; +} + +enum GameState { + READY = 0; + STARTED = 1; + ENDED = 2; +} + +message Game { + int32 id = 1; + GameType type = 2; + Player creator = 3; + repeated Player players = 4; + GameState state = 5; +} \ No newline at end of file diff --git a/src/common/proto/game.proto b/src/common/proto/game.proto new file mode 100644 index 0000000..d4ed140 --- /dev/null +++ b/src/common/proto/game.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; + +package ru.m.tankz.proto.game; + + +enum GameActionType { + MOVE = 0; + SHOT = 1; + STOP = 2; +} + +enum GameObjectType { + TANK = 0; + BULLET = 1; +} + +enum GameChangeType { + MOVED = 0; + DESTROED = 1; + MODIFIED = 2; + APPEND = 3; + DIRECTION = 4; +} + +message GameChange { + GameChangeType type = 1; + GameObjectType objectType = 2; + int32 objectId = 3; + float x = 4; + float y = 5; + int32 directionX = 6; + int32 directionY = 7; +} diff --git a/src/common/proto/pack.proto b/src/common/proto/pack.proto new file mode 100644 index 0000000..b25b1d9 --- /dev/null +++ b/src/common/proto/pack.proto @@ -0,0 +1,56 @@ +syntax = "proto3"; + +import "core.proto"; +import "game.proto"; + +package ru.m.tankz.proto.pack; + + +message ErrorResponse { + int32 code = 1; + string message = 2; +} + +message GameListRequest {} + +message GameListResponse { + repeated ru.m.tankz.proto.core.Game games = 1; +} + +message CreateGameRequest { + ru.m.tankz.proto.core.GameType type = 1; +} + +message CreateGameResponse { + ru.m.tankz.proto.core.Game game = 1; +} + +message JoinGameRequest { + int32 game_id = 1; +} + +message JoinGameResponse { + ru.m.tankz.proto.core.Game game = 1; +} + +message LeaveGameRequest {} + +message LeaveGameResponse { + ru.m.tankz.proto.core.Game game = 1; +} + +message StartGameRequest {} + +message StartGameResponse { + ru.m.tankz.proto.core.Game game = 1; +} + +message GameActionRequest { + ru.m.tankz.proto.game.GameActionType type = 1; + int32 directionX = 2; + int32 directionY = 3; +} + +message GameUpdateResponse { + repeated ru.m.tankz.proto.game.GameChange changes = 1; +}