diff --git a/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx b/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx index 609cf92..9a6f564 100644 --- a/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx +++ b/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx @@ -1,10 +1,5 @@ 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 ru.m.tankz.config.Config; import ru.m.tankz.Type; @@ -14,25 +9,12 @@ class LevelBundle implements ILevelBundle { 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 { - var data = Assets.getBytes('levels/${type}_${name}.zip'); - var files = Reader.readZip(new BytesInput(data)); + var bytes = Assets.getBytes('levels/${type}_${name}.zip'); return { type: type, name: name, - data: Lambda.array(files.map(extract)), + data: LevelUtil.unpack(bytes), }; } } diff --git a/src/client/haxe/ru/m/tankz/local/LocalGame.hx b/src/client/haxe/ru/m/tankz/local/LocalGame.hx index 2895233..dbf8742 100644 --- a/src/client/haxe/ru/m/tankz/local/LocalGame.hx +++ b/src/client/haxe/ru/m/tankz/local/LocalGame.hx @@ -1,18 +1,19 @@ 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.GameRunner; import ru.m.tankz.game.GameState; import ru.m.tankz.game.record.GameRecorder; +import ru.m.tankz.local.LocalControlFactory; import ru.m.tankz.storage.RecordStorage; class LocalGame extends GameRunner { @:provide var recordStorage:RecordStorage; private var recorder:GameRecorder; - public function new(state:GameState) { - super(state); + public function new(state:GameState, level:LevelConfig) { + super(state, level); controlFactory = new LocalControlFactory(); recorder = new GameRecorder(); connect(recorder); diff --git a/src/client/haxe/ru/m/tankz/network/NetworkGame.hx b/src/client/haxe/ru/m/tankz/network/NetworkGame.hx index 9b5fdaa..a99f515 100644 --- a/src/client/haxe/ru/m/tankz/network/NetworkGame.hx +++ b/src/client/haxe/ru/m/tankz/network/NetworkGame.hx @@ -14,7 +14,7 @@ class NetworkGame extends Game { private var 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.controlFactory = new NetworkControlFactory(); network.gameEventSignal.connect(onGameEventProto); diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 1863614..dcf0d56 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -115,7 +115,8 @@ class Render extends SpriteView implements IRender { public function onGameEvent(event:GameEvent):Void { switch event { - case START(_): + case START(_, level): + gridSize = level.size; content.addEventListener(Event.ENTER_FRAME, onEnterFrame); case COMPLETE(_, _): content.removeEventListener(Event.ENTER_FRAME, onEnterFrame); diff --git a/src/client/haxe/ru/m/tankz/view/GameFrame.hx b/src/client/haxe/ru/m/tankz/view/GameFrame.hx index 3b10940..f4dca55 100644 --- a/src/client/haxe/ru/m/tankz/view/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/GameFrame.hx @@ -31,7 +31,6 @@ import ru.m.tankz.view.game.GameView; gameView.type = game.type; soundManager.config = game.config; gameView.render.config = game.config; - gameView.render.gridSize = game.state.level.size; game.connect(gameView.render); game.connect(soundManager); if (gameView.panel != null) { diff --git a/src/client/haxe/ru/m/tankz/view/LevelFrame.hx b/src/client/haxe/ru/m/tankz/view/LevelFrame.hx index 9dfd00c..ee05fc4 100644 --- a/src/client/haxe/ru/m/tankz/view/LevelFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/LevelFrame.hx @@ -34,10 +34,9 @@ import ru.m.tankz.view.popup.LevelPopup; } private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void { - state.level = level; state.presetId = preset.id; state.controls = control.values; - game = new LocalGame(state); + game = new LocalGame(state, level); switcher.change(GameFrame.ID); } diff --git a/src/client/haxe/ru/m/tankz/view/ResultFrame.hx b/src/client/haxe/ru/m/tankz/view/ResultFrame.hx index c403787..8b49415 100644 --- a/src/client/haxe/ru/m/tankz/view/ResultFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/ResultFrame.hx @@ -1,6 +1,5 @@ package ru.m.tankz.view; -import haxework.view.ButtonView; import haxework.view.DataView; import haxework.view.frame.FrameSwitcher; import haxework.view.LabelView; @@ -18,7 +17,6 @@ import ru.m.tankz.view.common.LifeView; @:provide var frames:FrameSwitcher; @:provide var state:GameState; - @:provide("next") var nextState:GameState; @:provide var game:IGame; private function playerViewFactory(index:Int, player:PlayerState) { @@ -35,14 +33,11 @@ import ru.m.tankz.view.common.LifeView; public function onShow() { resultView.data = Lambda.array(state.players); - levelLabel.text = 'Level ${state.levelId}'; + //levelLabel.text = 'Level ${state.levelId}'; // ToDo: level? } private function next() { - if (nextState != null) { - game = new GameRunner(nextState); - frames.change(GameFrame.ID); - } + //ToDo: next level? } private function close() { diff --git a/src/client/haxe/ru/m/tankz/view/game/ClassicGamePanel.hx b/src/client/haxe/ru/m/tankz/view/game/ClassicGamePanel.hx index 0200759..594e05f 100644 --- a/src/client/haxe/ru/m/tankz/view/game/ClassicGamePanel.hx +++ b/src/client/haxe/ru/m/tankz/view/game/ClassicGamePanel.hx @@ -21,7 +21,6 @@ import ru.m.tankz.view.common.LifeView; private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1); public function refresh(state:GameState):Void { - level.text = 'Level ${state.levelId}'; bot.life = state.getTeamLife(ClassicGame.BOT); player1.life = state.getPlayerLife(player1Id); player1.score = state.getPlayerScore(player1Id); @@ -36,7 +35,8 @@ import ru.m.tankz.view.common.LifeView; public function onGameEvent(event:GameEvent):Void { switch event { - case START(state): + case START(state, level): + this.level.text = 'Level ${level.id}'; refresh(state); case CHANGE(TEAM_LIFE(teamId, life)): if (teamId == ClassicGame.BOT) { diff --git a/src/client/haxe/ru/m/tankz/view/game/DeathGamePanel.hx b/src/client/haxe/ru/m/tankz/view/game/DeathGamePanel.hx index 081ba92..9935b16 100644 --- a/src/client/haxe/ru/m/tankz/view/game/DeathGamePanel.hx +++ b/src/client/haxe/ru/m/tankz/view/game/DeathGamePanel.hx @@ -16,8 +16,8 @@ import ru.m.tankz.view.common.LifeView; public function onGameEvent(event:GameEvent):Void { switch event { - case START(state): - level.text = 'Level ${state.levelId}'; + case START(state, level): + this.level.text = 'Level ${level.id}'; players.data = Lambda.array(state.players); case _: for (view in players.views) { diff --git a/src/client/haxe/ru/m/tankz/view/game/DotaGamePanel.hx b/src/client/haxe/ru/m/tankz/view/game/DotaGamePanel.hx index 2ce9242..8f06dc3 100644 --- a/src/client/haxe/ru/m/tankz/view/game/DotaGamePanel.hx +++ b/src/client/haxe/ru/m/tankz/view/game/DotaGamePanel.hx @@ -17,7 +17,6 @@ import ru.m.tankz.view.common.LifeView; @:view var level:LabelView; public function refresh(state:GameState):Void { - level.text = 'Level ${state.levelId}'; radiant.life = state.getTeamLife(DotaGame.RADIANT); radiant.score = state.getTeamScore(DotaGame.RADIANT); dire.life = state.getTeamLife(DotaGame.DIRE); @@ -34,7 +33,8 @@ import ru.m.tankz.view.common.LifeView; public function onGameEvent(event:GameEvent):Void { switch event { - case START(state): + case START(state, level): + this.level.text = 'Level ${level.id}'; refresh(state); case CHANGE(TEAM_LIFE(teamId, life)): getLifeView(teamId).life = life; diff --git a/src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx b/src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx index c084828..106399a 100644 --- a/src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/network/RoomListFrame.hx @@ -30,7 +30,7 @@ import ru.m.tankz.view.popup.CreateGamePopup; private function create():Void { CreateGamePopup.instance.show().then(function(result) { if (result != null) { - network.createGame(result.type, result.level); + network.createGame(result.type, result.level.id); } }); } diff --git a/src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx b/src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx index bd4f991..5979ec1 100644 --- a/src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx +++ b/src/client/haxe/ru/m/tankz/view/popup/CreateGamePopup.hx @@ -4,22 +4,25 @@ import haxework.view.DataView; import haxework.view.popup.PopupView; import haxework.view.ToggleButtonView; import ru.m.tankz.bundle.IConfigBundle; +import ru.m.tankz.bundle.ILevelBundle; +import ru.m.tankz.config.Config; import ru.m.tankz.Type; private typedef Result = { var type:GameType; - var level:LevelId; + var level:LevelConfig; } @:template class CreateGamePopup extends PopupView { @:view("type") var typeView:DataView; - @:view("level") var levelView:DataView; + @:view("level") var levelView:DataView; - @:provide var configBundle:IConfigBundle; + @:provide static var configBundle:IConfigBundle; + @:provide static var levelBundle:ILevelBundle; private var type:GameType; - private var level:LevelId; + private var level:LevelConfig; override private function onShow():Void { super.onShow(); @@ -43,18 +46,18 @@ private typedef Result = { for (v in typeView.dataViews) { v.on = v == view; } - levelView.data = [for (i in 0...configBundle.get(type).game.levels) i]; - onLevelSelect(0, 0, levelView.dataViews[0]); + levelView.data = levelBundle.get(value, "standard").data; + 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(); result.skinId = "button.level"; - result.text = Std.string(value); + result.text = Std.string(value.id); 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; for (v in levelView.dataViews) { v.on = v == view; diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 7c0e360..1cf0454 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -25,6 +25,7 @@ import ru.m.tankz.Type; public var config(default, null):Config; public var winner(default, null):Null; 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 = level.points != null ? level.points : config.points; + // ToDo: Spawner not in Team? + var points:Array = 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]); diff --git a/src/common/haxe/ru/m/tankz/game/GameEvent.hx b/src/common/haxe/ru/m/tankz/game/GameEvent.hx index bd3ed35..f43cd0b 100644 --- a/src/common/haxe/ru/m/tankz/game/GameEvent.hx +++ b/src/common/haxe/ru/m/tankz/game/GameEvent.hx @@ -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); diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index c27f487..8569821 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -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(); } diff --git a/src/common/haxe/ru/m/tankz/game/GameState.hx b/src/common/haxe/ru/m/tankz/game/GameState.hx index 0a25d21..06a44e1 100644 --- a/src/common/haxe/ru/m/tankz/game/GameState.hx +++ b/src/common/haxe/ru/m/tankz/game/GameState.hx @@ -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; public var players:Map; public var teams:Map; 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 = null) { + public function new(type:GameType, presetId:PresetId = 0, state:GameState = null, controls:Array = 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); diff --git a/src/common/haxe/ru/m/tankz/game/record/GamePlayer.hx b/src/common/haxe/ru/m/tankz/game/record/GamePlayer.hx index 52dbc31..686df35 100644 --- a/src/common/haxe/ru/m/tankz/game/record/GamePlayer.hx +++ b/src/common/haxe/ru/m/tankz/game/record/GamePlayer.hx @@ -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(); diff --git a/src/common/haxe/ru/m/tankz/game/record/GameRecorder.hx b/src/common/haxe/ru/m/tankz/game/record/GameRecorder.hx index ba3b7ce..10cbf43 100644 --- a/src/common/haxe/ru/m/tankz/game/record/GameRecorder.hx +++ b/src/common/haxe/ru/m/tankz/game/record/GameRecorder.hx @@ -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(); diff --git a/src/common/haxe/ru/m/tankz/util/LevelUtil.hx b/src/common/haxe/ru/m/tankz/util/LevelUtil.hx index e23244d..05b37de 100644 --- a/src/common/haxe/ru/m/tankz/util/LevelUtil.hx +++ b/src/common/haxe/ru/m/tankz/util/LevelUtil.hx @@ -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 { + var files = Reader.readZip(new BytesInput(bytes)); + return Lambda.array(files.map(extract)); + } } diff --git a/src/editor/haxe/ru/m/tankz/editor/view/MapFrame.hx b/src/editor/haxe/ru/m/tankz/editor/view/MapFrame.hx index 55dc7a5..b597d11 100644 --- a/src/editor/haxe/ru/m/tankz/editor/view/MapFrame.hx +++ b/src/editor/haxe/ru/m/tankz/editor/view/MapFrame.hx @@ -70,7 +70,7 @@ import ru.m.tankz.util.LevelUtil; private function open():Void { FileUtil.browse().then(function(content:FileContent) { fileName = content.name; - var data = LevelUtil.loads(config, content.content); + var data = LevelUtil.loads(content.content); mapView.gridSize = data.size; mapView.data = data; levelName.text = data.name; diff --git a/src/editor/haxe/ru/m/tankz/editor/view/map/MapEditView.hx b/src/editor/haxe/ru/m/tankz/editor/view/map/MapEditView.hx index e80c60d..02aa3ce 100644 --- a/src/editor/haxe/ru/m/tankz/editor/view/map/MapEditView.hx +++ b/src/editor/haxe/ru/m/tankz/editor/view/map/MapEditView.hx @@ -43,13 +43,13 @@ enum Brush { override private function set_config(value:Config):Config { var result = super.set_config(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; } override private function set_gridSize(value:GridSize):GridSize { 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; } @@ -104,7 +104,7 @@ enum Brush { private function get_data():LevelConfig { 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, size: gridSize, } @@ -114,7 +114,7 @@ enum Brush { reset(); pointEntities = new Map(); 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)); for (point in config.points) { switch point.type { diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx index cb10d26..cb186bf 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx @@ -13,7 +13,7 @@ class ServerConfigBundle implements IConfigBundle { public function new() {} 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 source:ConfigSource = Yaml.parse(data, Parser.options().useObjects()); return Config.fromSource(type, source); diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx index 353ac6f..dd9fd95 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx @@ -11,9 +11,13 @@ class ServerLevelBundle implements ILevelBundle { public function new() {} - public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig { - var path:String = FileSystem.absolutePath('./resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt'); - var data:String = File.getContent(path); - return LevelUtil.loads(config, data); + public function get(type:GameType, name:String):LevelPack { + var path = FileSystem.absolutePath('./levels/${type}_${name}.zip'); + var bytes = File.getBytes(path); + return { + type: type, + name: name, + data: LevelUtil.unpack(bytes), + }; } } diff --git a/src/server/haxe/ru/m/tankz/server/game/ServerGame.hx b/src/server/haxe/ru/m/tankz/server/game/ServerGame.hx index 3e7b9e9..255ff7a 100644 --- a/src/server/haxe/ru/m/tankz/server/game/ServerGame.hx +++ b/src/server/haxe/ru/m/tankz/server/game/ServerGame.hx @@ -1,5 +1,6 @@ package ru.m.tankz.server.game; +import ru.m.tankz.bundle.ILevelBundle; import ru.m.tankz.proto.room.RoomSlotProto; import ru.m.tankz.config.Config; import ru.m.tankz.core.EntityType; @@ -18,8 +19,10 @@ class ServerGame extends GameRunner { public var room(default, null):RoomProto; public var id(get, null):Int; + @:provide static var levelBundle:ILevelBundle; + 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.room = room; } @@ -84,7 +87,7 @@ class ServerGame extends GameRunner { var result = []; result.push(EventUtil.buildBricksSpawn(engine.map)); result = result.concat(EventUtil.buildCellsDestroyed(engine.map)); - result.push(START(state)); + result.push(START(state, level)); for (entity in engine.entities) { switch EntityTypeResolver.of(entity) { case EAGLE(eagle): result.push(EventUtil.buildEagleSpawn(eagle));