[common] added LevelPack

This commit is contained in:
2019-06-14 16:06:22 +03:00
parent 4c3f1ca0fc
commit e39de4467d
82 changed files with 1321 additions and 1149 deletions

View File

@@ -8,6 +8,8 @@ typedef TeamId = String;
typedef BrickType = String;
typedef BrickIndex = Int;
typedef TankType = String;
typedef BonusType = String;

View File

@@ -4,5 +4,5 @@ import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
interface ILevelBundle {
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig;
public function get(type:GameType, name:String):LevelPack;
}

View File

@@ -108,12 +108,18 @@ typedef GamePreset = {
typedef LevelConfig = {
@:optional var id:LevelId;
var data:Array<BrickConfig>;
var data:Array<BrickIndex>;
@:optional var name:String;
@:optional var points:Array<SpawnPoint>;
@:optional var size:{width:Int, height:Int};
}
typedef LevelPack = {
var type:GameType;
var name:String;
var data:Array<LevelConfig>;
}
typedef PlayerControl = {
var playerId:PlayerId;
var control:String;

View File

@@ -51,7 +51,8 @@ class GameRunner extends Game implements EngineListener {
override public function start():Void {
super.start();
engine.map.setData(state.level.data);
var mapData = state.level.data.map(function(index:BrickIndex) return config.getBrickByIndex(index));
engine.map.setData(mapData);
for (team in teams.iterator()) {
team.spawner.runner = spawn;
for (player in team.players.iterator()) {
@@ -135,7 +136,8 @@ class GameRunner extends Game implements EngineListener {
for (team in teams.iterator()) {
if (team.isAlive) {
if (team.eagleId > -1) {
if (!cast(engine.entities[team.eagleId], Eagle).death) {
var eagle:Eagle = engine.getEntity(team.eagleId);
if (!eagle.death) {
actives.push(team.id);
}
} else {
@@ -148,12 +150,6 @@ class GameRunner extends Game implements EngineListener {
case []: complete(null);
case _:
}
/*if (actives.length == 1) {
complete(actives[0]);
}
if (actives.length == 0) {
complete(null);
}*/
}
private function complete(winner:TeamId):Void {

View File

@@ -72,21 +72,20 @@ class GameState {
public var type:GameType;
public var presetId:PresetId;
public var levelId:LevelId;
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(get, null):LevelConfig;
public var level(default, default):LevelConfig;
@:provide static private var configBundle:IConfigBundle;
@:provide static private var levelBundle:ILevelBundle;
public function new(type:GameType, presetId:PresetId = 0, levelId:Int = 0, state:GameState = null, controls:Array<PlayerControl> = null) {
public function new(type:GameType, presetId:PresetId = 0, level:LevelConfig = null, state:GameState = null, controls:Array<PlayerControl> = null) {
this.type = type;
this.presetId = presetId;
this.levelId = levelId;
this.level = level;
//this.controls = controls == null ? config.controls[0].values : controls;
this.controls = controls == null ? [] : controls;
if (state == null) {
@@ -118,8 +117,8 @@ class GameState {
return configBundle.get(type);
}
private function get_level():LevelConfig {
return levelBundle.get(type, config, levelId);
private function get_levelId():LevelId {
return level == null ? 0 : level.id;
}
public function getTeamLife(id:TeamId):Int {

View File

@@ -32,7 +32,7 @@ class GameRecord {
}
private inline function get_state():GameState {
return new GameState(info.type, info.presetId, info.levelId);
return new GameState(info.type, info.presetId);
}
public function toString():String {

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.map;
import ru.m.tankz.Type.BrickType;
import haxe.ds.HashMap;
import ru.m.tankz.map.Grid;
import ru.m.geom.Point;

View File

@@ -1,6 +1,7 @@
package ru.m.tankz.util;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
import yaml.Parser;
import yaml.Renderer;
import yaml.Yaml;
@@ -20,12 +21,12 @@ class LevelUtil {
return result;
}
public static function loadsOld(config:Config, data:String):LevelConfig {
var bricks:Array<BrickConfig> = [];
public static function loadsOld(data:String):LevelConfig {
var bricks:Array<BrickIndex> = [];
for (line in ~/\s+/g.split(data)) {
for (c in line.split('')) {
if (c.length > 0) {
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
bricks.push(Std.parseInt(c));
}
}
}
@@ -34,22 +35,22 @@ class LevelUtil {
}
}
public static function loads(config:Config, data:String):LevelConfig {
if (config.type == 'classic') {
return loadsOld(config, data);
} else {
public static function loads(data:String):LevelConfig {
try {
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
return {
data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))),
data: obj.data.split('').map(function(c) return Std.parseInt(c)),
points: obj.points,
name: obj.name,
size: obj.size,
}
} catch (error:Dynamic) {
return loadsOld(data);
}
}
public static function dumps(config:Config, level:LevelConfig):String {
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.index)).join('');
var bricksStr = level.data.join('');
return Yaml.render({
data: bricksStr,
points: level.points,
@@ -58,7 +59,7 @@ class LevelUtil {
}, Renderer.options().setFlowLevel(1));
}
public static function empty(size:GridSize, filler:BrickConfig):LevelConfig {
public static function empty(size:GridSize, filler:BrickIndex):LevelConfig {
return {
data: [for (i in 0...size.width * size.height) filler],
size: size,

View File

@@ -1,5 +1,4 @@
game:
levels: 36
friendlyFire: false
complete:
- team: human

View File

@@ -1,5 +1,4 @@
game:
levels: 4
friendlyFire: true
complete:
- team: alpha

View File

@@ -1,5 +1,4 @@
game:
levels: 23
friendlyFire: true
complete:
- team: radiant