Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 112cd7ba2f | |||
| 77ddd78d84 | |||
| 4fa5cf84fa | |||
| 40bdf6a5cc | |||
| 47039bbaa5 | |||
| 4d7fcb4b4b | |||
| 5f24e85deb | |||
| 42fd008a54 | |||
| c2b0618c93 | |||
| 94f72f71e3 | |||
| bb4b928c89 | |||
| d67d4e5709 | |||
| a4bbeb2573 | |||
| e032c25e1a | |||
| d9cce32bb8 | |||
| 10d5e0df40 | |||
| 0f3392aa0c | |||
| 9d4558ca47 | |||
| 6609756065 | |||
| 605935528b | |||
| f072d8dc6e | |||
| 00cd404a98 | |||
| d47be9ea8a | |||
| 2d70a5652b | |||
| bbf1438728 | |||
| c0496f2e7c | |||
| 636be8611f | |||
| 48f9c433e2 | |||
| 314f5a480c | |||
| 46f2abab05 | |||
| 883f14fb76 | |||
| cc151322d8 | |||
| de64e2813e | |||
| db80c151bb | |||
| ef971e03b9 | |||
| f10da93a12 | |||
| e63b41ae8a | |||
| 43a34cce39 | |||
| b9b5453f89 | |||
| f5af6716d5 | |||
| 7125cc1e9f | |||
| 8a3ceec1ee | |||
| 523f334c1b | |||
| a547b68dc0 | |||
| 45cabc1926 | |||
| 42138cd4ad | |||
| e8e3a6f1b3 |
@@ -7,3 +7,6 @@ indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -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
|
||||
------
|
||||
* Added display tank player name in `Render`
|
||||
|
||||
31
WORK.md
31
WORK.md
@@ -1,11 +1,22 @@
|
||||
* **shovel** bonus with armor bricks
|
||||
* bonuses in dota/death mod
|
||||
* bonuses
|
||||
* death game bonuses
|
||||
* boat bonus
|
||||
* tanks and bullets speed balancing
|
||||
* result frame update (next game select, only human player info)
|
||||
* network game series
|
||||
* map packs (create in editor, import in game, save imported in local storage)
|
||||
* update bots
|
||||
* improve bonuses system
|
||||
* screen gamepad on mobiles
|
||||
* resize render on mobiles
|
||||
* save state in classic game
|
||||
* game series
|
||||
* network series
|
||||
* map packs
|
||||
* create in editor
|
||||
* import in game
|
||||
* save imported in local storage
|
||||
* database
|
||||
* 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
|
||||
|
||||
@@ -5,7 +5,7 @@ project_user: holop
|
||||
deploy_user: "{{ project_user }}"
|
||||
deploy_project: "{{ project_name }}"
|
||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||
deploy_repo_version: master
|
||||
deploy_repo_version: develop
|
||||
deploy_npm: yes
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"SdkDir": "C:\\sdk",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
"SdkDir": "C:\\sdk",
|
||||
"PublishDir": "",
|
||||
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"SdkDir": "/home/holop/sdk",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
"SdkDir": "/home/holop/sdk",
|
||||
"PublishDir": "/opt/repo/tankz",
|
||||
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
}
|
||||
|
||||
78
gulpfile.js
78
gulpfile.js
@@ -1,16 +1,12 @@
|
||||
const gulp = require('gulp');
|
||||
const zip = require('gulp-zip');
|
||||
const foreach = require('gulp-foreach');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const Config = require('./config.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 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) {
|
||||
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:
|
||||
* windows target
|
||||
* window exe package (innosetup)
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
@@ -62,7 +43,6 @@ const config = new Project.Config({
|
||||
],
|
||||
assets: [
|
||||
'src/common/resources',
|
||||
'target/levels'
|
||||
],
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
@@ -84,11 +64,15 @@ const client = new Project(
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
Project.Platform.WINDOWS,
|
||||
Project.Platform.ANDROID,
|
||||
],
|
||||
config.branch({
|
||||
name: 'client',
|
||||
sources: ['src/client/haxe'],
|
||||
sources: [
|
||||
//'src/fixes/haxe',
|
||||
'src/client/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.Client',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
@@ -109,7 +93,6 @@ const client = new Project(
|
||||
`CompilationOption.set('port',${port})`,
|
||||
]
|
||||
}),
|
||||
module.exports.generate
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
@@ -123,7 +106,11 @@ const editor = new Project(
|
||||
],
|
||||
config.branch({
|
||||
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',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
@@ -133,7 +120,7 @@ const editor = new Project(
|
||||
meta: {
|
||||
filename: 'editor',
|
||||
width: 1024,
|
||||
height: 850,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'dev_layout',
|
||||
@@ -152,25 +139,50 @@ const server = new Project(
|
||||
sources: ['src/server/haxe'],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
}),
|
||||
module.exports.generate
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
|
||||
|
||||
/**
|
||||
* default
|
||||
*/
|
||||
module.exports.default = gulp.series(
|
||||
const defaultSeries = [
|
||||
exports.clean,
|
||||
exports.levels,
|
||||
exports.generate,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:flash:html'],
|
||||
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:html'],
|
||||
module.exports['editor:html5: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);
|
||||
|
||||
1556
package-lock.json
generated
1556
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,24 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.16.0",
|
||||
"version": "0.17.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-foreach": "^0.1.0",
|
||||
"gulp-haxetool": "0.0.20",
|
||||
"gulp-zip": "^5.0.0",
|
||||
"gulp-haxetool": "0.1.0",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||
"lime": "7.5.0",
|
||||
"openfl": "8.9.1",
|
||||
"hxcpp": "4.0.8",
|
||||
"hxcpp": "4.0.52",
|
||||
"promhx": "1.1.0",
|
||||
"protohx": "0.4.6",
|
||||
"yaml": "1.3.0",
|
||||
"orm": "2.1.0",
|
||||
"yield": "2.0.0",
|
||||
"haxe-crypto": "0.0.7",
|
||||
"svg": "1.1.2"
|
||||
}
|
||||
|
||||
31
sql/init.sql
31
sql/init.sql
@@ -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');
|
||||
|
||||
42
src/client/haxe/ru/m/Device.hx
Normal file
42
src/client/haxe/ru/m/Device.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
82
src/client/haxe/ru/m/Updater.hx
Normal file
82
src/client/haxe/ru/m/Updater.hx
Normal 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package ru.m.control;
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
|
||||
@@ -12,20 +12,26 @@ using haxework.color.ColorUtil;
|
||||
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
@:style(false) private var solid:Null<Bool>;
|
||||
|
||||
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.color = color;
|
||||
init();
|
||||
this.solid = solid;
|
||||
init(solid);
|
||||
}
|
||||
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
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.set(UP, buildSVG(color));
|
||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||
@@ -39,7 +45,9 @@ using haxework.color.ColorUtil;
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
if (!solid) {
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
}
|
||||
// ToDo: padding
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.text.TextFormatAlign;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.geometry.Box;
|
||||
import haxework.view.geometry.HAlign;
|
||||
@@ -7,6 +8,7 @@ import haxework.view.geometry.SizeValue;
|
||||
import haxework.view.geometry.VAlign;
|
||||
import haxework.view.theme.ITheme;
|
||||
import haxework.view.theme.Theme;
|
||||
import haxework.view.utils.DrawUtil;
|
||||
import openfl.Assets;
|
||||
import ru.m.skin.ButtonSVGSkin;
|
||||
|
||||
@@ -41,6 +43,7 @@ class AppTheme extends Theme {
|
||||
|
||||
register(new Style("text.header", [
|
||||
"font.size" => fontSize.big,
|
||||
"font.align" => TextFormatAlign.CENTER,
|
||||
"skin.background.color" => Color.fromInt(0x000000),
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.border.color" => colors.light,
|
||||
@@ -59,13 +62,14 @@ class AppTheme extends Theme {
|
||||
"skin.background.color" => Color.fromInt(0x000000),
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.border.color" => colors.light,
|
||||
"geometry.padding" => Box.fromArray([15, 8]),
|
||||
], ["text"]));
|
||||
|
||||
register(new Style("text.box.active", [
|
||||
"skin.background.color" => Color.fromInt(0x55aa55),
|
||||
"skin.background.alpha" => 1,
|
||||
"skin.border.color" => Color.fromInt(0x88dd88),
|
||||
], ["text"]));
|
||||
], ["text.box"]));
|
||||
|
||||
register(new Style("button.level", [
|
||||
"font.size" => fontSize.veryBig,
|
||||
@@ -92,7 +96,8 @@ class AppTheme extends Theme {
|
||||
], ["dark", "border"]));
|
||||
|
||||
register(new Style("line", [
|
||||
"_" => null,
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromInt(2),
|
||||
], ["border"]));
|
||||
|
||||
register(new Style("window.close", [
|
||||
@@ -101,6 +106,29 @@ class AppTheme extends Theme {
|
||||
"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("close", "times-circle-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("login", "sign-in-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', [
|
||||
"geometry.width" => 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', [
|
||||
"geometry.width" => 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),
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import haxework.view.theme.ITheme;
|
||||
import flash.Lib;
|
||||
import haxework.animate.FadeAnimate;
|
||||
import haxework.animate.UnFadeAnimate;
|
||||
import haxework.net.manage.ILoaderManager;
|
||||
import haxework.net.manage.LoaderManager;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.resources.Resources;
|
||||
import haxework.view.popup.PopupManager;
|
||||
import haxework.view.theme.ITheme;
|
||||
import lime.ui.Gamepad;
|
||||
import lime.ui.Joystick;
|
||||
import ru.m.connect.IConnection;
|
||||
@@ -42,6 +44,8 @@ class Init {
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
@:provide static var loaderManager:ILoaderManager;
|
||||
@:provide static var updater:Updater;
|
||||
|
||||
private static function buildConnection():IConnection<Request, Response> {
|
||||
var host:String = CompilationOption.get("host");
|
||||
@@ -77,6 +81,9 @@ class Init {
|
||||
bus = new ControlBus();
|
||||
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) {
|
||||
trace('gamepad', device);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.m.tankz.bundle;
|
||||
|
||||
import openfl.Assets;
|
||||
import openfl.utils.AssetType;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.util.LevelUtil;
|
||||
@@ -12,7 +13,7 @@ class LevelBundle implements ILevelBundle {
|
||||
public function new() {}
|
||||
|
||||
private function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('levels/${id}.zip');
|
||||
var bytes = Assets.getBytes('resources/level/${id}.zip');
|
||||
return {
|
||||
id: id,
|
||||
data: LevelUtil.unpack(bytes).map(function(level) {
|
||||
@@ -28,4 +29,14 @@ class LevelBundle implements ILevelBundle {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@@ -18,7 +20,7 @@ class HumanControl extends Control {
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimer:Timer;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
@@ -32,6 +34,16 @@ class HumanControl extends Control {
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
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 {
|
||||
@@ -49,10 +61,10 @@ class HumanControl extends Control {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
@@ -66,17 +78,18 @@ class HumanControl extends Control {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(300);
|
||||
shotTimer.run = shot;
|
||||
shot();
|
||||
if (!shotTimers.exists(weapon)) {
|
||||
var timer = new Timer(300);
|
||||
timer.run = shooter(weapon);
|
||||
timer.run();
|
||||
shotTimers.set(weapon, timer);
|
||||
}
|
||||
} else {
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
}
|
||||
case TankAction.STOP:
|
||||
@@ -96,7 +109,9 @@ class HumanControl extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
private function shot():Void {
|
||||
action(SHOT);
|
||||
private function shooter(weapon:Int):Void -> Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class LocalGame extends GameRunner {
|
||||
}
|
||||
}
|
||||
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);
|
||||
gameStorage.set(progress);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class NetworkManager {
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
connect();
|
||||
//connect(); // ToDo: disable network
|
||||
}
|
||||
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
|
||||
@@ -149,8 +149,8 @@ class Render extends SpriteView implements IRender {
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, piercing)):
|
||||
var item = new BulletRenderItem(rect, piercing);
|
||||
case SPAWN(BULLET(id, rect, playerId, skin)):
|
||||
var item = new BulletRenderItem(rect, skin);
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
|
||||
25
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
25
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal 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');
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,11 @@ import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.PixelSnapping;
|
||||
import openfl.Assets;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BitmapRenderItem extends RenderItem {
|
||||
public var image(default, set):String;
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
private var bitmapData:BitmapData;
|
||||
private var bitmap:Bitmap;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
@@ -22,11 +20,12 @@ class BitmapRenderItem extends RenderItem {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function set_image(value:String):String {
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
bitmapData = Assets.getBitmapData(image);
|
||||
bitmap.bitmapData = bitmapData;
|
||||
bitmap.bitmapData = image;
|
||||
bitmap.width = rect.width;
|
||||
bitmap.height = rect.height;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class BonusRenderItem extends BitmapRenderItem {
|
||||
private function set_type(value:BonusType):BonusType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
image = 'resources/image/bonus/${type}.png';
|
||||
image = RenderUtil.bonusImage(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -23,15 +23,19 @@ class BrickRenderItem extends RenderItem {
|
||||
private var shape:Shape;
|
||||
private var cells:Array<Point>;
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
this.shape = new Shape();
|
||||
cells = [
|
||||
private static function buildCells():Array<Point> {
|
||||
return [
|
||||
new Point(0, 0),
|
||||
new Point(0, 1),
|
||||
new Point(1, 0),
|
||||
new Point(1, 1),
|
||||
];
|
||||
}
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
this.shape = new Shape();
|
||||
cells = buildCells();
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
@@ -51,6 +55,7 @@ class BrickRenderItem extends RenderItem {
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
cells = buildCells();
|
||||
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
||||
redraw();
|
||||
}
|
||||
|
||||
@@ -3,20 +3,19 @@ package ru.m.tankz.render.item;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
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);
|
||||
this.piercing = piercing;
|
||||
this.skin = skin;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_piercing(value:Int):Int {
|
||||
if (piercing != value) {
|
||||
piercing = value;
|
||||
var type = piercing > 0 ? 'piercing' : 'normal';
|
||||
image = 'resources/image/bullet/${type}.png';
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
image = RenderUtil.bulletImage(skin);
|
||||
}
|
||||
return piercing;
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ class EagleRenderItem extends BitmapRenderItem {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
protectView.x = (bitmapData.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (bitmapData.height - protectView.frames[0].image.height) / 2;
|
||||
protectView.x = (image.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (image.height - protectView.frames[0].image.height) / 2;
|
||||
}
|
||||
protectView.visible = protect;
|
||||
protectView.playing = protect;
|
||||
@@ -47,10 +47,9 @@ class EagleRenderItem extends BitmapRenderItem {
|
||||
private function set_death(value:Bool):Bool {
|
||||
if (death != value) {
|
||||
death = value;
|
||||
var suffix = death ? '-death' : '';
|
||||
image = 'resources/image/eagle/eagle${suffix}.png';
|
||||
image = RenderUtil.eagleImage(death);
|
||||
if (!color.zero) {
|
||||
bitmap.bitmapData = bitmapData = BitmapUtil.colorize(bitmapData, color);
|
||||
bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
}
|
||||
return death;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import haxework.view.theme.ITheme;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
@@ -9,8 +8,8 @@ import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import haxework.color.Color;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.view.theme.ITheme;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
@@ -62,8 +61,8 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
||||
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
||||
var image1 = RenderUtil.tankImage(skin, 0);
|
||||
var image2 = RenderUtil.tankImage(skin, 1);
|
||||
var color1:Color = switch hits {
|
||||
case 1: 0x869C43;
|
||||
case 2: 0xDEAF80;
|
||||
|
||||
@@ -4,7 +4,7 @@ import haxe.DynamicAccess;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
|
||||
@:yield class RecordStorage extends SharedObjectStorage {
|
||||
class RecordStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
@@ -23,17 +23,19 @@ import ru.m.tankz.game.record.GameRecord;
|
||||
super.delete('${id}.info');
|
||||
}
|
||||
|
||||
public function iterator():Iterator<GameRecordInfo> {
|
||||
public function list():Array<GameRecordInfo> {
|
||||
var result = [];
|
||||
var data:DynamicAccess<String> = so.data;
|
||||
for (id in data.keys()) {
|
||||
try {
|
||||
if (StringTools.endsWith(id, '.info')) {
|
||||
@yield return read(id);
|
||||
result.push(read(id));
|
||||
}
|
||||
} catch (error:Dynamic) {
|
||||
L.w("RecordStorage", 'read ', error);
|
||||
delete(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import ru.m.tankz.control.Control;
|
||||
|
||||
class SettingsStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 3;
|
||||
private static inline var VERSION = 4.1;
|
||||
|
||||
public function new() {
|
||||
super('settings_${VERSION}');
|
||||
@@ -26,41 +26,56 @@ class SettingsStorage extends SharedObjectStorage {
|
||||
}
|
||||
|
||||
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 {
|
||||
var device = GAMEPAD(id);
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||
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> = [
|
||||
-1 => [
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => 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 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||
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 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||
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)},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.layout.DefaultLayout;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.group.GroupView;
|
||||
import haxework.view.layout.DefaultLayout;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
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.storage.GameStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.view.game.GameView;
|
||||
import ru.m.tankz.view.GamepadView;
|
||||
import ru.m.tankz.view.game.GameViewA;
|
||||
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 {
|
||||
public static inline var ID = "game";
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
@:view("game") private var gameView(default, null):GameView;
|
||||
@:view private var gamepad(default, null):GamepadView;
|
||||
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
@: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 recorder:GameRecord;
|
||||
|
||||
@@ -46,33 +51,32 @@ import ru.m.tankz.view.GamepadView;
|
||||
|
||||
override public function onShow(data:GameInit):Void {
|
||||
gamepad.visible = false;
|
||||
// ToDo:
|
||||
for (i in 0...1) {
|
||||
for (bind in settings.getBinding(i)) {
|
||||
switch bind.device {
|
||||
case GAMEPAD(GamepadView.ID):
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
game = switch data {
|
||||
case LOCAL(start): new LocalGame(start);
|
||||
case NETWORK(network): new NetworkGame(network);
|
||||
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;
|
||||
gameView.render.config = game.config;
|
||||
game.connect(gameView.render);
|
||||
game.connect(soundManager);
|
||||
if (gameView.panel != null) {
|
||||
game.connect(gameView.panel);
|
||||
}
|
||||
game.connect(gameView);
|
||||
game.connect(this);
|
||||
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 {
|
||||
@@ -80,7 +84,9 @@ import ru.m.tankz.view.GamepadView;
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
gameView.render.reset();
|
||||
if (gameView != null) {
|
||||
gameView.render.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
@@ -95,9 +101,13 @@ import ru.m.tankz.view.GamepadView;
|
||||
override public function onHide():Void {
|
||||
stop();
|
||||
soundManager.stopAll();
|
||||
if (gameView != null) {
|
||||
gameViewContainer.removeView(gameView);
|
||||
gameView = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
switcher.change(MenuFrame.ID);
|
||||
switcher.change(LevelFrame.ID, game.level.packId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,18 @@ overflow.x: crop
|
||||
overflow.y: crop
|
||||
views:
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.game.GameView
|
||||
$type: ru.m.tankz.view.game.GameViewContainer
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
- id: gamepad
|
||||
$type: ru.m.tankz.view.GamepadView
|
||||
$type: ru.m.tankz.view.gamepad.GamepadView
|
||||
geometry.position: absolute
|
||||
geometry.stretch: true
|
||||
visible: false
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.close
|
||||
geometry.position: absolute
|
||||
geometry.hAlign: left
|
||||
geometry.vAlign: top
|
||||
geometry.margin: 10
|
||||
+onPress: ~close()
|
||||
|
||||
@@ -12,6 +12,8 @@ import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type.PackId;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class LevelFrame extends FrameView<PackId> {
|
||||
public static inline var ID = "level";
|
||||
|
||||
@@ -35,7 +37,7 @@ import ru.m.tankz.Type.PackId;
|
||||
}
|
||||
|
||||
override public function onShow(data:PackId):Void {
|
||||
header.text = data.type;
|
||||
header.text = data.toPackLabel();
|
||||
pack = levelBundle.get(data);
|
||||
levels.data = pack.data;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.GameState;
|
||||
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.popup.LoginPopup;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class MenuFrame extends FrameView<Dynamic> {
|
||||
|
||||
public static var ID(default, never):String = "menu";
|
||||
|
||||
@:provide var gameInit:GameInit;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide static var gameInit:GameInit;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@: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("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
@:view("update") var updateButton:ButtonView;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
@@ -32,6 +40,15 @@ import ru.m.tankz.view.popup.LoginPopup;
|
||||
super.onShow(data);
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
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 {
|
||||
@@ -39,9 +56,16 @@ import ru.m.tankz.view.popup.LoginPopup;
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
|
||||
private function startGame(type:GameType):Void {
|
||||
gameInit = LOCAL({state: new GameState(type), level: null});
|
||||
switcher.change(LevelFrame.ID, new PackId(type));
|
||||
private function packButtonFactory(index:Int, packId:PackId):ButtonView {
|
||||
var result = new ButtonView();
|
||||
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 {
|
||||
@@ -93,4 +117,8 @@ import ru.m.tankz.view.popup.LoginPopup;
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
}
|
||||
|
||||
private function appUpdate():Void {
|
||||
appUpdater.download();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,74 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
layout.margin: 10
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- $type: haxework.view.group.VGroupView
|
||||
style: container
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- $type: haxework.view.group.VGroupView
|
||||
layout.margin: 10
|
||||
layout.hAlign: center
|
||||
views:
|
||||
- $type: haxework.view.form.LabelView
|
||||
text: Tank'z
|
||||
style: font
|
||||
font.size: 100
|
||||
geometry.margin.bottom: 30
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.menu
|
||||
+onPress: ~startGame('classic')
|
||||
text: Classic
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.menu
|
||||
+onPress: ~startGame('dota')
|
||||
text: DotA
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.menu
|
||||
+onPress: ~startGame('death')
|
||||
text: DeathMatch
|
||||
- id: packs
|
||||
$type: haxework.view.data.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
margin: 10
|
||||
factory: ~packButtonFactory
|
||||
+onDataSelect: ~startGame
|
||||
- $type: haxework.view.SpriteView
|
||||
style: line
|
||||
geometry.width: 250
|
||||
geometry.margin: [0, 10]
|
||||
visible: false
|
||||
- $type: haxework.view.form.ButtonView
|
||||
style: button.menu
|
||||
+onPress: ~switcher.change('record')
|
||||
text: Records
|
||||
visible: false
|
||||
- id: network
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.menu
|
||||
+onPress: ~startNetwork()
|
||||
text: Network
|
||||
- $type: haxework.view.form.LabelView
|
||||
geometry.hAlign: right
|
||||
geometry.vAlign: top
|
||||
geometry.padding: [20, 5]
|
||||
geometry.position: absolute
|
||||
geometry.margin: [0, 20, 20, 0]
|
||||
style: text.box
|
||||
text: $r:text:version
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: settings
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.settings
|
||||
+onPress: ~switcher.change('settings')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- id: username
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text
|
||||
- id: login
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.login
|
||||
+onPress: ~login()
|
||||
- id: logout
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.logout
|
||||
+onPress: ~logout()
|
||||
visible: false
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
visible: false
|
||||
- $type: haxework.view.form.LabelView
|
||||
geometry.hAlign: right
|
||||
geometry.vAlign: top
|
||||
geometry.position: absolute
|
||||
geometry.margin: [0, 20, 20, 0]
|
||||
style: text.box
|
||||
text: $r:text:version
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: settings
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.settings
|
||||
+onPress: ~switcher.change('settings')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- id: username
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text
|
||||
- id: login
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.login
|
||||
+onPress: ~login()
|
||||
- id: logout
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.logout
|
||||
+onPress: ~logout()
|
||||
visible: false
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- id: update
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.active
|
||||
+onPress: ~appUpdate()
|
||||
visible: false
|
||||
|
||||
@@ -20,7 +20,7 @@ import ru.m.tankz.storage.RecordStorage;
|
||||
}
|
||||
|
||||
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()));
|
||||
this.data.data = data;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.form.LabelView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.GameState;
|
||||
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> {
|
||||
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("next") var nextButton:ButtonView;
|
||||
|
||||
@@ -29,30 +31,15 @@ import ru.m.tankz.view.common.LifeView;
|
||||
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 {
|
||||
result = data;
|
||||
var players = Lambda.array(result.state.players);
|
||||
players.sort(function(a, b) return a.id.compare(b.id));
|
||||
resultView.data = players;
|
||||
var label = '${result.state.type} Level ${result.level.id}';
|
||||
if (result.level.name != null) {
|
||||
label += '\n${result.level.name}';
|
||||
resultView.data = result.state.humans;
|
||||
for (view in resultView.dataViews) {
|
||||
view.winner = view.data.id.team == data.winner;
|
||||
}
|
||||
levelLabel.text = label;
|
||||
levelLabel.text = data.level.toLevelLabel();
|
||||
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 {
|
||||
@@ -60,7 +47,8 @@ import ru.m.tankz.view.common.LifeView;
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -69,12 +57,9 @@ import ru.m.tankz.view.common.LifeView;
|
||||
var level = pack.data[result.level.id + 1];
|
||||
var progress = gameStorage.get(pack.id);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,15 @@ views:
|
||||
font.align: center
|
||||
- id: result
|
||||
$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%
|
||||
overflow.y: scroll
|
||||
geometry.margin.top: 20
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
hAlign: right
|
||||
margin: 10
|
||||
layout.margin: 5
|
||||
layout.hAlign: center
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
|
||||
@@ -16,6 +16,7 @@ import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.common.SlotView;
|
||||
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class StartFrame extends FrameView<Start> {
|
||||
|
||||
@@ -28,12 +29,11 @@ using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
@:view var header:LabelView;
|
||||
@: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 humanTotal:Int = 2;
|
||||
|
||||
|
||||
private var start:Start;
|
||||
|
||||
public function new() {
|
||||
@@ -44,38 +44,52 @@ using haxe.EnumTools.EnumValueTools;
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
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;
|
||||
slotsView.data = defaultControls(start.state.config);
|
||||
teamsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
private static function defaultControls(config:Config):Array<PlayerControl> {
|
||||
var controls:Array<PlayerControl> = [];
|
||||
private static function defaultControls(config:Config):Array<Array<PlayerControl>> {
|
||||
var result:Array<Array<PlayerControl>> = [];
|
||||
var preset = config.getPreset(0);
|
||||
var human = false;
|
||||
for (team in preset.teams) {
|
||||
if (team.id != "bot") { // ToDo:
|
||||
var controls:Array<PlayerControl> = [];
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
controls.push({
|
||||
var control:PlayerControl = {
|
||||
playerId: playerId,
|
||||
color: config.getColor(playerId),
|
||||
controller: NONE,
|
||||
});
|
||||
}
|
||||
if (!human) {
|
||||
control.controller = HUMAN(0);
|
||||
control.name = ControllerParser.defaultName(control.controller);
|
||||
human = true;
|
||||
}
|
||||
controls.push(control);
|
||||
}
|
||||
result.push(controls);
|
||||
}
|
||||
}
|
||||
controls.sort(function(a, b) return a.playerId.compare(b.playerId));
|
||||
if (controls.length > 0) {
|
||||
controls[0].controller = HUMAN(0);
|
||||
controls[0].name = ControllerParser.defaultName(controls[0].controller);
|
||||
}
|
||||
return controls;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function teamViewFactory(index:Int, value:Array<PlayerControl>):DataView<PlayerControl, SlotView> {
|
||||
var result = new DataView();
|
||||
result.style = "light";
|
||||
result.geometry.padding = 5;
|
||||
result.factory = slotViewFactory;
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
|
||||
var result = new SlotView();
|
||||
result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
|
||||
result.control = value;
|
||||
result.tank = start.state.config.getPlayerTank(value.playerId).skin;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -83,11 +97,13 @@ using haxe.EnumTools.EnumValueTools;
|
||||
switch controller {
|
||||
case NONE:
|
||||
case _:
|
||||
for (view in slotsView.dataViews) {
|
||||
if (view.control.controller.equals(controller)) {
|
||||
view.control.controller = NONE;
|
||||
view.select.selected = NONE;
|
||||
view.control.name = null;
|
||||
for (teamView in teamsView.dataViews) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.control.controller.equals(controller)) {
|
||||
view.control.controller = NONE;
|
||||
view.select.selected = NONE;
|
||||
view.control.name = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +122,11 @@ using haxe.EnumTools.EnumValueTools;
|
||||
private function onPresetSelect(value:GamePreset):Void {
|
||||
if (progress.isPresetAvailable(start.level.id, 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,18 @@ views:
|
||||
- id: header
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.header
|
||||
- id: slots
|
||||
- id: teams
|
||||
$type: haxework.view.data.DataView
|
||||
geometry.padding: 10
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
layout.hAlign: center
|
||||
overflow.y: scroll
|
||||
factory: ~slotViewFactory
|
||||
factory: ~teamViewFactory
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
# $type: haxework.view.layout.TailLayout
|
||||
$type: haxework.view.layout.TailLayout
|
||||
margin: 5
|
||||
rowSize: 2
|
||||
- $type: haxework.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
|
||||
62
src/client/haxe/ru/m/tankz/view/ViewUtil.hx
Normal file
62
src/client/haxe/ru/m/tankz/view/ViewUtil.hx
Normal 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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -11,22 +11,18 @@ views:
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
geometry.height: 38
|
||||
- id: type
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
geometry.height: 38
|
||||
- id: level
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
- id: preset
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
- id: delete
|
||||
$type: haxework.view.form.ButtonView
|
||||
style: button.close.small
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
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.SelectView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.skin.SpriteSkin;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
|
||||
@:template class SlotView extends HGroupView {
|
||||
|
||||
@:view("tank") public var tankView:ImageView;
|
||||
@:view("slot") public var slotLabel:LabelView;
|
||||
@:view("select") public var select:SelectView<Controller>;
|
||||
|
||||
public var control(default, set):PlayerControl;
|
||||
public var tank(default, set):String;
|
||||
|
||||
private function set_control(value:PlayerControl):PlayerControl {
|
||||
control = value;
|
||||
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;
|
||||
tankView.color = value.color;
|
||||
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 {
|
||||
select.currentView.style = switch value {
|
||||
case HUMAN(_): "button.active";
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
---
|
||||
geometry.height: 48
|
||||
geometry.padding: 2
|
||||
layout.margin: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: tank
|
||||
$type: haxework.view.ImageView
|
||||
style: icon.tank
|
||||
- id: slot
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 100%
|
||||
geometry.width: 150
|
||||
- id: select
|
||||
$type: haxework.view.form.SelectView<ru.m.tankz.control.Controller>
|
||||
|
||||
23
src/client/haxe/ru/m/tankz/view/common/TankView.hx
Normal file
23
src/client/haxe/ru/m/tankz/view/common/TankView.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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%
|
||||
27
src/client/haxe/ru/m/tankz/view/game/GameViewA.hx
Normal file
27
src/client/haxe/ru/m/tankz/view/game/GameViewA.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
27
src/client/haxe/ru/m/tankz/view/game/GameViewA.yaml
Normal file
27
src/client/haxe/ru/m/tankz/view/game/GameViewA.yaml
Normal 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
|
||||
27
src/client/haxe/ru/m/tankz/view/game/GameViewB.hx
Normal file
27
src/client/haxe/ru/m/tankz/view/game/GameViewB.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
20
src/client/haxe/ru/m/tankz/view/game/GameViewB.yaml
Normal file
20
src/client/haxe/ru/m/tankz/view/game/GameViewB.yaml
Normal 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
|
||||
30
src/client/haxe/ru/m/tankz/view/game/GameViewContainer.hx
Normal file
30
src/client/haxe/ru/m/tankz/view/game/GameViewContainer.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
src/client/haxe/ru/m/tankz/view/game/GameViewHelper.hx
Normal file
83
src/client/haxe/ru/m/tankz/view/game/GameViewHelper.hx
Normal 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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
14
src/client/haxe/ru/m/tankz/view/game/IGameView.hx
Normal file
14
src/client/haxe/ru/m/tankz/view/game/IGameView.hx
Normal 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;
|
||||
}
|
||||
52
src/client/haxe/ru/m/tankz/view/game/PlayerView.hx
Normal file
52
src/client/haxe/ru/m/tankz/view/game/PlayerView.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
19
src/client/haxe/ru/m/tankz/view/game/PlayerView.yaml
Normal file
19
src/client/haxe/ru/m/tankz/view/game/PlayerView.yaml
Normal 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
|
||||
35
src/client/haxe/ru/m/tankz/view/game/TeamView.hx
Normal file
35
src/client/haxe/ru/m/tankz/view/game/TeamView.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
24
src/client/haxe/ru/m/tankz/view/gamepad/CircleActionArea.hx
Normal file
24
src/client/haxe/ru/m/tankz/view/gamepad/CircleActionArea.hx
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
29
src/client/haxe/ru/m/tankz/view/gamepad/GamepadSkin.hx
Normal file
29
src/client/haxe/ru/m/tankz/view/gamepad/GamepadSkin.hx
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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.events.MouseEvent;
|
||||
import flash.events.TouchEvent;
|
||||
import haxework.color.Color;
|
||||
import haxework.signal.Signal;
|
||||
import haxework.view.skin.ISkin;
|
||||
import haxework.view.SpriteView;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlDevice;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
typedef ActionArea = {
|
||||
var action:DeviceAction;
|
||||
var rect:Rectangle;
|
||||
}
|
||||
|
||||
@: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 {
|
||||
public static var ID(default, never):Int = -128;
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public var areas(default, null):Array<ActionArea>;
|
||||
public var currentAreas(default, null):Map<Int, ActionArea>;
|
||||
public var areas(default, null):Array<IActionArea>;
|
||||
public var currentAreas(default, null):Map<Int, IActionArea>;
|
||||
|
||||
private var builder:IActionAreaBuilder;
|
||||
private var stage:Stage;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
type = GAMEPAD(ID);
|
||||
style = "gamepad";
|
||||
type = SCREEN;
|
||||
builder = new SmartActionAreaBuilder();
|
||||
signal = new Signal2();
|
||||
areas = [];
|
||||
currentAreas = new Map();
|
||||
skin = new GamepadSkin(0x00ff00);
|
||||
skin = new GamepadSkin();
|
||||
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
}
|
||||
@@ -106,13 +75,13 @@ class GamepadView extends SpriteView implements IControlDevice {
|
||||
private function updateTouch(pointID:Int, point:Point):Void {
|
||||
if (currentAreas.exists(pointID)) {
|
||||
var area = currentAreas[pointID];
|
||||
if (!area.rect.contain(point)) {
|
||||
if (!area.contain(point)) {
|
||||
currentAreas.remove(pointID);
|
||||
signal.emit(area.action, false);
|
||||
}
|
||||
}
|
||||
for (area in areas) {
|
||||
if (area.rect.contain(point)) {
|
||||
if (area.contain(point)) {
|
||||
currentAreas[pointID] = area;
|
||||
signal.emit(area.action, true);
|
||||
break;
|
||||
@@ -129,31 +98,10 @@ class GamepadView extends SpriteView implements IControlDevice {
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
areas = [];
|
||||
var size = Math.min(width, height) / 7;
|
||||
var padding = size / 2;
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.TOP),
|
||||
rect: new Rectangle(padding + size, height - size * 3 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.LEFT),
|
||||
rect: new Rectangle(padding, height - size * 2 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.BOTTOM),
|
||||
rect: new Rectangle(padding + size, height - size - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.RIGHT),
|
||||
rect: new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: KEY(0),
|
||||
rect: new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
|
||||
});
|
||||
areas = builder.build(width, height);
|
||||
}
|
||||
|
||||
|
||||
public function dispose():Void {
|
||||
stage = null;
|
||||
}
|
||||
11
src/client/haxe/ru/m/tankz/view/gamepad/IActionArea.hx
Normal file
11
src/client/haxe/ru/m/tankz/view/gamepad/IActionArea.hx
Normal 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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.m.tankz.view.gamepad;
|
||||
|
||||
interface IActionAreaBuilder {
|
||||
public function build(width:Float, height:Float):Array<IActionArea>;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
33
src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx
Normal file
33
src/client/haxe/ru/m/tankz/view/gamepad/RhombusActionArea.hx
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.text.TextView;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
@@ -16,7 +16,7 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
@:view var start:ButtonView;
|
||||
@:view var info:TextView;
|
||||
@:view var slots:VListView<RoomSlotProto>;
|
||||
@:view var slots:DataView<RoomSlotProto, SlotItemView>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
@@ -34,6 +34,8 @@ views:
|
||||
geometry.height: 3
|
||||
style: line
|
||||
- id: slots
|
||||
$type: haxework.view.list.VListView
|
||||
$type: haxework.view.data.DataView
|
||||
layout.hAlign: center
|
||||
geometry.stretch: true
|
||||
overflow.y: scroll
|
||||
factory: ~ru.m.tankz.view.network.SlotItemView.factory
|
||||
|
||||
@@ -34,7 +34,9 @@ import ru.m.tankz.proto.room.RoomProto;
|
||||
network.joinGame(data.game.id, true);
|
||||
}
|
||||
|
||||
public static function factory():RoomItemView {
|
||||
return new RoomItemView();
|
||||
public static function factory(index:Int, value:RoomProto):RoomItemView {
|
||||
var result = new RoomItemView();
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
---
|
||||
# geometry.width: 100%
|
||||
geometry.height: 48
|
||||
layout.margin: 10
|
||||
layout.hAlign: center
|
||||
views:
|
||||
- id: creator
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 200
|
||||
style: text.box
|
||||
- id: type
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 200
|
||||
style: text.box
|
||||
- id: users
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.height: 100%
|
||||
geometry.width: 150
|
||||
style: text.box
|
||||
- id: join
|
||||
$type: haxework.view.form.ButtonView
|
||||
geometry.height: 100%
|
||||
text: Join
|
||||
+onPress: ~join()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.view.network;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.list.VListView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
import ru.m.tankz.view.popup.CreateGamePopup;
|
||||
@@ -10,7 +10,7 @@ import ru.m.tankz.view.popup.CreateGamePopup;
|
||||
@:template class RoomListFrame extends FrameView<Dynamic> {
|
||||
public static inline var ID = "room_list";
|
||||
|
||||
@:view var games:VListView<RoomProto>;
|
||||
@:view var games:DataView<RoomProto, RoomItemView>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
|
||||
@@ -16,7 +16,7 @@ views:
|
||||
text: Create
|
||||
+onPress: ~create()
|
||||
- id: games
|
||||
$type: haxework.view.list.VListView
|
||||
$type: haxework.view.data.DataView
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.tankz.view.network.RoomItemView.factory
|
||||
geometry.margin: 10
|
||||
|
||||
@@ -37,7 +37,10 @@ import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
network.selectSlot(data.slot);
|
||||
}
|
||||
|
||||
public static function factory():SlotItemView {
|
||||
return new SlotItemView();
|
||||
public static function factory(index:Int, value:RoomSlotProto):SlotItemView {
|
||||
var result = new SlotItemView();
|
||||
result.index = index;
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
---
|
||||
geometry.height: 48
|
||||
geometry.padding: 2
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: type
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.height: 100%
|
||||
geometry.width: 150
|
||||
- $type: haxework.view.group.HGroupView
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
geometry.height: 100%
|
||||
geometry.width: 300
|
||||
views:
|
||||
- id: user
|
||||
|
||||
@@ -36,7 +36,6 @@ view:
|
||||
- id: username
|
||||
$type: haxework.view.form.InputView
|
||||
geometry.width: 100%
|
||||
geometry.height: 28
|
||||
style: text.box
|
||||
- $type: haxework.view.form.LabelView
|
||||
geometry.width: 100%
|
||||
@@ -47,7 +46,6 @@ view:
|
||||
$type: haxework.view.form.InputView
|
||||
textField.displayAsPassword: true
|
||||
geometry.width: 100%
|
||||
geometry.height: 28
|
||||
style: text.box
|
||||
visible: false
|
||||
- id: error
|
||||
|
||||
39
src/client/haxe/ru/m/tankz/view/result/FragView.hx
Normal file
39
src/client/haxe/ru/m/tankz/view/result/FragView.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
---
|
||||
layout.margin: 5
|
||||
geometry.width: 100%
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: tank
|
||||
$type: haxework.view.ImageView
|
||||
- id: life
|
||||
$type: ru.m.tankz.view.common.TankView
|
||||
- id: title
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 50
|
||||
geometry.height: 38
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- id: score
|
||||
$type: haxework.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
geometry.height: 38
|
||||
44
src/client/haxe/ru/m/tankz/view/result/ResultPlayerView.hx
Normal file
44
src/client/haxe/ru/m/tankz/view/result/ResultPlayerView.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
30
src/client/haxe/ru/m/tankz/view/result/ResultPlayerView.yaml
Normal file
30
src/client/haxe/ru/m/tankz/view/result/ResultPlayerView.yaml
Normal 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
|
||||
@@ -1,42 +1,18 @@
|
||||
package ru.m.tankz.view.settings;
|
||||
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.group.HGroupView;
|
||||
import haxework.view.list.ListView;
|
||||
import openfl.Assets;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
typedef ActionItem = {
|
||||
var action:TankAction;
|
||||
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> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
@@ -47,25 +23,10 @@ class KeyboardMap {
|
||||
@:view var action(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 {
|
||||
data = value;
|
||||
action.text = actionLabel(data.action);
|
||||
key.text = bindLabel(data.bind);
|
||||
action.text = data.action.toActionLabel();
|
||||
key.text = data.bind.toBindLabel();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
---
|
||||
geometry.margin: 5
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: action
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 180
|
||||
geometry.height: 38
|
||||
style: text.box
|
||||
- id: key
|
||||
$type: haxework.view.form.LabelView
|
||||
geometry.width: 250
|
||||
geometry.height: 38
|
||||
style: text.box
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.view.settings;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.group.GroupView;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.group.GroupView;
|
||||
import haxework.view.group.VGroupView;
|
||||
import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
@@ -97,7 +97,7 @@ class BindEditor {
|
||||
}
|
||||
|
||||
private function screen():Void {
|
||||
list.data = bindingToArray(SettingsStorage.buildGamepadBinding(GamepadView.ID));
|
||||
list.data = bindingToArray(SettingsStorage.buildDeviceBinding(SCREEN));
|
||||
list.toUpdate();
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ views:
|
||||
$type: haxework.view.group.GroupView
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 2
|
||||
margin: 10
|
||||
geometry.width: 100%
|
||||
views:
|
||||
@@ -19,9 +18,6 @@ views:
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~change()
|
||||
text: Change
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~clear()
|
||||
text: Clear
|
||||
- $type: haxework.view.form.ButtonView
|
||||
+onPress: ~default_()
|
||||
text: Default
|
||||
@@ -29,5 +25,6 @@ views:
|
||||
$type: haxework.view.data.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
margin: 5
|
||||
factory: ~viewFactory
|
||||
+onItemSelect: ~onItemSelect
|
||||
|
||||
BIN
src/client/resources/image/bullet/mine.png
Normal file
BIN
src/client/resources/image/bullet/mine.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/client/resources/image/bullet/rocket.png
Normal file
BIN
src/client/resources/image/bullet/rocket.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
6
src/client/resources/image/icon/backspace-light.svg
Normal file
6
src/client/resources/image/icon/backspace-light.svg
Normal 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 |
6
src/client/resources/image/icon/keyboard-light.svg
Normal file
6
src/client/resources/image/icon/keyboard-light.svg
Normal 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 |
@@ -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 |
41
src/common/haxe/ru/m/geom/Circle.hx
Normal file
41
src/common/haxe/ru/m/geom/Circle.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,10 @@ class Point {
|
||||
return new Point(x + point.x, y + point.y);
|
||||
}
|
||||
|
||||
public function clone():Point {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public function hashCode():Int {
|
||||
return Std.int(x + 1000 * y);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
typedef Type = Dynamic;
|
||||
import haxework.color.Color;
|
||||
|
||||
typedef GameType = String;
|
||||
|
||||
@@ -14,6 +14,15 @@ typedef TankType = 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>) {
|
||||
public var team(get, never):TeamId;
|
||||
public var index(get, never):Int;
|
||||
@@ -36,6 +45,10 @@ abstract PlayerId(Array<Dynamic>) {
|
||||
return index - other.index;
|
||||
}
|
||||
|
||||
public function format():String {
|
||||
return index > -1 ? '${team} #${index}' : team;
|
||||
}
|
||||
|
||||
@:from static public inline function fromArray(value:Array<Dynamic>):PlayerId {
|
||||
return new PlayerId(value[0], value[1]);
|
||||
}
|
||||
@@ -67,6 +80,10 @@ abstract PackId(Array<Dynamic>) {
|
||||
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 {
|
||||
return '${type}_${name}';
|
||||
}
|
||||
@@ -79,3 +96,10 @@ abstract PackId(Array<Dynamic>) {
|
||||
typedef LevelId = 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}$';
|
||||
}
|
||||
|
||||
63
src/common/haxe/ru/m/tankz/bonus/ArmorEagleBonus.hx
Normal file
63
src/common/haxe/ru/m/tankz/bonus/ArmorEagleBonus.hx
Normal 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
Reference in New Issue
Block a user