[all] fixes for LevelPack
This commit is contained in:
@@ -25,6 +25,7 @@ import ru.m.tankz.Type;
|
||||
public var config(default, null):Config;
|
||||
public var winner(default, null):Null<TeamId>;
|
||||
public var state(default, null):GameState;
|
||||
public var level(default, null):LevelConfig;
|
||||
public var engine(default, null):IEngine;
|
||||
public var controlFactory(default, null):IControlFactory;
|
||||
public var pause(default, set):Bool;
|
||||
@@ -33,9 +34,10 @@ import ru.m.tankz.Type;
|
||||
|
||||
@:provide var configBundle:IConfigBundle;
|
||||
|
||||
public function new(state:GameState) {
|
||||
public function new(state:GameState, level:LevelConfig) {
|
||||
this.type = state.type;
|
||||
this.state = state;
|
||||
this.level = level;
|
||||
this.teams = new Map();
|
||||
this.config = configBundle.get(type);
|
||||
this.controlFactory = new NoneControlFactory();
|
||||
@@ -71,8 +73,9 @@ import ru.m.tankz.Type;
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state):
|
||||
case START(state, level):
|
||||
this.state = state;
|
||||
this.level = level;
|
||||
case COMPLETE(state, winnerId):
|
||||
this.state = state;
|
||||
this.winner = winnerId;
|
||||
@@ -98,8 +101,8 @@ import ru.m.tankz.Type;
|
||||
}
|
||||
|
||||
public function start():Void {
|
||||
var level:LevelConfig = state.level;
|
||||
var points:Array<SpawnPoint> = level.points != null ? level.points : config.points;
|
||||
// ToDo: Spawner not in Team?
|
||||
var points:Array<SpawnPoint> = level != null && level.points != null ? level.points : config.points;
|
||||
for (teamConfig in state.preset.teams) {
|
||||
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.config.Config.LevelConfig;
|
||||
import haxework.color.Color;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.geom.Rectangle;
|
||||
@@ -73,7 +74,7 @@ enum ChangeEvent {
|
||||
}
|
||||
|
||||
enum GameEvent {
|
||||
START(state:GameState);
|
||||
START(state:GameState, level:LevelConfig);
|
||||
SPAWN(event:SpawnEvent);
|
||||
MOVE(event:MoveEvent);
|
||||
STOP(event:StopEvent);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.config.Config.LevelConfig;
|
||||
import ru.m.geom.Line;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.control.Control;
|
||||
@@ -19,10 +20,10 @@ class GameRunner extends Game implements EngineListener {
|
||||
private var timer:Timer;
|
||||
private var builder:EntityBuilder;
|
||||
|
||||
public function new(state:GameState) {
|
||||
super(state);
|
||||
public function new(state:GameState, level:LevelConfig) {
|
||||
super(state, level);
|
||||
this.builder = new EntityBuilder(config);
|
||||
this.engine = new Engine(config, state.level.size);
|
||||
this.engine = new Engine(config, level.size);
|
||||
this.engine.connect(this);
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ class GameRunner extends Game implements EngineListener {
|
||||
|
||||
override public function start():Void {
|
||||
super.start();
|
||||
var mapData = state.level.data.map(function(index:BrickIndex) return config.getBrickByIndex(index));
|
||||
var mapData = level.data.map(function(index:BrickIndex) return config.getBrickByIndex(index));
|
||||
engine.map.setData(mapData);
|
||||
for (team in teams.iterator()) {
|
||||
team.spawner.runner = spawn;
|
||||
@@ -68,7 +69,7 @@ class GameRunner extends Game implements EngineListener {
|
||||
}
|
||||
}
|
||||
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
||||
gameEventSignal.emit(START(state));
|
||||
gameEventSignal.emit(START(state, level));
|
||||
//for (i in 0...10) spawnBonus();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.m.tankz.game;
|
||||
|
||||
import haxework.color.Color;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
@@ -72,20 +71,17 @@ class GameState {
|
||||
|
||||
public var type:GameType;
|
||||
public var presetId:PresetId;
|
||||
public var levelId(get, null):LevelId;
|
||||
public var controls:Array<PlayerControl>;
|
||||
public var players:Map<String, PlayerState>;
|
||||
public var teams:Map<TeamId, TeamState>;
|
||||
public var preset(get, null):GamePreset;
|
||||
public var config(get, null):Config;
|
||||
public var level(default, default):LevelConfig;
|
||||
|
||||
@:provide static private var configBundle:IConfigBundle;
|
||||
|
||||
public function new(type:GameType, presetId:PresetId = 0, level:LevelConfig = null, state:GameState = null, controls:Array<PlayerControl> = null) {
|
||||
public function new(type:GameType, presetId:PresetId = 0, state:GameState = null, controls:Array<PlayerControl> = null) {
|
||||
this.type = type;
|
||||
this.presetId = presetId;
|
||||
this.level = level;
|
||||
//this.controls = controls == null ? config.controls[0].values : controls;
|
||||
this.controls = controls == null ? [] : controls;
|
||||
if (state == null) {
|
||||
@@ -117,10 +113,6 @@ class GameState {
|
||||
return configBundle.get(type);
|
||||
}
|
||||
|
||||
private function get_levelId():LevelId {
|
||||
return level == null ? 0 : level.id;
|
||||
}
|
||||
|
||||
public function getTeamLife(id:TeamId):Int {
|
||||
if (teams.exists(id)) {
|
||||
return teams[id].life + Lambda.fold(teams[id].players, function(p, c) return c + p.life, 0);
|
||||
|
||||
@@ -12,7 +12,7 @@ class GamePlayer extends Game {
|
||||
private var ticker:Ticker;
|
||||
|
||||
public function new(record:GameRecord) {
|
||||
super(record.state);
|
||||
super(record.state, null);
|
||||
this.record = record;
|
||||
this.data = null;
|
||||
this.ticker = new Ticker();
|
||||
|
||||
@@ -17,11 +17,11 @@ class GameRecorder implements GameListener {
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case GameEvent.START(state):
|
||||
case GameEvent.START(state, level):
|
||||
ticker.start();
|
||||
record.info.type = state.type;
|
||||
record.info.presetId = state.presetId;
|
||||
record.info.levelId = state.levelId;
|
||||
record.info.levelId = level.id;
|
||||
record.info.date = Date.now();
|
||||
case GameEvent.COMPLETE(_, _):
|
||||
ticker.stop();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package ru.m.tankz.util;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesInput;
|
||||
import haxe.zip.Entry;
|
||||
import haxe.zip.Reader;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
import yaml.Parser;
|
||||
@@ -65,4 +69,25 @@ class LevelUtil {
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
|
||||
private static function extract(entry:Entry):LevelConfig {
|
||||
var bytes:Bytes = entry.data;
|
||||
if (entry.compressed) {
|
||||
#if ((flash || html5) && lime)
|
||||
bytes = cast(bytes, lime.utils.Bytes).decompress(lime.utils.CompressionAlgorithm.DEFLATE);
|
||||
#else
|
||||
bytes = haxe.zip.Reader.unzip(entry);
|
||||
#end
|
||||
}
|
||||
var level = LevelUtil.loads(bytes.toString());
|
||||
if (level.id == null) {
|
||||
level.id = Std.parseInt(entry.fileName.split("level").pop());
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
public static function unpack(bytes:Bytes):Array<LevelConfig> {
|
||||
var files = Reader.readZip(new BytesInput(bytes));
|
||||
return Lambda.array(files.map(extract));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user