[editor] update spwan view

This commit is contained in:
2018-02-07 21:47:13 +03:00
parent baf696a3e1
commit 3096fba7c5
4 changed files with 34 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
package ru.m.tankz.render; package ru.m.tankz.render;
import ru.m.tankz.game.Game.TeamId;
import ru.m.tankz.config.Config.TankType;
import ru.m.tankz.control.Control; import ru.m.tankz.control.Control;
import flash.display.Sprite; import flash.display.Sprite;
import ru.m.animate.Animate; import ru.m.animate.Animate;
@@ -155,10 +157,8 @@ class TankItem extends RenderItem<Tank, Sprite> {
tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s)); tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
} }
private function getFrames():Array<String> { public static function getTankFrames(team:TeamId, index:Int, type:TankType, hits:Int=0):Array<String> {
var team = value.playerId.team; var group = type.group;
var group = value.config.group;
var index = value.playerId.index;
if (team == 'radiant') { if (team == 'radiant') {
index = 0; index = 0;
} }
@@ -169,14 +169,18 @@ class TankItem extends RenderItem<Tank, Sprite> {
group = 'player'; group = 'player';
} }
if (team == 'bot') { if (team == 'bot') {
index = value.hits; index = hits;
} }
return [ return [
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-0.png', 'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-0.png',
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-1.png', 'resources/images/tank/${group}/tank_${group.charAt(0)}${type.type}_${index}-1.png',
]; ];
} }
private function getFrames():Array<String> {
return getTankFrames(value.playerId.team, value.playerId.index, value.config, value.hits);
}
override public function update():Void { override public function update():Void {
super.update(); super.update();
var t = value.config.type; var t = value.config.type;

View File

@@ -107,6 +107,8 @@ class Editor {
private function setGameType(type:GameType):Void { private function setGameType(type:GameType):Void {
config = ConfigBundle.get(type); config = ConfigBundle.get(type);
Provider.set(Config, config);
view.mapView.config = config; view.mapView.config = config;
view.mapView.data = LevelBundle.empty(config); view.mapView.data = LevelBundle.empty(config);

View File

@@ -28,16 +28,27 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
private var cellX:Int; private var cellX:Int;
private var cellY:Int; private var cellY:Int;
private var src:String;
public function new(value:SpawnPoint, config:MapConfig) { public function new(value:SpawnPoint, config:Config) {
src = getSrc(value, config);
super(new SpawnPointEntity(value, new Rectangle( super(new SpawnPointEntity(value, new Rectangle(
value.x * config.cellWidth, value.x * config.map.cellWidth,
value.y * config.cellHeight, value.y * config.map.cellHeight,
config.cellWidth * 2, config.map.cellWidth * 2,
config.cellHeight * 2 config.map.cellHeight * 2
))); )));
} }
public static function getSrc(value:SpawnPoint, config:Config):String {
var tankType = config.getTeam(value.team).tanks[0];
return switch(value.type) {
case 'eagle': 'resources/images/eagle/eagle-0.png';
case 'tank': TankItem.getTankFrames(value.team, value.index, tankType)[0];
case x: 'resources/images/eagle/eagle-1.png';
}
}
override public function update():Void { override public function update():Void {
super.update(); super.update();
if (cellX != value.point.x || cellY != value.point.y) { if (cellX != value.point.x || cellY != value.point.y) {
@@ -50,11 +61,7 @@ class SpawnPointItem extends BitmapItem<SpawnPointEntity> {
} }
override private function getImage():String { override private function getImage():String {
return switch(value.point.type) { return src;
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';
}
} }
} }
@@ -186,7 +193,7 @@ class MapEditView extends SpriteView {
for (point in config.points) { for (point in config.points) {
var key = '${point.team}:${point.type}:${point.index}'; var key = '${point.team}:${point.type}:${point.index}';
if (!items.exists(key)) { if (!items.exists(key)) {
items[key] = new SpawnPointItem(point, config.map); items[key] = new SpawnPointItem(point, config);
spawnLayer.addChild(items[key].view); spawnLayer.addChild(items[key].view);
} }
} }

View File

@@ -1,5 +1,7 @@
package ru.m.tankz.editor; package ru.m.tankz.editor;
import haxework.provider.Provider;
import ru.m.tankz.editor.MapEditView.SpawnPointItem;
import flash.display.Bitmap; import flash.display.Bitmap;
import flash.display.Shape; import flash.display.Shape;
import haxework.gui.list.ListView; import haxework.gui.list.ListView;
@@ -38,11 +40,7 @@ class SpawnPointView extends SpriteView implements IListItemView<SpawnPoint> {
private function set_data(value:SpawnPoint):SpawnPoint { private function set_data(value:SpawnPoint):SpawnPoint {
data = value; data = value;
var src = switch(value.type) { var src = SpawnPointItem.getSrc(value, Provider.get(Config));
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.bitmapData = Assets.getBitmapData(src);
imageView.x = (width - imageView.width) / 2; imageView.x = (width - imageView.width) / 2;
imageView.y = (height - imageView.height) / 2; imageView.y = (height - imageView.height) / 2;