[proto] update
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package ru.m.tankz.frame;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
import ru.m.tankz.proto.core.Game;
|
import ru.m.tankz.proto.core.Game;
|
||||||
|
import ru.m.tankz.proto.core.User;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import haxework.gui.IGroupView;
|
import haxework.gui.IGroupView;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
@@ -24,6 +25,10 @@ interface NetworkFrameLayout {
|
|||||||
var gameListFrame(default, null):IGroupView;
|
var gameListFrame(default, null):IGroupView;
|
||||||
var createGameButton(default, null):ButtonView;
|
var createGameButton(default, null):ButtonView;
|
||||||
var gameList(default, null):ListView<Game>;
|
var gameList(default, null):ListView<Game>;
|
||||||
|
|
||||||
|
var gameFrame(default, null):IGroupView;
|
||||||
|
var leaveGameButton(default, null):ButtonView;
|
||||||
|
var userList(default, null):ListView<User>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||||
@@ -32,13 +37,19 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
|||||||
|
|
||||||
private var network(get, never):NetworkManager;
|
private var network(get, never):NetworkManager;
|
||||||
|
|
||||||
private function get_network():NetworkManager {
|
private inline function get_network():NetworkManager {
|
||||||
return Provider.get(NetworkManager);
|
return Provider.get(NetworkManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init():Void {
|
public function init():Void {
|
||||||
loginButton.onPress = this;
|
loginButton.onPress = this;
|
||||||
createGameButton.onPress = this;
|
createGameButton.onPress = this;
|
||||||
|
leaveGameButton.onPress = this;
|
||||||
|
gameList.dispatcher.addListener({
|
||||||
|
onListItemClick: function(item:IListItemView<Game>):Void {
|
||||||
|
network.joinGame(item.data.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
@@ -53,12 +64,30 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
|||||||
if (state == 'online') {
|
if (state == 'online') {
|
||||||
gameList.data = [];
|
gameList.data = [];
|
||||||
frameSwitcher.change(gameListFrame.id);
|
frameSwitcher.change(gameListFrame.id);
|
||||||
|
network.listGameSignal.connect(onListGame);
|
||||||
|
network.gameSignal.connect(onGame);
|
||||||
|
network.listGame();
|
||||||
} else {
|
} else {
|
||||||
frameSwitcher.change(loginFrame.id);
|
frameSwitcher.change(loginFrame.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onListGame(games:Array<Game>):Void {
|
||||||
|
gameList.data = games;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGame(game:Game):Void {
|
||||||
|
if (game != null) {
|
||||||
|
userList.data = game.players;
|
||||||
|
frameSwitcher.change(gameFrame.id);
|
||||||
|
} else {
|
||||||
|
frameSwitcher.change(gameListFrame.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onHide():Void {
|
public function onHide():Void {
|
||||||
|
network.listGameSignal.disconnect(onListGame);
|
||||||
|
network.gameSignal.disconnect(onGame);
|
||||||
network.stateSignal.disconnect(onStateChange);
|
network.stateSignal.disconnect(onStateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +96,9 @@ class NetworkFrame extends VGroupView implements ViewBuilder implements NetworkF
|
|||||||
case 'loginButton':
|
case 'loginButton':
|
||||||
network.login(nameInput.text);
|
network.login(nameInput.text);
|
||||||
case 'createGameButton':
|
case 'createGameButton':
|
||||||
|
network.createGame('classic');
|
||||||
|
case 'leaveGameButton':
|
||||||
|
network.leaveGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,32 @@ views:
|
|||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
paddings: 10
|
paddings: 10
|
||||||
|
scroll:
|
||||||
|
$type: haxework.gui.list.VScrollView
|
||||||
|
width: 10
|
||||||
|
pHeight: 100
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.list.VScrollSkin
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0
|
||||||
|
# game list
|
||||||
|
- id: gameFrame
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: leaveGameButton
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
$style: button
|
||||||
|
text: Leave
|
||||||
|
- id: userList
|
||||||
|
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.User>
|
||||||
|
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
paddings: 10
|
||||||
scroll:
|
scroll:
|
||||||
$type: haxework.gui.list.VScrollView
|
$type: haxework.gui.list.VScrollView
|
||||||
width: 10
|
width: 10
|
||||||
|
|||||||
25
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
25
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
package ru.m.tankz.frame.network;
|
||||||
|
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import haxework.gui.ViewBuilder;
|
||||||
|
import ru.m.tankz.proto.core.User;
|
||||||
|
|
||||||
|
|
||||||
|
interface UserItemViewLayout {
|
||||||
|
var label(default, null):LabelView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template("ru/m/tankz/frame/network/UserItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||||
|
class UserItemView extends HGroupView implements ViewBuilder implements IListItemView<User> implements UserItemViewLayout {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):User;
|
||||||
|
|
||||||
|
private function set_data(value:User):User {
|
||||||
|
data = value;
|
||||||
|
label.text = '${data.uuid} -- ${data.name}';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
width: 440
|
||||||
|
height: 44
|
||||||
|
margins: 5
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
$style: label
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
text: ""
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0.2
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.signal.Signal;
|
import ru.m.signal.Signal;
|
||||||
|
import ru.m.tankz.proto.core.Game;
|
||||||
|
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||||
import ru.m.tankz.proto.pack.LoginRequest;
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
@@ -15,6 +20,8 @@ class NetworkManager {
|
|||||||
|
|
||||||
public var state(default, null):String;
|
public var state(default, null):String;
|
||||||
public var stateSignal:Signal<String>;
|
public var stateSignal:Signal<String>;
|
||||||
|
public var listGameSignal:Signal<Array<Game>>;
|
||||||
|
public var gameSignal:Signal<Game>;
|
||||||
public var user(default, null):User;
|
public var user(default, null):User;
|
||||||
|
|
||||||
private var connection(get, never):ClientConnection;
|
private var connection(get, never):ClientConnection;
|
||||||
@@ -30,6 +37,8 @@ class NetworkManager {
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
stateSignal = new Signal<String>();
|
stateSignal = new Signal<String>();
|
||||||
|
listGameSignal = new Signal<Array<Game>>();
|
||||||
|
gameSignal = new Signal<Game>();
|
||||||
updateState('offline');
|
updateState('offline');
|
||||||
connection.handler.connect(onConnectionEvent);
|
connection.handler.connect(onConnectionEvent);
|
||||||
connection.receiveHandler.connect(onResponse);
|
connection.receiveHandler.connect(onResponse);
|
||||||
@@ -57,6 +66,22 @@ class NetworkManager {
|
|||||||
}).catchError(function(_) {});
|
}).catchError(function(_) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listGame():Void {
|
||||||
|
connection.send(new Request().setListGame(new ListGameRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createGame(type:String):Void {
|
||||||
|
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function joinGame(gameId:Int):Void {
|
||||||
|
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leaveGame():Void {
|
||||||
|
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
L.d('Network', '${event}');
|
L.d('Network', '${event}');
|
||||||
updateState(switch (event) {
|
updateState(switch (event) {
|
||||||
@@ -74,6 +99,17 @@ class NetworkManager {
|
|||||||
};
|
};
|
||||||
storage.write(user);
|
storage.write(user);
|
||||||
updateState('online');
|
updateState('online');
|
||||||
|
} else if (packet.hasLogout()) {
|
||||||
|
user = null;
|
||||||
|
updateState('connected');
|
||||||
|
} else if (packet.hasListGame()) {
|
||||||
|
listGameSignal.emit(packet.listGame.games);
|
||||||
|
} else if (packet.hasCreateGame()) {
|
||||||
|
gameSignal.emit(packet.createGame.game);
|
||||||
|
} else if (packet.hasJoinGame()) {
|
||||||
|
gameSignal.emit(packet.joinGame.game);
|
||||||
|
} else if (packet.hasLeaveGame()) {
|
||||||
|
gameSignal.emit(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class NekoConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
public function new(socket:Socket, i:Class<I>) {
|
public function new(socket:Socket, i:Class<I>) {
|
||||||
super(i);
|
super(i);
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
//socket.setFastSend(true);
|
socket.setFastSend(true);
|
||||||
//socket.output.bigEndian = false;
|
socket.output.bigEndian = false;
|
||||||
//socket.input.bigEndian = false;
|
socket.input.bigEndian = false;
|
||||||
sendHandler.connect(_send);
|
sendHandler.connect(_send);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,13 +21,19 @@ message LoginResponse {
|
|||||||
ru.m.tankz.proto.core.User user = 1;
|
ru.m.tankz.proto.core.User user = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logout
|
||||||
|
message LogoutRequest {}
|
||||||
|
|
||||||
message GameListRequest {}
|
message LogoutResponse {}
|
||||||
|
|
||||||
message GameListResponse {
|
// List Game
|
||||||
|
message ListGameRequest {}
|
||||||
|
|
||||||
|
message ListGameResponse {
|
||||||
repeated ru.m.tankz.proto.core.Game games = 1;
|
repeated ru.m.tankz.proto.core.Game games = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create Game
|
||||||
message CreateGameRequest {
|
message CreateGameRequest {
|
||||||
string type = 1;
|
string type = 1;
|
||||||
}
|
}
|
||||||
@@ -36,6 +42,7 @@ message CreateGameResponse {
|
|||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.Game game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join Game
|
||||||
message JoinGameRequest {
|
message JoinGameRequest {
|
||||||
int32 game_id = 1;
|
int32 game_id = 1;
|
||||||
}
|
}
|
||||||
@@ -44,19 +51,22 @@ message JoinGameResponse {
|
|||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.Game game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Leave Game
|
||||||
message LeaveGameRequest {}
|
message LeaveGameRequest {}
|
||||||
|
|
||||||
message LeaveGameResponse {
|
message LeaveGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.Game game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start Game
|
||||||
message StartGameRequest {}
|
message StartGameRequest {}
|
||||||
|
|
||||||
message StartGameResponse {
|
message StartGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.Game game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GameActionRequest {
|
// Game Update
|
||||||
|
message GameUpdateRequest {
|
||||||
ru.m.tankz.proto.game.GameActionType type = 1;
|
ru.m.tankz.proto.game.GameActionType type = 1;
|
||||||
int32 directionX = 2;
|
int32 directionX = 2;
|
||||||
int32 directionY = 3;
|
int32 directionY = 3;
|
||||||
@@ -66,19 +76,30 @@ message GameUpdateResponse {
|
|||||||
repeated ru.m.tankz.proto.game.GameChange changes = 1;
|
repeated ru.m.tankz.proto.game.GameChange changes = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Request
|
||||||
|
|
||||||
|
|
||||||
message Request {
|
message Request {
|
||||||
oneof content {
|
oneof content {
|
||||||
LoginRequest login = 1;
|
LoginRequest login = 1;
|
||||||
CreateGameRequest createGame = 2;
|
LogoutRequest logout = 2;
|
||||||
|
ListGameRequest listGame = 3;
|
||||||
|
CreateGameRequest createGame = 4;
|
||||||
|
JoinGameRequest joinGame = 5;
|
||||||
|
LeaveGameRequest leaveGame = 6;
|
||||||
|
StartGameRequest startGame = 7;
|
||||||
|
GameUpdateRequest updateGame = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Response
|
||||||
message Response {
|
message Response {
|
||||||
oneof content {
|
oneof content {
|
||||||
LoginResponse login = 1;
|
LoginResponse login = 1;
|
||||||
CreateGameResponse createGame = 2;
|
LogoutResponse logout = 2;
|
||||||
|
ListGameResponse listGame = 3;
|
||||||
|
CreateGameResponse createGame = 4;
|
||||||
|
JoinGameResponse joinGame = 5;
|
||||||
|
LeaveGameResponse leaveGame = 6;
|
||||||
|
StartGameResponse startGame = 7;
|
||||||
|
GameUpdateResponse udpateGame = 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
package ru.m.tankz.server.session;
|
package ru.m.tankz.server.session;
|
||||||
|
|
||||||
import ru.m.tankz.proto.pack.LoginRequest;
|
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||||
import ru.m.tankz.proto.pack.LoginResponse;
|
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
||||||
|
import ru.m.tankz.proto.pack.LogoutResponse;
|
||||||
|
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
import protohx.Message;
|
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.connect.neko.NekoConnection;
|
import ru.m.connect.neko.NekoConnection;
|
||||||
import ru.m.connect.neko.NekoWebConnection;
|
import ru.m.connect.neko.NekoWebConnection;
|
||||||
|
import ru.m.tankz.proto.core.Game;
|
||||||
import ru.m.tankz.proto.core.User;
|
import ru.m.tankz.proto.core.User;
|
||||||
|
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.ListGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.ListGameResponse;
|
||||||
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LoginResponse;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
import sys.net.Socket;
|
import sys.net.Socket;
|
||||||
import Type;
|
|
||||||
|
|
||||||
|
|
||||||
typedef ServerConnection = IConnection<Response, Request>;
|
typedef ServerConnection = IConnection<Response, Request>;
|
||||||
@@ -58,17 +67,56 @@ class Session {
|
|||||||
public function onRequest(request:Request):Void {
|
public function onRequest(request:Request):Void {
|
||||||
if (request.hasLogin()) {
|
if (request.hasLogin()) {
|
||||||
connection.send(new Response().setLogin(login(request.login)));
|
connection.send(new Response().setLogin(login(request.login)));
|
||||||
|
} else if (request.hasLogout()) {
|
||||||
|
connection.send(new Response().setLogout(logout(request.logout)));
|
||||||
|
} else if (request.hasListGame()) {
|
||||||
|
connection.send(new Response().setListGame(listGame(request.listGame)));
|
||||||
|
} else if (request.hasCreateGame()) {
|
||||||
|
connection.send(new Response().setCreateGame(createGame(request.createGame)));
|
||||||
|
} else if (request.hasJoinGame()) {
|
||||||
|
connection.send(new Response().setJoinGame(joinGame(request.joinGame)));
|
||||||
|
} else if (request.hasLeaveGame()) {
|
||||||
|
connection.send(new Response().setLeaveGame(leaveGame(request.leaveGame)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function login(request:LoginRequest):LoginResponse {
|
private function login(request:LoginRequest):LoginResponse {
|
||||||
return new LoginResponse().setUser(
|
user = new User()
|
||||||
new User()
|
.setUuid(request.uuid != null ? request.uuid : 'xxx')
|
||||||
.setUuid(request.uuid != null ? request.uuid : 'xxx')
|
.setName(request.name);
|
||||||
.setName(request.name)
|
return new LoginResponse().setUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logout(request:LogoutRequest):LogoutResponse {
|
||||||
|
user = null;
|
||||||
|
return new LogoutResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function listGame(request:ListGameRequest):ListGameResponse {
|
||||||
|
return new ListGameResponse().setGames([
|
||||||
|
new Game().setId(1).setType('test').setPlayers([new User().setUuid('test').setName('test')])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createGame(request:CreateGameRequest):CreateGameResponse {
|
||||||
|
return new CreateGameResponse().setGame(
|
||||||
|
new Game().setId(2).setType(request.type).setPlayers([user])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function joinGame(request:JoinGameRequest):JoinGameResponse {
|
||||||
|
return new JoinGameResponse().setGame(
|
||||||
|
new Game().setId(request.gameId).setType('test').setPlayers([
|
||||||
|
new User().setUuid('test').setName('test'),
|
||||||
|
user
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function leaveGame(request:LeaveGameRequest):LeaveGameResponse {
|
||||||
|
return new LeaveGameResponse();
|
||||||
|
}
|
||||||
|
|
||||||
/*public function onPersonSelectRequest(packet:PersonSelectRequest):Void {
|
/*public function onPersonSelectRequest(packet:PersonSelectRequest):Void {
|
||||||
var db = new DbProvider();
|
var db = new DbProvider();
|
||||||
var person = db.getPerson(packet.personId);
|
var person = db.getPerson(packet.personId);
|
||||||
|
|||||||
Reference in New Issue
Block a user