47 Commits

Author SHA1 Message Date
112cd7ba2f up version 2019-09-09 21:44:29 +03:00
77ddd78d84 [editor] support level pack edit 2019-09-09 17:56:08 +03:00
4fa5cf84fa [editor] add PackListFrame 2019-09-06 16:23:31 +03:00
40bdf6a5cc [build] downgrade lime,openfl (perfomance); remove yield 2019-09-05 22:02:54 +03:00
47039bbaa5 [build] up dependencies versions 2019-09-05 10:45:07 +03:00
4d7fcb4b4b [client] Updater update 2019-09-04 22:46:06 +03:00
5f24e85deb [build] app gulp-haxetool version 2019-09-03 21:05:36 +03:00
42fd008a54 [build] fixes for windows 2019-09-03 20:57:28 +03:00
c2b0618c93 [build] update publish task 2019-09-02 17:07:31 +03:00
94f72f71e3 [build] up openfl and lime versions 2019-09-02 01:00:32 +03:00
bb4b928c89 Merge remote-tracking branch 'origin/windows' into develop 2019-09-01 23:15:07 +03:00
d67d4e5709 [editor] fix 2019-08-30 16:06:45 +03:00
a4bbeb2573 up version 2019-08-30 15:52:23 +03:00
e032c25e1a [client] add Updater 2019-08-29 17:43:09 +03:00
d9cce32bb8 [common] saveState param in PlayerConfig 2019-08-28 17:54:41 +03:00
10d5e0df40 [gulp] add windows target 2019-08-28 07:24:19 +03:00
0f3392aa0c [client] gamepad: update SmartActionAreaBuilder 2019-08-27 21:17:26 +03:00
9d4558ca47 [client] GameView rework 2019-08-27 17:35:22 +03:00
6609756065 [work] update list 2019-08-26 23:04:38 +03:00
605935528b [gulp] add publish task 2019-08-26 14:44:51 +03:00
f072d8dc6e [client] add android build 2019-08-23 14:57:12 +03:00
00cd404a98 up version 2019-08-21 21:27:24 +03:00
d47be9ea8a [common] config: add bonus spwan interval 2019-08-19 20:57:36 +03:00
2d70a5652b [comon] ArmorEagleBonus improve 2019-08-18 15:57:29 +03:00
bbf1438728 [work] update work list 2019-08-16 22:39:49 +03:00
c0496f2e7c [client] bullet skins 2019-08-14 18:00:56 +03:00
636be8611f [common] weapon queue & bullet layer 2019-08-13 21:53:47 +03:00
48f9c433e2 [common] multiple weapon support 2019-08-13 16:41:57 +03:00
314f5a480c [common] add tank weapon array 2019-08-12 22:02:28 +03:00
46f2abab05 [client] screen gamepad as default on mobile devices 2019-08-07 17:47:11 +03:00
883f14fb76 up version 2019-08-06 21:40:01 +03:00
cc151322d8 [common] add ice brick logic 2019-08-06 17:47:00 +03:00
de64e2813e [common] add ArmorEagleBonus 2019-08-06 16:19:38 +03:00
db80c151bb [common] add bonuses classes 2019-08-05 23:02:04 +03:00
ef971e03b9 Merge branch 'develop' of bitbucket.org:infernalgames/tankz into develop 2019-08-02 17:50:47 +03:00
f10da93a12 [client] add result styles 2019-08-02 17:48:34 +03:00
e63b41ae8a up version 2019-08-01 22:21:19 +03:00
43a34cce39 [client] update ResultFrame 2019-08-01 17:15:16 +03:00
b9b5453f89 [client] update ResultFrame 2019-07-31 17:59:13 +03:00
f5af6716d5 up version 2019-07-29 21:50:48 +03:00
7125cc1e9f [client] rework GamePanel 2019-07-29 17:57:33 +03:00
8a3ceec1ee up version 2019-07-26 14:23:10 +03:00
523f334c1b [client] text.box style update 2019-07-26 12:04:59 +03:00
a547b68dc0 [client] SettingsEditor fixes 2019-07-24 17:32:48 +03:00
45cabc1926 up version 2019-07-23 17:38:31 +03:00
42138cd4ad [client] improve GamepadView 2019-07-23 17:37:59 +03:00
e8e3a6f1b3 [client] improve StartFrame 2019-07-23 16:39:43 +03:00
177 changed files with 5354 additions and 1945 deletions

View File

@@ -7,3 +7,6 @@ indent_style = space
indent_size = 4 indent_size = 4
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.yaml]
indent_size = 2

View File

@@ -1,3 +1,18 @@
0.17.0
------
* Improved `ResultFrame`
* Improved bonuses
* Set `DeviceType.SCREEN` as default on mobile devices
0.16.0
------
* Added `GamepadView` for sensor control
* Added `AppTheme`
* Replace `LevelPopup` with `StartFrame`
* Added `LevelPack`
* Added scrolls to lists
* Fixed `GameView` size for small screens
0.15.0 0.15.0
------ ------
* Added display tank player name in `Render` * Added display tank player name in `Render`

31
WORK.md
View File

@@ -1,11 +1,22 @@
* **shovel** bonus with armor bricks * bonuses
* bonuses in dota/death mod * death game bonuses
* boat bonus
* tanks and bullets speed balancing * tanks and bullets speed balancing
* result frame update (next game select, only human player info) * game series
* network game series * network series
* map packs (create in editor, import in game, save imported in local storage) * map packs
* update bots * create in editor
* improve bonuses system * import in game
* screen gamepad on mobiles * save imported in local storage
* resize render on mobiles * database
* save state in classic game * cache
* improve bots
* A star
* game config validate
* additional weapon
* mine
* display count
* bonus ammo
* screen gamepad (button enabled, count label)
* ui:
* game frame layouts

View File

@@ -5,7 +5,7 @@ project_user: holop
deploy_user: "{{ project_user }}" deploy_user: "{{ project_user }}"
deploy_project: "{{ project_name }}" deploy_project: "{{ project_name }}"
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git" deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
deploy_repo_version: master deploy_repo_version: develop
deploy_npm: yes deploy_npm: yes
service_name: "{{ project_name }}" service_name: "{{ project_name }}"

View File

