[server] GameManager restore

This commit is contained in:
2018-03-02 16:08:53 +03:00
parent 0565eec871
commit 73c46d821e
9 changed files with 119 additions and 137 deletions

View File

@@ -0,0 +1,47 @@
package ru.m.draw;
abstract Color(Int) {
public var alpha(get, never):Int;
public var red(get, never):Int;
public var green(get, never):Int;
public var blue(get, never):Int;
public var zero(get, never):Bool;
public inline function new(value:Int) {
this = value;
}
private inline function get_alpha():Int {
return (this >> 24) & 255;
}
private inline function get_red():Int {
return (this >> 16) & 255;
}
private inline function get_green():Int {
return (this >> 8) & 255;
}
private inline function get_blue():Int {
return this & 255;
}
private inline function get_zero():Bool {
return this == 0;
}
@:from
static public inline function fromInt(value:Int):Color {
return new Color(value);
}
@:from
static public inline function fromString(value:String):Color {
return new Color(Std.parseInt('0x${value.split('#').pop()}'));
}
public function toString():String {
return 'Color(${red},${green},${blue})';
}
}

View File

@@ -0,0 +1,8 @@
package ru.m.tankz.control;
import ru.m.tankz.game.Player;
interface IControlFactory {
public function build(player:Player):Control;
}

View File

@@ -0,0 +1,11 @@
package ru.m.tankz.control;
import ru.m.tankz.game.Player;
class NoneControlFactory implements IControlFactory {
public function build(player:Player):Control {
return null;
}
}

View File

@@ -1,5 +1,6 @@
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;
@@ -8,12 +9,10 @@ import promhx.Deferred;
import promhx.Stream;
import ru.m.geom.Direction;
import ru.m.geom.Point;
import ru.m.tankz.bot.BotControl;
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.HumanControl;
import ru.m.tankz.core.Bonus;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Entity;
@@ -88,19 +87,14 @@ class Game implements EngineListener {
points = level.points != null ? level.points : config.points;
engine.map.setData(level.data);
teams = new Map<TeamId, Team>();
var humanControlIndex = 0;
var controlFactory:IControlFactory = Provider.build(IControlFactory);
for (teamConfig in preset.teams) {
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
var team:Team = new Team(teamConfig, teamPoints, save);
teams[team.id] = team;
for (player in team.players.iterator()) {
if (player.config.control != null) {
var control = switch (player.config.control) {
case Control.HUMAN: new HumanControl(player.id, humanControlIndex++);
case Control.BOT: new BotControl(player.id);
case Control.NONE: null;
case _: throw 'Unsupported control type: "${player.config.control}"';
}
var control = controlFactory.build(player);
L.d(TAG, 'control(${player.id} - ${control})');
if (control != null) {
player.control = control;