Compare commits
183 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 | |||
| 6d5148e0a5 | |||
| 262221d969 | |||
| 9eccb263c0 | |||
| ba90b90cd3 | |||
| 94340bddb1 | |||
| 3361d252ee | |||
| 637772f2dd | |||
| f703c76c21 | |||
| 5fe307a218 | |||
| 670a11d6ba | |||
| 1ec1c3baae | |||
| 24f5b0c218 | |||
| b7bc1d244f | |||
| fbc9238d2f | |||
| eb7c311bb6 | |||
| 9640414ba4 | |||
| bc95ca03e2 | |||
| d0ebf05f1c | |||
| 91dd84a437 | |||
| 1b36016a1a | |||
| db0adbac30 | |||
| 948648b313 | |||
| 73822dc95a | |||
| 282bc68734 | |||
| 2ff374abb6 | |||
| f999c66fea | |||
| 2b3f368e0f | |||
| c0ab953115 | |||
| e39de4467d | |||
| 4c3f1ca0fc | |||
| 7fa5a4e048 | |||
| dc1279f636 | |||
| 5798fa9db7 | |||
| c534cf20fd | |||
| 38e14c9269 | |||
| a66b72ba22 | |||
| 2c42d993ca | |||
| a49d673f25 | |||
| ee5de9f3db | |||
| 94b3a94cbb | |||
| caab6ba3a3 | |||
| 7f70c49b87 | |||
| 8f50da64c2 | |||
| 982ca09a23 | |||
| dbf30decae | |||
| abd1b834d7 | |||
| 6ad9076987 | |||
| 78bbf5264e | |||
| 4c8ae66624 | |||
| 5a3d5b974e | |||
| fb9a28c126 | |||
| 7115ea8ac2 | |||
| 01417f5bbd | |||
| abf944418e | |||
| c7946ef1da | |||
| 241499bc2d | |||
| 74297dd9c7 | |||
| 31cb20bf85 | |||
| 1d95de02e1 | |||
| ba13111a8e | |||
| 94b19a1c26 | |||
| 50a0cee044 | |||
| 26ad5f47cd | |||
| 864d5f3335 | |||
| 4b426183e8 | |||
| a5722dfa9d | |||
| 7984d8282c | |||
| 17823ede11 | |||
| 5db3ae1af0 | |||
| bbe2aeb7fb | |||
| 09b188cf24 | |||
| 11f8fc6190 | |||
| 96e608c36f | |||
| 3c116db135 | |||
| efe826110c | |||
| c1ff14111d | |||
| cd7dd1984b | |||
| 686c659c84 | |||
| 797dfca2be | |||
| aa10825b12 | |||
| 608ed3acc4 | |||
| 03b461f082 | |||
| cbb28f4158 | |||
| 13240677b0 | |||
| b0ae85334b | |||
| 183c6c16f1 | |||
| a7f286dc42 | |||
| 20b60009e3 | |||
| d6b572aead | |||
| d11d0ac53f | |||
| ab02460b11 | |||
| fc18e2e0b7 | |||
| 363a48bb1b | |||
| e9de677ceb | |||
| 5ff7b19475 | |||
| 7ddba8f69b | |||
| b86e0ddd20 | |||
| a3f3de3af5 | |||
| 4a4ca463c3 | |||
| 13d01293f6 | |||
| d0104e4361 | |||
| c3db9f2414 | |||
| f34d35e03a | |||
| 9868d27bc3 | |||
| c0b4b2a4c1 | |||
| 9dc0a4ce06 | |||
| c58735ea43 | |||
| 4e2b65c225 | |||
| 663935bd75 | |||
| d1ed17d1d7 | |||
| 135ad0d992 | |||
| 8fb1d6132d | |||
| f60feea6e8 | |||
| d7b7744eb8 | |||
| 2eb606aa21 | |||
| a86c4fc447 | |||
| 1ea216fd20 | |||
| 121c470b00 | |||
| 404dd77806 | |||
| d2f23e7777 | |||
| fd0e2382d0 | |||
| e609dafedc | |||
| a948dfbaad | |||
| 5b804c6902 | |||
| 556cd2f1a9 | |||
| 7d570336a5 | |||
| a9b591a7ca | |||
| 216e1aa476 | |||
| 4d8de90419 | |||
| 0b17fbf804 | |||
| c6639e11b1 | |||
| e6f9aa8ba1 | |||
| 2c191d932c | |||
| d52b94d095 | |||
| c67385576e | |||
| f09e70c5f8 |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
44
CHANGELOG.md
Normal file
44
CHANGELOG.md
Normal file
@@ -0,0 +1,44 @@
|
||||
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`
|
||||
* Fixed join game after relogin
|
||||
* Updated `CreateGamePopup` for any screen sizes
|
||||
* Fixed tank destroy zero score label
|
||||
* Added custom size map support
|
||||
* Fixed clock bonus for spawned tanks
|
||||
|
||||
0.14.0
|
||||
------
|
||||
* Added `CreateGamePopup`
|
||||
* Fixed null tank color
|
||||
* Updated `Ticker`
|
||||
|
||||
0.13.0
|
||||
------
|
||||
* Added `Ticker`
|
||||
* Fixed `PacketQueue` stream reading
|
||||
* Added `PlayerControl` and `ControlPreset`
|
||||
* Added `BaseControlFactory`
|
||||
|
||||
0.12.0
|
||||
------
|
||||
* Added `GameRoomFrame`
|
||||
* Improved websocket connection with using binary protocol instead of text
|
||||
* Added `GameListFrame`
|
||||
* Added `DesktopConnection` for linux client build
|
||||
* Updated `SoundManager`
|
||||
95
WORK.md
95
WORK.md
@@ -1,73 +1,22 @@
|
||||
* build
|
||||
* gulp 100%
|
||||
* linux 100%
|
||||
* deb-package 100%
|
||||
* windows 0%
|
||||
* exe-package 0% (inno setup)
|
||||
|
||||
* deploy
|
||||
* capistrano 100%
|
||||
|
||||
* ui
|
||||
* auth frame 0%
|
||||
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
||||
* select level frame 10%
|
||||
* game frame 50%
|
||||
|
||||
* engine
|
||||
* config 100%
|
||||
* map 100%
|
||||
* tanks 100%
|
||||
* bullets 100%
|
||||
* boxes 100%
|
||||
* map changes 100%
|
||||
* bonuses 100%
|
||||
* eagle 100%
|
||||
|
||||
* game
|
||||
* classic
|
||||
* state 50%
|
||||
* bot 50%
|
||||
* human 100%
|
||||
* dota
|
||||
* state 50%
|
||||
* bot 10%
|
||||
* human 100%
|
||||
|
||||
* bonus
|
||||
* star 50%
|
||||
* grenade 0%
|
||||
* helm 0%
|
||||
* clock 0%
|
||||
* shovel 0%
|
||||
|
||||
* state
|
||||
* score 0%
|
||||
* human tank 0%
|
||||
* save/load 0%
|
||||
* export/import 0%
|
||||
|
||||
* render
|
||||
* map 100%
|
||||
* tanks 100%
|
||||
* bullet 100%
|
||||
* calc redraw 50%
|
||||
* animations
|
||||
* tank spawn 0%
|
||||
* tank move 100%
|
||||
* map water 100%
|
||||
* bullet boom 90%
|
||||
* tank boom 90%
|
||||
* bonuses 100%
|
||||
* html5 50%
|
||||
|
||||
* proto
|
||||
...
|
||||
|
||||
* editor
|
||||
* level
|
||||
* open 100%
|
||||
* edit 50%
|
||||
* save 100%
|
||||
* tank
|
||||
* color 10%
|
||||
* bonuses
|
||||
* death game bonuses
|
||||
* boat bonus
|
||||
* tanks and bullets speed balancing
|
||||
* 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
|
||||
|
||||
@@ -3,6 +3,8 @@ hash_behaviour = merge
|
||||
host_key_checking = False
|
||||
#callback_whitelist = profile_tasks
|
||||
display_skipped_hosts = False
|
||||
stdout_callback = yaml
|
||||
bin_ansible_callbacks = True
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
||||
|
||||
@@ -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: staging
|
||||
deploy_repo_version: develop
|
||||
deploy_npm: yes
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
remote_src: true
|
||||
|
||||
- name: "Gulp build"
|
||||
command: "/usr/local/lib/npm/bin/gulp default"
|
||||
command: "/usr/local/lib/npm/bin/gulp default --host shmyga.ru"
|
||||
args:
|
||||
chdir: "{{ deploy_release_dir }}"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
104
gulpfile.js
104
gulpfile.js
@@ -1,14 +1,12 @@
|
||||
"use strict";
|
||||
const gulp = require('gulp');
|
||||
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 = '31';
|
||||
if (Config.SdkDir) {
|
||||
Sdk.dir = Config.SdkDir;
|
||||
}
|
||||
@@ -26,9 +24,7 @@ exports.generate = function generate() {
|
||||
};
|
||||
|
||||
/**
|
||||
* ToDo:
|
||||
* windows target
|
||||
* window exe package (innosetup)
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
@@ -46,14 +42,19 @@ const config = new Project.Config({
|
||||
'src-gen/haxe',
|
||||
],
|
||||
assets: [
|
||||
'src/common/resources'
|
||||
'src/common/resources',
|
||||
],
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
],
|
||||
macros: [
|
||||
//'yield.parser.Parser.auto()', // ToDo: bug with extraParams.hxml in yield library
|
||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||
]
|
||||
});
|
||||
|
||||
const host = argv.host || 'localhost';
|
||||
const port = argv.port || 5000;
|
||||
|
||||
/**
|
||||
* client
|
||||
*/
|
||||
@@ -63,24 +64,35 @@ 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',
|
||||
assets: ['src/client/resources'],
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
'src/client/resources',
|
||||
],
|
||||
meta: {
|
||||
width: 1024,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
//'dom',
|
||||
//'dev_layout',
|
||||
//'bitmap_text',
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('host','${host}')`,
|
||||
`CompilationOption.set('port',${port})`,
|
||||
]
|
||||
}),
|
||||
module.exports.generate
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
@@ -88,16 +100,27 @@ const client = new Project(
|
||||
*/
|
||||
const editor = new Project(
|
||||
Project.BuildSystem.OPENFL,
|
||||
Project.Platform.FLASH,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
],
|
||||
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',
|
||||
assets: ['src/client/resources'],
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
'src/client/resources',
|
||||
'src/editor/resources',
|
||||
],
|
||||
meta: {
|
||||
filename: 'editor',
|
||||
width: 1024,
|
||||
height: 800,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'dev_layout',
|
||||
@@ -115,20 +138,51 @@ const server = new Project(
|
||||
name: 'server',
|
||||
sources: ['src/server/haxe'],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
})
|
||||
}),
|
||||
).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.generate,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:html5:build'],
|
||||
module.exports['client:linux:build'],
|
||||
//module.exports['client:android:build'],
|
||||
module.exports['editor:flash:build'],
|
||||
//module.exports['server:neko:build'],
|
||||
module.exports['client:flash:html'],
|
||||
module.exports['client:linux:deb'],
|
||||
module.exports['client:html5: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);
|
||||
|
||||
7863
package-lock.json
generated
7863
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@@ -1,25 +1,25 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.8.3",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "^0.0.16"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||
"lime": "7.2.1",
|
||||
"openfl": "8.8.0",
|
||||
"hxcpp": "4.0.8",
|
||||
"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"
|
||||
}
|
||||
"name": "tankz",
|
||||
"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-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.52",
|
||||
"promhx": "1.1.0",
|
||||
"protohx": "0.4.6",
|
||||
"yaml": "1.3.0",
|
||||
"orm": "2.1.0",
|
||||
"haxe-crypto": "0.0.7",
|
||||
"svg": "1.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"protoFiles": [
|
||||
"src/common/proto/core.proto",
|
||||
"src/common/proto/game.proto",
|
||||
"src/common/proto/room.proto",
|
||||
"src/common/proto/pack.proto"
|
||||
],
|
||||
"cleanOut": true,
|
||||
|
||||
BIN
resources/11756.png
Normal file
BIN
resources/11756.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
resources/60016.png
Normal file
BIN
resources/60016.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
@@ -0,0 +1,43 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.control.IControlBus;
|
||||
|
||||
class ControlBus implements IControlBus {
|
||||
|
||||
private static inline var TAG = "control";
|
||||
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
|
||||
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
||||
|
||||
public function new() {
|
||||
devices = [];
|
||||
signal = new Signal3();
|
||||
devicesSignal = new Signal();
|
||||
connections = new Map();
|
||||
}
|
||||
|
||||
public function connect(device:IControlDevice):Void {
|
||||
var connector = function(action:DeviceAction, on:Bool):Void {
|
||||
//L.d("TAG", '${device.type}, ${action}, ${on}');
|
||||
signal.emit(device.type, action, on);
|
||||
}
|
||||
connections.set(device.type, connector);
|
||||
device.signal.connect(connector);
|
||||
devices.push(device);
|
||||
devicesSignal.emit(devices);
|
||||
}
|
||||
|
||||
public function disconnect(device:IControlDevice):Void {
|
||||
if (connections.exists(device.type)) {
|
||||
device.signal.disconnect(connections.get(device.type));
|
||||
connections.remove(device.type);
|
||||
devices.remove(device);
|
||||
devicesSignal.emit(devices);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
enum DeviceAction {
|
||||
DIRECTION(direction:Direction);
|
||||
KEY(code:Int);
|
||||
}
|
||||
8
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
|
||||
interface IControlBus {
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
|
||||
public function connect(device:IControlDevice):Void;
|
||||
public function disconnect(device:IControlDevice):Void;
|
||||
}
|
||||
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
|
||||
interface IControlDevice {
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public function dispose():Void;
|
||||
}
|
||||
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
@@ -0,0 +1,62 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import lime.ui.Joystick;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
class JoystickDevice implements IControlDevice {
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
private var joystick:Joystick;
|
||||
private var axisState:Map<Int, Direction>;
|
||||
|
||||
public function new(joystick:Joystick) {
|
||||
this.joystick = joystick;
|
||||
type = GAMEPAD(joystick.id);
|
||||
signal = new Signal2();
|
||||
axisState = new Map();
|
||||
joystick.onButtonDown.add(onButtonDown);
|
||||
joystick.onButtonUp.add(onButtonUp);
|
||||
joystick.onAxisMove.add(onAxisMove);
|
||||
}
|
||||
|
||||
private function onButtonDown(code:Int):Void {
|
||||
signal.emit(KEY(code), true);
|
||||
}
|
||||
|
||||
private function onButtonUp(code:Int):Void {
|
||||
signal.emit(KEY(code), false);
|
||||
}
|
||||
|
||||
private function onAxisMove(axis:Int, position:Float):Void {
|
||||
var direction:Direction = switch [axis, position] {
|
||||
case [0, 1]: Direction.RIGHT;
|
||||
case [0, -1]: Direction.LEFT;
|
||||
case [1, 1]: Direction.BOTTOM;
|
||||
case [1, -1]: Direction.TOP;
|
||||
case _: null;
|
||||
}
|
||||
if (direction != null) {
|
||||
axisState.set(axis, direction);
|
||||
signal.emit(DIRECTION(direction), true);
|
||||
} else if (position == 0) {
|
||||
if (axisState.exists(axis)) {
|
||||
signal.emit(DIRECTION(axisState.get(axis)), false);
|
||||
axisState.remove(axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
if (joystick != null) {
|
||||
joystick.onButtonDown.remove(onButtonDown);
|
||||
joystick.onButtonUp.remove(onButtonUp);
|
||||
joystick.onAxisMove.remove(onAxisMove);
|
||||
joystick = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
@@ -0,0 +1,38 @@
|
||||
package ru.m.control;
|
||||
|
||||
import flash.display.Stage;
|
||||
import flash.events.KeyboardEvent;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.control.DeviceAction;
|
||||
|
||||
class KeyboardDevice implements IControlDevice {
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
private var stage:Stage;
|
||||
|
||||
public function new(stage:Stage) {
|
||||
this.stage = stage;
|
||||
type = DeviceType.KEYBOARD;
|
||||
signal = new Signal2();
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
signal.emit(KEY(event.keyCode), true);
|
||||
}
|
||||
|
||||
private function onKeyUp(event:KeyboardEvent):Void {
|
||||
signal.emit(KEY(event.keyCode), false);
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
if (stage != null) {
|
||||
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
stage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.m.display;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
class DisplayObjectContainerExtender {
|
||||
|
||||
public static function childrenIterator():Iterator<DisplayObject> {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||
if (self.contains(child)) {
|
||||
return self.removeChild(child);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
||||
throw "Not implemented";
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,42 @@
|
||||
package ru.m.skin;
|
||||
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.color.Color;
|
||||
import haxework.gui.ButtonView;
|
||||
import format.SVG;
|
||||
import haxework.gui.skin.ISkin;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.skin.ISkin;
|
||||
|
||||
class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
using StringTools;
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
private var svg:String;
|
||||
private var color:Color;
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
@: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(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||
}
|
||||
|
||||
private function init():Void {
|
||||
svgs = new Map<ButtonState, SVG>();
|
||||
svgs.set(ButtonState.UP, buildSVG(color));
|
||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||
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)));
|
||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
@@ -36,7 +45,10 @@ class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
graphics.lineStyle(2, ColorUtil.multiply(color, 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();
|
||||
graphics.endFill();
|
||||
|
||||
162
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
162
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
@@ -0,0 +1,162 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.text.TextFormatAlign;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.geometry.Box;
|
||||
import haxework.view.geometry.HAlign;
|
||||
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;
|
||||
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
class AppTheme extends Theme {
|
||||
|
||||
public static var COLORS(default, never):ThemeColors = {
|
||||
light: 0x95937D,
|
||||
dark: 0x777564,
|
||||
text: 0xE7E0BB,
|
||||
active: 0xFFFF00,
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super({embed: true}, COLORS);
|
||||
}
|
||||
|
||||
override private function reload():Void {
|
||||
super.reload();
|
||||
register(new Style("light", [
|
||||
"skin.background.color" => colors.light,
|
||||
]));
|
||||
|
||||
register(new Style("dark", [
|
||||
"skin.background.color" => colors.dark,
|
||||
]));
|
||||
|
||||
register(new Style("font", [
|
||||
"_" => null,
|
||||
], ["text"]));
|
||||
|
||||
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,
|
||||
"geometry.padding" => Box.fromArray([50, 8]),
|
||||
"geometry.margin" => Box.fromArray([0, 0, 30, 30]),
|
||||
], ["text"]));
|
||||
|
||||
register(new Style("button.menu", [
|
||||
"font.size" => fontSize.big,
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
"geometry.width" => SizeValue.fromInt(250),
|
||||
"geometry.height" => SizeValue.fromInt(50),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("text.box", [
|
||||
"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.box"]));
|
||||
|
||||
register(new Style("button.level", [
|
||||
"font.size" => fontSize.veryBig,
|
||||
"geometry.width" => SizeValue.fromInt(64),
|
||||
"geometry.height" => SizeValue.fromInt(64),
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("container", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromString("100%"),
|
||||
"layout.hAlign" => HAlign.CENTER,
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["dark"]));
|
||||
|
||||
register(new Style("panel", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.padding" => Box.fromArray([10, 5]),
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["light"]));
|
||||
|
||||
register(new Style("window", [
|
||||
"geometry.padding" => Box.fromFloat(2),
|
||||
], ["dark", "border"]));
|
||||
|
||||
register(new Style("line", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromInt(2),
|
||||
], ["border"]));
|
||||
|
||||
register(new Style("window.close", [
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), colors.light),
|
||||
"geometry.width" => SizeValue.fromInt(36),
|
||||
"geometry.height" => SizeValue.fromInt(36),
|
||||
]));
|
||||
|
||||
register(new Style("icon.tank", [
|
||||
"geometry.width" => SizeValue.fromInt(42),
|
||||
"geometry.height" => SizeValue.fromInt(42),
|
||||
"skin.fillType" => FillType.DEFAULT,
|
||||
]));
|
||||
|
||||
var green:Color = 0x00ff00;
|
||||
var red:Color = 0xff0000;
|
||||
register(new Style("result.winner", [
|
||||
"skin.border.color" => green,
|
||||
], ["light"]));
|
||||
register(new Style("result.loser", [
|
||||
"skin.border.color" => red,
|
||||
], ["light"]));
|
||||
register(new Style("player.winner", [
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.background.color" => green,
|
||||
]));
|
||||
register(new Style("player.loser", [
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.background.color" => red,
|
||||
]));
|
||||
|
||||
registerButton("settings", "cog-solid.svg");
|
||||
registerButton("close", "times-circle-solid.svg");
|
||||
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||
registerButton("prev", "arrow-alt-circle-left-solid.svg");
|
||||
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, 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, 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, solid),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,29 +2,20 @@ package ru.m.tankz;
|
||||
|
||||
import flash.Lib;
|
||||
import haxework.animate.Animate;
|
||||
import ru.m.tankz.frame.StartFrame;
|
||||
import flash.ui.Keyboard;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.text.Font;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.Root;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.log.TraceLogger;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.resources.IResources;
|
||||
#if flash import haxework.log.JSLogger; #end
|
||||
#if debug import haxework.log.SocketLogger; #end
|
||||
import haxework.view.Root;
|
||||
import ru.m.tankz.view.ClientView;
|
||||
|
||||
class Client {
|
||||
private static inline var TAG = 'Tankz';
|
||||
private static inline var TAG = "Tankz";
|
||||
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
#if flash
|
||||
L.push(new JSLogger());
|
||||
L.push(new haxework.log.JSLogger());
|
||||
#end
|
||||
#if debug
|
||||
//L.push(new SocketLogger());
|
||||
//L.push(new haxework.log.SocketLogger());
|
||||
#end
|
||||
Const.init();
|
||||
Init.init();
|
||||
@@ -32,33 +23,16 @@ class Client {
|
||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||
Style.register();
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.launch();
|
||||
}
|
||||
}
|
||||
|
||||
@:template class ClientView extends VGroupView {
|
||||
private static inline var TAG = 'Tankz';
|
||||
|
||||
@:view private var switcher(default, null):FrameSwitcher;
|
||||
@:provide var resources:IResources;
|
||||
|
||||
public function init():Void {
|
||||
var font:Font = Font.enumerateFonts()[0];
|
||||
resources.text.put('font', 'Bookman Old Style');
|
||||
resources.text.put('version', 'v${Const.VERSION} (${Const.BUILD})');
|
||||
Provider.set(FrameSwitcher, switcher);
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
content.stage.stageFocusRect = false;
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||
if (event.keyCode == Keyboard.ESCAPE) {
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
});
|
||||
switcher.change(StartFrame.ID);
|
||||
|
||||
#if debug
|
||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||
Lib.current.addChild(fps);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
---
|
||||
$type: haxework.gui.VGroupView
|
||||
geometry.size.stretch: true
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
skinId: light
|
||||
views:
|
||||
- id: switcher
|
||||
$type: haxework.gui.frame.FrameSwitcher
|
||||
skinId: dark
|
||||
geometry.size.stretch: true
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: start
|
||||
$type: ru.m.tankz.frame.StartFrame
|
||||
# classic
|
||||
- id: classic.level
|
||||
$type: ru.m.tankz.frame.classic.ClassicLevelFrame
|
||||
- id: classic.game
|
||||
$type: ru.m.tankz.frame.classic.ClassicGameFrame
|
||||
# dota
|
||||
- id: dota.level
|
||||
$type: ru.m.tankz.frame.dota.DotaLevelFrame
|
||||
- id: dota.game
|
||||
$type: ru.m.tankz.frame.dota.DotaGameFrame
|
||||
# - id: network
|
||||
# $type: ru.m.tankz.frame.NetworkFrame
|
||||
- id: settings
|
||||
$type: ru.m.tankz.frame.SettingsFrame
|
||||
@@ -3,17 +3,16 @@ package ru.m.tankz;
|
||||
import flash.Lib;
|
||||
import flash.system.Capabilities;
|
||||
|
||||
|
||||
class Const {
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
public static var VERSION:String;
|
||||
public static var DEBUG:Bool;
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
public static var VERSION:String;
|
||||
public static var DEBUG:Bool;
|
||||
|
||||
public static function init():Void {
|
||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||
BUILD = CompilationOption.get("build");
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
public static function init():Void {
|
||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||
BUILD = CompilationOption.get("build");
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,101 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import haxework.provider.Provider;
|
||||
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;
|
||||
import ru.m.control.ControlBus;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.control.JoystickDevice;
|
||||
import ru.m.control.KeyboardDevice;
|
||||
import ru.m.tankz.bundle.ConfigBundle;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.bundle.LevelBundle;
|
||||
import ru.m.tankz.control.ClientControlFactory;
|
||||
import ru.m.tankz.control.IControlFactory;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.UserStorage;
|
||||
#if flash
|
||||
import flash.Lib;
|
||||
#elseif html5
|
||||
import js.Browser;
|
||||
#end
|
||||
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
class Init {
|
||||
|
||||
private static function getHost():String {
|
||||
@:provide static var theme:ITheme;
|
||||
@:provide static var resources:IResources;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var settingsStorage:SettingsStorage;
|
||||
@:provide static var multiplayerStorage:NetworkStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var networkManager:NetworkManager;
|
||||
@: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");
|
||||
var port:Int = CompilationOption.get("port");
|
||||
L.d("Init", 'connect to $host:$port');
|
||||
#if flash
|
||||
var url = Lib.current.loaderInfo.url;
|
||||
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
|
||||
if (r.match(url) && !(r.matched(1) == "app")) {
|
||||
return r.matched(2);
|
||||
} else {
|
||||
return "localhost";
|
||||
}
|
||||
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||
#elseif html5
|
||||
return Browser.location.hostname;
|
||||
return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||
#else
|
||||
return "localhost";
|
||||
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||
#end
|
||||
}
|
||||
|
||||
public static function init():Void {
|
||||
Provider.setFactory(IResources, Resources);
|
||||
Provider.setFactory(ILevelBundle, LevelBundle);
|
||||
Provider.setFactory(IConfigBundle, ConfigBundle);
|
||||
Provider.setFactory(UserStorage, UserStorage);
|
||||
Provider.setFactory(SettingsStorage, SettingsStorage);
|
||||
Provider.setFactory(SoundManager, SoundManager);
|
||||
Provider.setFactory(NetworkManager, NetworkManager);
|
||||
Provider.setFactory(IControlFactory, ClientControlFactory);
|
||||
theme = new AppTheme();
|
||||
resources = new Resources();
|
||||
levelBundle = new LevelBundle();
|
||||
configBundle = new ConfigBundle();
|
||||
settingsStorage = new SettingsStorage();
|
||||
multiplayerStorage = new NetworkStorage();
|
||||
gameStorage = new GameStorage();
|
||||
recordStorage = new RecordStorage();
|
||||
soundManager = new SoundManager();
|
||||
popupManager = new PopupManager();
|
||||
|
||||
var host:String = getHost();
|
||||
L.d('Init', 'host: ${host}');
|
||||
#if flash
|
||||
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response));
|
||||
#elseif html5
|
||||
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response));
|
||||
#else
|
||||
Provider.set(IConnection, new ru.m.connect.fake.FakeConnection<Request, Response>(Response));
|
||||
#end
|
||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||
|
||||
connection = buildConnection();
|
||||
networkManager = new NetworkManager();
|
||||
|
||||
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);
|
||||
}
|
||||
Gamepad.onConnect.add(function(device) {
|
||||
trace('connect gamepad', device);
|
||||
});
|
||||
|
||||
for (device in Joystick.devices) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
}
|
||||
Joystick.onConnect.add(function(device) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
@@ -0,0 +1,27 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.filters.ColorMatrixFilter;
|
||||
import flash.geom.Point;
|
||||
import flash.Lib;
|
||||
import openfl.Assets;
|
||||
|
||||
class LinuxIcon {
|
||||
|
||||
private static function prepareIcon(bitmap:BitmapData):BitmapData {
|
||||
var matrix:Array<Float> = [];
|
||||
matrix = matrix.concat([0, 0, 1, 0, 0]);
|
||||
matrix = matrix.concat([0, 1, 0, 0, 0]);
|
||||
matrix = matrix.concat([1, 0, 0, 0, 0]);
|
||||
matrix = matrix.concat([0, 0, 0, 1, 0]);
|
||||
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
|
||||
var bitmap:BitmapData = bitmap.clone();
|
||||
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static function apply() {
|
||||
var icon = Assets.getBitmapData("resources/icon.png");
|
||||
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
|
||||
}
|
||||
}
|
||||
142
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
142
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
@@ -0,0 +1,142 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.Lib;
|
||||
import haxework.view.geometry.Size;
|
||||
import ru.m.tankz.AppTheme;
|
||||
|
||||
class Progress extends Sprite {
|
||||
|
||||
public var color(default, set):Int = 0;
|
||||
public var backColor(default, set):Int = 0;
|
||||
public var progress(default, set):Float = 0;
|
||||
public var size(default, set):Size = [0, 0];
|
||||
public var radius(get, null):Float;
|
||||
|
||||
private var maskShape:Shape;
|
||||
private var toRedraw:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
maskShape = new Shape();
|
||||
addChild(maskShape);
|
||||
mask = maskShape;
|
||||
}
|
||||
|
||||
private inline function get_radius():Float {
|
||||
return Math.min(size.width, size.height) / 2;
|
||||
}
|
||||
|
||||
private function set_color(value:Int):Int {
|
||||
if (color != value) {
|
||||
color = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_backColor(value:Int):Int {
|
||||
if (backColor != value) {
|
||||
backColor = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_progress(value:Float):Float {
|
||||
if (progress != value) {
|
||||
progress = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
private function set_size(value:Size):Size {
|
||||
if (size != value) {
|
||||
size = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (toRedraw) {
|
||||
redraw();
|
||||
redrawMask();
|
||||
toRedraw = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
graphics.clear();
|
||||
graphics.beginFill(color);
|
||||
graphics.drawCircle(radius, radius, radius);
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawCircle(radius, radius, radius / 2);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
public function redrawMask():Void {
|
||||
maskShape.graphics.clear();
|
||||
maskShape.graphics.beginFill(0x00ff00);
|
||||
maskShape.graphics.moveTo(radius, radius);
|
||||
var sides = 6;
|
||||
var rotation = (-(Math.PI) / 2);
|
||||
var r = radius / Math.cos(1/sides * Math.PI);
|
||||
var lineToRadians = function(rads:Float):Void {
|
||||
maskShape.graphics.lineTo(Math.cos(rads) * r + radius, Math.sin(rads) * r + radius);
|
||||
};
|
||||
var sidesToDraw:Int = Math.floor(progress * sides);
|
||||
for (i in 0...sidesToDraw + 1) {
|
||||
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
|
||||
}
|
||||
if (progress * sides != sidesToDraw) {
|
||||
lineToRadians(progress * (Math.PI * 2) + rotation);
|
||||
}
|
||||
maskShape.graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
class Preloader extends Sprite {
|
||||
|
||||
private var progress:Progress;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
Lib.current.stage.color = AppTheme.COLORS.light;
|
||||
progress = new Progress();
|
||||
progress.color = AppTheme.COLORS.dark;
|
||||
progress.backColor = AppTheme.COLORS.light;
|
||||
progress.size = [200, 200];
|
||||
addChild(progress);
|
||||
onResize(null);
|
||||
Lib.current.stage.addEventListener(Event.RESIZE, onResize);
|
||||
Lib.current.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
Lib.current.stage.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
addEventListener(Event.COMPLETE, onComplete);
|
||||
}
|
||||
|
||||
private function onResize(event:Event):Void {
|
||||
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
|
||||
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
progress.update();
|
||||
}
|
||||
|
||||
private function onProgress(event:ProgressEvent):Void {
|
||||
progress.progress = event.bytesLoaded / event.bytesTotal;
|
||||
}
|
||||
|
||||
private function onComplete(event:Event):Void {
|
||||
progress.update();
|
||||
Lib.current.stage.removeEventListener(Event.RESIZE, onResize);
|
||||
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
Lib.current.stage.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
removeEventListener(Event.COMPLETE, onComplete);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.gui.skin.Skin;
|
||||
import haxework.resources.IResources;
|
||||
import openfl.Assets;
|
||||
import ru.m.skin.ButtonSVGSkin;
|
||||
|
||||
class Style {
|
||||
|
||||
@:provide private static var resources:IResources;
|
||||
|
||||
private static var lightColor = 0x95937D;
|
||||
private static var darkColor = 0x777564;
|
||||
private static var textColor = 0xE7E0BB;
|
||||
private static var fontFamily = "Courirer New";
|
||||
|
||||
public static function register() {
|
||||
resources.skin.put("light", [
|
||||
Skin.color(lightColor),
|
||||
]);
|
||||
resources.skin.put("dark", [
|
||||
Skin.color(darkColor),
|
||||
]);
|
||||
resources.skin.put("text", [
|
||||
Skin.text(textColor, 16, fontFamily),
|
||||
]);
|
||||
resources.skin.put("text.header", [
|
||||
Skin.color(lightColor),
|
||||
Skin.text(textColor, 22, fontFamily),
|
||||
Skin.size(200, 38),
|
||||
]);
|
||||
resources.skin.put("button", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, 18, fontFamily),
|
||||
Skin.size(250, 50)
|
||||
]);
|
||||
resources.skin.put("text.box", [
|
||||
Skin.color(lightColor),
|
||||
Skin.text(textColor, 16, fontFamily),
|
||||
]);
|
||||
resources.skin.put("text.box.active", [
|
||||
Skin.color(0x55aa55),
|
||||
Skin.text(textColor, 16, fontFamily),
|
||||
]);
|
||||
resources.skin.put("button.simple", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, 16, fontFamily),
|
||||
Skin.size(100, 38),
|
||||
]);
|
||||
resources.skin.put("button.tab", [
|
||||
Skin.tabColor(lightColor),
|
||||
Skin.text(textColor, 16, fontFamily),
|
||||
Skin.size(200, 38),
|
||||
]);
|
||||
resources.skin.put("border", [
|
||||
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
||||
]);
|
||||
resources.skin.put("button.level", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, 24, fontFamily),
|
||||
Skin.size(64, 64),
|
||||
]);
|
||||
|
||||
resources.skin.put("button.settings", [
|
||||
Skin.size(64, 64),
|
||||
new ButtonSVGSkin(Assets.getText("resources/image/icon/cog-solid.svg"), lightColor)
|
||||
]);
|
||||
resources.skin.put("button.close", [
|
||||
Skin.size(64, 64),
|
||||
new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,16 @@ import ru.m.tankz.Type;
|
||||
import yaml.Parser;
|
||||
import yaml.Yaml;
|
||||
|
||||
|
||||
class ConfigBundle implements IConfigBundle {
|
||||
|
||||
private var _cache:Map<GameType, Config> = new Map();
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function get(type:GameType):Config {
|
||||
if (!_cache.exists(type)) {
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses));
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
}
|
||||
return _cache.get(type);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
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;
|
||||
|
||||
|
||||
class LevelBundle implements ILevelBundle {
|
||||
|
||||
public function get(type:GameType, config:Config, level:Int):LevelConfig {
|
||||
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt');
|
||||
return LevelUtil.loads(config, data);
|
||||
private var _cache:Map<String, LevelPack> = new Map();
|
||||
|
||||
public function new() {}
|
||||
|
||||
private function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('resources/level/${id}.zip');
|
||||
return {
|
||||
id: id,
|
||||
data: LevelUtil.unpack(bytes).map(function(level) {
|
||||
level.packId = id;
|
||||
return level;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
public function get(id:PackId):LevelPack {
|
||||
if (!_cache.exists(id)) {
|
||||
_cache.set(id, resolve(id));
|
||||
}
|
||||
return _cache.get(id);
|
||||
}
|
||||
|
||||
public function list():Array<PackId> {
|
||||
var result = [];
|
||||
for (path in Assets.list(AssetType.BINARY)) {
|
||||
if (StringTools.startsWith(path, "resources/level")) {
|
||||
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import haxe.Serializer;
|
||||
import haxe.Unserializer;
|
||||
import ru.m.tankz.control.Control.TankAction;
|
||||
|
||||
typedef ActionItem = {
|
||||
public var action:TankAction;
|
||||
public var key:Int;
|
||||
}
|
||||
|
||||
typedef KeyBinding = Map<Int, TankAction>;
|
||||
|
||||
class ActionConfig {
|
||||
|
||||
public var data(default, null):Array<ActionItem>;
|
||||
|
||||
public function new(data:Array<ActionItem>) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public function asKeyBinding():KeyBinding {
|
||||
var result = new Map<Int, TankAction>();
|
||||
for (item in data) {
|
||||
result[item.key] = item.action;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public function clone():ActionConfig {
|
||||
return loads(dumps());
|
||||
}
|
||||
|
||||
public function dumps():String {
|
||||
return Serializer.run(this);
|
||||
}
|
||||
|
||||
public static function loads(value:String):ActionConfig {
|
||||
return new Unserializer(value).unserialize();
|
||||
}
|
||||
}
|
||||
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
typedef BindAction = {
|
||||
var device:DeviceType;
|
||||
var action:DeviceAction;
|
||||
}
|
||||
|
||||
typedef Binding = Map<TankAction, BindAction>;
|
||||
@@ -1,23 +0,0 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.bot.BotControl;
|
||||
|
||||
|
||||
class ClientControlFactory implements IControlFactory {
|
||||
|
||||
private var humanControlIndex:Int;
|
||||
|
||||
public function new() {
|
||||
humanControlIndex = 0;
|
||||
}
|
||||
|
||||
public function build(id:PlayerId, type:ControlType):Control {
|
||||
return switch (type) {
|
||||
case Control.HUMAN: new HumanControl(id, humanControlIndex++);
|
||||
case Control.BOT: new BotControl(id);
|
||||
case Control.NONE: null;
|
||||
case _: throw 'Unsupported control type: "${type}"';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,98 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import flash.events.FocusEvent;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.Lib;
|
||||
import flash.ui.Keyboard;
|
||||
import haxe.Timer;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
@:provide var settings: SettingsStorage;
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private var keyBinding:KeyBinding;
|
||||
private var moveQueue:Array<Int>;
|
||||
private var shotTimer:Timer;
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
this.keyBinding = settings.read(controlIndex).asKeyBinding();
|
||||
moveQueue = new Array<Int>();
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
||||
var config = storage.getBinding(controlIndex);
|
||||
binding = new Map();
|
||||
for (action in config.keys()) {
|
||||
var bind = config.get(action);
|
||||
if (!binding.exists(bind.device)) {
|
||||
binding.set(bind.device, new Map());
|
||||
}
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
moveQueue = [];
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||
case TankAction.MOVE(direction):
|
||||
if (moveQueue.indexOf(event.keyCode) == -1) {
|
||||
moveQueue.unshift(event.keyCode);
|
||||
updateMove();
|
||||
}
|
||||
case TankAction.SHOT:
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(300);
|
||||
shotTimer.run = shot;
|
||||
shot();
|
||||
}
|
||||
case _:
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (event.keyCode == Keyboard.U) {
|
||||
action(TankAction.UPGRADE);
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
if (binding.exists(device) && binding[device].exists(action)) {
|
||||
toggleAction(binding[device][action], on);
|
||||
}
|
||||
}
|
||||
|
||||
private function onKeyUp(event:KeyboardEvent):Void {
|
||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||
override public function start():Void {
|
||||
super.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
override public function stop():Void {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
moveQueue.remove(event.keyCode);
|
||||
if (on) {
|
||||
if (moveQueue.indexOf(direction) == -1) {
|
||||
moveQueue.unshift(direction);
|
||||
}
|
||||
} else {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (!shotTimers.exists(weapon)) {
|
||||
var timer = new Timer(300);
|
||||
timer.run = shooter(weapon);
|
||||
timer.run();
|
||||
shotTimers.set(weapon, timer);
|
||||
}
|
||||
} else {
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
}
|
||||
case _:
|
||||
case TankAction.STOP:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,17 +103,15 @@ class HumanControl extends Control {
|
||||
|
||||
private function updateMove():Void {
|
||||
if (moveQueue.length == 0) {
|
||||
action(TankAction.STOP);
|
||||
action(STOP);
|
||||
} else {
|
||||
switch (keyBinding.get(moveQueue[0])) {
|
||||
case TankAction.MOVE(direction):
|
||||
action(TankAction.MOVE(direction));
|
||||
case _:
|
||||
}
|
||||
action(MOVE(moveQueue[0]));
|
||||
}
|
||||
}
|
||||
|
||||
private function shot():Void {
|
||||
action(TankAction.SHOT);
|
||||
private function shooter(weapon:Int):Void -> Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.IGroupView;
|
||||
import haxework.gui.InputView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.proto.core.GameInfoProto;
|
||||
import ru.m.tankz.proto.core.GameStateProto;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
|
||||
@:template class NetworkFrame extends VGroupView {
|
||||
public static var ID(default, never):String = "network";
|
||||
|
||||
@:view var frameSwitcher(default, null):IFrameSwitcher;
|
||||
|
||||
@:view var loginFrame(default, null):IGroupView;
|
||||
@:view var stateLabel(default, null):LabelView;
|
||||
@:view var nameInput(default, null):InputView;
|
||||
@:view var loginButton(default, null):ButtonView;
|
||||
|
||||
@:view var gameListFrame(default, null):IGroupView;
|
||||
@:view var createGameButton(default, null):ButtonView;
|
||||
@:view var gameList(default, null):ListView<GameInfoProto>;
|
||||
|
||||
@:view var gameFrame(default, null):IGroupView;
|
||||
@:view var leaveGameButton(default, null):ButtonView;
|
||||
@:view var startGameButton(default, null):ButtonView;
|
||||
@:view var userList(default, null):ListView<UserProto>;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var mainFrameSwitcher:IFrameSwitcher;
|
||||
|
||||
public function init():Void {
|
||||
loginButton.onPress = this;
|
||||
createGameButton.onPress = this;
|
||||
leaveGameButton.onPress = this;
|
||||
startGameButton.onPress = this;
|
||||
gameList.dispatcher.addListener({
|
||||
onListItemClick: function(item:IListItemView<GameInfoProto>):Void {
|
||||
network.joinGame(item.data.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
nameInput.text = network.user.name;
|
||||
onStateChange(network.state);
|
||||
network.stateSignal.connect(onStateChange);
|
||||
}
|
||||
|
||||
private function onStateChange(state:String):Void {
|
||||
loginButton.disabled = !(state == "offline" || state == "error");
|
||||
stateLabel.text = state;
|
||||
if (state == 'online') {
|
||||
gameList.data = [];
|
||||
frameSwitcher.change(gameListFrame.id);
|
||||
network.listGameSignal.connect(onListGame);
|
||||
network.gameSignal.connect(onGame);
|
||||
network.listGame();
|
||||
} else {
|
||||
frameSwitcher.change(loginFrame.id);
|
||||
}
|
||||
}
|
||||
|
||||
private function onListGame(games:Array<GameInfoProto>):Void {
|
||||
gameList.data = games;
|
||||
}
|
||||
|
||||
private function onGame(game:GameInfoProto):Void {
|
||||
if (game != null) {
|
||||
userList.data = game.players;
|
||||
frameSwitcher.change(gameFrame.id);
|
||||
if (game.state == GameStateProto.STARTED) {
|
||||
Provider.set(GameState, new GameState(ClassicGame.TYPE, ClassicGame.PLAYER1));
|
||||
mainFrameSwitcher.change(GameFrame.ID);
|
||||
}
|
||||
} else {
|
||||
frameSwitcher.change(gameListFrame.id);
|
||||
}
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
network.listGameSignal.disconnect(onListGame);
|
||||
network.gameSignal.disconnect(onGame);
|
||||
network.stateSignal.disconnect(onStateChange);
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case 'loginButton':
|
||||
network.login(nameInput.text);
|
||||
case 'createGameButton':
|
||||
network.createGame('classic');
|
||||
case 'leaveGameButton':
|
||||
network.leaveGame();
|
||||
case 'startGameButton':
|
||||
network.startGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
---
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: frameSwitcher
|
||||
$type: haxework.gui.frame.FrameSwitcher
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
# login
|
||||
- id: loginFrame
|
||||
$type: haxework.gui.VGroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: stateLabel
|
||||
$type: haxework.gui.LabelView
|
||||
$style: label
|
||||
text: offline
|
||||
width: 200
|
||||
height: 50
|
||||
- id: nameInput
|
||||
$type: haxework.gui.InputView
|
||||
$style: label
|
||||
width: 200
|
||||
height: 50
|
||||
text: User
|
||||
skin:
|
||||
$type: haxework.gui.skin.ColorSkin
|
||||
color: '#444444'
|
||||
- id: loginButton
|
||||
$type: haxework.gui.ButtonView
|
||||
$style: button
|
||||
text: Login
|
||||
# game list
|
||||
- id: gameListFrame
|
||||
$type: haxework.gui.VGroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: createGameButton
|
||||
$type: haxework.gui.ButtonView
|
||||
$style: button
|
||||
text: Create
|
||||
- id: gameList
|
||||
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.GameInfoProto>
|
||||
factory: "@class:ru.m.tankz.frame.network.GameItemView"
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
paddings: 10
|
||||
scroll:
|
||||
$type: haxework.gui.list.VScrollView
|
||||
width: 10
|
||||
pHeight: 100
|
||||
skin:
|
||||
$type: haxework.gui.list.VScrollSkin
|
||||
skin:
|
||||
$type: haxework.gui.skin.ColorSkin
|
||||
color: "#000000"
|
||||
alpha: 0
|
||||
# game
|
||||
- id: gameFrame
|
||||
$type: haxework.gui.VGroupView
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: startGameButton
|
||||
$type: haxework.gui.ButtonView
|
||||
$style: button
|
||||
text: Start
|
||||
- id: leaveGameButton
|
||||
$type: haxework.gui.ButtonView
|
||||
$style: button
|
||||
text: Leave
|
||||
- id: userList
|
||||
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.UserProto>
|
||||
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
paddings: 10
|
||||
scroll:
|
||||
$type: haxework.gui.list.VScrollView
|
||||
width: 10
|
||||
pHeight: 100
|
||||
skin:
|
||||
$type: haxework.gui.list.VScrollSkin
|
||||
skin:
|
||||
$type: haxework.gui.skin.ColorSkin
|
||||
color: "#000000"
|
||||
alpha: 0
|
||||
@@ -1,18 +0,0 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@:template class SettingsFrame extends VGroupView {
|
||||
|
||||
public static var ID(default, never):String = "settings";
|
||||
|
||||
@:provide var frameSwitcher:FrameSwitcher;
|
||||
|
||||
@:view var close:ButtonView;
|
||||
|
||||
public function onPress(_):Void {
|
||||
frameSwitcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
geometry.size.stretch: true
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- $type: haxework.gui.LabelView
|
||||
skinId: text.header
|
||||
text: Settings
|
||||
- $type: haxework.gui.HGroupView
|
||||
layout.margin: 20
|
||||
views:
|
||||
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
||||
controlIndex: 0
|
||||
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
||||
controlIndex: 1
|
||||
- id: close
|
||||
$type: haxework.gui.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $this:onPress
|
||||
geometry.position: absolute
|
||||
geometry.margin: 10
|
||||
geometry.vAlign: bottom
|
||||
geometry.hAlign: left
|
||||
@@ -1,27 +0,0 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import ru.m.tankz.frame.classic.ClassicLevelFrame;
|
||||
import ru.m.tankz.frame.dota.DotaLevelFrame;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
@:template class StartFrame extends VGroupView {
|
||||
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
@:provide var frameSwitcher:FrameSwitcher;
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case 'classic':
|
||||
frameSwitcher.change(ClassicLevelFrame.ID);
|
||||
case 'dota':
|
||||
frameSwitcher.change(DotaLevelFrame.ID);
|
||||
case 'network':
|
||||
//frameSwitcher.change(NetworkFrame.ID);
|
||||
case 'settings':
|
||||
frameSwitcher.change(SettingsFrame.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
---
|
||||
geometry.size.stretch: true
|
||||
layout.hAlign: center
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- $type: haxework.gui.ImageView
|
||||
image: $asset:image:resources/image/ui/logo.png
|
||||
geometry.margin.bottom: 15
|
||||
- $type: haxework.gui.VGroupView
|
||||
layout.margin: 3
|
||||
views:
|
||||
- id: classic
|
||||
$type: haxework.gui.ButtonView
|
||||
skinId: button
|
||||
+onPress: $this:onPress
|
||||
text: Classic
|
||||
- id: dota
|
||||
$type: haxework.gui.ButtonView
|
||||
skinId: button
|
||||
+onPress: $this:onPress
|
||||
text: DotA
|
||||
- id: network
|
||||
$type: haxework.gui.ButtonView
|
||||
skinId: button
|
||||
+onPress: $this:onPress
|
||||
text: Network (in developing)
|
||||
fontColor: 0xff0000
|
||||
visible: false
|
||||
- $type: haxework.gui.LabelView
|
||||
skinId: text
|
||||
geometry.position: absolute
|
||||
geometry.margin: 10
|
||||
geometry.vAlign: bottom
|
||||
geometry.hAlign: right
|
||||
text: $r:text:version
|
||||
- id: settings
|
||||
$type: haxework.gui.ButtonView
|
||||
geometry.position: absolute
|
||||
geometry.margin: 10
|
||||
geometry.vAlign: bottom
|
||||
geometry.hAlign: left
|
||||
skinId: button.settings
|
||||
+onPress: $this:onPress
|
||||
@@ -1,20 +0,0 @@
|
||||
package ru.m.tankz.frame.classic;
|
||||
|
||||
import ru.m.tankz.frame.common.IGamePanel;
|
||||
import ru.m.tankz.render.Render;
|
||||
import ru.m.tankz.frame.common.GameFrame;
|
||||
|
||||
@:template class ClassicGameFrame extends GameFrame {
|
||||
public static inline var ID = "classic.game";
|
||||
|
||||
@:view("render") private var renderView(default, null):Render;
|
||||
@:view("panel") private var panelView(default, null):IGamePanel;
|
||||
|
||||
override private function get_render():Render {
|
||||
return renderView;
|
||||
}
|
||||
|
||||
override private function get_panel():IGamePanel {
|
||||
return panelView;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
layout:
|
||||
$type: haxework.gui.layout.HorizontalLayout
|
||||
margin: 5
|
||||
hAlign: center
|
||||
vAlign: middle
|
||||
views:
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
- id: panel
|
||||
$type: ru.m.tankz.frame.classic.ClassicGamePanel
|
||||
@@ -1,39 +0,0 @@
|
||||
package ru.m.tankz.frame.classic;
|
||||
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.VGroupView;
|
||||
import ru.m.tankz.frame.common.IGamePanel;
|
||||
import ru.m.tankz.frame.common.LifeView;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
|
||||
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
|
||||
|
||||
@:view var bot:LifeView;
|
||||
@:view var player1:LifeView;
|
||||
@:view var player2:LifeView;
|
||||
@:view var level:LabelView;
|
||||
|
||||
public var game:Game;
|
||||
|
||||
private function updateViews():Void {
|
||||
level.text = 'Level: ${game.state.level}';
|
||||
bot.live = game.teams[ClassicGame.BOT].life;
|
||||
player1.live = game.teams[ClassicGame.HUMAN].players[0].state.life;
|
||||
player1.score = game.teams[ClassicGame.HUMAN].players[0].state.score;
|
||||
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
|
||||
player2.visible = true;
|
||||
player2.live = game.teams[ClassicGame.HUMAN].players[1].state.life;
|
||||
player2.score = game.teams[ClassicGame.HUMAN].players[1].state.score;
|
||||
} else {
|
||||
player2.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
if (game != null) {
|
||||
updateViews();
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: right
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.padding: [20, 0]
|
||||
geometry.hAlign: center
|
||||
- $type: haxework.gui.SpriteView
|
||||
geometry.size.height: 50%
|
||||
- id: bot
|
||||
$type: ru.m.tankz.frame.common.LifeView
|
||||
tank: ba
|
||||
scoreLabel.visible: false
|
||||
- id: player1
|
||||
$type: ru.m.tankz.frame.common.LifeView
|
||||
tank: pa
|
||||
color: 0xFFFF00
|
||||
- id: player2
|
||||
$type: ru.m.tankz.frame.common.LifeView
|
||||
tank: pa
|
||||
color: 0x15C040
|
||||
@@ -1,52 +0,0 @@
|
||||
package ru.m.tankz.frame.classic;
|
||||
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.DataView;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.ToggleButtonView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.frame.common.LevelFrame;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
|
||||
@:template class ClassicLevelFrame extends LevelFrame {
|
||||
public static inline var ID = "classic.level";
|
||||
|
||||
@:view var presets(default, null):DataView<GamePreset, ToggleButtonView>;
|
||||
@:view var levels(default, null):DataView<Int, ButtonView>;
|
||||
|
||||
@:provide var frames:FrameSwitcher;
|
||||
|
||||
private function onShow():Void {
|
||||
gameType = ClassicGame.TYPE;
|
||||
levels.data = [for (i in 0...config.game.levels) i];
|
||||
presets.data = config.presets;
|
||||
setSelectedPreset(preset);
|
||||
}
|
||||
|
||||
private function setSelectedPreset(preset:GamePreset) {
|
||||
for (view in presets.views) {
|
||||
cast(view, ToggleButtonView).on = view.id == preset.id;
|
||||
}
|
||||
}
|
||||
|
||||
private function presetViewFactory(index:Int, preset:GamePreset):ToggleButtonView {
|
||||
var view = new ToggleButtonView();
|
||||
view.id = preset.id;
|
||||
view.text = '${preset.id}';
|
||||
resources.skin.bind("button.simple", view, "skin");
|
||||
return view;
|
||||
}
|
||||
|
||||
override private function set_preset(value:GamePreset):GamePreset {
|
||||
var result = super.set_preset(value);
|
||||
setSelectedPreset(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
override private function set_level(value:Int):Int {
|
||||
var result = super.set_level(value);
|
||||
frames.change(ClassicGameFrame.ID);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
layout:
|
||||
$type: haxework.gui.layout.VerticalLayout
|
||||
hAlign: center
|
||||
views:
|
||||
- $type: haxework.gui.LabelView
|
||||
skinId: text.header
|
||||
text: Classic
|
||||
- id: presets
|
||||
$type: haxework.gui.DataView
|
||||
layout:
|
||||
$type: haxework.gui.layout.HorizontalLayout
|
||||
hAlign: center
|
||||
margin: 2
|
||||
factory: $this:presetViewFactory
|
||||
+onDataSelect: $code:function(value) preset = value
|
||||
geometry.padding: 10
|
||||
- id: levels
|
||||
$type: haxework.gui.DataView
|
||||
layout:
|
||||
$type: haxework.gui.layout.TailLayout
|
||||
rowSize: 10
|
||||
margin: 5
|
||||
factory: $this:levelViewFactory
|
||||
+onDataSelect: $code:function(value) level = value
|
||||
geometry.padding: 10
|
||||
@@ -1,93 +0,0 @@
|
||||
package ru.m.tankz.frame.common;
|
||||
|
||||
import ru.m.tankz.game.GameState;
|
||||
import flash.events.Event;
|
||||
import haxe.ds.Option;
|
||||
import haxe.Timer;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.GroupView;
|
||||
import ru.m.tankz.frame.common.IGamePanel;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.render.Render;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
|
||||
class GameFrame extends GroupView {
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
private var render(get, null):Render;
|
||||
private var panel(get, null):IGamePanel;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var sound:SoundManager;
|
||||
@:provide var state:GameState;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
private var game:Game;
|
||||
private var timer:Timer;
|
||||
|
||||
private function get_render():Render {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
private function get_panel():IGamePanel {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
start(state);
|
||||
}
|
||||
|
||||
private function start(state:GameState):Void {
|
||||
game = new Game(state.type);
|
||||
game.engine.connect(render);
|
||||
game.engine.connect(sound);
|
||||
game.start(state).then(onGameStateChange).endThen(onGameComplete);
|
||||
timer = new Timer(10);
|
||||
timer.run = updateEngine;
|
||||
panel.game = game;
|
||||
content.addEventListener(Event.ENTER_FRAME, _redraw);
|
||||
render.draw(game.engine);
|
||||
sound.play('start');
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
timer = null;
|
||||
}
|
||||
content.removeEventListener(Event.ENTER_FRAME, _redraw);
|
||||
if (game != null) {
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
render.reset();
|
||||
}
|
||||
|
||||
private function onGameStateChange(_):Void {
|
||||
panel.toUpdate();
|
||||
}
|
||||
|
||||
private function onGameComplete(_):Void {
|
||||
switch (game.next()) {
|
||||
case Option.Some(s):
|
||||
stop();
|
||||
start(s);
|
||||
case Option.None:
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
stop();
|
||||
}
|
||||
|
||||
private function updateEngine():Void {
|
||||
game.engine.update();
|
||||
}
|
||||
|
||||
private function _redraw(_):Void {
|
||||
render.draw(game.engine);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package ru.m.tankz.frame.common;
|
||||
|
||||
import ru.m.tankz.game.Game;
|
||||
import haxework.gui.IView;
|
||||
|
||||
interface IGamePanel extends IView<Dynamic> {
|
||||
public var game:Game;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package ru.m.tankz.frame.common;
|
||||
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.GroupView;
|
||||
import haxework.resources.IResources;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LevelFrame extends GroupView {
|
||||
|
||||
public var gameType(default, set):GameType;
|
||||
public var preset(default, set):GamePreset;
|
||||
public var level(default, set):Int;
|
||||
private var config(default, null):Config;
|
||||
|
||||
@:provide var configBundle:IConfigBundle;
|
||||
@:provide var state:GameState;
|
||||
@:provide var resources:IResources;
|
||||
|
||||
private function set_gameType(value:GameType):GameType {
|
||||
if (gameType != value || true) { // ToDo:
|
||||
gameType = value;
|
||||
config = configBundle.get(gameType);
|
||||
preset = config.presets[0];
|
||||
}
|
||||
return gameType;
|
||||
}
|
||||
|
||||
private function set_preset(value:GamePreset):GamePreset {
|
||||
if (preset != value || true) { // ToDo:
|
||||
preset = value;
|
||||
state = new GameState(gameType, preset.id);
|
||||
for (team in value.teams) {
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
state.players.push(new PlayerState(playerId, player.control, player.life));
|
||||
}
|
||||
}
|
||||
}
|
||||
return preset;
|
||||
}
|
||||
|
||||
private function set_level(value:Int):Int {
|
||||
state.level = value;
|
||||
return state.level;
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, level:Int):ButtonView {
|
||||
var view = new ButtonView();
|
||||
view.text = '${level}';
|
||||
resources.skin.bind("button.level", view, "skin");
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package ru.m.tankz.frame.common;
|
||||
|
||||
import openfl.Assets;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.ImageView;
|
||||
import haxework.gui.HGroupView;
|
||||
|
||||
@:template class LifeView extends HGroupView {
|
||||
@:view("tank") public var tankImage:ImageView;
|
||||
@:view("live") public var liveLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
public var tank(null, set):String;
|
||||
public var color(null, set):Int;
|
||||
public var live(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
|
||||
private inline function set_tank(value:String):String {
|
||||
tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png');
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_color(value:Int):Int {
|
||||
tankImage.color = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_live(value:Int):Int {
|
||||
liveLabel.text = 'x${value}';
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_score(value:Int):Int {
|
||||
scoreLabel.text = '${value}$';
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: tank
|
||||
$type: haxework.gui.ImageView
|
||||
- id: live
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
- id: score
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [100, 38]
|
||||
@@ -1,105 +0,0 @@
|
||||
package ru.m.tankz.frame.common;
|
||||
|
||||
import ru.m.tankz.control.Control;
|
||||
import haxework.gui.DataView;
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.skin.ISkin;
|
||||
import haxework.gui.ToggleButtonView;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type.TeamId;
|
||||
|
||||
class TeamButton extends ToggleButtonView {
|
||||
public var team(default, set):TeamId;
|
||||
|
||||
private function set_team(value:TeamId):TeamId {
|
||||
if (team != value) {
|
||||
team = value;
|
||||
text = team.substr(0, 1).toUpperCase() + team.substr(1);
|
||||
}
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
class TeamSkin implements ISkin<TeamButton> {
|
||||
|
||||
public var color(default, default):Int;
|
||||
|
||||
public function new(color:Int) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:TeamButton):Void {
|
||||
view.fontColor = view.on ? 0x000000 : 0xcccccc;
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(view.on ? color : 0x333333);
|
||||
graphics.lineStyle(1, view.on ? 0x333333 : color);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
graphics.lineStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@:template class PlayerView extends HGroupView {
|
||||
private static inline var NONE:TeamId = "none";
|
||||
|
||||
public var item_index(default, set):Int;
|
||||
public var data(default, set):Array<PlayerState>;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
||||
|
||||
@:provide var state:GameState;
|
||||
|
||||
private var player:PlayerState;
|
||||
|
||||
private function teamViewFactory(index:Int, team:TeamId) {
|
||||
var view = new TeamButton();
|
||||
view.skin = [new TeamSkin(getTeamColor(team))];
|
||||
view.geometry.padding = [10, 5];
|
||||
view.team = team;
|
||||
view.on = team == NONE;
|
||||
return view;
|
||||
}
|
||||
|
||||
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
|
||||
data = value;
|
||||
teams.data = [NONE].concat([for (team in state.preset.teams) team.id]);
|
||||
return data;
|
||||
}
|
||||
|
||||
private function getTeamColor(teamId:TeamId):Int {
|
||||
var color = 0xcccccc;
|
||||
for (team in state.preset.teams) {
|
||||
if (team.id == teamId) {
|
||||
if (!team.color.zero) color = team.color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_item_index(value:Int):Int {
|
||||
item_index = value;
|
||||
label.text = 'Player ${item_index}';
|
||||
return item_index;
|
||||
}
|
||||
|
||||
private function onTeamSelect(team:TeamId) {
|
||||
if (player != null) {
|
||||
player.control = Control.BOT;
|
||||
player = null;
|
||||
}
|
||||
for (p in data) {
|
||||
if (p.id.team == team && p.control != Control.HUMAN) {
|
||||
player = p;
|
||||
player.control = Control.HUMAN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (view in teams.views) {
|
||||
var button = cast(view, TeamButton);
|
||||
button.on = team == button.team;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
geometry.margin: 5
|
||||
layout.margin: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text
|
||||
- id: teams
|
||||
$type: haxework.gui.DataView
|
||||
factory: $this:teamViewFactory
|
||||
layout:
|
||||
$type: haxework.gui.layout.HorizontalLayout
|
||||
margin: 3
|
||||
+onDataSelect: $this:onTeamSelect
|
||||
@@ -1,21 +0,0 @@
|
||||
package ru.m.tankz.frame.dota;
|
||||
|
||||
import ru.m.tankz.frame.common.GameFrame;
|
||||
import ru.m.tankz.frame.common.IGamePanel;
|
||||
import ru.m.tankz.render.Render;
|
||||
|
||||
@:template class DotaGameFrame extends GameFrame {
|
||||
|
||||
public static inline var ID = "dota.game";
|
||||
|
||||
@:view("render") private var renderView(default, null):Render;
|
||||
@:view("panel") private var panelView(default, null):IGamePanel;
|
||||
|
||||
override private function get_render():Render {
|
||||
return renderView;
|
||||
}
|
||||
|
||||
override private function get_panel():IGamePanel {
|
||||
return panelView;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
layout:
|
||||
$type: haxework.gui.layout.VerticalLayout
|
||||
margin: 5
|
||||
views:
|
||||
- id: panel
|
||||
$type: ru.m.tankz.frame.dota.DotaGamePanel
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
@@ -1,32 +0,0 @@
|
||||
package ru.m.tankz.frame.dota;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import ru.m.tankz.frame.common.IGamePanel;
|
||||
import ru.m.tankz.frame.common.LifeView;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.preset.DotaGame;
|
||||
|
||||
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
|
||||
|
||||
@:view var radiant:LifeView;
|
||||
@:view var dire:LifeView;
|
||||
@:view var level:LabelView;
|
||||
|
||||
public var game:Game;
|
||||
|
||||
private function updateViews():Void {
|
||||
level.text = 'Level: ${game.state.level}';
|
||||
radiant.live = game.teams[DotaGame.RADIANT].life;
|
||||
radiant.score = game.teams[DotaGame.RADIANT].score;
|
||||
dire.live = game.teams[DotaGame.DIRE].life;
|
||||
dire.score = game.teams[DotaGame.DIRE].score;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
if (game != null) {
|
||||
updateViews();
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
geometry.size.width: 100%
|
||||
layout.margin: 20
|
||||
views:
|
||||
- id: radiant
|
||||
$type: ru.m.tankz.frame.common.LifeView
|
||||
tank: bc
|
||||
color: 0xff4422
|
||||
- $type: haxework.gui.SpriteView
|
||||
geometry.size.width: 50%
|
||||
- id: level
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.padding: [20, 0]
|
||||
- $type: haxework.gui.SpriteView
|
||||
geometry.size.width: 50%
|
||||
- id: dire
|
||||
$type: ru.m.tankz.frame.common.LifeView
|
||||
tank: bc
|
||||
color: 0x3284ff
|
||||
@@ -1,37 +0,0 @@
|
||||
package ru.m.tankz.frame.dota;
|
||||
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.DataView;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import ru.m.tankz.frame.common.LevelFrame;
|
||||
import ru.m.tankz.frame.common.PlayerView;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.preset.DotaGame;
|
||||
|
||||
@:template class DotaLevelFrame extends LevelFrame {
|
||||
public static inline var ID = "dota.level";
|
||||
|
||||
@:view var levels(default, null):DataView<Int, ButtonView>;
|
||||
@:view var players(default, null):DataView<Array<PlayerState>, PlayerView>;
|
||||
|
||||
@:provide var frames:FrameSwitcher;
|
||||
|
||||
private function onShow():Void {
|
||||
gameType = DotaGame.TYPE;
|
||||
levels.data = [for (i in 0...config.game.levels) i];
|
||||
players.data = [for (i in 0...2) state.players];
|
||||
}
|
||||
|
||||
private function playerViewFactory(index:Int, data:Array<PlayerState>):PlayerView {
|
||||
var view = new PlayerView();
|
||||
view.item_index = index;
|
||||
view.data = data;
|
||||
return view;
|
||||
}
|
||||
|
||||
override private function set_level(value:Int):Int {
|
||||
var result = super.set_level(value);
|
||||
frames.change(DotaGameFrame.ID);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
layout:
|
||||
$type: haxework.gui.layout.VerticalLayout
|
||||
hAlign: center
|
||||
views:
|
||||
- $type: haxework.gui.LabelView
|
||||
skinId: text.header
|
||||
text: DotA
|
||||
- id: players
|
||||
$type: haxework.gui.DataView
|
||||
layout:
|
||||
$type: haxework.gui.layout.VerticalLayout
|
||||
hAlign: center
|
||||
factory: $this:playerViewFactory
|
||||
geometry.padding: 10
|
||||
- id: levels
|
||||
$type: haxework.gui.DataView
|
||||
layout:
|
||||
$type: haxework.gui.layout.TailLayout
|
||||
rowSize: 5
|
||||
margin: 5
|
||||
factory: $this:levelViewFactory
|
||||
+onDataSelect: $code:function(value) level = value
|
||||
geometry.padding: 10
|
||||
@@ -1,21 +0,0 @@
|
||||
package ru.m.tankz.frame.network;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import ru.m.tankz.proto.core.GameInfoProto;
|
||||
|
||||
|
||||
@:template class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):GameInfoProto;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
|
||||
private function set_data(value:GameInfoProto):GameInfoProto {
|
||||
data = value;
|
||||
label.text = '${data.type}';
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
width: 440
|
||||
height: 44
|
||||
margins: 5
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.gui.LabelView
|
||||
$style: label
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
text: ""
|
||||
skin:
|
||||
$type: haxework.gui.skin.ColorSkin
|
||||
color: "#000000"
|
||||
alpha: 0.2
|
||||
@@ -1,21 +0,0 @@
|
||||
package ru.m.tankz.frame.network;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
|
||||
@:template class UserItemView extends HGroupView implements IListItemView<UserProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):UserProto;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
|
||||
private function set_data(value:UserProto):UserProto {
|
||||
data = value;
|
||||
label.text = '${data.uuid} -- ${data.name}';
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
---
|
||||
width: 440
|
||||
height: 44
|
||||
margins: 5
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.gui.LabelView
|
||||
$style: label
|
||||
pWidth: 100
|
||||
pHeight: 100
|
||||
text: ""
|
||||
skin:
|
||||
$type: haxework.gui.skin.ColorSkin
|
||||
color: "#000000"
|
||||
alpha: 0.2
|
||||
@@ -1,83 +0,0 @@
|
||||
package ru.m.tankz.frame.settings;
|
||||
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
import openfl.Assets;
|
||||
import openfl.events.KeyboardEvent;
|
||||
import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):ActionItem;
|
||||
|
||||
@:view var action(default, null):LabelView;
|
||||
@:view var key(default, null):LabelView;
|
||||
|
||||
private var editDeferred: Deferred<Int>;
|
||||
|
||||
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 keyLabel(key: Int): String {
|
||||
return KeyboardMap.getName(key);
|
||||
}
|
||||
|
||||
private function set_data(value:ActionItem):ActionItem {
|
||||
data = value;
|
||||
action.text = actionLabel(data.action);
|
||||
key.text = keyLabel(data.key);
|
||||
return data;
|
||||
}
|
||||
|
||||
public function edit():Promise<Int> {
|
||||
action.skinId = key.skinId = "text.box.active";
|
||||
toRedraw();
|
||||
editDeferred = new Deferred();
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
return editDeferred.promise();
|
||||
}
|
||||
|
||||
private function onKeyDown(event: KeyboardEvent):Void {
|
||||
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
action.skinId = key.skinId = "text.box";
|
||||
toRedraw();
|
||||
data.key = event.keyCode;
|
||||
key.text = keyLabel(data.key);
|
||||
editDeferred.resolve(data.key);
|
||||
editDeferred = null;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
geometry.margin: 5
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: action
|
||||
$type: haxework.gui.LabelView
|
||||
geometry.size.fixed: [200, 38]
|
||||
skinId: text.box
|
||||
- id: key
|
||||
$type: haxework.gui.LabelView
|
||||
geometry.size.fixed: [200, 38]
|
||||
skinId: text.box
|
||||
@@ -1,75 +0,0 @@
|
||||
package ru.m.tankz.frame.settings;
|
||||
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.DataView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.VGroupView;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.control.ActionConfig.ActionItem;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
@:template class SettingsEditor extends VGroupView {
|
||||
|
||||
public var controlIndex(default, set): Int;
|
||||
|
||||
@:view var label:LabelView;
|
||||
@:view var list:DataView<ActionItem, ActionView>;
|
||||
@:view var change:ButtonView;
|
||||
@:view var clear:ButtonView;
|
||||
@:view var reset:ButtonView;
|
||||
|
||||
@:provide var storage: SettingsStorage;
|
||||
|
||||
private function set_controlIndex(value: Int): Int {
|
||||
this.controlIndex = value;
|
||||
label.text = 'Player ${controlIndex+1}';
|
||||
list.data = storage.read(controlIndex).data;
|
||||
return this.controlIndex;
|
||||
}
|
||||
|
||||
private function viewFactory(index:Int, value:ActionItem) {
|
||||
var view = new ActionView();
|
||||
view.item_index = index;
|
||||
view.data = value;
|
||||
return view;
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
switch (view.id) {
|
||||
case "change": _change();
|
||||
case "clear": _clear();
|
||||
case "reset": _reset();
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function _change():Void {
|
||||
var p: Promise<Int> = Promise.promise(0);
|
||||
for (view in list.views) {
|
||||
var v: ActionView = cast view;
|
||||
if (v.data == null) break;
|
||||
p = p.pipe(function(_):Promise<Int> return v.edit());
|
||||
}
|
||||
p.then(function(_) _save());
|
||||
}
|
||||
|
||||
private function _clear():Void {
|
||||
for (item in list.data) {
|
||||
item.key = -1;
|
||||
}
|
||||
list.data = list.data;
|
||||
list.toUpdate();
|
||||
_save();
|
||||
}
|
||||
|
||||
private function _reset():Void {
|
||||
list.data = SettingsStorage.getDefault(controlIndex).data;
|
||||
list.toUpdate();
|
||||
_save();
|
||||
}
|
||||
|
||||
private function _save():Void {
|
||||
storage.write(controlIndex, new ActionConfig(list.data));
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
layout.margin: 10
|
||||
layout.hAlign: center
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.gui.LabelView
|
||||
skinId: text
|
||||
- $type: haxework.gui.HGroupView
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: change
|
||||
$type: haxework.gui.ButtonView
|
||||
+onPress: $this:onPress
|
||||
skinId: button.simple
|
||||
text: Change
|
||||
- id: clear
|
||||
$type: haxework.gui.ButtonView
|
||||
+onPress: $this:onPress
|
||||
skinId: button.simple
|
||||
text: Clear
|
||||
- id: reset
|
||||
$type: haxework.gui.ButtonView
|
||||
+onPress: $this:onPress
|
||||
skinId: button.simple
|
||||
text: Reset
|
||||
- id: list
|
||||
$type: haxework.gui.DataView
|
||||
layout:
|
||||
$type: haxework.gui.layout.VerticalLayout
|
||||
factory: $this:viewFactory
|
||||
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
@@ -0,0 +1,11 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
|
||||
enum GameInit {
|
||||
LOCAL(start:Start);
|
||||
NETWORK(network:NetworkManager);
|
||||
RECORD(record:GameRecord);
|
||||
}
|
||||
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalControlFactory extends BaseControlFactory {
|
||||
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new HumanControl(id, index);
|
||||
}
|
||||
}
|
||||
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
@@ -0,0 +1,41 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import ru.m.tankz.local.LocalControlFactory;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalGame extends GameRunner {
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result): updateProgress(result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function updateProgress(result:Result):Void {
|
||||
var complete = false;
|
||||
var humansTeams:Array<TeamId> = [];
|
||||
for (control in controls) {
|
||||
if (Std.is(control, HumanControl) && humansTeams.indexOf(control.playerId.team) == -1) {
|
||||
humansTeams.push(control.playerId.team);
|
||||
}
|
||||
}
|
||||
if (humansTeams.length == 1 && result.winner == humansTeams[0]) {
|
||||
var progress = gameStorage.get(result.level.packId);
|
||||
progress.completeLevel(result.level.id, result.state.presetId);
|
||||
gameStorage.set(progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package ru.m.tankz.control;
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
|
||||
class ClientNetworkControl extends HumanControl {
|
||||
class NetworkControl extends HumanControl {
|
||||
|
||||
@:provide private var network:NetworkManager;
|
||||
|
||||
override public function action(action:TankAction):Void {
|
||||
network.action(action);
|
||||
if (tankId > -1) {
|
||||
network.action(tankId, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
16
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
@@ -0,0 +1,16 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class NetworkControlFactory extends BaseControlFactory {
|
||||
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new NetworkControl(id, index);
|
||||
}
|
||||
|
||||
override private function buildBot(id:PlayerId, type:String):Control {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
@@ -0,0 +1,54 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import haxe.Unserializer;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.network.NetworkControlFactory;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
class NetworkGame extends Game {
|
||||
|
||||
private var network:NetworkManager;
|
||||
|
||||
public function new(network:NetworkManager) {
|
||||
super(network.room.game.type);
|
||||
this.network = network;
|
||||
this.controlFactory = new NetworkControlFactory();
|
||||
network.gameEventSignal.connect(onGameEventProto);
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
}
|
||||
|
||||
private function onGameEventProto(game:GameEventResponse):Void {
|
||||
var time = game.event.time;
|
||||
var eventStr = game.event.event;
|
||||
var event:GameEvent = Unserializer.run(eventStr);
|
||||
gameEventSignal.emit(event);
|
||||
}
|
||||
|
||||
private function onConnectionState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
network.joinGame(network.room.game.id);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
override private function onStart(start:Start):Void {
|
||||
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||
if (slot != null) {
|
||||
start.state.controls.push({playerId: [slot.slot.team, slot.slot.index], controller: HUMAN(0)});
|
||||
}
|
||||
super.onStart(start);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
}
|
||||
@@ -1,157 +1,173 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.proto.game.GameEventProto;
|
||||
import ru.m.tankz.proto.room.SlotProto;
|
||||
import ru.m.tankz.proto.room.SlotRequest;
|
||||
import haxe.Serializer;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.tankz.proto.pack.GameRequest;
|
||||
import ru.m.tankz.proto.core.GameProto;
|
||||
import ru.m.tankz.proto.pack.StartGameRequest;
|
||||
import ru.m.tankz.proto.game.GameChangeProto;
|
||||
import ru.m.tankz.proto.game.GameActionTypeProto;
|
||||
import ru.m.tankz.proto.pack.GameUpdateRequest;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.tankz.proto.core.GameInfoProto;
|
||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.pack.LoginRequest;
|
||||
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||
import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.tankz.storage.UserStorage;
|
||||
|
||||
import ru.m.tankz.proto.room.CreateRequest;
|
||||
import ru.m.tankz.proto.room.JoinRequest;
|
||||
import ru.m.tankz.proto.room.LeaveRequest;
|
||||
import ru.m.tankz.proto.room.RoomListRequest;
|
||||
import ru.m.tankz.proto.room.RoomProto;
|
||||
import ru.m.tankz.proto.room.RoomRequest;
|
||||
import ru.m.tankz.proto.room.StartRequest;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
|
||||
typedef ClientConnection = IConnection<Request, Response>;
|
||||
|
||||
enum ConnectionState {
|
||||
OFFLINE;
|
||||
CONNECT;
|
||||
CONNECTED;
|
||||
LOGIN;
|
||||
ONLINE(user:User);
|
||||
ERROR(error:Dynamic);
|
||||
}
|
||||
|
||||
class NetworkManager {
|
||||
|
||||
public var state(default, null):String;
|
||||
public var stateSignal:Signal<String>;
|
||||
public var listGameSignal:Signal<Array<GameInfoProto>>;
|
||||
public var gameSignal:Signal<GameInfoProto>;
|
||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
||||
public var user(default, null):User;
|
||||
public var game(default, set):NetworkGame;
|
||||
public var state(default, null):ConnectionState;
|
||||
public var room(default, null):RoomProto;
|
||||
public var user(default, null):UserProto;
|
||||
|
||||
public var stateSignal:Signal<ConnectionState>;
|
||||
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||
public var roomSignal:Signal<RoomProto>;
|
||||
public var gameEventSignal:Signal<GameEventResponse>;
|
||||
|
||||
@:provide private var connection:ClientConnection;
|
||||
@:provide private var storage:UserStorage;
|
||||
@:provide private var storage:NetworkStorage;
|
||||
|
||||
private var reconnectTimer:Timer;
|
||||
private var reconnectDelay:Int;
|
||||
|
||||
public function new() {
|
||||
stateSignal = new Signal<String>();
|
||||
listGameSignal = new Signal<Array<GameInfoProto>>();
|
||||
gameSignal = new Signal<GameInfoProto>();
|
||||
gameUpdateSignal = new Signal<Array<GameChangeProto>>();
|
||||
updateState('offline');
|
||||
reconnectDelay = 500;
|
||||
stateSignal = new Signal();
|
||||
listRoomSignal = new Signal();
|
||||
roomSignal = new Signal();
|
||||
gameEventSignal = new Signal();
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
user = storage.read();
|
||||
if (user == null) {
|
||||
user = {name: 'User', uuid: null};
|
||||
}
|
||||
//connect(); // ToDo: disable network
|
||||
}
|
||||
|
||||
private function updateState(value:String):Void {
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
state = value;
|
||||
stateSignal.emit(value);
|
||||
}
|
||||
|
||||
public function login(name:String):Void {
|
||||
user.name = name;
|
||||
updateState('connect...');
|
||||
connection.connect().then(function(c:ClientConnection) {
|
||||
updateState('login...');
|
||||
c.send(new Request().setLogin(
|
||||
new LoginRequest()
|
||||
.setUuid(user.uuid)
|
||||
.setName(user.name)
|
||||
));
|
||||
}).catchError(function(_) {});
|
||||
public function login(name:String, uuid:String = null):Void {
|
||||
updateState(LOGIN);
|
||||
connection.send(new Request().setLogin(
|
||||
new LoginRequest()
|
||||
.setUuid(uuid)
|
||||
.setName(name)
|
||||
));
|
||||
}
|
||||
|
||||
public function listGame():Void {
|
||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
||||
public function logout():Void {
|
||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||
}
|
||||
|
||||
public function createGame(type:String):Void {
|
||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type)));
|
||||
public function listGame(subscribe:Bool):Void {
|
||||
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int):Void {
|
||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
||||
public function createGame(type:String, level:Int):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type).setLevel(level))));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||
}
|
||||
|
||||
public function selectSlot(slot:SlotProto):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
||||
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||
}
|
||||
|
||||
public function startGame():Void {
|
||||
connection.send(new Request().setStartGame(new StartGameRequest()));
|
||||
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||
}
|
||||
|
||||
public function action(action:TankAction):Void {
|
||||
var update:GameUpdateRequest = switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
new GameUpdateRequest()
|
||||
.setType(GameActionTypeProto.MOVE)
|
||||
.setDirectionX(direction.x)
|
||||
.setDirectionY(direction.y);
|
||||
case TankAction.STOP:
|
||||
new GameUpdateRequest()
|
||||
.setType(GameActionTypeProto.STOP);
|
||||
case TankAction.SHOT:
|
||||
new GameUpdateRequest()
|
||||
.setType(GameActionTypeProto.SHOT);
|
||||
case _: null;
|
||||
public function action(tankId:Int, action:TankAction):Void {
|
||||
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
|
||||
new GameEventProto().setTime(0).setEvent(
|
||||
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
private function connect():Void {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.stop();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
if (update != null) {
|
||||
connection.send(new Request().setUpdateGame(update));
|
||||
reconnectTimer = null;
|
||||
updateState(CONNECT);
|
||||
connection.connect().catchError(function(error) {});
|
||||
}
|
||||
|
||||
private function reconnect():Void {
|
||||
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||
if (reconnectTimer == null) {
|
||||
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
updateState(switch (event) {
|
||||
case ConnectionEvent.CONNECTED:
|
||||
L.d('Network', '$event');
|
||||
'connected';
|
||||
case ConnectionEvent.DISCONNECTED:
|
||||
L.d('Network', '$event');
|
||||
'offline';
|
||||
case ConnectionEvent.ERROR(error):
|
||||
L.e('Network', '$error', error);
|
||||
'error';
|
||||
updateState(switch event {
|
||||
case CONNECTED: CONNECTED;
|
||||
case DISCONNECTED: OFFLINE;
|
||||
case ERROR(error): ERROR(error);
|
||||
});
|
||||
switch event {
|
||||
case CONNECTED:
|
||||
reconnectDelay = 500;
|
||||
var user = storage.user;
|
||||
if (user != null) {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
case DISCONNECTED | ERROR(_):
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private function onResponse(packet:Response):Void {
|
||||
if (packet.hasLogin()) {
|
||||
user = {
|
||||
uuid: packet.login.user.uuid,
|
||||
name: packet.login.user.name,
|
||||
this.user = packet.login.user;
|
||||
var user = {
|
||||
uuid: this.user.uuid,
|
||||
name: this.user.name,
|
||||
};
|
||||
storage.write(user);
|
||||
updateState('online');
|
||||
storage.user = user;
|
||||
updateState(ONLINE(user));
|
||||
} else if (packet.hasLogout()) {
|
||||
user = null;
|
||||
updateState('connected');
|
||||
} else if (packet.hasListGame()) {
|
||||
listGameSignal.emit(packet.listGame.games);
|
||||
} else if (packet.hasCreateGame()) {
|
||||
gameSignal.emit(packet.createGame.game);
|
||||
} else if (packet.hasJoinGame()) {
|
||||
gameSignal.emit(packet.joinGame.game);
|
||||
} else if (packet.hasLeaveGame()) {
|
||||
gameSignal.emit(null);
|
||||
} else if (packet.hasStartGame()) {
|
||||
gameSignal.emit(packet.startGame.game);
|
||||
} else if (packet.hasUpdateGame()) {
|
||||
gameUpdateSignal.emit(packet.updateGame.changes);
|
||||
} else if (packet.hasGame()) {
|
||||
game.load(packet.game.game);
|
||||
storage.user = null;
|
||||
updateState(CONNECTED);
|
||||
} else if (packet.hasRoomList()) {
|
||||
listRoomSignal.emit(packet.roomList.rooms);
|
||||
} else if (packet.hasRoom()) {
|
||||
room = packet.room.room;
|
||||
roomSignal.emit(room);
|
||||
} else if (packet.hasGameEvent()) {
|
||||
gameEventSignal.emit(packet.gameEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private function set_game(value:NetworkGame):NetworkGame {
|
||||
this.game = value;
|
||||
connection.send(new Request().setGame(new GameRequest()));
|
||||
return this.game;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import haxework.gui.utils.BitmapUtil;
|
||||
import haxework.color.Color;
|
||||
import flash.display.BitmapData;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class AnimateBundle {
|
||||
|
||||
@@ -44,27 +39,4 @@ class AnimateBundle {
|
||||
length: 5
|
||||
})]);
|
||||
}
|
||||
|
||||
public static function tankFrames(tank:Tank):Array<Frame> {
|
||||
var color:Color = switch (tank.hits) {
|
||||
case 1: 0x869C43;
|
||||
case 2: 0xDEAF80;
|
||||
case 3: 0x5EA67A;
|
||||
case _: tank.color;
|
||||
}
|
||||
var colors:Array<Color> = [color, color];
|
||||
if (tank.bonus) {
|
||||
colors[1] = 0xff00aa;
|
||||
}
|
||||
return [for (i in 0...2) ({
|
||||
image: BitmapUtil.colorize(Assets.getBitmapData('resources/image/tank/${tank.config.skin}-${i}.png'), colors[i]),
|
||||
length: 3
|
||||
})];
|
||||
}
|
||||
|
||||
public static function bonusFrames(type:BonusType):Array<Frame> {
|
||||
var image = Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
return [{image: image, length: 15}, {image: empty, length: 15}];
|
||||
}
|
||||
}
|
||||
|
||||
12
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
12
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import haxework.view.IView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
interface IRender extends IView<Dynamic> extends GameListener {
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
public function draw():Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
@@ -3,21 +3,33 @@ package ru.m.tankz.render;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFormat;
|
||||
import flash.events.Event;
|
||||
import haxe.Timer;
|
||||
import haxework.gui.SpriteView;
|
||||
import haxework.provider.Provider;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.view.form.LabelView;
|
||||
import haxework.view.SpriteView;
|
||||
import promhx.Promise;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.render.RenderItem;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.render.item.BonusRenderItem;
|
||||
import ru.m.tankz.render.item.BrickRenderItem;
|
||||
import ru.m.tankz.render.item.BulletRenderItem;
|
||||
import ru.m.tankz.render.item.EagleRenderItem;
|
||||
import ru.m.tankz.render.item.IRenderItem;
|
||||
import ru.m.tankz.render.item.TankRenderItem;
|
||||
import ru.m.tankz.Type;
|
||||
using ru.m.display.DisplayObjectContainerExtender;
|
||||
|
||||
class Render extends SpriteView {
|
||||
class Render extends SpriteView implements IRender {
|
||||
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
@@ -25,8 +37,7 @@ class Render extends SpriteView {
|
||||
private var upLayer:Sprite;
|
||||
private var upperLayer:Sprite;
|
||||
|
||||
private var background:Sprite;
|
||||
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
|
||||
private var items:Map<Int, IRenderItem>;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
@@ -44,154 +55,222 @@ class Render extends SpriteView {
|
||||
reset();
|
||||
}
|
||||
|
||||
private function drawBackground(game:Engine):Void {
|
||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
||||
private function get_mapWidth():Float {
|
||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||
}
|
||||
|
||||
private function get_mapHeight():Float {
|
||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||
}
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
setContentSize(mapWidth, mapHeight);
|
||||
}
|
||||
|
||||
public function draw(game:Engine):Void {
|
||||
for (brick in game.map.bricks) if (brick.config.index > 0) {
|
||||
if (!items.exists(brick.key)) {
|
||||
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
|
||||
case 'ace' | 'bush': new BrickItem(brick);
|
||||
case 'water': new BrickAnimateItem(brick);
|
||||
case 'armor' | 'brick': new BrickBreakingItem(brick);
|
||||
case x: null;
|
||||
};
|
||||
if (item != null) {
|
||||
items[brick.key] = item;
|
||||
if (brick.config.layer > 2) {
|
||||
upLayer.addChild(item.view);
|
||||
} else {
|
||||
groundLayer.addChild(item.view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
}
|
||||
if (background == null) {
|
||||
drawBackground(game);
|
||||
}
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
draw();
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
||||
while (layer.numChildren > 0) {
|
||||
layer.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
for (item in items.iterator()) {
|
||||
item.dispose();
|
||||
}
|
||||
items = new Map();
|
||||
if (background != null) {
|
||||
backgroundLayer.removeChild(background);
|
||||
background = null;
|
||||
}
|
||||
clearLayer(entryLayer);
|
||||
clearLayer(groundLayer);
|
||||
clearLayer(upLayer);
|
||||
clearLayer(upperLayer);
|
||||
}
|
||||
|
||||
public function onSpawn(entity:EntityType):Void {
|
||||
switch(entity) {
|
||||
case EntityType.TANK(tank):
|
||||
var item = new TankItem(tank);
|
||||
items.set(tank.key, item);
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case SPAWN(BRICK(bricks)):
|
||||
drawBackground();
|
||||
for (brick in bricks) {
|
||||
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||
var config = config.getBrick(brick.type);
|
||||
items[brick.id] = item;
|
||||
if (config.layer > 2) {
|
||||
upLayer.addChild(item.view);
|
||||
} else {
|
||||
groundLayer.addChild(item.view);
|
||||
}
|
||||
}
|
||||
case SPAWN(EAGLE(id, rect, teamId)):
|
||||
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playAnimate(tank.rect.center, AnimateBundle.tankSpawn());
|
||||
case EntityType.BULLET(bullet):
|
||||
var item = new BulletItem(bullet);
|
||||
items.set(bullet.key, item);
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
var item = new TankRenderItem(rect);
|
||||
var tankConfig = config.getTank(info.type);
|
||||
item.color = info.color;
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.EAGLE(eagle):
|
||||
var item = new EagleItem(eagle);
|
||||
items.set(eagle.key, item);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, skin)):
|
||||
var item = new BulletRenderItem(rect, skin);
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.BONUS(bonus):
|
||||
var item = new BonusItem(bonus);
|
||||
items.set(bonus.key, item);
|
||||
case SPAWN(BONUS(id, rect, type)):
|
||||
var item = new BonusRenderItem(rect, type);
|
||||
items.set(id, item);
|
||||
upperLayer.addChild(item.view);
|
||||
item.update();
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
public function onChange(entity:EntityType, change:EntityChange):Void {}
|
||||
|
||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||
switch [entity, with] {
|
||||
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
|
||||
if (eagle.death) {
|
||||
playAnimate(eagle.rect.center, AnimateBundle.tankBoom());
|
||||
case MOVE(EAGLE(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
||||
switch entity {
|
||||
case EntityType.TANK(tank):
|
||||
if (items.exists(tank.key)) {
|
||||
entryLayer.removeChild(items.get(tank.key).view);
|
||||
items.remove(tank.key);
|
||||
playAnimate(tank.rect.center, AnimateBundle.tankBoom());
|
||||
if (tank.config.score > 0) {
|
||||
showScore(tank.rect.center, tank.config.score);
|
||||
}
|
||||
case MOVE(BULLET(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case EntityType.BULLET(bullet):
|
||||
if (items.exists(bullet.key)) {
|
||||
entryLayer.removeChild(items.get(bullet.key).view);
|
||||
items.remove(bullet.key);
|
||||
var point = bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y));
|
||||
case MOVE(TANK(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
cast(item, TankRenderItem).moves = true;
|
||||
}
|
||||
case STOP(TANK(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
cast(item, TankRenderItem).moves = false;
|
||||
}
|
||||
case CHANGE(TANK(id, type, hits, bonus)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.skin = config.getTank(type).skin;
|
||||
item.hits = hits;
|
||||
item.bonus = bonus;
|
||||
}
|
||||
case CHANGE(TANK_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(EAGLE_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:EagleRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(BRICK(id, type)):
|
||||
if (items.exists(id)) {
|
||||
var item:BrickRenderItem = cast items[id];
|
||||
item.type = type;
|
||||
}
|
||||
case DESTROY(TANK(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
var rect = item.rect;
|
||||
// move boom
|
||||
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||
playAnimate(point, AnimateBundle.bulletBoom());
|
||||
items.remove(id);
|
||||
}
|
||||
case EntityType.BONUS(bonus):
|
||||
if (items.exists(bonus.key)) {
|
||||
upperLayer.removeChild(items.get(bonus.key).view);
|
||||
items.remove(bonus.key);
|
||||
if (bonus.config.score > 0) {
|
||||
showScore(bonus.rect.center, bonus.config.score);
|
||||
}
|
||||
case DESTROY(EAGLE(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroyCell(x, y);
|
||||
case DESTROY(BRICK(id, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroy();
|
||||
case _:
|
||||
}
|
||||
#if cpp
|
||||
flash.Lib.current.stage.invalidate();
|
||||
#end
|
||||
}
|
||||
|
||||
private function playAnimate(point:Point, animate:OnceAnimate):Void {
|
||||
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||
animate.x = point.x - animate.width / 2;
|
||||
animate.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
animate.play().then(function(animate:Animate):Void {
|
||||
return animate.play().then(function(animate:Animate):Void {
|
||||
// ToDo: clean animates on reset
|
||||
if (upperLayer.contains(animate)) {
|
||||
upperLayer.removeChild(animate);
|
||||
upperLayer.removeChildSafety(animate);
|
||||
}
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private function showScore(point:Point, score:Int):Void {
|
||||
var view:TextField = new TextField();
|
||||
view.embedFonts = true;
|
||||
var font:String = Provider.get(IResources).text.get('font');
|
||||
view.defaultTextFormat = new TextFormat(font, 28, 0xffffff);
|
||||
view.text = Std.string(score);
|
||||
view.x = point.x - view.textWidth / 2;
|
||||
view.y = point.y - view.textHeight / 2;
|
||||
upperLayer.addChild(view);
|
||||
Timer.delay(function() upperLayer.removeChild(view), 1000);
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import ru.m.tankz.Type.BrickType;
|
||||
|
||||
typedef TRectangle = {
|
||||
var rect(default, null):Rectangle;
|
||||
}
|
||||
|
||||
class RenderItem<T:TRectangle, D:DisplayObject> {
|
||||
|
||||
public var value(default, null):T;
|
||||
public var view(default, null):D;
|
||||
|
||||
public function new(value:T) {
|
||||
this.value = value;
|
||||
this.view = null;
|
||||
}
|
||||
|
||||
public function redraw():Void {}
|
||||
|
||||
public function update():Void {
|
||||
var rect = value.rect;
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
}
|
||||
|
||||
public function dispose():Void {}
|
||||
}
|
||||
|
||||
|
||||
class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
|
||||
|
||||
public function new(value:T) {
|
||||
super(value);
|
||||
this.view = new Bitmap();
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
view.bitmapData = Assets.getBitmapData(getImage());
|
||||
}
|
||||
|
||||
private function getImage():String {
|
||||
return 'ERROR';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BrickItem extends BitmapItem<Brick> {
|
||||
private var type:BrickType;
|
||||
|
||||
public function new(value:Brick) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var t = value.config.type;
|
||||
if (t != type) {
|
||||
type = t;
|
||||
view.visible = t != 'none';
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
override private function getImage():String {
|
||||
return 'resources/image/map/${value.config.type}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BrickAnimateItem extends AnimateItem<Brick> {
|
||||
|
||||
public function new(value:Brick) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
view.frames = [for (i in 0...2) ({
|
||||
image: Assets.getBitmapData('resources/image/map/${value.config.type}-${i}.png'),
|
||||
length: 15
|
||||
})];
|
||||
view.playing = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BrickBreakingItem extends RenderItem<Brick, Shape> {
|
||||
private var broken:Int;
|
||||
private var type:BrickType;
|
||||
|
||||
public function new(value:Brick) {
|
||||
super(value);
|
||||
this.view = new Shape();
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var image = Assets.getBitmapData(getImage());
|
||||
var g = view.graphics;
|
||||
g.clear();
|
||||
if (value.destroyed) return;
|
||||
if (value.config.index > 0) {
|
||||
g.beginBitmapFill(image);
|
||||
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
||||
for (c in value.cells) {
|
||||
if (c.destroyed) {
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(c.rect.x - value.rect.x, c.rect.y - value.rect.y, c.rect.width, c.rect.height);
|
||||
}
|
||||
}
|
||||
g.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var b = value.broken;
|
||||
var t = value.config.type;
|
||||
if (b != broken || t != type) {
|
||||
broken = b;
|
||||
type = t;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
private function getImage():String {
|
||||
return 'resources/image/map/${value.config.type}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AnimateItem<T:TRectangle> extends RenderItem<T, Animate> {
|
||||
|
||||
public function new(value:T) {
|
||||
super(value);
|
||||
view = new Animate();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
view.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TankItem extends RenderItem<Tank, Sprite> {
|
||||
|
||||
private var type:String;
|
||||
private var hits:Int;
|
||||
private var protected:Bool;
|
||||
private var frozen:Bool;
|
||||
|
||||
private var tankView:Animate;
|
||||
private var protectView:Animate;
|
||||
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
view = new Sprite();
|
||||
tankView = new Animate();
|
||||
view.addChild(tankView);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
view.addChild(protectView);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
tankView.frames = AnimateBundle.tankFrames(value);
|
||||
if (value.protect.active) {
|
||||
protectView.x = (tankView.frames[0].image.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (tankView.frames[0].image.height - protectView.frames[0].image.height) / 2;
|
||||
protectView.playing = true;
|
||||
protectView.visible = true;
|
||||
} else {
|
||||
protectView.playing = false;
|
||||
protectView.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
var frame0 = 'resources/image/tank/${value.config.skin}-0.png';
|
||||
var frame1 = 'resources/image/tank/${value.config.skin}-1.png';
|
||||
return [frame1, frame0];
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var t = value.config.type;
|
||||
var h = value.hits;
|
||||
var p = value.protect.active;
|
||||
var f = value.freezing.active;
|
||||
if (t != type || h != hits || p != protected || f != frozen) {
|
||||
this.type = t;
|
||||
this.hits = h;
|
||||
this.protected = p;
|
||||
this.frozen = f;
|
||||
redraw();
|
||||
}
|
||||
tankView.playing = !value.freezing.active && (value.mx !=0 || value.my != 0);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
if (tankView != null) {
|
||||
tankView.dispose();
|
||||
tankView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BulletItem extends BitmapItem<Bullet> {
|
||||
|
||||
override private function getImage():String {
|
||||
var type:String = 'normal';
|
||||
if (value.config.piercing > 0) type = 'piercing';
|
||||
return 'resources/image/bullet/${type}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class EagleItem extends BitmapItem<Eagle> {
|
||||
|
||||
private var death:Bool;
|
||||
private var protected:Bool;
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var d = value.death;
|
||||
var p = value.protect.active;
|
||||
if (d != death || p != protected) {
|
||||
death = d;
|
||||
protected = p;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
override private function getImage():String {
|
||||
var suffix = value.death ? '-death' : value.protect.active ? '-protected' : '';
|
||||
return 'resources/image/eagle/eagle${suffix}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BonusItem extends AnimateItem<Bonus> {
|
||||
|
||||
public function new(value:Bonus) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
|
||||
view.frames = AnimateBundle.bonusFrames(value.config.type);
|
||||
view.playing = true;
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
32
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
32
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
@@ -0,0 +1,32 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.PixelSnapping;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BitmapRenderItem extends RenderItem {
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
private var bitmap:Bitmap;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.AUTO, true);
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
bitmap.bitmapData = image;
|
||||
bitmap.width = rect.width;
|
||||
bitmap.height = rect.height;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class BonusRenderItem extends BitmapRenderItem {
|
||||
|
||||
public var type(default, set):BonusType;
|
||||
private var d = -0.05;
|
||||
private var alpha = 1.0;
|
||||
|
||||
public function new(rect:Rectangle, type:BonusType) {
|
||||
super(rect);
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_type(value:BonusType):BonusType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
image = RenderUtil.bonusImage(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
alpha += d;
|
||||
view.alpha = alpha;
|
||||
if (alpha <= 0 || alpha >= 1.5) {
|
||||
d = -d;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
96
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
@@ -0,0 +1,96 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Shape;
|
||||
import openfl.Assets;
|
||||
import openfl.display.DisplayObject;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type.BrickType;
|
||||
|
||||
enum BrickState {
|
||||
UNBROKEN;
|
||||
BROKEN;
|
||||
DESTROYED;
|
||||
}
|
||||
|
||||
class BrickRenderItem extends RenderItem {
|
||||
|
||||
public var type(default, set):BrickType;
|
||||
public var state(get, never):BrickState;
|
||||
|
||||
private var image:BitmapData;
|
||||
private var shape:Shape;
|
||||
private var cells:Array<Point>;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private function get_state():BrickState {
|
||||
return switch cells.length {
|
||||
case 0: DESTROYED;
|
||||
case 4: UNBROKEN;
|
||||
case _: BROKEN;
|
||||
}
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return shape;
|
||||
}
|
||||
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
cells = buildCells();
|
||||
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
||||
redraw();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public function destroyCell(x:Int, y:Int):Void {
|
||||
cells = cells.filter(function(point) return !(point.x == x && point.y == y));
|
||||
redraw();
|
||||
}
|
||||
|
||||
public function destroy():Void {
|
||||
cells = [];
|
||||
redraw();
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
shape.graphics.clear();
|
||||
if (type == "none") return;
|
||||
switch state {
|
||||
case UNBROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
shape.graphics.drawRect(0, 0, rect.width, rect.height);
|
||||
shape.graphics.endFill();
|
||||
case BROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
for (point in cells) {
|
||||
var x = point.x * (rect.width / 2);
|
||||
var y = point.y * (rect.width / 2);
|
||||
var width = rect.width / 2;
|
||||
var height = rect.height / 2;
|
||||
shape.graphics.drawRect(x, y, width, height);
|
||||
}
|
||||
shape.graphics.endFill();
|
||||
case DESTROYED:
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
21
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
@@ -0,0 +1,21 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BulletRenderItem extends BitmapRenderItem {
|
||||
public var skin(default, set):String;
|
||||
|
||||
public function new(rect:Rectangle, skin:String) {
|
||||
super(rect);
|
||||
this.skin = skin;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
image = RenderUtil.bulletImage(skin);
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
57
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
57
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
@@ -0,0 +1,57 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class EagleRenderItem extends BitmapRenderItem {
|
||||
public var color(default, default):Color;
|
||||
public var death(default, set):Bool = true;
|
||||
public var protect(default, set):Bool;
|
||||
|
||||
private var container:Sprite;
|
||||
private var protectView:Animate;
|
||||
|
||||
public function new(rect:Rectangle, color:Color) {
|
||||
super(rect);
|
||||
this.color = color;
|
||||
container = new Sprite();
|
||||
container.addChild(bitmap);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
death = false;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
private function set_protect(value:Bool):Bool {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
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;
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
private function set_death(value:Bool):Bool {
|
||||
if (death != value) {
|
||||
death = value;
|
||||
image = RenderUtil.eagleImage(death);
|
||||
if (!color.zero) {
|
||||
bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
}
|
||||
return death;
|
||||
}
|
||||
}
|
||||
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
interface IRenderItem {
|
||||
public var view(get, null):DisplayObject;
|
||||
public var rect(default, null):Rectangle;
|
||||
public function move(position:Position):Void;
|
||||
public function update():Void;
|
||||
public function dispose():Void;
|
||||
}
|
||||
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
@@ -0,0 +1,46 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class RenderItem implements IRenderItem {
|
||||
|
||||
public var view(get, null):DisplayObject;
|
||||
public var content(get, null):DisplayObject;
|
||||
|
||||
public var rect(default, null):Rectangle;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
this.rect = rect.clone();
|
||||
}
|
||||
|
||||
private function get_view():DisplayObject {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
private function get_content():DisplayObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function move(position:Position):Void {
|
||||
view.x = rect.x = position.x;
|
||||
view.y = rect.y = position.y;
|
||||
if (position.direction != null) {
|
||||
rect.direction = position.direction;
|
||||
if (content != null) {
|
||||
content.rotation = rect.direction.angle;
|
||||
content.x = - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
content.y = - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
} else {
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update():Void {}
|
||||
|
||||
public function dispose():Void {}
|
||||
}
|
||||
152
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
152
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
@@ -0,0 +1,152 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
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 ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class TankRenderItem extends BitmapRenderItem {
|
||||
public var color(default, default):Color;
|
||||
public var skin(default, set):String;
|
||||
public var hits(default, set):Int;
|
||||
public var bonus(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
|
||||
private var container:Sprite;
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var nameView:TextField;
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
container = new Sprite();
|
||||
container.addChild(bitmap);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function buildNameView():TextField {
|
||||
var result = new BitmapTextField();
|
||||
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
||||
result.embedFonts = theme.font.embed;
|
||||
result.autoSize = TextFieldAutoSize.LEFT;
|
||||
result.shadowColor = 0x000000;
|
||||
result.stroke = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
override private function get_content():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = RenderUtil.tankImage(skin, 0);
|
||||
var image2 = RenderUtil.tankImage(skin, 1);
|
||||
var color1:Color = switch hits {
|
||||
case 1: 0x869C43;
|
||||
case 2: 0xDEAF80;
|
||||
case 3: 0x5EA67A;
|
||||
case _: color;
|
||||
}
|
||||
var color2:Color = color1;
|
||||
if (bonus) {
|
||||
color1 = 0xff00aa;
|
||||
}
|
||||
if (!color1.zero) {
|
||||
image1 = BitmapUtil.colorize(image1, color1);
|
||||
}
|
||||
if (!color1.zero) {
|
||||
image2 = BitmapUtil.colorize(image2, color2);
|
||||
}
|
||||
images = [for (i in 0...6) image1].concat([for (i in 0...6) image2]);
|
||||
frame = 0;
|
||||
bitmap.bitmapData = images[frame];
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
redraw();
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
private function set_hits(value:Int):Int {
|
||||
if (hits != value) {
|
||||
hits = value;
|
||||
redraw();
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
private function set_bonus(value:Bool):Bool {
|
||||
if (bonus != value) {
|
||||
bonus = value;
|
||||
redraw();
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
private function set_protect(value:Bool):Bool {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
protectView.x = (images[0].width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (images[0].height - protectView.frames[0].image.height) / 2;
|
||||
}
|
||||
protectView.visible = protect;
|
||||
protectView.playing = protect;
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
private function set_moves(value:Bool):Bool {
|
||||
if (moves != value) {
|
||||
moves = value;
|
||||
bitmap.bitmapData = images[0];
|
||||
}
|
||||
return moves;
|
||||
}
|
||||
|
||||
private function set_name(value:String):String {
|
||||
if (name != value) {
|
||||
name = value;
|
||||
nameView.text = name;
|
||||
nameView.x = (rect.width - nameView.width) / 2;
|
||||
nameView.y = -nameView.height / 2; //(rect.height - nameView.height) / 2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (moves) {
|
||||
frame++;
|
||||
if (frame > images.length - 1) {
|
||||
frame = 0;
|
||||
}
|
||||
bitmap.bitmapData = images[frame];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,127 @@
|
||||
package ru.m.tankz.sound;
|
||||
|
||||
import openfl.media.Sound;
|
||||
import flash.events.Event;
|
||||
import flash.media.Sound;
|
||||
import flash.media.SoundChannel;
|
||||
import flash.media.SoundTransform;
|
||||
import openfl.utils.Assets;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
|
||||
class SoundManager {
|
||||
private static var TAG(default, never):String = 'SoundManager';
|
||||
class SoundManager implements GameListener {
|
||||
private static var TAG(default, never):String = "SoundManager";
|
||||
|
||||
#if flash
|
||||
private static var type:String = 'mp3';
|
||||
private static var type:String = "mp3";
|
||||
#else
|
||||
private static var type:String = 'ogg';
|
||||
private static var type:String = "ogg";
|
||||
#end
|
||||
|
||||
public function new() {}
|
||||
public var config(default, default):Config;
|
||||
public var volume(default, set):Float = 1;
|
||||
public var mute(default, set):Bool = false;
|
||||
|
||||
private var channels:Array<SoundChannel>;
|
||||
private var transform:SoundTransform;
|
||||
|
||||
private var humanTanks:Array<Int>;
|
||||
private var humanBullets:Array<Int>;
|
||||
private var liveBonuses:Array<Int>;
|
||||
|
||||
public function new() {
|
||||
channels = [];
|
||||
updateSoundTransform();
|
||||
}
|
||||
|
||||
private function updateSoundTransform():Void {
|
||||
transform = new SoundTransform(mute ? 0 : volume);
|
||||
for (channel in channels) {
|
||||
channel.soundTransform = transform;
|
||||
}
|
||||
}
|
||||
|
||||
private function set_volume(value:Float):Float {
|
||||
if (volume != value) {
|
||||
volume = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
return volume;
|
||||
}
|
||||
|
||||
private function set_mute(value:Bool):Bool {
|
||||
if (mute != value) {
|
||||
mute = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
return mute;
|
||||
}
|
||||
|
||||
public function play(id:String):Void {
|
||||
//L.d(TAG, 'play: ${id}');
|
||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||
if (sound != null) {
|
||||
sound.play();
|
||||
var channel = sound.play(0, 0, transform);
|
||||
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||
channels.push(channel);
|
||||
} else {
|
||||
L.w(TAG, 'Sound "${id}" not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function onSpawn(entity:EntityType):Void {
|
||||
switch entity {
|
||||
case EntityType.BULLET(_.tank.playerId.team => 'human'):
|
||||
play('shot');
|
||||
case EntityType.BONUS(_):
|
||||
play('bonus_add');
|
||||
case _:
|
||||
public function stopAll():Void {
|
||||
for (channel in channels) {
|
||||
channel.stop();
|
||||
}
|
||||
channels = [];
|
||||
}
|
||||
|
||||
public function onChange(entity:EntityType, change:EntityChange):Void {
|
||||
switch [entity, change] {
|
||||
case [EntityType.TANK(_), EntityChange.HIT]:
|
||||
play('bullet_hit');
|
||||
//case [EntityType.TANK(_), EntityChange.LIVE_UP]:
|
||||
// play('live');
|
||||
case [EntityType.EAGLE(_), EntityChange.DEATH(_)]:
|
||||
play('boom_player');
|
||||
case _:
|
||||
}
|
||||
private function onSoundComplete(event:Event):Void {
|
||||
channels.remove(event.currentTarget);
|
||||
}
|
||||
|
||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||
switch [entity, with] {
|
||||
case [EntityType.BULLET(_), EntityType.CELL(cell)]:
|
||||
//play('bullet_wall');
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
||||
switch entity {
|
||||
case EntityType.TANK(_):
|
||||
play('boom_bot');
|
||||
case EntityType.BONUS(_):
|
||||
play('bonus_get');
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
play("start");
|
||||
humanTanks = [];
|
||||
liveBonuses = [];
|
||||
humanBullets = [];
|
||||
case SPAWN(BULLET(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
play("shot");
|
||||
humanBullets.push(id);
|
||||
}
|
||||
case SPAWN(TANK(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
humanTanks.push(id);
|
||||
}
|
||||
case SPAWN(BONUS(id, _, type)):
|
||||
play("bonus_add");
|
||||
if (type == "live") {
|
||||
liveBonuses.push(id);
|
||||
}
|
||||
case HIT(TANK(_, _)):
|
||||
play("bullet_hit");
|
||||
case HIT(CELL(_, _, shot)):
|
||||
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
||||
//play("bullet_block");
|
||||
}
|
||||
case DESTROY(TANK(id, _)):
|
||||
if (humanTanks.indexOf(id) > -1) {
|
||||
play("boom_player");
|
||||
} else {
|
||||
play("boom_bot");
|
||||
}
|
||||
case DESTROY(EAGLE(_, _)):
|
||||
play("boom_player");
|
||||
case DESTROY(BONUS(id, _)):
|
||||
play("bonus_get");
|
||||
if (liveBonuses.indexOf(id) > -1) {
|
||||
play("live");
|
||||
} else {
|
||||
play("bonus_get");
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
22
src/client/haxe/ru/m/tankz/storage/GameStorage.hx
Normal file
22
src/client/haxe/ru/m/tankz/storage/GameStorage.hx
Normal file
@@ -0,0 +1,22 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class GameStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
public function new() {
|
||||
super('game_${VERSION}');
|
||||
}
|
||||
|
||||
public function get(id:PackId):PackProgress {
|
||||
return exists(id) ? read(id) : new PackProgress(id);
|
||||
}
|
||||
|
||||
public function set(progress:PackProgress):Void {
|
||||
write(progress.id, progress);
|
||||
}
|
||||
}
|
||||
21
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
21
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
@@ -0,0 +1,21 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
|
||||
class NetworkStorage extends SharedObjectStorage {
|
||||
|
||||
public var user(get, set):User;
|
||||
|
||||
public function new() {
|
||||
super("network");
|
||||
}
|
||||
|
||||
private inline function get_user():User {
|
||||
return read("user");
|
||||
}
|
||||
|
||||
private inline function set_user(value:User):User {
|
||||
write("user", value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
41
src/client/haxe/ru/m/tankz/storage/RecordStorage.hx
Normal file
41
src/client/haxe/ru/m/tankz/storage/RecordStorage.hx
Normal file
@@ -0,0 +1,41 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxe.DynamicAccess;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
|
||||
class RecordStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
public function new() {
|
||||
super('record_${VERSION}');
|
||||
}
|
||||
|
||||
public function save(record:GameRecord):Void {
|
||||
L.d("RecordStorage", 'save $record');
|
||||
write('${record.info.id}.info', record.info);
|
||||
write(record.info.id, record);
|
||||
}
|
||||
|
||||
override public function delete(id:String):Void {
|
||||
super.delete(id);
|
||||
super.delete('${id}.info');
|
||||
}
|
||||
|
||||
public function list():Array<GameRecordInfo> {
|
||||
var result = [];
|
||||
var data:DynamicAccess<String> = so.data;
|
||||
for (id in data.keys()) {
|
||||
try {
|
||||
if (StringTools.endsWith(id, '.info')) {
|
||||
result.push(read(id));
|
||||
}
|
||||
} catch (error:Dynamic) {
|
||||
L.w("RecordStorage", 'read ', error);
|
||||
delete(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,81 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import flash.net.SharedObject;
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import haxework.utils.ObjectUtil;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.tankz.control.Control.TankAction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class SettingsStorage extends SharedObjectStorage {
|
||||
|
||||
class SettingsStorage {
|
||||
|
||||
private static var TAG(default, never):String = 'SettingsStorage';
|
||||
|
||||
private var so:SharedObject;
|
||||
private static inline var VERSION = 4.1;
|
||||
|
||||
public function new() {
|
||||
so = SharedObject.getLocal('settings');
|
||||
super('settings_${VERSION}');
|
||||
}
|
||||
|
||||
public function read(index: Int):Null<ActionConfig> {
|
||||
var data:String = Reflect.getProperty(so.data, Std.string(index));
|
||||
L.d(TAG, 'read: ${data}');
|
||||
if (data != null) {
|
||||
try {
|
||||
return ActionConfig.loads(data);
|
||||
} catch (error:Dynamic) {
|
||||
L.w(TAG, "read", error);
|
||||
}
|
||||
}
|
||||
return getDefault(index);
|
||||
public function getBinding(index:Int):Binding {
|
||||
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||
}
|
||||
|
||||
public function write(index: Int, data: ActionConfig):Void {
|
||||
L.d(TAG, 'write: ${data}');
|
||||
so.setProperty(Std.string(index), data.dumps());
|
||||
so.flush();
|
||||
public function saveBinding(index:Int, value:Binding) {
|
||||
write('action:$index', value);
|
||||
}
|
||||
|
||||
public static function getDefault(index: Int): ActionConfig {
|
||||
return (defaults.exists(index) ? defaults.get(index) : empty).clone();
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||
}
|
||||
|
||||
private static var defaults: Map<Int, ActionConfig> = [
|
||||
0 => new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
||||
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
||||
]),
|
||||
1 => new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||
]),
|
||||
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(0) => {device: device, action: KEY(0)},
|
||||
SHOT(1) => {device: device, action: KEY(1)},
|
||||
SHOT(2) => {device: device, action: KEY(2)},
|
||||
];
|
||||
}
|
||||
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => null,
|
||||
MOVE(Direction.RIGHT) => null,
|
||||
SHOT(0) => null,
|
||||
SHOT(1) => null,
|
||||
SHOT(2) => null,
|
||||
];
|
||||
}
|
||||
|
||||
private static var mobileDefaults:Map<Int, Binding> = [
|
||||
0 => buildDeviceBinding(SCREEN),
|
||||
];
|
||||
|
||||
private static var empty: ActionConfig = new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
||||
{action:TankAction.SHOT, key:-1},
|
||||
]);
|
||||
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(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(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,27 +0,0 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import flash.net.SharedObject;
|
||||
|
||||
|
||||
class UserStorage {
|
||||
|
||||
private static var TAG(default, never):String = 'UserStorage';
|
||||
|
||||
private var so:SharedObject;
|
||||
|
||||
public function new() {
|
||||
so = SharedObject.getLocal('user');
|
||||
}
|
||||
|
||||
public function read():Null<User> {
|
||||
var user:User = Reflect.getProperty(so.data, 'user');
|
||||
L.d(TAG, 'read: ${user}');
|
||||
return user;
|
||||
}
|
||||
|
||||
public function write(user:User):Void {
|
||||
L.d(TAG, 'write: ${user}');
|
||||
so.setProperty('user', user);
|
||||
so.flush();
|
||||
}
|
||||
}
|
||||
42
src/client/haxe/ru/m/tankz/view/ClientView.hx
Normal file
42
src/client/haxe/ru/m/tankz/view/ClientView.hx
Normal file
@@ -0,0 +1,42 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.group.VGroupView;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
|
||||
@:template class ClientView extends VGroupView {
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var resources:IResources;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var game:IGame;
|
||||
|
||||
public function init():Void {
|
||||
resources.text.put('version', '${Const.VERSION}');
|
||||
switcher = switcherView;
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
content.stage.stageFocusRect = false;
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||
switch event.keyCode {
|
||||
case Keyboard.ESCAPE:
|
||||
switcher.change(MenuFrame.ID);
|
||||
case Keyboard.M:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case Keyboard.P:
|
||||
if (game != null) {
|
||||
game.pause = !game.pause;
|
||||
}
|
||||
}
|
||||
});
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user