Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| abd1b834d7 | |||
| 6ad9076987 | |||
| 78bbf5264e | |||
| 4c8ae66624 | |||
| 5a3d5b974e | |||
| fb9a28c126 | |||
| 7115ea8ac2 |
@@ -48,6 +48,9 @@ const config = new Project.Config({
|
|||||||
assets: [
|
assets: [
|
||||||
'src/common/resources'
|
'src/common/resources'
|
||||||
],
|
],
|
||||||
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
|
],
|
||||||
macros: [
|
macros: [
|
||||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.13.0",
|
"version": "0.14.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"protoFiles": [
|
"protoFiles": [
|
||||||
"src/common/proto/core.proto",
|
"src/common/proto/core.proto",
|
||||||
"src/common/proto/game.proto",
|
"src/common/proto/game.proto",
|
||||||
|
"src/common/proto/room.proto",
|
||||||
"src/common/proto/pack.proto"
|
"src/common/proto/pack.proto"
|
||||||
],
|
],
|
||||||
"cleanOut": true,
|
"cleanOut": true,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Style {
|
|||||||
public static var darkColor = 0x777564;
|
public static var darkColor = 0x777564;
|
||||||
public static var textColor = 0xE7E0BB;
|
public static var textColor = 0xE7E0BB;
|
||||||
public static var activeColor = 0xFFFF00;
|
public static var activeColor = 0xFFFF00;
|
||||||
|
public static var borderColor = ColorUtil.multiply(lightColor, 1.5);
|
||||||
|
|
||||||
public static var baseFontSize = 18;
|
public static var baseFontSize = 18;
|
||||||
public static var bigFontSize = 22;
|
public static var bigFontSize = 22;
|
||||||
@@ -45,6 +46,14 @@ class Style {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function textBox(color:Int):SkinSet {
|
||||||
|
return [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(color, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public static function register(font:Font = null):Void {
|
public static function register(font:Font = null):Void {
|
||||||
resources.color.put("light", lightColor);
|
resources.color.put("light", lightColor);
|
||||||
resources.color.put("dark", darkColor);
|
resources.color.put("dark", darkColor);
|
||||||
@@ -111,7 +120,7 @@ class Style {
|
|||||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
]);
|
]);
|
||||||
resources.skin.put("border", [
|
resources.skin.put("border", [
|
||||||
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
Skin.border(borderColor, 1, 2),
|
||||||
]);
|
]);
|
||||||
resources.skin.put("scroll", [
|
resources.skin.put("scroll", [
|
||||||
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
||||||
@@ -134,13 +143,16 @@ class Style {
|
|||||||
]);
|
]);
|
||||||
resources.skin.put("window", [
|
resources.skin.put("window", [
|
||||||
Skin.color(darkColor),
|
Skin.color(darkColor),
|
||||||
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
Skin.border(borderColor, 1, 2),
|
||||||
Skin.geometry(new Geometry().setPadding(2)),
|
Skin.geometry(new Geometry().setPadding(2)),
|
||||||
]);
|
]);
|
||||||
resources.skin.put("window.close", [
|
resources.skin.put("window.close", [
|
||||||
Skin.size(36, 36),
|
Skin.size(36, 36),
|
||||||
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
||||||
]);
|
]);
|
||||||
|
resources.skin.put("line", [
|
||||||
|
Skin.color(borderColor),
|
||||||
|
]);
|
||||||
|
|
||||||
registerButton("settings", "cog-solid.svg");
|
registerButton("settings", "cog-solid.svg");
|
||||||
registerButton("close", "times-circle-solid.svg");
|
registerButton("close", "times-circle-solid.svg");
|
||||||
|
|||||||
@@ -7,16 +7,18 @@ import ru.m.tankz.game.GameEvent;
|
|||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
class NetworkGame extends Game {
|
class NetworkGame extends Game {
|
||||||
|
|
||||||
private var network:NetworkManager;
|
private var network:NetworkManager;
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
public function new(network:NetworkManager) {
|
||||||
super(new GameState(network.game.type, 0, network.game.level));
|
super(new GameState(network.room.game.type, 0, network.room.game.level));
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.controlFactory = new NetworkControlFactory();
|
this.controlFactory = new NetworkControlFactory();
|
||||||
network.gameEventSignal.connect(onGameEventProto);
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
|
network.stateSignal.connect(onConnectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onGameEventProto(game:GameEventResponse):Void {
|
private function onGameEventProto(game:GameEventResponse):Void {
|
||||||
@@ -26,10 +28,20 @@ class NetworkGame extends Game {
|
|||||||
gameEventSignal.emit(event);
|
gameEventSignal.emit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onConnectionState(state:ConnectionState):Void {
|
||||||
|
switch state {
|
||||||
|
case ONLINE(user):
|
||||||
|
if (network.room != null) {
|
||||||
|
network.joinGame(network.room.game.id);
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
var player = Lambda.find(network.game.players, function(player) return player.user.uuid == network.user.uuid);
|
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||||
if (player != null) {
|
if (slot != null) {
|
||||||
state.controls.push({playerId: [player.team, player.index], control: "human-0"});
|
state.controls.push({playerId: [slot.slot.team, slot.slot.index], control: "human-0"});
|
||||||
}
|
}
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
@@ -37,5 +49,6 @@ class NetworkGame extends Game {
|
|||||||
override public function dispose():Void {
|
override public function dispose():Void {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
network.gameEventSignal.disconnect(onGameEventProto);
|
network.gameEventSignal.disconnect(onGameEventProto);
|
||||||
|
network.stateSignal.disconnect(onConnectionState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotRequest;
|
||||||
import haxe.Serializer;
|
import haxe.Serializer;
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.proto.game.GameChangeProto;
|
|
||||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.GameEventRequest;
|
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
|
||||||
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.LogoutRequest;
|
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||||
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 ru.m.tankz.proto.pack.StartGameRequest;
|
import ru.m.tankz.proto.room.CreateRequest;
|
||||||
|
import ru.m.tankz.proto.room.JoinRequest;
|
||||||
|
import ru.m.tankz.proto.room.LeaveRequest;
|
||||||
|
import ru.m.tankz.proto.room.RoomListRequest;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomRequest;
|
||||||
|
import ru.m.tankz.proto.room.StartRequest;
|
||||||
import ru.m.tankz.storage.MultiplayerStorage;
|
import ru.m.tankz.storage.MultiplayerStorage;
|
||||||
|
|
||||||
typedef ClientConnection = IConnection<Request, Response>;
|
typedef ClientConnection = IConnection<Request, Response>;
|
||||||
@@ -35,31 +37,30 @@ enum ConnectionState {
|
|||||||
class NetworkManager {
|
class NetworkManager {
|
||||||
|
|
||||||
public var state(default, null):ConnectionState;
|
public var state(default, null):ConnectionState;
|
||||||
public var game(default, null):GameProto;
|
public var room(default, null):RoomProto;
|
||||||
public var user(default, null):UserProto;
|
public var user(default, null):UserProto;
|
||||||
|
|
||||||
public var stateSignal:Signal<ConnectionState>;
|
public var stateSignal:Signal<ConnectionState>;
|
||||||
public var listGameSignal:Signal<Array<GameProto>>;
|
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||||
public var gameSignal:Signal<GameProto>;
|
public var roomSignal:Signal<RoomProto>;
|
||||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
|
||||||
public var gameEventSignal:Signal<GameEventResponse>;
|
public var gameEventSignal:Signal<GameEventResponse>;
|
||||||
|
|
||||||
@:provide private var connection:ClientConnection;
|
@:provide private var connection:ClientConnection;
|
||||||
@:provide private var storage:MultiplayerStorage;
|
@:provide private var storage:MultiplayerStorage;
|
||||||
|
|
||||||
|
private var reconnectTimer:Timer;
|
||||||
|
private var reconnectDelay:Int;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
|
reconnectDelay = 500;
|
||||||
stateSignal = new Signal();
|
stateSignal = new Signal();
|
||||||
listGameSignal = new Signal();
|
listRoomSignal = new Signal();
|
||||||
gameSignal = new Signal();
|
roomSignal = new Signal();
|
||||||
gameUpdateSignal = new Signal();
|
|
||||||
gameEventSignal = new Signal();
|
gameEventSignal = new Signal();
|
||||||
updateState(OFFLINE);
|
updateState(OFFLINE);
|
||||||
connection.handler.connect(onConnectionEvent);
|
connection.handler.connect(onConnectionEvent);
|
||||||
connection.receiveHandler.connect(onResponse);
|
connection.receiveHandler.connect(onResponse);
|
||||||
var user = storage.user;
|
connect();
|
||||||
if (user != null) {
|
|
||||||
login(user.name, user.uuid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateState(value:ConnectionState):Void {
|
private function updateState(value:ConnectionState):Void {
|
||||||
@@ -68,41 +69,40 @@ class NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function login(name:String, uuid:String = null):Void {
|
public function login(name:String, uuid:String = null):Void {
|
||||||
updateState(CONNECT);
|
|
||||||
connection.connect().then(function(c:ClientConnection) {
|
|
||||||
updateState(LOGIN);
|
updateState(LOGIN);
|
||||||
c.send(new Request().setLogin(
|
connection.send(new Request().setLogin(
|
||||||
new LoginRequest()
|
new LoginRequest()
|
||||||
.setUuid(uuid)
|
.setUuid(uuid)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
));
|
));
|
||||||
}).catchError(function(error) {
|
|
||||||
updateState(ERROR(error));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout():Void {
|
public function logout():Void {
|
||||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listGame():Void {
|
public function listGame(subscribe:Bool):Void {
|
||||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createGame(type:String, level:Int):Void {
|
public function createGame(type:String, level:Int):Void {
|
||||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type).setLevel(level)));
|
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type).setLevel(level))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function joinGame(gameId:Int):Void {
|
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectSlot(slot:SlotProto):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leaveGame():Void {
|
public function leaveGame():Void {
|
||||||
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startGame():Void {
|
public function startGame():Void {
|
||||||
connection.send(new Request().setStartGame(new StartGameRequest()));
|
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action(tankId:Int, action:TankAction):Void {
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
@@ -111,18 +111,39 @@ class NetworkManager {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function connect():Void {
|
||||||
|
if (reconnectTimer != null) {
|
||||||
|
reconnectTimer.stop();
|
||||||
|
reconnectTimer = null;
|
||||||
|
}
|
||||||
|
reconnectTimer = null;
|
||||||
|
updateState(CONNECT);
|
||||||
|
connection.connect().catchError(function(error) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function reconnect():Void {
|
||||||
|
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||||
|
if (reconnectTimer == null) {
|
||||||
|
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
updateState(switch event {
|
updateState(switch event {
|
||||||
case CONNECTED:
|
case CONNECTED: CONNECTED;
|
||||||
L.d('Network', '$event');
|
case DISCONNECTED: OFFLINE;
|
||||||
CONNECTED;
|
case ERROR(error): ERROR(error);
|
||||||
case DISCONNECTED:
|
|
||||||
L.d('Network', '$event');
|
|
||||||
OFFLINE;
|
|
||||||
case ERROR(error):
|
|
||||||
L.e('Network', '$error', error);
|
|
||||||
ERROR(error);
|
|
||||||
});
|
});
|
||||||
|
switch event {
|
||||||
|
case CONNECTED:
|
||||||
|
reconnectDelay = 500;
|
||||||
|
var user = storage.user;
|
||||||
|
if (user != null) {
|
||||||
|
login(user.name, user.uuid);
|
||||||
|
}
|
||||||
|
case DISCONNECTED | ERROR(_):
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onResponse(packet:Response):Void {
|
private function onResponse(packet:Response):Void {
|
||||||
@@ -137,25 +158,11 @@ class NetworkManager {
|
|||||||
} else if (packet.hasLogout()) {
|
} else if (packet.hasLogout()) {
|
||||||
storage.user = null;
|
storage.user = null;
|
||||||
updateState(CONNECTED);
|
updateState(CONNECTED);
|
||||||
} else if (packet.hasListGame()) {
|
} else if (packet.hasRoomList()) {
|
||||||
listGameSignal.emit(packet.listGame.games);
|
listRoomSignal.emit(packet.roomList.rooms);
|
||||||
} else if (packet.hasCreateGame()) {
|
} else if (packet.hasRoom()) {
|
||||||
game = packet.createGame.game;
|
room = packet.room.room;
|
||||||
gameSignal.emit(game);
|
roomSignal.emit(room);
|
||||||
} else if (packet.hasJoinGame()) {
|
|
||||||
game = packet.joinGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
} else if (packet.hasLeaveGame()) {
|
|
||||||
if (packet.leaveGame.user.uuid == user.uuid) {
|
|
||||||
game = null;
|
|
||||||
gameSignal.emit(null);
|
|
||||||
} else {
|
|
||||||
game = packet.leaveGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
}
|
|
||||||
} else if (packet.hasStartGame()) {
|
|
||||||
game = packet.startGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
} else if (packet.hasGameEvent()) {
|
} else if (packet.hasGameEvent()) {
|
||||||
gameEventSignal.emit(packet.gameEvent);
|
gameEventSignal.emit(packet.gameEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,34 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxework.resources.IResources;
|
import haxework.resources.IResources;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
|
|
||||||
@:template class ClientView extends FrameSwitcher {
|
@:template class ClientView extends VGroupView {
|
||||||
|
@:view("switcher") var switcherView:FrameSwitcher;
|
||||||
|
@:view var username:LabelView;
|
||||||
|
@:view("login") var loginButton:ButtonView;
|
||||||
|
@:view("logout") var logoutButton:ButtonView;
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
@:provide var resources:IResources;
|
@:provide var resources:IResources;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var soundManager:SoundManager;
|
@:provide var soundManager:SoundManager;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
public function init():Void {
|
public function init():Void {
|
||||||
resources.text.put('version', '${Const.VERSION}');
|
resources.text.put('version', '${Const.VERSION}');
|
||||||
switcher = this;
|
switcher = switcherView;
|
||||||
|
network.stateSignal.connect(onConnectionState);
|
||||||
|
onConnectionState(network.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function launch():Void {
|
public function launch():Void {
|
||||||
@@ -22,11 +36,50 @@ import ru.m.tankz.sound.SoundManager;
|
|||||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
switch event.keyCode {
|
switch event.keyCode {
|
||||||
case Keyboard.ESCAPE:
|
case Keyboard.ESCAPE:
|
||||||
change(StartFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
case Keyboard.M:
|
case Keyboard.M:
|
||||||
soundManager.mute = !soundManager.mute;
|
soundManager.mute = !soundManager.mute;
|
||||||
|
case Keyboard.P:
|
||||||
|
if (game != null) {
|
||||||
|
game.pause = !game.pause;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
change(StartFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionState(state:ConnectionState):Void {
|
||||||
|
L.d("ClientView", 'onConnectionState: ${state}');
|
||||||
|
switch state {
|
||||||
|
case ONLINE(user):
|
||||||
|
username.text = user.name;
|
||||||
|
logoutButton.visible = true;
|
||||||
|
loginButton.visible = false;
|
||||||
|
case CONNECTED:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = true;
|
||||||
|
case ERROR(error):
|
||||||
|
//L.e("ClientView", 'onConnectionState: ERROR', error);
|
||||||
|
L.w("ClientView", 'onConnectionState: ERROR');
|
||||||
|
case _:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function login():Void {
|
||||||
|
LoginPopup.instance.show().then(function(user:User):Void {
|
||||||
|
L.d("Login", 'user: $user');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logout():Void {
|
||||||
|
network.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function close():Void {
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
---
|
---
|
||||||
$type: haxework.view.frame.FrameSwitcher
|
layout.overflow: true
|
||||||
geometry.size.stretch: true
|
|
||||||
skinId: dark
|
|
||||||
views:
|
views:
|
||||||
|
- $type: haxework.view.frame.FrameSwitcher
|
||||||
|
id: switcher
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout.overflow: true
|
||||||
|
skinId: dark
|
||||||
|
views:
|
||||||
- id: start
|
- id: start
|
||||||
$type: ru.m.tankz.view.StartFrame
|
$type: ru.m.tankz.view.StartFrame
|
||||||
- id: level
|
- id: level
|
||||||
@@ -15,7 +19,35 @@ views:
|
|||||||
$type: ru.m.tankz.view.SettingsFrame
|
$type: ru.m.tankz.view.SettingsFrame
|
||||||
- id: record
|
- id: record
|
||||||
$type: ru.m.tankz.view.RecordFrame
|
$type: ru.m.tankz.view.RecordFrame
|
||||||
- id: game_list
|
- id: room_list
|
||||||
$type: ru.m.tankz.view.network.GameListFrame
|
$type: ru.m.tankz.view.network.RoomListFrame
|
||||||
- id: game_room
|
- id: room
|
||||||
$type: ru.m.tankz.view.network.GameRoomFrame
|
$type: ru.m.tankz.view.network.RoomFrame
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
skinId: panel
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: settings
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.settings
|
||||||
|
+onPress: $code:switcher.change('settings')
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: username
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text
|
||||||
|
- id: login
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.login
|
||||||
|
+onPress: $code:login()
|
||||||
|
- id: logout
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.logout
|
||||||
|
+onPress: $code:logout()
|
||||||
|
visible: false
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: close
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.close
|
||||||
|
+onPress: $code:close()
|
||||||
|
|||||||
@@ -5,10 +5,3 @@ views:
|
|||||||
views:
|
views:
|
||||||
- id: game
|
- id: game
|
||||||
$type: ru.m.tankz.view.game.GameView
|
$type: ru.m.tankz.view.game.GameView
|
||||||
# - $type: haxework.view.HGroupView
|
|
||||||
# skinId: panel
|
|
||||||
# views:
|
|
||||||
# - id: close
|
|
||||||
# $type: haxework.view.ButtonView
|
|
||||||
# skinId: button.close
|
|
||||||
# +onPress: $code:close()
|
|
||||||
|
|||||||
@@ -16,9 +16,3 @@ views:
|
|||||||
factory: $this:levelViewFactory
|
factory: $this:levelViewFactory
|
||||||
+onItemSelect: $this:onLevelSelect
|
+onItemSelect: $this:onLevelSelect
|
||||||
geometry.padding: 10
|
geometry.padding: 10
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:switcher.change('start')
|
|
||||||
|
|||||||
@@ -25,8 +25,4 @@ import ru.m.tankz.storage.RecordStorage;
|
|||||||
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function close() {
|
|
||||||
switcher.change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,3 @@ views:
|
|||||||
scroll:
|
scroll:
|
||||||
$type: haxework.view.list.VScrollBarView
|
$type: haxework.view.list.VScrollBarView
|
||||||
skinId: scroll
|
skinId: scroll
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:close()
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
public static var ID(default, never):String = "result";
|
public static var ID(default, never):String = "result";
|
||||||
|
|
||||||
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
||||||
@:view("next") var nextButton:ButtonView;
|
|
||||||
@:view("level") var levelLabel:LabelView;
|
@:view("level") var levelLabel:LabelView;
|
||||||
|
|
||||||
@:provide var frames:FrameSwitcher;
|
@:provide var frames:FrameSwitcher;
|
||||||
@@ -37,7 +36,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
public function onShow() {
|
public function onShow() {
|
||||||
resultView.data = Lambda.array(state.players);
|
resultView.data = Lambda.array(state.players);
|
||||||
levelLabel.text = 'Level ${state.levelId}';
|
levelLabel.text = 'Level ${state.levelId}';
|
||||||
nextButton.visible = nextState != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function next() {
|
private function next() {
|
||||||
|
|||||||
@@ -14,16 +14,3 @@ views:
|
|||||||
$type: haxework.view.layout.VerticalLayout
|
$type: haxework.view.layout.VerticalLayout
|
||||||
hAlign: right
|
hAlign: right
|
||||||
margin: 10
|
margin: 10
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- id: close
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:close()
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.size.width: 100%
|
|
||||||
- id: next
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.next
|
|
||||||
+onPress: $code:next()
|
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
|
|
||||||
@:template class SettingsFrame extends VGroupView {
|
@:template class SettingsFrame extends VGroupView {
|
||||||
|
|
||||||
public static var ID(default, never):String = "settings";
|
public static var ID(default, never):String = "settings";
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,3 @@ views:
|
|||||||
controlIndex: 0
|
controlIndex: 0
|
||||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
controlIndex: 1
|
controlIndex: 1
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:switcher.change('start')
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.ButtonView;
|
|
||||||
import haxework.view.LabelView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.Type.GameType;
|
import ru.m.tankz.Type.GameType;
|
||||||
|
import ru.m.tankz.view.network.RoomListFrame;
|
||||||
|
import ru.m.tankz.view.network.RoomFrame;
|
||||||
import ru.m.tankz.view.popup.FontPopup;
|
import ru.m.tankz.view.popup.FontPopup;
|
||||||
import ru.m.tankz.view.popup.LoginPopup;
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
|
|
||||||
@@ -14,54 +14,34 @@ import ru.m.tankz.view.popup.LoginPopup;
|
|||||||
|
|
||||||
public static var ID(default, never):String = "start";
|
public static var ID(default, never):String = "start";
|
||||||
|
|
||||||
@:view var username:LabelView;
|
|
||||||
@:view("login") var loginButton:ButtonView;
|
|
||||||
@:view("logout") var logoutButton:ButtonView;
|
|
||||||
@:view("network") var networkButton:ButtonView;
|
|
||||||
|
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
|
|
||||||
private var fontPopup:FontPopup;
|
private var fontPopup:FontPopup;
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
onConnectionState(network.state);
|
|
||||||
network.stateSignal.connect(onConnectionState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onHide():Void {
|
|
||||||
network.stateSignal.disconnect(onConnectionState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onConnectionState(state:ConnectionState):Void {
|
|
||||||
trace("state", state);
|
|
||||||
setUser(switch state {
|
|
||||||
case ONLINE(user): user;
|
|
||||||
case _: null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setUser(value:User):Void {
|
|
||||||
username.text = value == null ? "" : value.name;
|
|
||||||
loginButton.visible = value == null;
|
|
||||||
logoutButton.visible = value != null;
|
|
||||||
networkButton.disabled = value == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function startGame(type:GameType):Void {
|
private function startGame(type:GameType):Void {
|
||||||
state = new GameState(type);
|
state = new GameState(type);
|
||||||
switcher.change(LevelFrame.ID);
|
switcher.change(LevelFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function login():Void {
|
private function startNetwork():Void {
|
||||||
LoginPopup.instance.show().then(function(user:User):Void {
|
switch network.state {
|
||||||
L.d("Login", 'user: $user');
|
case ONLINE(user):
|
||||||
});
|
if (network.room != null) {
|
||||||
|
switcher.change(RoomFrame.ID);
|
||||||
|
network.joinGame(network.room.game.id, true);
|
||||||
|
} else {
|
||||||
|
switcher.change(RoomListFrame.ID);
|
||||||
|
}
|
||||||
|
case CONNECTED:
|
||||||
|
LoginPopup.instance.show().then(function(user):Void {
|
||||||
|
if (user != null) {
|
||||||
|
switcher.change(RoomListFrame.ID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
|
|
||||||
private function logout():Void {
|
|
||||||
network.logout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function choiceFont():Void {
|
private function choiceFont():Void {
|
||||||
|
|||||||
@@ -28,31 +28,9 @@ views:
|
|||||||
- id: network
|
- id: network
|
||||||
$type: haxework.view.ButtonView
|
$type: haxework.view.ButtonView
|
||||||
skinId: button
|
skinId: button
|
||||||
+onPress: $code:switcher.change('game_list')
|
+onPress: $code:startNetwork()
|
||||||
text: Network
|
text: Network
|
||||||
disabled: true
|
#disabled: true
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- id: settings
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.settings
|
|
||||||
+onPress: $code:switcher.change('settings')
|
|
||||||
- $type: haxework.view.SpriteView
|
|
||||||
geometry.size.width: 100%
|
|
||||||
- id: username
|
|
||||||
$type: haxework.view.LabelView
|
|
||||||
skinId: text
|
|
||||||
geometry.margin.right: 10
|
|
||||||
- id: login
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.login
|
|
||||||
+onPress: $code:login()
|
|
||||||
- id: logout
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.logout
|
|
||||||
+onPress: $code:logout()
|
|
||||||
visible: false
|
|
||||||
- $type: haxework.view.LabelView
|
- $type: haxework.view.LabelView
|
||||||
geometry.hAlign: right
|
geometry.hAlign: right
|
||||||
geometry.vAlign: top
|
geometry.vAlign: top
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package ru.m.tankz.view.network;
|
|
||||||
|
|
||||||
import haxework.view.LabelView;
|
|
||||||
import haxework.view.HGroupView;
|
|
||||||
import haxework.view.list.ListView;
|
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
|
|
||||||
@:template class GameItemView extends HGroupView implements IListItemView<GameProto> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):GameProto;
|
|
||||||
|
|
||||||
@:view var label:LabelView;
|
|
||||||
|
|
||||||
private function set_data(value:GameProto):GameProto {
|
|
||||||
data = value;
|
|
||||||
label.text = '[${value.creator.name}] ${value.type} ${value.level} (${value.players.length})';
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function factory():GameItemView {
|
|
||||||
return new GameItemView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.width: 100%
|
|
||||||
geometry.size.height: 48
|
|
||||||
views:
|
|
||||||
- id: label
|
|
||||||
$type: haxework.view.LabelView
|
|
||||||
geometry.size.stretch: true
|
|
||||||
skinId: text.box
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package ru.m.tankz.view.network;
|
|
||||||
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
|
||||||
import haxework.view.list.VListView;
|
|
||||||
import haxework.view.VGroupView;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
|
|
||||||
@:template class GameListFrame extends VGroupView {
|
|
||||||
public static inline var ID = "game_list";
|
|
||||||
|
|
||||||
@:view var games:VListView<GameProto>;
|
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
|
||||||
@:provide var network:NetworkManager;
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
network.listGameSignal.connect(onGameList);
|
|
||||||
network.gameSignal.connect(onGame);
|
|
||||||
network.stateSignal.connect(onState);
|
|
||||||
network.listGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onHide():Void {
|
|
||||||
network.listGameSignal.disconnect(onGameList);
|
|
||||||
network.gameSignal.disconnect(onGame);
|
|
||||||
network.stateSignal.disconnect(onState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function create():Void {
|
|
||||||
network.createGame("classic", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onState(state:ConnectionState):Void {
|
|
||||||
switch state {
|
|
||||||
case ONLINE(_):
|
|
||||||
case _: switcher.change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameList(data:Array<GameProto>):Void {
|
|
||||||
games.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGame(game:GameProto):Void {
|
|
||||||
if (game != null) {
|
|
||||||
switcher.change(GameRoomFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function selectGame(game:GameProto):Void {
|
|
||||||
network.joinGame(game.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package ru.m.tankz.view.network;
|
|
||||||
|
|
||||||
import haxework.view.ButtonView;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
|
||||||
import haxework.view.list.VListView;
|
|
||||||
import haxework.view.TextView;
|
|
||||||
import haxework.view.VGroupView;
|
|
||||||
import ru.m.tankz.game.IGame;
|
|
||||||
import ru.m.tankz.game.NetworkGame;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
import ru.m.tankz.proto.core.GameStateProto;
|
|
||||||
import ru.m.tankz.proto.core.PlayerProto;
|
|
||||||
|
|
||||||
@:template class GameRoomFrame extends VGroupView {
|
|
||||||
|
|
||||||
public static inline var ID = "game_room";
|
|
||||||
|
|
||||||
@:view var start:ButtonView;
|
|
||||||
@:view var info:TextView;
|
|
||||||
@:view var players:VListView<PlayerProto>;
|
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
|
||||||
@:provide var network:NetworkManager;
|
|
||||||
@:provide var game:IGame;
|
|
||||||
|
|
||||||
private function refresh(game:GameProto):Void {
|
|
||||||
if (game != null) {
|
|
||||||
start.visible = game.creator.uuid == network.user.uuid;
|
|
||||||
info.text = '[${game.creator.name}] ${game.type} ${game.level} (${game.players.length})';
|
|
||||||
players.data = game.players;
|
|
||||||
if (game.state == GameStateProto.STARTED) {
|
|
||||||
this.game = new NetworkGame(network);
|
|
||||||
switcher.change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Timer.delay(function() switcher.change(GameListFrame.ID), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
refresh(network.game);
|
|
||||||
network.gameSignal.connect(onGame);
|
|
||||||
network.stateSignal.connect(onState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onHide():Void {
|
|
||||||
network.gameSignal.disconnect(onGame);
|
|
||||||
network.stateSignal.disconnect(onState);
|
|
||||||
// ToDo:
|
|
||||||
//network.leaveGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGame(game:GameProto):Void {
|
|
||||||
refresh(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onState(state:ConnectionState):Void {
|
|
||||||
switch state {
|
|
||||||
case ONLINE(_):
|
|
||||||
case _: switcher.change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
---
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.VGroupView
|
|
||||||
skinId: container
|
|
||||||
geometry.padding: 20
|
|
||||||
views:
|
|
||||||
- id: header
|
|
||||||
$type: haxework.view.LabelView
|
|
||||||
geometry.margin.bottom: 20
|
|
||||||
skinId: text.header
|
|
||||||
text: Game Room
|
|
||||||
- id: start
|
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
skinId: button.simple
|
|
||||||
text: Start
|
|
||||||
+onPress: $code:network.startGame()
|
|
||||||
visible: false
|
|
||||||
- id: info
|
|
||||||
$type: haxework.view.LabelView
|
|
||||||
geometry.size.width: 100%
|
|
||||||
skinId: text.box
|
|
||||||
- id: players
|
|
||||||
$type: haxework.view.list.VListView
|
|
||||||
geometry.size.stretch: true
|
|
||||||
factory: $code:ru.m.tankz.view.network.PlayerItemView.factory
|
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:network.leaveGame()
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package ru.m.tankz.view.network;
|
|
||||||
|
|
||||||
import haxework.view.HGroupView;
|
|
||||||
import haxework.view.LabelView;
|
|
||||||
import haxework.view.list.ListView;
|
|
||||||
import ru.m.tankz.proto.core.PlayerProto;
|
|
||||||
|
|
||||||
@:template class PlayerItemView extends HGroupView implements IListItemView<PlayerProto> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):PlayerProto;
|
|
||||||
|
|
||||||
@:view var label:LabelView;
|
|
||||||
|
|
||||||
private function set_data(value:PlayerProto):PlayerProto {
|
|
||||||
data = value;
|
|
||||||
label.text = '${value.user.name}';
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function factory():PlayerItemView {
|
|
||||||
return new PlayerItemView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.width: 100%
|
|
||||||
geometry.size.height: 48
|
|
||||||
views:
|
|
||||||
- id: label
|
|
||||||
$type: haxework.view.LabelView
|
|
||||||
geometry.size.stretch: true
|
|
||||||
skinId: text.box
|
|
||||||
50
src/client/haxe/ru/m/tankz/view/network/RoomFrame.hx
Normal file
50
src/client/haxe/ru/m/tankz/view/network/RoomFrame.hx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.list.VListView;
|
||||||
|
import haxework.view.TextView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.game.NetworkGame;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
|
@:template class RoomFrame extends VGroupView {
|
||||||
|
|
||||||
|
public static inline var ID = "room";
|
||||||
|
|
||||||
|
@:view var start:ButtonView;
|
||||||
|
@:view var info:TextView;
|
||||||
|
@:view var slots:VListView<RoomSlotProto>;
|
||||||
|
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
|
private function refresh(room:RoomProto):Void {
|
||||||
|
if (room != null) {
|
||||||
|
start.visible = room.creator.uuid == network.user.uuid;
|
||||||
|
info.text = '${room.game.type} #${room.game.level}';
|
||||||
|
slots.data = room.slots;
|
||||||
|
if (room.game.started) {
|
||||||
|
if (this.game == null) {
|
||||||
|
this.game = new NetworkGame(network);
|
||||||
|
}
|
||||||
|
switcher.change(GameFrame.ID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timer.delay(function() switcher.change(RoomListFrame.ID), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
refresh(network.room);
|
||||||
|
network.roomSignal.connect(refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
|
network.roomSignal.disconnect(refresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/client/haxe/ru/m/tankz/view/network/RoomFrame.yaml
Normal file
38
src/client/haxe/ru/m/tankz/view/network/RoomFrame.yaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
geometry.padding: 20
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: header
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.margin.bottom: 20
|
||||||
|
skinId: text.header
|
||||||
|
text: Game Room
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: info
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.padding: [30, 10]
|
||||||
|
skinId: text.box
|
||||||
|
- id: start
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Start
|
||||||
|
+onPress: $code:network.startGame()
|
||||||
|
visible: false
|
||||||
|
- id: leave
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Leave
|
||||||
|
+onPress: $code:network.leaveGame()
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.size.height: 3
|
||||||
|
skinId: line
|
||||||
|
- id: slots
|
||||||
|
$type: haxework.view.list.VListView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
factory: $code:ru.m.tankz.view.network.SlotItemView.factory
|
||||||
40
src/client/haxe/ru/m/tankz/view/network/RoomItemView.hx
Normal file
40
src/client/haxe/ru/m/tankz/view/network/RoomItemView.hx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.HGroupView;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.list.ListView;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
|
||||||
|
@:template class RoomItemView extends HGroupView implements IListItemView<RoomProto> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):RoomProto;
|
||||||
|
|
||||||
|
@:view("creator") var creatorView:LabelView;
|
||||||
|
@:view("type") var typeView:LabelView;
|
||||||
|
@:view("users") var usersView:LabelView;
|
||||||
|
@:view("join") var joinButton:ButtonView;
|
||||||
|
|
||||||
|
@:provide static var network:NetworkManager;
|
||||||
|
|
||||||
|
private function set_data(value:RoomProto):RoomProto {
|
||||||
|
data = value;
|
||||||
|
creatorView.skinId = value.creator.uuid == network.user.uuid ? "text.box.active" : "text.box";
|
||||||
|
creatorView.text = value.creator.name;
|
||||||
|
typeView.text = '${value.game.type} #${value.game.level}';
|
||||||
|
var used = value.slots.filter(function(slot:RoomSlotProto) return slot.hasUser()).length;
|
||||||
|
usersView.text = value.game.started ? 'started' : '${used}/${value.slots.length}';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function join():Void {
|
||||||
|
network.joinGame(data.game.id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function factory():RoomItemView {
|
||||||
|
return new RoomItemView();
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/client/haxe/ru/m/tankz/view/network/RoomItemView.yaml
Normal file
27
src/client/haxe/ru/m/tankz/view/network/RoomItemView.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
# geometry.size.width: 100%
|
||||||
|
geometry.size.height: 48
|
||||||
|
layout.margin: 10
|
||||||
|
layout.hAlign: center
|
||||||
|
views:
|
||||||
|
- id: creator
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.height: 100%
|
||||||
|
geometry.size.width: 200
|
||||||
|
skinId: text.box
|
||||||
|
- id: type
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.height: 100%
|
||||||
|
geometry.size.width: 200
|
||||||
|
skinId: text.box
|
||||||
|
- id: users
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.height: 100%
|
||||||
|
geometry.size.width: 150
|
||||||
|
skinId: text.box
|
||||||
|
- id: join
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
geometry.size.height: 100%
|
||||||
|
skinId: button.simple
|
||||||
|
text: Join
|
||||||
|
+onPress: $code:join()
|
||||||
47
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx
Normal file
47
src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.list.VListView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.view.popup.CreateGamePopup;
|
||||||
|
|
||||||
|
@:template class RoomListFrame extends VGroupView {
|
||||||
|
public static inline var ID = "room_list";
|
||||||
|
|
||||||
|
@:view var games:VListView<RoomProto>;
|
||||||
|
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
network.listRoomSignal.connect(onRoomList);
|
||||||
|
network.roomSignal.connect(onRoom);
|
||||||
|
network.listGame(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
|
network.listRoomSignal.disconnect(onRoomList);
|
||||||
|
network.roomSignal.disconnect(onRoom);
|
||||||
|
network.listGame(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create():Void {
|
||||||
|
CreateGamePopup.instance.show().then(function(result) {
|
||||||
|
if (result != null) {
|
||||||
|
network.createGame(result.type, result.level);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onRoomList(data:Array<RoomProto>):Void {
|
||||||
|
games.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onRoom(room:RoomProto):Void {
|
||||||
|
if (room != null) {
|
||||||
|
switcher.change(RoomFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,12 +16,5 @@ views:
|
|||||||
- id: games
|
- id: games
|
||||||
$type: haxework.view.list.VListView
|
$type: haxework.view.list.VListView
|
||||||
geometry.size.stretch: true
|
geometry.size.stretch: true
|
||||||
factory: $code:ru.m.tankz.view.network.GameItemView.factory
|
factory: $code:ru.m.tankz.view.network.RoomItemView.factory
|
||||||
geometry.margin: 10
|
geometry.margin: 10
|
||||||
+onItemSelect: $code:function(item) selectGame(item.data)
|
|
||||||
- $type: haxework.view.HGroupView
|
|
||||||
skinId: panel
|
|
||||||
views:
|
|
||||||
- $type: haxework.view.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $code:switcher.change('start')
|
|
||||||
45
src/client/haxe/ru/m/tankz/view/network/SlotItemView.hx
Normal file
45
src/client/haxe/ru/m/tankz/view/network/SlotItemView.hx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package ru.m.tankz.view.network;
|
||||||
|
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.HGroupView;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.list.ListView;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
|
@:template class SlotItemView extends HGroupView implements IListItemView<RoomSlotProto> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):RoomSlotProto;
|
||||||
|
|
||||||
|
@:view("type") var typeView:LabelView;
|
||||||
|
@:view("user") var userView:LabelView;
|
||||||
|
@:view("select") var selectButton:ButtonView;
|
||||||
|
|
||||||
|
@:provide static var network:NetworkManager;
|
||||||
|
@:provide static var configBundle:IConfigBundle;
|
||||||
|
|
||||||
|
private function set_data(value:RoomSlotProto):RoomSlotProto {
|
||||||
|
data = value;
|
||||||
|
typeView.text = '${value.slot.team} #${value.slot.index}';
|
||||||
|
userView.text = value.hasUser() ? value.user.name : "(NONE)";
|
||||||
|
userView.visible = value.hasUser();
|
||||||
|
selectButton.visible = !value.hasUser();
|
||||||
|
userView.skinId = (value.hasUser() && value.user.uuid == network.user.uuid) ? "text.box.active" : "text.box";
|
||||||
|
var config = configBundle.get(network.room.game.type);
|
||||||
|
var color = config.getColor([value.slot.team, value.slot.index]);
|
||||||
|
if (color != null) {
|
||||||
|
typeView.skin = Style.textBox(color);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function select():Void {
|
||||||
|
network.selectSlot(data.slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function factory():SlotItemView {
|
||||||
|
return new SlotItemView();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/client/haxe/ru/m/tankz/view/network/SlotItemView.yaml
Normal file
25
src/client/haxe/ru/m/tankz/view/network/SlotItemView.yaml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
geometry.size.height: 48
|
||||||
|
geometry.padding: 2
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: type
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text.box
|
||||||
|
geometry.size.height: 100%
|
||||||
|
geometry.size.width: 150
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
geometry.size.height: 100%
|
||||||
|
geometry.size.width: 300
|
||||||
|
views:
|
||||||
|
- id: user
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
skinId: text.box
|
||||||
|
- id: select
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Select
|
||||||
|
+onPress: $this:select()
|
||||||
72
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
72
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.popup.PopupView;
|
||||||
|
import haxework.view.ToggleButtonView;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
private typedef Result = {
|
||||||
|
var type:GameType;
|
||||||
|
var level:LevelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template class CreateGamePopup extends PopupView<Result> {
|
||||||
|
|
||||||
|
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||||
|
@:view("level") var levelView:DataView<LevelId, ToggleButtonView>;
|
||||||
|
|
||||||
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
|
private var type:GameType;
|
||||||
|
private var level:LevelId;
|
||||||
|
|
||||||
|
override private function onShow():Void {
|
||||||
|
super.onShow();
|
||||||
|
onGameTypeSelect(0, "classic", typeView.dataViews[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function submit():Void {
|
||||||
|
close({type:type, level:level});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function gameTypeViewFactory(index:Int, type:GameType):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = "button.simple";
|
||||||
|
result.text = type;
|
||||||
|
result.on = type == this.type;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameTypeSelect(index:Int, value:GameType, view:ToggleButtonView):Void {
|
||||||
|
this.type = value;
|
||||||
|
for (v in typeView.dataViews) {
|
||||||
|
v.on = v == view;
|
||||||
|
}
|
||||||
|
levelView.data = [for (i in 0...configBundle.get(type).game.levels) i];
|
||||||
|
onLevelSelect(0, 0, levelView.dataViews[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function levelViewFactory(index:Int, value:LevelId):ToggleButtonView {
|
||||||
|
var result = new ToggleButtonView();
|
||||||
|
result.skinId = "button.level";
|
||||||
|
result.text = Std.string(value);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onLevelSelect(index:Int, level:LevelId, view:ToggleButtonView):Void {
|
||||||
|
this.level = level;
|
||||||
|
for (v in levelView.dataViews) {
|
||||||
|
v.on = v == view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var instance(get, null):CreateGamePopup;
|
||||||
|
|
||||||
|
private static function get_instance():CreateGamePopup {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new CreateGamePopup();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
68
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
68
src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.yaml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
---
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
view:
|
||||||
|
$type: haxework.view.VGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
geometry.size.width: 600
|
||||||
|
skinId: window
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 10
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: name
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.margin.left: 10
|
||||||
|
layout.hAlign: left
|
||||||
|
skinId: text
|
||||||
|
text: New game
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: window.close
|
||||||
|
+onPress: $code:reject('close')
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.padding: 20
|
||||||
|
layout.margin: 5
|
||||||
|
layout.hAlign: center
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Type
|
||||||
|
- id: type
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.HorizontalLayout
|
||||||
|
margin: 10
|
||||||
|
factory: $this:gameTypeViewFactory
|
||||||
|
+onItemSelect: $this:onGameTypeSelect
|
||||||
|
data:
|
||||||
|
- "classic"
|
||||||
|
- "dota"
|
||||||
|
- "death"
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
skinId: text
|
||||||
|
text: Level
|
||||||
|
- id: level
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onItemSelect: $this:onLevelSelect
|
||||||
|
geometry.padding: 10
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.margin: 5
|
||||||
|
skinId: panel
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
|
skinId: button.simple
|
||||||
|
text: Create
|
||||||
|
+onPress: $code:submit()
|
||||||
@@ -8,7 +8,7 @@ import haxework.view.popup.PopupView;
|
|||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.GameProgress;
|
||||||
|
|
||||||
typedef Result = {
|
private typedef Result = {
|
||||||
var control:ControlPreset;
|
var control:ControlPreset;
|
||||||
var preset:GamePreset;
|
var preset:GamePreset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,14 @@ view:
|
|||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
skinId: text
|
skinId: text
|
||||||
text: Password
|
text: Password
|
||||||
|
visible: false
|
||||||
- id: password
|
- id: password
|
||||||
$type: haxework.view.InputView
|
$type: haxework.view.InputView
|
||||||
textField.displayAsPassword: true
|
textField.displayAsPassword: true
|
||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
geometry.size.height: 28
|
geometry.size.height: 28
|
||||||
skinId: text.box
|
skinId: text.box
|
||||||
|
visible: false
|
||||||
- id: error
|
- id: error
|
||||||
$type: haxework.view.TextView
|
$type: haxework.view.TextView
|
||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ class DesktopConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
connected = true;
|
connected = true;
|
||||||
reader = Thread.create(_read);
|
reader = Thread.create(_read);
|
||||||
connectDeferred.resolve(this);
|
connectDeferred.resolve(this);
|
||||||
|
handler.emit(ConnectionEvent.CONNECTED);
|
||||||
}
|
}
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
|
handler.emit(ConnectionEvent.ERROR(error));
|
||||||
Timer.delay(function() connectDeferred.throwError(error), 1);
|
Timer.delay(function() connectDeferred.throwError(error), 1);
|
||||||
}
|
}
|
||||||
return connectDeferred.promise();
|
return connectDeferred.promise();
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onError(event:Dynamic):Void {
|
private function onError(event:Dynamic):Void {
|
||||||
socket.close();
|
socket.close(1000);
|
||||||
connected = false;
|
connected = false;
|
||||||
handler.emit(ConnectionEvent.ERROR(event));
|
handler.emit(ConnectionEvent.ERROR(event));
|
||||||
}
|
}
|
||||||
@@ -67,18 +67,25 @@ class JsConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onSocketData(event:Dynamic):Void {
|
private function onSocketData(event:Dynamic):Void {
|
||||||
|
var packet:I = null;
|
||||||
try {
|
try {
|
||||||
var bytes = Bytes.ofData(event.data);
|
var bytes = Bytes.ofData(event.data);
|
||||||
var packet:I = PacketUtil.fromBytes(bytes, queue.packetClass);
|
packet = PacketUtil.fromBytes(bytes, queue.packetClass);
|
||||||
receive(packet);
|
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
handler.emit(ConnectionEvent.ERROR(event));
|
handler.emit(ConnectionEvent.ERROR(error));
|
||||||
|
}
|
||||||
|
if (packet != null) {
|
||||||
|
receive(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function send(packet:O):Void {
|
override public function send(packet:O):Void {
|
||||||
|
if (connected) {
|
||||||
super.send(packet);
|
super.send(packet);
|
||||||
var bytes = PacketUtil.toBytes(packet);
|
var bytes = PacketUtil.toBytes(packet);
|
||||||
socket.send(bytes.getData());
|
socket.send(bytes.getData());
|
||||||
|
} else {
|
||||||
|
L.w("Connection", "closed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,22 @@ class NekoConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
|
|
||||||
public var socket(default, null):Socket;
|
public var socket(default, null):Socket;
|
||||||
|
|
||||||
|
private var sendQueue:Array<O>;
|
||||||
|
private var timer:Timer;
|
||||||
|
|
||||||
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(pushPacket);
|
||||||
|
sendQueue = [];
|
||||||
|
timer = new Timer(1);
|
||||||
|
timer.run = sendRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _send(packet:O):Void {
|
private function sendPacket(packet:O):Void {
|
||||||
try {
|
try {
|
||||||
var bytes = PacketUtil.toBytes(packet);
|
var bytes = PacketUtil.toBytes(packet);
|
||||||
socket.output.writeUInt16(bytes.length);
|
socket.output.writeUInt16(bytes.length);
|
||||||
@@ -26,4 +32,25 @@ class NekoConnection<O:Message, I:Message> extends BaseConnection<O, I> {
|
|||||||
L.e('Proto', 'Error send packet: ${packet}', error);
|
L.e('Proto', 'Error send packet: ${packet}', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function sendRun():Void {
|
||||||
|
if (sendQueue.length > 0) {
|
||||||
|
for (packet in sendQueue) {
|
||||||
|
sendPacket(packet);
|
||||||
|
}
|
||||||
|
sendQueue = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function pushPacket(packet:O):Void {
|
||||||
|
sendQueue.push(packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function disconnect():Void {
|
||||||
|
if (timer != null) {
|
||||||
|
timer.stop();
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
super.disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class NekoWSConnection<O:Message, I:Message> extends NekoConnection<O, I> {
|
|||||||
opened = false;
|
opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
override private function _send(packet:O):Void {
|
override private function sendPacket(packet:O):Void {
|
||||||
var data = PacketUtil.toBytes(packet);
|
var data = PacketUtil.toBytes(packet);
|
||||||
writeData(data, socket);
|
writeData(data, socket);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ typedef PlayerConfig = {
|
|||||||
@:optional var bonus:Float;
|
@:optional var bonus:Float;
|
||||||
@:optional var protect:Float;
|
@:optional var protect:Float;
|
||||||
@:optional var life:Int;
|
@:optional var life:Int;
|
||||||
@:optional var color:Color;
|
@:optional var color:Null<Int>;
|
||||||
@:optional var control:String;
|
@:optional var control:String;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ typedef TeamConfig = {
|
|||||||
@:optional var eagle:EagleConfig;
|
@:optional var eagle:EagleConfig;
|
||||||
@:optional var life:Int;
|
@:optional var life:Int;
|
||||||
@:optional var spawnInterval:Int;
|
@:optional var spawnInterval:Int;
|
||||||
@:optional var color:Color;
|
@:optional var color:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef GamePreset = {
|
typedef GamePreset = {
|
||||||
@@ -108,7 +108,7 @@ typedef LevelConfig = {
|
|||||||
typedef PlayerControl = {
|
typedef PlayerControl = {
|
||||||
var playerId:PlayerId;
|
var playerId:PlayerId;
|
||||||
var control:String;
|
var control:String;
|
||||||
@:optional var color:Color;
|
@:optional var color:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef ControlPreset = {
|
typedef ControlPreset = {
|
||||||
@@ -233,16 +233,16 @@ class Config {
|
|||||||
return playersMap.get(playerId);
|
return playersMap.get(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getColor(playerId:PlayerId):Color {
|
public function getColor(playerId:PlayerId):Null<Color> {
|
||||||
var player = getPlayer(playerId);
|
var player = getPlayer(playerId);
|
||||||
if (player != null && !player.color.zero) {
|
if (player != null && player.color != null) {
|
||||||
return player.color;
|
return player.color;
|
||||||
}
|
}
|
||||||
var team = getTeam(playerId.team);
|
var team = getTeam(playerId.team);
|
||||||
if (team != null) {
|
if (team != null) {
|
||||||
return team.color;
|
return team.color;
|
||||||
}
|
}
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPoint(teamId:TeamId, type:String, index:Int = -1):SpawnPoint {
|
public function getPoint(teamId:TeamId, type:String, index:Int = -1):SpawnPoint {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Eagle extends Entity {
|
|||||||
public var config(default, null):EagleConfig;
|
public var config(default, null):EagleConfig;
|
||||||
public var color(default, default):Color;
|
public var color(default, default):Color;
|
||||||
public var death(default, default):Bool;
|
public var death(default, default):Bool;
|
||||||
public var protect(default, null):Modificator;
|
public var protect(default, default):Bool;
|
||||||
|
|
||||||
public var score(get, null):Int;
|
public var score(get, null):Int;
|
||||||
|
|
||||||
@@ -20,15 +20,10 @@ class Eagle extends Entity {
|
|||||||
this.team = team;
|
this.team = team;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.death = false;
|
this.death = false;
|
||||||
this.protect = new Modificator(id);
|
this.protect = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function get_score():Int {
|
private inline function get_score():Int {
|
||||||
return config != null ? config.score : 0;
|
return config != null ? config.score : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function dispose() {
|
|
||||||
super.dispose();
|
|
||||||
protect.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,4 @@ class Entity {
|
|||||||
public function toString():String {
|
public function toString():String {
|
||||||
return '$type($id)';
|
return '$type($id)';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose() {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package ru.m.tankz.core;
|
|
||||||
|
|
||||||
import haxework.signal.Signal;
|
|
||||||
import ru.m.Timer;
|
|
||||||
|
|
||||||
class Modificator extends Signal2<Int, Bool> {
|
|
||||||
|
|
||||||
public var id(default, default):Int;
|
|
||||||
public var active(default, default):Bool;
|
|
||||||
private var timer:Timer;
|
|
||||||
|
|
||||||
public function new(id) {
|
|
||||||
super();
|
|
||||||
this.id = id;
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function connect(receiver:Int->Bool->Void):Void {
|
|
||||||
super.connect(receiver);
|
|
||||||
receiver(id, active);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function on(seconds:Float):Void {
|
|
||||||
off();
|
|
||||||
active = true;
|
|
||||||
timer = Timer.delay(off, Std.int(seconds * 1000));
|
|
||||||
emit(id, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function off():Void {
|
|
||||||
if (timer != null) {
|
|
||||||
timer.stop();
|
|
||||||
timer = null;
|
|
||||||
emit(id, false);
|
|
||||||
}
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,13 +12,13 @@ class Tank extends MobileEntity {
|
|||||||
public var color(default, default):Color;
|
public var color(default, default):Color;
|
||||||
public var hits(default, default):Int;
|
public var hits(default, default):Int;
|
||||||
public var bonus(default, default):Bool;
|
public var bonus(default, default):Bool;
|
||||||
public var protect(default, null):Modificator;
|
public var protect(default, default):Bool;
|
||||||
public var freezing(default, null):Modificator;
|
public var freezing(default, default):Bool;
|
||||||
|
|
||||||
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) {
|
public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) {
|
||||||
super(id, rect, config.speed, Direction.RIGHT);
|
super(id, rect, config.speed, Direction.RIGHT);
|
||||||
this.protect = new Modificator(id);
|
this.protect = false;
|
||||||
this.freezing = new Modificator(id);
|
this.freezing = false;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.layer = 1;
|
this.layer = 1;
|
||||||
@@ -35,14 +35,8 @@ class Tank extends MobileEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public function move(direction:Direction):Void {
|
override public function move(direction:Direction):Void {
|
||||||
if (!freezing.active) {
|
if (!freezing) {
|
||||||
super.move(direction);
|
super.move(direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function dispose() {
|
|
||||||
super.dispose();
|
|
||||||
protect.dispose();
|
|
||||||
freezing.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,10 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var map(default, null):LevelMap;
|
public var map(default, null):LevelMap;
|
||||||
|
public var ticker(default, null):ITicker;
|
||||||
public var allEntities(default, null):Map<Int, Entity>;
|
|
||||||
public var entities(default, null):Map<Int, Entity>;
|
public var entities(default, null):Map<Int, Entity>;
|
||||||
|
|
||||||
private var ticker:Ticker;
|
public var allEntities(default, null):Map<Int, Entity>;
|
||||||
|
|
||||||
public function new(config:Config) {
|
public function new(config:Config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -67,8 +66,7 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function update():Void {
|
public function update():Void {
|
||||||
if (!ticker.running) ticker.start();
|
var d:Float = ticker.tick();
|
||||||
var d:Float = ticker.passed;
|
|
||||||
|
|
||||||
for (ent in entities) if (Std.is(ent, MobileEntity)) {
|
for (ent in entities) if (Std.is(ent, MobileEntity)) {
|
||||||
var entityType:EntityType = EntityTypeResolver.of(ent);
|
var entityType:EntityType = EntityTypeResolver.of(ent);
|
||||||
@@ -138,9 +136,6 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
for (entity in allEntities) {
|
|
||||||
entity.dispose();
|
|
||||||
}
|
|
||||||
allEntities = new Map();
|
allEntities = new Map();
|
||||||
entities = new Map();
|
entities = new Map();
|
||||||
//map = null;
|
//map = null;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface IEngine {
|
|||||||
public var entities(default, null):Map<Int, Entity>;
|
public var entities(default, null):Map<Int, Entity>;
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var map(default, null):LevelMap;
|
public var map(default, null):LevelMap;
|
||||||
|
public var ticker(default, null):ITicker;
|
||||||
|
|
||||||
public var spawnSignal(default, null):Signal1<EntityType>;
|
public var spawnSignal(default, null):Signal1<EntityType>;
|
||||||
public var collisionSignal(default, null):Signal2<EntityType, EntityType>;
|
public var collisionSignal(default, null):Signal2<EntityType, EntityType>;
|
||||||
|
|||||||
11
src/common/haxe/ru/m/tankz/engine/ITicker.hx
Normal file
11
src/common/haxe/ru/m/tankz/engine/ITicker.hx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
|
interface ITicker {
|
||||||
|
public var time(get, null):Int;
|
||||||
|
public var running(default, null):Bool;
|
||||||
|
|
||||||
|
public function start():Void;
|
||||||
|
public function stop():Void;
|
||||||
|
public function tick():Int;
|
||||||
|
public function emit(f:Void->Void, delay:Int):Void;
|
||||||
|
}
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
package ru.m.tankz.engine;
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
class Ticker {
|
typedef Action = {
|
||||||
|
var time:Int;
|
||||||
|
var action:Void->Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ticker implements ITicker {
|
||||||
public var time(get, null):Int;
|
public var time(get, null):Int;
|
||||||
public var passed(get, null):Int;
|
|
||||||
public var running(default, null):Bool;
|
public var running(default, null):Bool;
|
||||||
|
|
||||||
private var begin:Int;
|
private var passed:Int;
|
||||||
private var last:Int;
|
private var last_tick:Int;
|
||||||
|
private var actions:Array<Action>;
|
||||||
|
|
||||||
private static var TIME = Timer.stamp();
|
private static var TIME = Timer.stamp();
|
||||||
|
|
||||||
@@ -15,13 +20,18 @@ class Ticker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
begin = 0;
|
passed = 0;
|
||||||
last = 0;
|
last_tick = 0;
|
||||||
running = false;
|
running = false;
|
||||||
|
actions = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_time():Int {
|
||||||
|
return passed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start():Void {
|
public function start():Void {
|
||||||
last = begin = now();
|
last_tick = now();
|
||||||
running = true;
|
running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +39,36 @@ class Ticker {
|
|||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_time():Int {
|
public function tick():Int {
|
||||||
return now() - begin;
|
if (!running) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_passed():Int {
|
|
||||||
var now = now();
|
var now = now();
|
||||||
var result = now - last;
|
var result = now - last_tick;
|
||||||
last = now;
|
last_tick = now;
|
||||||
|
passed += result;
|
||||||
|
if (actions.length > 0) {
|
||||||
|
runActions();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function runActions():Void {
|
||||||
|
var it = actions.iterator();
|
||||||
|
var action = it.next();
|
||||||
|
var i = 0;
|
||||||
|
while (action != null && time >= action.time) {
|
||||||
|
action.action();
|
||||||
|
i++;
|
||||||
|
action = it.next();
|
||||||
|
}
|
||||||
|
if (i > 0) {
|
||||||
|
actions = actions.slice(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function emit(action:Void->Void, delay:Int):Void {
|
||||||
|
actions.push({action:action, time:time+delay});
|
||||||
|
actions.sort(function(a, b) return a.time - b.time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,17 +44,14 @@ class EntityBuilder {
|
|||||||
return eagle;
|
return eagle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildTank(point:EntityPoint, playerId:PlayerId, type:TankType, color:Color, bonusOff:Bool = false):Tank {
|
public function buildTank(point:EntityPoint, playerId:PlayerId, type:TankType, color:Null<Color>, bonusOff:Bool = false):Tank {
|
||||||
var playerConfig = config.getPlayer(playerId);
|
var playerConfig = config.getPlayer(playerId);
|
||||||
var tankConfig = config.getTank(type);
|
var tankConfig = config.getTank(type);
|
||||||
var tank = new Tank(++entityId, buildRect(point, tankConfig.width, tankConfig.height), playerId, tankConfig);
|
var tank = new Tank(++entityId, buildRect(point, tankConfig.width, tankConfig.height), playerId, tankConfig);
|
||||||
tank.color = color.zero ? config.getColor(playerId) : color;
|
tank.color = color == null || color.zero ? config.getColor(playerId) : color;
|
||||||
if (!bonusOff) {
|
if (!bonusOff) {
|
||||||
tank.bonus = Math.random() < playerConfig.bonus;
|
tank.bonus = Math.random() < playerConfig.bonus;
|
||||||
}
|
}
|
||||||
if (playerConfig.protect > 0) {
|
|
||||||
tank.protect.on(playerConfig.protect);
|
|
||||||
}
|
|
||||||
return tank;
|
return tank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import ru.m.tankz.core.EntityType.EntityTypeResolver;
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Bullet;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
|
import ru.m.tankz.core.Entity;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
import ru.m.tankz.map.Brick;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.map.Brick;
|
||||||
import ru.m.tankz.map.LevelMap;
|
import ru.m.tankz.map.LevelMap;
|
||||||
|
|
||||||
class EventUtil {
|
class EventUtil {
|
||||||
@@ -20,15 +22,27 @@ class EventUtil {
|
|||||||
type: item.config.type,
|
type: item.config.type,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return GameEvent.SPAWN(BRICK(bricks));
|
return SPAWN(BRICK(bricks));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildCellsDestroyed(map:LevelMap):Array<GameEvent> {
|
||||||
|
var result = [];
|
||||||
|
for (brick in map.bricks) {
|
||||||
|
for (cell in brick.cells) {
|
||||||
|
if (cell.destroyed) {
|
||||||
|
result.push(DESTROY(CELL(brick.id, cell.cellX - brick.cellX * 2, cell.cellY - brick.cellY * 2, {tankId: -1})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function buildEagleSpawn(eagle:Eagle):GameEvent {
|
public static function buildEagleSpawn(eagle:Eagle):GameEvent {
|
||||||
return GameEvent.SPAWN(EAGLE(eagle.id, eagle.rect, eagle.team));
|
return SPAWN(EAGLE(eagle.id, eagle.rect, eagle.team));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function buildTankSpawn(tank:Tank):GameEvent {
|
public static function buildTankSpawn(tank:Tank):GameEvent {
|
||||||
return GameEvent.SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, {
|
return SPAWN(TANK(tank.id, tank.rect.clone(), tank.playerId, {
|
||||||
type:tank.config.type,
|
type:tank.config.type,
|
||||||
hits:tank.hits,
|
hits:tank.hits,
|
||||||
bonus:tank.bonus,
|
bonus:tank.bonus,
|
||||||
@@ -36,14 +50,22 @@ class EventUtil {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function buildBonusSpawn(bonus:Bonus):GameEvent {
|
||||||
|
return SPAWN(BONUS(bonus.id, bonus.rect.clone(), bonus.config.type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildBulletSpawn(bullet:Bullet):GameEvent {
|
||||||
|
return SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.piercing));
|
||||||
|
}
|
||||||
|
|
||||||
public static function buildMove(entity:Entity):GameEvent {
|
public static function buildMove(entity:Entity):GameEvent {
|
||||||
return switch EntityTypeResolver.of(entity) {
|
return switch EntityTypeResolver.of(entity) {
|
||||||
case EAGLE(eagle):
|
case EAGLE(eagle):
|
||||||
GameEvent.MOVE(EAGLE(entity.id, entity.rect.position));
|
MOVE(EAGLE(entity.id, entity.rect.position));
|
||||||
case TANK(tank):
|
case TANK(tank):
|
||||||
GameEvent.MOVE(TANK(entity.id, entity.rect.position));
|
MOVE(TANK(entity.id, entity.rect.position));
|
||||||
case BULLET(bullet):
|
case BULLET(bullet):
|
||||||
GameEvent.MOVE(BULLET(entity.id, entity.rect.position));
|
MOVE(BULLET(entity.id, entity.rect.position));
|
||||||
case _:
|
case _:
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import ru.m.tankz.Type;
|
|||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
public var engine(default, null):IEngine;
|
public var engine(default, null):IEngine;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
|
public var pause(default, set):Bool;
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
@@ -35,9 +36,20 @@ import ru.m.tankz.Type;
|
|||||||
this.teams = new Map();
|
this.teams = new Map();
|
||||||
this.config = configBundle.get(type);
|
this.config = configBundle.get(type);
|
||||||
this.controlFactory = new NoneControlFactory();
|
this.controlFactory = new NoneControlFactory();
|
||||||
|
this.pause = false;
|
||||||
connect(this);
|
connect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function set_pause(value:Bool):Bool {
|
||||||
|
if (pause != value) {
|
||||||
|
pause = value;
|
||||||
|
changePause(pause);
|
||||||
|
}
|
||||||
|
return pause;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function changePause(value:Bool):Void {}
|
||||||
|
|
||||||
private function applyPosition(entity:Entity, position:Position):Void {
|
private function applyPosition(entity:Entity, position:Position):Void {
|
||||||
entity.rect.center = new Point(position.x, position.y);
|
entity.rect.center = new Point(position.x, position.y);
|
||||||
if (position.direction != null) {
|
if (position.direction != null) {
|
||||||
@@ -86,7 +98,7 @@ import ru.m.tankz.Type;
|
|||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
for (player in team.players.iterator()) {
|
for (player in team.players.iterator()) {
|
||||||
var playerControl = controlsById.get(player.id);
|
var playerControl = controlsById.get(player.id);
|
||||||
if (playerControl != null && !playerControl.color.zero) {
|
if (playerControl != null && playerControl.color != null) {
|
||||||
player.state.color = playerControl.color;
|
player.state.color = playerControl.color;
|
||||||
}
|
}
|
||||||
var controlType:Controller = AController.fromString(playerControl != null ? playerControl.control : player.config.control);
|
var controlType:Controller = AController.fromString(playerControl != null ? playerControl.control : player.config.control);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import haxework.color.Color;
|
|
||||||
import ru.m.geom.Line;
|
import ru.m.geom.Line;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
@@ -27,6 +26,16 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
this.engine.connect(this);
|
this.engine.connect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override function changePause(value:Bool):Void {
|
||||||
|
if (engine != null) {
|
||||||
|
if (value) {
|
||||||
|
engine.ticker.stop();
|
||||||
|
} else {
|
||||||
|
engine.ticker.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function update():Void {
|
private function update():Void {
|
||||||
engine.update();
|
engine.update();
|
||||||
}
|
}
|
||||||
@@ -47,7 +56,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
team.spawner.runner = spawn;
|
team.spawner.runner = spawn;
|
||||||
for (player in team.players.iterator()) {
|
for (player in team.players.iterator()) {
|
||||||
if (team.tryRespawn(player.id)) {
|
if (team.tryRespawn(player.id)) {
|
||||||
team.spawner.push(player.id);
|
team.spawner.push(engine.ticker, player.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (team.config.eagle != null) {
|
if (team.config.eagle != null) {
|
||||||
@@ -55,7 +64,6 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
var eagle = builder.buildEagle(point, team.id);
|
var eagle = builder.buildEagle(point, team.id);
|
||||||
engine.spawn(eagle);
|
engine.spawn(eagle);
|
||||||
gameEventSignal.emit(EventUtil.buildEagleSpawn(eagle));
|
gameEventSignal.emit(EventUtil.buildEagleSpawn(eagle));
|
||||||
eagle.protect.connect(onEagleProtectChange);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
||||||
@@ -68,20 +76,36 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color);
|
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color);
|
||||||
engine.spawn(tank);
|
engine.spawn(tank);
|
||||||
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
||||||
tank.protect.connect(onTankProtectChange);
|
if (player.config.protect > 0) {
|
||||||
tank.freezing.connect(onTankFreezingChange);
|
protectTank(tank, player.config.protect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onEagleProtectChange(id:Int, state:Bool):Void {
|
private function protectEagle(eagle:Eagle, duration:Float):Void {
|
||||||
gameEventSignal.emit(CHANGE(EAGLE_PROTECT(id, state)));
|
eagle.protect = true;
|
||||||
|
gameEventSignal.emit(CHANGE(EAGLE_PROTECT(eagle.id, eagle.protect)));
|
||||||
|
engine.ticker.emit(function() {
|
||||||
|
eagle.protect = false;
|
||||||
|
gameEventSignal.emit(CHANGE(EAGLE_PROTECT(eagle.id, eagle.protect)));
|
||||||
|
}, Std.int(duration * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTankProtectChange(id:Int, state:Bool):Void {
|
private function protectTank(tank:Tank, duration:Float):Void {
|
||||||
gameEventSignal.emit(CHANGE(TANK_PROTECT(id, state)));
|
tank.protect = true;
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_PROTECT(tank.id, tank.protect)));
|
||||||
|
engine.ticker.emit(function() {
|
||||||
|
tank.protect = false;
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_PROTECT(tank.id, tank.protect)));
|
||||||
|
}, Std.int(duration * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTankFreezingChange(id:Int, state:Bool):Void {
|
private function freezeTank(tank:Tank, duration:Float):Void {
|
||||||
gameEventSignal.emit(CHANGE(TANK_FREEZE(id, state)));
|
tank.freezing = true;
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
||||||
|
engine.ticker.emit(function() {
|
||||||
|
tank.freezing = false;
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
||||||
|
}, Std.int(duration * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkComplete():Void {
|
private function checkComplete():Void {
|
||||||
@@ -168,7 +192,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
if (bullet.tankId == tank.id || (!config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) {
|
if (bullet.tankId == tank.id || (!config.game.friendlyFire && tank.playerId.team == bullet.playerId.team)) {
|
||||||
// Nothing
|
// Nothing
|
||||||
} else {
|
} else {
|
||||||
if (!tank.protect.active) {
|
if (!tank.protect) {
|
||||||
if (tank.hits > 0) {
|
if (tank.hits > 0) {
|
||||||
tank.hits--;
|
tank.hits--;
|
||||||
if (tank.bonus) {
|
if (tank.bonus) {
|
||||||
@@ -192,7 +216,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
gameEventSignal.emit(DESTROY(BULLET(bullet.id)));
|
gameEventSignal.emit(DESTROY(BULLET(bullet.id)));
|
||||||
}
|
}
|
||||||
case [BULLET(bullet), EAGLE(eagle)]:
|
case [BULLET(bullet), EAGLE(eagle)]:
|
||||||
if (!eagle.protect.active) {
|
if (!eagle.protect) {
|
||||||
gameEventSignal.emit(DESTROY(EAGLE(eagle.id, buildShot(bullet, eagle.score))));
|
gameEventSignal.emit(DESTROY(EAGLE(eagle.id, buildShot(bullet, eagle.score))));
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(DESTROY(BULLET(bullet.id)));
|
gameEventSignal.emit(DESTROY(BULLET(bullet.id)));
|
||||||
@@ -222,7 +246,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
var bonus = builder.buildBonus(point, type);
|
var bonus = builder.buildBonus(point, type);
|
||||||
engine.spawn(bonus);
|
engine.spawn(bonus);
|
||||||
gameEventSignal.emit(SPAWN(BONUS(bonus.id, bonus.rect.clone(), bonus.config.type)));
|
gameEventSignal.emit(EventUtil.buildBonusSpawn(bonus));
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function alienTank(team:TeamId):Tank->Bool {
|
private inline function alienTank(team:TeamId):Tank->Bool {
|
||||||
@@ -240,10 +264,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
gameEventSignal.emit(DESTROY(TANK(t.id, {tankId: tank.id})));
|
gameEventSignal.emit(DESTROY(TANK(t.id, {tankId: tank.id})));
|
||||||
}
|
}
|
||||||
case "helmet":
|
case "helmet":
|
||||||
tank.protect.on(bonus.config.duration);
|
protectTank(tank, bonus.config.duration);
|
||||||
case "clock":
|
case "clock":
|
||||||
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
||||||
t.freezing.on(bonus.config.duration);
|
freezeTank(t, bonus.config.duration);
|
||||||
t.stop();
|
t.stop();
|
||||||
gameEventSignal.emit(STOP(TANK(t.id)));
|
gameEventSignal.emit(STOP(TANK(t.id)));
|
||||||
}
|
}
|
||||||
@@ -252,7 +276,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
var team:Team = teams[tank.playerId.team];
|
var team:Team = teams[tank.playerId.team];
|
||||||
if (team.eagleId > 0) {
|
if (team.eagleId > 0) {
|
||||||
var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
|
var eagle:Eagle = cast(engine.entities[team.eagleId], Eagle);
|
||||||
eagle.protect.on(bonus.config.duration);
|
protectEagle(eagle, bonus.config.duration);
|
||||||
}
|
}
|
||||||
case "gun":
|
case "gun":
|
||||||
upgradeTank(tank, 5);
|
upgradeTank(tank, 5);
|
||||||
@@ -293,12 +317,20 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public function onGameEvent(event:GameEvent):Void {
|
override public function onGameEvent(event:GameEvent):Void {
|
||||||
|
if (pause) {
|
||||||
|
switch event {
|
||||||
|
case ACTION(_): return;
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
super.onGameEvent(event);
|
super.onGameEvent(event);
|
||||||
switch event {
|
switch event {
|
||||||
case START(_):
|
case START(_):
|
||||||
|
engine.ticker.start();
|
||||||
timer = new Timer(30);
|
timer = new Timer(30);
|
||||||
timer.run = update;
|
timer.run = update;
|
||||||
case COMPLETE(_, _):
|
case COMPLETE(_, _):
|
||||||
|
engine.ticker.stop();
|
||||||
if (timer != null) {
|
if (timer != null) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
timer = null;
|
timer = null;
|
||||||
@@ -306,14 +338,14 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
case ACTION(tankId, SHOT):
|
case ACTION(tankId, SHOT):
|
||||||
var tank:Tank = cast engine.entities.get(tankId);
|
var tank:Tank = cast engine.entities.get(tankId);
|
||||||
var player = getPlayer(tank.playerId);
|
var player = getPlayer(tank.playerId);
|
||||||
if (!tank.freezing.active && player.bullets < tank.config.bullets) {
|
if (!tank.freezing && player.bullets < tank.config.bullets) {
|
||||||
var rect = tank.rect;
|
var rect = tank.rect;
|
||||||
var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
|
var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y));
|
||||||
var bullet = builder.buildBullet(point, rect.direction, player.id, tank.config.type);
|
var bullet = builder.buildBullet(point, rect.direction, player.id, tank.config.type);
|
||||||
bullet.tank = tank;
|
bullet.tank = tank;
|
||||||
bullet.move(bullet.rect.direction);
|
bullet.move(bullet.rect.direction);
|
||||||
engine.spawn(bullet);
|
engine.spawn(bullet);
|
||||||
gameEventSignal.emit(SPAWN(BULLET(bullet.id, bullet.rect.clone(), bullet.playerId, bullet.config.piercing)));
|
gameEventSignal.emit(EventUtil.buildBulletSpawn(bullet));
|
||||||
}
|
}
|
||||||
case ACTION(tankId, MOVE(direction)):
|
case ACTION(tankId, MOVE(direction)):
|
||||||
engine.move(tankId, direction);
|
engine.move(tankId, direction);
|
||||||
@@ -351,7 +383,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
var respawn:Bool = team.tryRespawn(player.id);
|
var respawn:Bool = team.tryRespawn(player.id);
|
||||||
if (respawn) {
|
if (respawn) {
|
||||||
team.spawner.push(player.id);
|
team.spawner.push(engine.ticker, player.id);
|
||||||
}
|
}
|
||||||
if (!team.isAlive) {
|
if (!team.isAlive) {
|
||||||
checkComplete();
|
checkComplete();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface IGame extends GameListener {
|
|||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
|
public var pause(default, set):Bool;
|
||||||
|
|
||||||
public var gameEventSignal(default, null):Signal<GameEvent>;
|
public var gameEventSignal(default, null):Signal<GameEvent>;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.engine.ITicker;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.Timer;
|
|
||||||
|
|
||||||
typedef SpawnTask = {
|
typedef SpawnTask = {
|
||||||
var point:SpawnPoint;
|
var point:SpawnPoint;
|
||||||
@@ -18,7 +18,6 @@ class Spawner {
|
|||||||
private var config:TeamConfig;
|
private var config:TeamConfig;
|
||||||
private var points:Array<SpawnPoint>;
|
private var points:Array<SpawnPoint>;
|
||||||
private var queue:Array<SpawnTask>;
|
private var queue:Array<SpawnTask>;
|
||||||
private var timer:Timer;
|
|
||||||
|
|
||||||
private var indexedPoints:Map<Int, SpawnPoint>;
|
private var indexedPoints:Map<Int, SpawnPoint>;
|
||||||
private var anyPoints:Array<SpawnPoint>;
|
private var anyPoints:Array<SpawnPoint>;
|
||||||
@@ -61,7 +60,7 @@ class Spawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function push(playerId:PlayerId):Void {
|
public function push(ticker:ITicker, playerId:PlayerId):Void {
|
||||||
var point:SpawnPoint = null;
|
var point:SpawnPoint = null;
|
||||||
if (indexedPoints.exists(playerId.index)) {
|
if (indexedPoints.exists(playerId.index)) {
|
||||||
point = indexedPoints.get(playerId.index);
|
point = indexedPoints.get(playerId.index);
|
||||||
@@ -71,24 +70,16 @@ class Spawner {
|
|||||||
}
|
}
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
queue.push({playerId:playerId, point:point, tankType:getPlayerTank(playerId)});
|
queue.push({playerId:playerId, point:point, tankType:getPlayerTank(playerId)});
|
||||||
run();
|
if (config.spawnInterval == null) {
|
||||||
|
ticker.emit(spawn, 500);
|
||||||
|
} else {
|
||||||
|
ticker.emit(spawn, 500 + config.spawnInterval * queue.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function run():Void {
|
|
||||||
if (timer == null) {
|
|
||||||
timer = new Timer(config.spawnInterval == null ? 500 : config.spawnInterval);
|
|
||||||
timer.run = spawn;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function spawn():Void {
|
private function spawn():Void {
|
||||||
if (queue.length == 0) {
|
if (queue.length > 0) {
|
||||||
if (timer != null) {
|
|
||||||
timer.stop();
|
|
||||||
timer = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
runner(queue.shift());
|
runner(queue.shift());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game.record;
|
package ru.m.tankz.game.record;
|
||||||
|
|
||||||
|
import ru.m.tankz.engine.ITicker;
|
||||||
import ru.m.tankz.engine.Ticker;
|
import ru.m.tankz.engine.Ticker;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ class GameRecorder implements GameListener {
|
|||||||
|
|
||||||
public var record(default, null):GameRecord;
|
public var record(default, null):GameRecord;
|
||||||
|
|
||||||
private var ticker:Ticker;
|
private var ticker:ITicker;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
ticker = new Ticker();
|
ticker = new Ticker();
|
||||||
@@ -15,10 +16,9 @@ class GameRecorder implements GameListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
if (!ticker.running) ticker.start();
|
|
||||||
record.events.push({time: ticker.time, event: event});
|
|
||||||
switch event {
|
switch event {
|
||||||
case GameEvent.START(state):
|
case GameEvent.START(state):
|
||||||
|
ticker.start();
|
||||||
record.info.type = state.type;
|
record.info.type = state.type;
|
||||||
record.info.presetId = state.presetId;
|
record.info.presetId = state.presetId;
|
||||||
record.info.levelId = state.levelId;
|
record.info.levelId = state.levelId;
|
||||||
@@ -27,5 +27,7 @@ class GameRecorder implements GameListener {
|
|||||||
ticker.stop();
|
ticker.stop();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
|
ticker.tick();
|
||||||
|
record.events.push({time: ticker.time, event: event});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,23 +7,9 @@ message UserProto {
|
|||||||
string name = 2;
|
string name = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GameStateProto {
|
|
||||||
READY = 0;
|
|
||||||
STARTED = 1;
|
|
||||||
ENDED = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message PlayerProto {
|
|
||||||
UserProto user = 1;
|
|
||||||
string team = 2;
|
|
||||||
int32 index = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GameProto {
|
message GameProto {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string type = 2;
|
string type = 2;
|
||||||
int32 level = 3;
|
int32 level = 3;
|
||||||
UserProto creator = 4;
|
bool started = 4;
|
||||||
repeated PlayerProto players = 5;
|
|
||||||
GameStateProto state = 6;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,3 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
package ru.m.tankz.proto.game;
|
package ru.m.tankz.proto.game;
|
||||||
|
|
||||||
|
|
||||||
enum GameActionTypeProto {
|
|
||||||
MOVE = 0;
|
|
||||||
SHOT = 1;
|
|
||||||
STOP = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum GameChangeTypeProto {
|
|
||||||
MOVED = 0;
|
|
||||||
DESTROED = 1;
|
|
||||||
MODIFIED = 2;
|
|
||||||
APPEND = 3;
|
|
||||||
DIRECTION = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GameChangeProto {
|
|
||||||
GameChangeTypeProto type = 1;
|
|
||||||
string entityType = 2;
|
|
||||||
int32 entityId = 3;
|
|
||||||
float x = 4;
|
|
||||||
float y = 5;
|
|
||||||
int32 directionX = 6;
|
|
||||||
int32 directionY = 7;
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,15 @@ syntax = "proto3";
|
|||||||
|
|
||||||
import "core.proto";
|
import "core.proto";
|
||||||
import "game.proto";
|
import "game.proto";
|
||||||
|
import "room.proto";
|
||||||
|
|
||||||
package ru.m.tankz.proto.pack;
|
package ru.m.tankz.proto.pack;
|
||||||
|
|
||||||
|
|
||||||
message ErrorResponse {
|
message ErrorResponse {
|
||||||
int32 code = 1;
|
int32 code = 1;
|
||||||
string message = 2;
|
string message = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login
|
|
||||||
message LoginRequest {
|
message LoginRequest {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
@@ -21,54 +20,10 @@ message LoginResponse {
|
|||||||
ru.m.tankz.proto.core.UserProto user = 1;
|
ru.m.tankz.proto.core.UserProto user = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout
|
|
||||||
message LogoutRequest {}
|
message LogoutRequest {}
|
||||||
|
|
||||||
message LogoutResponse {}
|
message LogoutResponse {}
|
||||||
|
|
||||||
// List Game
|
|
||||||
message ListGameRequest {}
|
|
||||||
|
|
||||||
message ListGameResponse {
|
|
||||||
repeated ru.m.tankz.proto.core.GameProto games = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Game
|
|
||||||
message CreateGameRequest {
|
|
||||||
string type = 1;
|
|
||||||
int32 level = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message CreateGameResponse {
|
|
||||||
ru.m.tankz.proto.core.GameProto game = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Join Game
|
|
||||||
message JoinGameRequest {
|
|
||||||
int32 game_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message JoinGameResponse {
|
|
||||||
ru.m.tankz.proto.core.GameProto game = 1;
|
|
||||||
ru.m.tankz.proto.core.UserProto user = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leave Game
|
|
||||||
message LeaveGameRequest {}
|
|
||||||
|
|
||||||
message LeaveGameResponse {
|
|
||||||
ru.m.tankz.proto.core.GameProto game = 1;
|
|
||||||
ru.m.tankz.proto.core.UserProto user = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start Game
|
|
||||||
message StartGameRequest {}
|
|
||||||
|
|
||||||
message StartGameResponse {
|
|
||||||
ru.m.tankz.proto.core.GameProto game = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Game
|
|
||||||
message GameEventRequest {
|
message GameEventRequest {
|
||||||
int32 time = 1;
|
int32 time = 1;
|
||||||
string event = 2;
|
string event = 2;
|
||||||
@@ -79,31 +34,23 @@ message GameEventResponse {
|
|||||||
string event = 2;
|
string event = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request
|
|
||||||
message Request {
|
message Request {
|
||||||
oneof content {
|
oneof content {
|
||||||
LoginRequest login = 1;
|
LoginRequest login = 1;
|
||||||
LogoutRequest logout = 2;
|
LogoutRequest logout = 2;
|
||||||
ListGameRequest listGame = 3;
|
ru.m.tankz.proto.room.RoomRequest room = 3;
|
||||||
CreateGameRequest createGame = 4;
|
ru.m.tankz.proto.room.RoomListRequest roomList = 4;
|
||||||
JoinGameRequest joinGame = 5;
|
GameEventRequest gameEvent = 6;
|
||||||
LeaveGameRequest leaveGame = 6;
|
|
||||||
StartGameRequest startGame = 7;
|
|
||||||
GameEventRequest gameEvent = 8;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response
|
|
||||||
message Response {
|
message Response {
|
||||||
oneof content {
|
oneof content {
|
||||||
LoginResponse login = 1;
|
LoginResponse login = 1;
|
||||||
LogoutResponse logout = 2;
|
LogoutResponse logout = 2;
|
||||||
ListGameResponse listGame = 3;
|
ru.m.tankz.proto.room.RoomResponse room = 3;
|
||||||
CreateGameResponse createGame = 4;
|
ru.m.tankz.proto.room.RoomListResponse roomList = 4;
|
||||||
JoinGameResponse joinGame = 5;
|
GameEventResponse gameEvent = 6;
|
||||||
LeaveGameResponse leaveGame = 6;
|
|
||||||
StartGameResponse startGame = 7;
|
|
||||||
GameEventResponse gameEvent = 8;
|
|
||||||
|
|
||||||
ErrorResponse error = 999;
|
ErrorResponse error = 999;
|
||||||
}
|
}
|
||||||
|
|||||||
64
src/common/proto/room.proto
Normal file
64
src/common/proto/room.proto
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
import "core.proto";
|
||||||
|
|
||||||
|
package ru.m.tankz.proto.room;
|
||||||
|
|
||||||
|
message SlotProto {
|
||||||
|
string team = 3;
|
||||||
|
int32 index = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomSlotProto {
|
||||||
|
SlotProto slot = 1;
|
||||||
|
ru.m.tankz.proto.core.UserProto user = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomProto {
|
||||||
|
ru.m.tankz.proto.core.GameProto game = 1;
|
||||||
|
ru.m.tankz.proto.core.UserProto creator = 2;
|
||||||
|
repeated ru.m.tankz.proto.core.UserProto users = 3;
|
||||||
|
repeated RoomSlotProto slots = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateRequest {
|
||||||
|
string type = 2;
|
||||||
|
int32 level = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message JoinRequest {
|
||||||
|
int32 gameId = 1;
|
||||||
|
bool restore = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LeaveRequest {
|
||||||
|
}
|
||||||
|
|
||||||
|
message SlotRequest {
|
||||||
|
SlotProto slot = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message StartRequest {
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomRequest {
|
||||||
|
oneof content {
|
||||||
|
CreateRequest create = 1;
|
||||||
|
JoinRequest join = 2;
|
||||||
|
LeaveRequest leave = 3;
|
||||||
|
SlotRequest slot = 4;
|
||||||
|
StartRequest start = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomResponse {
|
||||||
|
RoomProto room = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomListRequest {
|
||||||
|
bool subscribe = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RoomListResponse {
|
||||||
|
repeated RoomProto rooms = 1;
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.PlayerControl;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.IGame.GameListener;
|
import ru.m.tankz.game.IGame.GameListener;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
import ru.m.tankz.proto.core.GameProto;
|
||||||
import ru.m.tankz.proto.core.GameStateProto;
|
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.server.game.IGameManager;
|
import ru.m.tankz.server.game.IGameManager;
|
||||||
|
|
||||||
@@ -21,7 +24,7 @@ class _GameListener implements GameListener {
|
|||||||
dispatcher.dispatchEvent(game, event);
|
dispatcher.dispatchEvent(game, event);
|
||||||
switch event {
|
switch event {
|
||||||
case COMPLETE(_, _):
|
case COMPLETE(_, _):
|
||||||
dispatcher.delete(game.proto.id);
|
dispatcher.delete(game.id);
|
||||||
dispose();
|
dispose();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
@@ -52,26 +55,36 @@ class _GameListener implements GameListener {
|
|||||||
|
|
||||||
public function create(user:UserProto, type:String, level:Int):ServerGame {
|
public function create(user:UserProto, type:String, level:Int):ServerGame {
|
||||||
if (gamesByCreator.exists(user.uuid)) {
|
if (gamesByCreator.exists(user.uuid)) {
|
||||||
delete(gamesByCreator[user.uuid].proto.id);
|
delete(gamesByCreator[user.uuid].id);
|
||||||
}
|
}
|
||||||
var proto = new GameProto()
|
var room = new RoomProto()
|
||||||
|
.setGame(
|
||||||
|
new GameProto()
|
||||||
.setId(++counter)
|
.setId(++counter)
|
||||||
.setCreator(user)
|
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.setLevel(level);
|
.setLevel(level)
|
||||||
var game = new ServerGame(proto);
|
)
|
||||||
game.joinUser(user);
|
.setCreator(user);
|
||||||
|
var game = new ServerGame(room);
|
||||||
|
var slots:Array<RoomSlotProto> = [];
|
||||||
|
for (team in game.state.teams) {
|
||||||
|
for (player in team.players) {
|
||||||
|
slots.push(new RoomSlotProto().setSlot(new SlotProto().setTeam(player.id.team).setIndex(player.id.index)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
game.room.setSlots(slots);
|
||||||
games.push(game);
|
games.push(game);
|
||||||
gamesById[game.proto.id] = game;
|
gamesById[game.id] = game;
|
||||||
gamesByCreator[game.proto.creator.uuid] = game;
|
gamesByCreator[game.room.creator.uuid] = game;
|
||||||
createSignal.emit(game);
|
createSignal.emit(game);
|
||||||
|
join(game.id, user);
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function join(gameId:Int, user:UserProto):Void {
|
public function join(gameId:Int, user:UserProto):Void {
|
||||||
if (gamesById.exists(gameId)) {
|
if (gamesById.exists(gameId)) {
|
||||||
var game = gamesById[gameId];
|
var game = gamesById[gameId];
|
||||||
game.joinUser(user);
|
game.join(user);
|
||||||
gamesByUser[user.uuid] = game;
|
gamesByUser[user.uuid] = game;
|
||||||
changeSignal.emit(game, JOIN(user));
|
changeSignal.emit(game, JOIN(user));
|
||||||
}
|
}
|
||||||
@@ -81,26 +94,35 @@ class _GameListener implements GameListener {
|
|||||||
if (gamesById.exists(gameId)) {
|
if (gamesById.exists(gameId)) {
|
||||||
var game = gamesById[gameId];
|
var game = gamesById[gameId];
|
||||||
games.remove(game);
|
games.remove(game);
|
||||||
gamesById.remove(game.proto.id);
|
gamesById.remove(game.id);
|
||||||
gamesByCreator.remove(game.proto.creator.uuid);
|
gamesByCreator.remove(game.room.creator.uuid);
|
||||||
deleteSignal.emit(game);
|
deleteSignal.emit(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(user:UserProto):Void {
|
public function leave(user:UserProto):Void {
|
||||||
if (gamesByCreator.exists(user.uuid)) {
|
/*if (gamesByCreator.exists(user.uuid)) {
|
||||||
delete(gamesByCreator[user.uuid].proto.id);
|
delete(gamesByCreator[user.uuid].proto.id);
|
||||||
} else if (gamesByUser.exists(user.uuid)) {
|
} else*/ if (gamesByUser.exists(user.uuid)) {
|
||||||
var game = gamesByUser[user.uuid];
|
var game = gamesByUser[user.uuid];
|
||||||
game.leaveUser(user);
|
gamesByUser.remove(user.uuid);
|
||||||
|
game.leave(user);
|
||||||
changeSignal.emit(game, LEAVE(user));
|
changeSignal.emit(game, LEAVE(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function slot(user:UserProto, slot:SlotProto):Void {
|
||||||
|
if (gamesByUser.exists(user.uuid)) {
|
||||||
|
var game = gamesByUser[user.uuid];
|
||||||
|
game.slot(user, slot);
|
||||||
|
changeSignal.emit(game, SLOT(user, slot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function start(gameId:Int):Void {
|
public function start(gameId:Int):Void {
|
||||||
if (gamesById.exists(gameId)) {
|
if (gamesById.exists(gameId)) {
|
||||||
var game:ServerGame = gamesById[gameId];
|
var game:ServerGame = gamesById[gameId];
|
||||||
game.proto.setState(GameStateProto.STARTED);
|
game.room.game.setStarted(true);
|
||||||
changeSignal.emit(game, START);
|
changeSignal.emit(game, START);
|
||||||
game.connect(new _GameListener(game, this));
|
game.connect(new _GameListener(game, this));
|
||||||
game.start();
|
game.start();
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
|
|
||||||
enum GameChange {
|
enum GameChange {
|
||||||
JOIN(user:UserProto);
|
JOIN(user:UserProto);
|
||||||
LEAVE(user:UserProto);
|
LEAVE(user:UserProto);
|
||||||
|
SLOT(user:UserProto, slot:SlotProto);
|
||||||
START();
|
START();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +37,7 @@ interface IGameManager {
|
|||||||
public function create(user:UserProto, type:String, level:Int):ServerGame;
|
public function create(user:UserProto, type:String, level:Int):ServerGame;
|
||||||
public function delete(gameId:Int):Void;
|
public function delete(gameId:Int):Void;
|
||||||
public function join(gameId:Int, user:UserProto):Void;
|
public function join(gameId:Int, user:UserProto):Void;
|
||||||
|
public function slot(user:UserProto, slot:SlotProto):Void;
|
||||||
public function leave(user:UserProto):Void;
|
public function leave(user:UserProto):Void;
|
||||||
public function start(gameId:Int):Void;
|
public function start(gameId:Int):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,87 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.game.EventUtil;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameRunner;
|
import ru.m.tankz.game.GameRunner;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
import ru.m.tankz.proto.core.PlayerProto;
|
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
import ru.m.tankz.server.control.ServerControlFactory;
|
import ru.m.tankz.server.control.ServerControlFactory;
|
||||||
|
|
||||||
class ServerGame extends GameRunner {
|
class ServerGame extends GameRunner {
|
||||||
|
|
||||||
public var runner(default, null):GameRunner;
|
public var runner(default, null):GameRunner;
|
||||||
public var proto(default, null):GameProto;
|
public var room(default, null):RoomProto;
|
||||||
|
public var id(get, null):Int;
|
||||||
|
|
||||||
public function new(proto:GameProto) {
|
public function new(room:RoomProto) {
|
||||||
super(new GameState(proto.type, 0, proto.level));
|
super(new GameState(room.game.type, 0, room.game.level));
|
||||||
this.controlFactory = new ServerControlFactory();
|
this.controlFactory = new ServerControlFactory();
|
||||||
this.proto = proto;
|
this.room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function joinUser(user:UserProto):Void {
|
private inline function get_id():Int {
|
||||||
var index = proto.players.length;
|
return room.game.id;
|
||||||
var teamId = "human"; // ToDo:
|
|
||||||
proto.players.push(new PlayerProto().setUser(user).setTeam(teamId).setIndex(index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leaveUser(user:UserProto):Void {
|
public function join(user:UserProto):Void {
|
||||||
proto.setPlayers(proto.players.filter(function(player) return player.user.uuid != user.uuid));
|
leave(user);
|
||||||
|
room.users.push(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function slot(user:UserProto, slot:SlotProto):Void {
|
||||||
|
for (s in room.slots) {
|
||||||
|
if (s.hasUser() && s.user.uuid == user.uuid) {
|
||||||
|
s.clearUser();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (s in room.slots) {
|
||||||
|
if (s.slot.team == slot.team && s.slot.index == slot.index) {
|
||||||
|
s.setUser(user);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leave(user:UserProto):Void {
|
||||||
|
for (slot in room.slots) {
|
||||||
|
if (slot.user != null && slot.user.uuid == user.uuid) {
|
||||||
|
slot.clearUser();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
room.setUsers(room.users.filter(function(u:UserProto) return u.uuid != user.uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
state.controls = proto.players.map(function(player):PlayerControl return {
|
state.controls = room.slots
|
||||||
playerId: [player.team, player.index],
|
.filter(function(slot:RoomSlotProto) return slot.hasUser())
|
||||||
control: 'human-0'
|
.map(function(slot:RoomSlotProto):PlayerControl return {
|
||||||
|
playerId: [slot.slot.team, slot.slot.index],
|
||||||
|
control: "human-0",
|
||||||
});
|
});
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function restore():Array<GameEvent> {
|
||||||
|
var result = [];
|
||||||
|
result.push(EventUtil.buildBricksSpawn(engine.map));
|
||||||
|
result = result.concat(EventUtil.buildCellsDestroyed(engine.map));
|
||||||
|
for (entity in engine.entities) {
|
||||||
|
switch EntityTypeResolver.of(entity) {
|
||||||
|
case EAGLE(eagle): result.push(EventUtil.buildEagleSpawn(eagle));
|
||||||
|
case TANK(tank): result.push(EventUtil.buildTankSpawn(tank));
|
||||||
|
case BONUS(bonus): result.push(EventUtil.buildBonusSpawn(bonus));
|
||||||
|
case BULLET(bullet): result.push(EventUtil.buildBulletSpawn(bullet));
|
||||||
|
case CELL(_):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push(START(state));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,20 @@
|
|||||||
package ru.m.tankz.server.session;
|
package ru.m.tankz.server.session;
|
||||||
|
|
||||||
import haxe.Unserializer;
|
|
||||||
import haxe.Serializer;
|
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import com.hurlant.crypto.extra.UUID;
|
import com.hurlant.crypto.extra.UUID;
|
||||||
import com.hurlant.crypto.prng.Random;
|
import com.hurlant.crypto.prng.Random;
|
||||||
|
import haxe.Serializer;
|
||||||
|
import haxe.Unserializer;
|
||||||
import haxework.log.BaseLogger.LoggerUtil;
|
import haxework.log.BaseLogger.LoggerUtil;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.proto.pack.CreateGameResponse;
|
|
||||||
import ru.m.tankz.proto.pack.ErrorResponse;
|
import ru.m.tankz.proto.pack.ErrorResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
|
||||||
import ru.m.tankz.proto.pack.ListGameResponse;
|
|
||||||
import ru.m.tankz.proto.pack.LoginResponse;
|
import ru.m.tankz.proto.pack.LoginResponse;
|
||||||
import ru.m.tankz.proto.pack.LogoutResponse;
|
import ru.m.tankz.proto.pack.LogoutResponse;
|
||||||
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 ru.m.tankz.proto.pack.StartGameResponse;
|
import ru.m.tankz.proto.room.RoomListResponse;
|
||||||
|
import ru.m.tankz.proto.room.RoomResponse;
|
||||||
import ru.m.tankz.server.game.IGameManager;
|
import ru.m.tankz.server.game.IGameManager;
|
||||||
import ru.m.tankz.server.game.ServerGame;
|
import ru.m.tankz.server.game.ServerGame;
|
||||||
import sys.net.Socket;
|
import sys.net.Socket;
|
||||||
@@ -30,6 +27,7 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
public var user(default, null):UserProto;
|
public var user(default, null):UserProto;
|
||||||
public var gameId(default, null):Int;
|
public var gameId(default, null):Int;
|
||||||
|
|
||||||
|
private var subscribed:Bool;
|
||||||
private var tag(get, never):String;
|
private var tag(get, never):String;
|
||||||
|
|
||||||
private function get_tag():String {
|
private function get_tag():String {
|
||||||
@@ -45,9 +43,9 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
send(new Response().setError(new ErrorResponse().setCode(code).setMessage(message)));
|
send(new Response().setError(new ErrorResponse().setCode(code).setMessage(message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function listGame():ListGameResponse {
|
private function listGame():RoomListResponse {
|
||||||
var games = gameManager.games;
|
var games = gameManager.games;
|
||||||
return new ListGameResponse().setGames([for (game in games) game.proto]);
|
return new RoomListResponse().setRooms([for (game in games) game.room]);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function send(packet:Response):Void {
|
override public function send(packet:Response):Void {
|
||||||
@@ -85,24 +83,34 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
} else if (request.hasLogout()) {
|
} else if (request.hasLogout()) {
|
||||||
logout();
|
logout();
|
||||||
send(new Response().setLogout(new LogoutResponse()));
|
send(new Response().setLogout(new LogoutResponse()));
|
||||||
// create
|
// room
|
||||||
} else if (request.hasCreateGame()) {
|
} else if (request.hasRoom()) {
|
||||||
var game = gameManager.create(user, request.createGame.type, request.createGame.level);
|
if (request.room.hasCreate()) {
|
||||||
gameId = game.proto.id;
|
var game = gameManager.create(user, request.room.create.type, request.room.create.level);
|
||||||
send(new Response().setCreateGame(new CreateGameResponse().setGame(game.proto)));
|
gameId = game.id;
|
||||||
// list
|
send(new Response().setRoom(new RoomResponse().setRoom(game.room)));
|
||||||
} else if (request.hasListGame()) {
|
} else if (request.room.hasJoin()) {
|
||||||
send(new Response().setListGame(listGame()));
|
gameId = request.room.join.gameId;
|
||||||
// join
|
gameManager.join(gameId, user);
|
||||||
} else if (request.hasJoinGame()) {
|
var game = gameManager.gamesById[gameId];
|
||||||
gameId = request.joinGame.gameId;
|
if (request.room.join.restore && game.room.game.started) {
|
||||||
gameManager.join(request.joinGame.gameId, user);
|
for (event in game.restore()) {
|
||||||
// leave
|
send(new Response().setGameEvent(new GameEventResponse().setTime(0).setEvent(Serializer.run(event))));
|
||||||
} else if (request.hasLeaveGame()) {
|
}
|
||||||
|
}
|
||||||
|
} else if (request.room.hasLeave()) {
|
||||||
gameManager.leave(user);
|
gameManager.leave(user);
|
||||||
// start
|
} else if (request.room.hasSlot()) {
|
||||||
} else if (request.hasStartGame()) {
|
gameManager.slot(user, request.room.slot.slot);
|
||||||
|
} else if (request.room.hasStart()) {
|
||||||
gameManager.start(gameId);
|
gameManager.start(gameId);
|
||||||
|
}
|
||||||
|
// room list
|
||||||
|
} else if (request.hasRoomList()) {
|
||||||
|
subscribed = request.roomList.subscribe;
|
||||||
|
if (subscribed) {
|
||||||
|
send(new Response().setRoomList(listGame()));
|
||||||
|
}
|
||||||
} else if (request.hasGameEvent()) {
|
} else if (request.hasGameEvent()) {
|
||||||
if (gameManager.gamesById.exists(gameId)) {
|
if (gameManager.gamesById.exists(gameId)) {
|
||||||
var event:GameEvent = Unserializer.run(request.gameEvent.event);
|
var event:GameEvent = Unserializer.run(request.gameEvent.event);
|
||||||
@@ -122,44 +130,41 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onCreate(game:ServerGame):Void {
|
public function onCreate(game:ServerGame):Void {
|
||||||
if (gameId == -1) {
|
if (subscribed) {
|
||||||
send(new Response().setListGame(listGame()));
|
send(new Response().setRoomList(listGame()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChange(game:ServerGame, change:GameChange):Void {
|
public function onChange(game:ServerGame, change:GameChange):Void {
|
||||||
if (gameId == game.proto.id) {
|
if (gameId == game.id) {
|
||||||
switch change {
|
switch change {
|
||||||
case JOIN(user):
|
|
||||||
if (user.uuid == this.user.uuid) {
|
|
||||||
gameId = game.proto.id;
|
|
||||||
}
|
|
||||||
send(new Response().setJoinGame(new JoinGameResponse().setGame(game.proto).setUser(user)));
|
|
||||||
case LEAVE(user):
|
case LEAVE(user):
|
||||||
if (user.uuid == this.user.uuid) {
|
if (user.uuid == this.user.uuid) {
|
||||||
gameId = -1;
|
gameId = -1;
|
||||||
|
send(new Response().setRoom(new RoomResponse()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
send(new Response().setLeaveGame(new LeaveGameResponse().setGame(game.proto).setUser(user)));
|
case _:
|
||||||
case START:
|
|
||||||
send(new Response().setStartGame(new StartGameResponse().setGame(game.proto)));
|
|
||||||
}
|
}
|
||||||
} else {
|
send(new Response().setRoom(new RoomResponse().setRoom(game.room)));
|
||||||
// ToDo: change game event
|
}
|
||||||
send(new Response().setListGame(listGame()));
|
if (subscribed) {
|
||||||
|
send(new Response().setRoomList(listGame()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onDelete(game:ServerGame):Void {
|
public function onDelete(game:ServerGame):Void {
|
||||||
if (gameId == -1) {
|
if (gameId == game.id) {
|
||||||
send(new Response().setListGame(listGame()));
|
|
||||||
} else if (gameId == game.proto.id) {
|
|
||||||
gameId = -1;
|
gameId = -1;
|
||||||
send(new Response().setLeaveGame(new LeaveGameResponse().setGame(game.proto).setUser(user)));
|
send(new Response().setRoom(new RoomResponse()));
|
||||||
|
}
|
||||||
|
if (subscribed) {
|
||||||
|
send(new Response().setRoomList(listGame()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onEvent(game:ServerGame, event:GameEvent):Void {
|
public function onEvent(game:ServerGame, event:GameEvent):Void {
|
||||||
if (gameId == game.proto.id) {
|
if (gameId == game.id) {
|
||||||
send(new Response().setGameEvent(new GameEventResponse().setTime(0).setEvent(Serializer.run(event))));
|
send(new Response().setGameEvent(new GameEventResponse().setTime(0).setEvent(Serializer.run(event))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user