Compare commits
21 Commits
event_prot
...
0.15.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 91dd84a437 | |||
| 1b36016a1a | |||
| db0adbac30 | |||
| 948648b313 | |||
| 73822dc95a | |||
| 282bc68734 | |||
| 2ff374abb6 | |||
| f999c66fea | |||
| 2b3f368e0f | |||
| c0ab953115 | |||
| e39de4467d | |||
| 4c3f1ca0fc | |||
| 7fa5a4e048 | |||
| dc1279f636 | |||
| 5798fa9db7 | |||
| c534cf20fd | |||
| 38e14c9269 | |||
| a66b72ba22 | |||
| 2c42d993ca | |||
| a49d673f25 | |||
| ee5de9f3db |
29
CHANGELOG.md
Normal file
29
CHANGELOG.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
0.15.0
|
||||||
|
------
|
||||||
|
* Added display tank player name in `Render`
|
||||||
|
* Fixed join game after relogin
|
||||||
|
* Updated `CreateGamePopup` for any screen sizes
|
||||||
|
* Fixed tank destroy zero score label
|
||||||
|
* Added custom size map support
|
||||||
|
* Fixed clock bonus for spawned tanks
|
||||||
|
|
||||||
|
0.14.0
|
||||||
|
------
|
||||||
|
* Added `CreateGamePopup`
|
||||||
|
* Fixed null tank color
|
||||||
|
* Updated `Ticker`
|
||||||
|
|
||||||
|
0.13.0
|
||||||
|
------
|
||||||
|
* Added `Ticker`
|
||||||
|
* Fixed `PacketQueue` stream reading
|
||||||
|
* Added `PlayerControl` and `ControlPreset`
|
||||||
|
* Added `BaseControlFactory`
|
||||||
|
|
||||||
|
0.12.0
|
||||||
|
------
|
||||||
|
* Added `GameRoomFrame`
|
||||||
|
* Improved websocket connection with using binary protocol instead of text
|
||||||
|
* Added `GameListFrame`
|
||||||
|
* Added `DesktopConnection` for linux client build
|
||||||
|
* Updated `SoundManager`
|
||||||
85
WORK.md
85
WORK.md
@@ -1,73 +1,12 @@
|
|||||||
* build
|
* **shovel** bonus with armor bricks
|
||||||
* gulp 100%
|
* bonuses in dota/death mod
|
||||||
* linux 100%
|
* tanks and bullets speed balancing
|
||||||
* deb-package 100%
|
* result frame update (next game select, only human player info)
|
||||||
* windows 0%
|
* network game series
|
||||||
* exe-package 0% (inno setup)
|
* map packs (create in editor, import in game, save imported in local storage)
|
||||||
|
* update bots
|
||||||
* deploy
|
* improve bonuses system
|
||||||
* capistrano 100%
|
* gamepad support
|
||||||
|
* screen gamepad on mobiles
|
||||||
* ui
|
* resize render on mobiles
|
||||||
* auth frame 0%
|
* [bug] game progress broken
|
||||||
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
|
||||||
* select level frame 10%
|
|
||||||
* game frame 50%
|
|
||||||
|
|
||||||
* engine
|
|
||||||
* config 100%
|
|
||||||
* map 100%
|
|
||||||
* tanks 100%
|
|
||||||
* bullets 100%
|
|
||||||
* boxes 100%
|
|
||||||
* map changes 100%
|
|
||||||
* bonuses 100%
|
|
||||||
* eagle 100%
|
|
||||||
|
|
||||||
* game
|
|
||||||
* classic
|
|
||||||
* state 50%
|
|
||||||
* bot 50%
|
|
||||||
* human 100%
|
|
||||||
* dota
|
|
||||||
* state 50%
|
|
||||||
* bot 10%
|
|
||||||
* human 100%
|
|
||||||
|
|
||||||
* bonus
|
|
||||||
* star 50%
|
|
||||||
* grenade 0%
|
|
||||||
* helm 0%
|
|
||||||
* clock 0%
|
|
||||||
* shovel 0%
|
|
||||||
|
|
||||||
* state
|
|
||||||
* score 0%
|
|
||||||
* human tank 0%
|
|
||||||
* save/load 0%
|
|
||||||
* export/import 0%
|
|
||||||
|
|
||||||
* render
|
|
||||||
* map 100%
|
|
||||||
* tanks 100%
|
|
||||||
* bullet 100%
|
|
||||||
* calc redraw 50%
|
|
||||||
* animations
|
|
||||||
* tank spawn 0%
|
|
||||||
* tank move 100%
|
|
||||||
* map water 100%
|
|
||||||
* bullet boom 90%
|
|
||||||
* tank boom 90%
|
|
||||||
* bonuses 100%
|
|
||||||
* html5 50%
|
|
||||||
|
|
||||||
* proto
|
|
||||||
...
|
|
||||||
|
|
||||||
* editor
|
|
||||||
* level
|
|
||||||
* open 100%
|
|
||||||
* edit 50%
|
|
||||||
* save 100%
|
|
||||||
* tank
|
|
||||||
* color 10%
|
|
||||||
|
|||||||
19
gulpfile.js
19
gulpfile.js
@@ -1,4 +1,6 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
const zip = require('gulp-zip');
|
||||||
|
const foreach = require('gulp-foreach');
|
||||||
const gulpClean = require('gulp-clean');
|
const gulpClean = require('gulp-clean');
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const packageInfo = require('./package.json');
|
const packageInfo = require('./package.json');
|
||||||
@@ -25,6 +27,19 @@ exports.generate = function generate() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.levels = function () {
|
||||||
|
return gulp.src("./src/common/level/*").pipe(foreach(function (stream, file) {
|
||||||
|
const type = file.path.substr(file.path.lastIndexOf("/") + 1);
|
||||||
|
gulp.src("./src/common/level/" + type + "/*").pipe(foreach(function (stream, file) {
|
||||||
|
const name = file.path.substr(file.path.lastIndexOf("/") + 1);
|
||||||
|
gulp.src("./src/common/level/" + type + "/" + name + "/*")
|
||||||
|
.pipe(zip(`${type}_${name}.zip`))
|
||||||
|
.pipe(gulp.dest("./target/levels"));
|
||||||
|
}));
|
||||||
|
return stream;
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToDo:
|
* ToDo:
|
||||||
* windows target
|
* windows target
|
||||||
@@ -46,7 +61,8 @@ const config = new Project.Config({
|
|||||||
'src-gen/haxe',
|
'src-gen/haxe',
|
||||||
],
|
],
|
||||||
assets: [
|
assets: [
|
||||||
'src/common/resources'
|
'src/common/resources',
|
||||||
|
'target/levels'
|
||||||
],
|
],
|
||||||
flags: [
|
flags: [
|
||||||
//'proto_debug',
|
//'proto_debug',
|
||||||
@@ -144,6 +160,7 @@ const server = new Project(
|
|||||||
*/
|
*/
|
||||||
module.exports.default = gulp.series(
|
module.exports.default = gulp.series(
|
||||||
exports.clean,
|
exports.clean,
|
||||||
|
exports.levels,
|
||||||
module.exports['client:flash:build'],
|
module.exports['client:flash:build'],
|
||||||
module.exports['client:flash:html'],
|
module.exports['client:flash:html'],
|
||||||
module.exports['client:html5:build'],
|
module.exports['client:html5:build'],
|
||||||
|
|||||||
2303
package-lock.json
generated
2303
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.14.2",
|
"version": "0.15.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-add": "0.0.2",
|
"gulp-add": "0.0.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
|
"gulp-foreach": "^0.1.0",
|
||||||
"gulp-haxetool": "^0.0.19",
|
"gulp-haxetool": "^0.0.19",
|
||||||
|
"gulp-zip": "^5.0.0",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
|
|||||||
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
|
||||||
|
class ControlBus implements IControlBus {
|
||||||
|
|
||||||
|
private static inline var TAG = "control";
|
||||||
|
|
||||||
|
public var devices(default, null):Array<IControlDevice>;
|
||||||
|
|
||||||
|
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||||
|
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||||
|
|
||||||
|
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
devices = [];
|
||||||
|
signal = new Signal3();
|
||||||
|
devicesSignal = new Signal();
|
||||||
|
connections = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function connect(device:IControlDevice):Void {
|
||||||
|
var connector = function(action:DeviceAction, on:Bool):Void {
|
||||||
|
//L.d("TAG", '${device.type}, ${action}, ${on}');
|
||||||
|
signal.emit(device.type, action, on);
|
||||||
|
}
|
||||||
|
connections.set(device.type, connector);
|
||||||
|
device.signal.connect(connector);
|
||||||
|
devices.push(device);
|
||||||
|
devicesSignal.emit(devices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disconnect(device:IControlDevice):Void {
|
||||||
|
if (connections.exists(device.type)) {
|
||||||
|
device.signal.disconnect(connections.get(device.type));
|
||||||
|
connections.remove(device.type);
|
||||||
|
devices.remove(device);
|
||||||
|
devicesSignal.emit(devices);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import ru.m.geom.Direction;
|
||||||
|
|
||||||
|
enum DeviceAction {
|
||||||
|
DIRECTION(direction:Direction);
|
||||||
|
KEY(code:Int);
|
||||||
|
}
|
||||||
7
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
7
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
enum DeviceType {
|
||||||
|
NONE;
|
||||||
|
KEYBOARD;
|
||||||
|
GAMEPAD(id:Int);
|
||||||
|
}
|
||||||
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
|
||||||
|
interface IControlBus {
|
||||||
|
public var devices(default, null):Array<IControlDevice>;
|
||||||
|
|
||||||
|
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||||
|
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||||
|
|
||||||
|
public function connect(device:IControlDevice):Void;
|
||||||
|
public function disconnect(device:IControlDevice):Void;
|
||||||
|
}
|
||||||
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
|
||||||
|
interface IControlDevice {
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
public function dispose():Void;
|
||||||
|
}
|
||||||
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import lime.ui.Joystick;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
|
|
||||||
|
class JoystickDevice implements IControlDevice {
|
||||||
|
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
private var joystick:Joystick;
|
||||||
|
private var axisState:Map<Int, Direction>;
|
||||||
|
|
||||||
|
public function new(joystick:Joystick) {
|
||||||
|
this.joystick = joystick;
|
||||||
|
type = GAMEPAD(joystick.id);
|
||||||
|
signal = new Signal2();
|
||||||
|
axisState = new Map();
|
||||||
|
joystick.onButtonDown.add(onButtonDown);
|
||||||
|
joystick.onButtonUp.add(onButtonUp);
|
||||||
|
joystick.onAxisMove.add(onAxisMove);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onButtonDown(code:Int):Void {
|
||||||
|
signal.emit(KEY(code), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onButtonUp(code:Int):Void {
|
||||||
|
signal.emit(KEY(code), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onAxisMove(axis:Int, position:Float):Void {
|
||||||
|
var direction:Direction = switch [axis, position] {
|
||||||
|
case [0, 1]: Direction.RIGHT;
|
||||||
|
case [0, -1]: Direction.LEFT;
|
||||||
|
case [1, 1]: Direction.BOTTOM;
|
||||||
|
case [1, -1]: Direction.TOP;
|
||||||
|
case _: null;
|
||||||
|
}
|
||||||
|
if (direction != null) {
|
||||||
|
axisState.set(axis, direction);
|
||||||
|
signal.emit(DIRECTION(direction), true);
|
||||||
|
} else if (position == 0) {
|
||||||
|
if (axisState.exists(axis)) {
|
||||||
|
signal.emit(DIRECTION(axisState.get(axis)), false);
|
||||||
|
axisState.remove(axis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispose():Void {
|
||||||
|
if (joystick != null) {
|
||||||
|
joystick.onButtonDown.remove(onButtonDown);
|
||||||
|
joystick.onButtonUp.remove(onButtonUp);
|
||||||
|
joystick.onAxisMove.remove(onAxisMove);
|
||||||
|
joystick = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import flash.display.Stage;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
|
||||||
|
class KeyboardDevice implements IControlDevice {
|
||||||
|
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
private var stage:Stage;
|
||||||
|
|
||||||
|
public function new(stage:Stage) {
|
||||||
|
this.stage = stage;
|
||||||
|
type = DeviceType.KEYBOARD;
|
||||||
|
signal = new Signal2();
|
||||||
|
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onKeyDown(event:KeyboardEvent):Void {
|
||||||
|
signal.emit(KEY(event.keyCode), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onKeyUp(event:KeyboardEvent):Void {
|
||||||
|
signal.emit(KEY(event.keyCode), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispose():Void {
|
||||||
|
if (stage != null) {
|
||||||
|
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
|
stage = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.Lib;
|
||||||
import haxework.animate.FadeAnimate;
|
import haxework.animate.FadeAnimate;
|
||||||
import haxework.animate.UnFadeAnimate;
|
import haxework.animate.UnFadeAnimate;
|
||||||
import haxework.resources.IResources;
|
import haxework.resources.IResources;
|
||||||
import haxework.resources.Resources;
|
import haxework.resources.Resources;
|
||||||
import haxework.view.popup.PopupManager;
|
import haxework.view.popup.PopupManager;
|
||||||
|
import lime.ui.Gamepad;
|
||||||
|
import lime.ui.Joystick;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
|
import ru.m.control.ControlBus;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
import ru.m.control.JoystickDevice;
|
||||||
|
import ru.m.control.KeyboardDevice;
|
||||||
import ru.m.tankz.bundle.ConfigBundle;
|
import ru.m.tankz.bundle.ConfigBundle;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
@@ -32,6 +39,7 @@ class Init {
|
|||||||
@:provide static var networkManager:NetworkManager;
|
@:provide static var networkManager:NetworkManager;
|
||||||
@:provide static var popupManager:PopupManager;
|
@:provide static var popupManager:PopupManager;
|
||||||
@:provide static var connection:IConnection<Request, Response>;
|
@:provide static var connection:IConnection<Request, Response>;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
private static function buildConnection():IConnection<Request, Response> {
|
private static function buildConnection():IConnection<Request, Response> {
|
||||||
var host:String = CompilationOption.get("host");
|
var host:String = CompilationOption.get("host");
|
||||||
@@ -62,5 +70,22 @@ class Init {
|
|||||||
|
|
||||||
connection = buildConnection();
|
connection = buildConnection();
|
||||||
networkManager = new NetworkManager();
|
networkManager = new NetworkManager();
|
||||||
|
|
||||||
|
bus = new ControlBus();
|
||||||
|
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||||
|
|
||||||
|
for (device in Gamepad.devices) {
|
||||||
|
trace('gamepad', device);
|
||||||
|
}
|
||||||
|
Gamepad.onConnect.add(function(device) {
|
||||||
|
trace('connect gamepad', device);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (device in Joystick.devices) {
|
||||||
|
bus.connect(new JoystickDevice(device));
|
||||||
|
}
|
||||||
|
Joystick.onConnect.add(function(device) {
|
||||||
|
bus.connect(new JoystickDevice(device));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Style {
|
|||||||
|
|
||||||
public static function registerButton(name:String, resource:String):Void {
|
public static function registerButton(name:String, resource:String):Void {
|
||||||
resources.skin.put('button.$name', [
|
resources.skin.put('button.$name', [
|
||||||
Skin.size(64, 64),
|
Skin.size(42, 42),
|
||||||
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||||
]);
|
]);
|
||||||
resources.skin.put('button.$name.small', [
|
resources.skin.put('button.$name.small', [
|
||||||
@@ -137,7 +137,7 @@ class Style {
|
|||||||
Skin.color(darkColor),
|
Skin.color(darkColor),
|
||||||
]);
|
]);
|
||||||
resources.skin.put("panel", [
|
resources.skin.put("panel", [
|
||||||
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([20, 10])),
|
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([10, 5])),
|
||||||
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
||||||
Skin.color(lightColor),
|
Skin.color(lightColor),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ConfigBundle implements IConfigBundle {
|
|||||||
|
|
||||||
public function get(type:GameType):Config {
|
public function get(type:GameType):Config {
|
||||||
if (!_cache.exists(type)) {
|
if (!_cache.exists(type)) {
|
||||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
||||||
_cache.set(type, Config.fromSource(type, source));
|
_cache.set(type, Config.fromSource(type, source));
|
||||||
}
|
}
|
||||||
return _cache.get(type);
|
return _cache.get(type);
|
||||||
|
|||||||
@@ -7,17 +7,13 @@ import ru.m.tankz.util.LevelUtil;
|
|||||||
|
|
||||||
class LevelBundle implements ILevelBundle {
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
private var cache:Map<String, LevelConfig> = new Map();
|
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
public function get(id:PackId):LevelPack {
|
||||||
var key = '${type}:${levelId}';
|
var bytes = Assets.getBytes('levels/${id}.zip');
|
||||||
if (!cache.exists(key)) {
|
return {
|
||||||
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
id: id,
|
||||||
cache[key] = LevelUtil.loads(config, data);
|
data: LevelUtil.unpack(bytes),
|
||||||
cache[key].id = levelId;
|
};
|
||||||
}
|
|
||||||
return cache[key];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import ru.m.tankz.control.Control.TankAction;
|
|
||||||
|
|
||||||
typedef ActionItem = {
|
|
||||||
public var action:TankAction;
|
|
||||||
public var key:Int;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef KeyBinding = Map<Int, TankAction>;
|
|
||||||
|
|
||||||
class ActionConfig {
|
|
||||||
|
|
||||||
public var data(default, null):Array<ActionItem>;
|
|
||||||
|
|
||||||
public function new(data:Array<ActionItem>) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asKeyBinding():KeyBinding {
|
|
||||||
var result = new KeyBinding();
|
|
||||||
for (item in data) {
|
|
||||||
result[item.key] = item.action;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
typedef BindAction = {
|
||||||
|
var device:DeviceType;
|
||||||
|
var action:DeviceAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef Binding = Map<TankAction, BindAction>;
|
||||||
@@ -1,69 +1,85 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
import flash.events.KeyboardEvent;
|
|
||||||
import flash.Lib;
|
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
|
|
||||||
@:provide var storage:SettingsStorage;
|
@:provide static var storage:SettingsStorage;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
private var keyBinding:KeyBinding;
|
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||||
private var moveQueue:Array<Int>;
|
|
||||||
|
private var moveQueue:Array<Direction>;
|
||||||
private var shotTimer:Timer;
|
private var shotTimer:Timer;
|
||||||
|
|
||||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super(playerId);
|
super(playerId);
|
||||||
this.keyBinding = storage.getActionConfig(controlIndex).asKeyBinding();
|
var config = storage.getBinding(controlIndex);
|
||||||
|
binding = new Map();
|
||||||
|
for (action in config.keys()) {
|
||||||
|
var bind = config.get(action);
|
||||||
|
if (!binding.exists(bind.device)) {
|
||||||
|
binding.set(bind.device, new Map());
|
||||||
|
}
|
||||||
|
binding.get(bind.device).set(bind.action, action);
|
||||||
|
}
|
||||||
moveQueue = [];
|
moveQueue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||||
|
if (binding.exists(device) && binding[device].exists(action)) {
|
||||||
|
toggleAction(binding[device][action], on);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
super.start();
|
super.start();
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
bus.signal.connect(onDeviceAction);
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function stop():Void {
|
override public function stop():Void {
|
||||||
super.stop();
|
super.stop();
|
||||||
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
bus.signal.disconnect(onDeviceAction);
|
||||||
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
|
||||||
moveQueue = [];
|
moveQueue = [];
|
||||||
}
|
if (shotTimer != null) {
|
||||||
|
shotTimer.stop();
|
||||||
private function onKeyDown(event:KeyboardEvent):Void {
|
shotTimer = null;
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
|
||||||
case TankAction.MOVE(direction):
|
|
||||||
if (moveQueue.indexOf(event.keyCode) == -1) {
|
|
||||||
moveQueue.unshift(event.keyCode);
|
|
||||||
updateMove();
|
|
||||||
}
|
|
||||||
case TankAction.SHOT:
|
|
||||||
if (shotTimer == null) {
|
|
||||||
shotTimer = new Timer(300);
|
|
||||||
shotTimer.run = shot;
|
|
||||||
shot();
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onKeyUp(event:KeyboardEvent):Void {
|
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
switch action {
|
||||||
case TankAction.MOVE(direction):
|
case TankAction.MOVE(direction):
|
||||||
moveQueue.remove(event.keyCode);
|
if (on) {
|
||||||
|
if (moveQueue.indexOf(direction) == -1) {
|
||||||
|
moveQueue.unshift(direction);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
moveQueue.remove(direction);
|
||||||
|
}
|
||||||
updateMove();
|
updateMove();
|
||||||
case TankAction.SHOT:
|
case TankAction.SHOT:
|
||||||
if (shotTimer != null) {
|
if (on) {
|
||||||
shotTimer.stop();
|
if (shotTimer == null) {
|
||||||
shotTimer = null;
|
shotTimer = new Timer(300);
|
||||||
|
shotTimer.run = shot;
|
||||||
|
shot();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (shotTimer != null) {
|
||||||
|
shotTimer.stop();
|
||||||
|
shotTimer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case _:
|
case TankAction.STOP:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,17 +90,13 @@ class HumanControl extends Control {
|
|||||||
|
|
||||||
private function updateMove():Void {
|
private function updateMove():Void {
|
||||||
if (moveQueue.length == 0) {
|
if (moveQueue.length == 0) {
|
||||||
action(TankAction.STOP);
|
action(STOP);
|
||||||
} else {
|
} else {
|
||||||
switch (keyBinding.get(moveQueue[0])) {
|
action(MOVE(moveQueue[0]));
|
||||||
case TankAction.MOVE(direction):
|
|
||||||
action(TankAction.MOVE(direction));
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function shot():Void {
|
private function shot():Void {
|
||||||
action(TankAction.SHOT);
|
action(SHOT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package ru.m.tankz.local;
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
import ru.m.tankz.local.LocalControlFactory;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameRunner;
|
import ru.m.tankz.game.GameRunner;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.record.GameRecorder;
|
import ru.m.tankz.game.record.GameRecorder;
|
||||||
|
import ru.m.tankz.local.LocalControlFactory;
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
class LocalGame extends GameRunner {
|
class LocalGame extends GameRunner {
|
||||||
@:provide var recordStorage:RecordStorage;
|
@:provide var recordStorage:RecordStorage;
|
||||||
private var recorder:GameRecorder;
|
private var recorder:GameRecorder;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
super(state);
|
super(state, level);
|
||||||
controlFactory = new LocalControlFactory();
|
controlFactory = new LocalControlFactory();
|
||||||
recorder = new GameRecorder();
|
recorder = new GameRecorder();
|
||||||
connect(recorder);
|
connect(recorder);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class NetworkGame extends Game {
|
|||||||
private var network:NetworkManager;
|
private var network:NetworkManager;
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
public function new(network:NetworkManager) {
|
||||||
super(new GameState(network.room.game.type, 0, network.room.game.level));
|
super(new GameState(network.room.game.type, 0), null);
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.controlFactory = new NetworkControlFactory();
|
this.controlFactory = new NetworkControlFactory();
|
||||||
network.gameEventSignal.connect(onGameEventProto);
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import ru.m.tankz.game.IGame;
|
|||||||
|
|
||||||
interface IRender extends IView<Dynamic> extends GameListener {
|
interface IRender extends IView<Dynamic> extends GameListener {
|
||||||
public var config(default, set):Config;
|
public var config(default, set):Config;
|
||||||
|
public var gridSize(default, set):GridSize;
|
||||||
public function draw():Void;
|
public function draw():Void;
|
||||||
public function reset():Void;
|
public function reset():Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ using ru.m.display.DisplayObjectContainerExtender;
|
|||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
public var config(default, set):Config;
|
public var config(default, set):Config;
|
||||||
|
public var gridSize(default, set):GridSize;
|
||||||
|
|
||||||
|
private var mapWidth(get, null):Float;
|
||||||
|
private var mapHeight(get, null):Float;
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
@@ -51,18 +55,33 @@ class Render extends SpriteView implements IRender {
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_mapWidth():Float {
|
||||||
|
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_mapHeight():Float {
|
||||||
|
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||||
|
}
|
||||||
|
|
||||||
private function set_config(value:Config):Config {
|
private function set_config(value:Config):Config {
|
||||||
config = value;
|
config = value;
|
||||||
setContentSize(config.mapWidth, config.mapHeight);
|
setContentSize(mapWidth, mapHeight, "render");
|
||||||
drawBackground();
|
drawBackground();
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function set_gridSize(value:GridSize):GridSize {
|
||||||
|
gridSize = value;
|
||||||
|
setContentSize(mapWidth, mapHeight, "render");
|
||||||
|
drawBackground();
|
||||||
|
return gridSize;
|
||||||
|
}
|
||||||
|
|
||||||
private function drawBackground():Void {
|
private function drawBackground():Void {
|
||||||
var g:Graphics = backgroundLayer.graphics;
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, config.mapWidth, config.mapHeight);
|
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +96,9 @@ class Render extends SpriteView implements IRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function clearLayer(layer:DisplayObjectContainer) {
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
while (layer.numChildren > 0) {
|
||||||
|
layer.removeChildAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset():Void {
|
public function reset():Void {
|
||||||
@@ -94,7 +115,8 @@ class Render extends SpriteView implements IRender {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(_):
|
case START(_, level):
|
||||||
|
gridSize = level.size;
|
||||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
case COMPLETE(_, _):
|
case COMPLETE(_, _):
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
@@ -185,7 +207,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
var item = items[id];
|
var item = items[id];
|
||||||
entryLayer.removeChild(item.view);
|
entryLayer.removeChild(item.view);
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
showScore(item.rect.center, shot.score);
|
showScore(item.rect.center, shot.score);
|
||||||
}
|
}
|
||||||
items.remove(id);
|
items.remove(id);
|
||||||
@@ -204,7 +226,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
if (items.exists(id)) {
|
if (items.exists(id)) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
showScore(item.rect.center, shot.score);
|
showScore(item.rect.center, shot.score);
|
||||||
}
|
}
|
||||||
cast(item, EagleRenderItem).death = true;
|
cast(item, EagleRenderItem).death = true;
|
||||||
@@ -213,7 +235,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
if (items.exists(id)) {
|
if (items.exists(id)) {
|
||||||
var item = items[id];
|
var item = items[id];
|
||||||
upperLayer.removeChild(item.view);
|
upperLayer.removeChild(item.view);
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
showScore(item.rect.center, shot.score);
|
showScore(item.rect.center, shot.score);
|
||||||
}
|
}
|
||||||
items.remove(id);
|
items.remove(id);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import haxework.storage.SharedObjectStorage;
|
import haxework.storage.SharedObjectStorage;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.PackProgress;
|
||||||
import ru.m.tankz.Type.GameType;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class GameStorage extends SharedObjectStorage {
|
class GameStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ class GameStorage extends SharedObjectStorage {
|
|||||||
super('game_${VERSION}');
|
super('game_${VERSION}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(type:GameType):GameProgress {
|
public function get(id:PackId):PackProgress {
|
||||||
return exists(type) ? read(type) : new GameProgress(type);
|
return exists(id) ? read(id) : new PackProgress(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(progress:GameProgress):Void {
|
public function set(progress:PackProgress):Void {
|
||||||
write(progress.type, progress);
|
write(progress.id, progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,50 +3,64 @@ package ru.m.tankz.storage;
|
|||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxework.storage.SharedObjectStorage;
|
import haxework.storage.SharedObjectStorage;
|
||||||
import haxework.utils.ObjectUtil;
|
import haxework.utils.ObjectUtil;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
import ru.m.tankz.control.Binding;
|
||||||
import ru.m.tankz.control.Control.TankAction;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
class SettingsStorage extends SharedObjectStorage {
|
class SettingsStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
private static inline var VERSION = 3;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super("settings");
|
super('settings_${VERSION}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActionConfig(index:Int):ActionConfig {
|
public function getBinding(index:Int):Binding {
|
||||||
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setActionConffig(index:Int, value:ActionConfig) {
|
public function saveBinding(index:Int, value:Binding) {
|
||||||
write('action:$index', value);
|
write('action:$index', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDefaultActionConfig(index:Int):ActionConfig {
|
public static function getDefaultBinding(index:Int):Binding {
|
||||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : empty);
|
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var defaults:Map<Int, ActionConfig> = [
|
public static function buildGamepadBinding(id:Int):Binding {
|
||||||
0 => new ActionConfig([
|
var device = GAMEPAD(id);
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
return [
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||||
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||||
]),
|
SHOT => {device: device, action: KEY(0)},
|
||||||
1 => new ActionConfig([
|
];
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
}
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
|
||||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
|
||||||
]),
|
|
||||||
];
|
|
||||||
|
|
||||||
private static var empty:ActionConfig = new ActionConfig([
|
private static var defaults:Map<Int, Binding> = [
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
-1 => [
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
MOVE(Direction.TOP) => null,
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
MOVE(Direction.LEFT) => null,
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
MOVE(Direction.BOTTOM) => null,
|
||||||
{action:TankAction.SHOT, key:-1},
|
MOVE(Direction.RIGHT) => null,
|
||||||
]);
|
SHOT => null,
|
||||||
|
],
|
||||||
|
0 => [
|
||||||
|
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||||
|
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||||
|
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||||
|
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||||
|
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||||
|
],
|
||||||
|
1 => [
|
||||||
|
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||||
|
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||||
|
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||||
|
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||||
|
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxe.ds.Option;
|
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
@@ -10,8 +11,10 @@ import ru.m.tankz.game.record.GameRecord;
|
|||||||
import ru.m.tankz.network.NetworkManager;
|
import ru.m.tankz.network.NetworkManager;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.game.GameView;
|
import ru.m.tankz.view.game.GameView;
|
||||||
|
import ru.m.tankz.view.GamepadView;
|
||||||
|
|
||||||
@:template class GameFrame extends VGroupView implements GameListener {
|
@:template class GameFrame extends VGroupView implements GameListener {
|
||||||
public static inline var ID = "game";
|
public static inline var ID = "game";
|
||||||
@@ -19,18 +22,36 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
private static inline var TAG = "GameFrame";
|
private static inline var TAG = "GameFrame";
|
||||||
|
|
||||||
@:view("game") private var gameView(default, null):GameView;
|
@:view("game") private var gameView(default, null):GameView;
|
||||||
|
@:view private var gamepad(default, null):GamepadView;
|
||||||
|
|
||||||
@:provide var network:NetworkManager;
|
@:provide var network:NetworkManager;
|
||||||
@:provide var soundManager:SoundManager;
|
@:provide var soundManager:SoundManager;
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide var record:GameRecord;
|
@:provide var record:GameRecord;
|
||||||
@:provide("next") var nextState:GameState;
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var gameStorage:GameStorage;
|
@:provide static var gameStorage:GameStorage;
|
||||||
|
@:provide static var settings:SettingsStorage;
|
||||||
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
|
public function init():Void {
|
||||||
|
bus.connect(gamepad);
|
||||||
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
|
gamepad.visible = false;
|
||||||
|
// ToDo:
|
||||||
|
for (i in 0...1) {
|
||||||
|
for (bind in settings.getBinding(i)) {
|
||||||
|
switch bind.device {
|
||||||
|
case GAMEPAD(GamepadView.ID):
|
||||||
|
gamepad.visible = true;
|
||||||
|
break;
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
gameView.type = game.type;
|
gameView.type = game.type;
|
||||||
soundManager.config = game.config;
|
soundManager.config = game.config;
|
||||||
gameView.render.config = game.config;
|
gameView.render.config = game.config;
|
||||||
@@ -53,18 +74,9 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case GameEvent.COMPLETE(state, winner):
|
case COMPLETE(state, winner):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
nextState = switch next(winner) {
|
updateProgress(game, winner);
|
||||||
case Some(s):
|
|
||||||
// ToDo:
|
|
||||||
var progress = gameStorage.get(game.type);
|
|
||||||
progress.completeLevel(state.levelId, state.presetId);
|
|
||||||
gameStorage.set(progress);
|
|
||||||
s;
|
|
||||||
case None:
|
|
||||||
null;
|
|
||||||
}
|
|
||||||
stop();
|
stop();
|
||||||
switcher.change(ResultFrame.ID);
|
switcher.change(ResultFrame.ID);
|
||||||
case _:
|
case _:
|
||||||
@@ -72,15 +84,18 @@ import ru.m.tankz.view.game.GameView;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToDo:
|
// ToDo:
|
||||||
private function next(winner:TeamId):Option<GameState> {
|
private static function updateProgress(game:IGame, winner:TeamId):Void {
|
||||||
|
var complete = true;
|
||||||
for (rule in game.config.game.complete) {
|
for (rule in game.config.game.complete) {
|
||||||
if (rule.team != null && rule.team != winner) {
|
if (rule.team != null && rule.team != winner) {
|
||||||
return Option.None;
|
complete = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var level = state.levelId + 1;
|
if (complete) {
|
||||||
if (level >= game.config.game.levels) level = 0;
|
var progress = gameStorage.get(new PackId(game.state.type));
|
||||||
return Option.Some(new GameState(game.type, state.presetId, level, state));
|
progress.completeLevel(game.level.id, game.state.presetId);
|
||||||
|
gameStorage.set(progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onHide():Void {
|
public function onHide():Void {
|
||||||
|
|||||||
@@ -2,6 +2,12 @@
|
|||||||
views:
|
views:
|
||||||
- $type: haxework.view.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
skinId: container
|
skinId: container
|
||||||
|
layout.overflow: true
|
||||||
views:
|
views:
|
||||||
- id: game
|
- id: game
|
||||||
$type: ru.m.tankz.view.game.GameView
|
$type: ru.m.tankz.view.game.GameView
|
||||||
|
- id: gamepad
|
||||||
|
$type: ru.m.tankz.view.GamepadView
|
||||||
|
geometry.position: absolute
|
||||||
|
geometry.size.stretch: true
|
||||||
|
visible: false
|
||||||
|
|||||||
159
src/client/haxe/ru/m/tankz/view/GamepadView.hx
Normal file
159
src/client/haxe/ru/m/tankz/view/GamepadView.hx
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import flash.display.Graphics;
|
||||||
|
import flash.display.Stage;
|
||||||
|
import flash.events.MouseEvent;
|
||||||
|
import flash.events.TouchEvent;
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import haxework.view.skin.ISkin;
|
||||||
|
import haxework.view.SpriteView;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.control.IControlDevice;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
typedef ActionArea = {
|
||||||
|
var action:DeviceAction;
|
||||||
|
var rect:Rectangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
class GamepadSkin implements ISkin<GamepadView> {
|
||||||
|
|
||||||
|
public var color(default, default):Int;
|
||||||
|
|
||||||
|
public function new(color:Int = 0) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw(view:GamepadView):Void {
|
||||||
|
var graphics:Graphics = view.content.graphics;
|
||||||
|
graphics.clear();
|
||||||
|
graphics.beginFill(0, 0.0);
|
||||||
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
|
graphics.endFill();
|
||||||
|
graphics.lineStyle(2, color);
|
||||||
|
graphics.beginFill(color, 0.2);
|
||||||
|
for (area in view.areas) {
|
||||||
|
graphics.drawRect(area.rect.x, area.rect.y, area.rect.width, area.rect.height);
|
||||||
|
}
|
||||||
|
graphics.lineStyle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GamepadView extends SpriteView implements IControlDevice {
|
||||||
|
public static var ID(default, never):Int = -128;
|
||||||
|
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
public var areas(default, null):Array<ActionArea>;
|
||||||
|
public var currentAreas(default, null):Map<Int, ActionArea>;
|
||||||
|
|
||||||
|
private var stage:Stage;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
type = GAMEPAD(ID);
|
||||||
|
signal = new Signal2();
|
||||||
|
areas = [];
|
||||||
|
currentAreas = new Map();
|
||||||
|
skin = [new GamepadSkin(0x00ff00)];
|
||||||
|
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
|
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseDown(event:MouseEvent):Void {
|
||||||
|
onMouseMove(event);
|
||||||
|
stage = content.stage;
|
||||||
|
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseMove(event:MouseEvent):Void {
|
||||||
|
var point = new Point(event.localX, event.localY);
|
||||||
|
updateTouch(-1, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onMouseUp(event:MouseEvent):Void {
|
||||||
|
endTouch(-1);
|
||||||
|
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||||
|
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onTouchBegin(event:TouchEvent):Void {
|
||||||
|
onTouchMove(event);
|
||||||
|
stage = content.stage;
|
||||||
|
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
|
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onTouchMove(event:TouchEvent):Void {
|
||||||
|
var point = new Point(event.localX, event.localY);
|
||||||
|
updateTouch(event.touchPointID, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onTouchEnd(event:TouchEvent):Void {
|
||||||
|
endTouch(event.touchPointID);
|
||||||
|
if (Lambda.count(currentAreas) == 0) {
|
||||||
|
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||||
|
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateTouch(pointID:Int, point:Point):Void {
|
||||||
|
if (currentAreas.exists(pointID)) {
|
||||||
|
var area = currentAreas[pointID];
|
||||||
|
if (!area.rect.contain(point)) {
|
||||||
|
currentAreas.remove(pointID);
|
||||||
|
signal.emit(area.action, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (area in areas) {
|
||||||
|
if (area.rect.contain(point)) {
|
||||||
|
currentAreas[pointID] = area;
|
||||||
|
signal.emit(area.action, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function endTouch(pointID:Int):Void {
|
||||||
|
if (currentAreas.exists(pointID)) {
|
||||||
|
signal.emit(currentAreas[pointID].action, false);
|
||||||
|
currentAreas.remove(pointID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
areas = [];
|
||||||
|
var size = Math.min(width, height) / 7;
|
||||||
|
var padding = size / 2;
|
||||||
|
areas.push({
|
||||||
|
action: DIRECTION(Direction.TOP),
|
||||||
|
rect: new Rectangle(padding + size, height - size * 3 - padding, size, size)
|
||||||
|
});
|
||||||
|
areas.push({
|
||||||
|
action: DIRECTION(Direction.LEFT),
|
||||||
|
rect: new Rectangle(padding, height - size * 2 - padding, size, size)
|
||||||
|
});
|
||||||
|
areas.push({
|
||||||
|
action: DIRECTION(Direction.BOTTOM),
|
||||||
|
rect: new Rectangle(padding + size, height - size - padding, size, size)
|
||||||
|
});
|
||||||
|
areas.push({
|
||||||
|
action: DIRECTION(Direction.RIGHT),
|
||||||
|
rect: new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
|
||||||
|
});
|
||||||
|
areas.push({
|
||||||
|
action: KEY(0),
|
||||||
|
rect: new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispose():Void {
|
||||||
|
stage = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
public static inline var ID = "level";
|
public static inline var ID = "level";
|
||||||
|
|
||||||
@:view var header:LabelView;
|
@:view var header:LabelView;
|
||||||
@:view var levels:DataView<LevelId, ButtonView>;
|
@:view var levels:DataView<LevelConfig, ButtonView>;
|
||||||
|
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
@@ -26,44 +26,44 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
@:provide var levelBundle:ILevelBundle;
|
@:provide var levelBundle:ILevelBundle;
|
||||||
@:provide var storage:GameStorage;
|
@:provide var storage:GameStorage;
|
||||||
|
|
||||||
|
private var pack:LevelPack;
|
||||||
private var levelPopup:LevelPopup;
|
private var levelPopup:LevelPopup;
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
header.text = state.type;
|
header.text = state.type;
|
||||||
levels.data = [for (i in 0...state.config.game.levels) i];
|
pack = levelBundle.get(new PackId(state.type));
|
||||||
|
levels.data = pack.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||||
state.levelId = level.id;
|
|
||||||
state.presetId = preset.id;
|
state.presetId = preset.id;
|
||||||
state.controls = control.values;
|
state.controls = control.values;
|
||||||
game = new LocalGame(state);
|
game = new LocalGame(state, level);
|
||||||
switcher.change(GameFrame.ID);
|
switcher.change(GameFrame.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, levelId:LevelId):ButtonView {
|
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
||||||
var progress = storage.get(state.type);
|
var progress = storage.get(pack.id);
|
||||||
var result = new ButtonView();
|
var result = new ButtonView();
|
||||||
result.skinId = "button.level";
|
result.skinId = "button.level";
|
||||||
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(levelId, p.id) ? '*' : '_'].join('');
|
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||||
result.text = '${levelId}\n${presetsLine}';
|
result.text = '${level.id}\n${presetsLine}';
|
||||||
result.disabled = !progress.isLevelAvailable(levelId);
|
result.disabled = !progress.isLevelAvailable(level.id);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, levelId:LevelId, view:ButtonView):Void {
|
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||||
if (!storage.get(state.type).isLevelAvailable(levelId)) {
|
if (!storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (levelPopup == null) {
|
if (levelPopup == null) {
|
||||||
levelPopup = new LevelPopup();
|
levelPopup = new LevelPopup();
|
||||||
}
|
}
|
||||||
var level = levelBundle.get(state.type, state.config, levelId);
|
|
||||||
levelPopup.setData(
|
levelPopup.setData(
|
||||||
level,
|
level,
|
||||||
state.config.presets,
|
state.config.presets,
|
||||||
state.config.controls,
|
state.config.controls,
|
||||||
storage.get(state.type)
|
storage.get(pack.id)
|
||||||
);
|
);
|
||||||
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package ru.m.tankz.view;
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
import haxework.view.ButtonView;
|
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
@@ -18,7 +17,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
@:provide var frames:FrameSwitcher;
|
@:provide var frames:FrameSwitcher;
|
||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide("next") var nextState:GameState;
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
|
|
||||||
private function playerViewFactory(index:Int, player:PlayerState) {
|
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||||
@@ -35,14 +33,11 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onShow() {
|
public function onShow() {
|
||||||
resultView.data = Lambda.array(state.players);
|
resultView.data = Lambda.array(state.players);
|
||||||
levelLabel.text = 'Level ${state.levelId}';
|
//levelLabel.text = 'Level ${state.levelId}'; // ToDo: level?
|
||||||
}
|
}
|
||||||
|
|
||||||
private function next() {
|
private function next() {
|
||||||
if (nextState != null) {
|
//ToDo: next level?
|
||||||
game = new GameRunner(nextState);
|
|
||||||
frames.change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function close() {
|
private function close() {
|
||||||
|
|||||||
@@ -2,14 +2,28 @@
|
|||||||
views:
|
views:
|
||||||
- $type: haxework.view.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
skinId: container
|
skinId: container
|
||||||
|
geometry.padding: 20
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.LabelView
|
- $type: haxework.view.LabelView
|
||||||
skinId: text.header
|
skinId: text.header
|
||||||
text: Settings
|
text: Settings
|
||||||
- $type: haxework.view.HGroupView
|
- $type: haxework.view.ScrollView
|
||||||
layout.margin: 20
|
geometry.size.stretch: true
|
||||||
views:
|
scroll:
|
||||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
$type: haxework.view.list.VScrollBarView
|
||||||
controlIndex: 0
|
skinId: scroll.vertical
|
||||||
- $type: ru.m.tankz.view.settings.SettingsEditor
|
view:
|
||||||
controlIndex: 1
|
$type: haxework.view.GroupView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
vAlign: top
|
||||||
|
margin: 20
|
||||||
|
overflow: true
|
||||||
|
views:
|
||||||
|
- id: settings0
|
||||||
|
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
|
controlIndex: 0
|
||||||
|
- id: settings1
|
||||||
|
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
|
controlIndex: 1
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
level.text = 'Level ${state.levelId}';
|
|
||||||
bot.life = state.getTeamLife(ClassicGame.BOT);
|
bot.life = state.getTeamLife(ClassicGame.BOT);
|
||||||
player1.life = state.getPlayerLife(player1Id);
|
player1.life = state.getPlayerLife(player1Id);
|
||||||
player1.score = state.getPlayerScore(player1Id);
|
player1.score = state.getPlayerScore(player1Id);
|
||||||
@@ -36,7 +35,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
|
this.level.text = 'Level ${level.id}';
|
||||||
refresh(state);
|
refresh(state);
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
if (teamId == ClassicGame.BOT) {
|
if (teamId == ClassicGame.BOT) {
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
level.text = 'Level ${state.levelId}';
|
this.level.text = 'Level ${level.id}';
|
||||||
players.data = Lambda.array(state.players);
|
players.data = Lambda.array(state.players);
|
||||||
case _:
|
case _:
|
||||||
for (view in players.views) {
|
for (view in players.views) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
@:view var level:LabelView;
|
@:view var level:LabelView;
|
||||||
|
|
||||||
public function refresh(state:GameState):Void {
|
public function refresh(state:GameState):Void {
|
||||||
level.text = 'Level ${state.levelId}';
|
|
||||||
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
radiant.life = state.getTeamLife(DotaGame.RADIANT);
|
||||||
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
radiant.score = state.getTeamScore(DotaGame.RADIANT);
|
||||||
dire.life = state.getTeamLife(DotaGame.DIRE);
|
dire.life = state.getTeamLife(DotaGame.DIRE);
|
||||||
@@ -34,7 +33,8 @@ import ru.m.tankz.view.common.LifeView;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
|
this.level.text = 'Level ${level.id}';
|
||||||
refresh(state);
|
refresh(state);
|
||||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||||
getLifeView(teamId).life = life;
|
getLifeView(teamId).life = life;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
|||||||
private function create():Void {
|
private function create():Void {
|
||||||
CreateGamePopup.instance.show().then(function(result) {
|
CreateGamePopup.instance.show().then(function(result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
network.createGame(result.type, result.level);
|
network.createGame(result.type, result.level.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,25 @@ import haxework.view.DataView;
|
|||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
import haxework.view.ToggleButtonView;
|
import haxework.view.ToggleButtonView;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
private typedef Result = {
|
private typedef Result = {
|
||||||
var type:GameType;
|
var type:GameType;
|
||||||
var level:LevelId;
|
var level:LevelConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:template class CreateGamePopup extends PopupView<Result> {
|
@:template class CreateGamePopup extends PopupView<Result> {
|
||||||
|
|
||||||
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
@:view("type") var typeView:DataView<GameType, ToggleButtonView>;
|
||||||
@:view("level") var levelView:DataView<LevelId, ToggleButtonView>;
|
@:view("level") var levelView:DataView<LevelConfig, ToggleButtonView>;
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide static var configBundle:IConfigBundle;
|
||||||
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
|
||||||
private var type:GameType;
|
private var type:GameType;
|
||||||
private var level:LevelId;
|
private var level:LevelConfig;
|
||||||
|
|
||||||
override private function onShow():Void {
|
override private function onShow():Void {
|
||||||
super.onShow();
|
super.onShow();
|
||||||
@@ -43,18 +46,18 @@ private typedef Result = {
|
|||||||
for (v in typeView.dataViews) {
|
for (v in typeView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
}
|
}
|
||||||
levelView.data = [for (i in 0...configBundle.get(type).game.levels) i];
|
levelView.data = levelBundle.get(new PackId(value)).data;
|
||||||
onLevelSelect(0, 0, levelView.dataViews[0]);
|
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, value:LevelId):ToggleButtonView {
|
private function levelViewFactory(index:Int, value:LevelConfig):ToggleButtonView {
|
||||||
var result = new ToggleButtonView();
|
var result = new ToggleButtonView();
|
||||||
result.skinId = "button.level";
|
result.skinId = "button.level";
|
||||||
result.text = Std.string(value);
|
result.text = Std.string(value.id);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, level:LevelId, view:ToggleButtonView):Void {
|
private function onLevelSelect(index:Int, level:LevelConfig, view:ToggleButtonView):Void {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
for (v in levelView.dataViews) {
|
for (v in levelView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ layout.vAlign: middle
|
|||||||
view:
|
view:
|
||||||
$type: haxework.view.VGroupView
|
$type: haxework.view.VGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
geometry.size.width: 600
|
geometry.size.stretch: true
|
||||||
|
geometry.margin: 10
|
||||||
skinId: window
|
skinId: window
|
||||||
views:
|
views:
|
||||||
- $type: haxework.view.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
@@ -23,8 +24,8 @@ view:
|
|||||||
skinId: window.close
|
skinId: window.close
|
||||||
+onPress: $code:reject('close')
|
+onPress: $code:reject('close')
|
||||||
- $type: haxework.view.VGroupView
|
- $type: haxework.view.VGroupView
|
||||||
geometry.size.width: 100%
|
geometry.size.stretch: true
|
||||||
geometry.padding: 20
|
geometry.padding: [5, 20]
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
views:
|
views:
|
||||||
@@ -34,8 +35,9 @@ view:
|
|||||||
text: Type
|
text: Type
|
||||||
- id: type
|
- id: type
|
||||||
$type: haxework.view.DataView
|
$type: haxework.view.DataView
|
||||||
|
geometry.size.width: 100%
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.HorizontalLayout
|
$type: haxework.view.layout.TailLayout
|
||||||
margin: 10
|
margin: 10
|
||||||
factory: $this:gameTypeViewFactory
|
factory: $this:gameTypeViewFactory
|
||||||
+onItemSelect: $this:onGameTypeSelect
|
+onItemSelect: $this:onGameTypeSelect
|
||||||
@@ -47,16 +49,22 @@ view:
|
|||||||
geometry.size.width: 100%
|
geometry.size.width: 100%
|
||||||
skinId: text
|
skinId: text
|
||||||
text: Level
|
text: Level
|
||||||
- id: level
|
- $type: haxework.view.ScrollView
|
||||||
$type: haxework.view.DataView
|
geometry.size.stretch: true
|
||||||
geometry.size.width: 100%
|
scroll:
|
||||||
layout:
|
$type: haxework.view.list.VScrollBarView
|
||||||
$type: haxework.view.layout.TailLayout
|
skinId: scroll.vertical
|
||||||
rowSize: 10
|
view:
|
||||||
margin: 5
|
id: level
|
||||||
factory: $this:levelViewFactory
|
$type: haxework.view.DataView
|
||||||
+onItemSelect: $this:onLevelSelect
|
geometry.size.width: 100%
|
||||||
geometry.padding: 10
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onItemSelect: $this:onLevelSelect
|
||||||
|
geometry.padding: 10
|
||||||
- $type: haxework.view.HGroupView
|
- $type: haxework.view.HGroupView
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
layout.margin: 5
|
layout.margin: 5
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.tankz.view.popup;
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
import haxework.view.ToggleButtonView;
|
|
||||||
import haxework.view.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
|
import haxework.view.ToggleButtonView;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.PackProgress;
|
||||||
|
|
||||||
private typedef Result = {
|
private typedef Result = {
|
||||||
var control:ControlPreset;
|
var control:ControlPreset;
|
||||||
@@ -16,14 +16,14 @@ private typedef Result = {
|
|||||||
@:template class LevelPopup extends PopupView<Result> {
|
@:template class LevelPopup extends PopupView<Result> {
|
||||||
|
|
||||||
private var level:LevelConfig;
|
private var level:LevelConfig;
|
||||||
private var progress:GameProgress;
|
private var progress:PackProgress;
|
||||||
|
|
||||||
@:view var name:LabelView;
|
@:view var name:LabelView;
|
||||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||||
@:view("controls") var controlsView:DataView<ControlPreset, ToggleButtonView>;
|
@:view("controls") var controlsView:DataView<ControlPreset, ToggleButtonView>;
|
||||||
private var control:ControlPreset;
|
private var control:ControlPreset;
|
||||||
|
|
||||||
public function setData(level:LevelConfig, presets:Array<GamePreset>, controls:Array<ControlPreset>, progress:GameProgress):Void {
|
public function setData(level:LevelConfig, presets:Array<GamePreset>, controls:Array<ControlPreset>, progress:PackProgress):Void {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
name.text = '${level.id}. ${level.name != null ? level.name : "#"}';
|
name.text = '${level.id}. ${level.name != null ? level.name : "#"}';
|
||||||
|
|||||||
@@ -2,14 +2,17 @@ package ru.m.tankz.view.settings;
|
|||||||
|
|
||||||
import haxework.view.HGroupView;
|
import haxework.view.HGroupView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.list.ListView.IListItemView;
|
import haxework.view.list.ListView;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import openfl.events.KeyboardEvent;
|
import ru.m.control.DeviceAction;
|
||||||
import promhx.Deferred;
|
import ru.m.tankz.control.Binding;
|
||||||
import promhx.Promise;
|
|
||||||
import ru.m.tankz.control.ActionConfig;
|
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
typedef ActionItem = {
|
||||||
|
var action:TankAction;
|
||||||
|
var bind:BindAction;
|
||||||
|
}
|
||||||
|
|
||||||
class KeyboardMap {
|
class KeyboardMap {
|
||||||
|
|
||||||
private var data:Map<Int, String>;
|
private var data:Map<Int, String>;
|
||||||
@@ -26,9 +29,9 @@ class KeyboardMap {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var instance: KeyboardMap;
|
private static var instance:KeyboardMap;
|
||||||
|
|
||||||
public static function getName(key: Int): String {
|
public static function getName(key:Int):String {
|
||||||
if (instance == null) instance = new KeyboardMap();
|
if (instance == null) instance = new KeyboardMap();
|
||||||
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||||
}
|
}
|
||||||
@@ -39,12 +42,12 @@ class KeyboardMap {
|
|||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):ActionItem;
|
public var data(default, set):ActionItem;
|
||||||
|
|
||||||
|
public var edit(default, set):Bool;
|
||||||
|
|
||||||
@:view var action(default, null):LabelView;
|
@:view var action(default, null):LabelView;
|
||||||
@:view var key(default, null):LabelView;
|
@:view var key(default, null):LabelView;
|
||||||
|
|
||||||
private var editDeferred: Deferred<Int>;
|
private static function actionLabel(action:TankAction):String {
|
||||||
|
|
||||||
private static function actionLabel(action: TankAction): String {
|
|
||||||
return switch (action) {
|
return switch (action) {
|
||||||
case TankAction.SHOT: "SHOT";
|
case TankAction.SHOT: "SHOT";
|
||||||
case TankAction.MOVE(d): 'MOVE_$d';
|
case TankAction.MOVE(d): 'MOVE_$d';
|
||||||
@@ -52,32 +55,25 @@ class KeyboardMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function keyLabel(key: Int): String {
|
private static function bindLabel(bind:BindAction):String {
|
||||||
return KeyboardMap.getName(key);
|
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||||
|
case KEY(code): KeyboardMap.getName(code);
|
||||||
|
case DIRECTION(direction): Std.string(direction);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_data(value:ActionItem):ActionItem {
|
private function set_data(value:ActionItem):ActionItem {
|
||||||
data = value;
|
data = value;
|
||||||
action.text = actionLabel(data.action);
|
action.text = actionLabel(data.action);
|
||||||
key.text = keyLabel(data.key);
|
key.text = bindLabel(data.bind);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit():Promise<Int> {
|
private function set_edit(value:Bool):Bool {
|
||||||
action.skinId = key.skinId = "text.box.active";
|
if (edit != value) {
|
||||||
toRedraw();
|
edit = value;
|
||||||
editDeferred = new Deferred();
|
action.skinId = key.skinId = edit ? "text.box.active" : "text.box";
|
||||||
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
}
|
||||||
return editDeferred.promise();
|
return edit;
|
||||||
}
|
|
||||||
|
|
||||||
private function onKeyDown(event: KeyboardEvent):Void {
|
|
||||||
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
|
||||||
action.skinId = key.skinId = "text.box";
|
|
||||||
toRedraw();
|
|
||||||
data.key = event.keyCode;
|
|
||||||
key.text = keyLabel(data.key);
|
|
||||||
editDeferred.resolve(data.key);
|
|
||||||
editDeferred = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ layout.margin: 5
|
|||||||
views:
|
views:
|
||||||
- id: action
|
- id: action
|
||||||
$type: haxework.view.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.size.fixed: [200, 38]
|
geometry.size.fixed: [180, 38]
|
||||||
skinId: text.box
|
skinId: text.box
|
||||||
- id: key
|
- id: key
|
||||||
$type: haxework.view.LabelView
|
$type: haxework.view.LabelView
|
||||||
geometry.size.fixed: [200, 38]
|
geometry.size.fixed: [250, 38]
|
||||||
skinId: text.box
|
skinId: text.box
|
||||||
|
|||||||
@@ -1,11 +1,66 @@
|
|||||||
package ru.m.tankz.view.settings;
|
package ru.m.tankz.view.settings;
|
||||||
|
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.GroupView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.VGroupView;
|
import haxework.view.VGroupView;
|
||||||
|
import promhx.Deferred;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
import ru.m.tankz.control.Binding;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
import ru.m.tankz.view.settings.ActionView;
|
||||||
|
|
||||||
|
class BindEditor {
|
||||||
|
|
||||||
|
private var editViews:Array<ActionView>;
|
||||||
|
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
|
private var def:Deferred<Bool>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
editViews = [];
|
||||||
|
bus.signal.connect(onBusAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onBusAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||||
|
if (on && editViews.length > 0) {
|
||||||
|
var view = editViews.shift();
|
||||||
|
view.edit = false;
|
||||||
|
view.data.bind = {device: device, action: action};
|
||||||
|
view.data = view.data;
|
||||||
|
if (editViews.length > 0) {
|
||||||
|
editViews[0].edit = true;
|
||||||
|
} else {
|
||||||
|
def.resolve(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function push(views:Array<ActionView>):Promise<Bool> {
|
||||||
|
for (view in editViews) {
|
||||||
|
view.edit = false;
|
||||||
|
}
|
||||||
|
editViews = views.slice(0);
|
||||||
|
if (editViews.length > 0) {
|
||||||
|
editViews[0].edit = true;
|
||||||
|
}
|
||||||
|
def = new Deferred();
|
||||||
|
return def.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var i(get, null):BindEditor;
|
||||||
|
|
||||||
|
private static function get_i():BindEditor {
|
||||||
|
if (i == null) {
|
||||||
|
i = new BindEditor();
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@:template class SettingsEditor extends VGroupView {
|
@:template class SettingsEditor extends VGroupView {
|
||||||
|
|
||||||
@@ -13,13 +68,20 @@ import ru.m.tankz.storage.SettingsStorage;
|
|||||||
|
|
||||||
@:view var label:LabelView;
|
@:view var label:LabelView;
|
||||||
@:view var list:DataView<ActionItem, ActionView>;
|
@:view var list:DataView<ActionItem, ActionView>;
|
||||||
|
@:view var panel:GroupView;
|
||||||
|
|
||||||
@:provide var storage:SettingsStorage;
|
@:provide static var storage:SettingsStorage;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
|
private function refresh():Void {
|
||||||
|
label.text = 'Player ${controlIndex+1}';
|
||||||
|
var binding = storage.getBinding(controlIndex);
|
||||||
|
list.data = bindingToArray(binding);
|
||||||
|
}
|
||||||
|
|
||||||
private function set_controlIndex(value: Int): Int {
|
private function set_controlIndex(value: Int): Int {
|
||||||
this.controlIndex = value;
|
this.controlIndex = value;
|
||||||
label.text = 'Player ${controlIndex+1}';
|
refresh();
|
||||||
list.data = storage.getActionConfig(controlIndex).data;
|
|
||||||
return this.controlIndex;
|
return this.controlIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,34 +93,48 @@ import ru.m.tankz.storage.SettingsStorage;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onItemSelect(index:Int, value:ActionItem, view:ActionView):Void {
|
private function onItemSelect(index:Int, value:ActionItem, view:ActionView):Void {
|
||||||
view.edit();
|
BindEditor.i.push([view]).then(function(_) save());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function change():Void {
|
private function screen():Void {
|
||||||
var p: Promise<Int> = Promise.promise(0);
|
list.data = bindingToArray(SettingsStorage.buildGamepadBinding(GamepadView.ID));
|
||||||
for (view in list.views) {
|
|
||||||
var v: ActionView = cast view;
|
|
||||||
p = p.pipe(function(_):Promise<Int> return v.edit());
|
|
||||||
}
|
|
||||||
p.then(function(_) save());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function clear():Void {
|
|
||||||
for (item in list.data) {
|
|
||||||
item.key = -1;
|
|
||||||
}
|
|
||||||
list.data = list.data;
|
|
||||||
list.toUpdate();
|
list.toUpdate();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function reset():Void {
|
private function change():Void {
|
||||||
list.data = SettingsStorage.getDefaultActionConfig(controlIndex).data;
|
BindEditor.i.push(list.dataViews).then(function(_) save());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function clear():Void {
|
||||||
|
list.data = bindingToArray(SettingsStorage.getDefaultBinding(-1));
|
||||||
|
list.toUpdate();
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function default_():Void {
|
||||||
|
list.data = bindingToArray(SettingsStorage.getDefaultBinding(controlIndex));
|
||||||
list.toUpdate();
|
list.toUpdate();
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function save():Void {
|
private function save():Void {
|
||||||
storage.setActionConffig(controlIndex, new ActionConfig(list.data));
|
storage.saveBinding(controlIndex, arrayToBinding(list.data));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function bindingToArray(binding:Binding):Array<ActionItem> {
|
||||||
|
var result:Array<ActionItem> = [];
|
||||||
|
for (action in binding.keys()) {
|
||||||
|
result.push({action: action, bind: binding.get(action)});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function arrayToBinding(array:Array<ActionItem>):Binding {
|
||||||
|
var result = new Binding();
|
||||||
|
for (item in array) {
|
||||||
|
result.set(item.action, item.bind);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,34 @@
|
|||||||
layout.margin: 10
|
layout.margin: 10
|
||||||
layout.hAlign: center
|
layout.hAlign: center
|
||||||
|
geometry.size.width: 400
|
||||||
views:
|
views:
|
||||||
- id: label
|
- id: label
|
||||||
$type: haxework.view.LabelView
|
$type: haxework.view.LabelView
|
||||||
skinId: text
|
skinId: text
|
||||||
- $type: haxework.view.HGroupView
|
- id: panel
|
||||||
layout.margin: 10
|
$type: haxework.view.GroupView
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 2
|
||||||
|
margin: 10
|
||||||
|
geometry.size.width: 100%
|
||||||
views:
|
views:
|
||||||
- id: change
|
- $type: haxework.view.ButtonView
|
||||||
$type: haxework.view.ButtonView
|
+onPress: $code:screen()
|
||||||
|
skinId: button.simple
|
||||||
|
text: Screen
|
||||||
|
- $type: haxework.view.ButtonView
|
||||||
+onPress: $code:change()
|
+onPress: $code:change()
|
||||||
skinId: button.simple
|
skinId: button.simple
|
||||||
text: Change
|
text: Change
|
||||||
- id: clear
|
- $type: haxework.view.ButtonView
|
||||||
$type: haxework.view.ButtonView
|
|
||||||
+onPress: $code:clear()
|
+onPress: $code:clear()
|
||||||
skinId: button.simple
|
skinId: button.simple
|
||||||
text: Clear
|
text: Clear
|
||||||
- id: reset
|
- $type: haxework.view.ButtonView
|
||||||
$type: haxework.view.ButtonView
|
+onPress: $code:default_()
|
||||||
+onPress: $code:reset()
|
|
||||||
skinId: button.simple
|
skinId: button.simple
|
||||||
text: Reset
|
text: Default
|
||||||
- id: list
|
- id: list
|
||||||
$type: haxework.view.DataView
|
$type: haxework.view.DataView
|
||||||
layout:
|
layout:
|
||||||
|
|||||||
BIN
src/client/resources/image/map/wood-dark.png
Normal file
BIN
src/client/resources/image/map/wood-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
BIN
src/client/resources/image/map/wood.png
Normal file
BIN
src/client/resources/image/map/wood.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
@@ -8,6 +8,8 @@ typedef TeamId = String;
|
|||||||
|
|
||||||
typedef BrickType = String;
|
typedef BrickType = String;
|
||||||
|
|
||||||
|
typedef BrickIndex = Int;
|
||||||
|
|
||||||
typedef TankType = String;
|
typedef TankType = String;
|
||||||
|
|
||||||
typedef BonusType = String;
|
typedef BonusType = String;
|
||||||
@@ -37,5 +39,33 @@ abstract PlayerId(Array<Dynamic>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract PackId(Array<Dynamic>) {
|
||||||
|
public static inline var DEFAULT = "standard";
|
||||||
|
|
||||||
|
public var type(get, never):GameType;
|
||||||
|
public var name(get, never):String;
|
||||||
|
|
||||||
|
public function new(type:GameType, name:String = DEFAULT) {
|
||||||
|
this = [type, name];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_type():GameType return this[0];
|
||||||
|
|
||||||
|
private inline function get_name():String return this[1];
|
||||||
|
|
||||||
|
@:from static public inline function fromArray(value:Array<Dynamic>):PackId {
|
||||||
|
return new PackId(value[0], value[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@:to public inline function toString():String {
|
||||||
|
return '${type}_${name}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@:op(X == Y) static public inline function equals(x:PackId, y:PackId):Bool {
|
||||||
|
return x.type == y.type && x.name == y.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef LevelId = Int;
|
typedef LevelId = Int;
|
||||||
|
|
||||||
typedef PresetId = Int;
|
typedef PresetId = Int;
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import ru.m.tankz.config.Config;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface ILevelBundle {
|
interface ILevelBundle {
|
||||||
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig;
|
public function get(id:PackId):LevelPack;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,18 +23,26 @@ typedef SpawnPoint = {
|
|||||||
var direction:String;
|
var direction:String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef CellSize = {
|
||||||
|
var width:Float;
|
||||||
|
var height:Float;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef GridSize = {
|
||||||
|
var width:Int;
|
||||||
|
var height:Int;
|
||||||
|
}
|
||||||
|
|
||||||
typedef MapConfig = {
|
typedef MapConfig = {
|
||||||
var cellWidth:Float;
|
var cell:CellSize;
|
||||||
var cellHeight:Float;
|
var grid:GridSize;
|
||||||
var gridWidth:Int;
|
|
||||||
var gridHeight:Int;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BrickConfig = {
|
typedef BrickConfig = {
|
||||||
var type:BrickType;
|
var type:BrickType;
|
||||||
var index:Int;
|
var index:Int;
|
||||||
var layer:Int;
|
var layer:Int;
|
||||||
var armor:Int;
|
var armor:Float;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BulletConfig = {
|
typedef BulletConfig = {
|
||||||
@@ -55,13 +63,13 @@ typedef TankConfig = {
|
|||||||
@:optinal var hits:Int;
|
@:optinal var hits:Int;
|
||||||
@:optinal var upgrade:TankType;
|
@:optinal var upgrade:TankType;
|
||||||
@:optinal var downgrade:TankType;
|
@:optinal var downgrade:TankType;
|
||||||
@:optinal var score:Int;
|
@:optinal var score:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BonusConfig = {
|
typedef BonusConfig = {
|
||||||
var type:BonusType;
|
var type:BonusType;
|
||||||
@:optional var duration:Int;
|
@:optional var duration:Null<Int>;
|
||||||
@:optinal var score:Int;
|
@:optinal var score:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TankSpawn = {
|
typedef TankSpawn = {
|
||||||
@@ -80,7 +88,7 @@ typedef PlayerConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef EagleConfig = {
|
typedef EagleConfig = {
|
||||||
@:optional var score:Int;
|
@:optional var score:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TeamConfig = {
|
typedef TeamConfig = {
|
||||||
@@ -100,9 +108,15 @@ typedef GamePreset = {
|
|||||||
|
|
||||||
typedef LevelConfig = {
|
typedef LevelConfig = {
|
||||||
@:optional var id:LevelId;
|
@:optional var id:LevelId;
|
||||||
var data:Array<BrickConfig>;
|
var data:Array<BrickIndex>;
|
||||||
@:optional var name:String;
|
@:optional var name:String;
|
||||||
@:optional var points:Array<SpawnPoint>;
|
@:optional var points:Array<SpawnPoint>;
|
||||||
|
@:optional var size:{width:Int, height:Int};
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef LevelPack = {
|
||||||
|
var id:PackId;
|
||||||
|
var data:Array<LevelConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef PlayerControl = {
|
typedef PlayerControl = {
|
||||||
@@ -139,8 +153,6 @@ class Config {
|
|||||||
public var controls(default, null):Array<ControlPreset>;
|
public var controls(default, null):Array<ControlPreset>;
|
||||||
public var points(default, null):Array<SpawnPoint>;
|
public var points(default, null):Array<SpawnPoint>;
|
||||||
public var bonuses(default, null):Array<BonusConfig>;
|
public var bonuses(default, null):Array<BonusConfig>;
|
||||||
public var mapWidth(get, null):Float;
|
|
||||||
public var mapHeight(get, null):Float;
|
|
||||||
|
|
||||||
private var brickMap:Map<BrickType, BrickConfig>;
|
private var brickMap:Map<BrickType, BrickConfig>;
|
||||||
private var brickMapByIndex:Map<Int, BrickConfig>;
|
private var brickMapByIndex:Map<Int, BrickConfig>;
|
||||||
@@ -208,14 +220,6 @@ class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_mapWidth():Float {
|
|
||||||
return map.cellWidth * map.gridWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_mapHeight():Float {
|
|
||||||
return map.cellHeight * map.gridHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBrick(type:BrickType):BrickConfig {
|
public function getBrick(type:BrickType):BrickConfig {
|
||||||
return brickMap.get(type);
|
return brickMap.get(type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ enum TankAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Control {
|
class Control {
|
||||||
public var type:String;
|
|
||||||
public var playerId(default, null):PlayerId;
|
public var playerId(default, null):PlayerId;
|
||||||
public var tankId(default, default):Int;
|
public var tankId(default, default):Int;
|
||||||
private var handler:IGame;
|
private var handler:IGame;
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
|
|
||||||
public var allEntities(default, null):Map<Int, Entity>;
|
public var allEntities(default, null):Map<Int, Entity>;
|
||||||
|
|
||||||
public function new(config:Config) {
|
public function new(config:Config, size:GridSize = null) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
map = new LevelMap(config.map);
|
map = new LevelMap(config.map, size);
|
||||||
allEntities = new Map();
|
allEntities = new Map();
|
||||||
entities = new Map();
|
entities = new Map();
|
||||||
ticker = new Ticker();
|
ticker = new Ticker();
|
||||||
@@ -112,6 +112,7 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (withCollision != null) break;
|
||||||
|
|
||||||
for (other in entities.iterator()) {
|
for (other in entities.iterator()) {
|
||||||
if (other != ent && other != null) {
|
if (other != ent && other != null) {
|
||||||
@@ -120,7 +121,6 @@ import ru.m.tankz.map.LevelMap;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (withCollision != null) break;
|
if (withCollision != null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.m.tankz.engine;
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
typedef Action = {
|
typedef Action = {
|
||||||
|
var id:Int;
|
||||||
var time:Int;
|
var time:Int;
|
||||||
var action:Void->Void;
|
var action:Void->Void;
|
||||||
}
|
}
|
||||||
@@ -12,6 +13,7 @@ class Ticker implements ITicker {
|
|||||||
private var passed:Int;
|
private var passed:Int;
|
||||||
private var last_tick:Int;
|
private var last_tick:Int;
|
||||||
private var actions:Array<Action>;
|
private var actions:Array<Action>;
|
||||||
|
private var actionId = 0;
|
||||||
|
|
||||||
private static var TIME = Timer.stamp();
|
private static var TIME = Timer.stamp();
|
||||||
|
|
||||||
@@ -58,17 +60,23 @@ class Ticker implements ITicker {
|
|||||||
var action = it.next();
|
var action = it.next();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (action != null && time >= action.time) {
|
while (action != null && time >= action.time) {
|
||||||
action.action();
|
|
||||||
i++;
|
i++;
|
||||||
action = it.next();
|
action = it.next();
|
||||||
}
|
}
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
var timeActions = actions.slice(0, i);
|
||||||
actions = actions.slice(i);
|
actions = actions.slice(i);
|
||||||
|
for (action in timeActions) {
|
||||||
|
//L.d("Ticker", 'action: ${action.id} ${action.time} on ${time}');
|
||||||
|
action.action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emit(action:Void->Void, delay:Int):Void {
|
public function emit(fun:Void->Void, delay:Int):Void {
|
||||||
actions.push({action:action, time:time+delay});
|
var action:Action = {action:fun, time:time+delay, id:++actionId};
|
||||||
|
//L.d("Ticker", 'emit: ${action.id} ${action.time}');
|
||||||
|
actions.push(action);
|
||||||
actions.sort(function(a, b) return a.time - b.time);
|
actions.sort(function(a, b) return a.time - b.time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {
|
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {
|
||||||
return new Rectangle(
|
return new Rectangle(
|
||||||
(point.x + 1) * config.map.cellWidth - width / 2,
|
(point.x + 1) * config.map.cell.width - width / 2,
|
||||||
(point.y + 1) * config.map.cellHeight - height / 2,
|
(point.y + 1) * config.map.cell.height - height / 2,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
Direction.fromString(point.direction)
|
Direction.fromString(point.direction)
|
||||||
@@ -39,7 +39,7 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildEagle(point:EntityPoint, teamId:TeamId):Eagle {
|
public function buildEagle(point:EntityPoint, teamId:TeamId):Eagle {
|
||||||
var eageleConfig = config.getTeam(teamId).eagle;
|
var eageleConfig = config.getTeam(teamId).eagle;
|
||||||
var eagle = new Eagle(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), teamId, eageleConfig);
|
var eagle = new Eagle(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), teamId, eageleConfig);
|
||||||
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
eagle.color = config.getColor(new PlayerId(teamId, -1));
|
||||||
return eagle;
|
return eagle;
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ class EntityBuilder {
|
|||||||
|
|
||||||
public function buildBonus(point:EntityPoint, type:BonusType):Bonus {
|
public function buildBonus(point:EntityPoint, type:BonusType):Bonus {
|
||||||
var bonusConfig = config.getBonus(type);
|
var bonusConfig = config.getBonus(type);
|
||||||
var bonus = new Bonus(++entityId, buildRect(point, config.map.cellWidth * 2, config.map.cellHeight * 2), bonusConfig);
|
var bonus = new Bonus(++entityId, buildRect(point, config.map.cell.width * 2, config.map.cell.height * 2), bonusConfig);
|
||||||
return bonus;
|
return bonus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,17 +25,18 @@ import ru.m.tankz.Type;
|
|||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
public var level(default, null):LevelConfig;
|
||||||
public var engine(default, null):IEngine;
|
public var engine(default, null):IEngine;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
public var pause(default, set):Bool;
|
public var pause(default, set):Bool;
|
||||||
|
public var controls(default, null):Map<String, Control>;
|
||||||
private var controls:Map<String, Control>;
|
|
||||||
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
this.type = state.type;
|
this.type = state.type;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.level = level;
|
||||||
this.teams = new Map();
|
this.teams = new Map();
|
||||||
this.config = configBundle.get(type);
|
this.config = configBundle.get(type);
|
||||||
this.controlFactory = new NoneControlFactory();
|
this.controlFactory = new NoneControlFactory();
|
||||||
@@ -71,8 +72,9 @@ import ru.m.tankz.Type;
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case START(state):
|
case START(state, level):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.level = level;
|
||||||
case COMPLETE(state, winnerId):
|
case COMPLETE(state, winnerId):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.winner = winnerId;
|
this.winner = winnerId;
|
||||||
@@ -98,8 +100,8 @@ import ru.m.tankz.Type;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function start():Void {
|
public function start():Void {
|
||||||
var level:LevelConfig = state.level;
|
// ToDo: Spawner not in Team?
|
||||||
var points:Array<SpawnPoint> = level.points != null ? level.points : config.points;
|
var points:Array<SpawnPoint> = level != null && level.points != null ? level.points : config.points;
|
||||||
for (teamConfig in state.preset.teams) {
|
for (teamConfig in state.preset.teams) {
|
||||||
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
var teamPoints = points.filter(function(p:SpawnPoint) return p.team == teamConfig.id);
|
||||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.LevelConfig;
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import ru.m.geom.Position;
|
import ru.m.geom.Position;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
@@ -32,8 +33,8 @@ enum SpawnEvent {
|
|||||||
|
|
||||||
typedef Shot = {
|
typedef Shot = {
|
||||||
var tankId:Int;
|
var tankId:Int;
|
||||||
@:optional var bulletId:Int;
|
@:optional var bulletId:Null<Int>;
|
||||||
@:optional var score:Int;
|
@:optional var score:Null<Int>;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HitEvent {
|
enum HitEvent {
|
||||||
@@ -73,7 +74,7 @@ enum ChangeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GameEvent {
|
enum GameEvent {
|
||||||
START(state:GameState);
|
START(state:GameState, level:LevelConfig);
|
||||||
SPAWN(event:SpawnEvent);
|
SPAWN(event:SpawnEvent);
|
||||||
MOVE(event:MoveEvent);
|
MOVE(event:MoveEvent);
|
||||||
STOP(event:StopEvent);
|
STOP(event:StopEvent);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.LevelConfig;
|
||||||
import ru.m.geom.Line;
|
import ru.m.geom.Line;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
@@ -19,10 +20,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
private var builder:EntityBuilder;
|
private var builder:EntityBuilder;
|
||||||
|
|
||||||
public function new(state:GameState) {
|
public function new(state:GameState, level:LevelConfig) {
|
||||||
super(state);
|
super(state, level);
|
||||||
this.builder = new EntityBuilder(config);
|
this.builder = new EntityBuilder(config);
|
||||||
this.engine = new Engine(config);
|
this.engine = new Engine(config, level.size);
|
||||||
this.engine.connect(this);
|
this.engine.connect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +52,8 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
|
|
||||||
override public function start():Void {
|
override public function start():Void {
|
||||||
super.start();
|
super.start();
|
||||||
engine.map.setData(state.level.data);
|
var mapData = level.data.map(function(index:BrickIndex) return config.getBrickByIndex(index));
|
||||||
|
engine.map.setData(mapData);
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
team.spawner.runner = spawn;
|
team.spawner.runner = spawn;
|
||||||
for (player in team.players.iterator()) {
|
for (player in team.players.iterator()) {
|
||||||
@@ -67,13 +69,16 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
gameEventSignal.emit(EventUtil.buildBricksSpawn(engine.map));
|
||||||
gameEventSignal.emit(START(state));
|
gameEventSignal.emit(START(state, level));
|
||||||
//for (i in 0...10) spawnBonus();
|
//for (i in 0...10) spawnBonus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function spawn(task:SpawnTask):Void {
|
private function spawn(task:SpawnTask):Void {
|
||||||
var player = getPlayer(task.playerId);
|
var player = getPlayer(task.playerId);
|
||||||
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color, player.state.name);
|
var tank = builder.buildTank(task.point, task.playerId, task.tankType, player.state.color, player.state.name);
|
||||||
|
if (getTeam(player.id.team).freezing) {
|
||||||
|
tank.freezing = true;
|
||||||
|
}
|
||||||
engine.spawn(tank);
|
engine.spawn(tank);
|
||||||
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
gameEventSignal.emit(EventUtil.buildTankSpawn(tank));
|
||||||
if (player.config.protect > 0) {
|
if (player.config.protect > 0) {
|
||||||
@@ -101,6 +106,8 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
|
|
||||||
private function freezeTank(tank:Tank, duration:Float):Void {
|
private function freezeTank(tank:Tank, duration:Float):Void {
|
||||||
tank.freezing = true;
|
tank.freezing = true;
|
||||||
|
tank.stop();
|
||||||
|
gameEventSignal.emit(STOP(TANK(tank.id)));
|
||||||
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
||||||
engine.ticker.emit(function() {
|
engine.ticker.emit(function() {
|
||||||
tank.freezing = false;
|
tank.freezing = false;
|
||||||
@@ -108,12 +115,30 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}, Std.int(duration * 1000));
|
}, Std.int(duration * 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function freezeTeam(teamId:TeamId, duration:Float):Void {
|
||||||
|
getTeam(teamId).freezing = true;
|
||||||
|
for (tank in engine.iterTanks(teamTank(teamId))) {
|
||||||
|
tank.freezing = true;
|
||||||
|
tank.stop();
|
||||||
|
gameEventSignal.emit(STOP(TANK(tank.id)));
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
||||||
|
}
|
||||||
|
engine.ticker.emit(function() {
|
||||||
|
getTeam(teamId).freezing = false;
|
||||||
|
for (tank in engine.iterTanks(teamTank(teamId))) {
|
||||||
|
tank.freezing = false;
|
||||||
|
gameEventSignal.emit(CHANGE(TANK_FREEZE(tank.id, tank.freezing)));
|
||||||
|
}
|
||||||
|
}, Std.int(duration * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
private function checkComplete():Void {
|
private function checkComplete():Void {
|
||||||
var actives:Array<TeamId> = [];
|
var actives:Array<TeamId> = [];
|
||||||
for (team in teams.iterator()) {
|
for (team in teams.iterator()) {
|
||||||
if (team.isAlive) {
|
if (team.isAlive) {
|
||||||
if (team.eagleId > -1) {
|
if (team.eagleId > -1) {
|
||||||
if (!cast(engine.entities[team.eagleId], Eagle).death) {
|
var eagle:Eagle = engine.getEntity(team.eagleId);
|
||||||
|
if (!eagle.death) {
|
||||||
actives.push(team.id);
|
actives.push(team.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -121,11 +146,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (actives.length == 1) {
|
switch actives {
|
||||||
complete(actives[0]);
|
case [winner]: complete(winner);
|
||||||
}
|
case []: complete(null);
|
||||||
if (actives.length == 0) {
|
case _:
|
||||||
complete(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +162,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
public function onSpawn(entity:EntityType):Void {
|
public function onSpawn(entity:EntityType):Void {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function buildShot(bullet:Bullet, score:Int = 0):Shot {
|
private static function buildShot(bullet:Bullet, score:Null<Int> = null):Shot {
|
||||||
return {
|
return {
|
||||||
tankId: bullet.tank.id,
|
tankId: bullet.tank.id,
|
||||||
bulletId: bullet.id,
|
bulletId: bullet.id,
|
||||||
@@ -200,7 +224,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
emitTankChange(tank);
|
emitTankChange(tank);
|
||||||
} else {
|
} else {
|
||||||
var score = tank.config.score;
|
var score = tank.config.score;
|
||||||
if (tank.playerId.team == bullet.playerId.team) {
|
if (score != null && tank.playerId.team == bullet.playerId.team) {
|
||||||
score = Math.round(score * -0.5);
|
score = Math.round(score * -0.5);
|
||||||
}
|
}
|
||||||
gameEventSignal.emit(DESTROY(TANK(tank.id, buildShot(bullet, score))));
|
gameEventSignal.emit(DESTROY(TANK(tank.id, buildShot(bullet, score))));
|
||||||
@@ -230,8 +254,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
public function onDestroy(entity:EntityType):Void {
|
public function onDestroy(entity:EntityType):Void {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function spawnBonus():Void {
|
private function spawnBonus(type:BonusType = null):Void {
|
||||||
var type = config.bonuses[Math.floor(Math.random() * config.bonuses.length)].type;
|
if (type == null) {
|
||||||
|
type = config.bonuses[Math.floor(Math.random() * config.bonuses.length)].type;
|
||||||
|
}
|
||||||
var point = {
|
var point = {
|
||||||
x: Math.floor(Math.random() * (engine.map.gridWidth - 1)),
|
x: Math.floor(Math.random() * (engine.map.gridWidth - 1)),
|
||||||
y: Math.floor(Math.random() * (engine.map.gridHeight - 1)),
|
y: Math.floor(Math.random() * (engine.map.gridHeight - 1)),
|
||||||
@@ -242,6 +268,10 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
gameEventSignal.emit(EventUtil.buildBonusSpawn(bonus));
|
gameEventSignal.emit(EventUtil.buildBonusSpawn(bonus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inline function teamTank(team:TeamId):Tank->Bool {
|
||||||
|
return function(tank:Tank):Bool return team == tank.playerId.team;
|
||||||
|
}
|
||||||
|
|
||||||
private inline function alienTank(team:TeamId):Tank->Bool {
|
private inline function alienTank(team:TeamId):Tank->Bool {
|
||||||
return function(tank:Tank):Bool return team != tank.playerId.team;
|
return function(tank:Tank):Bool return team != tank.playerId.team;
|
||||||
}
|
}
|
||||||
@@ -259,11 +289,14 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
case "helmet":
|
case "helmet":
|
||||||
protectTank(tank, bonus.config.duration);
|
protectTank(tank, bonus.config.duration);
|
||||||
case "clock":
|
case "clock":
|
||||||
for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
for (team in teams) {
|
||||||
freezeTank(t, bonus.config.duration);
|
if (team.id != tank.playerId.team) {
|
||||||
t.stop();
|
freezeTeam(team.id, bonus.config.duration);
|
||||||
gameEventSignal.emit(STOP(TANK(t.id)));
|
}
|
||||||
}
|
}
|
||||||
|
/*for (t in engine.iterTanks(alienTank(tank.playerId.team))) {
|
||||||
|
freezeTank(t, bonus.config.duration);
|
||||||
|
}*/
|
||||||
case "shovel":
|
case "shovel":
|
||||||
// ToDo: protect eagle/area
|
// ToDo: protect eagle/area
|
||||||
var team:Team = teams[tank.playerId.team];
|
var team:Team = teams[tank.playerId.team];
|
||||||
@@ -350,7 +383,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
case DESTROY(EAGLE(id, shot)):
|
case DESTROY(EAGLE(id, shot)):
|
||||||
var eagle:Eagle = engine.getEntity(id);
|
var eagle:Eagle = engine.getEntity(id);
|
||||||
eagle.death = true;
|
eagle.death = true;
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
var tank:Tank = engine.getEntity(shot.tankId);
|
var tank:Tank = engine.getEntity(shot.tankId);
|
||||||
changeScore(tank.playerId, shot.score);
|
changeScore(tank.playerId, shot.score);
|
||||||
}
|
}
|
||||||
@@ -376,7 +409,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
if (tank.bonus && shot.bulletId != null) {
|
if (tank.bonus && shot.bulletId != null) {
|
||||||
spawnBonus();
|
spawnBonus();
|
||||||
}
|
}
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
var shooterTank:Tank = engine.getEntity(shot.tankId);
|
var shooterTank:Tank = engine.getEntity(shot.tankId);
|
||||||
changeScore(shooterTank.playerId, shot.score);
|
changeScore(shooterTank.playerId, shot.score);
|
||||||
}
|
}
|
||||||
@@ -385,7 +418,7 @@ class GameRunner extends Game implements EngineListener {
|
|||||||
var bonus:Bonus = engine.getEntity(id);
|
var bonus:Bonus = engine.getEntity(id);
|
||||||
var tank:Tank = engine.getEntity(shot.tankId);
|
var tank:Tank = engine.getEntity(shot.tankId);
|
||||||
applyBonus(tank, bonus);
|
applyBonus(tank, bonus);
|
||||||
if (shot.score != 0) {
|
if (shot.score != null) {
|
||||||
changeScore(tank.playerId, shot.score);
|
changeScore(tank.playerId, shot.score);
|
||||||
}
|
}
|
||||||
engine.destroy(id);
|
engine.destroy(id);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ru.m.tankz.game;
|
|||||||
|
|
||||||
import haxework.color.Color;
|
import haxework.color.Color;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
@@ -72,21 +71,17 @@ class GameState {
|
|||||||
|
|
||||||
public var type:GameType;
|
public var type:GameType;
|
||||||
public var presetId:PresetId;
|
public var presetId:PresetId;
|
||||||
public var levelId:LevelId;
|
|
||||||
public var controls:Array<PlayerControl>;
|
public var controls:Array<PlayerControl>;
|
||||||
public var players:Map<String, PlayerState>;
|
public var players:Map<String, PlayerState>;
|
||||||
public var teams:Map<TeamId, TeamState>;
|
public var teams:Map<TeamId, TeamState>;
|
||||||
public var preset(get, null):GamePreset;
|
public var preset(get, null):GamePreset;
|
||||||
public var config(get, null):Config;
|
public var config(get, null):Config;
|
||||||
public var level(get, null):LevelConfig;
|
|
||||||
|
|
||||||
@:provide static private var configBundle:IConfigBundle;
|
@:provide static private var configBundle:IConfigBundle;
|
||||||
@:provide static private var levelBundle:ILevelBundle;
|
|
||||||
|
|
||||||
public function new(type:GameType, presetId:PresetId = 0, levelId:Int = 0, state:GameState = null, controls:Array<PlayerControl> = null) {
|
public function new(type:GameType, presetId:PresetId = 0, state:GameState = null, controls:Array<PlayerControl> = null) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.presetId = presetId;
|
this.presetId = presetId;
|
||||||
this.levelId = levelId;
|
|
||||||
//this.controls = controls == null ? config.controls[0].values : controls;
|
//this.controls = controls == null ? config.controls[0].values : controls;
|
||||||
this.controls = controls == null ? [] : controls;
|
this.controls = controls == null ? [] : controls;
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
@@ -118,10 +113,6 @@ class GameState {
|
|||||||
return configBundle.get(type);
|
return configBundle.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_level():LevelConfig {
|
|
||||||
return levelBundle.get(type, config, levelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTeamLife(id:TeamId):Int {
|
public function getTeamLife(id:TeamId):Int {
|
||||||
if (teams.exists(id)) {
|
if (teams.exists(id)) {
|
||||||
return teams[id].life + Lambda.fold(teams[id].players, function(p, c) return c + p.life, 0);
|
return teams[id].life + Lambda.fold(teams[id].players, function(p, c) return c + p.life, 0);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package ru.m.tankz.game;
|
|||||||
|
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.control.IControlFactory;
|
import ru.m.tankz.control.IControlFactory;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
@@ -11,8 +12,10 @@ interface IGame extends GameListener {
|
|||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
public var level(default, null):LevelConfig;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
public var pause(default, set):Bool;
|
public var pause(default, set):Bool;
|
||||||
|
public var controls(default, null):Map<String, Control>;
|
||||||
|
|
||||||
public var gameEventSignal(default, null):Signal<GameEvent>;
|
public var gameEventSignal(default, null):Signal<GameEvent>;
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ typedef LevelProgress = {
|
|||||||
var presets:Map<Int, LevelResult>;
|
var presets:Map<Int, LevelResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameProgress {
|
class PackProgress {
|
||||||
|
|
||||||
|
public var id(default, null):PackId;
|
||||||
|
|
||||||
public var type(default, null):GameType;
|
|
||||||
private var completed(default, null):Map<Int, LevelProgress>;
|
private var completed(default, null):Map<Int, LevelProgress>;
|
||||||
|
|
||||||
public function new(type:GameType) {
|
public function new(id:PackId) {
|
||||||
this.type = type;
|
this.id = id;
|
||||||
this.completed = new Map();
|
this.completed = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.game;
|
package ru.m.tankz.game;
|
||||||
|
|
||||||
import ru.m.tankz.game.GameState.TeamState;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class Team {
|
class Team {
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ class Team {
|
|||||||
public var eagleId(default, default):Int;
|
public var eagleId(default, default):Int;
|
||||||
private var active(default, default):Int;
|
private var active(default, default):Int;
|
||||||
public var state(default, default):TeamState;
|
public var state(default, default):TeamState;
|
||||||
|
public var freezing(default, default):Bool;
|
||||||
|
|
||||||
public function new(config:TeamConfig, points:Array<SpawnPoint>, state:TeamState = null) {
|
public function new(config:TeamConfig, points:Array<SpawnPoint>, state:TeamState = null) {
|
||||||
this.id = config.id;
|
this.id = config.id;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class GamePlayer extends Game {
|
|||||||
private var ticker:Ticker;
|
private var ticker:Ticker;
|
||||||
|
|
||||||
public function new(record:GameRecord) {
|
public function new(record:GameRecord) {
|
||||||
super(record.state);
|
super(record.state, null);
|
||||||
this.record = record;
|
this.record = record;
|
||||||
this.data = null;
|
this.data = null;
|
||||||
this.ticker = new Ticker();
|
this.ticker = new Ticker();
|
||||||
@@ -26,10 +26,12 @@ class GamePlayer extends Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function stop():Void {
|
public function stop():Void {
|
||||||
|
ticker.stop();
|
||||||
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onEnterFrame(event:Event):Void {
|
private function onEnterFrame(event:Event):Void {
|
||||||
|
ticker.tick();
|
||||||
var events = 0;
|
var events = 0;
|
||||||
for (event in data) {
|
for (event in data) {
|
||||||
if (event.time <= ticker.time) {
|
if (event.time <= ticker.time) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class GameRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline function get_state():GameState {
|
private inline function get_state():GameState {
|
||||||
return new GameState(info.type, info.presetId, info.levelId);
|
return new GameState(info.type, info.presetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toString():String {
|
public function toString():String {
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ class GameRecorder implements GameListener {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case GameEvent.START(state):
|
case GameEvent.START(state, level):
|
||||||
ticker.start();
|
ticker.start();
|
||||||
record.info.type = state.type;
|
record.info.type = state.type;
|
||||||
record.info.presetId = state.presetId;
|
record.info.presetId = state.presetId;
|
||||||
record.info.levelId = state.levelId;
|
record.info.levelId = level.id;
|
||||||
record.info.date = Date.now();
|
record.info.date = Date.now();
|
||||||
case GameEvent.COMPLETE(_, _):
|
case GameEvent.COMPLETE(_, _):
|
||||||
ticker.stop();
|
ticker.stop();
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ class Brick {
|
|||||||
this.mapConfig = mapConfig;
|
this.mapConfig = mapConfig;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.rect = new Rectangle(
|
this.rect = new Rectangle(
|
||||||
cellX * mapConfig.cellWidth,
|
cellX * mapConfig.cell.width,
|
||||||
cellY * mapConfig.cellHeight,
|
cellY * mapConfig.cell.height,
|
||||||
mapConfig.cellWidth,
|
mapConfig.cell.width,
|
||||||
mapConfig.cellHeight
|
mapConfig.cell.height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
import ru.m.tankz.config.Config.GridSize;
|
||||||
|
import ru.m.tankz.config.Config.CellSize;
|
||||||
import ru.m.geom.Line;
|
import ru.m.geom.Line;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
@@ -13,10 +15,10 @@ class GridCell {
|
|||||||
public var position(default, null):Point;
|
public var position(default, null):Point;
|
||||||
public var rect(default, null):Rectangle;
|
public var rect(default, null):Rectangle;
|
||||||
public var layer:Int;
|
public var layer:Int;
|
||||||
public var armor:Int;
|
public var armor:Float;
|
||||||
public var destroyed(default, set):Bool;
|
public var destroyed(default, set):Bool;
|
||||||
|
|
||||||
public function new(cellX:Int, cellY:Int, width:Int, height:Int, layer:Int, armor:Int) {
|
public function new(cellX:Int, cellY:Int, width:Int, height:Int, layer:Int, armor:Float) {
|
||||||
this.cellX = cellX;
|
this.cellX = cellX;
|
||||||
this.cellY = cellY;
|
this.cellY = cellY;
|
||||||
this.position = new Point(cellX, cellY);
|
this.position = new Point(cellX, cellY);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.m.tankz.map;
|
package ru.m.tankz.map;
|
||||||
|
|
||||||
|
import ru.m.tankz.Type.BrickType;
|
||||||
import haxe.ds.HashMap;
|
import haxe.ds.HashMap;
|
||||||
import ru.m.tankz.map.Grid;
|
import ru.m.tankz.map.Grid;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
@@ -24,12 +25,12 @@ class LevelMap {
|
|||||||
|
|
||||||
private var bricksMap(default, null):HashMap<Point, Brick>;
|
private var bricksMap(default, null):HashMap<Point, Brick>;
|
||||||
|
|
||||||
public function new(config:MapConfig) {
|
public function new(config:MapConfig, size:GridSize = null) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
cellWidth = config.cellWidth;
|
cellWidth = config.cell.width;
|
||||||
cellHeight = config.cellHeight;
|
cellHeight = config.cell.width;
|
||||||
gridWidth = config.gridWidth;
|
gridWidth = size != null ? size.width : config.grid.width;
|
||||||
gridHeight = config.gridHeight;
|
gridHeight = size != null ? size.height : config.grid.width;
|
||||||
bricksMap = new HashMap();
|
bricksMap = new HashMap();
|
||||||
bricks = [];
|
bricks = [];
|
||||||
grid = new Grid(
|
grid = new Grid(
|
||||||
@@ -67,16 +68,16 @@ class LevelMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getPointBrick(point:Point):Brick {
|
public function getPointBrick(point:Point):Brick {
|
||||||
var cellX:Int = Math.floor(point.x / config.cellWidth);
|
var cellX:Int = Math.floor(point.x / cellWidth);
|
||||||
var cellY:Int = Math.floor(point.y / config.cellHeight);
|
var cellY:Int = Math.floor(point.y / cellHeight);
|
||||||
return bricks[cellX + cellY * config.gridWidth];
|
return bricks[cellX + cellY * gridWidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function get_width():Float {
|
private inline function get_width():Float {
|
||||||
return config.cellWidth * config.gridWidth;
|
return cellWidth * gridWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function get_height():Float {
|
private inline function get_height():Float {
|
||||||
return config.cellHeight * config.gridHeight;
|
return cellHeight * gridHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package ru.m.tankz.util;
|
package ru.m.tankz.util;
|
||||||
|
|
||||||
|
import haxe.io.Bytes;
|
||||||
|
import haxe.io.BytesInput;
|
||||||
|
import haxe.zip.Entry;
|
||||||
|
import haxe.zip.Reader;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
import yaml.Parser;
|
import yaml.Parser;
|
||||||
import yaml.Renderer;
|
import yaml.Renderer;
|
||||||
import yaml.Yaml;
|
import yaml.Yaml;
|
||||||
@@ -9,6 +14,7 @@ typedef LevelSource = {
|
|||||||
var data:String;
|
var data:String;
|
||||||
@:optional var name:String;
|
@:optional var name:String;
|
||||||
@:optional var points:Array<SpawnPoint>;
|
@:optional var points:Array<SpawnPoint>;
|
||||||
|
@:optional var size:GridSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LevelUtil {
|
class LevelUtil {
|
||||||
@@ -19,12 +25,12 @@ class LevelUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loadsOld(config:Config, data:String):LevelConfig {
|
public static function loadsOld(data:String):LevelConfig {
|
||||||
var bricks:Array<BrickConfig> = [];
|
var bricks:Array<BrickIndex> = [];
|
||||||
for (line in ~/\s+/g.split(data)) {
|
for (line in ~/\s+/g.split(data)) {
|
||||||
for (c in line.split('')) {
|
for (c in line.split('')) {
|
||||||
if (c.length > 0) {
|
if (c.length > 0) {
|
||||||
bricks.push(config.getBrickByIndex(Std.parseInt(c)));
|
bricks.push(Std.parseInt(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,31 +39,56 @@ class LevelUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function loads(config:Config, data:String):LevelConfig {
|
public static function loads(data:String):LevelConfig {
|
||||||
if (config.type == 'classic') {
|
// If first char is digit load as old format
|
||||||
return loadsOld(config, data);
|
if (Std.parseInt(data.charAt(0)) != null) {
|
||||||
|
return loadsOld(data);
|
||||||
} else {
|
} else {
|
||||||
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
|
var obj:LevelSource = Yaml.parse(data, Parser.options().useObjects());
|
||||||
return {
|
return {
|
||||||
data: obj.data.split('').map(function(c) return config.getBrickByIndex(Std.parseInt(c))),
|
data: obj.data.split('').map(function(c) return Std.parseInt(c)),
|
||||||
points: obj.points,
|
points: obj.points,
|
||||||
name: obj.name,
|
name: obj.name,
|
||||||
|
size: obj.size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dumps(config:Config, level:LevelConfig):String {
|
public static function dumps(config:Config, level:LevelConfig):String {
|
||||||
var bricksStr = level.data.map(function(brick:BrickConfig) return Std.string(brick.index)).join('');
|
var bricksStr = level.data.join('');
|
||||||
return Yaml.render({
|
return Yaml.render({
|
||||||
data: bricksStr,
|
data: bricksStr,
|
||||||
points: level.points,
|
points: level.points,
|
||||||
name: level.name,
|
name: level.name,
|
||||||
|
size: level.size,
|
||||||
}, Renderer.options().setFlowLevel(1));
|
}, Renderer.options().setFlowLevel(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function empty(config:Config):LevelConfig {
|
public static function empty(size:GridSize, filler:BrickIndex):LevelConfig {
|
||||||
return {
|
return {
|
||||||
data: [for (i in 0...config.map.gridWidth * config.map.gridHeight) config.bricks[1]]
|
data: [for (i in 0...size.width * size.height) filler],
|
||||||
|
size: size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function extract(entry:Entry):LevelConfig {
|
||||||
|
var bytes:Bytes = entry.data;
|
||||||
|
if (entry.compressed) {
|
||||||
|
#if ((flash || html5) && lime)
|
||||||
|
bytes = cast(bytes, lime.utils.Bytes).decompress(lime.utils.CompressionAlgorithm.DEFLATE);
|
||||||
|
#else
|
||||||
|
bytes = haxe.zip.Reader.unzip(entry);
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
var level = LevelUtil.loads(bytes.toString());
|
||||||
|
if (level.id == null) {
|
||||||
|
level.id = Std.parseInt(entry.fileName.split("level").pop());
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function unpack(bytes:Bytes):Array<LevelConfig> {
|
||||||
|
var files = Reader.readZip(new BytesInput(bytes));
|
||||||
|
return Lambda.array(files.map(extract));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user