[client] LevelFrame

This commit is contained in:
2018-01-26 14:38:36 +03:00
parent d72d7e8c81
commit 6a00ee83d7
50 changed files with 120 additions and 65 deletions

View File

@@ -54,6 +54,7 @@ typedef TeamConfig = {
class Config {
public var type(default, null):String;
public var levels(default, null):Int;
public var map(default, null):MapConfig;
public var bricks(default, null):Array<BrickConfig>;
public var tanks(default, null):Array<TankConfig>;
@@ -63,8 +64,9 @@ class Config {
private var tankMap:Map<String, Map<String, TankConfig>>;
private var teamMap:Map<String, TeamConfig>;
public function new(type:String, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
public function new(type:String, levels:Int, map:MapConfig, bricks:Array<BrickConfig>, teams:Array<TeamConfig>, tanks:Array<TankConfig>) {
this.type = type;
this.levels = levels;
this.map = map;
this.bricks = bricks;
this.teams = teams;

View File

@@ -8,6 +8,7 @@ import ru.m.tankz.config.Config;
typedef ConfigSource = {
var levels:Int;
var map: MapConfig;
var bricks: Array<BrickConfig>;
var teams: Array<TeamConfig>;
@@ -23,7 +24,7 @@ class ConfigBundle {
public static function get(type:String):Config {
switch (type) {
case ClassicGame.TYPE:
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects()));
var source:ConfigSource = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
var tanks:Array<TankConfig> = [];
for (group in Reflect.fields(source.tanks)) {
var data:Array<TankConfig> = Reflect.field(source.tanks, group);
@@ -32,7 +33,7 @@ class ConfigBundle {
tanks.push(item);
}
}
return new Config(type, source.map, source.bricks, source.teams, tanks);
return new Config(type, source.levels, source.map, source.bricks, source.teams, tanks);
case _:
return null;
}

View File

@@ -5,10 +5,16 @@ import ru.m.tankz.game.Game;
import ru.m.tankz.config.Config;
class MapBundle {
class LevelBundle {
private static function formatLevel(level:Int):String {
var result = Std.string(level);
while (result.length < 3) result = '0${result}';
return result;
}
public static function get(type:GameType, config:Config, level:Int):Array<BrickConfig> {
var bricksData:String = Assets.getText('resources/levels/level00${level}.txt');
var bricksData:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt');
var bricks:Array<BrickConfig> = [];
for (line in ~/\s+/g.split(bricksData)) {
for (c in line.split('')) {

View File

@@ -3,7 +3,7 @@ package ru.m.tankz.game;
import ru.m.tankz.bot.BotControl;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.config.ConfigBundle;
import ru.m.tankz.config.MapBundle;
import ru.m.tankz.config.LevelBundle;
import ru.m.tankz.game.Spawner;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.Eagle;
@@ -60,7 +60,7 @@ class Game implements EngineListener {
public function start(state:GameState):Void {
this.state = state;
var bricks = MapBundle.get(type, config, state.level);
var bricks = LevelBundle.get(type, config, state.level);
engine.map.setData(bricks);
teams = new Map<TeamId, Team>();
spawners = new Map<TeamId, Spawner>();