[common] added Type bundle

This commit is contained in:
2018-02-09 10:59:25 +03:00
parent a7effef412
commit 5c57454998
25 changed files with 214 additions and 228 deletions

View File

@@ -1,18 +1,17 @@
package ru.m.tankz.control;
import ru.m.tankz.game.Game;
import ru.m.tankz.control.Control;
import haxe.Timer;
import ru.m.geom.Direction;
import flash.events.FocusEvent;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.Lib;
import flash.ui.Keyboard;
import haxe.Timer;
import ru.m.geom.Direction;
import ru.m.tankz.control.Control;
import ru.m.tankz.Type;
typedef KeyBinding = Map<Int, TankAction>;
class HumanControl extends Control {
private var keyBinding:KeyBinding;

View File

@@ -1,28 +1,25 @@
package ru.m.tankz.render;
import ru.m.draw.BitmapUtil;
import ru.m.tankz.game.Game.TeamId;
import ru.m.tankz.config.Config.TankType;
import ru.m.tankz.control.Control;
import flash.display.Sprite;
import ru.m.animate.Animate;
import ru.m.tankz.core.Eagle;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Shape;
import flash.display.Sprite;
import openfl.Assets;
import ru.m.animate.Animate;
import ru.m.draw.BitmapUtil;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
import ru.m.tankz.control.Control;
import ru.m.tankz.core.Bullet;
import ru.m.tankz.map.Brick;
import openfl.Assets;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Tank;
import flash.display.Bitmap;
import ru.m.tankz.map.Brick;
typedef TRectangle = {
var rect(default, null):Rectangle;
}
class RenderItem<T:TRectangle, D:DisplayObject> {
public var value(default, null):T;

View File

@@ -1,14 +1,14 @@
package ru.m.tankz.view.frames;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameState;
import haxework.gui.ButtonView;
import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.VGroupView;
import haxework.gui.ViewBuilder;
import haxework.provider.Provider;
import ru.m.tankz.game.ClassicGame;
import ru.m.tankz.game.DotaGame;
import haxework.gui.frame.IFrameSwitcher;
import haxework.provider.Provider;
import haxework.gui.ButtonView;
import haxework.gui.ViewBuilder;
import haxework.gui.VGroupView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
interface StartFrameLayout {
@@ -19,7 +19,6 @@ interface StartFrameLayout {
var dota_2p_vs(default, null):ButtonView;
}
@:template("layout/frames/start.json", "layout/styles.json")
class StartFrame extends VGroupView implements ViewBuilder implements StartFrameLayout {

View File

@@ -20,14 +20,14 @@ bricks:
teams:
- id: human
tanks:
- {group: human, type: 0, rate: 1}
- {type: human0, rate: 1}
- id: bot
spawnInterval: 3000
tanks:
- {group: bot, type: 0, rate: 0.5}
- {group: bot, type: 1, rate: 0.5}
- {group: bot, type: 2, rate: 0.5}
- {group: bot, type: 3, rate: 0.5}
- {type: bot0, rate: 0.5}
- {type: bot1, rate: 0.5}
- {type: bot2, rate: 0.5}
- {type: bot3, rate: 0.5}
points:
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
@@ -44,8 +44,7 @@ bullet: &bullet
piercing: 1
tanks:
human:
- type: 0
- type: human0
width: 36
height: 36
speed: 2.5
@@ -55,7 +54,7 @@ tanks:
bullets: 1
skin: pa
- type: 1
- type: human1
width: 40
height: 36
speed: 3.0
@@ -65,7 +64,7 @@ tanks:
bullets: 1
skin: pb
- type: 2
- type: human2
width: 40
height: 36
speed: 3.0
@@ -75,7 +74,7 @@ tanks:
bullets: 2
skin: pc
- type: 3
- type: human3
width: 42
height: 38
speed: 2.9
@@ -87,8 +86,7 @@ tanks:
hits: 1
skin: pd
bot:
- type: 0
- type: bot0
width: 38
height: 36
speed: 2.0
@@ -99,7 +97,7 @@ tanks:
score: 100
skin: ba
- type: 1
- type: bot1
width: 40
height: 36
speed: 4.0
@@ -110,7 +108,7 @@ tanks:
score: 200
skin: bb
- type: 2
- type: bot2
width: 38
height: 36
speed: 2.0
@@ -121,7 +119,7 @@ tanks:
score: 300
skin: bc
- type: 3
- type: bot3
width: 40
height: 36
speed: 1.8

View File

@@ -19,8 +19,8 @@ bricks:
team_tanks: &team_tanks
tanks:
- {group: any, type: 0, rate: 0.5}
- {group: any, type: 1, rate: 0.5}
- {type: slow, rate: 0.5}
- {type: fast, rate: 0.5}
teams:
- <<: *team_tanks
@@ -51,8 +51,7 @@ bullet: &bullet
piercing: 1
tanks:
any:
- type: 0
- type: slow
width: 38
height: 36
speed: 2.0
@@ -62,7 +61,7 @@ tanks:
bullets: 1
skin: bc
- type: 1
- type: fast
width: 40
height: 36
speed: 4.0

View File

@@ -1,20 +1,22 @@
package ru.m.tankz;
import ru.m.tankz.proto.pack.LeaveGameRequest;
import ru.m.tankz.proto.pack.LeaveGameResponse;
import ru.m.tankz.proto.pack.GameUpdateResponse;
import ru.m.tankz.proto.pack.GameActionRequest;
import ru.m.connect.IConnection;
import protohx.Message;
import ru.m.tankz.proto.pack.ErrorResponse;
import ru.m.tankz.proto.pack.GameListRequest;
import ru.m.tankz.proto.pack.GameListResponse;
import ru.m.connect.IConnection;
import ru.m.tankz.proto.pack.CreateGameRequest;
import ru.m.tankz.proto.pack.CreateGameResponse;
import ru.m.tankz.proto.pack.ErrorResponse;
import ru.m.tankz.proto.pack.GameActionRequest;
import ru.m.tankz.proto.pack.GameListRequest;
import ru.m.tankz.proto.pack.GameListResponse;
import ru.m.tankz.proto.pack.GameUpdateResponse;
import ru.m.tankz.proto.pack.JoinGameRequest;
import ru.m.tankz.proto.pack.JoinGameResponse;
import ru.m.tankz.proto.pack.LeaveGameRequest;
import ru.m.tankz.proto.pack.LeaveGameResponse;
import ru.m.tankz.proto.pack.StartGameRequest;
import ru.m.tankz.proto.pack.StartGameResponse;
import Type;
class PacketBuilder implements IPacketBuilder {

View File

@@ -0,0 +1,22 @@
package ru.m.tankz;
import ru.m.draw.Color;
typedef Type = Dynamic;
typedef GameType = String;
typedef TeamId = String;
typedef ControlType = String;
typedef TankType = String;
typedef PlayerId = {
var team:TeamId;
var type:ControlType;
var index:Int;
@:optional var color:Color;
}
typedef GameMode = Array<PlayerId>;

View File

@@ -1,14 +1,13 @@
package ru.m.tankz.bot;
import ru.m.tankz.core.Tank;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.game.Game;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.control.Control;
import ru.m.geom.Direction;
import haxe.Timer;
import ru.m.geom.Direction;
import ru.m.tankz.control.Control;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
import ru.m.tankz.core.Tank;
import ru.m.tankz.Type;
class BotHelper {
@@ -46,7 +45,6 @@ class BotHelper {
}
}
class BotControl extends Control {
private var shotTimer:Timer;

View File

@@ -1,6 +1,7 @@
package ru.m.tankz.config;
import ru.m.draw.Color;
import ru.m.tankz.Type;
typedef GameConfig = {
@@ -9,7 +10,7 @@ typedef GameConfig = {
}
typedef SpawnPoint = {
var team:String;
var team:TeamId;
var type:String;
var index:Int;
var x:Int;
@@ -37,13 +38,8 @@ typedef BulletConfig = {
var piercing:Int;
}
typedef TankType = {
var group:String;
var type:String;
}
typedef TankConfig = { > TankType,
typedef TankConfig = {
var type:TankType;
var width:Float;
var height:Float;
var speed:Float;
@@ -53,13 +49,14 @@ typedef TankConfig = { > TankType,
var skin:String;
}
typedef TankSpawn = { > TankType,
typedef TankSpawn = {
var type:TankType;
var rate: Float;
}
typedef TeamConfig = {
var id:String;
var id:TeamId;
var size:Int;
var tanks:Array<TankSpawn>;
@:optional var spawnInterval:Int;
@@ -83,7 +80,7 @@ class Config {
public var points(default, null):Array<SpawnPoint>;
private var brickMap:Map<Int, BrickConfig>;
private var tankMap:Map<String, Map<String, TankConfig>>;
private var tankMap:Map<TankType, TankConfig>;
private var teamMap:Map<String, TeamConfig>;
public function new(
@@ -116,8 +113,7 @@ class Config {
}
tankMap = new Map();
for (item in tanks) {
if (!tankMap.exists(item.group)) tankMap.set(item.group, new Map<String, TankConfig>());
tankMap.get(item.group).set(item.type, item);
tankMap.set(item.type, item);
}
}
@@ -129,7 +125,7 @@ class Config {
return teamMap.get(id);
}
public function getTank(group:String, type:String):TankConfig {
return tankMap.get(group).get(type);
public function getTank(type:TankType):TankConfig {
return tankMap.get(type);
}
}

View File

@@ -12,7 +12,7 @@ typedef ConfigSource = {
var bricks: Array<BrickConfig>;
var teams: Array<TeamConfig>;
var points: Array<SpawnPoint>;
var tanks: Dynamic<Array<TankConfig>>;
var tanks: Array<TankConfig>;
}
class ConfigBundle {
@@ -22,15 +22,7 @@ class ConfigBundle {
}
public static function get(type:String):Config {
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);
for (item in data) {
item.group = group;
tanks.push(item);
}
}
return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, tanks);
var source = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, source.tanks);
}
}

View File

@@ -1,11 +1,11 @@
package ru.m.tankz.config;
import yaml.Renderer;
import yaml.Parser;
import yaml.Yaml;
import openfl.Assets;
import ru.m.tankz.game.Game;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
import yaml.Parser;
import yaml.Renderer;
import yaml.Yaml;
typedef LevelSource = {
@@ -13,7 +13,6 @@ typedef LevelSource = {
@:optional var points:Array<SpawnPoint>;
}
class LevelBundle {
private static function formatLevel(level:Int):String {

View File

@@ -1,9 +1,9 @@
package ru.m.tankz.control;
import ru.m.tankz.game.Game;
import ru.m.geom.Direction;
import ru.m.tankz.core.Entity;
import ru.m.tankz.core.EntityType;
import ru.m.geom.Direction;
import ru.m.tankz.Type;
enum TankAction {
@@ -14,9 +14,6 @@ enum TankAction {
}
typedef ControlType = String;
class Control {
public static var NONE(default, never):ControlType = 'none';
public static var HUMAN(default, never):ControlType = 'human';

View File

@@ -1,9 +1,9 @@
package ru.m.tankz.core;
import ru.m.tankz.game.Game;
import ru.m.tankz.config.Config;
import ru.m.geom.Rectangle;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
class Bullet extends MobileEntity {

View File

@@ -1,7 +1,7 @@
package ru.m.tankz.core;
import ru.m.tankz.game.Game;
import ru.m.geom.Rectangle;
import ru.m.tankz.Type;
class Eagle extends Entity {

View File

@@ -1,6 +1,7 @@
package ru.m.tankz.core;
import ru.m.geom.Rectangle;
import Type;
class Entity implements IKey {

View File

@@ -1,6 +1,6 @@
package ru.m.tankz.core;
import Type.ValueType;
import Type;
import ru.m.tankz.map.Grid.GridCell;

View File

@@ -1,12 +1,12 @@
package ru.m.tankz.core;
import ru.m.draw.Color;
import ru.m.tankz.game.Game;
import ru.m.geom.Direction;
import ru.m.geom.Point;
import ru.m.geom.Rectangle;
import ru.m.tankz.config.Config;
import ru.m.tankz.core.Bullet;
import ru.m.geom.Rectangle;
import ru.m.geom.Direction;
import ru.m.tankz.Type;
class Tank extends MobileEntity {

View File

@@ -133,7 +133,13 @@ class Engine implements ControlHandler {
tank.move(direction);
case TankAction.LEVEL_UP(level):
// ToDo:
tank.config = config.getTank('human', Std.string(Std.int(Math.min(Std.parseInt(tank.config.type) + level, 3))));
var newType = switch(tank.config.type) {
case 'human0': 'human1';
case 'human1': 'human2';
case 'human2': 'human3';
case x: 'human3';
}
tank.config = config.getTank(newType);
case TankAction.STOP:
tank.stop();
case TankAction.SHOT:

View File

@@ -1,10 +1,11 @@
package ru.m.tankz.game;
import haxe.ds.Option;
import ru.m.draw.Color;
import ru.m.tankz.control.Control;
import haxe.ds.Option;
import ru.m.tankz.game.GameState.PlayerState;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameState.PlayerState;
import ru.m.tankz.Type;
class ClassicGame extends Game {

View File

@@ -1,10 +1,11 @@
package ru.m.tankz.game;
import haxe.ds.Option;
import ru.m.draw.Color;
import ru.m.tankz.control.Control;
import haxe.ds.Option;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
class DotaGame extends Game {

View File

@@ -1,6 +1,5 @@
package ru.m.tankz.game;
import ru.m.draw.Color;
import haxe.ds.Option;
import haxe.Timer;
import promhx.Deferred;
@@ -20,25 +19,12 @@ import ru.m.tankz.core.Tank;
import ru.m.tankz.engine.Engine;
import ru.m.tankz.game.GameState;
import ru.m.tankz.game.Spawner;
typedef GameType = String;
typedef GameMode = Array<PlayerId>;
typedef TeamId = String;
typedef PlayerId = {
var team:TeamId;
var type:ControlType;
var index:Int;
@:optional var color:Color;
}
import ru.m.tankz.Type;
class Game implements EngineListener {
private static var TAG(default, never):String = Type.getClassName(Game).split('.').pop();
private static var TAG(default, never):String = 'Game';
public var type(default, null):GameType;
public var state(default, null):GameState;
@@ -63,9 +49,9 @@ class Game implements EngineListener {
}
private function buildTank(playerId:PlayerId, point:SpawnPoint):Tank {
var types:Array<TankSpawn> = teams[playerId.team].config.tanks;
var type:TankSpawn = types[Math.floor(Math.random() * types.length)];
var tankConfig:TankConfig = config.getTank(type.group, type.type);
var spawns:Array<TankSpawn> = teams[playerId.team].config.tanks;
var spawn:TankSpawn = spawns[Math.floor(Math.random() * spawns.length)];
var tankConfig:TankConfig = config.getTank(spawn.type);
var tank = new Tank(playerId, tankConfig);
tank.color = playerId.color.zero ? teams[playerId.team].config.color : playerId.color;
applyPoint(tank, point);

View File

@@ -1,9 +1,6 @@
package ru.m.tankz.game;
import ru.m.tankz.game.Game;
typedef ControlType = String;
import ru.m.tankz.Type;
typedef PlayerState = {
@@ -11,14 +8,12 @@ typedef PlayerState = {
var life:Int;
}
typedef TeamState = {
var players:Map<Int, PlayerState>;
var life:Int;
var lose:Bool;
}
class GameState {
public var type:GameType;
public var mode:GameMode;

View File

@@ -1,7 +1,7 @@
package ru.m.tankz.game;
import ru.m.tankz.control.Control;
import ru.m.tankz.game.Game;
import ru.m.tankz.Type;
class Player {

View File

@@ -1,9 +1,8 @@
package ru.m.tankz.game;
import haxe.Timer;
import ru.m.tankz.game.Game;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
typedef SpawnTask = {
@@ -11,7 +10,6 @@ typedef SpawnTask = {
var playerId:PlayerId;
}
class Spawner {
public var active(get, never):Bool;

View File

@@ -1,8 +1,8 @@
package ru.m.tankz.game;
import ru.m.tankz.config.Config.TeamConfig;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.Player;
import ru.m.tankz.game.Game;
import ru.m.tankz.Type;
class Team {