@@ -1,5 +1,7 @@
{ {
"SdkDir": "C:\\sdk", "SdkDir": "C:\\sdk",
"PublishDir": "",
"PublishUrl": "https://shmyga.ru/repo/tankz",
"SSH": { "SSH": {
"PrivateKey": null, "PrivateKey": null,
"Passphrase": null "Passphrase": null

View File

@@ -1,5 +1,7 @@
{ {
"SdkDir": "/home/holop/sdk", "SdkDir": "/home/holop/sdk",
"PublishDir": "/opt/repo/tankz",
"PublishUrl": "https://shmyga.ru/repo/tankz",
"SSH": { "SSH": {
"PrivateKey": null, "PrivateKey": null,
"Passphrase": null "Passphrase": null

View File

@@ -1,16 +1,12 @@
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');
const {Sdk, Haxe, Project, FlashPlayer} = require('gulp-haxetool'); const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
const dateformat = require('dateformat'); const dateformat = require('dateformat');
const argv = require('yargs').argv; const argv = require('yargs').argv;
const publish = require('./tasks/gulp-publish');
// ToDo: update default in gulp-haxetool
FlashPlayer.VERSION = '32';
//Haxe.VERSION = '4.0.0-rc.2';
if (Config.SdkDir) { if (Config.SdkDir) {
Sdk.dir = Config.SdkDir; Sdk.dir = Config.SdkDir;
} }
@@ -27,23 +23,8 @@ 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: * base config
* windows target
* window exe package (innosetup)
*/ */
const config = new Project.Config({ const config = new Project.Config({
meta: { meta: {
@@ -62,7 +43,6 @@ const config = new Project.Config({
], ],
assets: [ assets: [
'src/common/resources', 'src/common/resources',
'target/levels'
], ],
flags: [ flags: [
//'proto_debug', //'proto_debug',
@@ -84,11 +64,15 @@ const client = new Project(
Project.Platform.FLASH, Project.Platform.FLASH,
Project.Platform.HTML5, Project.Platform.HTML5,
Project.Platform.LINUX, Project.Platform.LINUX,
Project.Platform.WINDOWS,
Project.Platform.ANDROID, Project.Platform.ANDROID,
], ],
config.branch({ config.branch({
name: 'client', name: 'client',
sources: ['src/client/haxe'], sources: [
//'src/fixes/haxe',
'src/client/haxe',
],
main: 'ru.m.tankz.Client', main: 'ru.m.tankz.Client',
preloader: 'ru.m.tankz.Preloader', preloader: 'ru.m.tankz.Preloader',
assets: [ assets: [
@@ -109,7 +93,6 @@ const client = new Project(
`CompilationOption.set('port',${port})`, `CompilationOption.set('port',${port})`,
] ]
}), }),
module.exports.generate
).bind(module, gulp); ).bind(module, gulp);
/** /**
@@ -123,7 +106,11 @@ const editor = new Project(
], ],
config.branch({ config.branch({
name: 'editor', name: 'editor',
sources: ['src/client/haxe', 'src/editor/haxe'], sources: [
//'src/fixes/haxe',
'src/client/haxe',
'src/editor/haxe',
],
main: 'ru.m.tankz.editor.Editor', main: 'ru.m.tankz.editor.Editor',
preloader: 'ru.m.tankz.Preloader', preloader: 'ru.m.tankz.Preloader',
assets: [ assets: [
@@ -133,7 +120,7 @@ const editor = new Project(
meta: { meta: {
filename: 'editor', filename: 'editor',
width: 1024, width: 1024,
height: 850, height: 768,
}, },
flags: [ flags: [
//'dev_layout', //'dev_layout',
@@ -152,25 +139,50 @@ const server = new Project(
sources: ['src/server/haxe'], sources: ['src/server/haxe'],
main: 'ru.m.tankz.server.Server', main: 'ru.m.tankz.server.Server',
}), }),
module.exports.generate
).bind(module, gulp); ).bind(module, gulp);
/**
* publish
*/
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
/** /**
* default * default
*/ */
module.exports.default = gulp.series( const defaultSeries = [
exports.clean, exports.clean,
exports.levels, exports.generate,
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'],
module.exports['client:linux:build'],
module.exports['client:linux:deb'],
//module.exports['client:android:build'],
module.exports['editor:flash:build'], module.exports['editor:flash:build'],
module.exports['editor:flash:html'], module.exports['editor:flash:html'],
module.exports['editor:html5:build'], module.exports['editor:html5:build'],
module.exports['server:neko:build'], module.exports['server:neko:build'],
];
if (System.isLinux) {
defaultSeries.push(
module.exports['client:linux:build'],
module.exports['client:linux:archive'],
module.exports['client:linux:deb'],
module.exports['client:android:build'],
);
}
if (System.isWindows) {
defaultSeries.push(
module.exports['client:windows:build'],
module.exports['client:windows:archive'],
module.exports['client:windows:installer'],
);
}
defaultSeries.push(
exports.publish,
); );
module.exports.default = gulp.series(defaultSeries);

1550
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +1,24 @@
{ {
"name": "tankz", "name": "tankz",
"version": "0.16.0", "version": "0.17.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.1.0",
"gulp-haxetool": "0.0.20",
"gulp-zip": "^5.0.0",
"yargs": "^13.2.4" "yargs": "^13.2.4"
}, },
"haxeDependencies": { "haxeDependencies": {
"haxework": "git@bitbucket.org:shmyga/haxework.git", "haxework": "git@bitbucket.org:shmyga/haxework.git",
"lime": "7.5.0", "lime": "7.5.0",
"openfl": "8.9.1", "openfl": "8.9.1",
"hxcpp": "4.0.8", "hxcpp": "4.0.52",
"promhx": "1.1.0", "promhx": "1.1.0",
"protohx": "0.4.6", "protohx": "0.4.6",
"yaml": "1.3.0", "yaml": "1.3.0",
"orm": "2.1.0", "orm": "2.1.0",
"yield": "2.0.0",
"haxe-crypto": "0.0.7", "haxe-crypto": "0.0.7",
"svg": "1.1.2" "svg": "1.1.2"
} }

View File

@@ -1,31 +0,0 @@
-- mysql -u shmyga -pxkbp8jh9z2 armageddon --protocol TCP
CREATE USER 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
DROP DATABASE IF EXISTS armageddon;
CREATE DATABASE IF NOT EXISTS armageddon;
GRANT ALL ON armageddon.* TO 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
DROP TABLE IF EXISTS armageddon.account;
CREATE TABLE IF NOT EXISTS armageddon.account (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
login VARCHAR(255) UNIQUE,
password VARCHAR(32)
);
DROP TABLE IF EXISTS armageddon.person;
CREATE TABLE IF NOT EXISTS armageddon.person (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
account_id INT UNSIGNED NOT NULL,
name VARCHAR(255),
CONSTRAINT person_2_account FOREIGN KEY (account_id) REFERENCES armageddon.account(id)
MATCH SIMPLE ON DELETE CASCADE ON UPDATE NO ACTION
);
INSERT INTO armageddon.account (id,login,password) VALUES(1,'shmyga', 'd48cc4eb42c058869ae90daef9606e43');
INSERT INTO armageddon.person (id,account_id,name) VALUES(1,1,'-=Shmyga=-');
INSERT INTO armageddon.account (id,login,password) VALUES(2,'a', md5('a'));
INSERT INTO armageddon.person (id,account_id,name) VALUES(2,2,'a');

View File

@@ -0,0 +1,42 @@
package ru.m;
@:enum abstract Platform(String) from String to String {
var ANDROID = "android";
var LINUX = "linux";
var WINDOWS = "windows";
}
class Device {
public static var platform(get, null):Platform;
private static function get_platform():Platform {
#if android
return ANDROID;
#elseif linux
return LINUX;
#elseif windows
return WINDOWS;
#else
return null;
#end
}
private static var MOBILES(default, never):Array<String> = [
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
];
public static function isMobile():Bool {
#if android
return true;
#elseif js
var userAgent = js.Browser.navigator.userAgent;
for (mobile in MOBILES) {
if (userAgent.indexOf(mobile) > -1) {
return true;
}
}
#end
return false;
}
}

View File

@@ -0,0 +1,82 @@
package ru.m;
import haxework.net.JsonLoader;
import openfl.Lib;
import openfl.net.URLRequest;
import promhx.Promise;
import ru.m.Device;
@:enum abstract PackageType(String) from String to String {
var APK = "apk";
var DEB = "deb";
var EXE = "exe";
var ARCHIVE = "archive";
}
typedef PackageInfo = {
var platform:Platform;
var type:PackageType;
var path:String;
var filename:String;
var url:String;
}
typedef PackagesBundle = {
var name:String;
var version:String;
var packages:Array<PackageInfo>;
}
class Updater {
private static inline var TAG = "Update";
public var type(get, null):PackageType;
public var bundle(default, null):PackagesBundle;
private var url:String;
private var version:String;
public function new(version:String, url:String) {
this.url = url;
this.version = version;
}
private function get_type():PackageType {
return switch Device.platform {
case ANDROID: APK;
case LINUX: DEB;
case WINDOWS: EXE;
case _: null;
}
}
private function resolveBundle():Promise<PackagesBundle> {
return bundle != null ? Promise.promise(bundle) : new JsonLoader().GET(url).then(function(bundle) {
this.bundle = bundle;
return this.bundle;
});
}
public function check():Promise<Bool> {
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
this.bundle = bundle;
return bundle.version != version && Lambda.exists(bundle.packages, function(item) {
return item.platform == Device.platform && item.type == type;
});
});
}
public function download():Promise<Bool> {
return resolveBundle().then(function(bundle:PackagesBundle) {
for (item in bundle.packages) {
if (item.platform == Device.platform && item.type == type) {
L.i(TAG, 'download: ${item.url}');
Lib.getURL(new URLRequest(item.url));
return true;
}
}
return false;
});
}
}

View File

@@ -3,5 +3,6 @@ package ru.m.control;
enum DeviceType { enum DeviceType {
NONE; NONE;
KEYBOARD; KEYBOARD;
SCREEN;
GAMEPAD(id:Int); GAMEPAD(id:Int);
} }

View File

@@ -12,20 +12,26 @@ using haxework.color.ColorUtil;
@:style(null) private var svg:String; @:style(null) private var svg:String;
@:style(0) private var color:Null<Color>; @:style(0) private var color:Null<Color>;
@:style(false) private var solid:Null<Bool>;
private var svgs:Map<ButtonState, SVG>; private var svgs:Map<ButtonState, SVG>;
public function new(?svg:String, ?color:Color) { public function new(?svg:String, ?color:Color, ?solid:Bool) {
this.svg = svg; this.svg = svg;
this.color = color; this.color = color;
init(); this.solid = solid;
init(solid);
} }
private inline function buildSVG(color:Color):SVG { private inline function buildSVG(color:Color):SVG {
return new SVG(svg.replace("currentColor", '#${color}')); return new SVG(svg.replace("currentColor", '#${color}'));
} }
private function init():Void { private function init(solid:Bool):Void {
var color = color;
if (solid) {
color = color.multiply(1.5);
}
svgs = new Map(); svgs = new Map();
svgs.set(UP, buildSVG(color)); svgs.set(UP, buildSVG(color));
svgs.set(DOWN, buildSVG(color.diff(-24))); svgs.set(DOWN, buildSVG(color.diff(-24)));
@@ -39,7 +45,9 @@ using haxework.color.ColorUtil;
graphics.beginFill(0, 0); graphics.beginFill(0, 0);
graphics.drawRect(0, 0, view.width, view.height); graphics.drawRect(0, 0, view.width, view.height);
graphics.beginFill(color); graphics.beginFill(color);
if (!solid) {
graphics.lineStyle(2, color.multiply(1.5)); graphics.lineStyle(2, color.multiply(1.5));
}
// ToDo: padding // ToDo: padding
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8)); svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
graphics.lineStyle(); graphics.lineStyle();

View File

@@ -1,5 +1,6 @@
package ru.m.tankz; package ru.m.tankz;
import flash.text.TextFormatAlign;
import haxework.color.Color; import haxework.color.Color;
import haxework.view.geometry.Box; import haxework.view.geometry.Box;
import haxework.view.geometry.HAlign; import haxework.view.geometry.HAlign;
@@ -7,6 +8,7 @@ import haxework.view.geometry.SizeValue;
import haxework.view.geometry.VAlign; import haxework.view.geometry.VAlign;
import haxework.view.theme.ITheme; import haxework.view.theme.ITheme;
import haxework.view.theme.Theme; import haxework.view.theme.Theme;
import haxework.view.utils.DrawUtil;
import openfl.Assets; import openfl.Assets;
import ru.m.skin.ButtonSVGSkin; import ru.m.skin.ButtonSVGSkin;
@@ -41,6 +43,7 @@ class AppTheme extends Theme {
register(new Style("text.header", [ register(new Style("text.header", [
"font.size" => fontSize.big, "font.size" => fontSize.big,
"font.align" => TextFormatAlign.CENTER,
"skin.background.color" => Color.fromInt(0x000000), "skin.background.color" => Color.fromInt(0x000000),
"skin.background.alpha" => 0.1, "skin.background.alpha" => 0.1,
"skin.border.color" => colors.light, "skin.border.color" => colors.light,
@@ -59,13 +62,14 @@ class AppTheme extends Theme {
"skin.background.color" => Color.fromInt(0x000000), "skin.background.color" => Color.fromInt(0x000000),
"skin.background.alpha" => 0.1, "skin.background.alpha" => 0.1,
"skin.border.color" => colors.light, "skin.border.color" => colors.light,
"geometry.padding" => Box.fromArray([15, 8]),
], ["text"])); ], ["text"]));
register(new Style("text.box.active", [ register(new Style("text.box.active", [
"skin.background.color" => Color.fromInt(0x55aa55), "skin.background.color" => Color.fromInt(0x55aa55),
"skin.background.alpha" => 1, "skin.background.alpha" => 1,
"skin.border.color" => Color.fromInt(0x88dd88), "skin.border.color" => Color.fromInt(0x88dd88),
], ["text"])); ], ["text.box"]));
register(new Style("button.level", [ register(new Style("button.level", [
"font.size" => fontSize.veryBig, "font.size" => fontSize.veryBig,
@@ -92,7 +96,8 @@ class AppTheme extends Theme {
], ["dark", "border"])); ], ["dark", "border"]));
register(new Style("line", [ register(new Style("line", [
"_" => null, "geometry.width" => SizeValue.fromString("100%"),
"geometry.height" => SizeValue.fromInt(2),
], ["border"])); ], ["border"]));
register(new Style("window.close", [ register(new Style("window.close", [
@@ -101,6 +106,29 @@ class AppTheme extends Theme {
"geometry.height" => SizeValue.fromInt(36), "geometry.height" => SizeValue.fromInt(36),
])); ]));
register(new Style("icon.tank", [
"geometry.width" => SizeValue.fromInt(42),
"geometry.height" => SizeValue.fromInt(42),
"skin.fillType" => FillType.DEFAULT,
]));
var green:Color = 0x00ff00;
var red:Color = 0xff0000;
register(new Style("result.winner", [
"skin.border.color" => green,
], ["light"]));
register(new Style("result.loser", [
"skin.border.color" => red,
], ["light"]));
register(new Style("player.winner", [
"skin.background.alpha" => 0.1,
"skin.background.color" => green,
]));
register(new Style("player.loser", [
"skin.background.alpha" => 0.1,
"skin.background.color" => red,
]));
registerButton("settings", "cog-solid.svg"); registerButton("settings", "cog-solid.svg");
registerButton("close", "times-circle-solid.svg"); registerButton("close", "times-circle-solid.svg");
registerButton("next", "arrow-alt-circle-right-solid.svg"); registerButton("next", "arrow-alt-circle-right-solid.svg");
@@ -108,18 +136,26 @@ class AppTheme extends Theme {
registerButton("start", "play-circle-solid.svg"); registerButton("start", "play-circle-solid.svg");
registerButton("login", "sign-in-solid.svg"); registerButton("login", "sign-in-solid.svg");
registerButton("logout", "sign-out-solid.svg"); registerButton("logout", "sign-out-solid.svg");
registerButton("keyboard", "keyboard-light.svg", true);
registerButton("backspace", "backspace-light.svg", true);
registerButton("tablet-android-alt", "tablet-android-alt-light.svg", true);
register(new Style("gamepad", [
"skin.color" => colors.active,
]));
} }
private function registerButton(name:String, resource:String):Void { private function registerButton(name:String, resource:String, solid:Bool = false):Void {
register(new Style('button.$name', [ register(new Style('button.$name', [
"geometry.width" => SizeValue.fromInt(42), "geometry.width" => SizeValue.fromInt(42),
"geometry.height" => SizeValue.fromInt(42), "geometry.height" => SizeValue.fromInt(42),
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light), "skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
])); ]));
register(new Style('button.$name.small', [ register(new Style('button.$name.small', [
"geometry.width" => SizeValue.fromInt(32), "geometry.width" => SizeValue.fromInt(32),
"geometry.height" => SizeValue.fromInt(32), "geometry.height" => SizeValue.fromInt(32),
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light), "skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
])); ]));
} }

View File

@@ -1,12 +1,14 @@
package ru.m.tankz; package ru.m.tankz;
import haxework.view.theme.ITheme;
import flash.Lib; import flash.Lib;
import haxework.animate.FadeAnimate; import haxework.animate.FadeAnimate;
import haxework.animate.UnFadeAnimate; import haxework.animate.UnFadeAnimate;
import haxework.net.manage.ILoaderManager;
import haxework.net.manage.LoaderManager;
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 haxework.view.theme.ITheme;
import lime.ui.Gamepad; import lime.ui.Gamepad;
import lime.ui.Joystick; import lime.ui.Joystick;
import ru.m.connect.IConnection; import ru.m.connect.IConnection;
@@ -42,6 +44,8 @@ class Init {
@: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; @:provide static var bus:IControlBus;
@:provide static var loaderManager:ILoaderManager;
@:provide static var updater:Updater;
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");
@@ -77,6 +81,9 @@ class Init {
bus = new ControlBus(); bus = new ControlBus();
bus.connect(new KeyboardDevice(Lib.current.stage)); bus.connect(new KeyboardDevice(Lib.current.stage));
loaderManager = new LoaderManager();
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
for (device in Gamepad.devices) { for (device in Gamepad.devices) {
trace('gamepad', device); trace('gamepad', device);
} }

View File

@@ -1,6 +1,7 @@
package ru.m.tankz.bundle; package ru.m.tankz.bundle;
import openfl.Assets; import openfl.Assets;
import openfl.utils.AssetType;
import ru.m.tankz.config.Config; import ru.m.tankz.config.Config;
import ru.m.tankz.Type; import ru.m.tankz.Type;
import ru.m.tankz.util.LevelUtil; import ru.m.tankz.util.LevelUtil;
@@ -12,7 +13,7 @@ class LevelBundle implements ILevelBundle {
public function new() {} public function new() {}
private function resolve(id:PackId):LevelPack { private function resolve(id:PackId):LevelPack {
var bytes = Assets.getBytes('levels/${id}.zip'); var bytes = Assets.getBytes('resources/level/${id}.zip');
return { return {
id: id, id: id,
data: LevelUtil.unpack(bytes).map(function(level) { data: LevelUtil.unpack(bytes).map(function(level) {
@@ -28,4 +29,14 @@ class LevelBundle implements ILevelBundle {
} }
return _cache.get(id); return _cache.get(id);
} }
public function list():Array<PackId> {
var result = [];
for (path in Assets.list(AssetType.BINARY)) {
if (StringTools.startsWith(path, "resources/level")) {
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
}
}
return result;
}
} }

View File

@@ -10,6 +10,8 @@ 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;
using haxe.EnumTools.EnumValueTools;
class HumanControl extends Control { class HumanControl extends Control {
@:provide static var storage:SettingsStorage; @:provide static var storage:SettingsStorage;
@@ -18,7 +20,7 @@ class HumanControl extends Control {
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>; private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
private var moveQueue:Array<Direction>; private var moveQueue:Array<Direction>;
private var shotTimer:Timer; private var shotTimers:Map<Int, Timer>;
public function new(playerId:PlayerId, controlIndex:Int) { public function new(playerId:PlayerId, controlIndex:Int) {
super(playerId); super(playerId);
@@ -32,6 +34,16 @@ class HumanControl extends Control {
binding.get(bind.device).set(bind.action, action); binding.get(bind.device).set(bind.action, action);
} }
moveQueue = []; moveQueue = [];
shotTimers = new Map();
}
public function hasDevice(device:DeviceType):Bool {
for (d in binding.keys()) {
if (d.equals(device)) {
return true;
}
}
return false;
} }
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void { private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
@@ -49,10 +61,10 @@ class HumanControl extends Control {
super.stop(); super.stop();
bus.signal.disconnect(onDeviceAction); bus.signal.disconnect(onDeviceAction);
moveQueue = []; moveQueue = [];
if (shotTimer != null) { for (timer in shotTimers) {
shotTimer.stop(); timer.stop();
shotTimer = null;
} }
shotTimers = new Map();
} }
public function toggleAction(action:TankAction, on:Bool):Void { public function toggleAction(action:TankAction, on:Bool):Void {
@@ -66,17 +78,18 @@ class HumanControl extends Control {
moveQueue.remove(direction); moveQueue.remove(direction);
} }
updateMove(); updateMove();
case TankAction.SHOT: case TankAction.SHOT(weapon):
if (on) { if (on) {
if (shotTimer == null) { if (!shotTimers.exists(weapon)) {
shotTimer = new Timer(300); var timer = new Timer(300);
shotTimer.run = shot; timer.run = shooter(weapon);
shot(); timer.run();
shotTimers.set(weapon, timer);
} }
} else { } else {
if (shotTimer != null) { if (shotTimers.exists(weapon)) {
shotTimer.stop(); shotTimers.get(weapon).stop();
shotTimer = null; shotTimers.remove(weapon);
} }
} }
case TankAction.STOP: case TankAction.STOP:
@@ -96,7 +109,9 @@ class HumanControl extends Control {
} }
} }
private function shot():Void { private function shooter(weapon:Int):Void -> Void {
action(SHOT); return function():Void {
action(SHOT(weapon));
}
} }
} }

View File

@@ -33,7 +33,7 @@ class LocalGame extends GameRunner {
} }
} }
if (humansTeams.length == 1 && result.winner == humansTeams[0]) { if (humansTeams.length == 1 && result.winner == humansTeams[0]) {
var progress = gameStorage.get(new PackId(result.state.type)); var progress = gameStorage.get(result.level.packId);
progress.completeLevel(result.level.id, result.state.presetId); progress.completeLevel(result.level.id, result.state.presetId);
gameStorage.set(progress); gameStorage.set(progress);
} }

View File

@@ -61,7 +61,7 @@ class NetworkManager {
updateState(OFFLINE); updateState(OFFLINE);
connection.handler.connect(onConnectionEvent); connection.handler.connect(onConnectionEvent);
connection.receiveHandler.connect(onResponse); connection.receiveHandler.connect(onResponse);
connect(); //connect(); // ToDo: disable network
} }
private function updateState(value:ConnectionState):Void { private function updateState(value:ConnectionState):Void {

View File

@@ -149,8 +149,8 @@ class Render extends SpriteView implements IRender {
entryLayer.addChild(item.view); entryLayer.addChild(item.view);
item.update(); item.update();
playAnimate(item.rect.center, AnimateBundle.tankSpawn()); playAnimate(item.rect.center, AnimateBundle.tankSpawn());
case SPAWN(BULLET(id, rect, playerId, piercing)): case SPAWN(BULLET(id, rect, playerId, skin)):
var item = new BulletRenderItem(rect, piercing); var item = new BulletRenderItem(rect, skin);
items.set(id, item); items.set(id, item);
entryLayer.addChild(item.view); entryLayer.addChild(item.view);
item.update(); item.update();

View File

@@ -0,0 +1,25 @@
package ru.m.tankz.render;
import flash.display.BitmapData;
import openfl.Assets;
import ru.m.tankz.Type;
class RenderUtil {
public static function eagleImage(death:Bool = false):BitmapData {
var suffix = death ? '-death' : '';
return Assets.getBitmapData('resources/image/eagle/eagle${suffix}.png');
}
public static function tankImage(skin:String, frame:Int = 0):BitmapData {
return Assets.getBitmapData('resources/image/tank/${skin}-${frame}.png');
}
public static function bonusImage(type:BonusType):BitmapData {
return Assets.getBitmapData('resources/image/bonus/${type}.png');
}
public static function bulletImage(skin:String):BitmapData {
return Assets.getBitmapData('resources/image/bullet/${skin}.png');
}
}

View File

@@ -4,13 +4,11 @@ import flash.display.Bitmap;
import flash.display.BitmapData; import flash.display.BitmapData;
import flash.display.DisplayObject; import flash.display.DisplayObject;
import flash.display.PixelSnapping; import flash.display.PixelSnapping;
import openfl.Assets;
import ru.m.geom.Rectangle; import ru.m.geom.Rectangle;
class BitmapRenderItem extends RenderItem { class BitmapRenderItem extends RenderItem {
public var image(default, set):String; public var image(default, set):BitmapData;
private var bitmapData:BitmapData;
private var bitmap:Bitmap; private var bitmap:Bitmap;
public function new(rect:Rectangle) { public function new(rect:Rectangle) {
@@ -22,11 +20,12 @@ class BitmapRenderItem extends RenderItem {
return bitmap; return bitmap;
} }
private function set_image(value:String):String { private function set_image(value:BitmapData):BitmapData {
if (image != value) { if (image != value) {
image = value; image = value;
bitmapData = Assets.getBitmapData(image); bitmap.bitmapData = image;
bitmap.bitmapData = bitmapData; bitmap.width = rect.width;
bitmap.height = rect.height;
} }
return image; return image;
} }

View File

@@ -18,7 +18,7 @@ class BonusRenderItem extends BitmapRenderItem {
private function set_type(value:BonusType):BonusType { private function set_type(value:BonusType):BonusType {
if (type != value) { if (type != value) {
type = value; type = value;
image = 'resources/image/bonus/${type}.png'; image = RenderUtil.bonusImage(type);
} }
return type; return type;
} }

View File

@@ -23,15 +23,19 @@ class BrickRenderItem extends RenderItem {
private var shape:Shape; private var shape:Shape;
private var cells:Array<Point>; private var cells:Array<Point>;
public function new(rect:Rectangle, type:BrickType) { private static function buildCells():Array<Point> {
super(rect); return [
this.shape = new Shape();
cells = [
new Point(0, 0), new Point(0, 0),
new Point(0, 1), new Point(0, 1),
new Point(1, 0), new Point(1, 0),
new Point(1, 1), new Point(1, 1),
]; ];
}
public function new(rect:Rectangle, type:BrickType) {
super(rect);
this.shape = new Shape();
cells = buildCells();
this.type = type; this.type = type;
move(rect.position); move(rect.position);
} }
@@ -51,6 +55,7 @@ class BrickRenderItem extends RenderItem {
private function set_type(value:BrickType):BrickType { private function set_type(value:BrickType):BrickType {
if (type != value) { if (type != value) {
type = value; type = value;
cells = buildCells();
image = Assets.getBitmapData('resources/image/map/${type}.png'); image = Assets.getBitmapData('resources/image/map/${type}.png');
redraw(); redraw();
} }

View File

@@ -3,20 +3,19 @@ package ru.m.tankz.render.item;
import ru.m.geom.Rectangle; import ru.m.geom.Rectangle;
class BulletRenderItem extends BitmapRenderItem { class BulletRenderItem extends BitmapRenderItem {
public var piercing(default, set):Int = -1; public var skin(default, set):String;
public function new(rect:Rectangle, piercing:Int) { public function new(rect:Rectangle, skin:String) {
super(rect); super(rect);
this.piercing = piercing; this.skin = skin;
move(rect.position); move(rect.position);
} }
private function set_piercing(value:Int):Int { private function set_skin(value:String):String {
if (piercing != value) { if (skin != value) {
piercing = value; skin = value;
var type = piercing > 0 ? 'piercing' : 'normal'; image = RenderUtil.bulletImage(skin);
image = 'resources/image/bullet/${type}.png';
} }
return piercing; return skin;
} }
} }

View File

@@ -35,8 +35,8 @@ class EagleRenderItem extends BitmapRenderItem {
if (protect != value) { if (protect != value) {
protect = value; protect = value;
if (protect) { if (protect) {
protectView.x = (bitmapData.width - protectView.frames[0].image.width) / 2; protectView.x = (image.width - protectView.frames[0].image.width) / 2;
protectView.y = (bitmapData.height - protectView.frames[0].image.height) / 2; protectView.y = (image.height - protectView.frames[0].image.height) / 2;
} }
protectView.visible = protect; protectView.visible = protect;
protectView.playing = protect; protectView.playing = protect;
@@ -47,10 +47,9 @@ class EagleRenderItem extends BitmapRenderItem {
private function set_death(value:Bool):Bool { private function set_death(value:Bool):Bool {
if (death != value) { if (death != value) {
death = value; death = value;
var suffix = death ? '-death' : ''; image = RenderUtil.eagleImage(death);
image = 'resources/image/eagle/eagle${suffix}.png';
if (!color.zero) { if (!color.zero) {
bitmap.bitmapData = bitmapData = BitmapUtil.colorize(bitmapData, color); bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
} }
} }
return death; return death;

View File

@@ -1,6 +1,5 @@
package ru.m.tankz.render.item; package ru.m.tankz.render.item;
import haxework.view.theme.ITheme;
import flash.display.BitmapData; import flash.display.BitmapData;
import flash.display.DisplayObject; import flash.display.DisplayObject;
import flash.display.Sprite; import flash.display.Sprite;
@@ -9,8 +8,8 @@ import flash.text.TextFieldAutoSize;
import flash.text.TextFormat; import flash.text.TextFormat;
import haxework.color.Color; import haxework.color.Color;
import haxework.text.BitmapTextField; import haxework.text.BitmapTextField;
import haxework.view.theme.ITheme;
import haxework.view.utils.BitmapUtil; import haxework.view.utils.BitmapUtil;
import openfl.Assets;
import ru.m.animate.Animate; import ru.m.animate.Animate;
import ru.m.geom.Rectangle; import ru.m.geom.Rectangle;
@@ -62,8 +61,8 @@ class TankRenderItem extends BitmapRenderItem {
} }
private function redraw():Void { private function redraw():Void {
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png'); var image1 = RenderUtil.tankImage(skin, 0);
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png'); var image2 = RenderUtil.tankImage(skin, 1);
var color1:Color = switch hits { var color1:Color = switch hits {
case 1: 0x869C43; case 1: 0x869C43;
case 2: 0xDEAF80; case 2: 0xDEAF80;

View File

@@ -4,7 +4,7 @@ import haxe.DynamicAccess;
import haxework.storage.SharedObjectStorage; import haxework.storage.SharedObjectStorage;
import ru.m.tankz.game.record.GameRecord; import ru.m.tankz.game.record.GameRecord;
@:yield class RecordStorage extends SharedObjectStorage { class RecordStorage extends SharedObjectStorage {
private static inline var VERSION = 1; private static inline var VERSION = 1;
@@ -23,17 +23,19 @@ import ru.m.tankz.game.record.GameRecord;
super.delete('${id}.info'); super.delete('${id}.info');
} }
public function iterator():Iterator<GameRecordInfo> { public function list():Array<GameRecordInfo> {
var result = [];
var data:DynamicAccess<String> = so.data; var data:DynamicAccess<String> = so.data;
for (id in data.keys()) { for (id in data.keys()) {
try { try {
if (StringTools.endsWith(id, '.info')) { if (StringTools.endsWith(id, '.info')) {
@yield return read(id); result.push(read(id));
} }
} catch (error:Dynamic) { } catch (error:Dynamic) {
L.w("RecordStorage", 'read ', error); L.w("RecordStorage", 'read ', error);
delete(id); delete(id);
} }
} }
return result;
} }
} }

View File

@@ -11,7 +11,7 @@ import ru.m.tankz.control.Control;
class SettingsStorage extends SharedObjectStorage { class SettingsStorage extends SharedObjectStorage {
private static inline var VERSION = 3; private static inline var VERSION = 4.1;
public function new() { public function new() {
super('settings_${VERSION}'); super('settings_${VERSION}');
@@ -26,41 +26,56 @@ class SettingsStorage extends SharedObjectStorage {
} }
public static function getDefaultBinding(index:Int):Binding { public static function getDefaultBinding(index:Int):Binding {
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1)); var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
} }
public static function buildGamepadBinding(id:Int):Binding { public static function buildDeviceBinding(device:DeviceType):Binding {
var device = GAMEPAD(id);
return [ return [
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)}, MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)}, MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)}, MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)}, MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
SHOT => {device: device, action: KEY(0)}, SHOT(0) => {device: device, action: KEY(0)},
SHOT(1) => {device: device, action: KEY(1)},
SHOT(2) => {device: device, action: KEY(2)},
]; ];
} }
private static var defaults:Map<Int, Binding> = [ public static function buildEmpty():Binding {
-1 => [ return [
MOVE(Direction.TOP) => null, MOVE(Direction.TOP) => null,
MOVE(Direction.LEFT) => null, MOVE(Direction.LEFT) => null,
MOVE(Direction.BOTTOM) => null, MOVE(Direction.BOTTOM) => null,
MOVE(Direction.RIGHT) => null, MOVE(Direction.RIGHT) => null,
SHOT => null, SHOT(0) => null,
], SHOT(1) => null,
SHOT(2) => null,
];
}
private static var mobileDefaults:Map<Int, Binding> = [
0 => buildDeviceBinding(SCREEN),
];
private static var defaults:Map<Int, Binding> = [
0 => [ 0 => [
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)}, MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)}, MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)}, MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)}, MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)}, SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.E)},
], ],
1 => [ 1 => [
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)}, MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)}, MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)}, MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)}, MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)}, SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_1)},
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_2)},
], ],
]; ];
} }

