diff --git a/gulpfile.js b/gulpfile.js index 4df69b2..d8e2741 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,7 +42,7 @@ const config = new Project.Config({ 'src-gen/haxe', ], assets: [ - 'src/common/resources', + 'src/common/resources/config', ], flags: [ //'proto_debug', @@ -76,6 +76,7 @@ const client = new Project( main: 'ru.m.tankz.Client', preloader: 'ru.m.tankz.Preloader', assets: [ + 'src/common/resources/level', 'src/client/resources', ], meta: { @@ -138,6 +139,9 @@ const server = new Project( name: 'server', sources: ['src/server/haxe'], main: 'ru.m.tankz.server.Server', + resources: [ + 'src/common/resources/level', + ] }), ).bind(module, gulp); diff --git a/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx b/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx index 725258d..e09c990 100644 --- a/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx +++ b/src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx @@ -15,7 +15,7 @@ class ConfigBundle implements IConfigBundle { public function get(type:GameType):Config { if (!_cache.exists(type)) { - var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects()); + var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects()); _cache.set(type, Config.fromSource(type, source)); } return _cache.get(type); diff --git a/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx b/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx index aa529fe..ad74f84 100644 --- a/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx +++ b/src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx @@ -13,7 +13,7 @@ class LevelBundle implements ILevelBundle { public function new() {} private function resolve(id:PackId):LevelPack { - var bytes = Assets.getBytes('resources/level/${id}.zip'); + var bytes = Assets.getBytes('level/${id}.zip'); return { id: id, data: LevelUtil.unpack(bytes).map(function(level) { @@ -33,7 +33,7 @@ class LevelBundle implements ILevelBundle { public function list():Array { var result = []; for (path in Assets.list(AssetType.BINARY)) { - if (StringTools.startsWith(path, "resources/level")) { + if (StringTools.startsWith(path, "level")) { result.push(PackId.fromString(path.split("/").pop().split(".").shift())); } } diff --git a/src/client/haxe/ru/m/tankz/local/LocalGame.hx b/src/client/haxe/ru/m/tankz/local/LocalGame.hx index fe6b1d3..66af688 100644 --- a/src/client/haxe/ru/m/tankz/local/LocalGame.hx +++ b/src/client/haxe/ru/m/tankz/local/LocalGame.hx @@ -34,7 +34,7 @@ class LocalGame extends GameRunner { } if (humansTeams.length == 1 && result.winner == humansTeams[0]) { var progress = gameStorage.get(result.level.packId); - progress.completeLevel(result.level.id, result.state.presetId); + progress.completeLevel(result.level.id, result.state.presetId, {}); gameStorage.set(progress); } } diff --git a/src/common/haxe/ru/m/geom/GridPoint.hx b/src/common/haxe/ru/m/geom/GridPoint.hx new file mode 100644 index 0000000..1867191 --- /dev/null +++ b/src/common/haxe/ru/m/geom/GridPoint.hx @@ -0,0 +1,23 @@ +package ru.m.geom; + +abstract GridPoint({x:Int, y:Int}) { + public var x(get, set):Int; + public var y(get, set):Int; + + public function new(x:Int, y:Int) { + this = {x: x, y: y}; + } + + private inline function get_x():Int return this.x; + private inline function get_y():Int return this.y; + private inline function set_x(value:Int):Int return this.x = value; + private inline function set_y(value:Int):Int return this.y = value; + + @:to inline public function toInt():Int { + return (this.x << 16) + this.y; + } + + @:to inline public function toPoint():Point { + return new Point(this.x, this.y); + } +} diff --git a/src/common/haxe/ru/m/geom/Point.hx b/src/common/haxe/ru/m/geom/Point.hx index 20de2fc..862fd0f 100644 --- a/src/common/haxe/ru/m/geom/Point.hx +++ b/src/common/haxe/ru/m/geom/Point.hx @@ -1,14 +1,18 @@ package ru.m.geom; -class Point { - public var x(default, default):Float; - public var y(default, default):Float; +abstract Point(Array) { + public var x(get, set):Float; + public var y(get, set):Float; public function new(x:Float, y:Float) { - this.x = x; - this.y = y; + this = [x, y]; } + private inline function get_x():Float return this[0]; + private inline function get_y():Float return this[1]; + private inline function set_x(value:Float):Float return this[0] = value; + private inline function set_y(value:Float):Float return this[1] = value; + public function add(point:Point):Point { return new Point(x + point.x, y + point.y); } @@ -16,12 +20,4 @@ class Point { public function clone():Point { return new Point(x, y); } - - public function hashCode():Int { - return Std.int(x + 1000 * y); - } - - public function toString():String { - return 'Point{x=${Math.round(x * 100) / 100},y=${Math.round(y * 100) / 100}}'; - } } diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index ede8b59..464adf8 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -1,5 +1,6 @@ package ru.m.tankz.engine; +import ru.m.geom.GridPoint; import ru.m.geom.Direction; import ru.m.geom.Line; import ru.m.geom.Point; @@ -48,7 +49,7 @@ import ru.m.tankz.map.LevelMap; } public function destroyCell(x:Int, y:Int):Void { - var cell = map.grid.cells.get(new Point(x, y)); + var cell = map.grid.cells.get(new GridPoint(x, y)); cell.destroyed = true; destroySignal.emit(EntityTypeResolver.of(cell)); } diff --git a/src/common/haxe/ru/m/tankz/game/PackProgress.hx b/src/common/haxe/ru/m/tankz/game/PackProgress.hx index a3c196a..91929ad 100644 --- a/src/common/haxe/ru/m/tankz/game/PackProgress.hx +++ b/src/common/haxe/ru/m/tankz/game/PackProgress.hx @@ -34,13 +34,13 @@ class PackProgress { return completed.exists(levelId) && completed.get(levelId).presets.get(presetId) != null; } - public function completeLevel(levelId:LevelId, presetId:PresetId):Void { + public function completeLevel(levelId:LevelId, presetId:PresetId, result:LevelResult):Void { if (!completed.exists(levelId)) { completed[levelId] = { id: levelId, presets: new Map(), } } - completed[levelId].presets[presetId] = {}; + completed[levelId].presets[presetId] = result; } } diff --git a/src/common/haxe/ru/m/tankz/map/Brick.hx b/src/common/haxe/ru/m/tankz/map/Brick.hx index 1b878a2..e9679b2 100644 --- a/src/common/haxe/ru/m/tankz/map/Brick.hx +++ b/src/common/haxe/ru/m/tankz/map/Brick.hx @@ -1,7 +1,5 @@ package ru.m.tankz.map; -import haxe.ds.HashMap; -import ru.m.geom.Point; import ru.m.geom.Rectangle; import ru.m.tankz.config.Config; import ru.m.tankz.map.Grid.GridCell; @@ -16,11 +14,11 @@ class Brick { public var config(default, set):BrickConfig; public var rect(default, null):Rectangle; - public var cells(default, null):HashMap; + public var cells(default, null):Map; public var broken(get, null):Int; public var destroyed(get, set):Bool; - public function new(mapConfig:MapConfig, config:BrickConfig, cellX:Int, cellY:Int, cells:HashMap) { + public function new(mapConfig:MapConfig, config:BrickConfig, cellX:Int, cellY:Int, cells:Map) { this.cellX = cellX; this.cellY = cellY; this.cells = cells; diff --git a/src/common/haxe/ru/m/tankz/map/Grid.hx b/src/common/haxe/ru/m/tankz/map/Grid.hx index 51a34f9..928bf1e 100644 --- a/src/common/haxe/ru/m/tankz/map/Grid.hx +++ b/src/common/haxe/ru/m/tankz/map/Grid.hx @@ -1,15 +1,14 @@ package ru.m.tankz.map; -import haxe.ds.HashMap; +import ru.m.geom.GridPoint; import ru.m.geom.Line; -import ru.m.geom.Point; import ru.m.geom.Rectangle; class GridCell { public var cellX(default, null):Int; public var cellY(default, null):Int; - public var position(default, null):Point; + public var position(default, null):GridPoint; public var rect(default, null):Rectangle; public var layer:Int; public var armor:Float; @@ -18,7 +17,7 @@ class GridCell { public function new(cellX:Int, cellY:Int, width:Int, height:Int, layer:Int, armor:Float) { this.cellX = cellX; this.cellY = cellY; - this.position = new Point(cellX, cellY); + this.position = new GridPoint(cellX, cellY); this.rect = new Rectangle(cellX * width, cellY * height, width, height); this.layer = layer; this.armor = armor; @@ -47,7 +46,7 @@ class Grid { private var border:Rectangle; - public var cells(default, null):HashMap; + public var cells(default, null):Map; public function new(cellWidth:Int, cellHeight:Int, width:Int, height:Int) { this.cellWidth = cellWidth; @@ -55,7 +54,7 @@ class Grid { this.width = width; this.height = height; border = new Rectangle(0, 0, Math.floor(width / cellWidth) - 1, Math.floor(height / cellHeight) - 1); - cells = new HashMap(); + cells = new Map(); } private function buildBorderCell(cellX:Int, cellY:Int):GridCell { @@ -66,7 +65,7 @@ class Grid { var result:Array = []; for (x in Math.floor(line.point1.x / cellWidth)...Math.ceil(line.point2.x / cellWidth)) { for (y in Math.floor(line.point1.y / cellHeight)...Math.ceil(line.point2.y / cellHeight)) { - var point = new Point(x, y); + var point = new GridPoint(x, y); if (!border.contain(point)) { var cell = buildBorderCell(Std.int(point.x), Std.int(point.y)); cells.set(point, cell); diff --git a/src/common/haxe/ru/m/tankz/map/LevelMap.hx b/src/common/haxe/ru/m/tankz/map/LevelMap.hx index 68a6a66..80f10d2 100755 --- a/src/common/haxe/ru/m/tankz/map/LevelMap.hx +++ b/src/common/haxe/ru/m/tankz/map/LevelMap.hx @@ -1,6 +1,6 @@ package ru.m.tankz.map; -import haxe.ds.HashMap; +import ru.m.geom.GridPoint; import ru.m.geom.Point; import ru.m.tankz.config.Config; import ru.m.tankz.map.Grid; @@ -22,7 +22,7 @@ class LevelMap { public var grid(default, null):Grid; - private var bricksMap(default, null):HashMap; + private var bricksMap(default, null):Map; public function new(config:MapConfig, size:GridSize = null) { this.config = config; @@ -30,7 +30,7 @@ class LevelMap { cellHeight = config.cell.width; gridWidth = size != null ? size.width : config.grid.width; gridHeight = size != null ? size.height : config.grid.height; - bricksMap = new HashMap(); + bricksMap = new Map(); bricks = []; bricksById = new Map(); grid = new Grid( @@ -42,17 +42,17 @@ class LevelMap { } public function setData(data:Array):Void { - bricksMap = new HashMap(); + bricksMap = new Map(); bricks = Lambda.array(Lambda.mapi(data, function(i:Int, brickConfig:BrickConfig):Brick { var cellX = Std.int(i % gridWidth); var cellY = Std.int(Math.floor(i / gridWidth)); - var cells:HashMap = new HashMap(); + var cells:Map = new Map(); var point:Point = new Point(cellX * 2, cellY * 2); if (brickConfig.layer > 0 || brickConfig.armor > 0) { for (x in 0...2) for (y in 0...2) { var cell:GridCell = new GridCell(Std.int(point.x + x), Std.int(point.y + y), Std.int(cellWidth / 2), Std.int(cellHeight / 2), brickConfig.layer, brickConfig.armor); grid.cells.set(cell.position, cell); - cells.set(new Point(x, y), cell); + cells.set(new GridPoint(x, y), cell); } } var brick = new Brick(config, brickConfig, cellX, cellY, cells); @@ -68,7 +68,7 @@ class LevelMap { return bricks[Std.int(position.x + position.y * gridWidth)]; } - public function getCellBrick(position:Point):Brick { + public function getCellBrick(position:GridPoint):Brick { return bricksMap.get(position); } diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx index cb186bf..f015e5c 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerConfigBundle.hx @@ -13,7 +13,7 @@ class ServerConfigBundle implements IConfigBundle { public function new() {} public function get(type:GameType):Config { - var path:String = FileSystem.absolutePath('./resources/config/${type}.yaml'); + var path:String = FileSystem.absolutePath('./config/${type}.yaml'); var data:String = File.getContent(path); var source:ConfigSource = Yaml.parse(data, Parser.options().useObjects()); return Config.fromSource(type, source); diff --git a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx index e01d812..ca3f7d6 100644 --- a/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx +++ b/src/server/haxe/ru/m/tankz/server/bundle/ServerLevelBundle.hx @@ -12,7 +12,7 @@ class ServerLevelBundle implements ILevelBundle { public function new() {} public function get(id:PackId):LevelPack { - var path = FileSystem.absolutePath('./resources/level/${id}.zip'); + var path = FileSystem.absolutePath('./level/${id}.zip'); var bytes = File.getBytes(path); return { id: id, @@ -25,7 +25,7 @@ class ServerLevelBundle implements ILevelBundle { public function list():Array { var result = []; - for (path in FileSystem.readDirectory("./resources/level")) { + for (path in FileSystem.readDirectory("./level")) { result.push(PackId.fromString(path.split("/").pop().split(".").shift())); } return result;