From 1f6e4fbc3d2d3c3126d04adeb014bab51f723c01 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 6 Feb 2018 17:41:45 +0300 Subject: [PATCH] [common] update level config, spawns points --- package.json | 2 +- .../haxe/ru/m/tankz/view/frames/StartFrame.hx | 2 +- src/client/resources/classic/config.yaml | 95 +++---------- src/client/resources/dota/config.yaml | 125 ++++-------------- src/client/resources/dota/levels/level001.txt | 3 +- src/client/resources/dota/levels/level002.txt | 3 +- src/common/haxe/ru/m/tankz/config/Config.hx | 20 ++- .../haxe/ru/m/tankz/config/ConfigBundle.hx | 3 +- .../haxe/ru/m/tankz/config/LevelBundle.hx | 46 +++++-- src/common/haxe/ru/m/tankz/game/Game.hx | 9 +- src/common/haxe/ru/m/tankz/game/Spawner.hx | 8 +- src/editor/haxe/ru/m/tankz/editor/Editor.hx | 43 ++++-- src/editor/haxe/ru/m/tankz/editor/Editor.yaml | 15 +++ .../haxe/ru/m/tankz/editor/MapEditView.hx | 110 +++++++++++++-- .../haxe/ru/m/tankz/editor/SpawnPointView.hx | 57 ++++++++ 15 files changed, 319 insertions(+), 222 deletions(-) create mode 100644 src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx diff --git a/package.json b/package.json index d023e26..c5c0d75 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tankz", - "version": "0.4.2", + "version": "0.5.0", "private": true, "devDependencies": { "ansi-colors": "^1.0.1", 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 1604343..d5c42d5 100644 --- a/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/StartFrame.hx @@ -55,7 +55,7 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame Provider.get(IFrameSwitcher).change(LevelFrame.ID); case DotaGame.TYPE: Provider.set(GameState, DotaGame.buildState(0, mode)); - Provider.get(IFrameSwitcher).change(GameFrame.ID); + Provider.get(IFrameSwitcher).change(LevelFrame.ID); } } } diff --git a/src/client/resources/classic/config.yaml b/src/client/resources/classic/config.yaml index 5f69e96..b733324 100644 --- a/src/client/resources/classic/config.yaml +++ b/src/client/resources/classic/config.yaml @@ -9,89 +9,34 @@ map: gridHeight: 26 bricks: - # border - - type: -1 - layer: 2 - armor: -1 - # none - - type: 0 - layer: 0 - armor: 0 - # ace - - type: 1 - layer: 0 - armor: 0 - # bush - - type: 2 - layer: 3 - armor: 0 - # water - - type: 3 - layer: 1 - armor: 0 - # armor - - type: 4 - layer: 2 - armor: 2 - # brick - - type: 5 - layer: 2 - armor: 1 + - {type: -1, layer: 2, armor: -1} # border + - {type: 0, layer: 0, armor: 0} # none + - {type: 1, layer: 0, armor: 0} # ace + - {type: 2, layer: 3, armor: 0} # bush + - {type: 3, layer: 1, armor: 0} # water + - {type: 4, layer: 2, armor: 2} # armor + - {type: 5, layer: 2, armor: 1} # brick teams: - id: human spawnInterval: 0 tanks: - - group: human - type: 0 - rate: 1 - points: - - type: eagle - index: -1 - x: 12 - y: 24 - direction: right - - type: tank - index: 0 - x: 8 - y: 24 - direction: top - - type: tank - index: 1 - x: 16 - y: 24 - direction: top + - {group: human, type: 0, 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 - points: - - type: tank - index: -1 - x: 0 - y: 0 - direction: bottom - - type: tank - index: -1 - x: 12 - y: 0 - direction: bottom - - type: tank - index: -1 - x: 24 - y: 0 - direction: bottom + - {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} + +points: + - {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24} + - {team: human, type: tank, index: 0, direction: top, x: 8, y: 24} + - {team: human, type: tank, index: 1, direction: top, x: 16, y: 24} + - {team: bot, type: tank, index: -1, direction: bottom, x: 0, y: 0} + - {team: bot, type: tank, index: -1, direction: bottom, x: 12, y: 0} + - {team: bot, type: tank, index: -1, direction: bottom, x: 24, y: 0} bullet: &bullet width: 12 diff --git a/src/client/resources/dota/config.yaml b/src/client/resources/dota/config.yaml index e815626..9ff2e9b 100644 --- a/src/client/resources/dota/config.yaml +++ b/src/client/resources/dota/config.yaml @@ -9,120 +9,41 @@ map: gridHeight: 30 bricks: - # border - - type: -1 - layer: 2 - armor: -1 - # none - - type: 0 - layer: 0 - armor: 0 - # ace - - type: 1 - layer: 0 - armor: 0 - # bush - - type: 2 - layer: 3 - armor: 0 - # water - - type: 3 - layer: 1 - armor: 0 - # armor - - type: 4 - layer: 2 - armor: 2 - # brick - - type: 5 - layer: 2 - armor: 1 + - {type: -1, layer: 2, armor: -1} # border + - {type: 0, layer: 0, armor: 0} # none + - {type: 1, layer: 0, armor: 0} # ace + - {type: 2, layer: 3, armor: 0} # bush + - {type: 3, layer: 1, armor: 0} # water + - {type: 4, layer: 2, armor: 2} # armor + - {type: 5, layer: 2, armor: 1} # brick team_tanks: &team_tanks tanks: - - group: any - type: 0 - rate: 0.25 - - group: any - type: 1 - rate: 0.25 - - group: any - type: 2 - rate: 0.25 - # - group: any - # type: 3 - # rate: 0.25 + - {group: any, type: 0, rate: 0.25} + - {group: any, type: 1, rate: 0.25} + - {group: any, type: 2, rate: 0.25} teams: - <<: *team_tanks id: radiant spawnInterval: 0 - points: - - type: eagle - index: -1 - x: 0 - y: 28 - direction: right - - type: tank - index: 0 - x: 0 - y: 0 - direction: right - - type: tank - index: 1 - x: 6 - y: 10 - direction: right - - type: tank - index: 2 - x: 6 - y: 16 - direction: right - - type: tank - index: 3 - x: 6 - y: 22 - direction: right - - type: tank - index: 4 - x: 10 - y: 28 - direction: right - <<: *team_tanks id: dire spawnInterval: 0 - points: - - type: eagle - index: -1 - x: 38 - y: 0 - direction: right - - type: tank - index: 0 - x: 38 - y: 28 - direction: left - - type: tank - index: 1 - x: 32 - y: 18 - direction: left - - type: tank - index: 2 - x: 32 - y: 12 - direction: left - - type: tank - index: 3 - x: 32 - y: 6 - direction: left - - type: tank - index: 4 - x: 28 - y: 0 - direction: left +points: + - {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28} + - {team: radiant, type: tank, index: 0, direction: right, x: 0, y: 0} + - {team: radiant, type: tank, index: 1, direction: right, x: 6, y: 10} + - {team: radiant, type: tank, index: 2, direction: right, x: 6, y: 16} + - {team: radiant, type: tank, index: 3, direction: right, x: 6, y: 22} + - {team: radiant, type: tank, index: 4, direction: right, x: 10, y: 28} + - {team: dire, type: eagle, index: -1, direction: right, x: 38, y: 0} + - {team: dire, type: tank, index: 0, direction: left, x: 38, y: 28} + - {team: dire, type: tank, index: 1, direction: left, x: 32, y: 18} + - {team: dire, type: tank, index: 2, direction: left, x: 32, y: 12} + - {team: dire, type: tank, index: 3, direction: left, x: 32, y: 6} + - {team: dire, type: tank, index: 4, direction: left, x: 28, y: 0} bullet: &bullet width: 12 diff --git a/src/client/resources/dota/levels/level001.txt b/src/client/resources/dota/levels/level001.txt index 046c1de..5e53819 100644 --- a/src/client/resources/dota/levels/level001.txt +++ b/src/client/resources/dota/levels/level001.txt @@ -1 +1,2 @@ -005500330033003300333300330033003300550000550033003300330033330033003300330055000000000000330033000000003300330000000000000000000033003300000000330033000000000000550033000000330000000033000000330055000055003300000033000000003300000033005500000000330000003300333300330000003300000000000033000000330033330033000000330000000055000000330033003333003300330000005500005500000033003300333300330033000000550000000033003300330033330033003300330000000000003300330033003333003300330033000000005500330000003300333300330000003300550000550033000000330033330033000000330055000000000000330033003333003300330000000000000000000033003300333300330033000000000000550033003300330033330033003300330055000055003300330033003333003300330033005500000000330033003300333300330033003300000000000033003300330033330033003300330000005555553300330033003333003300330033555555555555330033003300333300330033003355555555555533003300330033330033003300335555555555553300330033003333003300330033555555440000330033000000333300000033000000004444000033003300000033330000003300000000440000443300330000003333000000330033440000000044330033000000333300000033003344000000440033003300330033330033003300330044000044003300330033003333003300330033004400 \ No newline at end of file +points: [{index: -1, direction: right, team: radiant, type: eagle, y: 28, x: 0}, {index: 0, direction: right, team: radiant, type: tank, y: 2, x: 2}, {index: 1, direction: right, team: radiant, type: tank, y: 6, x: 2}, {index: 2, direction: right, team: radiant, type: tank, y: 10, x: 2}, {index: 3, direction: right, team: radiant, type: tank, y: 14, x: 2}, {index: 4, direction: right, team: radiant, type: tank, y: 18, x: 2}, {index: -1, direction: right, team: dire, type: eagle, y: 28, x: 38}, {index: 0, direction: left, team: dire, type: tank, y: 2, x: 36}, {index: 1, direction: left, team: dire, type: tank, y: 6, x: 36}, {index: 2, direction: left, team: dire, type: tank, y: 10, x: 36}, {index: 3, direction: left, team: dire, type: tank, y: 14, x: 36}, {index: 4, direction: left, team: dire, type: tank, y: 18, x: 36}] +data: "005500330033003300333300330033003300550000550033003300330033330033003300330055000000000000330033000000003300330000000000000000000033003300000000330033000000000000550033000000330000000033000000330055000055003300000033000000003300000033005500000000330000003300333300330000003300000000000033000000330033330033000000330000000055000000330033003333003300330000005500005500000033003300333300330033000000550000000033003300330033330033003300330000000000003300330033003333003300330033000000005500330000003300333300330000003300550000550033000000330033330033000000330055000000000000330033003333003300330000000000000000000033003300333300330033000000000000550033003300330033330033003300330055000055003300330033003333003300330033005500000000330033003300333300330033003300000000000033003300330033330033003300330000005555553300330033003333003300330033555555555555330033003300333300330033003355555555555533003300330033330033003300335555555555553300330033003333003300330033555555440000330033000000333300000033000000004444000033003300000033330000003300000000440000443300330000003333000000330033440000000044330033000000333300000033003344000000440033003300330033330033003300330044000044003300330033003333003300330033004400" diff --git a/src/client/resources/dota/levels/level002.txt b/src/client/resources/dota/levels/level002.txt index 4a80a0c..bc107a8 100644 --- a/src/client/resources/dota/levels/level002.txt +++ b/src/client/resources/dota/levels/level002.txt @@ -1 +1,2 @@ -000000000000000000000000000000440000000000000000000000000000000000000044000000000044003300005500440000440055000000000000004400330000550044000044005500000000000000000000440000000000000000000055004400000000000044000000000000000000005500440000003300000000330044003300440000000000000000330000000033004400330044000000000000000000440055000000000000000000005500003300000044005500000000000000000000550000330000000000000055000044005500440000004400000000000000005500004400550044000000440000555500003300000000000000000000000000555555550000330000000000000000000000000055550055440000004400330000000000003300445500005544000000440033000000000000330044550055550000440000000044004400550000000055555555000044000000004400440055000000005555000000000000000000000000000044000044000000000000000000000000000000004400004400000044000044000044005500004400000000000000004400004400004400550000440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003300000000550000330055003300005500440000330000000055000033005500330000550044000000440033000000440000000000440000000000000044003300000044000000000044000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file +data: "000000000000000000000000000000440000000000000000000000000000000000000044000000000044003300005500440000440055000000000000004400330000550044000044005500000000000000000000440000000000000000000055004400000000000044000000000000000000005500440000003300000000330044003300440000000000000000330000000033004400330044000000000000000000440055000000000000000000005500003300000044005500000000000000000000550000330000000000000055000044005500440000004400000000000000005500004400550044000000440000555500003300000000000000000000000000555555550000330000000000000000000000000055550055440000004400330000000000003300445500005544000000440033000000000000330044550055550000440000000044004400550000000055555555000044000000004400440055000000005555000000000000000000000000000044000044000000000000000000000000000000004400004400000044000044000044005500004400000000000000004400004400004400550000440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003300000000550000330055003300005500440000330000000055000033005500330000550044000000440033000000440000000000440000000000000044003300000044000000000044000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +points: [{direction: right, team: radiant, x: 0, type: eagle, y: 14, index: -1}, {direction: right, team: radiant, x: 0, type: tank, y: 0, index: 0}, {direction: right, team: radiant, x: 6, type: tank, y: 10, index: 1}, {direction: right, team: radiant, x: 6, type: tank, y: 16, index: 2}, {direction: right, team: radiant, x: 6, type: tank, y: 22, index: 3}, {direction: right, team: radiant, x: 10, type: tank, y: 28, index: 4}, {direction: right, team: dire, x: 38, type: eagle, y: 14, index: -1}, {direction: left, team: dire, x: 38, type: tank, y: 28, index: 0}, {direction: left, team: dire, x: 32, type: tank, y: 18, index: 1}, {direction: left, team: dire, x: 32, type: tank, y: 12, index: 2}, {direction: left, team: dire, x: 32, type: tank, y: 6, index: 3}, {direction: left, team: dire, x: 28, type: tank, y: 0, index: 4}] diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index d7e965d..df79144 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -7,6 +7,7 @@ typedef GameConfig = { } typedef SpawnPoint = { + var team:String; var type:String; var index:Int; var x:Int; @@ -59,7 +60,12 @@ typedef TeamConfig = { var size:Int; var spawnInterval:Int; var tanks:Array; - var points:Array; +} + + +typedef LevelConfig = { + var data:Array; + @:optional var points:Array; } @@ -70,17 +76,27 @@ class Config { public var bricks(default, null):Array; public var tanks(default, null):Array; public var teams(default, null):Array; + public var points(default, null):Array; private var brickMap:Map; private var tankMap:Map>; private var teamMap:Map; - public function new(type:String, game:GameConfig, map:MapConfig, bricks:Array, teams:Array, tanks:Array) { + public function new( + type:String, + game:GameConfig, + map:MapConfig, + bricks:Array, + teams:Array, + points:Array, + tanks:Array + ) { this.type = type; this.game = game; this.map = map; this.bricks = bricks; this.teams = teams; + this.points = points; this.tanks = tanks; init(); } diff --git a/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx b/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx index fd8911d..3867d65 100644 --- a/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/ConfigBundle.hx @@ -11,6 +11,7 @@ typedef ConfigSource = { var map: MapConfig; var bricks: Array; var teams: Array; + var points: Array; var tanks: Dynamic>; } @@ -30,6 +31,6 @@ class ConfigBundle { tanks.push(item); } } - return new Config(type, source.game, source.map, source.bricks, source.teams, tanks); + return new Config(type, source.game, source.map, source.bricks, source.teams, source.points, tanks); } } diff --git a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx index 10681cb..d9ec855 100644 --- a/src/common/haxe/ru/m/tankz/config/LevelBundle.hx +++ b/src/common/haxe/ru/m/tankz/config/LevelBundle.hx @@ -1,10 +1,19 @@ 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; +typedef LevelSource = { + var data:String; + @:optional var points:Array; +} + + class LevelBundle { private static function formatLevel(level:Int):String { @@ -13,27 +22,48 @@ class LevelBundle { return result; } - public static function loads(config:Config, data:String):Array { + public static function loadsOld(config:Config, data:String):LevelConfig { var bricks:Array = []; for (line in ~/\s+/g.split(data)) { for (c in line.split('')) { if (c.length > 0) { - bricks.push(config.bricks[Std.parseInt(c) + 1]); + bricks.push(config.getBrick(Std.parseInt(c))); } } } - return bricks; + return { + data: bricks + } } - public static function dumps(config:Config, bricks:Array):String { - return bricks.map(function(brick:BrickConfig) return brick.type).join(''); + public static function loads(config:Config, data:String):LevelConfig { + try { + var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects()); + return { + data: obj.data.split('').map(function(c) return config.getBrick(Std.parseInt(c))), + points: obj.points, + } + } catch (error:Dynamic) { + L.w('LevelBundle', '${error}'); + return loadsOld(config, data); + } } - public static function empty(config:Config):Array { - return [for (i in 0...config.map.gridWidth*config.map.gridHeight) config.bricks[1]]; + public static function dumps(config:Config, level:LevelConfig):String { + var bricksStr = level.data.map(function(brick:BrickConfig) return brick.type).join(''); + return Yaml.render({ + data: bricksStr, + points: level.points, + }, Renderer.options().setFlowLevel(1)); } - public static function get(type:GameType, config:Config, level:Int):Array { + public static function empty(config:Config):LevelConfig { + return { + data: [for (i in 0...config.map.gridWidth * config.map.gridHeight) config.bricks[1]] + } + } + + public static function get(type:GameType, config:Config, level:Int):LevelConfig { var data:String = Assets.getText('resources/${type}/levels/level${formatLevel(level)}.txt'); return loads(config, data); } diff --git a/src/common/haxe/ru/m/tankz/game/Game.hx b/src/common/haxe/ru/m/tankz/game/Game.hx index bd096fb..2ccd4fd 100644 --- a/src/common/haxe/ru/m/tankz/game/Game.hx +++ b/src/common/haxe/ru/m/tankz/game/Game.hx @@ -44,6 +44,7 @@ class Game implements EngineListener { public var config(default, null):Config; public var engine(default, null):Engine; + private var points:Array; private var spawners:Map; private var deferred:Deferred; private var stream:Stream; @@ -76,8 +77,9 @@ class Game implements EngineListener { public function start(state:GameState):Stream { this.deferred = new Deferred(); this.state = state; - var bricks = LevelBundle.get(type, config, state.level); - engine.map.setData(bricks); + var level = LevelBundle.get(type, config, state.level); + points = level.points != null ? level.points : config.points; + engine.map.setData(level.data); teams = new Map(); spawners = new Map(); var humanControlIndex = 0; @@ -101,7 +103,8 @@ class Game implements EngineListener { } } } - spawners[team.id] = new Spawner(team.config, spawn); + var teamPoints = points.filter(function(p:SpawnPoint) return p.team == team.id); + spawners[team.id] = new Spawner(team.config, teamPoints, spawn); } for (team in teams) { diff --git a/src/common/haxe/ru/m/tankz/game/Spawner.hx b/src/common/haxe/ru/m/tankz/game/Spawner.hx index 3d41b87..f078717 100644 --- a/src/common/haxe/ru/m/tankz/game/Spawner.hx +++ b/src/common/haxe/ru/m/tankz/game/Spawner.hx @@ -17,6 +17,7 @@ class Spawner { public var active(get, never):Bool; private var config:TeamConfig; + private var points:Array; private var runner:SpawnTask -> Void; private var queue:Array; private var timer:Timer; @@ -25,13 +26,14 @@ class Spawner { private var anyPoints:Array; private var index:Int; - public function new(config:TeamConfig, runner:SpawnTask -> Void) { + public function new(config:TeamConfig, points:Array, runner:SpawnTask -> Void) { this.config = config; + this.points = points; this.runner = runner; queue = []; indexedPoints = new Map(); anyPoints = []; - for (point in config.points) { + for (point in points) { if (point.type == 'tank') { if (point.index > -1) { indexedPoints.set(point.index, point); @@ -43,7 +45,7 @@ class Spawner { } public function getPoint(type:String, index:Int=-1):Null { - for (point in config.points) { + for (point in points) { if (point.type == type && point.index == index) { return point; } diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.hx b/src/editor/haxe/ru/m/tankz/editor/Editor.hx index 32cf2c6..d38be45 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.hx +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.hx @@ -1,6 +1,7 @@ package ru.m.tankz.editor; +import ru.m.tankz.editor.MapEditView.Brush; import ru.m.tankz.game.DotaGame; import haxework.gui.list.ListView; import haxework.gui.list.VListView; @@ -28,10 +29,10 @@ interface EditorViewLayout { var saveButton(default, null):ButtonView; var fileNameLabel(default, null):LabelView; var mapView(default, null):MapEditView; + var spawnPointList(default, null):VListView; var brickList(default, null):VListView; } - @:template("ru/m/tankz/editor/Editor.yaml") class EditorView extends GroupView implements ViewBuilder implements EditorViewLayout {} @@ -73,14 +74,38 @@ class Editor { view.saveButton.onPress = this; config = ConfigBundle.get(DotaGame.TYPE); - view.mapView.config = config.map; + view.mapView.config = config; view.mapView.data = LevelBundle.empty(config); view.brickList.data = config.bricks.filter(function(brick) return brick.type > -1); - view.mapView.brick = view.brickList.data[0]; - cast(view.brickList.items[0], BrickView).selected = true; + view.spawnPointList.data = config.points; - view.brickList.dispatcher.addListener(onBrickItemSelect); + var resetSelected = function() { + for (v in view.brickList.items) { + cast(v, BrickView).selected = false; + } + for (v in view.spawnPointList.items) { + cast(v, SpawnPointView).selected = false; + } + }; + + view.brickList.dispatcher.addListener({ + onListItemClick: function(item:IListItemView) { + view.mapView.brush = Brush.BRICK(item.data); + resetSelected(); + cast(item, BrickView).selected = true; } + }); + + view.spawnPointList.dispatcher.addListener({ + onListItemClick: function(item:IListItemView) { + view.mapView.brush = Brush.POINT(item.data); + resetSelected(); + cast(item, SpawnPointView).selected = true; + } + }); + + view.mapView.brush = Brush.BRICK(view.brickList.data[0]); + cast(view.brickList.items[0], BrickView).selected = true; } public function onPress(v:ButtonView):Void { @@ -100,12 +125,4 @@ class Editor { case _: } } - - private function onBrickItemSelect(item:IListItemView):Void { - view.mapView.brick = item.data; - for (v in view.brickList.items) { - cast(v, BrickView).selected = false; - } - cast(item, BrickView).selected = true; - } } diff --git a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml index 5759a4c..1508440 100644 --- a/src/editor/haxe/ru/m/tankz/editor/Editor.yaml +++ b/src/editor/haxe/ru/m/tankz/editor/Editor.yaml @@ -30,6 +30,21 @@ views: - $type: haxework.gui.HGroupView contentSize: true views: + - id: spawnPointList + $type: haxework.gui.list.VListView + factory: '@class:ru.m.tankz.editor.SpawnPointView' + width: 56 + pHeight: 100 + scroll: + $type: haxework.gui.list.VScrollView + width: 0 + pHeight: 100 + skin: + $type: haxework.gui.list.VScrollSkin + skin: + $type: haxework.gui.skin.ColorSkin + color: 0x000000 + alpha: 0.0 - id: mapView $type: ru.m.tankz.editor.MapEditView contentSize: true diff --git a/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx b/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx index 0b06d77..749f919 100644 --- a/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx +++ b/src/editor/haxe/ru/m/tankz/editor/MapEditView.hx @@ -1,5 +1,7 @@ package ru.m.tankz.editor; +import ru.m.geom.Rectangle; +import ru.m.tankz.core.Entity; import ru.m.geom.Point; import flash.events.MouseEvent; import ru.m.tankz.map.Brick; @@ -12,19 +14,71 @@ import ru.m.tankz.map.LevelMap; import haxework.gui.SpriteView; +class SpawnPointEntity extends Entity { + + public var point(default, null):SpawnPoint; + + public function new(point:SpawnPoint, rect:Rectangle) { + super(rect); + this.point = point; + } +} + +class SpawnPointItem extends BitmapItem { + + private var cellX:Int; + private var cellY:Int; + + public function new(value:SpawnPoint, config:MapConfig) { + super(new SpawnPointEntity(value, new Rectangle( + value.x * config.cellWidth, + value.y * config.cellHeight, + config.cellWidth * 2, + config.cellHeight * 2 + ))); + } + + override public function update():Void { + super.update(); + if (cellX != value.point.x || cellY != value.point.y) { + cellX = value.point.x; + cellY = value.point.y; + value.rect.x = cellX * (value.rect.width / 2); + value.rect.y = cellY * (value.rect.height / 2); + redraw(); + } + } + + override private function getImage():String { + return switch(value.point.type) { + case 'eagle': 'resources/images/eagle/eagle-0.png'; + case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png'; + case x: 'resources/images/eagle/eagle-1.png'; + } + } +} + + +enum Brush { + POINT(point:SpawnPoint); + BRICK(brick:BrickConfig); +} + + //ToDo: copy paste from ru.m.tankz.render.Render class MapEditView extends SpriteView { - public var config(default, set):MapConfig; - public var data(get, set):Array; + public var config(default, set):Config; + public var data(get, set):LevelConfig; public var map(default, null):LevelMap; - public var brick(default, default):BrickConfig; + public var brush(default, default):Brush; private var items:Map>; private var backgroundLayer:Sprite; private var upLayer:Sprite; private var groundLayer:Sprite; + private var spawnLayer:Sprite; public function new() { super(); @@ -33,9 +87,11 @@ class MapEditView extends SpriteView { backgroundLayer = new Sprite(); upLayer = new Sprite(); groundLayer = new Sprite(); + spawnLayer = new Sprite(); contentAsSprite.addChild(backgroundLayer); contentAsSprite.addChild(groundLayer); contentAsSprite.addChild(upLayer); + contentAsSprite.addChild(spawnLayer); contentAsSprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); reset(); } @@ -54,8 +110,20 @@ class MapEditView extends SpriteView { private function onMouseMove(event:MouseEvent):Void { var b = map.getPointBrick(new Point(event.localX, event.localY)); if (b != null) { - b.config = brick; - drawMap(); + switch (brush) { + case Brush.POINT(point): + for (p in config.points) { + if (p.team == point.team && p.type == point.type && p.index == point.index) { + p.x = b.cellX; + p.y = b.cellY; + drawMap(); + break; + } + } + case Brush.BRICK(brick): + b.config = brick; + drawMap(); + } } } @@ -70,6 +138,7 @@ class MapEditView extends SpriteView { items = new Map(); clearLayer(groundLayer); clearLayer(upLayer); + clearLayer(spawnLayer); } private function drawBackground():Void { @@ -114,25 +183,44 @@ class MapEditView extends SpriteView { } } } + for (point in config.points) { + var key = '${point.team}:${point.type}:${point.index}'; + if (!items.exists(key)) { + items[key] = new SpawnPointItem(point, config.map); + spawnLayer.addChild(items[key].view); + } + } for (item in items) { item.update(); } } - private function set_config(value:MapConfig):MapConfig { + private function set_config(value:Config):Config { config = value; - map = new LevelMap(config); + map = new LevelMap(config.map); invalidate(); return config; } - private function get_data():Array { - return map.bricks.map(function(brick:Brick) return brick.config); + private function get_data():LevelConfig { + return { + data: map.bricks.map(function(brick:Brick) return brick.config), + points: config.points, + } } - private function set_data(value:Array):Array { + private function set_data(value:LevelConfig):LevelConfig { reset(); - map.setData(value); + map.setData(value.data); + if (value.points != null) for (point in value.points) { + for (p in config.points) { + if (p.team == point.team && p.type == point.type && p.index == point.index) { + p.x = point.x; + p.y = point.y; + break; + } + } + } invalidate(); return value; } diff --git a/src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx b/src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx new file mode 100644 index 0000000..e4f524c --- /dev/null +++ b/src/editor/haxe/ru/m/tankz/editor/SpawnPointView.hx @@ -0,0 +1,57 @@ +package ru.m.tankz.editor; + +import flash.display.Bitmap; +import flash.display.Shape; +import haxework.gui.list.ListView; +import haxework.gui.SpriteView; +import openfl.utils.Assets; +import ru.m.tankz.config.Config; + + +class SpawnPointView extends SpriteView implements IListItemView { + + public var item_index(default, default):Int; + public var data(default, set):SpawnPoint; + public var selected(default, set):Bool; + + private var imageView:Bitmap; + private var selectView:Shape; + + public function new() { + super(); + width = 52; + height = 52; + selectView = createSelectView(width, height); + selectView.visible = false; + contentAsSprite.addChild(selectView); + imageView = new Bitmap(); + contentAsSprite.addChild(imageView); + } + + private static function createSelectView(width:Float, height:Float):Shape { + var view = new Shape(); + view.graphics.lineStyle(4, 0x33ff00); + view.graphics.drawRect(0, 0, width, height); + view.graphics.lineStyle(); + return view; + } + + private function set_data(value:SpawnPoint):SpawnPoint { + data = value; + var src = switch(value.type) { + case 'eagle': 'resources/images/eagle/eagle-0.png'; + case 'tank': 'resources/images/tank/bot/tank_b0_0-0.png'; + case x: 'resources/images/eagle/eagle-1.png'; + } + imageView.bitmapData = Assets.getBitmapData(src); + imageView.x = (width - imageView.width) / 2; + imageView.y = (height - imageView.height) / 2; + return data; + } + + private function set_selected(value:Bool):Bool { + selected = value; + selectView.visible = value; + return selected; + } +} \ No newline at end of file