View File

@@ -1,10 +1,12 @@
package ru.m.tankz.view; package ru.m.tankz.view;
import haxework.view.layout.DefaultLayout;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView; import haxework.view.frame.FrameView;
import haxework.view.group.GroupView;
import haxework.view.layout.DefaultLayout;
import ru.m.control.DeviceType; import ru.m.control.DeviceType;
import ru.m.control.IControlBus; import ru.m.control.IControlBus;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.game.GameEvent; import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameInit; import ru.m.tankz.game.GameInit;
import ru.m.tankz.game.IGame; import ru.m.tankz.game.IGame;
@@ -15,24 +17,27 @@ import ru.m.tankz.network.NetworkGame;
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.storage.SettingsStorage;
import ru.m.tankz.view.game.GameView; import ru.m.tankz.view.game.GameViewA;
import ru.m.tankz.view.GamepadView; import ru.m.tankz.view.game.GameViewB;
import ru.m.tankz.view.game.IGameView;
import ru.m.tankz.view.gamepad.GamepadView;
@:template class GameFrame extends FrameView<GameInit> implements GameListener { @:template class GameFrame extends FrameView<GameInit> implements GameListener {
public static inline var ID = "game"; public static inline var ID = "game";
private static inline var TAG = "GameFrame"; private static inline var TAG = "GameFrame";
@:view("game") private var gameView(default, null):GameView; @:provide static var soundManager:SoundManager;
@:view private var gamepad(default, null):GamepadView; @:provide static var switcher:FrameSwitcher;
@:provide var soundManager:SoundManager;
@:provide var switcher:FrameSwitcher;
@:provide static var gameStorage:GameStorage; @:provide static var gameStorage:GameStorage;
@:provide static var settings:SettingsStorage; @:provide static var settings:SettingsStorage;
@:provide static var bus:IControlBus; @:provide static var bus:IControlBus;
@:view("game") private var gameViewContainer(default, null):GroupView;
@:view private var gamepad(default, null):GamepadView;
private var gameView:IGameView;
private var game:IGame; private var game:IGame;
private var recorder:GameRecord; private var recorder:GameRecord;
@@ -46,33 +51,32 @@ import ru.m.tankz.view.GamepadView;
override public function onShow(data:GameInit):Void { override public function onShow(data:GameInit):Void {
gamepad.visible = false; 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 _:
}
}
}
game = switch data { game = switch data {
case LOCAL(start): new LocalGame(start); case LOCAL(start): new LocalGame(start);
case NETWORK(network): new NetworkGame(network); case NETWORK(network): new NetworkGame(network);
case RECORD(record): new GamePlayer(record); case RECORD(record): new GamePlayer(record);
case _: null;
} }
gameView.type = game.type; gameView = switch game.type {
case "dota": GameViewB.factory(game.config);
case _: GameViewA.factory(game.config);
};
gameViewContainer.addView(gameView);
soundManager.config = game.config; soundManager.config = game.config;
gameView.render.config = game.config; gameView.render.config = game.config;
game.connect(gameView.render); game.connect(gameView.render);
game.connect(soundManager); game.connect(soundManager);
if (gameView.panel != null) { game.connect(gameView);
game.connect(gameView.panel);
}
game.connect(this); game.connect(this);
game.start(); game.start();
// ToDo:
for (control in game.controls) {
if (Std.is(control, HumanControl)) {
if (cast(control, HumanControl).hasDevice(SCREEN)) {
gamepad.visible = true;
break;
}
}
}
} }
private function stop():Void { private function stop():Void {
@@ -80,8 +84,10 @@ import ru.m.tankz.view.GamepadView;
game.dispose(); game.dispose();
game = null; game = null;
} }
if (gameView != null) {
gameView.render.reset(); gameView.render.reset();
} }
}
public function onGameEvent(event:GameEvent):Void { public function onGameEvent(event:GameEvent):Void {
switch event { switch event {
@@ -95,9 +101,13 @@ import ru.m.tankz.view.GamepadView;
override public function onHide():Void { override public function onHide():Void {
stop(); stop();
soundManager.stopAll(); soundManager.stopAll();
if (gameView != null) {
gameViewContainer.removeView(gameView);
gameView = null;
}
} }
public function close():Void { public function close():Void {
switcher.change(MenuFrame.ID); switcher.change(LevelFrame.ID, game.level.packId);
} }
} }

View File

@@ -4,9 +4,18 @@ overflow.x: crop
overflow.y: crop overflow.y: crop
views: views:
- id: game - id: game
$type: ru.m.tankz.view.game.GameView $type: ru.m.tankz.view.game.GameViewContainer
layout.hAlign: center
layout.vAlign: middle
- id: gamepad - id: gamepad
$type: ru.m.tankz.view.GamepadView $type: ru.m.tankz.view.gamepad.GamepadView
geometry.position: absolute geometry.position: absolute
geometry.stretch: true geometry.stretch: true
visible: false visible: false
- $type: haxework.view.form.ButtonView
style: button.close
geometry.position: absolute
geometry.hAlign: left
geometry.vAlign: top
geometry.margin: 10
+onPress: ~close()

View File

@@ -12,6 +12,8 @@ import ru.m.tankz.game.GameState;
import ru.m.tankz.storage.GameStorage; import ru.m.tankz.storage.GameStorage;
import ru.m.tankz.Type.PackId; import ru.m.tankz.Type.PackId;
using ru.m.tankz.view.ViewUtil;
@:template class LevelFrame extends FrameView<PackId> { @:template class LevelFrame extends FrameView<PackId> {
public static inline var ID = "level"; public static inline var ID = "level";
@@ -35,7 +37,7 @@ import ru.m.tankz.Type.PackId;
} }
override public function onShow(data:PackId):Void { override public function onShow(data:PackId):Void {
header.text = data.type; header.text = data.toPackLabel();
pack = levelBundle.get(data); pack = levelBundle.get(data);
levels.data = pack.data; levels.data = pack.data;
} }

View File

@@ -1,9 +1,11 @@
package ru.m.tankz.view; package ru.m.tankz.view;
import haxework.view.data.DataView;
import haxework.view.form.ButtonView; import haxework.view.form.ButtonView;
import haxework.view.form.LabelView; import haxework.view.form.LabelView;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView; import haxework.view.frame.FrameView;
import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.game.GameInit; import ru.m.tankz.game.GameInit;
import ru.m.tankz.game.GameState; import ru.m.tankz.game.GameState;
import ru.m.tankz.network.NetworkManager; import ru.m.tankz.network.NetworkManager;
@@ -12,17 +14,23 @@ import ru.m.tankz.view.network.RoomFrame;
import ru.m.tankz.view.network.RoomListFrame; import ru.m.tankz.view.network.RoomListFrame;
import ru.m.tankz.view.popup.LoginPopup; import ru.m.tankz.view.popup.LoginPopup;
using ru.m.tankz.view.ViewUtil;
@:template class MenuFrame extends FrameView<Dynamic> { @:template class MenuFrame extends FrameView<Dynamic> {
public static var ID(default, never):String = "menu"; public static var ID(default, never):String = "menu";
@:provide var gameInit:GameInit; @:provide static var gameInit:GameInit;
@:provide var switcher:FrameSwitcher; @:provide static var switcher:FrameSwitcher;
@:provide var network:NetworkManager; @:provide static var network:NetworkManager;
@:provide static var appUpdater:Updater;
@:provide static var levelBundle:ILevelBundle;
@:view var packs:DataView<PackId, ButtonView>;
@:view var username:LabelView; @:view var username:LabelView;
@:view("login") var loginButton:ButtonView; @:view("login") var loginButton:ButtonView;
@:view("logout") var logoutButton:ButtonView; @:view("logout") var logoutButton:ButtonView;
@:view("update") var updateButton:ButtonView;
public function new() { public function new() {
super(ID); super(ID);
@@ -32,6 +40,15 @@ import ru.m.tankz.view.popup.LoginPopup;
super.onShow(data); super.onShow(data);
network.stateSignal.connect(onConnectionState); network.stateSignal.connect(onConnectionState);
onConnectionState(network.state); onConnectionState(network.state);
appUpdater.check().then(function(update:Bool) {
updateButton.visible = update;
if (update) {
updateButton.text = 'Update ${appUpdater.bundle.version}';
}
});
var list = levelBundle.list();
list.sort(function(a:PackId, b:PackId) return a.toPackLabel() > b.toPackLabel() ? 1 : -1);
packs.data = list;
} }
override public function onHide():Void { override public function onHide():Void {
@@ -39,9 +56,16 @@ import ru.m.tankz.view.popup.LoginPopup;
network.stateSignal.disconnect(onConnectionState); network.stateSignal.disconnect(onConnectionState);
} }
private function startGame(type:GameType):Void { private function packButtonFactory(index:Int, packId:PackId):ButtonView {
gameInit = LOCAL({state: new GameState(type), level: null}); var result = new ButtonView();
switcher.change(LevelFrame.ID, new PackId(type)); result.style = "button.menu";
result.text = packId.toPackLabel();
return result;
}
private function startGame(packId:PackId):Void {
gameInit = LOCAL({state: new GameState(packId.type), level: null});
switcher.change(LevelFrame.ID, packId);
} }
private function startNetwork():Void { private function startNetwork():Void {
@@ -93,4 +117,8 @@ import ru.m.tankz.view.popup.LoginPopup;
private function logout():Void { private function logout():Void {
network.logout(); network.logout();
} }
private function appUpdate():Void {
appUpdater.download();
}
} }

View File

@@ -2,39 +2,43 @@
views: views:
- $type: haxework.view.group.VGroupView - $type: haxework.view.group.VGroupView
style: container style: container
layout.margin: 10
overflow.y: scroll overflow.y: scroll
views:
- $type: haxework.view.group.VGroupView
layout.margin: 10
layout.hAlign: center
views: views:
- $type: haxework.view.form.LabelView - $type: haxework.view.form.LabelView
text: Tank'z text: Tank'z
style: font style: font
font.size: 100 font.size: 100
geometry.margin.bottom: 30 geometry.margin.bottom: 30
- $type: haxework.view.form.ButtonView - id: packs
style: button.menu $type: haxework.view.data.DataView
+onPress: ~startGame('classic') layout:
text: Classic $type: haxework.view.layout.VerticalLayout
- $type: haxework.view.form.ButtonView margin: 10
style: button.menu factory: ~packButtonFactory
+onPress: ~startGame('dota') +onDataSelect: ~startGame
text: DotA - $type: haxework.view.SpriteView
- $type: haxework.view.form.ButtonView style: line
style: button.menu geometry.width: 250
+onPress: ~startGame('death') geometry.margin: [0, 10]
text: DeathMatch visible: false
- $type: haxework.view.form.ButtonView - $type: haxework.view.form.ButtonView
style: button.menu style: button.menu
+onPress: ~switcher.change('record') +onPress: ~switcher.change('record')
text: Records text: Records
visible: false
- id: network - id: network
$type: haxework.view.form.ButtonView $type: haxework.view.form.ButtonView
style: button.menu style: button.menu
+onPress: ~startNetwork() +onPress: ~startNetwork()
text: Network text: Network
visible: false
- $type: haxework.view.form.LabelView - $type: haxework.view.form.LabelView
geometry.hAlign: right geometry.hAlign: right
geometry.vAlign: top geometry.vAlign: top
geometry.padding: [20, 5]
geometry.position: absolute geometry.position: absolute
geometry.margin: [0, 20, 20, 0] geometry.margin: [0, 20, 20, 0]
style: text.box style: text.box
@@ -63,3 +67,8 @@ views:
visible: false visible: false
- $type: haxework.view.SpriteView - $type: haxework.view.SpriteView
geometry.width: 50% geometry.width: 50%
- id: update
$type: haxework.view.form.ButtonView
style: button.active
+onPress: ~appUpdate()
visible: false

View File

@@ -20,7 +20,7 @@ import ru.m.tankz.storage.RecordStorage;
} }
override public function onShow(_:Dynamic):Void { override public function onShow(_:Dynamic):Void {
var data = Lambda.array(recordStorage); var data = recordStorage.list();
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime())); data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
this.data.data = data; this.data.data = data;
} }

