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