From 5c57454998f72e4930cd08289930b50f9c995cb0 Mon Sep 17 00:00:00 2001 From: shmyga Date: Fri, 9 Feb 2018 10:59:25 +0300 Subject: [PATCH] [common] added Type bundle --- .../haxe/ru/m/tankz/control/HumanControl.hx | 11 +- .../haxe/ru/m/tankz/render/RenderItem.hx | 19 +- .../haxe/ru/m/tankz/view/frames/StartFrame.hx | 15 +- src/client/resources/classic/config.yaml | 170 +++++++++--------- src/client/resources/dota/config.yaml | 41 +++-- src/common/haxe/ru/m/tankz/PacketBuilder.hx | 18 +- src/common/haxe/ru/m/tankz/Type.hx | 22 +++ src/common/haxe/ru/m/tankz/bot/BotControl.hx | 16 +- src/common/haxe/ru/m/tankz/config/Config.hx | 26 ++- .../haxe/ru/m/tankz/config/ConfigBundle.hx | 14 +- .../haxe/ru/m/tankz/config/LevelBundle.hx | 9 +- src/common/haxe/ru/m/tankz/control/Control.hx | 7 +- src/common/haxe/ru/m/tankz/core/Bullet.hx | 6 +- src/common/haxe/ru/m/tankz/core/Eagle.hx | 2 +- src/common/haxe/ru/m/tankz/core/Entity.hx | 1 + src/common/haxe/ru/m/tankz/core/EntityType.hx | 2 +- src/common/haxe/ru/m/tankz/core/Tank.hx | 6 +- src/common/haxe/ru/m/tankz/engine/Engine.hx | 8 +- .../haxe/ru/m/tankz/game/ClassicGame.hx | 5 +- src/common/haxe/ru/m/tankz/game/DotaGame.hx | 3 +- src/common/haxe/ru/m/tankz/game/Game.hx | 24 +-- src/common/haxe/ru/m/tankz/game/GameState.hx | 7 +- src/common/haxe/ru/m/tankz/game/Player.hx | 2 +- src/common/haxe/ru/m/tankz/game/Spawner.hx | 4 +- src/common/haxe/ru/m/tankz/game/Team.hx | 4 +- 25 files changed, 214 insertions(+), 228 deletions(-) create mode 100644 src/common/haxe/ru/m/tankz/Type.hx diff --git a/src/client/haxe/ru/m/tankz/control/HumanControl.hx b/src/client/haxe/ru/m/tankz/control/HumanControl.hx index 2edf923..5582b3d 100644 --- a/src/client/haxe/ru/m/tankz/control/HumanControl.hx +++ b/src/client/haxe/ru/m/tankz/control/HumanControl.hx @@ -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; - class HumanControl extends Control { private var keyBinding:KeyBinding; diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index 31d5bc9..e5a1f21 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -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 { public var value(default, null):T; diff --git a/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx index d5c42d5..38ce4f6 100644 --- a/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx @@ -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 { diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml index 5d0c9d4..51dada7 100644 --- a/src/client/resources/classic/config.yaml +++ b/src/client/resources/classic/config.yaml @@ -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,91 +44,89 @@ bullet: &bullet piercing: 1 tanks: - human: - - type: 0 - width: 36 - height: 36 - speed: 2.5 - bullet: - <<: *bullet - speed: 8.0 - bullets: 1 - skin: pa + - type: human0 + width: 36 + height: 36 + speed: 2.5 + bullet: + <<: *bullet + speed: 8.0 + bullets: 1 + skin: pa - - type: 1 - width: 40 - height: 36 - speed: 3.0 - bullet: - <<: *bullet - speed: 8.5 - bullets: 1 - skin: pb + - type: human1 + width: 40 + height: 36 + speed: 3.0 + bullet: + <<: *bullet + speed: 8.5 + bullets: 1 + skin: pb - - type: 2 - width: 40 - height: 36 - speed: 3.0 - bullet: - <<: *bullet - speed: 9.0 - bullets: 2 - skin: pc + - type: human2 + width: 40 + height: 36 + speed: 3.0 + bullet: + <<: *bullet + speed: 9.0 + bullets: 2 + skin: pc - - type: 3 - width: 42 - height: 38 - speed: 2.9 - bullet: - <<: *bullet - speed: 9.0 - piercing: 3 - bullets: 2 - hits: 1 - skin: pd + - type: human3 + width: 42 + height: 38 + speed: 2.9 + bullet: + <<: *bullet + speed: 9.0 + piercing: 3 + bullets: 2 + hits: 1 + skin: pd - bot: - - type: 0 - width: 38 - height: 36 - speed: 2.0 - bullet: - <<: *bullet - speed: 7.0 - bullets: 1 - score: 100 - skin: ba + - type: bot0 + width: 38 + height: 36 + speed: 2.0 + bullet: + <<: *bullet + speed: 7.0 + bullets: 1 + score: 100 + skin: ba - - type: 1 - width: 40 - height: 36 - speed: 4.0 - bullet: - <<: *bullet - speed: 7.0 - bullets: 1 - score: 200 - skin: bb + - type: bot1 + width: 40 + height: 36 + speed: 4.0 + bullet: + <<: *bullet + speed: 7.0 + bullets: 1 + score: 200 + skin: bb - - type: 2 - width: 38 - height: 36 - speed: 2.0 - bullet: - <<: *bullet - speed: 9.0 - bullets: 1 - score: 300 - skin: bc + - type: bot2 + width: 38 + height: 36 + speed: 2.0 + bullet: + <<: *bullet + speed: 9.0 + bullets: 1 + score: 300 + skin: bc - - type: 3 - width: 40 - height: 36 - speed: 1.8 - bullet: - <<: *bullet - speed: 8.0 - bullets: 1 - score: 400 - hits: 3 - skin: bd + - type: bot3 + width: 40 + height: 36 + speed: 1.8 + bullet: + <<: *bullet + speed: 8.0 + bullets: 1 + score: 400 + hits: 3 + skin: bd diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml index 5fb237b..60b3433 100644 --- a/src/client/resources/dota/config.yaml +++ b/src/client/resources/dota/config.yaml @@ -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,23 +51,22 @@ bullet: &bullet piercing: 1 tanks: - any: - - type: 0 - width: 38 - height: 36 - speed: 2.0 - bullet: - <<: *bullet - speed: 10.0 - bullets: 1 - skin: bc + - type: slow + width: 38 + height: 36 + speed: 2.0 + bullet: + <<: *bullet + speed: 10.0 + bullets: 1 + skin: bc - - type: 1 - width: 40 - height: 36 - speed: 4.0 - bullet: - <<: *bullet - speed: 7.0 - bullets: 1 - skin: bb + - type: fast + width: 40 + height: 36 + speed: 4.0 + bullet: + <<: *bullet + speed: 7.0 + bullets: 1 + skin: bb diff --git a/src/common/haxe/ru/m/tankz/PacketBuilder.hx b/src/common/haxe/ru/m/tankz/PacketBuilder.hx index faa7db0..2913f64 100755 --- a/src/common/haxe/ru/m/tankz/PacketBuilder.hx +++ b/src/common/haxe/ru/m/tankz/PacketBuilder.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/Type.hx b/src/common/haxe/ru/m/tankz/Type.hx new file mode 100644 index 0000000..0d82d2f --- /dev/null +++ b/src/common/haxe/ru/m/tankz/Type.hx @@ -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; diff --git a/src/common/haxe/ru/m/tankz/bot/BotControl.hx b/src/common/haxe/ru/m/tankz/bot/BotControl.hx index ffdc1ec..b9d8a71 100644 --- a/src/common/haxe/ru/m/tankz/bot/BotControl.hx +++ b/src/common/haxe/ru/m/tankz/bot/BotControl.hx @@ -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; diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index adc77fd..9a29108 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -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; @:optional var spawnInterval:Int; @@ -83,7 +80,7 @@ class Config { public var points(default, null):Array; private var brickMap:Map; - private var tankMap:Map>; + private var tankMap:Map; private var teamMap:Map; 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()); - 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); } } diff --git a/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx b/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx index 3867d65..68c0fc2 100644 --- a/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx @@ -12,7 +12,7 @@ typedef ConfigSource = { var bricks: Array; var teams: Array; var points: Array; - var tanks: Dynamic>; + var tanks: Array; } 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 = []; - for (group in Reflect.fields(source.tanks)) { - var data:Array = 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); } } diff --git a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx index 2412766..067339f 100644 --- a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx @@ -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; } - class LevelBundle { private static function formatLevel(level:Int):String { diff --git a/src/common/haxe/ru/m/tankz/control/Control.hx b/src/common/haxe/ru/m/tankz/control/Control.hx index 39cdd72..0d1827b 100644 --- a/src/common/haxe/ru/m/tankz/control/Control.hx +++ b/src/common/haxe/ru/m/tankz/control/Control.hx @@ -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'; diff --git a/src/common/haxe/ru/m/tankz/core/Bullet.hx b/src/common/haxe/ru/m/tankz/core/Bullet.hx index b0f68e2..f054185 100644 --- a/src/common/haxe/ru/m/tankz/core/Bullet.hx +++ b/src/common/haxe/ru/m/tankz/core/Bullet.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/core/Eagle.hx b/src/common/haxe/ru/m/tankz/core/Eagle.hx index 16c6489..4a5701d 100644 --- a/src/common/haxe/ru/m/tankz/core/Eagle.hx +++ b/src/common/haxe/ru/m/tankz/core/Eagle.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/core/Entity.hx b/src/common/haxe/ru/m/tankz/core/Entity.hx index a369f34..e91850f 100755 --- a/src/common/haxe/ru/m/tankz/core/Entity.hx +++ b/src/common/haxe/ru/m/tankz/core/Entity.hx @@ -1,6 +1,7 @@ package ru.m.tankz.core; import ru.m.geom.Rectangle; +import Type; class Entity implements IKey { diff --git a/src/common/haxe/ru/m/tankz/core/EntityType.hx b/src/common/haxe/ru/m/tankz/core/EntityType.hx index 6b40605..03a6965 100644 --- a/src/common/haxe/ru/m/tankz/core/EntityType.hx +++ b/src/common/haxe/ru/m/tankz/core/EntityType.hx @@ -1,6 +1,6 @@ package ru.m.tankz.core; -import Type.ValueType; +import Type; import ru.m.tankz.map.Grid.GridCell; diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index f5a7e62..b1b87f6 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index a87c245..2ac4130 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -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: diff --git a/src/common/haxe/ru/m/tankz/game/ClassicGame.hx b/src/common/haxe/ru/m/tankz/game/ClassicGame.hx index 9a6e5d5..ab86ddd 100644 --- a/src/common/haxe/ru/m/tankz/game/ClassicGame.hx +++ b/src/common/haxe/ru/m/tankz/game/ClassicGame.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/game/DotaGame.hx b/src/common/haxe/ru/m/tankz/game/DotaGame.hx index 19440f5..934cb7e 100644 --- a/src/common/haxe/ru/m/tankz/game/DotaGame.hx +++ b/src/common/haxe/ru/m/tankz/game/DotaGame.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index 775e8a8..39e8c61 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -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; - -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 = 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 = 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); diff --git a/src/common/haxe/ru/m/tankz/game/GameState.hx b/src/common/haxe/ru/m/tankz/game/GameState.hx index 00cdfae..2555f06 100644 --- a/src/common/haxe/ru/m/tankz/game/GameState.hx +++ b/src/common/haxe/ru/m/tankz/game/GameState.hx @@ -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; var life:Int; var lose:Bool; } - class GameState { public var type:GameType; public var mode:GameMode; diff --git a/src/common/haxe/ru/m/tankz/game/Player.hx b/src/common/haxe/ru/m/tankz/game/Player.hx index 3f4cd41..20d5c28 100644 --- a/src/common/haxe/ru/m/tankz/game/Player.hx +++ b/src/common/haxe/ru/m/tankz/game/Player.hx @@ -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 { diff --git a/src/common/haxe/ru/m/tankz/game/Spawner.hx b/src/common/haxe/ru/m/tankz/game/Spawner.hx index f078717..74d6b76 100644 --- a/src/common/haxe/ru/m/tankz/game/Spawner.hx +++ b/src/common/haxe/ru/m/tankz/game/Spawner.hx @@ -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; diff --git a/src/common/haxe/ru/m/tankz/game/Team.hx b/src/common/haxe/ru/m/tankz/game/Team.hx index a174b5e..5b1a804 100644 --- a/src/common/haxe/ru/m/tankz/game/Team.hx +++ b/src/common/haxe/ru/m/tankz/game/Team.hx @@ -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 {