View File

@@ -1,21 +1,23 @@
package ru.m.tankz.view; package ru.m.tankz.view;
import haxework.view.form.ButtonView;
import haxework.view.data.DataView; import haxework.view.data.DataView;
import haxework.view.form.ButtonView;
import haxework.view.form.LabelView;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView; import haxework.view.frame.FrameView;
import haxework.view.form.LabelView;
import ru.m.tankz.bundle.ILevelBundle; import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.game.GameEvent; import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameInit; import ru.m.tankz.game.GameInit;
import ru.m.tankz.game.GameState; import ru.m.tankz.game.GameState;
import ru.m.tankz.storage.GameStorage; import ru.m.tankz.storage.GameStorage;
import ru.m.tankz.view.common.LifeView; import ru.m.tankz.view.result.ResultPlayerView;
using ru.m.tankz.view.ViewUtil;
@:template class ResultFrame extends FrameView<Result> { @:template class ResultFrame extends FrameView<Result> {
public static var ID(default, never):String = "result"; public static var ID(default, never):String = "result";
@:view("result") var resultView:DataView<PlayerState, LifeView>; @:view("result") var resultView:DataView<PlayerState, ResultPlayerView>;
@:view("level") var levelLabel:LabelView; @:view("level") var levelLabel:LabelView;
@:view("next") var nextButton:ButtonView; @:view("next") var nextButton:ButtonView;
@@ -29,30 +31,15 @@ import ru.m.tankz.view.common.LifeView;
super(ID); super(ID);
} }
private function playerViewFactory(index:Int, player:PlayerState):LifeView {
var view = new LifeView();
var playerConfig = result.state.config.getPlayer(player.id);
var tankType = playerConfig.tanks[0].type;
var tankConfig = result.state.config.getTank(tankType);
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
view.color = result.state.getPlayerColor(player.id);
view.life = player.frags;
view.score = player.score;
return view;
}
override public function onShow(data:Result):Void { override public function onShow(data:Result):Void {
result = data; result = data;
var players = Lambda.array(result.state.players); resultView.data = result.state.humans;
players.sort(function(a, b) return a.id.compare(b.id)); for (view in resultView.dataViews) {
resultView.data = players; view.winner = view.data.id.team == data.winner;
var label = '${result.state.type} Level ${result.level.id}';
if (result.level.name != null) {
label += '\n${result.level.name}';
} }
levelLabel.text = label; levelLabel.text = data.level.toLevelLabel();
nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId); nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId);
nextButton.text = 'Next (${result.level.id + 1})'; nextButton.text = 'Next #${result.level.id + 1}';
} }
private function levels():Void { private function levels():Void {
@@ -60,7 +47,8 @@ import ru.m.tankz.view.common.LifeView;
} }
private function restart():Void { private function restart():Void {
frames.change(GameFrame.ID, LOCAL({state: result.state.clean(), level: result.level})); result.state.clean();
frames.change(GameFrame.ID, LOCAL({state: result.state, level: result.level}));
} }
private function next():Void { private function next():Void {
@@ -69,12 +57,9 @@ import ru.m.tankz.view.common.LifeView;
var level = pack.data[result.level.id + 1]; var level = pack.data[result.level.id + 1];
var progress = gameStorage.get(pack.id); var progress = gameStorage.get(pack.id);
if (progress.isPresetAvailable(level.id, result.state.presetId)) { if (progress.isPresetAvailable(level.id, result.state.presetId)) {
frames.change(GameFrame.ID, LOCAL({state: result.state.clean(), level: level})); result.state.clean();
frames.change(GameFrame.ID, LOCAL({state: result.state, level: level}));
} }
} }
} }
private function close():Void {
frames.change(MenuFrame.ID);
}
} }

View File

@@ -9,14 +9,15 @@ views:
font.align: center font.align: center
- id: result - id: result
$type: haxework.view.data.DataView $type: haxework.view.data.DataView
factory: ~playerViewFactory layout:
$type: haxework.view.layout.TailLayout
factory: ~ru.m.tankz.view.result.ResultPlayerView.factory
geometry.width: 100%
geometry.height: 100% geometry.height: 100%
overflow.y: scroll overflow.y: scroll
geometry.margin.top: 20 geometry.margin.top: 20
layout: layout.margin: 5
$type: haxework.view.layout.VerticalLayout layout.hAlign: center
hAlign: right
margin: 10
- $type: haxework.view.group.HGroupView - $type: haxework.view.group.HGroupView
style: panel style: panel
layout.margin: 10 layout.margin: 10

View File

