Compare commits
190 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 | |||
| 0f5cf7fdc5 | |||
| 426b2718bb | |||
| 8ea862a118 | |||
| 1f87a71833 | |||
| 56c2cd9437 | |||
| 85e5f9a553 | |||
| d9915120d4 |
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
|
* bonuses
|
||||||
* gulp 100%
|
* death game bonuses
|
||||||
* linux 100%
|
* boat bonus
|
||||||
* deb-package 100%
|
* tanks and bullets speed balancing
|
||||||
* windows 0%
|
* game series
|
||||||
* exe-package 0% (inno setup)
|
* network series
|
||||||
|
* map packs
|
||||||
* deploy
|
* create in editor
|
||||||
* capistrano 100%
|
* import in game
|
||||||
|
* save imported in local storage
|
||||||
* ui
|
* database
|
||||||
* auth frame 0%
|
* cache
|
||||||
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
* improve bots
|
||||||
* select level frame 10%
|
* A star
|
||||||
* game frame 50%
|
* game config validate
|
||||||
|
* additional weapon
|
||||||
* engine
|
* mine
|
||||||
* config 100%
|
* display count
|
||||||
* map 100%
|
* bonus ammo
|
||||||
* tanks 100%
|
* screen gamepad (button enabled, count label)
|
||||||
* bullets 100%
|
* ui:
|
||||||
* boxes 100%
|
* game frame layouts
|
||||||
* 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%
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ hash_behaviour = merge
|
|||||||
host_key_checking = False
|
host_key_checking = False
|
||||||
#callback_whitelist = profile_tasks
|
#callback_whitelist = profile_tasks
|
||||||
display_skipped_hosts = False
|
display_skipped_hosts = False
|
||||||
|
stdout_callback = yaml
|
||||||
|
bin_ansible_callbacks = True
|
||||||
|
|
||||||
[ssh_connection]
|
[ssh_connection]
|
||||||
pipelining = True
|
pipelining = True
|
||||||
ssh_args = -o ForwardAgent=yes
|
ssh_args = -o ForwardAgent=yes
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ project_user: holop
|
|||||||
deploy_user: "{{ project_user }}"
|
deploy_user: "{{ project_user }}"
|
||||||
deploy_project: "{{ project_name }}"
|
deploy_project: "{{ project_name }}"
|
||||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||||
deploy_repo_version: staging
|
deploy_repo_version: develop
|
||||||
deploy_npm: yes
|
deploy_npm: yes
|
||||||
|
|
||||||
service_name: "{{ project_name }}"
|
service_name: "{{ project_name }}"
|
||||||
|
|||||||
@@ -6,6 +6,6 @@
|
|||||||
remote_src: true
|
remote_src: true
|
||||||
|
|
||||||
- name: "Gulp build"
|
- name: "Gulp build"
|
||||||
command: "/usr/local/lib/npm/bin/gulp default"
|
command: "/usr/local/lib/npm/bin/gulp default --host shmyga.ru"
|
||||||
args:
|
args:
|
||||||
chdir: "{{ deploy_release_dir }}"
|
chdir: "{{ deploy_release_dir }}"
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"SdkDir": "C:\\sdk",
|
"SdkDir": "C:\\sdk",
|
||||||
"SSH": {
|
"PublishDir": "",
|
||||||
"PrivateKey": null,
|
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||||
"Passphrase": null
|
"SSH": {
|
||||||
}
|
"PrivateKey": null,
|
||||||
|
"Passphrase": null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"SdkDir": "/home/holop/sdk",
|
"SdkDir": "/home/holop/sdk",
|
||||||
"SSH": {
|
"PublishDir": "/opt/repo/tankz",
|
||||||
"PrivateKey": null,
|
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||||
"Passphrase": null
|
"SSH": {
|
||||||
}
|
"PrivateKey": null,
|
||||||
|
"Passphrase": null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
gen.sh
4
gen.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
haxelib run protohx generate protohx.json
|
haxelib run protohx generate protohx.json
|
||||||
haxelib run orm mysql://shmyga:xkbp8jh9z2@localhost:3306/armageddon \
|
haxelib run orm mysql://shmyga:password@localhost:3306/armageddon \
|
||||||
-s src-gen/haxe \
|
-s src-gen/haxe \
|
||||||
-c ru.m.tankz.db \
|
-c ru.m.tankz.db \
|
||||||
-a ru.m.tankz.db
|
-a ru.m.tankz.db
|
||||||
|
|||||||
117
gulpfile.js
117
gulpfile.js
@@ -1,14 +1,12 @@
|
|||||||
"use strict";
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const gulpClean = require('gulp-clean');
|
const gulpClean = require('gulp-clean');
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const packageInfo = require('./package.json');
|
const packageInfo = require('./package.json');
|
||||||
const {Sdk, Haxe, Project, FlashPlayer} = require('gulp-haxetool');
|
const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
|
||||||
const dateformat = require('dateformat');
|
const dateformat = require('dateformat');
|
||||||
|
const argv = require('yargs').argv;
|
||||||
|
const publish = require('./tasks/gulp-publish');
|
||||||
|
|
||||||
|
|
||||||
// ToDo: update default in gulp-haxetool
|
|
||||||
FlashPlayer.VERSION = '31';
|
|
||||||
if (Config.SdkDir) {
|
if (Config.SdkDir) {
|
||||||
Sdk.dir = Config.SdkDir;
|
Sdk.dir = Config.SdkDir;
|
||||||
}
|
}
|
||||||
@@ -26,15 +24,13 @@ exports.generate = function generate() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToDo:
|
* base config
|
||||||
* windows target
|
|
||||||
* window exe package (innosetup)
|
|
||||||
*/
|
*/
|
||||||
const config = new Project.Config({
|
const config = new Project.Config({
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Tank\'z',
|
title: 'Tank\'z',
|
||||||
filename: 'tankz',
|
filename: 'tankz',
|
||||||
icon: 'src/client/resources/image/tank/pd-0.png',
|
icon: 'src/client/resources/icon.png',
|
||||||
pack: 'ru.m.tankz',
|
pack: 'ru.m.tankz',
|
||||||
author: 'shmyga <shmyga.z@gmail.com>',
|
author: 'shmyga <shmyga.z@gmail.com>',
|
||||||
company: 'MegaLoMania',
|
company: 'MegaLoMania',
|
||||||
@@ -46,14 +42,19 @@ const config = new Project.Config({
|
|||||||
'src-gen/haxe',
|
'src-gen/haxe',
|
||||||
],
|
],
|
||||||
assets: [
|
assets: [
|
||||||
'src/common/resources'
|
'src/common/resources',
|
||||||
|
],
|
||||||
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
],
|
],
|
||||||
macros: [
|
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')}')`,
|
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const host = argv.host || 'localhost';
|
||||||
|
const port = argv.port || 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* client
|
* client
|
||||||
*/
|
*/
|
||||||
@@ -63,20 +64,35 @@ const client = new Project(
|
|||||||
Project.Platform.FLASH,
|
Project.Platform.FLASH,
|
||||||
Project.Platform.HTML5,
|
Project.Platform.HTML5,
|
||||||
Project.Platform.LINUX,
|
Project.Platform.LINUX,
|
||||||
|
Project.Platform.WINDOWS,
|
||||||
Project.Platform.ANDROID,
|
Project.Platform.ANDROID,
|
||||||
],
|
],
|
||||||
config.branch({
|
config.branch({
|
||||||
name: 'client',
|
name: 'client',
|
||||||
sources: ['src/client/haxe'],
|
sources: [
|
||||||
|
//'src/fixes/haxe',
|
||||||
|
'src/client/haxe',
|
||||||
|
],
|
||||||
main: 'ru.m.tankz.Client',
|
main: 'ru.m.tankz.Client',
|
||||||
assets: ['src/client/resources'],
|
preloader: 'ru.m.tankz.Preloader',
|
||||||
|
assets: [
|
||||||
|
'src/client/resources',
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
width: 1024,
|
||||||
|
height: 768,
|
||||||
|
},
|
||||||
flags: [
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
//'dom',
|
//'dom',
|
||||||
//'dev_layout',
|
//'dev_layout',
|
||||||
//'bitmap_text',
|
//'bitmap_text',
|
||||||
],
|
],
|
||||||
|
macros: [
|
||||||
|
`CompilationOption.set('host','${host}')`,
|
||||||
|
`CompilationOption.set('port',${port})`,
|
||||||
|
]
|
||||||
}),
|
}),
|
||||||
module.exports.generate
|
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,13 +100,31 @@ const client = new Project(
|
|||||||
*/
|
*/
|
||||||
const editor = new Project(
|
const editor = new Project(
|
||||||
Project.BuildSystem.OPENFL,
|
Project.BuildSystem.OPENFL,
|
||||||
Project.Platform.FLASH,
|
[
|
||||||
|
Project.Platform.FLASH,
|
||||||
|
Project.Platform.HTML5,
|
||||||
|
],
|
||||||
config.branch({
|
config.branch({
|
||||||
name: 'editor',
|
name: 'editor',
|
||||||
sources: ['src/client/haxe', 'src/editor/haxe'],
|
sources: [
|
||||||
|
//'src/fixes/haxe',
|
||||||
|
'src/client/haxe',
|
||||||
|
'src/editor/haxe',
|
||||||
|
],
|
||||||
main: 'ru.m.tankz.editor.Editor',
|
main: 'ru.m.tankz.editor.Editor',
|
||||||
assets: ['src/client/resources'],
|
preloader: 'ru.m.tankz.Preloader',
|
||||||
meta: {filename: 'editor'}
|
assets: [
|
||||||
|
'src/client/resources',
|
||||||
|
'src/editor/resources',
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
filename: 'editor',
|
||||||
|
width: 1024,
|
||||||
|
height: 768,
|
||||||
|
},
|
||||||
|
flags: [
|
||||||
|
//'dev_layout',
|
||||||
|
]
|
||||||
})
|
})
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
@@ -104,20 +138,51 @@ const server = new Project(
|
|||||||
name: 'server',
|
name: 'server',
|
||||||
sources: ['src/server/haxe'],
|
sources: ['src/server/haxe'],
|
||||||
main: 'ru.m.tankz.server.Server',
|
main: 'ru.m.tankz.server.Server',
|
||||||
})
|
}),
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* publish
|
||||||
|
*/
|
||||||
|
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default
|
* default
|
||||||
*/
|
*/
|
||||||
module.exports.default = gulp.series(
|
const defaultSeries = [
|
||||||
exports.clean,
|
exports.clean,
|
||||||
|
exports.generate,
|
||||||
module.exports['client:flash:build'],
|
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: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);
|
||||||
|
|||||||
2695
package-lock.json
generated
2695
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",
|
"name": "tankz",
|
||||||
"version": "0.8.1",
|
"version": "0.17.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-add": "0.0.2",
|
"gulp-add": "0.0.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-haxetool": "^0.0.14"
|
"gulp-haxetool": "0.1.0",
|
||||||
},
|
"yargs": "^13.2.4"
|
||||||
"haxeDependencies": {
|
},
|
||||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
"haxeDependencies": {
|
||||||
"lime": "7.2.1",
|
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||||
"openfl": "8.8.0",
|
"lime": "7.5.0",
|
||||||
"hxcpp": "4.0.8",
|
"openfl": "8.9.1",
|
||||||
"promhx": "1.1.0",
|
"hxcpp": "4.0.52",
|
||||||
"protohx": "0.4.6",
|
"promhx": "1.1.0",
|
||||||
"yaml": "1.3.0",
|
"protohx": "0.4.6",
|
||||||
"orm": "2.1.0",
|
"yaml": "1.3.0",
|
||||||
"yield": "2.0.0",
|
"orm": "2.1.0",
|
||||||
"haxe-crypto": "0.0.7",
|
"haxe-crypto": "0.0.7",
|
||||||
"svg": "1.1.2"
|
"svg": "1.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
"protoFiles": [
|
"protoFiles": [
|
||||||
"src/common/proto/core.proto",
|
"src/common/proto/core.proto",
|
||||||
"src/common/proto/game.proto",
|
"src/common/proto/game.proto",
|
||||||
|
"src/common/proto/room.proto",
|
||||||
"src/common/proto/pack.proto"
|
"src/common/proto/pack.proto"
|
||||||
],
|
],
|
||||||
"cleanOut": true,
|
"cleanOut": true,
|
||||||
"haxeOut": "src-gen/haxe",
|
"haxeOut": "src-gen/haxe",
|
||||||
"javaOut": null
|
"javaOut": null
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
package ru.m.skin;
|
||||||
|
|
||||||
import haxework.color.ColorUtil;
|
|
||||||
import haxework.color.Color;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import format.SVG;
|
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;
|
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||||
private var color:Color;
|
|
||||||
|
@: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>;
|
private var svgs:Map<ButtonState, SVG>;
|
||||||
|
|
||||||
public function new(svg:String, color:Color) {
|
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
init();
|
this.solid = solid;
|
||||||
|
init(solid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline function buildSVG(color:Color):SVG {
|
private inline function buildSVG(color:Color):SVG {
|
||||||
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init():Void {
|
private function init(solid:Bool):Void {
|
||||||
svgs = new Map<ButtonState, SVG>();
|
var color = color;
|
||||||
svgs.set(ButtonState.UP, buildSVG(color));
|
if (solid) {
|
||||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
color = color.multiply(1.5);
|
||||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
}
|
||||||
|
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 {
|
public function draw(view:ButtonView):Void {
|
||||||
@@ -36,7 +45,10 @@ class ButtonSVGSkin implements ISkin<ButtonView> {
|
|||||||
graphics.beginFill(0, 0);
|
graphics.beginFill(0, 0);
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
graphics.beginFill(color);
|
graphics.beginFill(color);
|
||||||
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));
|
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||||
graphics.lineStyle();
|
graphics.lineStyle();
|
||||||
graphics.endFill();
|
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 flash.Lib;
|
||||||
import haxework.animate.Animate;
|
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.log.TraceLogger;
|
||||||
import haxework.provider.Provider;
|
import haxework.view.Root;
|
||||||
import haxework.resources.IResources;
|
import ru.m.tankz.view.ClientView;
|
||||||
#if flash import haxework.log.JSLogger; #end
|
|
||||||
#if debug import haxework.log.SocketLogger; #end
|
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
private static inline var TAG = 'Tankz';
|
private static inline var TAG = "Tankz";
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
#if flash
|
#if flash
|
||||||
L.push(new JSLogger());
|
L.push(new haxework.log.JSLogger());
|
||||||
#end
|
#end
|
||||||
#if debug
|
#if debug
|
||||||
//L.push(new SocketLogger());
|
//L.push(new haxework.log.SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
Init.init();
|
Init.init();
|
||||||
@@ -32,33 +23,16 @@ class Client {
|
|||||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
Style.register();
|
#if linux
|
||||||
|
LinuxIcon.apply();
|
||||||
|
#end
|
||||||
var view:ClientView = new ClientView();
|
var view:ClientView = new ClientView();
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.launch();
|
view.launch();
|
||||||
}
|
|
||||||
}
|
#if debug
|
||||||
|
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||||
@:template class ClientView extends VGroupView {
|
Lib.current.addChild(fps);
|
||||||
private static inline var TAG = 'Tankz';
|
#end
|
||||||
|
|
||||||
@: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} b${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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.Lib;
|
||||||
import flash.system.Capabilities;
|
import flash.system.Capabilities;
|
||||||
|
|
||||||
|
|
||||||
class Const {
|
class Const {
|
||||||
public static var FPS:Int;
|
public static var FPS:Int;
|
||||||
public static var BUILD:String;
|
public static var BUILD:String;
|
||||||
public static var VERSION:String;
|
public static var VERSION:String;
|
||||||
public static var DEBUG:Bool;
|
public static var DEBUG:Bool;
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||||
BUILD = CompilationOption.get("build");
|
BUILD = CompilationOption.get("build");
|
||||||
VERSION = Lib.current.stage.application.meta.get("version");
|
VERSION = Lib.current.stage.application.meta.get("version");
|
||||||
DEBUG = Capabilities.isDebugger;
|
DEBUG = Capabilities.isDebugger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,101 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import flash.Lib;
|
||||||
import haxework.provider.Provider;
|
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.IResources;
|
||||||
import haxework.resources.Resources;
|
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.connect.IConnection;
|
||||||
|
import ru.m.control.ControlBus;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
import ru.m.control.JoystickDevice;
|
||||||
|
import ru.m.control.KeyboardDevice;
|
||||||
import ru.m.tankz.bundle.ConfigBundle;
|
import ru.m.tankz.bundle.ConfigBundle;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.bundle.LevelBundle;
|
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.network.NetworkManager;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.storage.UserStorage;
|
import ru.m.tankz.storage.NetworkStorage;
|
||||||
#if flash
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
import flash.Lib;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
#elseif html5
|
|
||||||
import js.Browser;
|
|
||||||
#end
|
|
||||||
|
|
||||||
|
|
||||||
class Init {
|
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
|
#if flash
|
||||||
var url = Lib.current.loaderInfo.url;
|
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||||
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
|
|
||||||
if (r.match(url) && !(r.matched(1) == "app")) {
|
|
||||||
return r.matched(2);
|
|
||||||
} else {
|
|
||||||
return "localhost";
|
|
||||||
}
|
|
||||||
#elseif html5
|
#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
|
#else
|
||||||
return "localhost";
|
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
Provider.setFactory(IResources, Resources);
|
theme = new AppTheme();
|
||||||
Provider.setFactory(ILevelBundle, LevelBundle);
|
resources = new Resources();
|
||||||
Provider.setFactory(IConfigBundle, ConfigBundle);
|
levelBundle = new LevelBundle();
|
||||||
Provider.setFactory(SaveStorage, SaveStorage);
|
configBundle = new ConfigBundle();
|
||||||
Provider.setFactory(UserStorage, UserStorage);
|
settingsStorage = new SettingsStorage();
|
||||||
Provider.setFactory(SettingsStorage, SettingsStorage);
|
multiplayerStorage = new NetworkStorage();
|
||||||
Provider.setFactory(SoundManager, SoundManager);
|
gameStorage = new GameStorage();
|
||||||
Provider.setFactory(NetworkManager, NetworkManager);
|
recordStorage = new RecordStorage();
|
||||||
Provider.setFactory(IControlFactory, ClientControlFactory);
|
soundManager = new SoundManager();
|
||||||
|
popupManager = new PopupManager();
|
||||||
|
|
||||||
var host:String = getHost();
|
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||||
L.d('Init', 'host: ${host}');
|
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||||
#if flash
|
|
||||||
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response));
|
connection = buildConnection();
|
||||||
#elseif html5
|
networkManager = new NetworkManager();
|
||||||
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response));
|
|
||||||
#else
|
bus = new ControlBus();
|
||||||
Provider.set(IConnection, new ru.m.connect.fake.FakeConnection<Request, Response>(Response));
|
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||||
#end
|
|
||||||
|
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,63 +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("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.Parser;
|
||||||
import yaml.Yaml;
|
import yaml.Yaml;
|
||||||
|
|
||||||
|
|
||||||
class ConfigBundle implements IConfigBundle {
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
|
||||||
private var _cache:Map<GameType, Config> = new Map();
|
private var _cache:Map<GameType, Config> = new Map();
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType):Config {
|
public function get(type:GameType):Config {
|
||||||
if (!_cache.exists(type)) {
|
if (!_cache.exists(type)) {
|
||||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
||||||
_cache.set(type, new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses));
|
_cache.set(type, Config.fromSource(type, source));
|
||||||
}
|
}
|
||||||
return _cache.get(type);
|
return _cache.get(type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,42 @@
|
|||||||
package ru.m.tankz.bundle;
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
import openfl.utils.AssetType;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.util.LevelUtil;
|
import ru.m.tankz.util.LevelUtil;
|
||||||
|
|
||||||
|
|
||||||
class LevelBundle implements ILevelBundle {
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
public function get(type:GameType, config:Config, level:Int):LevelConfig {
|
private var _cache:Map<String, LevelPack> = new Map();
|
||||||
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt');
|
|
||||||
return LevelUtil.loads(config, data);
|
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;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
import flash.events.KeyboardEvent;
|
|
||||||
import flash.Lib;
|
|
||||||
import flash.ui.Keyboard;
|
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
using haxe.EnumTools.EnumValueTools;
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
|
|
||||||
@:provide var settings: SettingsStorage;
|
@:provide static var storage:SettingsStorage;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
private var keyBinding:KeyBinding;
|
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||||
private var moveQueue:Array<Int>;
|
|
||||||
private var shotTimer:Timer;
|
private var moveQueue:Array<Direction>;
|
||||||
|
private var shotTimers:Map<Int, Timer>;
|
||||||
|
|
||||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super(playerId);
|
super(playerId);
|
||||||
this.keyBinding = settings.read(controlIndex).asKeyBinding();
|
var config = storage.getBinding(controlIndex);
|
||||||
moveQueue = new Array<Int>();
|
binding = new Map();
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
for (action in config.keys()) {
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
var bind = config.get(action);
|
||||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
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 {
|
public function hasDevice(device:DeviceType):Bool {
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
for (d in binding.keys()) {
|
||||||
case TankAction.MOVE(direction):
|
if (d.equals(device)) {
|
||||||
if (moveQueue.indexOf(event.keyCode) == -1) {
|
return true;
|
||||||
moveQueue.unshift(event.keyCode);
|
}
|
||||||
updateMove();
|
|
||||||
}
|
|
||||||
case TankAction.SHOT:
|
|
||||||
if (shotTimer == null) {
|
|
||||||
shotTimer = new Timer(300);
|
|
||||||
shotTimer.run = shot;
|
|
||||||
shot();
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
if (event.keyCode == Keyboard.U) {
|
return false;
|
||||||
action(TankAction.UPGRADE);
|
}
|
||||||
|
|
||||||
|
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 {
|
override public function start():Void {
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
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):
|
case TankAction.MOVE(direction):
|
||||||
moveQueue.remove(event.keyCode);
|
if (on) {
|
||||||
|
if (moveQueue.indexOf(direction) == -1) {
|
||||||
|
moveQueue.unshift(direction);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
moveQueue.remove(direction);
|
||||||
|
}
|
||||||
updateMove();
|
updateMove();
|
||||||
case TankAction.SHOT:
|
case TankAction.SHOT(weapon):
|
||||||
if (shotTimer != null) {
|
if (on) {
|
||||||
shotTimer.stop();
|
if (!shotTimers.exists(weapon)) {
|
||||||
shotTimer = null;
|
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 {
|
private function updateMove():Void {
|
||||||
if (moveQueue.length == 0) {
|
if (moveQueue.length == 0) {
|
||||||
action(TankAction.STOP);
|
action(STOP);
|
||||||
} else {
|
} else {
|
||||||
switch (keyBinding.get(moveQueue[0])) {
|
action(MOVE(moveQueue[0]));
|
||||||
case TankAction.MOVE(direction):
|
|
||||||
action(TankAction.MOVE(direction));
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function shot():Void {
|
private function shooter(weapon:Int):Void -> Void {
|
||||||
action(TankAction.SHOT);
|
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,29 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.stretch: true
|
|
||||||
layout.hAlign: center
|
|
||||||
layout.vAlign: middle
|
|
||||||
views:
|
|
||||||
- $type: haxework.gui.LabelView
|
|
||||||
skinId: text
|
|
||||||
geometry.size.fixed.height: 20
|
|
||||||
text: Settings
|
|
||||||
- $type: haxework.gui.HGroupView
|
|
||||||
geometry.size.width: 100%
|
|
||||||
views:
|
|
||||||
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
|
||||||
geometry.size.percent.width: 50
|
|
||||||
#geometry.size.percent.height: 100
|
|
||||||
controlIndex: 0
|
|
||||||
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
|
||||||
geometry.size.percent.width: 50
|
|
||||||
#geometry.size.percent.height: 100
|
|
||||||
controlIndex: 1
|
|
||||||
- id: close
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
skinId: button.close
|
|
||||||
+onPress: $this:onPress
|
|
||||||
geometry.position: absolute
|
|
||||||
geometry.margin.left: 10
|
|
||||||
geometry.margin.bottom: 10
|
|
||||||
geometry.vAlign: bottom
|
|
||||||
geometry.hAlign: left
|
|
||||||
@@ -1,29 +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;
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
|
||||||
|
|
||||||
@:template class StartFrame extends VGroupView {
|
|
||||||
|
|
||||||
public static var ID(default, never):String = "start";
|
|
||||||
|
|
||||||
@:provide var frameSwitcher:FrameSwitcher;
|
|
||||||
@:provide var storage:SaveStorage;
|
|
||||||
|
|
||||||
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,45 +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.right: 10
|
|
||||||
geometry.margin.bottom: 10
|
|
||||||
geometry.vAlign: bottom
|
|
||||||
geometry.hAlign: right
|
|
||||||
text: $r:text:version
|
|
||||||
- id: settings
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
geometry.position: absolute
|
|
||||||
geometry.margin.left: 10
|
|
||||||
geometry.margin.bottom: 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,33 +0,0 @@
|
|||||||
package ru.m.tankz.frame.classic;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public var game:Game;
|
|
||||||
|
|
||||||
private function updateViews():Void {
|
|
||||||
bot.count.text = '${game.teams[ClassicGame.BOT].life}';
|
|
||||||
player1.count.text = '${game.teams[ClassicGame.HUMAN].players[0].state.life}';
|
|
||||||
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
|
|
||||||
player2.count.text = '${game.teams[ClassicGame.HUMAN].players[1].state.life}';
|
|
||||||
} else {
|
|
||||||
player2.count.text = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
if (game != null) {
|
|
||||||
updateViews();
|
|
||||||
}
|
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.padding: 5
|
|
||||||
layout.margin: 5
|
|
||||||
layout.hAlign: right
|
|
||||||
views:
|
|
||||||
- id: bot
|
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
|
||||||
image.image: $asset:image:resources/image/tank/ba-0.png
|
|
||||||
- id: player1
|
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
|
||||||
image.image: $asset:image:resources/image/tank/pa-0.png
|
|
||||||
image.color: 0xFFFF00
|
|
||||||
- id: player2
|
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
|
||||||
image.image: $asset:image:resources/image/tank/pa-0.png
|
|
||||||
image.color: 0x15C040
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package ru.m.tankz.frame.classic;
|
|
||||||
|
|
||||||
import haxework.gui.frame.FrameSwitcher;
|
|
||||||
import haxework.gui.DataView;
|
|
||||||
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>;
|
|
||||||
@:view var levels(default, null):DataView<Int>;
|
|
||||||
|
|
||||||
@: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,23 +0,0 @@
|
|||||||
---
|
|
||||||
layout:
|
|
||||||
$type: haxework.gui.layout.VerticalLayout
|
|
||||||
hAlign: center
|
|
||||||
views:
|
|
||||||
- id: presets
|
|
||||||
$type: haxework.gui.DataView<GamePreset>
|
|
||||||
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<Int>
|
|
||||||
layout:
|
|
||||||
$type: haxework.gui.layout.TailLayout
|
|
||||||
rowSize: 10
|
|
||||||
margin: 5
|
|
||||||
factory: $this:levelViewFactory
|
|
||||||
+onDataSelect: $code:function(value) level = value
|
|
||||||
geometry.padding: 10
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
package ru.m.tankz.frame.common;
|
|
||||||
|
|
||||||
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.game.GameState;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
import ru.m.tankz.render.Render;
|
|
||||||
import ru.m.tankz.sound.SoundManager;
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
|
||||||
|
|
||||||
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 storage:SaveStorage;
|
|
||||||
@: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(s:GameState):GameState {
|
|
||||||
panel.toUpdate();
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameComplete(result:Option<GameState>):Void {
|
|
||||||
switch (result) {
|
|
||||||
case Option.Some(s):
|
|
||||||
panel.toUpdate();
|
|
||||||
case Option.None:
|
|
||||||
}
|
|
||||||
switch (game.next()) {
|
|
||||||
case Option.Some(s):
|
|
||||||
var state = game.save();
|
|
||||||
this.state = state;
|
|
||||||
storage.write(state);
|
|
||||||
stop();
|
|
||||||
start(state);
|
|
||||||
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,59 +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.control.Control;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
|
||||||
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 storage:SaveStorage;
|
|
||||||
@:provide var resources:IResources;
|
|
||||||
|
|
||||||
private function set_gameType(value:GameType):GameType {
|
|
||||||
if (gameType != value) {
|
|
||||||
gameType = value;
|
|
||||||
config = configBundle.get(gameType);
|
|
||||||
preset = config.presets[0];
|
|
||||||
}
|
|
||||||
return gameType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_preset(value:GamePreset):GamePreset {
|
|
||||||
if (preset != value) {
|
|
||||||
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.control.set(playerId, player.control != null ? player.control : Control.BOT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,20 +0,0 @@
|
|||||||
package ru.m.tankz.frame.common;
|
|
||||||
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
import haxework.gui.LabelView;
|
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
|
||||||
|
|
||||||
|
|
||||||
@:template class LevelView extends HGroupView implements IListItemView<Int> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):Int;
|
|
||||||
|
|
||||||
@:view var label(default, null):LabelView;
|
|
||||||
|
|
||||||
private function set_data(value:Int):Int {
|
|
||||||
data = value;
|
|
||||||
label.text = 'Level ${data}';
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.width: 100%
|
|
||||||
geometry.size.height: 44
|
|
||||||
geometry.margin: 5
|
|
||||||
views:
|
|
||||||
- id: label
|
|
||||||
$type: haxework.gui.LabelView
|
|
||||||
skinId: text
|
|
||||||
geometry.size.stretch: true
|
|
||||||
text: ""
|
|
||||||
skin:
|
|
||||||
- $type: haxework.gui.skin.ColorSkin
|
|
||||||
color: 0x000000
|
|
||||||
alpha: 0.2
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package ru.m.tankz.frame.common;
|
|
||||||
|
|
||||||
import haxework.gui.LabelView;
|
|
||||||
import haxework.gui.ImageView;
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
|
|
||||||
@:template class LifeView extends HGroupView {
|
|
||||||
@:view public var image:ImageView;
|
|
||||||
@:view public var count:LabelView;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
layout.margin: 5
|
|
||||||
views:
|
|
||||||
- id: image
|
|
||||||
$type: haxework.gui.ImageView
|
|
||||||
- id: count
|
|
||||||
$type: haxework.gui.LabelView
|
|
||||||
skinId: text.box
|
|
||||||
geometry.size.fixed: [50, 38]
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package ru.m.tankz.frame.common;
|
|
||||||
|
|
||||||
import haxework.color.Color;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
import haxework.gui.LabelView;
|
|
||||||
import haxework.gui.list.ListView;
|
|
||||||
import haxework.gui.skin.Skin;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
@:template class PlayerView extends HGroupView implements IListItemView<PlayerId> {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
|
||||||
public var data(default, set):PlayerId;
|
|
||||||
|
|
||||||
@:view("index") var indexLabel(default, null):LabelView;
|
|
||||||
@:view var control(default, null):ButtonView;
|
|
||||||
|
|
||||||
@:provide var state:GameState;
|
|
||||||
@:provide var configBundle:IConfigBundle;
|
|
||||||
|
|
||||||
private function set_data(value:PlayerId):PlayerId {
|
|
||||||
data = value;
|
|
||||||
indexLabel.text = '${value.team} ${Std.string(data.index + 1)}';
|
|
||||||
var color = 0xffffff;
|
|
||||||
var config = configBundle.get(state.type);
|
|
||||||
var preset = config.getPreset(state.presetId);
|
|
||||||
for (team in preset.teams) {
|
|
||||||
if (team.id == data.team) {
|
|
||||||
color = team.color;
|
|
||||||
for (player in team.players) {
|
|
||||||
if (player.index == data.index) {
|
|
||||||
if (!player.color.zero) {
|
|
||||||
color = player.color;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
preset.teams;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
indexLabel.fontColor = color;
|
|
||||||
var controlType = state.control.get(value);
|
|
||||||
var image = Assets.getBitmapData('resources/image/ui/control/${controlType}.png');
|
|
||||||
control.skin = [Skin.buttonBitmap(image)];
|
|
||||||
indexLabel.update();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toggleControl():Void {
|
|
||||||
if (data != null && data.index > -1) {
|
|
||||||
var controlType = switch state.control.get(data) {
|
|
||||||
case Control.BOT: Control.HUMAN;
|
|
||||||
case Control.HUMAN: Control.BOT;
|
|
||||||
case _: Control.BOT;
|
|
||||||
}
|
|
||||||
state.control.set(data, controlType);
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.width: 200
|
|
||||||
geometry.size.height: 44
|
|
||||||
geometry.margin: 5
|
|
||||||
layout.margin: 10
|
|
||||||
views:
|
|
||||||
- id: index
|
|
||||||
$type: haxework.gui.LabelView
|
|
||||||
geometry.size.stretch: true
|
|
||||||
skin:
|
|
||||||
- $type: haxework.gui.skin.ColorSkin
|
|
||||||
color: 0x000000
|
|
||||||
alpha: 0.2
|
|
||||||
shadow: true
|
|
||||||
shadowColor: 0x000000
|
|
||||||
- id: control
|
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
+onPress: $code:toggleControl()
|
|
||||||
@@ -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,49 +0,0 @@
|
|||||||
package ru.m.tankz.frame.dota;
|
|
||||||
|
|
||||||
import ru.m.tankz.preset.DotaGame;
|
|
||||||
import ru.m.tankz.frame.common.LifeView;
|
|
||||||
import ru.m.tankz.frame.common.IGamePanel;
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
|
|
||||||
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
|
|
||||||
|
|
||||||
@:view var radiant:LifeView;
|
|
||||||
@:view var dire:LifeView;
|
|
||||||
|
|
||||||
public var game:Game;
|
|
||||||
|
|
||||||
private function stateString(game:Game):String {
|
|
||||||
if (game == null) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
var result:Array<String> = [];
|
|
||||||
result.push('Level: ${game.state.level}');
|
|
||||||
for (team in game.teams) {
|
|
||||||
if (game.loser == team.id) {
|
|
||||||
result.push('${team.id}: LOSE');
|
|
||||||
} else if (team.life > 0) {
|
|
||||||
result.push('${team.id}: ${team.life}');
|
|
||||||
} else {
|
|
||||||
for (player in team.players) {
|
|
||||||
if (player.state.life > 0) {
|
|
||||||
result.push('${player.id.team}${player.id.index}: ${player.state.life}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '[ ${result.join(' | ')} ]';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateViews():Void {
|
|
||||||
radiant.count.text = '${game.teams[DotaGame.RADIANT].life}';
|
|
||||||
dire.count.text = '${game.teams[DotaGame.DIRE].life}';
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
if (game != null) {
|
|
||||||
updateViews();
|
|
||||||
}
|
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
geometry.size.width: 100%
|
|
||||||
layout.margin: 20
|
|
||||||
views:
|
|
||||||
- id: radiant
|
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
|
||||||
image.image: $asset:image:resources/image/tank/bc-0.png
|
|
||||||
image.color: 0xff4422
|
|
||||||
- $type: haxework.gui.SpriteView
|
|
||||||
geometry.size.width: 100%
|
|
||||||
- id: dire
|
|
||||||
$type: ru.m.tankz.frame.common.LifeView
|
|
||||||
image.image: $asset:image:resources/image/tank/bc-0.png
|
|
||||||
image.color: 0x3284ff
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package ru.m.tankz.frame.dota;
|
|
||||||
|
|
||||||
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.preset.DotaGame;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
@:template class DotaLevelFrame extends LevelFrame {
|
|
||||||
public static inline var ID = "dota.level";
|
|
||||||
|
|
||||||
@:view var levels(default, null):DataView<Int>;
|
|
||||||
@:view var players(default, null):DataView<PlayerId>;
|
|
||||||
|
|
||||||
@:provide var frames:FrameSwitcher;
|
|
||||||
|
|
||||||
private function onShow():Void {
|
|
||||||
gameType = DotaGame.TYPE;
|
|
||||||
levels.data = [for (i in 0...config.game.levels) i];
|
|
||||||
var data = [];
|
|
||||||
for (team in preset.teams) {
|
|
||||||
for (p in team.players) {
|
|
||||||
data.push(new PlayerId(team.id, p.index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
players.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playerViewFactory(index:Int, player:PlayerId):PlayerView {
|
|
||||||
var view = new PlayerView();
|
|
||||||
view.item_index = index;
|
|
||||||
view.data = player;
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
override private function set_level(value:Int):Int {
|
|
||||||
var result = super.set_level(value);
|
|
||||||
frames.change(DotaGameFrame.ID);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
layout:
|
|
||||||
$type: haxework.gui.layout.HorizontalLayout
|
|
||||||
views:
|
|
||||||
- id: players
|
|
||||||
$type: haxework.gui.DataView<PlayerId>
|
|
||||||
layout:
|
|
||||||
$type: haxework.gui.layout.VerticalLayout
|
|
||||||
hAlign: center
|
|
||||||
factory: $this:playerViewFactory
|
|
||||||
geometry.padding: 10
|
|
||||||
- id: levels
|
|
||||||
$type: haxework.gui.DataView<Int>
|
|
||||||
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>;
|
|
||||||
@: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<ru.m.tankz.control.ActionItem>
|
|
||||||
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.network.NetworkManager;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
class NetworkControl extends HumanControl {
|
||||||
class ClientNetworkControl extends HumanControl {
|
|
||||||
|
|
||||||
@:provide private var network:NetworkManager;
|
@:provide private var network:NetworkManager;
|
||||||
|
|
||||||
override public function action(action:TankAction):Void {
|
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;
|
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 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.connect.IConnection;
|
||||||
import ru.m.tankz.proto.core.GameInfoProto;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
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.LoginRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
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>;
|
typedef ClientConnection = IConnection<Request, Response>;
|
||||||
|
|
||||||
|
enum ConnectionState {
|
||||||
|
OFFLINE;
|
||||||
|
CONNECT;
|
||||||
|
CONNECTED;
|
||||||
|
LOGIN;
|
||||||
|
ONLINE(user:User);
|
||||||
|
ERROR(error:Dynamic);
|
||||||
|
}
|
||||||
|
|
||||||
class NetworkManager {
|
class NetworkManager {
|
||||||
|
|
||||||
public var state(default, null):String;
|
public var state(default, null):ConnectionState;
|
||||||
public var stateSignal:Signal<String>;
|
public var room(default, null):RoomProto;
|
||||||
public var listGameSignal:Signal<Array<GameInfoProto>>;
|
public var user(default, null):UserProto;
|
||||||
public var gameSignal:Signal<GameInfoProto>;
|
|
||||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
public var stateSignal:Signal<ConnectionState>;
|
||||||
public var user(default, null):User;
|
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||||
public var game(default, set):NetworkGame;
|
public var roomSignal:Signal<RoomProto>;
|
||||||
|
public var gameEventSignal:Signal<GameEventResponse>;
|
||||||
|
|
||||||
@:provide private var connection:ClientConnection;
|
@: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() {
|
public function new() {
|
||||||
stateSignal = new Signal<String>();
|
reconnectDelay = 500;
|
||||||
listGameSignal = new Signal<Array<GameInfoProto>>();
|
stateSignal = new Signal();
|
||||||
gameSignal = new Signal<GameInfoProto>();
|
listRoomSignal = new Signal();
|
||||||
gameUpdateSignal = new Signal<Array<GameChangeProto>>();
|
roomSignal = new Signal();
|
||||||
updateState('offline');
|
gameEventSignal = new Signal();
|
||||||
|
updateState(OFFLINE);
|
||||||
connection.handler.connect(onConnectionEvent);
|
connection.handler.connect(onConnectionEvent);
|
||||||
connection.receiveHandler.connect(onResponse);
|
connection.receiveHandler.connect(onResponse);
|
||||||
user = storage.read();
|
//connect(); // ToDo: disable network
|
||||||
if (user == null) {
|
|
||||||
user = {name: 'User', uuid: null};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateState(value:String):Void {
|
private function updateState(value:ConnectionState):Void {
|
||||||
state = value;
|
state = value;
|
||||||
stateSignal.emit(value);
|
stateSignal.emit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(name:String):Void {
|
public function login(name:String, uuid:String = null):Void {
|
||||||
user.name = name;
|
updateState(LOGIN);
|
||||||
updateState('connect...');
|
connection.send(new Request().setLogin(
|
||||||
connection.connect().then(function(c:ClientConnection) {
|
new LoginRequest()
|
||||||
updateState('login...');
|
.setUuid(uuid)
|
||||||
c.send(new Request().setLogin(
|
.setName(name)
|
||||||
new LoginRequest()
|
));
|
||||||
.setUuid(user.uuid)
|
|
||||||
.setName(user.name)
|
|
||||||
));
|
|
||||||
}).catchError(function(_) {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listGame():Void {
|
public function logout():Void {
|
||||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createGame(type:String):Void {
|
public function listGame(subscribe:Bool):Void {
|
||||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type)));
|
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function joinGame(gameId:Int):Void {
|
public function createGame(type:String, level:Int):Void {
|
||||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
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 {
|
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 {
|
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 {
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
var update:GameUpdateRequest = switch action {
|
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
|
||||||
case TankAction.MOVE(direction):
|
new GameEventProto().setTime(0).setEvent(
|
||||||
new GameUpdateRequest()
|
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||||
.setType(GameActionTypeProto.MOVE)
|
)))
|
||||||
.setDirectionX(direction.x)
|
);
|
||||||
.setDirectionY(direction.y);
|
}
|
||||||
case TankAction.STOP:
|
|
||||||
new GameUpdateRequest()
|
private function connect():Void {
|
||||||
.setType(GameActionTypeProto.STOP);
|
if (reconnectTimer != null) {
|
||||||
case TankAction.SHOT:
|
reconnectTimer.stop();
|
||||||
new GameUpdateRequest()
|
reconnectTimer = null;
|
||||||
.setType(GameActionTypeProto.SHOT);
|
|
||||||
case _: null;
|
|
||||||
}
|
}
|
||||||
if (update != null) {
|
reconnectTimer = null;
|
||||||
connection.send(new Request().setUpdateGame(update));
|
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 {
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
updateState(switch (event) {
|
updateState(switch event {
|
||||||
case ConnectionEvent.CONNECTED:
|
case CONNECTED: CONNECTED;
|
||||||
L.d('Network', '$event');
|
case DISCONNECTED: OFFLINE;
|
||||||
'connected';
|
case ERROR(error): ERROR(error);
|
||||||
case ConnectionEvent.DISCONNECTED:
|
|
||||||
L.d('Network', '$event');
|
|
||||||
'offline';
|
|
||||||
case ConnectionEvent.ERROR(error):
|
|
||||||
L.e('Network', '$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 {
|
private function onResponse(packet:Response):Void {
|
||||||
if (packet.hasLogin()) {
|
if (packet.hasLogin()) {
|
||||||
user = {
|
this.user = packet.login.user;
|
||||||
uuid: packet.login.user.uuid,
|
var user = {
|
||||||
name: packet.login.user.name,
|
uuid: this.user.uuid,
|
||||||
|
name: this.user.name,
|
||||||
};
|
};
|
||||||
storage.write(user);
|
storage.user = user;
|
||||||
updateState('online');
|
updateState(ONLINE(user));
|
||||||
} else if (packet.hasLogout()) {
|
} else if (packet.hasLogout()) {
|
||||||
user = null;
|
storage.user = null;
|
||||||
updateState('connected');
|
updateState(CONNECTED);
|
||||||
} else if (packet.hasListGame()) {
|
} else if (packet.hasRoomList()) {
|
||||||
listGameSignal.emit(packet.listGame.games);
|
listRoomSignal.emit(packet.roomList.rooms);
|
||||||
} else if (packet.hasCreateGame()) {
|
} else if (packet.hasRoom()) {
|
||||||
gameSignal.emit(packet.createGame.game);
|
room = packet.room.room;
|
||||||
} else if (packet.hasJoinGame()) {
|
roomSignal.emit(room);
|
||||||
gameSignal.emit(packet.joinGame.game);
|
} else if (packet.hasGameEvent()) {
|
||||||
} else if (packet.hasLeaveGame()) {
|
gameEventSignal.emit(packet.gameEvent);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import haxework.gui.utils.BitmapUtil;
|
|
||||||
import haxework.color.Color;
|
|
||||||
import flash.display.BitmapData;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
import ru.m.tankz.core.Tank;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
class AnimateBundle {
|
class AnimateBundle {
|
||||||
|
|
||||||
@@ -44,27 +39,4 @@ class AnimateBundle {
|
|||||||
length: 5
|
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.DisplayObjectContainer;
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.text.TextField;
|
import flash.events.Event;
|
||||||
import flash.text.TextFormat;
|
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxework.gui.SpriteView;
|
import haxework.view.form.LabelView;
|
||||||
import haxework.provider.Provider;
|
import haxework.view.SpriteView;
|
||||||
import haxework.resources.IResources;
|
import promhx.Promise;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.render.RenderItem;
|
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;
|
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 backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
@@ -25,8 +37,7 @@ class Render extends SpriteView {
|
|||||||
private var upLayer:Sprite;
|
private var upLayer:Sprite;
|
||||||
private var upperLayer:Sprite;
|
private var upperLayer:Sprite;
|
||||||
|
|
||||||
private var background:Sprite;
|
private var items:Map<Int, IRenderItem>;
|
||||||
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
@@ -44,154 +55,222 @@ class Render extends SpriteView {
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function drawBackground(game:Engine):Void {
|
private function get_mapWidth():Float {
|
||||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
}
|
||||||
|
|
||||||
|
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;
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
setContentSize(mapWidth, mapHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:Engine):Void {
|
public function draw():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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
item.update();
|
item.update();
|
||||||
}
|
}
|
||||||
if (background == null) {
|
}
|
||||||
drawBackground(game);
|
|
||||||
}
|
private function onEnterFrame(event:Event):Void {
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clearLayer(layer:DisplayObjectContainer) {
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
while (layer.numChildren > 0) {
|
||||||
|
layer.removeChildAt(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset():Void {
|
public function reset():Void {
|
||||||
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
for (item in items.iterator()) {
|
for (item in items.iterator()) {
|
||||||
item.dispose();
|
item.dispose();
|
||||||
}
|
}
|
||||||
items = new Map();
|
items = new Map();
|
||||||
if (background != null) {
|
|
||||||
backgroundLayer.removeChild(background);
|
|
||||||
background = null;
|
|
||||||
}
|
|
||||||
clearLayer(entryLayer);
|
clearLayer(entryLayer);
|
||||||
clearLayer(groundLayer);
|
clearLayer(groundLayer);
|
||||||
clearLayer(upLayer);
|
clearLayer(upLayer);
|
||||||
clearLayer(upperLayer);
|
clearLayer(upperLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch(entity) {
|
switch event {
|
||||||
case EntityType.TANK(tank):
|
case START(start):
|
||||||
var item = new TankItem(tank);
|
gridSize = start.level.size;
|
||||||
items.set(tank.key, item);
|
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);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
playAnimate(tank.rect.center, AnimateBundle.tankSpawn());
|
case SPAWN(TANK(id, rect, playerId, info)):
|
||||||
case EntityType.BULLET(bullet):
|
var item = new TankRenderItem(rect);
|
||||||
var item = new BulletItem(bullet);
|
var tankConfig = config.getTank(info.type);
|
||||||
items.set(bullet.key, item);
|
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);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case EntityType.EAGLE(eagle):
|
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||||
var item = new EagleItem(eagle);
|
case SPAWN(BULLET(id, rect, playerId, skin)):
|
||||||
items.set(eagle.key, item);
|
var item = new BulletRenderItem(rect, skin);
|
||||||
|
items.set(id, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case EntityType.BONUS(bonus):
|
case SPAWN(BONUS(id, rect, type)):
|
||||||
var item = new BonusItem(bonus);
|
var item = new BonusRenderItem(rect, type);
|
||||||
items.set(bonus.key, item);
|
items.set(id, item);
|
||||||
upperLayer.addChild(item.view);
|
upperLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case _:
|
case MOVE(EAGLE(id, position)):
|
||||||
}
|
if (items.exists(id)) {
|
||||||
}
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
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 _:
|
case MOVE(BULLET(id, position)):
|
||||||
}
|
if (items.exists(id)) {
|
||||||
}
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
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 EntityType.BULLET(bullet):
|
case MOVE(TANK(id, position)):
|
||||||
if (items.exists(bullet.key)) {
|
if (items.exists(id)) {
|
||||||
entryLayer.removeChild(items.get(bullet.key).view);
|
var item = items[id];
|
||||||
items.remove(bullet.key);
|
item.move(position);
|
||||||
var point = bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y));
|
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());
|
playAnimate(point, AnimateBundle.bulletBoom());
|
||||||
|
items.remove(id);
|
||||||
}
|
}
|
||||||
case EntityType.BONUS(bonus):
|
case DESTROY(EAGLE(id, shot)):
|
||||||
if (items.exists(bonus.key)) {
|
if (items.exists(id)) {
|
||||||
upperLayer.removeChild(items.get(bonus.key).view);
|
var item = items[id];
|
||||||
items.remove(bonus.key);
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
if (bonus.config.score > 0) {
|
showScore(item.rect.center, shot.score);
|
||||||
showScore(bonus.rect.center, bonus.config.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 _:
|
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.x = point.x - animate.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
animate.play().then(function(animate:Animate):Void {
|
return animate.play().then(function(animate:Animate):Void {
|
||||||
// ToDo: clean animates on reset
|
// ToDo: clean animates on reset
|
||||||
if (upperLayer.contains(animate)) {
|
if (upperLayer.contains(animate)) {
|
||||||
upperLayer.removeChild(animate);
|
upperLayer.removeChildSafety(animate);
|
||||||
}
|
}
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function showScore(point:Point, score:Int):Void {
|
private function showScore(point:Point, score:Null<Int>):Void {
|
||||||
var view:TextField = new TextField();
|
if (score != null && score != 0) {
|
||||||
view.embedFonts = true;
|
var view:LabelView = new LabelView();
|
||||||
var font:String = Provider.get(IResources).text.get('font');
|
view.style = "text";
|
||||||
view.defaultTextFormat = new TextFormat(font, 28, 0xffffff);
|
view.text = Std.string(score);
|
||||||
view.text = Std.string(score);
|
view.update();
|
||||||
view.x = point.x - view.textWidth / 2;
|
view.redraw();
|
||||||
view.y = point.y - view.textHeight / 2;
|
view.x = point.x - view.width / 2;
|
||||||
upperLayer.addChild(view);
|
view.y = point.y - view.height / 2;
|
||||||
Timer.delay(function() upperLayer.removeChild(view), 1000);
|
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;
|
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 openfl.utils.Assets;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
|
class SoundManager implements GameListener {
|
||||||
class SoundManager {
|
private static var TAG(default, never):String = "SoundManager";
|
||||||
private static var TAG(default, never):String = 'SoundManager';
|
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
private static var type:String = 'mp3';
|
private static var type:String = "mp3";
|
||||||
#else
|
#else
|
||||||
private static var type:String = 'ogg';
|
private static var type:String = "ogg";
|
||||||
#end
|
#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 {
|
public function play(id:String):Void {
|
||||||
//L.d(TAG, 'play: ${id}');
|
//L.d(TAG, 'play: ${id}');
|
||||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
sound.play();
|
var channel = sound.play(0, 0, transform);
|
||||||
|
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||||
|
channels.push(channel);
|
||||||
} else {
|
} else {
|
||||||
L.w(TAG, 'Sound "${id}" not found');
|
L.w(TAG, 'Sound "${id}" not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function stopAll():Void {
|
||||||
switch entity {
|
for (channel in channels) {
|
||||||
case EntityType.BULLET(_.tank.playerId.team => 'human'):
|
channel.stop();
|
||||||
play('shot');
|
|
||||||
case EntityType.BONUS(_):
|
|
||||||
play('bonus_add');
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
|
channels = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChange(entity:EntityType, change:EntityChange):Void {
|
private function onSoundComplete(event:Event):Void {
|
||||||
switch [entity, change] {
|
channels.remove(event.currentTarget);
|
||||||
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 _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch [entity, with] {
|
switch event {
|
||||||
case [EntityType.BULLET(_), EntityType.CELL(cell)]:
|
case START(_):
|
||||||
//play('bullet_wall');
|
play("start");
|
||||||
case _:
|
humanTanks = [];
|
||||||
}
|
liveBonuses = [];
|
||||||
}
|
humanBullets = [];
|
||||||
|
case SPAWN(BULLET(id, _, playerId, _)):
|
||||||
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
if (config.isHuman(playerId)) {
|
||||||
switch entity {
|
play("shot");
|
||||||
case EntityType.TANK(_):
|
humanBullets.push(id);
|
||||||
play('boom_bot');
|
}
|
||||||
case EntityType.BONUS(_):
|
case SPAWN(TANK(id, _, playerId, _)):
|
||||||
play('bonus_get');
|
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 _:
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user