[common] refactor ControlFactory
This commit is contained in:
@@ -10,8 +10,6 @@ import ru.m.tankz.bundle.ConfigBundle;
|
|||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.bundle.LevelBundle;
|
import ru.m.tankz.bundle.LevelBundle;
|
||||||
import ru.m.tankz.control.ClientControlFactory;
|
|
||||||
import ru.m.tankz.control.IControlFactory;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
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;
|
||||||
@@ -32,7 +30,6 @@ class Init {
|
|||||||
@:provide static var recordStorage:RecordStorage;
|
@:provide static var recordStorage:RecordStorage;
|
||||||
@:provide static var soundManager:SoundManager;
|
@:provide static var soundManager:SoundManager;
|
||||||
@:provide static var networkManager:NetworkManager;
|
@:provide static var networkManager:NetworkManager;
|
||||||
@:provide static var controlFactory:IControlFactory;
|
|
||||||
@:provide static var popupManager:PopupManager;
|
@:provide static var popupManager:PopupManager;
|
||||||
@:provide static var connection:IConnection<Request, Response>;
|
@:provide static var connection:IConnection<Request, Response>;
|
||||||
|
|
||||||
@@ -58,7 +55,6 @@ class Init {
|
|||||||
gameStorage = new GameStorage();
|
gameStorage = new GameStorage();
|
||||||
recordStorage = new RecordStorage();
|
recordStorage = new RecordStorage();
|
||||||
soundManager = new SoundManager();
|
soundManager = new SoundManager();
|
||||||
controlFactory = new ClientControlFactory();
|
|
||||||
popupManager = new PopupManager();
|
popupManager = new PopupManager();
|
||||||
|
|
||||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ru.m.tankz.control;
|
|||||||
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class ClientControlFactory extends BaseControlFactory {
|
class LocalControlFactory extends BaseControlFactory {
|
||||||
|
|
||||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||||
return new HumanControl(id, index);
|
return new HumanControl(id, index);
|
||||||
@@ -3,11 +3,11 @@ package ru.m.tankz.control;
|
|||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
class ClientNetworkControl extends HumanControl {
|
class NetworkControl extends HumanControl {
|
||||||
|
|
||||||
@:provide private var network:NetworkManager;
|
@:provide private var network:NetworkManager;
|
||||||
|
|
||||||
override public function action(action:TankAction):Void {
|
override public function action(action:TankAction):Void {
|
||||||
network.action(action);
|
network.action(tankId, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
src/client/haxe/ru/m/tankz/control/NetworkControlFactory.hx
Normal file
10
src/client/haxe/ru/m/tankz/control/NetworkControlFactory.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class NetworkControlFactory extends BaseControlFactory {
|
||||||
|
|
||||||
|
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||||
|
return new NetworkControl(id, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/client/haxe/ru/m/tankz/game/LocalGame.hx
Normal file
28
src/client/haxe/ru/m/tankz/game/LocalGame.hx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.LocalControlFactory;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.record.GameRecorder;
|
||||||
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
|
class LocalGame extends GameRunner {
|
||||||
|
@:provide var recordStorage:RecordStorage;
|
||||||
|
private var recorder:GameRecorder;
|
||||||
|
|
||||||
|
public function new(state:GameState) {
|
||||||
|
super(state);
|
||||||
|
controlFactory = new LocalControlFactory();
|
||||||
|
recorder = new GameRecorder();
|
||||||
|
connect(recorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function onGameEvent(event:GameEvent):Void {
|
||||||
|
super.onGameEvent(event);
|
||||||
|
switch event {
|
||||||
|
case GameEvent.COMPLETE(_, _):
|
||||||
|
disconnect(recorder);
|
||||||
|
recordStorage.save(recorder.record);
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/client/haxe/ru/m/tankz/game/NetworkGame.hx
Normal file
33
src/client/haxe/ru/m/tankz/game/NetworkGame.hx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import haxe.Unserializer;
|
||||||
|
import ru.m.tankz.control.NetworkControlFactory;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
|
|
||||||
|
class NetworkGame extends Game {
|
||||||
|
|
||||||
|
private var network:NetworkManager;
|
||||||
|
|
||||||
|
public function new(network:NetworkManager) {
|
||||||
|
super(new GameState(network.game.type, 0, network.game.level));
|
||||||
|
this.network = network;
|
||||||
|
this.controlFactory = new NetworkControlFactory();
|
||||||
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameEventProto(game:GameEventResponse):Void {
|
||||||
|
var frame = game.frame;
|
||||||
|
var eventStr = game.event;
|
||||||
|
var event:GameEvent = Unserializer.run(eventStr);
|
||||||
|
gameEventSignal.emit(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function dispose():Void {
|
||||||
|
super.dispose();
|
||||||
|
network.gameEventSignal.disconnect(onGameEventProto);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package ru.m.tankz.network;
|
|
||||||
|
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
|
|
||||||
class NetworkGame extends Game {
|
|
||||||
|
|
||||||
private var network:NetworkManager;
|
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
|
||||||
super(new GameState(network.game.type, 0, network.game.level));
|
|
||||||
this.network = network;
|
|
||||||
network.gameSignal.connect(onGameChange);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameChange(game:GameProto):Void {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function dispose():Void {
|
|
||||||
super.dispose();
|
|
||||||
network.gameSignal.disconnect(onGameChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
import ru.m.tankz.game.IGame;
|
import haxe.Serializer;
|
||||||
import haxe.Unserializer;
|
|
||||||
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;
|
||||||
@@ -10,6 +9,8 @@ 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.game.GameChangeProto;
|
||||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||||
@@ -41,16 +42,17 @@ class NetworkManager {
|
|||||||
public var listGameSignal:Signal<Array<GameProto>>;
|
public var listGameSignal:Signal<Array<GameProto>>;
|
||||||
public var gameSignal:Signal<GameProto>;
|
public var gameSignal:Signal<GameProto>;
|
||||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
||||||
|
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;
|
||||||
@:provide private var _game:IGame;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
stateSignal = new Signal();
|
stateSignal = new Signal();
|
||||||
listGameSignal = new Signal();
|
listGameSignal = new Signal();
|
||||||
gameSignal = new Signal();
|
gameSignal = new Signal();
|
||||||
gameUpdateSignal = new Signal();
|
gameUpdateSignal = 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);
|
||||||
@@ -103,8 +105,10 @@ class NetworkManager {
|
|||||||
connection.send(new Request().setStartGame(new StartGameRequest()));
|
connection.send(new Request().setStartGame(new StartGameRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function action(action:TankAction):Void {
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
// ToDo: network
|
connection.send(new Request().setGameEvent(new GameEventRequest().setFrame(0).setEvent(
|
||||||
|
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
@@ -153,10 +157,7 @@ class NetworkManager {
|
|||||||
game = packet.startGame.game;
|
game = packet.startGame.game;
|
||||||
gameSignal.emit(game);
|
gameSignal.emit(game);
|
||||||
} else if (packet.hasGameEvent()) {
|
} else if (packet.hasGameEvent()) {
|
||||||
var frame = packet.gameEvent.frame;
|
gameEventSignal.emit(packet.gameEvent);
|
||||||
var eventStr = packet.gameEvent.event;
|
|
||||||
var event:GameEvent = Unserializer.run(eventStr);
|
|
||||||
_game.gameEventSignal.emit(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ import haxework.view.VGroupView;
|
|||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.game.record.GamePlayer;
|
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
import ru.m.tankz.game.record.GameRecorder;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.game.GameView;
|
import ru.m.tankz.view.game.GameView;
|
||||||
|
|
||||||
@@ -30,10 +27,8 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
@:provide("next") var nextState:GameState;
|
@:provide("next") var nextState:GameState;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var gameStorage:GameStorage;
|
@:provide var gameStorage:GameStorage;
|
||||||
@:provide var recordStorage:RecordStorage;
|
|
||||||
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
private var recorder:GameRecorder;
|
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
gameView.type = game.type;
|
gameView.type = game.type;
|
||||||
@@ -44,11 +39,6 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
if (gameView.panel != null) {
|
if (gameView.panel != null) {
|
||||||
game.connect(gameView.panel);
|
game.connect(gameView.panel);
|
||||||
}
|
}
|
||||||
// ToDo:
|
|
||||||
if (!Std.is(game, GamePlayer)) {
|
|
||||||
recorder = new GameRecorder();
|
|
||||||
game.connect(recorder);
|
|
||||||
}
|
|
||||||
game.connect(this);
|
game.connect(this);
|
||||||
game.start();
|
game.start();
|
||||||
}
|
}
|
||||||
@@ -64,10 +54,6 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case GameEvent.COMPLETE(state, winner):
|
case GameEvent.COMPLETE(state, winner):
|
||||||
// ToDo:
|
|
||||||
if (recorder != null) {
|
|
||||||
recordStorage.save(recorder.record);
|
|
||||||
}
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
nextState = switch next(winner) {
|
nextState = switch next(winner) {
|
||||||
case Some(s):
|
case Some(s):
|
||||||
@@ -100,7 +86,6 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
public function onHide():Void {
|
public function onHide():Void {
|
||||||
stop();
|
stop();
|
||||||
soundManager.stopAll();
|
soundManager.stopAll();
|
||||||
recorder = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close():Void {
|
public function close():Void {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import haxework.view.LabelView;
|
|||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameRunner;
|
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.game.LocalGame;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.popup.LevelPopup;
|
import ru.m.tankz.view.popup.LevelPopup;
|
||||||
@@ -36,7 +36,7 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
private function start(level:LevelConfig, preset:GamePreset):Void {
|
private function start(level:LevelConfig, preset:GamePreset):Void {
|
||||||
state.levelId = level.id;
|
state.levelId = level.id;
|
||||||
state.presetId = preset.id;
|
state.presetId = preset.id;
|
||||||
game = new GameRunner(state);
|
game = new LocalGame(state);
|
||||||
switcher.change(GameFrame.ID);
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import haxework.view.list.VListView;
|
|||||||
import haxework.view.TextView;
|
import haxework.view.TextView;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.network.NetworkGame;
|
import ru.m.tankz.game.NetworkGame;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
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.GameStateProto;
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import ru.m.geom.Point;
|
|||||||
import ru.m.geom.Position;
|
import ru.m.geom.Position;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.control.Controller;
|
||||||
|
import ru.m.tankz.control.IControlFactory;
|
||||||
|
import ru.m.tankz.control.NoneControlFactory;
|
||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
@@ -21,6 +25,8 @@ import ru.m.tankz.Type;
|
|||||||
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 frame(default, null):Int;
|
public var frame(default, null):Int;
|
||||||
|
public var engine(default, null):IEngine;
|
||||||
|
public var controlFactory(default, null):IControlFactory;
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
@@ -30,6 +36,7 @@ import ru.m.tankz.Type;
|
|||||||
this.teams = new Map();
|
this.teams = new Map();
|
||||||
this.config = configBundle.get(type);
|
this.config = configBundle.get(type);
|
||||||
this.frame = 0;
|
this.frame = 0;
|
||||||
|
this.controlFactory = new NoneControlFactory();
|
||||||
connect(this);
|
connect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +81,15 @@ import ru.m.tankz.Type;
|
|||||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||||
teams[team.id] = team;
|
teams[team.id] = team;
|
||||||
}
|
}
|
||||||
|
for (team in teams.iterator()) {
|
||||||
|
for (player in team.players.iterator()) {
|
||||||
|
var control = controlFactory.build(player.id, AController.fromString(player.config.control));
|
||||||
|
if (control != null) {
|
||||||
|
player.control = control;
|
||||||
|
player.control.bind(this, engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package ru.m.tankz.game;
|
|||||||
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;
|
||||||
import ru.m.tankz.control.Controller;
|
|
||||||
import ru.m.tankz.control.IControlFactory;
|
|
||||||
import ru.m.tankz.core.Bonus;
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Bullet;
|
import ru.m.tankz.core.Bullet;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
@@ -18,10 +16,6 @@ import ru.m.tankz.Type;
|
|||||||
import ru.m.Timer;
|
import ru.m.Timer;
|
||||||
|
|
||||||
class GameRunner extends Game implements EngineListener {
|
class GameRunner extends Game implements EngineListener {
|
||||||
@:provide var controlFactory:IControlFactory;
|
|
||||||
|
|
||||||
public var engine(default, null):IEngine;
|
|
||||||
|
|
||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
private var builder:EntityBuilder;
|
private var builder:EntityBuilder;
|
||||||
|
|
||||||
@@ -50,13 +44,6 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
super.start();
|
super.start();
|
||||||
engine.map.setData(state.level.data);
|
engine.map.setData(state.level.data);
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
for (player in team.players.iterator()) {
|
|
||||||
var control = controlFactory.build(player.id, AController.fromString(player.config.control));
|
|
||||||
if (control != null) {
|
|
||||||
player.control = control;
|
|
||||||
player.control.bind(this, engine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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)) {
|
||||||
@@ -120,8 +107,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
private function complete(winner:TeamId):Void {
|
private function complete(winner:TeamId):Void {
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
for (player in team.players) {
|
for (player in team.players) {
|
||||||
player.control.action(TankAction.STOP);
|
if (player.control != null) {
|
||||||
player.control.dispose();
|
player.control.action(TankAction.STOP);
|
||||||
|
player.control.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Timer.delay(function() {
|
Timer.delay(function() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ru.m.tankz.game;
|
|||||||
|
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.control.IControlFactory;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface IGame extends GameListener {
|
interface IGame extends GameListener {
|
||||||
@@ -11,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 frame(default, null):Int;
|
public var frame(default, null):Int;
|
||||||
|
public var controlFactory(default, null):IControlFactory;
|
||||||
|
|
||||||
public var gameEventSignal(default, null):Signal<GameEvent>;
|
public var gameEventSignal(default, null):Signal<GameEvent>;
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import haxework.provider.Provider;
|
|||||||
import neko.net.ThreadServer;
|
import neko.net.ThreadServer;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.control.IControlFactory;
|
|
||||||
import ru.m.tankz.server.bundle.ServerConfigBundle;
|
import ru.m.tankz.server.bundle.ServerConfigBundle;
|
||||||
import ru.m.tankz.server.bundle.ServerLevelBundle;
|
import ru.m.tankz.server.bundle.ServerLevelBundle;
|
||||||
import ru.m.tankz.server.control.ServerControlFactory;
|
|
||||||
import ru.m.tankz.server.game.GameManager;
|
import ru.m.tankz.server.game.GameManager;
|
||||||
import ru.m.tankz.server.game.IGameManager;
|
import ru.m.tankz.server.game.IGameManager;
|
||||||
import ru.m.tankz.server.session.GameSession;
|
import ru.m.tankz.server.session.GameSession;
|
||||||
@@ -50,7 +48,6 @@ class Server extends ThreadServer<GameSession, Bytes> {
|
|||||||
L.i(TAG, 'Build: ${CompilationOption.get("build")}');
|
L.i(TAG, 'Build: ${CompilationOption.get("build")}');
|
||||||
Provider.setFactory(IConfigBundle, ServerConfigBundle);
|
Provider.setFactory(IConfigBundle, ServerConfigBundle);
|
||||||
Provider.setFactory(ILevelBundle, ServerLevelBundle);
|
Provider.setFactory(ILevelBundle, ServerLevelBundle);
|
||||||
Provider.setFactory(IControlFactory, ServerControlFactory);
|
|
||||||
gameManager = new GameManager();
|
gameManager = new GameManager();
|
||||||
var host:String = Sys.args().length > 0 ? Sys.args()[0] : "0.0.0.0";
|
var host:String = Sys.args().length > 0 ? Sys.args()[0] : "0.0.0.0";
|
||||||
var port:Int = Sys.args().length > 1 ? Std.parseInt(Sys.args()[1]) : 5000;
|
var port:Int = Sys.args().length > 1 ? Std.parseInt(Sys.args()[1]) : 5000;
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
package ru.m.tankz.server.control;
|
package ru.m.tankz.server.control;
|
||||||
|
|
||||||
import ru.m.tankz.bot.HardBotControl;
|
|
||||||
import ru.m.tankz.control.BaseControlFactory;
|
import ru.m.tankz.control.BaseControlFactory;
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
import ru.m.tankz.Type.PlayerId;
|
|
||||||
|
|
||||||
class ServerControlFactory extends BaseControlFactory {
|
class ServerControlFactory extends BaseControlFactory {
|
||||||
|
|
||||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
|
||||||
return new HardBotControl(id); // ToDo:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.m.tankz.server.game;
|
|||||||
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.GameProto;
|
||||||
|
import ru.m.tankz.server.control.ServerControlFactory;
|
||||||
|
|
||||||
class ServerGame extends GameRunner {
|
class ServerGame extends GameRunner {
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ class ServerGame extends GameRunner {
|
|||||||
|
|
||||||
public function new(proto:GameProto) {
|
public function new(proto:GameProto) {
|
||||||
super(new GameState(proto.type, 0, proto.level));
|
super(new GameState(proto.type, 0, proto.level));
|
||||||
|
this.controlFactory = new ServerControlFactory();
|
||||||
this.proto = proto;
|
this.proto = proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.server.session;
|
package ru.m.tankz.server.session;
|
||||||
|
|
||||||
|
import haxe.Unserializer;
|
||||||
import haxe.Serializer;
|
import haxe.Serializer;
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
@@ -102,6 +103,11 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
// start
|
// start
|
||||||
} else if (request.hasStartGame()) {
|
} else if (request.hasStartGame()) {
|
||||||
gameManager.start(gameId);
|
gameManager.start(gameId);
|
||||||
|
} else if (request.hasGameEvent()) {
|
||||||
|
if (gameManager.gamesById.exists(gameId)) {
|
||||||
|
var event:GameEvent = Unserializer.run(request.gameEvent.event);
|
||||||
|
gameManager.gamesById[gameId].gameEventSignal.emit(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
L.e(TAG, '$tag onRequest ', error);
|
L.e(TAG, '$tag onRequest ', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user