@@ -16,6 +16,7 @@ import ru.m.tankz.Type;
import ru.m.tankz.view.common.SlotView; import ru.m.tankz.view.common.SlotView;
using haxe.EnumTools.EnumValueTools; using haxe.EnumTools.EnumValueTools;
using ru.m.tankz.view.ViewUtil;
@:template class StartFrame extends FrameView<Start> { @:template class StartFrame extends FrameView<Start> {
@@ -28,12 +29,11 @@ using haxe.EnumTools.EnumValueTools;
@:view var header:LabelView; @:view var header:LabelView;
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>; @:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
@:view("slots") var slotsView:DataView<PlayerControl, SlotView>; @:view("teams") var teamsView:DataView<Array<PlayerControl>, DataView<PlayerControl, SlotView>>;
private var humanIndex:Int = 0; private var humanIndex:Int = 0;
private var humanTotal:Int = 2; private var humanTotal:Int = 2;
private var start:Start; private var start:Start;
public function new() { public function new() {
@@ -44,38 +44,52 @@ using haxe.EnumTools.EnumValueTools;
super.onShow(data); super.onShow(data);
start = data; start = data;
this.progress = storage.get(start.level.packId); this.progress = storage.get(start.level.packId);
header.text = '${start.state.type} - ${start.level.id}. ${start.level.name != null ? start.level.name : "#"}'; header.text = start.level.toLevelLabel();
presetsView.data = start.state.config.presets; presetsView.data = start.state.config.presets;
slotsView.data = defaultControls(start.state.config); teamsView.data = defaultControls(start.state.config);
} }
private static function defaultControls(config:Config):Array<PlayerControl> { private static function defaultControls(config:Config):Array<Array<PlayerControl>> {
var controls:Array<PlayerControl> = []; var result:Array<Array<PlayerControl>> = [];
var preset = config.getPreset(0); var preset = config.getPreset(0);
var human = false;
for (team in preset.teams) { for (team in preset.teams) {
if (team.id != "bot") { // ToDo: if (team.id != "bot") { // ToDo:
var controls:Array<PlayerControl> = [];
for (player in team.players) { for (player in team.players) {
var playerId = new PlayerId(team.id, player.index); var playerId = new PlayerId(team.id, player.index);
controls.push({ var control:PlayerControl = {
playerId: playerId, playerId: playerId,
color: config.getColor(playerId), color: config.getColor(playerId),
controller: NONE, controller: NONE,
}); }
if (!human) {
control.controller = HUMAN(0);
control.name = ControllerParser.defaultName(control.controller);
human = true;
}
controls.push(control);
}
result.push(controls);
} }
} }
return result;
} }
controls.sort(function(a, b) return a.playerId.compare(b.playerId));
if (controls.length > 0) { private function teamViewFactory(index:Int, value:Array<PlayerControl>):DataView<PlayerControl, SlotView> {
controls[0].controller = HUMAN(0); var result = new DataView();
controls[0].name = ControllerParser.defaultName(controls[0].controller); result.style = "light";
} result.geometry.padding = 5;
return controls; result.factory = slotViewFactory;
result.data = value;
return result;
} }
private function slotViewFactory(index:Int, value:PlayerControl):SlotView { private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
var result = new SlotView(); var result = new SlotView();
result.select.onSelect.connect(function(controller:Controller) setController(value, controller)); result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
result.control = value; result.control = value;
result.tank = start.state.config.getPlayerTank(value.playerId).skin;
return result; return result;
} }
@@ -83,7 +97,8 @@ using haxe.EnumTools.EnumValueTools;
switch controller { switch controller {
case NONE: case NONE:
case _: case _:
for (view in slotsView.dataViews) { for (teamView in teamsView.dataViews) {
for (view in teamView.dataViews) {
if (view.control.controller.equals(controller)) { if (view.control.controller.equals(controller)) {
view.control.controller = NONE; view.control.controller = NONE;
view.select.selected = NONE; view.select.selected = NONE;
@@ -91,6 +106,7 @@ using haxe.EnumTools.EnumValueTools;
} }
} }
} }
}
value.controller = controller; value.controller = controller;
value.name = ControllerParser.defaultName(controller); value.name = ControllerParser.defaultName(controller);
} }
@@ -106,7 +122,11 @@ using haxe.EnumTools.EnumValueTools;
private function onPresetSelect(value:GamePreset):Void { private function onPresetSelect(value:GamePreset):Void {
if (progress.isPresetAvailable(start.level.id, value.id)) { if (progress.isPresetAvailable(start.level.id, value.id)) {
start.state.presetId = value.id; start.state.presetId = value.id;
start.state.controls = slotsView.data; var controls = [];
for (item in teamsView.data) {
controls = controls.concat(item);
}
start.state.controls = controls;
switcher.change(GameFrame.ID, LOCAL(start)); switcher.change(GameFrame.ID, LOCAL(start));
} }
} }

View File

@@ -6,18 +6,18 @@ views:
- id: header - id: header
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.header style: text.header
- id: slots - id: teams
$type: haxework.view.data.DataView $type: haxework.view.data.DataView
geometry.padding: 10 geometry.padding: 10
geometry.width: 100% geometry.width: 100%
geometry.height: 100% geometry.height: 100%
layout.hAlign: center layout.hAlign: center
overflow.y: scroll overflow.y: scroll
factory: ~slotViewFactory factory: ~teamViewFactory
layout: layout:
$type: haxework.view.layout.VerticalLayout $type: haxework.view.layout.TailLayout
# $type: haxework.view.layout.TailLayout
margin: 5 margin: 5
rowSize: 2
- $type: haxework.view.group.HGroupView - $type: haxework.view.group.HGroupView
style: panel style: panel
layout.margin: 10 layout.margin: 10

View File

@@ -0,0 +1,62 @@
package ru.m.tankz.view;
import ru.m.tankz.Type.PackId;
import openfl.Assets;
import ru.m.control.DeviceAction;
import ru.m.tankz.config.Config;
import ru.m.tankz.control.Binding;
import ru.m.tankz.control.Control;
class KeyboardMap {
private var data:Map<Int, String>;
public function new() {
this.data = new Map();
var data = Assets.getText("resources/keyboard.txt");
for (line in data.split("\n")) {
var arr = line.split("\t");
if (arr.length == 2) {
this.data.set(Std.parseInt(arr[1]), arr[0]);
}
}
}
private static var instance:KeyboardMap;
public static function getName(key:Int):String {
if (instance == null) instance = new KeyboardMap();
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
}
}
class ViewUtil {
public static function toLevelLabel(level:LevelConfig, oneline:Bool = false):String {
var result:Array<String> = ['${level.packId.type} #${level.id}'];
if (level.name != null) {
result.push(level.name);
}
return result.join(oneline ? " " : "\n");
}
public static function toPackLabel(packId:PackId):String {
return packId.name != PackId.DEFAULT ? '${packId.type} #${packId.name}' : packId.type;
}
public static function toActionLabel(action:TankAction):String {
return switch (action) {
case MOVE(d): 'MOVE_$d';
case SHOT(w): 'SHOT_$w';
case x: '$x';
}
}
public static function toBindLabel(bind:BindAction):String {
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
case KEY(code): KeyboardMap.getName(code);
case DIRECTION(direction): Std.string(direction);
};
}
}

View File

@@ -1,61 +0,0 @@
package ru.m.tankz.view.common;
import haxework.color.Color;
import haxework.view.group.HGroupView;
import haxework.view.ImageView;
import haxework.view.form.LabelView;
import openfl.Assets;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
@:template class LifeView extends HGroupView {
@:view("tank") public var tankImage:ImageView;
@:view("life") public var lifeLabel:LabelView;
@:view("score") public var scoreLabel:LabelView;
public var playerId(default, default):PlayerId;
public var state(null, set):PlayerState;
public var tank(null, set):String;
public var color(null, set):Color;
public var life(null, set):Int;
public var score(null, set):Int;
private inline function set_state(value:PlayerState):PlayerState {
playerId = value.id;
tank = value.tank;
color = value.color;
life = value.life;
score = value.score;
return state;
}
private inline function set_tank(value:String):String {
if (value != null && value != tank) {
tank = value;
tankImage.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
}
return tank;
}
private inline function set_color(value:Color):Color {
tankImage.color = value;
return value;
}
private inline function set_life(value:Int):Int {
lifeLabel.text = '${value}';
return value;
}
private inline function set_score(value:Int):Int {
scoreLabel.text = '${value}$';
return value;
}
public static inline function factory(index:Int, data:PlayerState):LifeView {
var result = new LifeView();
result.state = data;
return result;
}
}

View File

@@ -11,22 +11,18 @@ views:
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.width: 200 geometry.width: 200
geometry.height: 38
- id: type - id: type
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.width: 200 geometry.width: 200
geometry.height: 38
- id: level - id: level
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.width: 100 geometry.width: 100
geometry.height: 38
- id: preset - id: preset
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.width: 100 geometry.width: 100
geometry.height: 38
- id: delete - id: delete
$type: haxework.view.form.ButtonView $type: haxework.view.form.ButtonView
style: button.close.small style: button.close.small

View File

