[all] fixes for LevelPack
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
package ru.m.tankz.bundle;
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
import haxe.io.BytesInput;
|
|
||||||
import haxe.zip.Entry;
|
|
||||||
import haxe.zip.Reader;
|
|
||||||
import lime.utils.Bytes;
|
|
||||||
import lime.utils.CompressionAlgorithm;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
@@ -14,25 +9,12 @@ class LevelBundle implements ILevelBundle {
|
|||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
private function extract(entry:Entry):LevelConfig {
|
|
||||||
var bytes:Bytes = entry.data;
|
|
||||||
if (entry.compressed) {
|
|
||||||
bytes = bytes.decompress(CompressionAlgorithm.DEFLATE);
|
|
||||||
}
|
|
||||||
var level = LevelUtil.loads(bytes.toString());
|
|
||||||
if (level.id == null) {
|
|
||||||
level.id = Std.parseInt(entry.fileName.split("level").pop());
|
|
||||||
}
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get(type:GameType, name:String):LevelPack {
|
public function get(type:GameType, name:String):LevelPack {
|
||||||
var data = Assets.getBytes('levels/${type}_${name}.zip');
|
var bytes = Assets.getBytes('levels/${type}_${name}.zip');
|
||||||
var files = Reader.readZip(new BytesInput(data));
|
|
||||||
return {
|
return {
|
||||||
type: type,
|
type: type,
|
||||||
name: name,
|
name: name,
|
||||||
data: Lambda.array(files.map(extract)),
|
data: LevelUtil.unpack(bytes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package ru.m.tankz.local;
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
import ru.m.tankz.local.LocalControlFactory;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
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.game.record.GameRecorder;
|
import ru.m.tankz.game.record.GameRecorder;
|
||||||
|
import ru.m.tankz.local.LocalControlFactory;
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
class LocalGame extends GameRunner {
|
class LocalGame extends GameRunner {
|
||||||
@:provide var recordStorage:RecordStorage;
|
@:provide var recordStorage:RecordStorage;
|
||||||
private var recorder:GameRecorder;
|
private var recorder:GameRecorder;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
super(state);
|
super(state, level);
|
||||||
controlFactory = new LocalControlFactory();
|
controlFactory = new LocalControlFactory();
|
||||||
recorder = new GameRecorder();
|
recorder = new GameRecorder();
|
||||||
connect(recorder);
|
connect(recorder);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class NetworkGame extends Game {
|
|||||||
private var network:NetworkManager;
|
private var network:NetworkManager;
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
public function new(network:NetworkManager) {
|
||||||
super(new GameState(network.room.game.type, 0));
|
super(new GameState(network.room.game.type, 0), null);
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.controlFactory = new NetworkControlFactory();
|
this.controlFactory = new NetworkControlFactory();
|
||||||
network.gameEventSignal.connect(onGameEventProto);
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
|
|||||||
@@ -115,7 +115,8 @@ class Render extends SpriteView implements IRender {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(_):
|
case START(_, level):
|
||||||
|
gridSize = level.size;
|
||||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
case COMPLETE(_, _):
|
case COMPLETE(_, _):
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
gameView.type = game.type;
|
gameView.type = game.type;
|
||||||
soundManager.config = game.config;
|
soundManager.config = game.config;
|
||||||
gameView.render.config = game.config;
|
gameView.render.config = game.config;
|
||||||
gameView.render.gridSize = game.state.level.size;
|
|
||||||
game.connect(gameView.render);
|
game.connect(gameView.render);
|
||||||
game.connect(soundManager);
|
game.connect(soundManager);
|
||||||
if (gameView.panel != null) {
|
if (gameView.panel != null) {
|
||||||
|
|||||||
@@ -34,10 +34,9 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||||
state.level = level;
|
|
||||||
state.presetId = preset.id;
|
state.presetId = preset.id;
|
||||||
state.controls = control.values;
|
state.controls = control.values;
|
||||||
game = new LocalGame(state);
|
game = new LocalGame(state, level);
|
||||||
switcher.change(GameFrame.ID);
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.ButtonView;
|
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
@@ -18,7 +17,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
@:provide var frames:FrameSwitcher;
|
@:provide var frames:FrameSwitcher;
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide("next") var nextState:GameState;
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
|
|
||||||
private function playerViewFactory(index:Int, player:PlayerState) {
|
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||||
@@ -35,14 +33,11 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onShow() {
|
public function onShow() {
|
||||||
resultView.data = Lambda.array(state.players);
|
resultView.data = Lambda.array(state.players);
|
||||||
levelLabel.text = 'Level ${state.levelId}';
|
//levelLabel.text = 'Level ${state.levelId}'; // ToDo: level?
|
||||||
}
|
}
|
||||||
|
|
||||||
private function next() {
|
private function next() {
|
||||||
if (nextState != null) {
|
//ToDo: next level?
|
||||||
game = new GameRunner(nextState);
|
|
||||||
frames.change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function close() {
|
private function close() {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
level.text = 'Level ${state.levelId}';
|
|
||||||
bot.life = state.getTeamLife(ClassicGame.BOT);
|
bot.life = state.getTeamLife(ClassicGame.BOT);
|
||||||
player1.life = state.getPlayerLife(player1Id);
|
player1.life = state.getPlayerLife(player1Id);
|
||||||
player1.score = state.getPlayerScore(player1Id);
|
player1.score = state.getPlayerScore(player1Id);
|
||||||
@@ -36,7 +35,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
|
this.level.text = 'Level ${level.id}';
|
||||||
refresh(state);
|
refresh(state);
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
if (teamId == ClassicGame.BOT) {
|
if (teamId == ClassicGame.BOT) {
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
level.text = 'Level ${state.levelId}';
|
this.level.text = 'Level ${level.id}';
|
||||||
players.data = Lambda.array(state.players);
|
players.data = Lambda.array(state.players);
|
||||||
case _:
|
case _:
|
||||||
for (view in players.views) {
|
for (view in players.views) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
@:view var level:LabelView;
|
@:view var level:LabelView;
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
level.text = 'Level ${state.levelId}';
|
|
||||||
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
||||||
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
||||||
dire.life = state.getTeamLife(DotaGame.DIRE);
|
dire.life = state.getTeamLife(DotaGame.DIRE);
|
||||||
@@ -34,7 +33,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
|
this.level.text = 'Level ${level.id}';
|
||||||
refresh(state);
|
refresh(state);
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
getLifeView(teamId).life = life;
|
getLifeView(teamId).life = life;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
|||||||
private function create():Void {
|
private function create():Void {
|
||||||
CreateGamePopup.instance.show().then(function(result) {
|
CreateGamePopup.instance.show().then(function(result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
network.createGame(result.type, result.level);
|
network.createGame(result.type, result.level.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,25 @@ import haxework.view.DataView;
|
|||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
import haxework.view.ToggleButtonView;
|
import haxework.view.ToggleButtonView;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
private typedef Result = {
|
private typedef Result = {
|
||||||
var type:GameType;
|
var type:GameType;
|
||||||
var level:LevelId;
|
var level:LevelConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:template class CreateGamePopup extends PopupView<Result> {
|
@:template class CreateGamePopup extends PopupView<Result> {
|
||||||
|
|
||||||
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||||
@:view("level") var levelView:DataView<LevelId, ToggleButtonView>;
|
@:view("level") var levelView:DataView<LevelConfig, ToggleButtonView>;
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide static var configBundle:IConfigBundle;
|
||||||
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
|
||||||
private var type:GameType;
|
private var type:GameType;
|
||||||
private var level:LevelId;
|
private var level:LevelConfig;
|
||||||
|
|
||||||
override private function onShow():Void {
|
override private function onShow():Void {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
@@ -43,18 +46,18 @@ private typedef Result = {
|
|||||||
for (v in typeView.dataViews) {
|
for (v in typeView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
}
|
}
|
||||||
levelView.data = [for (i in 0...configBundle.get(type).game.levels) i];
|
levelView.data = levelBundle.get(value, "standard").data;
|
||||||
onLevelSelect(0, 0, levelView.dataViews[0]);
|
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, value:LevelId):ToggleButtonView {
|
private function levelViewFactory(index:Int, value:LevelConfig):ToggleButtonView {
|
||||||
var result = new ToggleButtonView();
|
var result = new ToggleButtonView();
|
||||||
result.skinId = "button.level";
|
result.skinId = "button.level";
|
||||||
result.text = Std.string(value);
|
result.text = Std.string(value.id);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, level:LevelId, view:ToggleButtonView):Void {
|
private function onLevelSelect(index:Int, level:LevelConfig, view:ToggleButtonView):Void {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
for (v in levelView.dataViews) {
|
for (v in levelView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import ru.m.tankz.Type;
|
|||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
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 level(default, null):LevelConfig;
|
||||||
public var engine(default, null):IEngine;
|
public var engine(default, null):IEngine;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
public var pause(default, set):Bool;
|
public var pause(default, set):Bool;
|
||||||
@@ -33,9 +34,10 @@ import ru.m.tankz.Type;
|
|||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
this.type = state.type;
|
this.type = state.type;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.level = level;
|
||||||
this.teams = new Map();
|
this.teams = new Map();
|
||||||
this.config = configBundle.get(type);
|
this.config = configBundle.get(type);
|
||||||
this.controlFactory = new NoneControlFactory();
|
this.controlFactory = new NoneControlFactory();
|
||||||
@@ -71,8 +73,9 @@ import ru.m.tankz.Type;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.level = level;
|
||||||
case COMPLETE(state, winnerId):
|
case COMPLETE(state, winnerId):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.winner = winnerId;
|
this.winner = winnerId;
|
||||||
@@ -98,8 +101,8 @@ import ru.m.tankz.Type;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function start():Void {
|
public function start():Void {
|
||||||
var level:LevelConfig = state.level;
|
// ToDo: Spawner not in Team?
|
||||||
var points:Array<SpawnPoint> = level.points != null ? level.points : config.points;
|
var points:Array<SpawnPoint> = level != null && level.points != null ? level.points : config.points;
|
||||||
for (teamConfig in state.preset.teams) {
|
for (teamConfig in state.preset.teams) {
|
||||||
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
||||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.LevelConfig;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import ru.m.geom.Position;
|
import ru.m.geom.Position;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
@@ -73,7 +74,7 @@ enum ChangeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GameEvent {
|
enum GameEvent {
|
||||||
START(state:GameState);
|
START(state:GameState, level:LevelConfig);
|
||||||
SPAWN(event:SpawnEvent);
|
SPAWN(event:SpawnEvent);
|
||||||
MOVE(event:MoveEvent);
|
MOVE(event:MoveEvent);
|
||||||
STOP(event:StopEvent);
|
STOP(event:StopEvent);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.LevelConfig;
|
||||||
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;
|
||||||
@@ -19,10 +20,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
private var builder:EntityBuilder;
|
private var builder:EntityBuilder;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
super(state);
|
super(state, level);
|
||||||
this.builder = new EntityBuilder(config);
|
this.builder = new EntityBuilder(config);
|
||||||
this.engine = new Engine(config, state.level.size);
|
this.engine = new Engine(config, level.size);
|
||||||
this.engine.connect(this);
|
this.engine.connect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
super.start();
|
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);
|
engine.map.setData(mapData);
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
team.spawner.runner = spawn;
|
team.spawner.runner = spawn;
|
||||||
@@ -68,7 +69,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
||||||
gameEventSignal.emit(START(state));
|
gameEventSignal.emit(START(state, level));
|
||||||
//for (i in 0...10) spawnBonus();
|
//for (i in 0...10) spawnBonus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ru.m.tankz.game;
|
|||||||
|
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
@@ -72,20 +71,17 @@ class GameState {
|
|||||||
|
|
||||||
public var type:GameType;
|
public var type:GameType;
|
||||||
public var presetId:PresetId;
|
public var presetId:PresetId;
|
||||||
public var levelId(get, null):LevelId;
|
|
||||||
public var controls:Array<PlayerControl>;
|
public var controls:Array<PlayerControl>;
|
||||||
public var players:Map<String, PlayerState>;
|
public var players:Map<String, PlayerState>;
|
||||||
public var teams:Map<TeamId, TeamState>;
|
public var teams:Map<TeamId, TeamState>;
|
||||||
public var preset(get, null):GamePreset;
|
public var preset(get, null):GamePreset;
|
||||||
public var config(get, null):Config;
|
public var config(get, null):Config;
|
||||||
public var level(default, default):LevelConfig;
|
|
||||||
|
|
||||||
@:provide static private var configBundle:IConfigBundle;
|
@: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.type = type;
|
||||||
this.presetId = presetId;
|
this.presetId = presetId;
|
||||||
this.level = level;
|
|
||||||
//this.controls = controls == null ? config.controls[0].values : controls;
|
//this.controls = controls == null ? config.controls[0].values : controls;
|
||||||
this.controls = controls == null ? [] : controls;
|
this.controls = controls == null ? [] : controls;
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
@@ -117,10 +113,6 @@ class GameState {
|
|||||||
return configBundle.get(type);
|
return configBundle.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_levelId():LevelId {
|
|
||||||
return level == null ? 0 : level.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTeamLife(id:TeamId):Int {
|
public function getTeamLife(id:TeamId):Int {
|
||||||
if (teams.exists(id)) {
|
if (teams.exists(id)) {
|
||||||
return teams[id].life + Lambda.fold(teams[id].players, function(p, c) return c + p.life, 0);
|
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;
|
private var ticker:Ticker;
|
||||||
|
|
||||||
public function new(record:GameRecord) {
|
public function new(record:GameRecord) {
|
||||||
super(record.state);
|
super(record.state, null);
|
||||||
this.record = record;
|
this.record = record;
|
||||||
this.data = null;
|
this.data = null;
|
||||||
this.ticker = new Ticker();
|
this.ticker = new Ticker();
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ class GameRecorder implements GameListener {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case GameEvent.START(state):
|
case GameEvent.START(state, level):
|
||||||
ticker.start();
|
ticker.start();
|
||||||
record.info.type = state.type;
|
record.info.type = state.type;
|
||||||
record.info.presetId = state.presetId;
|
record.info.presetId = state.presetId;
|
||||||
record.info.levelId = state.levelId;
|
record.info.levelId = level.id;
|
||||||
record.info.date = Date.now();
|
record.info.date = Date.now();
|
||||||
case GameEvent.COMPLETE(_, _):
|
case GameEvent.COMPLETE(_, _):
|
||||||
ticker.stop();
|
ticker.stop();
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package ru.m.tankz.util;
|
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.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import yaml.Parser;
|
import yaml.Parser;
|
||||||
@@ -65,4 +69,25 @@ class LevelUtil {
|
|||||||
size: size,
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ import ru.m.tankz.util.LevelUtil;
|
|||||||
private function open():Void {
|
private function open():Void {
|
||||||
FileUtil.browse().then(function(content:FileContent) {
|
FileUtil.browse().then(function(content:FileContent) {
|
||||||
fileName = content.name;
|
fileName = content.name;
|
||||||
var data = LevelUtil.loads(config, content.content);
|
var data = LevelUtil.loads(content.content);
|
||||||
mapView.gridSize = data.size;
|
mapView.gridSize = data.size;
|
||||||
mapView.data = data;
|
mapView.data = data;
|
||||||
levelName.text = data.name;
|
levelName.text = data.name;
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ enum Brush {
|
|||||||
override private function set_config(value:Config):Config {
|
override private function set_config(value:Config):Config {
|
||||||
var result = super.set_config(value);
|
var result = super.set_config(value);
|
||||||
builder = new EntityBuilder(value);
|
builder = new EntityBuilder(value);
|
||||||
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]);
|
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1].index);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
override private function set_gridSize(value:GridSize):GridSize {
|
override private function set_gridSize(value:GridSize):GridSize {
|
||||||
var result = super.set_gridSize(value);
|
var result = super.set_gridSize(value);
|
||||||
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]);
|
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1].index);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ enum Brush {
|
|||||||
|
|
||||||
private function get_data():LevelConfig {
|
private function get_data():LevelConfig {
|
||||||
return {
|
return {
|
||||||
data: map.bricks.map(function(brick:Brick) return brick.config),
|
data: map.bricks.map(function(brick:Brick) return brick.config.index),
|
||||||
points: config.points,
|
points: config.points,
|
||||||
size: gridSize,
|
size: gridSize,
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ enum Brush {
|
|||||||
reset();
|
reset();
|
||||||
pointEntities = new Map();
|
pointEntities = new Map();
|
||||||
map = new LevelMap(config.map, gridSize);
|
map = new LevelMap(config.map, gridSize);
|
||||||
map.setData(value.data);
|
map.setData(value.data.map(function(index) return config.getBrickByIndex(index)));
|
||||||
gameEventSignal.emit(EventUtil.buildBricksSpawn(map));
|
gameEventSignal.emit(EventUtil.buildBricksSpawn(map));
|
||||||
for (point in config.points) {
|
for (point in config.points) {
|
||||||
switch point.type {
|
switch point.type {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class ServerConfigBundle implements IConfigBundle {
|
|||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType):Config {
|
public function get(type:GameType):Config {
|
||||||
var path:String = FileSystem.absolutePath('./resources/${type}/config.yaml');
|
var path:String = FileSystem.absolutePath('./resources/config/${type}.yaml');
|
||||||
var data:String = File.getContent(path);
|
var data:String = File.getContent(path);
|
||||||
var source:ConfigSource = Yaml.parse(data, Parser.options().useObjects());
|
var source:ConfigSource = Yaml.parse(data, Parser.options().useObjects());
|
||||||
return Config.fromSource(type, source);
|
return Config.fromSource(type, source);
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ class ServerLevelBundle implements ILevelBundle {
|
|||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
public function get(type:GameType, name:String):LevelPack {
|
||||||
var path:String = FileSystem.absolutePath('./resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
var path = FileSystem.absolutePath('./levels/${type}_${name}.zip');
|
||||||
var data:String = File.getContent(path);
|
var bytes = File.getBytes(path);
|
||||||
return LevelUtil.loads(config, data);
|
return {
|
||||||
|
type: type,
|
||||||
|
name: name,
|
||||||
|
data: LevelUtil.unpack(bytes),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
@@ -18,8 +19,10 @@ class ServerGame extends GameRunner {
|
|||||||
public var room(default, null):RoomProto;
|
public var room(default, null):RoomProto;
|
||||||
public var id(get, null):Int;
|
public var id(get, null):Int;
|
||||||
|
|
||||||
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
|
||||||
public function new(room:RoomProto) {
|
public function new(room:RoomProto) {
|
||||||
super(new GameState(room.game.type, 0, room.game.level));
|
super(new GameState(room.game.type, 0), levelBundle.get(room.game.type, "standard").data[room.game.level]);
|
||||||
this.controlFactory = new ServerControlFactory();
|
this.controlFactory = new ServerControlFactory();
|
||||||
this.room = room;
|
this.room = room;
|
||||||
}
|
}
|
||||||
@@ -84,7 +87,7 @@ class ServerGame extends GameRunner {
|
|||||||
var result = [];
|
var result = [];
|
||||||
result.push(EventUtil.buildBricksSpawn(engine.map));
|
result.push(EventUtil.buildBricksSpawn(engine.map));
|
||||||
result = result.concat(EventUtil.buildCellsDestroyed(engine.map));
|
result = result.concat(EventUtil.buildCellsDestroyed(engine.map));
|
||||||
result.push(START(state));
|
result.push(START(state, level));
|
||||||
for (entity in engine.entities) {
|
for (entity in engine.entities) {
|
||||||
switch EntityTypeResolver.of(entity) {
|
switch EntityTypeResolver.of(entity) {
|
||||||
case EAGLE(eagle): result.push(EventUtil.buildEagleSpawn(eagle));
|
case EAGLE(eagle): result.push(EventUtil.buildEagleSpawn(eagle));
|
||||||
|
|||||||
Reference in New Issue
Block a user