[common] add map size

This commit is contained in:
2019-06-11 17:29:18 +03:00
parent 2c42d993ca
commit a66b72ba22
19 changed files with 143 additions and 62 deletions

View File

@@ -29,6 +29,8 @@ import ru.m.tankz.util.LevelUtil;
@:view var mapView:MapEditView;
@:view var spawnPointList:DataView<SpawnPoint, SpawnPointView>;
@:view var brickList:DataView<BrickConfig, BrickView>;
@:view("width") var widthInput:InputView;
@:view("height") var heightInput:InputView;
@:provide var configBundle:IConfigBundle;
@:provide var config:Config;
@@ -68,7 +70,6 @@ import ru.m.tankz.util.LevelUtil;
config = configBundle.get(type);
mapView.config = config;
mapView.data = LevelUtil.empty(config);
brickList.data = config.bricks.filter(function(brick) return brick.index > -1);
spawnPointList.data = config.points;
@@ -90,6 +91,13 @@ import ru.m.tankz.util.LevelUtil;
var data = LevelUtil.loads(config, content.content);
mapView.data = data;
levelName.text = data.name;
/*if (data.size != null) {
widthInput.text = Std.string(data.size.width);
heightInput.text = Std.string(data.size.height);
} else {
widthInput.text = "";
heightInput.text = "";
}*/
});
case 'saveButton':
L.d(TAG, 'SAVE');
@@ -102,4 +110,12 @@ import ru.m.tankz.util.LevelUtil;
case _:
}
}
private function applySize():Void {
mapView.gridSize = {width: Std.parseInt(widthInput.text), height: Std.parseInt(heightInput.text)};
}
private function resetSize():Void {
mapView.gridSize = null;
}
}

View File

@@ -30,6 +30,24 @@ views:
geometry.size.width: 300
geometry.size.height: 26
text: ""
- $type: haxework.view.HGroupView
views:
- id: width
$type: haxework.view.InputView
skinId: text.box
geometry.size.fixed: [50, 26]
- id: height
$type: haxework.view.InputView
skinId: text.box
geometry.size.fixed: [50, 26]
- $type: haxework.view.ButtonView
skinId: button.simple
text: apply
+onPress: "$code:applySize()"
- $type: haxework.view.ButtonView
skinId: button.simple
text: reset
+onPress: "$code:resetSize()"
# map
- $type: haxework.view.HGroupView
views:

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.editor.level;
import ru.m.tankz.util.LevelUtil;
import flash.display.Graphics;
import flash.events.MouseEvent;
import ru.m.geom.Point;
@@ -40,21 +41,31 @@ enum Brush {
}
override private function set_config(value:Config):Config {
var result = super.set_config(value);
builder = new EntityBuilder(value);
return super.set_config(value);
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]);
return result;
}
override private function set_gridSize(value:GridSize):GridSize {
var result = super.set_gridSize(value);
data = LevelUtil.empty(gridSize != null ? gridSize : config.map.grid, config.bricks[1]);
return result;
}
override private function drawBackground():Void {
super.drawBackground();
var g:Graphics = backgroundLayer.graphics;
g.lineStyle(1, 0x007700);
for (x in 0...config.map.gridWidth) {
g.moveTo(x * config.map.cellWidth, 0);
g.lineTo(x * config.map.cellWidth, config.mapHeight);
var gridWidth = gridSize != null ? gridSize.width : config.map.grid.width;
var gridHeight = gridSize != null ? gridSize.height : config.map.grid.height;
for (x in 0...gridWidth) {
g.moveTo(x * config.map.cell.width, 0);
g.lineTo(x * config.map.cell.height, mapHeight);
}
for (y in 0...config.map.gridHeight) {
g.moveTo(0, y * config.map.cellHeight);
g.lineTo(config.mapWidth, y * config.map.cellHeight);
for (y in 0...gridHeight) {
g.moveTo(0, y * config.map.cell.height);
g.lineTo(mapWidth, y * config.map.cell.height);
}
}
@@ -95,6 +106,7 @@ enum Brush {
return {
data: map.bricks.map(function(brick:Brick) return brick.config),
points: config.points,
size: gridSize,
}
}
@@ -102,8 +114,8 @@ enum Brush {
reset();
pointEntities = new Map();
map = new LevelMap(config.map);
setContentSize(map.gridWidth * map.cellWidth, map.gridHeight * map.cellHeight, "map");
map.setData(value.data);
gridSize = value.size;
gameEventSignal.emit(EventUtil.buildBricksSpawn(map));
for (point in config.points) {
switch point.type {