@@ -1,26 +1,44 @@
package ru.m.tankz.view.common; package ru.m.tankz.view.common;
import haxework.view.group.HGroupView; import openfl.Assets;
import haxework.view.ImageView;
import haxework.view.form.LabelView; import haxework.view.form.LabelView;
import haxework.view.form.SelectView; import haxework.view.form.SelectView;
import haxework.view.group.HGroupView;
import haxework.view.skin.SpriteSkin;
import ru.m.tankz.control.Controller; import ru.m.tankz.control.Controller;
import ru.m.tankz.control.PlayerControl; import ru.m.tankz.control.PlayerControl;
@:template class SlotView extends HGroupView { @:template class SlotView extends HGroupView {
@:view("tank") public var tankView:ImageView;
@:view("slot") public var slotLabel:LabelView; @:view("slot") public var slotLabel:LabelView;
@:view("select") public var select:SelectView<Controller>; @:view("select") public var select:SelectView<Controller>;
public var control(default, set):PlayerControl; public var control(default, set):PlayerControl;
public var tank(default, set):String;
private function set_control(value:PlayerControl):PlayerControl { private function set_control(value:PlayerControl):PlayerControl {
control = value; control = value;
slotLabel.text = '${control.playerId.team} #${control.playerId.index}'; slotLabel.text = '${control.playerId.team} #${control.playerId.index}';
slotLabel.font.color = value.color; var skin:SpriteSkin = cast slotLabel.skin;
skin.border.color = value.color;
skin.border.alpha = 0.8;
skin.background.color = value.color;
skin.background.alpha = 0.2;
select.selected = control.controller; select.selected = control.controller;
tankView.color = value.color;
return control; return control;
} }
private function set_tank(value:String):String {
if (tank != value) {
tank = value;
tankView.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
}
return tank;
}
private function onControllerSelect(value:Controller):Void { private function onControllerSelect(value:Controller):Void {
select.currentView.style = switch value { select.currentView.style = switch value {
case HUMAN(_): "button.active"; case HUMAN(_): "button.active";

View File

@@ -1,12 +1,14 @@
--- ---
geometry.height: 48
geometry.padding: 2 geometry.padding: 2
layout.margin: 10 layout.margin: 10
layout.vAlign: middle
views: views:
- id: tank
$type: haxework.view.ImageView
style: icon.tank
- id: slot - id: slot
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.height: 100%
geometry.width: 150 geometry.width: 150
- id: select - id: select
$type: haxework.view.form.SelectView<ru.m.tankz.control.Controller> $type: haxework.view.form.SelectView<ru.m.tankz.control.Controller>

View File

@@ -0,0 +1,23 @@
package ru.m.tankz.view.common;
import haxework.view.ImageView;
import ru.m.tankz.render.RenderUtil;
import ru.m.tankz.Type.TankInfo;
class TankView extends ImageView {
public var tank(null, set):TankInfo;
public function new() {
super();
style = "icon.tank";
}
private function set_tank(value:TankInfo):TankInfo {
if (value != null) {
color = value.color;
image = RenderUtil.tankImage(value.skin);
}
return value;
}
}

View File

@@ -1,60 +0,0 @@
package ru.m.tankz.view.game;
import haxework.view.form.LabelView;
import haxework.view.group.VGroupView;
import ru.m.geom.Direction;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.preset.ClassicGame;
import ru.m.tankz.Type.PlayerId;
import ru.m.tankz.view.common.LifeView;
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
public var position(default, null):Direction = Direction.RIGHT;
@:view var bot:LifeView;
@:view var player1:LifeView;
@:view var player2:LifeView;
@:view var level:LabelView;
private var player1Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 0);
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
public function refresh(state:GameState):Void {
bot.life = state.getTeamLife(ClassicGame.BOT);
player1.life = state.getPlayerLife(player1Id);
player1.score = state.getPlayerScore(player1Id);
if (state.getPlayerLife(player2Id) > 0) {
player2.visible = true;
player2.life = state.getPlayerLife(player2Id);
player2.score = state.getPlayerScore(player2Id);
} else {
player2.visible = false;
}
}
public function onGameEvent(event:GameEvent):Void {
switch event {
case START(start):
this.level.text = 'Level ${start.level.id}';
refresh(start.state);
case CHANGE(TEAM_LIFE(teamId, life)):
if (teamId == ClassicGame.BOT) {
bot.life = life;
}
case CHANGE(PLAYER_LIFE(playerId, life)):
if (playerId == player1Id) {
player1.life = life;
} else if (playerId == player2Id) {
player2.life = life;
}
case CHANGE(PLAYER_SCORE(playerId, score)):
if (playerId == player1Id) {
player1.score = score;
} else if (playerId == player2Id) {
player2.score = score;
}
case _:
}
}
}

View File

@@ -1,25 +0,0 @@
---
geometry.padding: 5
geometry.height: 100%
layout.margin: 5
layout.hAlign: left
views:
- id: level
$type: haxework.view.form.LabelView
style: text.box
geometry.height: 38
geometry.width: 100%
- $type: haxework.view.SpriteView
geometry.height: 50%
- id: bot
$type: ru.m.tankz.view.common.LifeView
tank: ba
scoreLabel.visible: false
- id: player1
$type: ru.m.tankz.view.common.LifeView
tank: pa
color: 0xFFFF00
- id: player2
$type: ru.m.tankz.view.common.LifeView
tank: pa
color: 0x15C040

View File

@@ -1,46 +0,0 @@
package ru.m.tankz.view.game;
import haxework.view.data.DataView;
import haxework.view.form.LabelView;
import haxework.view.group.VGroupView;
import ru.m.geom.Direction;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.preset.DeathGame;
import ru.m.tankz.view.common.LifeView;
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
public var position(default, null):Direction = Direction.RIGHT;
@:view var level:LabelView;
@:view var players:DataView<PlayerState, LifeView>;
@:provide var configBundle:IConfigBundle;
private function getView(playerId):LifeView {
for (view in players.dataViews) {
if (view.playerId == playerId) {
return view;
}
}
return null;
}
public function onGameEvent(event:GameEvent):Void {
switch event {
case START(start):
this.level.text = 'Level ${start.level.id}';
players.data = Lambda.array(start.state.players);
case SPAWN(TANK(_, _, playerId, info)):
var skin = configBundle.get(DeathGame.TYPE).getTank(info.type).skin;
getView(playerId).tank = skin;
getView(playerId).color = info.color;
case CHANGE(PLAYER_LIFE(playerId, life)):
getView(playerId).life = life;
case CHANGE(PLAYER_SCORE(playerId, score)):
getView(playerId).score = score;
case _:
}
}
}

View File

@@ -1,18 +0,0 @@
---
geometry.padding: 5
geometry.height: 100%
layout.margin: 5
layout.hAlign: right
views:
- id: level
$type: haxework.view.form.LabelView
style: text.box
geometry.height: 38
geometry.width: 100%
- $type: haxework.view.SpriteView
geometry.height: 50%
- id: players
$type: haxework.view.data.DataView
layout:
$type: haxework.view.layout.VerticalLayout
factory: ~ru.m.tankz.view.common.LifeView.factory

View File

@@ -1,46 +0,0 @@
package ru.m.tankz.view.game;
import haxework.view.group.HGroupView;
import haxework.view.form.LabelView;
import ru.m.geom.Direction;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.preset.DotaGame;
import ru.m.tankz.Type.TeamId;
import ru.m.tankz.view.common.LifeView;
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
public var position(default, null):Direction = Direction.TOP;
@:view var radiant:LifeView;
@:view var dire:LifeView;
@:view var level:LabelView;
public function refresh(state:GameState):Void {
radiant.life = state.getTeamLife(DotaGame.RADIANT);
radiant.score = state.getTeamScore(DotaGame.RADIANT);
dire.life = state.getTeamLife(DotaGame.DIRE);
dire.score = state.getTeamScore(DotaGame.DIRE);
}
private inline function getLifeView(teamId:TeamId):LifeView {
return switch teamId {
case DotaGame.RADIANT: radiant;
case DotaGame.DIRE: dire;
case _: null;
}
}
public function onGameEvent(event:GameEvent):Void {
switch event {
case START(start):
this.level.text = 'Level ${start.level.id}';
refresh(start.state);
case CHANGE(TEAM_LIFE(teamId, life)):
getLifeView(teamId).life = life;
case CHANGE(TEAM_SCORE(teamId, score)):
getLifeView(teamId).score = score;
case _:
}
}
}

View File

@@ -1,21 +0,0 @@
---
geometry.width: 100%
layout.margin: 20
views:
- id: radiant
$type: ru.m.tankz.view.common.LifeView
tank: bc
color: 0xff4422
- $type: haxework.view.SpriteView
geometry.width: 25%
- id: level
$type: haxework.view.form.LabelView
style: text.box
geometry.height: 38
geometry.width: 50%
- $type: haxework.view.SpriteView
geometry.width: 25%
- id: dire
$type: ru.m.tankz.view.common.LifeView
tank: bc
color: 0x3284ff

View File

@@ -1,67 +0,0 @@
package ru.m.tankz.view.game;
import haxework.view.group.IGroupView;
import haxework.view.group.VGroupView;
import ru.m.geom.Direction;
import ru.m.tankz.preset.ClassicGame;
import ru.m.tankz.preset.DeathGame;
import ru.m.tankz.preset.DotaGame;
import ru.m.tankz.render.IRender;
import ru.m.tankz.Type;
@:template class GameView extends VGroupView {
@:view public var render(default, null):IRender;
public var panel(default, null):IGamePanel;
public var type(default, set):GameType;
@:view public var top(default, null):IGroupView;
@:view public var bottom(default, null):IGroupView;
@:view public var left(default, null):IGroupView;
@:view public var right(default, null):IGroupView;
private function set_type(value:GameType):GameType {
if (type != value) {
type = value;
if (panel != null) {
panel.remove();
}
panel = buildPanel(type);
getContainer(panel.position).addView(panel);
}
return type;
}
private function buildPanel(type:GameType):IGamePanel {
return switch type {
case ClassicGame.TYPE: new ClassicGamePanel();
case DotaGame.TYPE: new DotaGamePanel();
case DeathGame.TYPE: new DeathGamePanel();
case _: throw 'Unsupported type: ${type}';
}
}
private function getContainer(position:Direction):IGroupView {
return switch position.toString() {
case "RIGHT": right;
case "LEFT": left;
case "TOP": top;
case "BOTTOM": bottom;
case _: throw 'Unsupported position: ${position}';
}
}
override public function update():Void {
super.update();
if (parent != null) {
var s = Math.min(parent.width / width, parent.height / height);
if (s < 1) {
content.scaleX = content.scaleY = s;
content.x = (parent.width - width * s) / 2;
content.y = (parent.height - height * s) / 2;
} else {
content.scaleX = content.scaleY = 1;
}
}
}
}

View File

@@ -1,22 +0,0 @@
---
views:
- id: top
$type: haxework.view.group.GroupView
layout.hAlign: center
geometry.width: 100%
- $type: haxework.view.group.HGroupView
views:
- id: left
$type: haxework.view.group.GroupView
layout.vAlign: middle
geometry.height: 100%
- id: render
$type: ru.m.tankz.render.Render
- id: right
$type: haxework.view.group.GroupView
layout.vAlign: middle
geometry.height: 100%
- id: bottom
$type: haxework.view.group.GroupView
layout.hAlign: center
geometry.width: 100%

View File

@@ -0,0 +1,27 @@
package ru.m.tankz.view.game;
import haxework.view.data.DataView;
import haxework.view.form.LabelView;
import haxework.view.group.HGroupView;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.render.IRender;
@:template class GameViewA extends HGroupView implements IGameView {
@:view public var render:IRender;
@:view public var teams:DataView<TeamState, TeamView>;
@:view public var level:LabelView;
private var helper:GameViewHelper;
public function onGameEvent(event:GameEvent):Void {
helper.onGameEvent(event);
}
public static function factory(config:Config):GameViewA {
var result = new GameViewA();
result.helper = new GameViewHelper(result, config);
return result;
}
}

View File

@@ -0,0 +1,27 @@
---
views:
- id: left
$type: haxework.view.group.GroupView
layout.vAlign: middle
geometry.height: 100%
geometry.width: 50%
- id: render
$type: ru.m.tankz.render.Render
- id: right
$type: haxework.view.group.VGroupView
geometry.height: 100%
geometry.width: 50%
geometry.padding: 5
layout.vAlign: top
layout.margin: 5
views:
- id: level
$type: haxework.view.form.LabelView
style: text.box
geometry.width: 100%
- $type: haxework.view.SpriteView
geometry.height: 30%
- id: teams
$type: haxework.view.data.DataView
layout.margin: 3
factory: ~TeamView.viewFactory

View File

@@ -0,0 +1,27 @@
package ru.m.tankz.view.game;
import haxework.view.data.DataView;
import haxework.view.form.LabelView;
import haxework.view.group.VGroupView;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.GameState;
import ru.m.tankz.render.IRender;
@:template class GameViewB extends VGroupView implements IGameView {
@:view public var render:IRender;
@:view public var teams:DataView<TeamState, TeamView>;
@:view public var level:LabelView;
private var helper:GameViewHelper;
public function onGameEvent(event:GameEvent):Void {
helper.onGameEvent(event);
}
public static function factory(config:Config):GameViewB {
var result = new GameViewB();
result.helper = new GameViewHelper(result, config, true);
return result;
}
}

View File

@@ -0,0 +1,20 @@
---
views:
- id: top
$type: haxework.view.group.HGroupView
layout.vAlign: middle
geometry.width: 100%
views:
- id: level
$type: haxework.view.form.LabelView
style: text.box
- $type: haxework.view.SpriteView
geometry.width: 100%
- id: teams
$type: haxework.view.data.DataView
layout:
$type: haxework.view.layout.HorizontalLayout
margin: 5
factory: ~TeamView.viewFactory
- id: render
$type: ru.m.tankz.render.Render

View File

@@ -0,0 +1,30 @@
package ru.m.tankz.view.game;
import haxework.view.geometry.HAlign;
import haxework.view.geometry.VAlign;
import haxework.view.group.GroupView;
class GameViewContainer extends GroupView {
override public function update():Void {
super.update();
if (parent != null) {
var s = Math.min(parent.width / width, parent.height / height);
if (s < 1) {
content.scaleX = content.scaleY = s;
content.x = switch layout.hAlign {
case LEFT | NONE: 0;
case CENTER: (parent.width - width * s) / 2;
case RIGHT: (parent.width - width * s);
}
content.y = switch layout.vAlign {
case TOP | NONE: 0;
case MIDDLE: (parent.height - height * s) / 2;
case BOTTOM: (parent.height - height * s);
}
} else {
content.scaleX = content.scaleY = 1;
}
}
}
}

View File

@@ -0,0 +1,83 @@
package ru.m.tankz.view.game;
import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.Type;
using ru.m.tankz.view.ViewUtil;
class GameViewHelper {
private var view:IGameView;
private var config:Config;
private var onelinelevel:Bool;
public function new(view:IGameView, config:Config, onelinelevel:Bool = false) {
this.view = view;
this.config = config;
this.onelinelevel = onelinelevel;
}
private function findTeamView(id:TeamId):Null<TeamView> {
for (view in view.teams.dataViews) {
if (view.teamId == id) {
return view;
}
}
return null;
}
private function findPlayerView(id:PlayerId):Null<PlayerView> {
var teamView = findTeamView(id.team);
if (teamView != null) {
for (view in teamView.dataViews) {
if (view.playerId == id) {
return view;
}
}
}
return null;
}
public function onGameEvent(event:GameEvent):Void {
switch event {
case START(start):
view.level.text = start.level.toLevelLabel(onelinelevel);
view.teams.data = [for (team in start.state.teams) team];
// ToDo: PlayerState default tank?
for (teamView in view.teams.dataViews) {
for (playerView in teamView.dataViews) {
var tank = config.getPlayerTank(playerView.playerId);
playerView.tank = {
type: tank.type,
skin: tank.skin,
hits: 0,
bonus: false,
color: config.getColor(playerView.playerId),
};
}
}
case CHANGE(TEAM_LIFE(teamId, life)):
var view = findPlayerView([teamId, -1]);
if (view != null) {
view.life = life;
}
case CHANGE(TEAM_SCORE(teamId, score)):
var view = findPlayerView([teamId, -1]);
if (view != null) {
view.score = score;
}
case CHANGE(PLAYER_LIFE(playerId, life)):
var view = findPlayerView(playerId);
if (view != null) {
view.life = life;
}
case CHANGE(PLAYER_SCORE(playerId, score)):
var view = findPlayerView(playerId);
if (view != null) {
view.score = score;
}
case _:
}
}
}

View File

@@ -1,9 +0,0 @@
package ru.m.tankz.view.game;
import haxework.view.IView;
import ru.m.geom.Direction;
import ru.m.tankz.game.IGame;
interface IGamePanel extends IView<Dynamic> extends GameListener {
public var position(default, null):Direction;
}

View File

@@ -0,0 +1,14 @@
package ru.m.tankz.view.game;
import ru.m.tankz.render.IRender;
import haxework.view.data.DataView;
import haxework.view.form.LabelView;
import haxework.view.IView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.game.IGame;
interface IGameView extends IView<Dynamic> extends GameListener {
public var render(default, null):IRender;
public var teams(default, null):DataView<TeamState, TeamView>;
public var level(default, null):LabelView;
}

View File

@@ -0,0 +1,52 @@
package ru.m.tankz.view.game;
import haxework.view.form.LabelView;
import haxework.view.group.VGroupView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
import ru.m.tankz.view.common.TankView;
@:template class PlayerView extends VGroupView {
@:view("title") public var titleView:LabelView;
@:view("tank") public var tankView:TankView;
@:view("life") public var lifeLabel:LabelView;
@:view("score") public var scoreLabel:LabelView;
public var playerId(default, default):PlayerId;
public var state(null, set):PlayerState;
public var tank(null, set):TankInfo;
public var life(null, set):Int;
public var score(null, set):Int;
private function set_state(value:PlayerState):PlayerState {
playerId = value.id;
titleView.text = value.name != null ? value.name : playerId.format();
life = value.life;
score = value.score;
tank = value.tank;
return state;
}
private function set_tank(value:TankInfo):TankInfo {
tank = value;
tankView.tank = tank;
return tank;
}
private function set_life(value:Int):Int {
lifeLabel.text = '${value}';
return value;
}
private function set_score(value:Int):Int {
scoreLabel.text = '${value}$';
return value;
}
public static function factory(index:Int, data:PlayerState):PlayerView {
var result = new PlayerView();
result.state = data;
return result;
}
}

View File

@@ -0,0 +1,19 @@
---
views:
- id: title
$type: haxework.view.form.LabelView
visible: false
- $type: haxework.view.group.HGroupView
layout.margin: 5
layout.vAlign: middle
views:
- id: tank
$type: ru.m.tankz.view.common.TankView
- id: life
$type: haxework.view.form.LabelView
style: text.box
geometry.width: 55
- id: score
$type: haxework.view.form.LabelView
style: text.box
geometry.width: 100

View File

@@ -0,0 +1,35 @@
package ru.m.tankz.view.game;
import haxework.view.data.DataView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
class TeamView extends DataView<PlayerState, PlayerView> {
public var teamId(default, default):TeamId;
public var state(default, set):TeamState;
private function new():Void {
super();
factory = PlayerView.factory;
layout.margin = 5;
}
private function set_state(value:TeamState):TeamState {
teamId = value.id;
var players = [for (player in value.players) player].filter(function(player) return player.life > 0);
if (value.life > 0) {
var teamState = new PlayerState([value.id, -1]);
teamState.life = value.life;
players.unshift(teamState);
}
data = players;
return value;
}
public static inline function viewFactory(index:Int, data:TeamState):TeamView {
var result = new TeamView();
result.state = data;
return result;
}
}

View File

@@ -0,0 +1,24 @@
package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import ru.m.control.DeviceAction;
import ru.m.geom.Circle;
import ru.m.geom.Point;
class CircleActionArea implements IActionArea {
public var action(default, null):DeviceAction;
public var circle(default, null):Circle;
public function new(action:DeviceAction, circle:Circle) {
this.action = action;
this.circle = circle;
}
public function contain(point:Point):Bool {
return circle.contain(point);
}
public function draw(graphics:Graphics):Void {
graphics.drawCircle(circle.x, circle.y, circle.radius);
}
}

View File

@@ -0,0 +1,42 @@
package ru.m.tankz.view.gamepad;
import ru.m.control.DeviceAction;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
class DefaultActionAreaBuilder implements IActionAreaBuilder {
public function new() {
}
public function build(width:Float, height:Float):Array<IActionArea> {
var areas:Array<IActionArea> = [];
var size = Math.min(width, height) / 7;
var padding = size / 2;
// top
areas.push(new RectangleActionArea(
DIRECTION(Direction.TOP),
new Rectangle(padding + size, height - size * 3 - padding, size, size)
));
// left
areas.push(new RectangleActionArea(
DIRECTION(Direction.LEFT),
new Rectangle(padding, height - size * 2 - padding, size, size)
));
// bottom
areas.push(new RectangleActionArea(
DIRECTION(Direction.BOTTOM),
new Rectangle(padding + size, height - size - padding, size, size)
));
// right
areas.push(new RectangleActionArea(
DIRECTION(Direction.RIGHT),
new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
));
// button
areas.push(new RectangleActionArea(
KEY(0),
new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
));
return areas;
}
}

View File

@@ -0,0 +1,29 @@
package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import haxework.color.Color;
import haxework.view.skin.ISkin;
@:style class GamepadSkin implements ISkin<GamepadView> {
@:style(0x00ff00) public var color(default, default):Null<Color>;
public function new(?color:Color) {
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) {
area.draw(graphics);
}
graphics.lineStyle();
graphics.endFill();
}
}

View File

@@ -1,66 +1,35 @@
package ru.m.tankz.view; package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import flash.display.Stage; import flash.display.Stage;
import flash.events.MouseEvent; import flash.events.MouseEvent;
import flash.events.TouchEvent; import flash.events.TouchEvent;
import haxework.color.Color;
import haxework.signal.Signal; import haxework.signal.Signal;
import haxework.view.skin.ISkin;
import haxework.view.SpriteView; import haxework.view.SpriteView;
import ru.m.control.DeviceAction; import ru.m.control.DeviceAction;
import ru.m.control.DeviceType; import ru.m.control.DeviceType;
import ru.m.control.IControlDevice; import ru.m.control.IControlDevice;
import ru.m.geom.Direction;
import ru.m.geom.Point; import ru.m.geom.Point;
import ru.m.geom.Rectangle;
typedef ActionArea = {
var action:DeviceAction;
var rect:Rectangle;
}
@:style class GamepadSkin implements ISkin<GamepadView> {
@:style(0) public var color(default, default):Null<Color>;
public function new(?color:Color) {
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 { class GamepadView extends SpriteView implements IControlDevice {
public static var ID(default, never):Int = -128;
public var type(default, null):DeviceType; public var type(default, null):DeviceType;
public var signal(default, null):Signal2<DeviceAction, Bool>; public var signal(default, null):Signal2<DeviceAction, Bool>;
public var areas(default, null):Array<ActionArea>; public var areas(default, null):Array<IActionArea>;
public var currentAreas(default, null):Map<Int, ActionArea>; public var currentAreas(default, null):Map<Int, IActionArea>;
private var builder:IActionAreaBuilder;
private var stage:Stage; private var stage:Stage;
public function new() { public function new() {
super(); super();
type = GAMEPAD(ID); style = "gamepad";
type = SCREEN;
builder = new SmartActionAreaBuilder();
signal = new Signal2(); signal = new Signal2();
areas = []; areas = [];
currentAreas = new Map(); currentAreas = new Map();
skin = new GamepadSkin(0x00ff00); skin = new GamepadSkin();
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin); content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
} }
@@ -106,13 +75,13 @@ class GamepadView extends SpriteView implements IControlDevice {
private function updateTouch(pointID:Int, point:Point):Void { private function updateTouch(pointID:Int, point:Point):Void {
if (currentAreas.exists(pointID)) { if (currentAreas.exists(pointID)) {
var area = currentAreas[pointID]; var area = currentAreas[pointID];
if (!area.rect.contain(point)) { if (!area.contain(point)) {
currentAreas.remove(pointID); currentAreas.remove(pointID);
signal.emit(area.action, false); signal.emit(area.action, false);
} }
} }
for (area in areas) { for (area in areas) {
if (area.rect.contain(point)) { if (area.contain(point)) {
currentAreas[pointID] = area; currentAreas[pointID] = area;
signal.emit(area.action, true); signal.emit(area.action, true);
break; break;
@@ -129,31 +98,10 @@ class GamepadView extends SpriteView implements IControlDevice {
override public function update():Void { override public function update():Void {
super.update(); super.update();
areas = []; areas = builder.build(width, height);
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 { public function dispose():Void {
stage = null; stage = null;
} }

View File

@@ -0,0 +1,11 @@
package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import ru.m.control.DeviceAction;
import ru.m.geom.Point;
interface IActionArea {
public var action(default, null):DeviceAction;
public function contain(point:Point):Bool;
public function draw(graphics:Graphics):Void;
}

View File

@@ -0,0 +1,5 @@
package ru.m.tankz.view.gamepad;
interface IActionAreaBuilder {
public function build(width:Float, height:Float):Array<IActionArea>;
}

View File

@@ -0,0 +1,24 @@
package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import ru.m.control.DeviceAction;
import ru.m.geom.Point;
import ru.m.geom.Rectangle;
class RectangleActionArea implements IActionArea {
public var action(default, null):DeviceAction;
public var rectangle(default, null):Rectangle;
public function new(action:DeviceAction, rectangle:Rectangle) {
this.action = action;
this.rectangle = rectangle;
}
public function contain(point:Point):Bool {
return rectangle.contain(point);
}
public function draw(graphics:Graphics):Void {
graphics.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
}
}

View File

@@ -0,0 +1,33 @@
package ru.m.tankz.view.gamepad;
import flash.display.Graphics;
import ru.m.control.DeviceAction;
import ru.m.geom.Point;
import ru.m.geom.Rectangle;
class RhombusActionArea implements IActionArea {
public var action(default, null):DeviceAction;
public var rectangle(default, null):Rectangle;
private var center:Point;
private var distance:Float;
public function new(action:DeviceAction, rectangle:Rectangle) {
this.action = action;
this.rectangle = rectangle;
center = rectangle.center;
distance = Math.max(rectangle.width / 2, rectangle.height / 2);
}
public function contain(point:Point):Bool {
return Math.abs(point.x - center.x) + Math.abs(point.y - center.y) < distance;
}
public function draw(graphics:Graphics):Void {
graphics.moveTo(rectangle.x + rectangle.width / 2, rectangle.top);
graphics.lineTo(rectangle.right, rectangle.y + rectangle.height / 2);
graphics.lineTo(rectangle.x + rectangle.width / 2, rectangle.bottom);
graphics.lineTo(rectangle.left, rectangle.y + rectangle.height / 2);
graphics.lineTo(rectangle.x + rectangle.width / 2, rectangle.top);
}
}

View File

@@ -0,0 +1,49 @@
package ru.m.tankz.view.gamepad;
import haxework.view.geometry.Box;
import ru.m.control.DeviceAction;
import ru.m.geom.Circle;
import ru.m.geom.Direction;
import ru.m.geom.Rectangle;
class SmartActionAreaBuilder implements IActionAreaBuilder {
public function new() {
}
public function build(width:Float, height:Float):Array<IActionArea> {
var areas:Array<IActionArea> = [];
var size = Math.min(width, height) / 5;
var padding = Box.fromArray([size / 4, size / 3]);
// top
areas.push(new RhombusActionArea(
DIRECTION(Direction.TOP),
new Rectangle(padding.left + size * 0.5, height - size * 2 - padding.bottom, size, size )
));
// left
areas.push(new RhombusActionArea(
DIRECTION(Direction.LEFT),
new Rectangle(padding.left, height - size * 1.5 - padding.bottom, size, size)
));
// bottom
areas.push(new RhombusActionArea(
DIRECTION(Direction.BOTTOM),
new Rectangle(padding.left + size * 0.5, height - size - padding.bottom, size, size)
));
// right
areas.push(new RhombusActionArea(
DIRECTION(Direction.RIGHT),
new Rectangle(padding.left + size, height - size * 1.5 - padding.bottom, size, size)
));
// key 0
areas.push(new CircleActionArea(
KEY(0),
new Circle(width - size * 0.5 - padding.right, height - size * 0.5 - padding.bottom, size / 2)
));
// key 1
areas.push(new CircleActionArea(
KEY(1),
new Circle(width - size * 0.5 - padding.right, height - size * 1.5 - padding.bottom, size / 2)
));
return areas;
}
}

View File

@@ -1,9 +1,9 @@
package ru.m.tankz.view.network; package ru.m.tankz.view.network;
import haxework.view.data.DataView;
import haxework.view.form.ButtonView; import haxework.view.form.ButtonView;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView; import haxework.view.frame.FrameView;
import haxework.view.list.VListView;
import haxework.view.text.TextView; import haxework.view.text.TextView;
import ru.m.tankz.game.GameInit; import ru.m.tankz.game.GameInit;
import ru.m.tankz.network.NetworkManager; import ru.m.tankz.network.NetworkManager;
@@ -16,7 +16,7 @@ import ru.m.tankz.proto.room.RoomSlotProto;
@:view var start:ButtonView; @:view var start:ButtonView;
@:view var info:TextView; @:view var info:TextView;
@:view var slots:VListView<RoomSlotProto>; @:view var slots:DataView<RoomSlotProto, SlotItemView>;
@:provide var switcher:FrameSwitcher; @:provide var switcher:FrameSwitcher;
@:provide var network:NetworkManager; @:provide var network:NetworkManager;

View File

@@ -34,6 +34,8 @@ views:
geometry.height: 3 geometry.height: 3
style: line style: line
- id: slots - id: slots
$type: haxework.view.list.VListView $type: haxework.view.data.DataView
layout.hAlign: center
geometry.stretch: true geometry.stretch: true
overflow.y: scroll
factory: ~ru.m.tankz.view.network.SlotItemView.factory factory: ~ru.m.tankz.view.network.SlotItemView.factory

View File

@@ -34,7 +34,9 @@ import ru.m.tankz.proto.room.RoomProto;
network.joinGame(data.game.id, true); network.joinGame(data.game.id, true);
} }
public static function factory():RoomItemView { public static function factory(index:Int, value:RoomProto):RoomItemView {
return new RoomItemView(); var result = new RoomItemView();
result.data = value;
return result;
} }
} }

View File

@@ -1,26 +1,20 @@
--- ---
# geometry.width: 100%
geometry.height: 48
layout.margin: 10 layout.margin: 10
layout.hAlign: center layout.hAlign: center
views: views:
- id: creator - id: creator
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
geometry.height: 100%
geometry.width: 200 geometry.width: 200
style: text.box style: text.box
- id: type - id: type
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
geometry.height: 100%
geometry.width: 200 geometry.width: 200
style: text.box style: text.box
- id: users - id: users
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
geometry.height: 100%
geometry.width: 150 geometry.width: 150
style: text.box style: text.box
- id: join - id: join
$type: haxework.view.form.ButtonView $type: haxework.view.form.ButtonView
geometry.height: 100%
text: Join text: Join
+onPress: ~join() +onPress: ~join()

View File

@@ -1,8 +1,8 @@
package ru.m.tankz.view.network; package ru.m.tankz.view.network;
import haxework.view.data.DataView;
import haxework.view.frame.FrameSwitcher; import haxework.view.frame.FrameSwitcher;
import haxework.view.frame.FrameView; import haxework.view.frame.FrameView;
import haxework.view.list.VListView;
import ru.m.tankz.network.NetworkManager; import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.proto.room.RoomProto; import ru.m.tankz.proto.room.RoomProto;
import ru.m.tankz.view.popup.CreateGamePopup; import ru.m.tankz.view.popup.CreateGamePopup;
@@ -10,7 +10,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
@:template class RoomListFrame extends FrameView<Dynamic> { @:template class RoomListFrame extends FrameView<Dynamic> {
public static inline var ID = "room_list"; public static inline var ID = "room_list";
@:view var games:VListView<RoomProto>; @:view var games:DataView<RoomProto, RoomItemView>;
@:provide var switcher:FrameSwitcher; @:provide var switcher:FrameSwitcher;
@:provide var network:NetworkManager; @:provide var network:NetworkManager;

View File

@@ -16,7 +16,7 @@ views:
text: Create text: Create
+onPress: ~create() +onPress: ~create()
- id: games - id: games
$type: haxework.view.list.VListView $type: haxework.view.data.DataView
geometry.stretch: true geometry.stretch: true
factory: ~ru.m.tankz.view.network.RoomItemView.factory factory: ~ru.m.tankz.view.network.RoomItemView.factory
geometry.margin: 10 geometry.margin: 10

View File

@@ -37,7 +37,10 @@ import ru.m.tankz.proto.room.RoomSlotProto;
network.selectSlot(data.slot); network.selectSlot(data.slot);
} }
public static function factory():SlotItemView { public static function factory(index:Int, value:RoomSlotProto):SlotItemView {
return new SlotItemView(); var result = new SlotItemView();
result.index = index;
result.data = value;
return result;
} }
} }

View File

@@ -1,17 +1,14 @@
--- ---
geometry.height: 48
geometry.padding: 2 geometry.padding: 2
layout.margin: 10 layout.margin: 10
views: views:
- id: type - id: type
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.height: 100%
geometry.width: 150 geometry.width: 150
- $type: haxework.view.group.HGroupView - $type: haxework.view.group.HGroupView
layout.hAlign: center layout.hAlign: center
layout.vAlign: middle layout.vAlign: middle
geometry.height: 100%
geometry.width: 300 geometry.width: 300
views: views:
- id: user - id: user

View File

@@ -36,7 +36,6 @@ view:
- id: username - id: username
$type: haxework.view.form.InputView $type: haxework.view.form.InputView
geometry.width: 100% geometry.width: 100%
geometry.height: 28
style: text.box style: text.box
- $type: haxework.view.form.LabelView - $type: haxework.view.form.LabelView
geometry.width: 100% geometry.width: 100%
@@ -47,7 +46,6 @@ view:
$type: haxework.view.form.InputView $type: haxework.view.form.InputView
textField.displayAsPassword: true textField.displayAsPassword: true
geometry.width: 100% geometry.width: 100%
geometry.height: 28
style: text.box style: text.box
visible: false visible: false
- id: error - id: error

View File

@@ -0,0 +1,39 @@
package ru.m.tankz.view.result;
import haxework.view.form.LabelView;
import haxework.view.group.HGroupView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.render.RenderUtil;
import ru.m.tankz.view.common.TankView;
@:template class FragView extends HGroupView {
@:view("tank") var tankView:TankView;
@:view("title") var titleView:LabelView;
@:view("score") var scoreView:LabelView;
public var data(default, set):Frag;
private function set_data(value:Frag):Frag {
data = value;
titleView.text = data.playerId.format();
scoreView.text = data.score.format();
switch data.target {
case TANK(tank):
tankView.tank = tank;
case EAGLE(color):
tankView.image = RenderUtil.eagleImage();
tankView.color = color;
case BONUS(type):
tankView.image = RenderUtil.bonusImage(type);
titleView.text = type;
}
return data;
}
public static function factory(index:Int, data:Frag):FragView {
var result = new FragView();
result.data = data;
return result;
}
}

View File

@@ -1,15 +1,14 @@
--- ---
layout.margin: 5 geometry.width: 100%
layout.vAlign: middle
views: views:
- id: tank - id: tank
$type: haxework.view.ImageView $type: ru.m.tankz.view.common.TankView
- id: life - id: title
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box - $type: haxework.view.SpriteView
geometry.width: 50 geometry.width: 100%
geometry.height: 38
- id: score - id: score
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
style: text.box style: text.box
geometry.width: 100 geometry.width: 100
geometry.height: 38

View File

@@ -0,0 +1,44 @@
package ru.m.tankz.view.result;
import haxework.view.data.DataView;
import haxework.view.form.LabelView;
import haxework.view.group.HGroupView;
import haxework.view.group.VGroupView;
import ru.m.tankz.game.GameState;
import ru.m.tankz.view.common.TankView;
@:template class ResultPlayerView extends VGroupView {
@:view("player") var playerView:HGroupView;
@:view("tank") var tankView:TankView;
@:view("title") var titleView:LabelView;
@:view("score") var scoreView:LabelView;
@:view("frags") var fragsView:DataView<Frag, FragView>;
public var data(default, set):PlayerState;
public var winner(default, set):Bool;
private function set_data(value:PlayerState):PlayerState {
data = value;
titleView.text = data.name != null ? '${data.id.format()} * ${data.name}' : data.id.format();
var additionalScore = Lambda.fold(data.frags, function(frag:Frag, score:Int) return score + frag.score, 0);
scoreView.text = '${data.score}$ (+${additionalScore}$)';
tankView.color = value.color;
fragsView.data = data.frags;
tankView.tank = value.tank;
return data;
}
private function set_winner(value:Bool):Bool {
winner = value;
style = winner ? "result.winner" : "result.loser";
playerView.style = winner ? "player.winner" : "player.loser";
return winner;
}
public static function factory(index:Int, data:PlayerState):ResultPlayerView {
var result = new ResultPlayerView();
result.data = data;
return result;
}
}

View File

@@ -0,0 +1,30 @@
---
style: light
geometry.margin: 15
geometry.padding: 10
geometry.width: 50%
geometry.height: 100%
layout.hAlign: center
views:
- id: player
$type: haxework.view.group.HGroupView
geometry.width: 100%
layout.vAlign: middle
views:
- id: tank
$type: ru.m.tankz.view.common.TankView
- id: title
$type: haxework.view.form.LabelView
- $type: haxework.view.SpriteView
geometry.width: 100%
- id: score
$type: haxework.view.form.LabelView
style: text.box
geometry.width: 100
- $type: haxework.view.SpriteView
style: line
- id: frags
$type: haxework.view.data.DataView
factory: ~ru.m.tankz.view.result.FragView.factory
geometry.stretch: true
overflow.y: scroll

View File

@@ -1,42 +1,18 @@
package ru.m.tankz.view.settings; package ru.m.tankz.view.settings;
import haxework.view.group.HGroupView;
import haxework.view.form.LabelView; import haxework.view.form.LabelView;
import haxework.view.group.HGroupView;
import haxework.view.list.ListView; import haxework.view.list.ListView;
import openfl.Assets;
import ru.m.control.DeviceAction;
import ru.m.tankz.control.Binding; import ru.m.tankz.control.Binding;
import ru.m.tankz.control.Control; import ru.m.tankz.control.Control;
using ru.m.tankz.view.ViewUtil;
typedef ActionItem = { typedef ActionItem = {
var action:TankAction; var action:TankAction;
var bind:BindAction; var bind:BindAction;
} }
class KeyboardMap {
private var data:Map<Int, String>;
public function new() {
this.data = new Map();
var data = Assets.getText("resources/keyboard.txt");
for (line in data.split("\n")) {
var arr = line.split("\t");
if (arr.length == 2) {
this.data.set(Std.parseInt(arr[1]), arr[0]);
}
}
}
private static var instance:KeyboardMap;
public static function getName(key:Int):String {
if (instance == null) instance = new KeyboardMap();
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
}
}
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> { @:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
public var item_index(default, default):Int; public var item_index(default, default):Int;
@@ -47,25 +23,10 @@ class KeyboardMap {
@: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 static function actionLabel(action:TankAction):String {
return switch (action) {
case TankAction.SHOT: "SHOT";
case TankAction.MOVE(d): 'MOVE_$d';
case x: '$x';
}
}
private static function bindLabel(bind:BindAction):String {
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 = data.action.toActionLabel();
key.text = bindLabel(data.bind); key.text = data.bind.toBindLabel();
return data; return data;
} }

View File

@@ -1,14 +1,11 @@
--- ---
geometry.margin: 5
layout.margin: 5 layout.margin: 5
views: views:
- id: action - id: action
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
geometry.width: 180 geometry.width: 180
geometry.height: 38
style: text.box style: text.box
- id: key - id: key
$type: haxework.view.form.LabelView $type: haxework.view.form.LabelView
geometry.width: 250 geometry.width: 250
geometry.height: 38
style: text.box style: text.box

View File

@@ -1,8 +1,8 @@
package ru.m.tankz.view.settings; package ru.m.tankz.view.settings;
import haxework.view.data.DataView; import haxework.view.data.DataView;
import haxework.view.group.GroupView;
import haxework.view.form.LabelView; import haxework.view.form.LabelView;
import haxework.view.group.GroupView;
import haxework.view.group.VGroupView; import haxework.view.group.VGroupView;
import promhx.Deferred; import promhx.Deferred;
import promhx.Promise; import promhx.Promise;
@@ -97,7 +97,7 @@ class BindEditor {
} }
private function screen():Void { private function screen():Void {
list.data = bindingToArray(SettingsStorage.buildGamepadBinding(GamepadView.ID)); list.data = bindingToArray(SettingsStorage.buildDeviceBinding(SCREEN));
list.toUpdate(); list.toUpdate();
save(); save();
} }

View File

@@ -9,7 +9,6 @@ views:
$type: haxework.view.group.GroupView $type: haxework.view.group.GroupView
layout: layout:
$type: haxework.view.layout.TailLayout $type: haxework.view.layout.TailLayout
rowSize: 2
margin: 10 margin: 10
geometry.width: 100% geometry.width: 100%
views: views:
@@ -19,9 +18,6 @@ views:
- $type: haxework.view.form.ButtonView - $type: haxework.view.form.ButtonView
+onPress: ~change() +onPress: ~change()
text: Change text: Change
- $type: haxework.view.form.ButtonView
+onPress: ~clear()
text: Clear
- $type: haxework.view.form.ButtonView - $type: haxework.view.form.ButtonView
+onPress: ~default_() +onPress: ~default_()
text: Default text: Default
@@ -29,5 +25,6 @@ views:
$type: haxework.view.data.DataView $type: haxework.view.data.DataView
layout: layout:
$type: haxework.view.layout.VerticalLayout $type: haxework.view.layout.VerticalLayout
margin: 5
factory: ~viewFactory factory: ~viewFactory
+onItemSelect: ~onItemSelect +onItemSelect: ~onItemSelect

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,6 @@
<svg aria-hidden="true" focusable="false" data-prefix="fal" data-icon="backspace" role="img"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" class="svg-inline--fa fa-backspace fa-w-20 fa-5x">
<path fill="currentColor"
d="M469.66 181.65l-11.31-11.31c-3.12-3.12-8.19-3.12-11.31 0L384 233.37l-63.03-63.03c-3.12-3.12-8.19-3.12-11.31 0l-11.31 11.31c-3.12 3.12-3.12 8.19 0 11.31L361.38 256l-63.03 63.03c-3.12 3.12-3.12 8.19 0 11.31l11.31 11.31c3.12 3.12 8.19 3.12 11.31 0L384 278.63l63.03 63.03c3.12 3.12 8.19 3.12 11.31 0l11.31-11.31c3.12-3.12 3.12-8.19 0-11.31L406.63 256l63.03-63.03a8.015 8.015 0 0 0 0-11.32zM576 64H205.26C188.28 64 172 70.74 160 82.74L9.37 233.37c-12.5 12.5-12.5 32.76 0 45.25L160 429.25c12 12 28.28 18.75 45.25 18.75H576c35.35 0 64-28.65 64-64V128c0-35.35-28.65-64-64-64zm32 320c0 17.64-14.36 32-32 32H205.26c-8.55 0-16.58-3.33-22.63-9.37L32 256l150.63-150.63c6.04-6.04 14.08-9.37 22.63-9.37H576c17.64 0 32 14.36 32 32v256z"
class=""></path>
</svg>

After

Width:  |  Height:  |  Size: 1004 B

View File

@@ -0,0 +1,6 @@
<svg aria-hidden="true" focusable="false" data-prefix="fal" data-icon="keyboard" role="img"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-keyboard fa-w-18 fa-5x">
<path fill="currentColor"
d="M528 64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h480c26.51 0 48-21.49 48-48V112c0-26.51-21.49-48-48-48zm16 336c0 8.823-7.177 16-16 16H48c-8.823 0-16-7.177-16-16V112c0-8.823 7.177-16 16-16h480c8.823 0 16 7.177 16 16v288zM168 268v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm-336 80v-24c0-6.627-5.373-12-12-12H84c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm384 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zM120 188v-24c0-6.627-5.373-12-12-12H84c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm96 0v-24c0-6.627-5.373-12-12-12h-24c-6.627 0-12 5.373-12 12v24c0 6.627 5.373 12 12 12h24c6.627 0 12-5.373 12-12zm-96 152v-8c0-6.627-5.373-12-12-12H180c-6.627 0-12 5.373-12 12v8c0 6.627 5.373 12 12 12h216c6.627 0 12-5.373 12-12z"
class=""></path>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,7 @@
<svg aria-hidden="true" focusable="false" data-prefix="fal" data-icon="tablet-android-alt" role="img"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"
class="svg-inline--fa fa-tablet-android-alt fa-w-14 fa-3x">
<path fill="currentColor"
d="M352 96v256H96V96h256m48-96H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zM48 480c-8.8 0-16-7.2-16-16V48c0-8.8 7.2-16 16-16h352c8.8 0 16 7.2 16 16v416c0 8.8-7.2 16-16 16H48zM372 64H76c-6.6 0-12 5.4-12 12v296c0 6.6 5.4 12 12 12h296c6.6 0 12-5.4 12-12V76c0-6.6-5.4-12-12-12zm-96 352H172c-6.6 0-12 5.4-12 12v8c0 6.6 5.4 12 12 12h104c6.6 0 12-5.4 12-12v-8c0-6.6-5.4-12-12-12z"
class=""></path>
</svg>

After

Width:  |  Height:  |  Size: 729 B

View File

@@ -0,0 +1,41 @@
package ru.m.geom;
abstract Circle(Array<Float>) {
public var x(get, set):Float;
public var y(get, set):Float;
public var radius(get, set):Float;
public function new(x:Float = 0, y:Float = 0, radius:Float = 0) {
this = [
x, y, radius,
];
}
private inline function get_x():Float {
return this[0];
}
private inline function set_x(value:Float):Float {
return this[0] = value;
}
private inline function get_y():Float {
return this[1];
}
private inline function set_y(value:Float):Float {
return this[1] = value;
}
private inline function get_radius():Float {
return this[2];
}
private inline function set_radius(value:Float):Float {
return this[2] = value;
}
public function contain(point:Point):Bool {
return Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2)) < radius;
}
}

View File

@@ -13,6 +13,10 @@ class Point {
return new Point(x + point.x, y + point.y); return new Point(x + point.x, y + point.y);
} }
public function clone():Point {
return new Point(x, y);
}
public function hashCode():Int { public function hashCode():Int {
return Std.int(x + 1000 * y); return Std.int(x + 1000 * y);
} }

View File

@@ -1,6 +1,6 @@
package ru.m.tankz; package ru.m.tankz;
typedef Type = Dynamic; import haxework.color.Color;
typedef GameType = String; typedef GameType = String;
@@ -14,6 +14,15 @@ typedef TankType = String;
typedef BonusType = String; typedef BonusType = String;
typedef TankInfo = {
var type:TankType;
var skin:String;
var hits:Int;
var bonus:Bool;
var color:Color;
@:optional var name:String;
}
abstract PlayerId(Array<Dynamic>) { abstract PlayerId(Array<Dynamic>) {
public var team(get, never):TeamId; public var team(get, never):TeamId;
public var index(get, never):Int; public var index(get, never):Int;
@@ -36,6 +45,10 @@ abstract PlayerId(Array<Dynamic>) {
return index - other.index; return index - other.index;
} }
public function format():String {
return index > -1 ? '${team} #${index}' : team;
}
@:from static public inline function fromArray(value:Array<Dynamic>):PlayerId { @:from static public inline function fromArray(value:Array<Dynamic>):PlayerId {
return new PlayerId(value[0], value[1]); return new PlayerId(value[0], value[1]);
} }
@@ -67,6 +80,10 @@ abstract PackId(Array<Dynamic>) {
return new PackId(value[0], value[1]); return new PackId(value[0], value[1]);
} }
@:from static public function fromString(value:String):PackId {
return fromArray(value.split("_"));
}
@:to public inline function toString():String { @:to public inline function toString():String {
return '${type}_${name}'; return '${type}_${name}';
} }
@@ -79,3 +96,10 @@ abstract PackId(Array<Dynamic>) {
typedef LevelId = Int; typedef LevelId = Int;
typedef PresetId = Int; typedef PresetId = Int;
abstract Score(Int) from Int to Int {
public function new(value:Int) this = value;
public inline function format():String return '${this}$';
}

View File

@@ -0,0 +1,63 @@
package ru.m.tankz.bonus;
import ru.m.geom.Point;
import ru.m.tankz.core.Eagle;
import ru.m.tankz.engine.IEngine;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.IGame;
import ru.m.tankz.map.LevelMap;
import ru.m.tankz.Type;
using ru.m.tankz.game.GameUtil;
class ArmorEagleBonus extends BaseBonus {
public static inline var CLASS = "armor.eagle";
private static var brickMap(default, never) = [
[1, 1, 1, 1],
[1, 0, 0, 1],
[1, 0, 0, 1],
[1, 1, 1, 1],
];
override public function apply(playerId:PlayerId, game:IGame, engine:IEngine):Void {
for (team in game.teams) {
if (team.eagleId > 0) {
var brickType = team.id == playerId.team ? "armor" : "none";
applyEagleArmor(team.eagleId, brickType, config.duration, game, engine);
}
}
}
private function getEagleBricksIds(eagle:Eagle, map:LevelMap):Array<Int> {
var result:Array<Int> = [];
var center = eagle.rect.center;
var cx:Int = Math.round(center.x / map.cellWidth - brickMap.length / 2);
var cy:Int = Math.round(center.y / map.cellHeight - brickMap[0].length / 2);
for (x in 0...brickMap.length) {
for (y in 0...brickMap[0].length) {
if (brickMap[x][y] > 0) {
var brick = map.getBrick(new Point(cx + x, cy + y));
if (brick != null) {
result.push(brick.id);
}
}
}
}
return result;
}
private function applyEagleArmor(eagleId:Int, brickType:BrickType, duration:Int, game:IGame, engine:IEngine):Void {
var eagle:Eagle = engine.getEntity(eagleId);
var bricks:Array<Int> = getEagleBricksIds(eagle, engine.map);
for (brickId in bricks) {
game.gameEventSignal.emit(CHANGE(BRICK(brickId, brickType)));
}
game.ticker.emit(function() {
for (brickId in bricks) {
game.gameEventSignal.emit(CHANGE(BRICK(brickId, "brick")));
}
}, Std.int(duration * 1000), '$CLASS.${eagle.id}');
}
}

Some files were not shown because too many files have changed in this diff Show More