[proto] update message names
This commit is contained in:
@@ -5,11 +5,11 @@ project_user: holop
|
|||||||
deploy_user: "{{ project_user }}"
|
deploy_user: "{{ project_user }}"
|
||||||
deploy_project: "{{ project_name }}"
|
deploy_project: "{{ project_name }}"
|
||||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||||
deploy_repo_version: ansible
|
deploy_repo_version: network
|
||||||
deploy_npm: yes
|
deploy_npm: yes
|
||||||
|
|
||||||
service_name: "{{ project_name }}"
|
service_name: "{{ project_name }}"
|
||||||
service_work_dir: "{{ deploy_current_dir }}/target"
|
service_work_dir: "{{ deploy_current_dir }}/target/server/neko"
|
||||||
service_command: "/usr/bin/neko {{ deploy_current_dir }}/target/{{ project_name }}.n {{ service_host }}"
|
service_command: "/usr/bin/neko {{ service_work_dir }}/{{ project_name }}.n {{ service_host }}"
|
||||||
service_user: www-data
|
service_user: www-data
|
||||||
service_control_user: "{{ project_user }}"
|
service_control_user: "{{ project_user }}"
|
||||||
|
|||||||
19
gulpfile.js
19
gulpfile.js
@@ -16,7 +16,11 @@ exports.clean = function clean() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.generate = function generate() {
|
exports.generate = function generate() {
|
||||||
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']);
|
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => {
|
||||||
|
if (stdout.indexOf('FAIL') > -1) {
|
||||||
|
throw stdout;
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,10 +44,11 @@ const config = new Project.Config({
|
|||||||
'src-gen/haxe',
|
'src-gen/haxe',
|
||||||
],
|
],
|
||||||
assets: [
|
assets: [
|
||||||
'src/client/resources'
|
'src/common/resources'
|
||||||
],
|
],
|
||||||
macros: [
|
macros: [
|
||||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`
|
'yield.parser.Parser.auto()', // ToDo: bug with extraParams.hxml in yield library
|
||||||
|
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,9 +67,10 @@ const client = new Project(
|
|||||||
name: 'client',
|
name: 'client',
|
||||||
sources: ['src/client/haxe'],
|
sources: ['src/client/haxe'],
|
||||||
main: 'ru.m.tankz.Client',
|
main: 'ru.m.tankz.Client',
|
||||||
|
assets: ['src/client/resources'],
|
||||||
}),
|
}),
|
||||||
module.exports.generate
|
module.exports.generate
|
||||||
).bind(module);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* editor
|
* editor
|
||||||
@@ -76,9 +82,10 @@ const editor = new Project(
|
|||||||
name: 'editor',
|
name: 'editor',
|
||||||
sources: ['src/client/haxe', 'src/editor/haxe'],
|
sources: ['src/client/haxe', 'src/editor/haxe'],
|
||||||
main: 'ru.m.tankz.editor.Editor',
|
main: 'ru.m.tankz.editor.Editor',
|
||||||
|
assets: ['src/client/resources'],
|
||||||
meta: {filename: 'editor'}
|
meta: {filename: 'editor'}
|
||||||
})
|
})
|
||||||
).bind(module);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server
|
* server
|
||||||
@@ -91,7 +98,7 @@ const server = new Project(
|
|||||||
sources: ['src/server/haxe'],
|
sources: ['src/server/haxe'],
|
||||||
main: 'ru.m.tankz.server.Server',
|
main: 'ru.m.tankz.server.Server',
|
||||||
})
|
})
|
||||||
).bind(module);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default
|
* default
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ 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.ClientControlFactory;
|
||||||
import ru.m.tankz.control.IControlFactory;
|
import ru.m.tankz.control.IControlFactory;
|
||||||
import ru.m.tankz.game.ClassicGame;
|
|
||||||
import ru.m.tankz.game.DotaGame;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
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;
|
||||||
@@ -53,8 +50,6 @@ class Init {
|
|||||||
Provider.setFactory(SoundManager, SoundManager);
|
Provider.setFactory(SoundManager, SoundManager);
|
||||||
Provider.setFactory(NetworkManager, NetworkManager);
|
Provider.setFactory(NetworkManager, NetworkManager);
|
||||||
Provider.setFactory(IControlFactory, ClientControlFactory);
|
Provider.setFactory(IControlFactory, ClientControlFactory);
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
|
||||||
|
|
||||||
var host:String = getHost();
|
var host:String = getHost();
|
||||||
L.d('Init', 'host: ${host}');
|
L.d('Init', 'host: ${host}');
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class GameFrame extends VGroupView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function start(save:GameSave):Void {
|
private function start(save:GameSave):Void {
|
||||||
game = Provider.build(Game, save.state.type);
|
game = new Game(save.state.type);
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
throw 'Unsupported game type "${save.state.type}"';
|
throw 'Unsupported game type "${save.state.type}"';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package ru.m.tankz.frame;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
import ru.m.tankz.game.ClassicGame;
|
|
||||||
import ru.m.tankz.game.GameSave;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import ru.m.tankz.proto.core.GameState;
|
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.gui.IGroupView;
|
import haxework.gui.IGroupView;
|
||||||
@@ -11,9 +7,13 @@ import haxework.gui.InputView;
|
|||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import ru.m.tankz.game.GameSave;
|
||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.core.Game;
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
import ru.m.tankz.proto.core.User;
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
|
import ru.m.tankz.proto.core.GameStateProto;
|
||||||
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||||
@@ -29,12 +29,12 @@ class NetworkFrame extends VGroupView {
|
|||||||
|
|
||||||
@:view var gameListFrame(default, null):IGroupView;
|
@:view var gameListFrame(default, null):IGroupView;
|
||||||
@:view var createGameButton(default, null):ButtonView;
|
@:view var createGameButton(default, null):ButtonView;
|
||||||
@:view var gameList(default, null):ListView<Game>;
|
@:view var gameList(default, null):ListView<GameInfoProto>;
|
||||||
|
|
||||||
@:view var gameFrame(default, null):IGroupView;
|
@:view var gameFrame(default, null):IGroupView;
|
||||||
@:view var leaveGameButton(default, null):ButtonView;
|
@:view var leaveGameButton(default, null):ButtonView;
|
||||||
@:view var startGameButton(default, null):ButtonView;
|
@:view var startGameButton(default, null):ButtonView;
|
||||||
@:view var userList(default, null):ListView<User>;
|
@:view var userList(default, null):ListView<UserProto>;
|
||||||
|
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
@:provide var mainFrameSwitcher:IFrameSwitcher;
|
@:provide var mainFrameSwitcher:IFrameSwitcher;
|
||||||
@@ -45,7 +45,7 @@ class NetworkFrame extends VGroupView {
|
|||||||
leaveGameButton.onPress = this;
|
leaveGameButton.onPress = this;
|
||||||
startGameButton.onPress = this;
|
startGameButton.onPress = this;
|
||||||
gameList.dispatcher.addListener({
|
gameList.dispatcher.addListener({
|
||||||
onListItemClick: function(item:IListItemView<Game>):Void {
|
onListItemClick: function(item:IListItemView<GameInfoProto>):Void {
|
||||||
network.joinGame(item.data.id);
|
network.joinGame(item.data.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -71,15 +71,15 @@ class NetworkFrame extends VGroupView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onListGame(games:Array<Game>):Void {
|
private function onListGame(games:Array<GameInfoProto>):Void {
|
||||||
gameList.data = games;
|
gameList.data = games;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onGame(game:Game):Void {
|
private function onGame(game:GameInfoProto):Void {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
userList.data = game.players;
|
userList.data = game.players;
|
||||||
frameSwitcher.change(gameFrame.id);
|
frameSwitcher.change(gameFrame.id);
|
||||||
if (game.state == GameState.STARTED) {
|
if (game.state == GameStateProto.STARTED) {
|
||||||
Provider.set(GameSave, new GameSave({type: ClassicGame.TYPE, presetId: ClassicGame.PLAYER1}));
|
Provider.set(GameSave, new GameSave({type: ClassicGame.TYPE, presetId: ClassicGame.PLAYER1}));
|
||||||
mainFrameSwitcher.change(GameFrame.ID);
|
mainFrameSwitcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ views:
|
|||||||
$style: button
|
$style: button
|
||||||
text: Create
|
text: Create
|
||||||
- id: gameList
|
- id: gameList
|
||||||
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.Game>
|
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.GameInfoProto>
|
||||||
factory: "@class:ru.m.tankz.frame.network.GameItemView"
|
factory: "@class:ru.m.tankz.frame.network.GameItemView"
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
@@ -73,7 +73,7 @@ views:
|
|||||||
$style: button
|
$style: button
|
||||||
text: Leave
|
text: Leave
|
||||||
- id: userList
|
- id: userList
|
||||||
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.User>
|
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.UserProto>
|
||||||
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import haxework.gui.ButtonView;
|
|||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.tankz.game.ClassicGame;
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
import ru.m.tankz.game.DotaGame;
|
import ru.m.tankz.preset.DotaGame;
|
||||||
import ru.m.tankz.game.GameSave;
|
import ru.m.tankz.game.GameSave;
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package ru.m.tankz.frame.network;
|
|||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import ru.m.tankz.proto.core.Game;
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/network/GameItemView.yaml", "ru/m/tankz/Style.yaml")
|
@:template("ru/m/tankz/frame/network/GameItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||||
class GameItemView extends HGroupView implements IListItemView<Game> {
|
class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):Game;
|
public var data(default, set):GameInfoProto;
|
||||||
|
|
||||||
@:view var label(default, null):LabelView;
|
@:view var label(default, null):LabelView;
|
||||||
|
|
||||||
private function set_data(value:Game):Game {
|
private function set_data(value:GameInfoProto):GameInfoProto {
|
||||||
data = value;
|
data = value;
|
||||||
label.text = '${data.type}';
|
label.text = '${data.type}';
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package ru.m.tankz.frame.network;
|
|||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.list.ListView;
|
import haxework.gui.list.ListView;
|
||||||
import ru.m.tankz.proto.core.User;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/network/UserItemView.yaml", "ru/m/tankz/Style.yaml")
|
@:template("ru/m/tankz/frame/network/UserItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||||
class UserItemView extends HGroupView implements IListItemView<User> {
|
class UserItemView extends HGroupView implements IListItemView<UserProto> {
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):User;
|
public var data(default, set):UserProto;
|
||||||
|
|
||||||
@:view var label(default, null):LabelView;
|
@:view var label(default, null):LabelView;
|
||||||
|
|
||||||
private function set_data(value:User):User {
|
private function set_data(value:UserProto):UserProto {
|
||||||
data = value;
|
data = value;
|
||||||
label.text = '${data.uuid} -- ${data.name}';
|
label.text = '${data.uuid} -- ${data.name}';
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
import ru.m.tankz.proto.pack.StartGameRequest;
|
import ru.m.tankz.proto.pack.StartGameRequest;
|
||||||
import ru.m.tankz.proto.game.GameChange;
|
import ru.m.tankz.proto.game.GameChangeProto;
|
||||||
import ru.m.tankz.proto.game.GameActionType;
|
import ru.m.tankz.proto.game.GameActionTypeProto;
|
||||||
import ru.m.tankz.proto.pack.GameUpdateRequest;
|
import ru.m.tankz.proto.pack.GameUpdateRequest;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||||
@@ -10,7 +10,7 @@ import ru.m.tankz.proto.pack.LeaveGameRequest;
|
|||||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.signal.Signal;
|
import ru.m.signal.Signal;
|
||||||
import ru.m.tankz.proto.core.Game;
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||||
import ru.m.tankz.proto.pack.LoginRequest;
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
@@ -24,9 +24,9 @@ class NetworkManager {
|
|||||||
|
|
||||||
public var state(default, null):String;
|
public var state(default, null):String;
|
||||||
public var stateSignal:Signal<String>;
|
public var stateSignal:Signal<String>;
|
||||||
public var listGameSignal:Signal<Array<Game>>;
|
public var listGameSignal:Signal<Array<GameInfoProto>>;
|
||||||
public var gameSignal:Signal<Game>;
|
public var gameSignal:Signal<GameInfoProto>;
|
||||||
public var gameUpdateSignal:Signal<Array<GameChange>>;
|
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
||||||
public var user(default, null):User;
|
public var user(default, null):User;
|
||||||
|
|
||||||
@:provide private var connection:ClientConnection;
|
@:provide private var connection:ClientConnection;
|
||||||
@@ -34,9 +34,9 @@ class NetworkManager {
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
stateSignal = new Signal<String>();
|
stateSignal = new Signal<String>();
|
||||||
listGameSignal = new Signal<Array<Game>>();
|
listGameSignal = new Signal<Array<GameInfoProto>>();
|
||||||
gameSignal = new Signal<Game>();
|
gameSignal = new Signal<GameInfoProto>();
|
||||||
gameUpdateSignal = new Signal<Array<GameChange>>();
|
gameUpdateSignal = new Signal<Array<GameChangeProto>>();
|
||||||
updateState('offline');
|
updateState('offline');
|
||||||
connection.handler.connect(onConnectionEvent);
|
connection.handler.connect(onConnectionEvent);
|
||||||
connection.receiveHandler.connect(onResponse);
|
connection.receiveHandler.connect(onResponse);
|
||||||
@@ -86,9 +86,17 @@ class NetworkManager {
|
|||||||
|
|
||||||
public function action(action:TankAction):Void {
|
public function action(action:TankAction):Void {
|
||||||
var update:GameUpdateRequest = switch action {
|
var update:GameUpdateRequest = switch action {
|
||||||
case TankAction.MOVE(direction): new GameUpdateRequest().setType(GameActionType.MOVE).setDirectionX(direction.x).setDirectionY(direction.y);
|
case TankAction.MOVE(direction):
|
||||||
case TankAction.STOP: new GameUpdateRequest().setType(GameActionType.STOP);
|
new GameUpdateRequest()
|
||||||
case TankAction.SHOT: new GameUpdateRequest().setType(GameActionType.SHOT);
|
.setType(GameActionTypeProto.MOVE)
|
||||||
|
.setDirectionX(direction.x)
|
||||||
|
.setDirectionY(direction.y);
|
||||||
|
case TankAction.STOP:
|
||||||
|
new GameUpdateRequest()
|
||||||
|
.setType(GameActionTypeProto.STOP);
|
||||||
|
case TankAction.SHOT:
|
||||||
|
new GameUpdateRequest()
|
||||||
|
.setType(GameActionTypeProto.SHOT);
|
||||||
case _: null;
|
case _: null;
|
||||||
}
|
}
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class SoundManager {
|
|||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function play(id:String):Void {
|
public function play(id:String):Void {
|
||||||
L.d(TAG, 'play: ${id}');
|
//L.d(TAG, 'play: ${id}');
|
||||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
sound.play();
|
sound.play();
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ import ru.m.draw.Color;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
typedef CompleteRule = {
|
||||||
|
@:optional var team:TeamId;
|
||||||
|
}
|
||||||
|
|
||||||
typedef GameConfig = {
|
typedef GameConfig = {
|
||||||
var levels: Int;
|
var levels: Int;
|
||||||
var friendlyFire:Bool;
|
var friendlyFire:Bool;
|
||||||
|
var complete:Array<CompleteRule>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SpawnPoint = {
|
typedef SpawnPoint = {
|
||||||
|
|||||||
@@ -14,11 +14,15 @@ class Entity implements IKey {
|
|||||||
|
|
||||||
public function new(rect:Rectangle) {
|
public function new(rect:Rectangle) {
|
||||||
this.id = ++idCounter;
|
this.id = ++idCounter;
|
||||||
this.type = Type.getClassName(Type.getClass(this)).split('.').pop();
|
this.type = Type.getClassName(Type.getClass(this)).split('.').pop().toLowerCase();
|
||||||
this.rect = rect;
|
this.rect = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_key():String {
|
private function get_key():String {
|
||||||
return '$type:$id';
|
return '$type:$id';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toString():String {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import ru.m.tankz.control.IControlFactory;
|
|
||||||
import ru.m.tankz.game.GameSave.PlayerSave;
|
|
||||||
import haxe.ds.Option;
|
import haxe.ds.Option;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
@@ -13,6 +11,7 @@ import ru.m.tankz.bundle.IConfigBundle;
|
|||||||
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.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.control.IControlFactory;
|
||||||
import ru.m.tankz.core.Bonus;
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Eagle;
|
import ru.m.tankz.core.Eagle;
|
||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Entity;
|
||||||
@@ -232,6 +231,11 @@ class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function next():Option<GameState> {
|
public function next():Option<GameState> {
|
||||||
|
for (rule in config.game.complete) {
|
||||||
|
if (rule.team != null && rule.team == state.loser) {
|
||||||
|
return Option.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
state.level++;
|
state.level++;
|
||||||
if (state.level >= config.game.levels) state.level = 0;
|
if (state.level >= config.game.levels) state.level = 0;
|
||||||
return Option.Some({type: state.type, presetId: preset.id, level: state.level});
|
return Option.Some({type: state.type, presetId: preset.id, level: state.level});
|
||||||
|
|||||||
26
src/common/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
26
src/common/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.proto.game.GameChangeProto;
|
||||||
|
import ru.m.tankz.proto.core.GameProto;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkGame extends Game {
|
||||||
|
|
||||||
|
public function new(type:GameType) {
|
||||||
|
super(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(proto:GameProto):Void {
|
||||||
|
// ToDo:
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(changes:Array<GameChangeProto>):Void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export():GameProto {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.preset;
|
||||||
|
|
||||||
import haxe.ds.Option;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class ClassicGame extends Game {
|
class ClassicGame extends GamePreset {
|
||||||
|
|
||||||
public static var TYPE(default, never):GameType = 'classic';
|
public static var TYPE(default, never):GameType = 'classic';
|
||||||
|
|
||||||
@@ -17,13 +14,6 @@ class ClassicGame extends Game {
|
|||||||
public static var PLAYER2(default, never):PresetId = 'player2';
|
public static var PLAYER2(default, never):PresetId = 'player2';
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(TYPE);
|
super(TYPE, [HUMAN, BOT], [PLAYER1, PLAYER2]);
|
||||||
}
|
|
||||||
|
|
||||||
override public function next():Option<GameState> {
|
|
||||||
if (state.loser == HUMAN) {
|
|
||||||
return Option.None;
|
|
||||||
}
|
|
||||||
return super.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.preset;
|
||||||
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class DotaGame extends Game {
|
class DotaGame extends GamePreset {
|
||||||
|
|
||||||
public static var TYPE(default, never):GameType = 'dota';
|
public static var TYPE(default, never):GameType = 'dota';
|
||||||
|
|
||||||
@@ -16,6 +15,6 @@ class DotaGame extends Game {
|
|||||||
public static var PLAYER2_VS(default, never):PresetId = 'player2_vs';
|
public static var PLAYER2_VS(default, never):PresetId = 'player2_vs';
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(TYPE);
|
super(TYPE, [RADIANT, DIRE], [PLAYER1, PLAYER2_COOP, PLAYER2_VS]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
17
src/common/haxe/ru/m/tankz/preset/GamePreset.hx
Normal file
17
src/common/haxe/ru/m/tankz/preset/GamePreset.hx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.m.tankz.preset;
|
||||||
|
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
class GamePreset {
|
||||||
|
|
||||||
|
public var type(default, null):GameType;
|
||||||
|
public var teams(default, null):Array<TeamId>;
|
||||||
|
public var presets(default, null):Array<PresetId>;
|
||||||
|
|
||||||
|
public function new(type:GameType, teams:Array<TeamId>, presets:Array<PresetId>) {
|
||||||
|
this.type = type;
|
||||||
|
this.teams = teams;
|
||||||
|
this.presets = presets;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,21 +3,35 @@ syntax = "proto3";
|
|||||||
package ru.m.tankz.proto.core;
|
package ru.m.tankz.proto.core;
|
||||||
|
|
||||||
|
|
||||||
message User {
|
message UserProto {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GameState {
|
enum GameStateProto {
|
||||||
READY = 0;
|
READY = 0;
|
||||||
STARTED = 1;
|
STARTED = 1;
|
||||||
ENDED = 2;
|
ENDED = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Game {
|
message BrickProto {
|
||||||
|
string type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EntityProto {
|
||||||
|
string type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GameInfoProto {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string type = 2;
|
string type = 2;
|
||||||
User creator = 3;
|
UserProto creator = 3;
|
||||||
repeated User players = 4;
|
repeated UserProto players = 4;
|
||||||
GameState state = 5;
|
GameStateProto state = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GameProto {
|
||||||
|
GameInfoProto info = 1;
|
||||||
|
repeated BrickProto map = 2;
|
||||||
|
repeated EntityProto entities = 3;
|
||||||
}
|
}
|
||||||
@@ -3,18 +3,13 @@ syntax = "proto3";
|
|||||||
package ru.m.tankz.proto.game;
|
package ru.m.tankz.proto.game;
|
||||||
|
|
||||||
|
|
||||||
enum GameActionType {
|
enum GameActionTypeProto {
|
||||||
MOVE = 0;
|
MOVE = 0;
|
||||||
SHOT = 1;
|
SHOT = 1;
|
||||||
STOP = 2;
|
STOP = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GameObjectType {
|
enum GameChangeTypeProto {
|
||||||
TANK = 0;
|
|
||||||
BULLET = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum GameChangeType {
|
|
||||||
MOVED = 0;
|
MOVED = 0;
|
||||||
DESTROED = 1;
|
DESTROED = 1;
|
||||||
MODIFIED = 2;
|
MODIFIED = 2;
|
||||||
@@ -22,10 +17,10 @@ enum GameChangeType {
|
|||||||
DIRECTION = 4;
|
DIRECTION = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GameChange {
|
message GameChangeProto {
|
||||||
GameChangeType type = 1;
|
GameChangeTypeProto type = 1;
|
||||||
GameObjectType objectType = 2;
|
string entityType = 2;
|
||||||
int32 objectId = 3;
|
int32 entityId = 3;
|
||||||
float x = 4;
|
float x = 4;
|
||||||
float y = 5;
|
float y = 5;
|
||||||
int32 directionX = 6;
|
int32 directionX = 6;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ message LoginRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message LoginResponse {
|
message LoginResponse {
|
||||||
ru.m.tankz.proto.core.User user = 1;
|
ru.m.tankz.proto.core.UserProto user = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
@@ -30,7 +30,7 @@ message LogoutResponse {}
|
|||||||
message ListGameRequest {}
|
message ListGameRequest {}
|
||||||
|
|
||||||
message ListGameResponse {
|
message ListGameResponse {
|
||||||
repeated ru.m.tankz.proto.core.Game games = 1;
|
repeated ru.m.tankz.proto.core.GameInfoProto games = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Game
|
// Create Game
|
||||||
@@ -39,7 +39,7 @@ message CreateGameRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message CreateGameResponse {
|
message CreateGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.GameInfoProto game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join Game
|
// Join Game
|
||||||
@@ -48,32 +48,32 @@ message JoinGameRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message JoinGameResponse {
|
message JoinGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.GameInfoProto game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave Game
|
// Leave Game
|
||||||
message LeaveGameRequest {}
|
message LeaveGameRequest {}
|
||||||
|
|
||||||
message LeaveGameResponse {
|
message LeaveGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.GameInfoProto game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start Game
|
// Start Game
|
||||||
message StartGameRequest {}
|
message StartGameRequest {}
|
||||||
|
|
||||||
message StartGameResponse {
|
message StartGameResponse {
|
||||||
ru.m.tankz.proto.core.Game game = 1;
|
ru.m.tankz.proto.core.GameInfoProto game = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game Update
|
// Game Update
|
||||||
message GameUpdateRequest {
|
message GameUpdateRequest {
|
||||||
ru.m.tankz.proto.game.GameActionType type = 1;
|
ru.m.tankz.proto.game.GameActionTypeProto type = 1;
|
||||||
int32 directionX = 2;
|
int32 directionX = 2;
|
||||||
int32 directionY = 3;
|
int32 directionY = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GameUpdateResponse {
|
message GameUpdateResponse {
|
||||||
repeated ru.m.tankz.proto.game.GameChange changes = 1;
|
repeated ru.m.tankz.proto.game.GameChangeProto changes = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request
|
// Request
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
game:
|
game:
|
||||||
levels: 36
|
levels: 36
|
||||||
friendlyFire: false
|
friendlyFire: false
|
||||||
|
complete:
|
||||||
|
- team: human
|
||||||
|
|
||||||
map:
|
map:
|
||||||
cellWidth: 22
|
cellWidth: 22
|
||||||
@@ -180,3 +182,4 @@ bonuses:
|
|||||||
- {score: 500, type: life}
|
- {score: 500, type: life}
|
||||||
- {score: 500, type: shovel, duration: 10}
|
- {score: 500, type: shovel, duration: 10}
|
||||||
- {score: 500, type: star}
|
- {score: 500, type: star}
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
game:
|
game:
|
||||||
levels: 8
|
levels: 8
|
||||||
friendlyFire: true
|
friendlyFire: true
|
||||||
|
complete: []
|
||||||
|
|
||||||
map:
|
map:
|
||||||
cellWidth: 22
|
cellWidth: 22
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
import ru.m.tankz.game.GameSave;
|
import ru.m.tankz.game.GameSave;
|
||||||
import ru.m.tankz.proto.pack.StartGameResponse;
|
import ru.m.tankz.proto.pack.StartGameResponse;
|
||||||
import ru.m.tankz.game.ClassicGame;
|
|
||||||
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
import ru.m.tankz.proto.pack.LeaveGameResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameResponse;
|
import ru.m.tankz.proto.pack.JoinGameResponse;
|
||||||
import ru.m.tankz.proto.pack.ListGameResponse;
|
import ru.m.tankz.proto.pack.ListGameResponse;
|
||||||
import ru.m.tankz.proto.pack.CreateGameResponse;
|
import ru.m.tankz.proto.pack.CreateGameResponse;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
import ru.m.tankz.game.Game as RunGame;
|
import ru.m.tankz.game.Game;
|
||||||
import ru.m.tankz.proto.core.GameState;
|
import ru.m.tankz.proto.core.GameStateProto;
|
||||||
import ru.m.tankz.proto.core.Game;
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
import ru.m.tankz.proto.core.User;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.server.session.Thread;
|
import ru.m.tankz.server.session.Thread;
|
||||||
import ru.m.tankz.server.session.Session;
|
import ru.m.tankz.server.session.Session;
|
||||||
|
|
||||||
@@ -57,27 +57,27 @@ class GameManager {
|
|||||||
|
|
||||||
private static var idCounter:Int = 0;
|
private static var idCounter:Int = 0;
|
||||||
|
|
||||||
|
public var gameInfo(default, null):GameInfoProto;
|
||||||
public var game(default, null):Game;
|
public var game(default, null):Game;
|
||||||
public var runGame(default, null):RunGame;
|
|
||||||
|
|
||||||
private var timer:NekoTimer;
|
private var timer:NekoTimer;
|
||||||
|
|
||||||
//private var changes:Array<GameChange> = new Array<GameChange>();
|
//private var changes:Array<GameChange> = new Array<GameChange>();
|
||||||
|
|
||||||
public function new(creator:User) {
|
public function new(creator:UserProto) {
|
||||||
game = new Game()
|
gameInfo = new GameInfoProto()
|
||||||
.setId(idCounter++)
|
.setId(idCounter++)
|
||||||
.setState(GameState.READY)
|
.setState(GameStateProto.READY)
|
||||||
.setCreator(creator);
|
.setCreator(creator);
|
||||||
game.addPlayers(creator);
|
gameInfo.addPlayers(creator);
|
||||||
byGameId.set(game.id, this);
|
byGameId.set(gameInfo.id, this);
|
||||||
byPersonId.set(creator.uuid, this);
|
byPersonId.set(creator.uuid, this);
|
||||||
broadcast(new Response().setCreateGame(new CreateGameResponse().setGame(game)));
|
broadcast(new Response().setCreateGame(new CreateGameResponse().setGame(gameInfo)));
|
||||||
broadcastGames();
|
broadcastGames();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getReadyGames():Array<Game> {
|
public static function getReadyGames():Array<GameInfoProto> {
|
||||||
return Lambda.array(Lambda.filter(Lambda.map(GameManager.byGameId, function(gm) return gm.game), function(game) return game.state == GameState.READY));
|
return Lambda.array(Lambda.filter(Lambda.map(GameManager.byGameId, function(gm) return gm.gameInfo), function(game) return game.state == GameStateProto.READY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function broadcastGames() {
|
public function broadcastGames() {
|
||||||
@@ -89,24 +89,24 @@ class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function broadcast(packet:Response) {
|
public function broadcast(packet:Response) {
|
||||||
for (player in game.players) {
|
for (player in gameInfo.players) {
|
||||||
var session:Session = Session.sessions.get(player.uuid);
|
var session:Session = Session.sessions.get(player.uuid);
|
||||||
session.send(packet);
|
session.send(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function join(user:User) {
|
public function join(user:UserProto) {
|
||||||
game.addPlayers(user);
|
gameInfo.addPlayers(user);
|
||||||
byPersonId.set(user.uuid, this);
|
byPersonId.set(user.uuid, this);
|
||||||
broadcast(new Response().setJoinGame(new JoinGameResponse().setGame(game)));
|
broadcast(new Response().setJoinGame(new JoinGameResponse().setGame(gameInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(user:User) {
|
public function leave(user:UserProto) {
|
||||||
game.setPlayers(game.players.filter(function(p) return p.uuid != user.uuid));
|
gameInfo.setPlayers(gameInfo.players.filter(function(p:UserProto) return p.uuid != user.uuid));
|
||||||
byPersonId.remove(user.uuid);
|
byPersonId.remove(user.uuid);
|
||||||
var packet = new Response().setLeaveGame(new LeaveGameResponse().setGame(game));
|
var packet = new Response().setLeaveGame(new LeaveGameResponse().setGame(gameInfo));
|
||||||
Session.sessions.get(user.uuid).send(packet);
|
Session.sessions.get(user.uuid).send(packet);
|
||||||
if (game.players.length == 0/* || person.id == game.creator.id*/) {
|
if (gameInfo.players.length == 0/* || person.id == game.creator.id*/) {
|
||||||
stop();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
broadcast(packet);
|
broadcast(packet);
|
||||||
@@ -114,29 +114,29 @@ class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function start() {
|
public function start() {
|
||||||
game.setState(GameState.STARTED);
|
gameInfo.setState(GameStateProto.STARTED);
|
||||||
runGame = new ClassicGame();
|
game = new Game(ClassicGame.TYPE);
|
||||||
runGame.start(new GameSave({type: ClassicGame.TYPE, presetId: ClassicGame.PLAYER1, level: 0}));
|
game.start(new GameSave({type: ClassicGame.TYPE, presetId: ClassicGame.PLAYER1, level: 0}));
|
||||||
timer = new NekoTimer(30);
|
timer = new NekoTimer(30);
|
||||||
timer.run = update;
|
timer.run = update;
|
||||||
broadcast(new Response().setStartGame(new StartGameResponse().setGame(game)));
|
broadcast(new Response().setStartGame(new StartGameResponse().setGame(gameInfo)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop() {
|
public function stop() {
|
||||||
game.setState(GameState.ENDED);
|
gameInfo.setState(GameStateProto.ENDED);
|
||||||
game.setPlayers([]);
|
gameInfo.setPlayers([]);
|
||||||
byGameId.remove(game.id);
|
byGameId.remove(gameInfo.id);
|
||||||
for (p in game.players) byPersonId.remove(p.uuid);
|
for (p in gameInfo.players) byPersonId.remove(p.uuid);
|
||||||
if (timer != null) {
|
if (timer != null) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
timer = null;
|
timer = null;
|
||||||
}
|
}
|
||||||
broadcast(new Response().setLeaveGame(new LeaveGameResponse().setGame(game)));
|
broadcast(new Response().setLeaveGame(new LeaveGameResponse().setGame(gameInfo)));
|
||||||
broadcastGames();
|
broadcastGames();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function update() {
|
private function update() {
|
||||||
runGame.engine.update();
|
game.engine.update();
|
||||||
/*var changes = engine.update();
|
/*var changes = engine.update();
|
||||||
changes = this.changes.concat(changes);
|
changes = this.changes.concat(changes);
|
||||||
this.changes = [];
|
this.changes = [];
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import haxe.io.Bytes;
|
|||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.connect.neko.NekoConnection;
|
import ru.m.connect.neko.NekoConnection;
|
||||||
import ru.m.connect.neko.NekoWebConnection;
|
import ru.m.connect.neko.NekoWebConnection;
|
||||||
import ru.m.tankz.proto.core.User;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||||
import ru.m.tankz.proto.pack.CreateGameResponse;
|
import ru.m.tankz.proto.pack.CreateGameResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||||
@@ -43,7 +43,7 @@ class Session {
|
|||||||
|
|
||||||
public static var sessions:Map<String, Session> = new Map<String, Session>();
|
public static var sessions:Map<String, Session> = new Map<String, Session>();
|
||||||
|
|
||||||
public var user(default, null):User;
|
public var user(default, null):UserProto;
|
||||||
public var gameId(default, null):Int = -1;
|
public var gameId(default, null):Int = -1;
|
||||||
|
|
||||||
public var connection(default, null):ServerConnection;
|
public var connection(default, null):ServerConnection;
|
||||||
@@ -103,7 +103,7 @@ class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function login(request:LoginRequest):LoginResponse {
|
private function login(request:LoginRequest):LoginResponse {
|
||||||
user = new User()
|
user = new UserProto()
|
||||||
.setUuid(request.uuid != null ? request.uuid : UUID.generateRandom(new Random()).toString())
|
.setUuid(request.uuid != null ? request.uuid : UUID.generateRandom(new Random()).toString())
|
||||||
.setName(request.name);
|
.setName(request.name);
|
||||||
sessions.set(user.uuid, this);
|
sessions.set(user.uuid, this);
|
||||||
@@ -123,24 +123,24 @@ class Session {
|
|||||||
|
|
||||||
private function createGame(request:CreateGameRequest):CreateGameResponse {
|
private function createGame(request:CreateGameRequest):CreateGameResponse {
|
||||||
var gameManager:GameManager = new GameManager(user);
|
var gameManager:GameManager = new GameManager(user);
|
||||||
return new CreateGameResponse().setGame(gameManager.game);
|
return new CreateGameResponse().setGame(gameManager.gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function joinGame(request:JoinGameRequest):JoinGameResponse {
|
private function joinGame(request:JoinGameRequest):JoinGameResponse {
|
||||||
var gameManager:GameManager = GameManager.byGameId.get(request.gameId);
|
var gameManager:GameManager = GameManager.byGameId.get(request.gameId);
|
||||||
gameManager.join(user);
|
gameManager.join(user);
|
||||||
return new JoinGameResponse().setGame(gameManager.game);
|
return new JoinGameResponse().setGame(gameManager.gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function leaveGame(request:LeaveGameRequest):LeaveGameResponse {
|
private function leaveGame(request:LeaveGameRequest):LeaveGameResponse {
|
||||||
var gameManager:GameManager = GameManager.byPersonId.get(user.uuid);
|
var gameManager:GameManager = GameManager.byPersonId.get(user.uuid);
|
||||||
gameManager.leave(user);
|
gameManager.leave(user);
|
||||||
return new LeaveGameResponse().setGame(gameManager.game);
|
return new LeaveGameResponse().setGame(gameManager.gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function startGame(request:StartGameRequest):StartGameResponse {
|
private function startGame(request:StartGameRequest):StartGameResponse {
|
||||||
var gameManager:GameManager = GameManager.byPersonId.get(user.uuid);
|
var gameManager:GameManager = GameManager.byPersonId.get(user.uuid);
|
||||||
gameManager.start();
|
gameManager.start();
|
||||||
return new StartGameResponse().setGame(gameManager.game);
|
return new StartGameResponse().setGame(gameManager.gameInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user