Compare commits
1 Commits
develop
...
d124588e70
| Author | SHA1 | Date | |
|---|---|---|---|
| d124588e70 |
@@ -8,6 +8,5 @@ indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
|
||||
@@ -19,6 +19,3 @@ DOCKER_PROJECTS=(
|
||||
DOCKER_ARGS=(
|
||||
"PROJECT_NAME=$PROJECT"
|
||||
)
|
||||
|
||||
NEKO_SDK="$SDK_PATH/neko/2.2.0"
|
||||
HAXE_SDK="$SDK_PATH/haxe/4.2.5"
|
||||
11
ansible/ansible.cfg
Normal file
11
ansible/ansible.cfg
Normal file
@@ -0,0 +1,11 @@
|
||||
[defaults]
|
||||
hash_behaviour = merge
|
||||
host_key_checking = False
|
||||
#callback_whitelist = profile_tasks
|
||||
display_skipped_hosts = False
|
||||
stdout_callback = yaml
|
||||
bin_ansible_callbacks = True
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
||||
ssh_args = -o ForwardAgent=yes
|
||||
14
ansible/deploy.yml
Normal file
14
ansible/deploy.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
ansible_user: "{{ deploy_user }}"
|
||||
roles:
|
||||
- ansible-deploy
|
||||
- build
|
||||
post_tasks:
|
||||
- include_role:
|
||||
name: ansible-deploy
|
||||
tasks_from: complete.yml
|
||||
- include_role:
|
||||
name: service
|
||||
tasks_from: restart.yml
|
||||
2
ansible/dev/inventory.yml
Normal file
2
ansible/dev/inventory.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
hosts: localhost
|
||||
15
ansible/group_vars/all.yml
Normal file
15
ansible/group_vars/all.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
project_name: tankz
|
||||
project_user: holop
|
||||
|
||||
deploy_user: "{{ project_user }}"
|
||||
deploy_project: "{{ project_name }}"
|
||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||
deploy_repo_version: develop
|
||||
deploy_npm: yes
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
service_work_dir: "{{ deploy_current_dir }}/target/server/cpp"
|
||||
service_command: "{{ service_work_dir }}/{{ project_name }} {{ service_host }}"
|
||||
service_user: www-data
|
||||
service_control_user: "{{ project_user }}"
|
||||
5
ansible/prod/inventory.yml
Normal file
5
ansible/prod/inventory.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
all:
|
||||
hosts: shmyga.ru
|
||||
vars:
|
||||
service_host: 213.139.208.180
|
||||
config_src: "/home/holop/tankz/config.json"
|
||||
7
ansible/requirements.yml
Normal file
7
ansible/requirements.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: ansible-deploy
|
||||
src: git@bitbucket.org:shmyga/ansible-deploy.git
|
||||
version: master
|
||||
scm: git
|
||||
|
||||
- name: geerlingguy.nodejs
|
||||
2
ansible/roles/build/defaults/main.yml
Normal file
2
ansible/roles/build/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
config_src: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json"
|
||||
config_dest: "{{ deploy_release_dir }}/config.json"
|
||||
11
ansible/roles/build/tasks/main.yml
Normal file
11
ansible/roles/build/tasks/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: "Copy config"
|
||||
copy:
|
||||
src: "{{ config_src }}"
|
||||
dest: "{{ config_dest }}"
|
||||
remote_src: true
|
||||
|
||||
- name: "Gulp build"
|
||||
command: "{{ deploy_release_dir }}/node_modules/.bin/gulp default --host shmyga.ru"
|
||||
args:
|
||||
chdir: "{{ deploy_release_dir }}"
|
||||
6
ansible/roles/service/defaults/main.yml
Normal file
6
ansible/roles/service/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
service_name: null
|
||||
service_description: "{{ service_name }} service"
|
||||
service_work_dir: null
|
||||
service_command: null
|
||||
service_user: null
|
||||
service_control_user: null
|
||||
21
ansible/roles/service/tasks/main.yml
Normal file
21
ansible/roles/service/tasks/main.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: "Install {{ service_name }} systemd unit file"
|
||||
template:
|
||||
src: "template/service.j2"
|
||||
dest: "/etc/systemd/system/{{ service_name }}.service"
|
||||
|
||||
- name: "Start {{ service_name }} service"
|
||||
systemd:
|
||||
enabled: yes
|
||||
state: started
|
||||
name: "{{ service_name }}"
|
||||
daemon_reload: yes
|
||||
|
||||
- name: "Add sudoers record for {{ service_name }} service"
|
||||
lineinfile:
|
||||
path: /etc/sudoers.d/{{ service_name }}
|
||||
state: present
|
||||
create: yes
|
||||
regexp: "^{{ service_control_user }} ALL="
|
||||
line: "{{ service_control_user }} ALL= NOPASSWD: /bin/systemctl * {{ service_name }}"
|
||||
validate: "/usr/sbin/visudo -cf %s"
|
||||
11
ansible/roles/service/tasks/restart.yml
Normal file
11
ansible/roles/service/tasks/restart.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# - name: "Restart {{ service_name }} service"
|
||||
# systemd:
|
||||
# enabled: yes
|
||||
# state: restarted
|
||||
# name: "{{ service_name }}"
|
||||
|
||||
- name: "Restart {{ service_name }} service"
|
||||
command: "sudo /bin/systemctl restart {{ service_name }}"
|
||||
args:
|
||||
warn: no
|
||||
15
ansible/roles/service/template/service.j2
Normal file
15
ansible/roles/service/template/service.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description={{ service_description }}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
PIDFile=/var/run/{{ service_name }}.pid
|
||||
WorkingDirectory={{ service_work_dir }}
|
||||
User={{ service_user }}
|
||||
Group={{ service_user }}
|
||||
ExecStart={{ service_command }}
|
||||
TimeoutSec=300
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
3
ansible/roles/setup/tasks/apt.yml
Normal file
3
ansible/roles/setup/tasks/apt.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
- name: "Install neko package"
|
||||
apt:
|
||||
name: neko
|
||||
2
ansible/roles/setup/tasks/main.yml
Normal file
2
ansible/roles/setup/tasks/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
- import_tasks: apt.yml
|
||||
when: ansible_distribution|lower == 'ubuntu'
|
||||
1
ansible/roles/user/keys/shmyga.pub
Normal file
1
ansible/roles/user/keys/shmyga.pub
Normal file
@@ -0,0 +1 @@
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCot1zSeqj7Tj5/7aNMzXAuXQPPxudYFV9z6M03dPijh2bXyHDcXk53xUO8XY5R4GyLhvAn98axbPM++urKY8BXuQqAG36soI7iZJ/KcPY1EKDwVBeZneFC/wMc8HMT0hj9+uHcGAMtmklIgPPkawzLxbEh6oAY4H8Vvz08qyco6suYB5NjkpFwVMf9Xa2Fj8rTodKpPRDBh/Xk+5bh11RKL6b9WcwuwpKU8zl2qZiqNfjr0H+sKEk7ohcYvzSCltLdKJcoKbiCcnrnBJT5/JpGWeAbA2MMmvmt/dJrHykd1CbmXW2DuG4tIlwMb5xU739PoKCePctK1retb8TrWOLT shmyga@shmyga-desktop
|
||||
40
ansible/roles/user/tasks/main.yml
Normal file
40
ansible/roles/user/tasks/main.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
# barin
|
||||
- name: Make barin group
|
||||
group:
|
||||
name: barin
|
||||
state: present
|
||||
|
||||
- name: Make barin user
|
||||
user:
|
||||
name: barin
|
||||
group: barin
|
||||
password: '$6$mbw5KZWwtrRUy$eFcMNTW.QzG1Em45r5hZf/qri4hKAHImozWuW4/pYnDK.tOrVKrXTKYfRDtYEFRgCgVVg0zuPvyq/xn0KiKlz0'
|
||||
groups: www-data,sudo,adm
|
||||
|
||||
- name: Set up authorized_keys for the barin user
|
||||
authorized_key:
|
||||
user: barin
|
||||
key: '{{ item }}'
|
||||
with_file:
|
||||
- keys/shmyga.pub
|
||||
|
||||
|
||||
# holop
|
||||
- name: Make holop group
|
||||
group:
|
||||
name: holop
|
||||
state: present
|
||||
|
||||
- name: Make holop user
|
||||
user:
|
||||
name: holop
|
||||
group: holop
|
||||
password: '$6$B/7g0xlcXFCIHk$hzSjb8KLll7YrTsp3z640sxNixNAkLpm6UUdZgWPh0Ffy7Ue18AiXTzkDdGTaTH6Woz4kvgVDSggnKGTU6u03.'
|
||||
groups: www-data
|
||||
|
||||
- name: Set up authorized_keys for the holop user
|
||||
authorized_key:
|
||||
user: holop
|
||||
key: '{{ item }}'
|
||||
with_file:
|
||||
- keys/shmyga.pub
|
||||
1
ansible/roles/user/vars/main.yml
Normal file
1
ansible/roles/user/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
ansible_become: yes
|
||||
8
ansible/service.yml
Normal file
8
ansible/service.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
ansible_user: "{{ deploy_user }}"
|
||||
tasks:
|
||||
- include_role:
|
||||
name: service
|
||||
tasks_from: restart.yml
|
||||
16
ansible/setup.yml
Normal file
16
ansible/setup.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
- hosts:
|
||||
- all
|
||||
pre_tasks:
|
||||
- include_role:
|
||||
name: ansible-deploy
|
||||
tasks_from: facts.yml
|
||||
roles:
|
||||
- geerlingguy.nodejs
|
||||
- setup
|
||||
- service
|
||||
vars:
|
||||
nodejs_version: 9.x
|
||||
nodejs_npm_global_packages: [gulp-cli]
|
||||
vars_files:
|
||||
- vars/barin.yml
|
||||
4
ansible/user.yml
Normal file
4
ansible/user.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- hosts: all
|
||||
gather_facts: no
|
||||
roles:
|
||||
- user
|
||||
4
ansible/vars/barin.yml
Normal file
4
ansible/vars/barin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
ansible_user: barin
|
||||
ansible_become_pass: 1234!QAZ
|
||||
ansible_become: yes
|
||||
243
gulpfile.js
243
gulpfile.js
@@ -1,28 +1,26 @@
|
||||
const gulp = require("gulp");
|
||||
const gulpClean = require("gulp-clean");
|
||||
const Config = require("./config.json");
|
||||
const packageInfo = require("./package.json");
|
||||
const { System, Sdk, Haxe, Project } = require("gulp-haxetool");
|
||||
const dateformat = require("dateformat");
|
||||
const argv = require("yargs").argv;
|
||||
const publish = require("./tasks/gulp-publish");
|
||||
|
||||
Project.useRuffle();
|
||||
const gulp = require('gulp');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const Config = require('./config.json');
|
||||
const packageInfo = require('./package.json');
|
||||
const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
|
||||
const dateformat = require('dateformat');
|
||||
const argv = require('yargs').argv;
|
||||
const publish = require('./tasks/gulp-publish');
|
||||
|
||||
if (packageInfo.haxe) {
|
||||
Haxe.VERSION = packageInfo.haxe;
|
||||
Haxe.VERSION = packageInfo.haxe;
|
||||
}
|
||||
|
||||
if (Config.SdkDir) {
|
||||
Sdk.dir = Config.SdkDir;
|
||||
Sdk.dir = Config.SdkDir;
|
||||
}
|
||||
|
||||
if (Config.BuildDir) {
|
||||
Haxe.buildDir = Config.BuildDir;
|
||||
Haxe.buildDir = Config.BuildDir;
|
||||
}
|
||||
|
||||
exports.clean = function clean() {
|
||||
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
||||
};
|
||||
|
||||
exports.setup = function setup() {
|
||||
@@ -50,146 +48,167 @@ exports.generate = function generate() {
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
title: "Tank'z",
|
||||
filename: "tankz",
|
||||
icon: "src/client/resources/icon.png",
|
||||
pack: "ru.m.tankz",
|
||||
author: "shmyga <shmyga.z@gmail.com>",
|
||||
company: "MegaLoMania",
|
||||
version: packageInfo.version + (Config.Develop ? "-SNAPSHOT" : ""),
|
||||
},
|
||||
key: Config.Key,
|
||||
libs: packageInfo.haxeDependencies,
|
||||
sources: ["src/common/haxe", "src-gen/haxe"],
|
||||
assets: ["src/common/resources/config"],
|
||||
flags: ["proto_debug"],
|
||||
macros: [
|
||||
`CompilationOption.set('build','${dateformat(new Date(), "yyyy-mm-dd HH:MM:ss")}')`,
|
||||
],
|
||||
meta: {
|
||||
title: 'Tank\'z',
|
||||
filename: 'tankz',
|
||||
icon: 'src/client/resources/icon.png',
|
||||
pack: 'ru.m.tankz',
|
||||
author: 'shmyga <shmyga.z@gmail.com>',
|
||||
company: 'MegaLoMania',
|
||||
version: packageInfo.version + (Config.Develop ? '-SNAPSHOT' : ''),
|
||||
},
|
||||
key: Config.Key,
|
||||
libs: packageInfo.haxeDependencies,
|
||||
sources: [
|
||||
'src/common/haxe',
|
||||
'src-gen/haxe',
|
||||
],
|
||||
assets: [
|
||||
'src/common/resources/config',
|
||||
],
|
||||
flags: [
|
||||
'proto_debug',
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||
]
|
||||
});
|
||||
|
||||
const host = argv.host || "localhost";
|
||||
const host = argv.host || 'localhost';
|
||||
const port = argv.port || 5000;
|
||||
|
||||
/**
|
||||
* client
|
||||
*/
|
||||
const client = new Project(
|
||||
Project.BuildSystem.OPENFL,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
Project.Platform.WINDOWS,
|
||||
Project.Platform.ANDROID,
|
||||
],
|
||||
config.branch({
|
||||
name: "client",
|
||||
sources: ["src/client/haxe"],
|
||||
main: "ru.m.tankz.Client",
|
||||
preloader: "ru.m.tankz.Preloader",
|
||||
assets: ["src/common/resources/level", "src/client/resources"],
|
||||
meta: {
|
||||
width: 1024,
|
||||
height: 576,
|
||||
},
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
//'dom',
|
||||
//'dev_layout',
|
||||
//'bitmap_text',
|
||||
Project.BuildSystem.OPENFL,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
Project.Platform.WINDOWS,
|
||||
Project.Platform.ANDROID,
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('host','${host}')`,
|
||||
`CompilationOption.set('port',${port})`,
|
||||
],
|
||||
}),
|
||||
config.branch({
|
||||
name: 'client',
|
||||
sources: [
|
||||
'src/client/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.Client',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
'src/common/resources/level',
|
||||
'src/client/resources',
|
||||
],
|
||||
meta: {
|
||||
width: 1024,
|
||||
height: 576,
|
||||
},
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
//'dom',
|
||||
//'dev_layout',
|
||||
//'bitmap_text',
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('host','${host}')`,
|
||||
`CompilationOption.set('port',${port})`,
|
||||
]
|
||||
}),
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* editor
|
||||
*/
|
||||
const editor = new Project(
|
||||
Project.BuildSystem.OPENFL,
|
||||
[Project.Platform.FLASH, Project.Platform.HTML5, Project.Platform.LINUX],
|
||||
config.branch({
|
||||
name: "editor",
|
||||
sources: ["src/client/haxe", "src/editor/haxe"],
|
||||
main: "ru.m.tankz.editor.Editor",
|
||||
preloader: "ru.m.tankz.Preloader",
|
||||
assets: ["src/client/resources", "src/editor/resources"],
|
||||
meta: {
|
||||
filename: "editor",
|
||||
pack: "ru.m.tankz.editor",
|
||||
width: 1024,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'dev_layout',
|
||||
Project.BuildSystem.OPENFL,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
],
|
||||
}),
|
||||
config.branch({
|
||||
name: 'editor',
|
||||
sources: [
|
||||
'src/client/haxe',
|
||||
'src/editor/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.editor.Editor',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
'src/client/resources',
|
||||
'src/editor/resources',
|
||||
],
|
||||
meta: {
|
||||
filename: 'editor',
|
||||
pack: 'ru.m.tankz.editor',
|
||||
width: 1024,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'dev_layout',
|
||||
]
|
||||
})
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* server
|
||||
*/
|
||||
const server = new Project(
|
||||
Project.BuildSystem.HAXE,
|
||||
Project.Platform.CPP,
|
||||
config.branch({
|
||||
name: "server",
|
||||
sources: ["src/server/haxe"],
|
||||
main: "ru.m.tankz.server.Server",
|
||||
assets: ["src/common/resources/level"],
|
||||
}),
|
||||
Project.BuildSystem.HAXE,
|
||||
Project.Platform.CPP,
|
||||
config.branch({
|
||||
name: 'server',
|
||||
sources: ['src/server/haxe'],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
assets: [
|
||||
'src/common/resources/level',
|
||||
]
|
||||
}),
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
module.exports.publish = publish(
|
||||
packageInfo.name,
|
||||
packageInfo.version,
|
||||
Config.PublishDir,
|
||||
Config.PublishUrl,
|
||||
);
|
||||
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
|
||||
|
||||
/**
|
||||
* default
|
||||
*/
|
||||
const defaultSeries = [
|
||||
exports.clean,
|
||||
exports.generate,
|
||||
module.exports["client:flash:build"],
|
||||
module.exports["client:flash:html"],
|
||||
module.exports["client:html5:build"],
|
||||
exports.clean,
|
||||
exports.generate,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:flash:html'],
|
||||
module.exports['client:html5:build'],
|
||||
|
||||
module.exports["editor:flash:build"],
|
||||
module.exports["editor:flash:html"],
|
||||
module.exports["editor:html5:build"],
|
||||
module.exports['editor:flash:build'],
|
||||
module.exports['editor:flash:html'],
|
||||
module.exports['editor:html5:build'],
|
||||
|
||||
module.exports["server:cpp:build"],
|
||||
module.exports['server:cpp:build'],
|
||||
];
|
||||
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(
|
||||
module.exports["client:linux:build"],
|
||||
module.exports["client:linux:archive"],
|
||||
module.exports["client:linux:deb"],
|
||||
defaultSeries.push(
|
||||
module.exports['client:linux:build'],
|
||||
module.exports['client:linux:archive'],
|
||||
module.exports['client:linux:deb'],
|
||||
|
||||
module.exports["client:android:build"],
|
||||
);
|
||||
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(
|
||||
module.exports['client:windows:build'],
|
||||
module.exports['client:windows:archive'],
|
||||
module.exports['client:windows:installer'],
|
||||
);
|
||||
}
|
||||
|
||||
defaultSeries.push(exports.publish);
|
||||
defaultSeries.push(
|
||||
exports.publish,
|
||||
);
|
||||
|
||||
module.exports.default = gulp.series(defaultSeries);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
{
|
||||
"indentation": {
|
||||
"character": " "
|
||||
},
|
||||
"wrapping": {
|
||||
"maxLineLength": 120
|
||||
}
|
||||
}
|
||||
|
||||
14741
package-lock.json
generated
14741
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,11 @@
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "^0.2.1",
|
||||
"gulp-haxetool": "^0.1.9",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"haxework": "2.1.1",
|
||||
"haxework": "2.1.0",
|
||||
"lime": "8.0.0",
|
||||
"openfl": "9.2.0",
|
||||
"hxcpp": "4.2.1",
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
set -e
|
||||
cd "$(dirname $(dirname "$0"))" || exit
|
||||
|
||||
source .env
|
||||
source $NEKO_SDK/activate
|
||||
source $HAXE_SDK/activate
|
||||
haxelib install formatter
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
set -e
|
||||
cd "$(dirname $(dirname "$0"))" || exit
|
||||
|
||||
source .env
|
||||
source $NEKO_SDK/activate
|
||||
source $HAXE_SDK/activate
|
||||
haxelib install formatter
|
||||
|
||||
@@ -1,42 +1,44 @@
|
||||
package ru.m;
|
||||
|
||||
@:enum abstract Platform(String) from String to String {
|
||||
var ANDROID = "android";
|
||||
var LINUX = "linux";
|
||||
var WINDOWS = "windows";
|
||||
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
|
||||
}
|
||||
public static var platform(get, null):Platform;
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,51 +5,52 @@ import flash.display.BitmapData;
|
||||
import flash.display.PixelSnapping;
|
||||
|
||||
typedef Frame = {
|
||||
var image:BitmapData;
|
||||
var length:Int;
|
||||
var image:BitmapData;
|
||||
var length:Int;
|
||||
}
|
||||
|
||||
class Animate extends Bitmap {
|
||||
public var playing(default, default):Bool;
|
||||
public var frames(default, set):Array<Frame>;
|
||||
|
||||
private var sequence:Array<BitmapData>;
|
||||
private var index:Int;
|
||||
public var playing(default, default):Bool;
|
||||
public var frames(default, set):Array<Frame>;
|
||||
|
||||
@:provide private static var manager:AnimateManager;
|
||||
private var sequence:Array<BitmapData>;
|
||||
private var index:Int;
|
||||
|
||||
public function new(?frames:Array<Frame>) {
|
||||
super(null, PixelSnapping.AUTO, true);
|
||||
this.frames = frames == null ? [] : frames;
|
||||
manager.add(this);
|
||||
}
|
||||
@:provide private static var manager:AnimateManager;
|
||||
|
||||
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||
sequence = [];
|
||||
index = 0;
|
||||
if (value != null) {
|
||||
frames = value;
|
||||
for (frame in frames) {
|
||||
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||
}
|
||||
bitmapData = sequence[0];
|
||||
} else {
|
||||
bitmapData = null;
|
||||
public function new(?frames:Array<Frame>) {
|
||||
super(null, PixelSnapping.AUTO, true);
|
||||
this.frames = frames == null ? [] : frames;
|
||||
manager.add(this);
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (++index >= sequence.length) {
|
||||
index = 0;
|
||||
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||
sequence = [];
|
||||
index = 0;
|
||||
if (value != null) {
|
||||
frames = value;
|
||||
for (frame in frames) {
|
||||
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||
}
|
||||
bitmapData = sequence[0];
|
||||
} else {
|
||||
bitmapData = null;
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
var nextBitmapData = sequence[index];
|
||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||
bitmapData = nextBitmapData;
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
manager.remove(this);
|
||||
}
|
||||
public function update():Void {
|
||||
if (++index >= sequence.length) {
|
||||
index = 0;
|
||||
}
|
||||
var nextBitmapData = sequence[index];
|
||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||
bitmapData = nextBitmapData;
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
manager.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
package ru.m.animate;
|
||||
|
||||
@:provide class AnimateManager {
|
||||
public var playing(default, default):Bool;
|
||||
public var playing(default, default):Bool;
|
||||
|
||||
private var timer:Timer;
|
||||
private var animations:Array<Animate>;
|
||||
private var timer:Timer;
|
||||
private var animations:Array<Animate>;
|
||||
|
||||
public function new() {
|
||||
animations = [];
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
}
|
||||
public function new() {
|
||||
animations = [];
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (playing) {
|
||||
for (animation in animations) {
|
||||
if (animation.playing) {
|
||||
animation.update();
|
||||
public function update():Void {
|
||||
if (playing) {
|
||||
for (animation in animations) {
|
||||
if (animation.playing) {
|
||||
animation.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add(animate:Animate):Void {
|
||||
animations.push(animate);
|
||||
}
|
||||
|
||||
public function remove(animate:Animate):Void {
|
||||
if (animations.indexOf(animate) > -1) {
|
||||
animations.remove(animate);
|
||||
public function add(animate:Animate):Void {
|
||||
animations.push(animate);
|
||||
}
|
||||
|
||||
public function remove(animate:Animate):Void {
|
||||
if (animations.indexOf(animate) > -1) {
|
||||
animations.remove(animate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,23 @@ import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
|
||||
class OnceAnimate extends Animate {
|
||||
private var deferred:Deferred<Animate>;
|
||||
|
||||
public function play():Promise<Animate> {
|
||||
deferred = new Deferred();
|
||||
playing = true;
|
||||
return deferred.promise();
|
||||
}
|
||||
private var deferred:Deferred<Animate>;
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (index == 0) {
|
||||
playing = false;
|
||||
if (deferred != null) {
|
||||
deferred.resolve(this);
|
||||
}
|
||||
dispose();
|
||||
public function play():Promise<Animate> {
|
||||
deferred = new Deferred();
|
||||
playing = true;
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (index == 0) {
|
||||
playing = false;
|
||||
if (deferred != null) {
|
||||
deferred.resolve(this);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,39 +4,40 @@ import hw.signal.Signal;
|
||||
import ru.m.control.IControlBus;
|
||||
|
||||
class ControlBus implements IControlBus {
|
||||
private static inline var TAG = "control";
|
||||
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
private static inline var TAG = "control";
|
||||
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
|
||||
public function new() {
|
||||
devices = [];
|
||||
signal = new Signal3();
|
||||
devicesSignal = new Signal();
|
||||
connections = new Map();
|
||||
}
|
||||
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
||||
|
||||
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);
|
||||
public function new() {
|
||||
devices = [];
|
||||
signal = new Signal3();
|
||||
devicesSignal = new Signal();
|
||||
connections = new Map();
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package ru.m.control;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
enum DeviceAction {
|
||||
DIRECTION(direction:Direction);
|
||||
KEY(code:Int);
|
||||
DIRECTION(direction:Direction);
|
||||
KEY(code:Int);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package ru.m.control;
|
||||
import hw.signal.Signal;
|
||||
|
||||
interface IControlBus {
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
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 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;
|
||||
public function connect(device:IControlDevice):Void;
|
||||
public function disconnect(device:IControlDevice):Void;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package ru.m.control;
|
||||
import hw.signal.Signal;
|
||||
|
||||
interface IControlDevice {
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public function dispose():Void;
|
||||
public function dispose():Void;
|
||||
}
|
||||
|
||||
@@ -7,55 +7,56 @@ 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 var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
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 var joystick:Joystick;
|
||||
private var axisState:Map<Int, Direction>;
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,32 +6,33 @@ import hw.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 var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
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 var stage:Stage;
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ 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);
|
||||
public static function childrenIterator():Iterator<DisplayObject> {
|
||||
throw "Not implemented";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,47 +9,48 @@ using StringTools;
|
||||
using hw.color.ColorUtil;
|
||||
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
@:style(false) private var solid:Null<Bool>;
|
||||
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
@:style(false) private var solid:Null<Bool>;
|
||||
|
||||
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
this.solid = solid;
|
||||
init(solid);
|
||||
}
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||
}
|
||||
|
||||
private function init(solid:Bool):Void {
|
||||
var color = color;
|
||||
if (solid) {
|
||||
color = color.multiply(1.5);
|
||||
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
this.solid = solid;
|
||||
init(solid);
|
||||
}
|
||||
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 {
|
||||
var svg = svgs.get(view.state);
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
if (!solid) {
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||
}
|
||||
|
||||
private function init(solid:Bool):Void {
|
||||
var color = color;
|
||||
if (solid) {
|
||||
color = color.multiply(1.5);
|
||||
}
|
||||
svgs = new Map();
|
||||
svgs.set(UP, buildSVG(color));
|
||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
var svg = svgs.get(view.state);
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
if (!solid) {
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
}
|
||||
// ToDo: padding
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
// ToDo: padding
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,164 +15,186 @@ import ru.m.skin.ButtonSVGSkin;
|
||||
using hw.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, {base: "3h", big: "4h", veryBig: "4.5h"});
|
||||
}
|
||||
public static var COLORS(default, never):ThemeColors = {
|
||||
light: 0x95937D,
|
||||
dark: 0x777564,
|
||||
text: 0xE7E0BB,
|
||||
active: 0xFFFF00,
|
||||
}
|
||||
|
||||
override private function reload():Void {
|
||||
super.reload();
|
||||
register(new Style("light", ["skin.background.color" => colors.light,]));
|
||||
public function new() {
|
||||
super({embed: true}, COLORS, {base: "3h", big: "4h", veryBig: "4.5h"});
|
||||
}
|
||||
|
||||
register(new Style("dark", ["skin.background.color" => colors.dark,]));
|
||||
override private function reload():Void {
|
||||
super.reload();
|
||||
register(new Style("light", [
|
||||
"skin.background.color" => colors.light,
|
||||
]));
|
||||
|
||||
register(new Style("font", ["_" => null,], ["text"]));
|
||||
register(new Style("dark", [
|
||||
"skin.background.color" => colors.dark,
|
||||
]));
|
||||
|
||||
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("font", [
|
||||
"_" => null,
|
||||
], ["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.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.small", [
|
||||
"font.size" => SizeValue.fromString("3h"),
|
||||
"geometry.padding" => Box.fromArray([8, 2]),
|
||||
"skin.round" => 5,
|
||||
], ["button"]));
|
||||
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("button.small", [
|
||||
"font.size" => SizeValue.fromString("3h"),
|
||||
"geometry.padding" => Box.fromArray([8, 2]),
|
||||
"skin.round" => 5,
|
||||
], ["button"]));
|
||||
|
||||
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("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("button.level", [
|
||||
"font.size" => fontSize.big,
|
||||
"geometry.width" => SizeValue.fromString("12h"),
|
||||
"geometry.height" => SizeValue.fromString("12h"),
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
], ["button"]));
|
||||
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("container", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromString("100%"),
|
||||
"layout.hAlign" => HAlign.CENTER,
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["dark"]));
|
||||
register(new Style("button.level", [
|
||||
"font.size" => fontSize.big,
|
||||
"geometry.width" => SizeValue.fromString("12h"),
|
||||
"geometry.height" => SizeValue.fromString("12h"),
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("panel", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.padding" => Box.fromArray([20, 10]),
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["light"]));
|
||||
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_button",
|
||||
["font.size" => fontSize.big, "geometry.height" => SizeValue.fromString("100%"),], ["button"]));
|
||||
register(new Style("panel", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.padding" => Box.fromArray([20, 10]),
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["light"]));
|
||||
|
||||
register(new Style("window", ["geometry.padding" => Box.fromFloat(2),], ["dark", "border"]));
|
||||
register(new Style("panel_button", [
|
||||
"font.size" => fontSize.big,
|
||||
"geometry.height" => SizeValue.fromString("100%"),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("line", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromInt(2),
|
||||
], ["border"]));
|
||||
register(new Style("window", [
|
||||
"geometry.padding" => Box.fromFloat(2),
|
||||
], ["dark", "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.fromString("8h"),
|
||||
"geometry.height" => SizeValue.fromString("8h"),
|
||||
]));
|
||||
register(new Style("line", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromInt(2),
|
||||
], ["border"]));
|
||||
|
||||
register(new Style("icon.tank", [
|
||||
"geometry.width" => SizeValue.fromString("6h"),
|
||||
"geometry.height" => SizeValue.fromString("6h"),
|
||||
"skin.fillType" => FillType.CONTAIN,
|
||||
]));
|
||||
register(new Style("window.close", [
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), colors.light),
|
||||
"geometry.width" => SizeValue.fromString("8h"),
|
||||
"geometry.height" => SizeValue.fromString("8h"),
|
||||
]));
|
||||
|
||||
var green:Color = 0x00ff00;
|
||||
var red:Color = 0xff0000;
|
||||
register(new Style("result.winner", [
|
||||
"skin.border.color" => green,
|
||||
"skin.border.alpha" => 0.5,
|
||||
"skin.border.thickness" => 5,
|
||||
"skin.round" => 10,
|
||||
], ["light"]));
|
||||
register(new Style("result.loser", [
|
||||
"skin.border.color" => red,
|
||||
"skin.border.alpha" => 0.5,
|
||||
"skin.border.thickness" => 5,
|
||||
"skin.round" => 10,
|
||||
], ["light"]));
|
||||
register(new Style("player.winner", ["skin.background.alpha" => 0.2, "skin.background.color" => green,]));
|
||||
register(new Style("player.loser", ["skin.background.alpha" => 0.2, "skin.background.color" => red,]));
|
||||
register(new Style("icon.tank", [
|
||||
"geometry.width" => SizeValue.fromString("6h"),
|
||||
"geometry.height" => SizeValue.fromString("6h"),
|
||||
"skin.fillType" => FillType.CONTAIN,
|
||||
]));
|
||||
|
||||
register(new Style("button.pack", [
|
||||
"geometry.width" => SizeValue.fromString("35h"),
|
||||
"geometry.height" => SizeValue.fromString("20h"),
|
||||
"geometry.padding" => Box.fromFloat(5),
|
||||
"layout.hAlign" => HAlign.CENTER,
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
"content.buttonMode" => true,
|
||||
"content.mouseChildren" => false,
|
||||
"skin.round" => 15,
|
||||
], ["border", "light"]));
|
||||
var green:Color = 0x00ff00;
|
||||
var red:Color = 0xff0000;
|
||||
register(new Style("result.winner", [
|
||||
"skin.border.color" => green,
|
||||
"skin.border.alpha" => 0.5,
|
||||
"skin.border.thickness" => 5,
|
||||
"skin.round" => 10,
|
||||
], ["light"]));
|
||||
register(new Style("result.loser", [
|
||||
"skin.border.color" => red,
|
||||
"skin.border.alpha" => 0.5,
|
||||
"skin.border.thickness" => 5,
|
||||
"skin.round" => 10,
|
||||
], ["light"]));
|
||||
register(new Style("player.winner", [
|
||||
"skin.background.alpha" => 0.2,
|
||||
"skin.background.color" => green,
|
||||
]));
|
||||
register(new Style("player.loser", [
|
||||
"skin.background.alpha" => 0.2,
|
||||
"skin.background.color" => red,
|
||||
]));
|
||||
|
||||
register(new Style("button.menu", ["geometry.padding" => Box.fromArray([20, 10]),]));
|
||||
register(new Style("button.pack", [
|
||||
"geometry.width" => SizeValue.fromString("35h"),
|
||||
"geometry.height" => SizeValue.fromString("20h"),
|
||||
"geometry.padding" => Box.fromFloat(5),
|
||||
"layout.hAlign" => HAlign.CENTER,
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
"content.buttonMode" => true,
|
||||
"content.mouseChildren" => false,
|
||||
"skin.round" => 15,
|
||||
], ["border", "light"]));
|
||||
|
||||
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("bars", "bars-solid.svg");
|
||||
register(new Style("button.menu", [
|
||||
"geometry.padding" => Box.fromArray([20, 10]),
|
||||
]));
|
||||
|
||||
registerButton("keyboard", "keyboard-light.svg", true);
|
||||
registerButton("backspace", "backspace-light.svg", true);
|
||||
registerButton("tablet-android-alt", "tablet-android-alt-light.svg", true);
|
||||
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("bars", "bars-solid.svg");
|
||||
|
||||
register(new Style("gamepad", ["skin.color" => colors.text, "skin.activeColor" => colors.active,]));
|
||||
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("render", ["skin.background.color" => colors.dark,]));
|
||||
}
|
||||
register(new Style("gamepad", [
|
||||
"skin.color" => colors.text,
|
||||
"skin.activeColor" => colors.active,
|
||||
]));
|
||||
|
||||
register(new Style("render", [
|
||||
"skin.background.color" => colors.dark,
|
||||
]));
|
||||
}
|
||||
|
||||
private function registerButton(name:String, resource:String, solid:Bool = false):Void {
|
||||
register(new Style('button.$name', [
|
||||
"geometry.width" => SizeValue.fromString("10h"),
|
||||
"geometry.height" => SizeValue.fromString("10h"),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
|
||||
]));
|
||||
register(new Style('button.$name.small', [
|
||||
"geometry.width" => SizeValue.fromString("7h"),
|
||||
"geometry.height" => SizeValue.fromString("7h"),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
|
||||
]));
|
||||
}
|
||||
|
||||
private function registerButton(name:String, resource:String, solid:Bool = false):Void {
|
||||
register(new Style('button.$name', [
|
||||
"geometry.width" => SizeValue.fromString("10h"),
|
||||
"geometry.height" => SizeValue.fromString("10h"),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light,
|
||||
solid),
|
||||
]));
|
||||
register(new Style('button.$name.small', [
|
||||
"geometry.width" => SizeValue.fromString("7h"),
|
||||
"geometry.height" => SizeValue.fromString("7h"),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light,
|
||||
solid),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,49 +12,49 @@ import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.view.ClientView;
|
||||
|
||||
class Client {
|
||||
private static inline var TAG = "Tankz";
|
||||
private static inline var TAG = "Tankz";
|
||||
|
||||
@:provide private static var settings:SettingsStorage;
|
||||
@:provide private static var settings:SettingsStorage;
|
||||
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
#if flash
|
||||
L.push(new hw.log.JSLogger());
|
||||
#end
|
||||
#if debug
|
||||
// L.push(new hw.log.SocketLogger());
|
||||
#end
|
||||
// ToDo: fix @:provide macro
|
||||
PopupManager;
|
||||
LoaderManager;
|
||||
GameStorage;
|
||||
AnimateManager;
|
||||
//
|
||||
Const.init();
|
||||
Init.init();
|
||||
// TODO:
|
||||
// Animate.bind(Lib.current.stage);
|
||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||
L.i(TAG, 'Mobile: ${Device.isMobile()}');
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.launch();
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
#if flash
|
||||
L.push(new hw.log.JSLogger());
|
||||
#end
|
||||
#if debug
|
||||
//L.push(new hw.log.SocketLogger());
|
||||
#end
|
||||
// ToDo: fix @:provide macro
|
||||
PopupManager;
|
||||
LoaderManager;
|
||||
GameStorage;
|
||||
AnimateManager;
|
||||
//
|
||||
Const.init();
|
||||
Init.init();
|
||||
// TODO:
|
||||
// Animate.bind(Lib.current.stage);
|
||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||
L.i(TAG, 'Mobile: ${Device.isMobile()}');
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.launch();
|
||||
|
||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||
fps.visible = settings.displayFPS;
|
||||
Lib.current.addChild(fps);
|
||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||
fps.visible = settings.displayFPS;
|
||||
Lib.current.addChild(fps);
|
||||
|
||||
settings.signal.connect(function(setting) {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value):
|
||||
fps.visible = value;
|
||||
case _:
|
||||
}
|
||||
});
|
||||
}
|
||||
settings.signal.connect(function(setting) {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value):
|
||||
fps.visible = value;
|
||||
case _:
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,17 @@ import flash.Lib;
|
||||
import flash.system.Capabilities;
|
||||
|
||||
class Const {
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
public static var VERSION:String;
|
||||
public static var NAME:String;
|
||||
public static var DEBUG:Bool;
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
public static var VERSION:String;
|
||||
public static var NAME:String;
|
||||
public static var DEBUG:Bool;
|
||||
|
||||
public static function init():Void {
|
||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||
BUILD = CompilationOption.get("build");
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
NAME = Lib.current.stage.application.meta.get("name");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
public static function init():Void {
|
||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||
BUILD = CompilationOption.get("build");
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
NAME = Lib.current.stage.application.meta.get("name");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,56 +23,56 @@ import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
class Init {
|
||||
@:provide static var theme:ITheme;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
@: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
|
||||
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||
#elseif html5
|
||||
return new ru.m.connect.js.JsConnection<Request, Response>(host,
|
||||
port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||
#else
|
||||
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||
#end
|
||||
}
|
||||
@:provide static var theme:ITheme;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
@:provide static var updater:Updater;
|
||||
|
||||
public static function init():Void {
|
||||
theme = new AppTheme();
|
||||
levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
|
||||
levelBundle.load();
|
||||
configBundle = new ConfigBundle();
|
||||
|
||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||
|
||||
connection = buildConnection();
|
||||
|
||||
bus = new ControlBus();
|
||||
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||
|
||||
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
|
||||
|
||||
for (device in Gamepad.devices) {
|
||||
trace('gamepad', device);
|
||||
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
|
||||
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||
#elseif html5
|
||||
return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||
#else
|
||||
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||
#end
|
||||
}
|
||||
Gamepad.onConnect.add(function(device) {
|
||||
trace('connect gamepad', device);
|
||||
});
|
||||
|
||||
for (device in Joystick.devices) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
public static function init():Void {
|
||||
theme = new AppTheme();
|
||||
levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
|
||||
levelBundle.load();
|
||||
configBundle = new ConfigBundle();
|
||||
|
||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||
|
||||
connection = buildConnection();
|
||||
|
||||
bus = new ControlBus();
|
||||
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
Joystick.onConnect.add(function(device) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,21 @@ 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,132 +9,134 @@ import hw.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 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;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
maskShape = new Shape();
|
||||
addChild(maskShape);
|
||||
mask = maskShape;
|
||||
}
|
||||
private var maskShape:Shape;
|
||||
private var toRedraw:Bool;
|
||||
|
||||
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;
|
||||
public function new() {
|
||||
super();
|
||||
maskShape = new Shape();
|
||||
addChild(maskShape);
|
||||
mask = maskShape;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_backColor(value:Int):Int {
|
||||
if (backColor != value) {
|
||||
backColor = value;
|
||||
toRedraw = true;
|
||||
private inline function get_radius():Float {
|
||||
return Math.min(size.width, size.height) / 2;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_progress(value:Float):Float {
|
||||
if (progress != value) {
|
||||
progress = value;
|
||||
toRedraw = true;
|
||||
private function set_color(value:Int):Int {
|
||||
if (color != value) {
|
||||
color = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
private function set_size(value:Size):Size {
|
||||
if (size != value) {
|
||||
size = value;
|
||||
toRedraw = true;
|
||||
private function set_backColor(value:Int):Int {
|
||||
if (backColor != value) {
|
||||
backColor = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (toRedraw) {
|
||||
redraw();
|
||||
redrawMask();
|
||||
toRedraw = false;
|
||||
private function set_progress(value:Float):Float {
|
||||
if (progress != value) {
|
||||
progress = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
private function set_size(value:Size):Size {
|
||||
if (size != value) {
|
||||
size = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
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);
|
||||
public function update():Void {
|
||||
if (toRedraw) {
|
||||
redraw();
|
||||
redrawMask();
|
||||
toRedraw = false;
|
||||
}
|
||||
}
|
||||
if (progress * sides != sidesToDraw) {
|
||||
lineToRadians(progress * (Math.PI * 2) + rotation);
|
||||
|
||||
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();
|
||||
}
|
||||
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 var progress:Progress;
|
||||
|
||||
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;
|
||||
}
|
||||
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 onEnterFrame(event:Event):Void {
|
||||
progress.update();
|
||||
}
|
||||
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 onProgress(event:ProgressEvent):Void {
|
||||
progress.progress = event.bytesLoaded / event.bytesTotal;
|
||||
}
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
progress.update();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,25 +8,26 @@ import ru.m.tankz.Type;
|
||||
import ru.m.tankz.util.LevelUtil;
|
||||
|
||||
class ClientLevelSource implements ILevelSource {
|
||||
public function new() {}
|
||||
|
||||
public function resolveMeta(id:PackId):LevelPackMeta {
|
||||
var bytes = Assets.getBytes('level/${id}.zip');
|
||||
return LevelUtil.getMeta(bytes);
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
public function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('level/${id}.zip');
|
||||
return LevelUtil.unpack(bytes);
|
||||
}
|
||||
|
||||
public function list():Array<PackId> {
|
||||
var result = [];
|
||||
for (path in Assets.list(AssetType.BINARY)) {
|
||||
if (StringTools.startsWith(path, "level")) {
|
||||
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
|
||||
}
|
||||
public function resolveMeta(id:PackId):LevelPackMeta {
|
||||
var bytes = Assets.getBytes('level/${id}.zip');
|
||||
return LevelUtil.getMeta(bytes);
|
||||
}
|
||||
|
||||
public function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('level/${id}.zip');
|
||||
return LevelUtil.unpack(bytes);
|
||||
}
|
||||
|
||||
public function list():Array<PackId> {
|
||||
var result = [];
|
||||
for (path in Assets.list(AssetType.BINARY)) {
|
||||
if (StringTools.startsWith(path, "level")) {
|
||||
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,16 @@ import yaml.Parser;
|
||||
import yaml.Yaml;
|
||||
|
||||
class ConfigBundle implements IConfigBundle {
|
||||
private var _cache:Map<GameType, Config> = new Map();
|
||||
|
||||
public function new() {}
|
||||
private var _cache:Map<GameType, Config> = new Map();
|
||||
|
||||
public function get(type:GameType):Config {
|
||||
if (!_cache.exists(type)) {
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
public function new() {}
|
||||
|
||||
public function get(type:GameType):Config {
|
||||
if (!_cache.exists(type)) {
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
}
|
||||
return _cache.get(type);
|
||||
}
|
||||
return _cache.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import ru.m.control.DeviceType;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
typedef BindAction = {
|
||||
var device:DeviceType;
|
||||
var action:DeviceAction;
|
||||
var device:DeviceType;
|
||||
var action:DeviceAction;
|
||||
}
|
||||
|
||||
typedef Binding = Map<TankAction, BindAction>;
|
||||
|
||||
@@ -13,105 +13,106 @@ import ru.m.tankz.Type;
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
var config = storage.getBinding(controlIndex);
|
||||
binding = new Map();
|
||||
for (action in config.keys()) {
|
||||
var bind = config.get(action);
|
||||
if (!binding.exists(bind.device)) {
|
||||
binding.set(bind.device, new Map());
|
||||
}
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
moveQueue = [];
|
||||
shotTimers = new Map();
|
||||
}
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
if (binding.exists(device) && binding[device].exists(action)) {
|
||||
toggleAction(binding[device][action], on);
|
||||
}
|
||||
}
|
||||
|
||||
override public function start():Void {
|
||||
super.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
override public function stop():Void {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
if (on) {
|
||||
if (moveQueue.indexOf(direction) == -1) {
|
||||
moveQueue.unshift(direction);
|
||||
}
|
||||
} else {
|
||||
moveQueue.remove(direction);
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
var config = storage.getBinding(controlIndex);
|
||||
binding = new Map();
|
||||
for (action in config.keys()) {
|
||||
var bind = config.get(action);
|
||||
if (!binding.exists(bind.device)) {
|
||||
binding.set(bind.device, new Map());
|
||||
}
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
moveQueue = [];
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
if (binding.exists(device) && binding[device].exists(action)) {
|
||||
toggleAction(binding[device][action], on);
|
||||
}
|
||||
}
|
||||
|
||||
override public function start():Void {
|
||||
super.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
override public function stop():Void {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
if (on) {
|
||||
if (moveQueue.indexOf(direction) == -1) {
|
||||
moveQueue.unshift(direction);
|
||||
}
|
||||
} else {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (!shotTimers.exists(weapon)) {
|
||||
// ToDo: weapon.config.delay
|
||||
var timer = new Timer(350);
|
||||
timer.run = shooter(weapon);
|
||||
timer.run();
|
||||
shotTimers.set(weapon, timer);
|
||||
}
|
||||
} else {
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
}
|
||||
case TankAction.STOP:
|
||||
}
|
||||
}
|
||||
|
||||
private function onFocusOut(event:FocusEvent):Void {
|
||||
moveQueue = [];
|
||||
updateMove();
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (!shotTimers.exists(weapon)) {
|
||||
// ToDo: weapon.config.delay
|
||||
var timer = new Timer(350);
|
||||
timer.run = shooter(weapon);
|
||||
timer.run();
|
||||
shotTimers.set(weapon, timer);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateMove():Void {
|
||||
if (moveQueue.length == 0) {
|
||||
action(STOP);
|
||||
} else {
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
action(MOVE(moveQueue[0]));
|
||||
}
|
||||
case TankAction.STOP:
|
||||
}
|
||||
}
|
||||
|
||||
private function onFocusOut(event:FocusEvent):Void {
|
||||
moveQueue = [];
|
||||
updateMove();
|
||||
}
|
||||
|
||||
private function updateMove():Void {
|
||||
if (moveQueue.length == 0) {
|
||||
action(STOP);
|
||||
} else {
|
||||
action(MOVE(moveQueue[0]));
|
||||
private function shooter(weapon:Int):Void -> Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function shooter(weapon:Int):Void->Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
|
||||
enum GameInit {
|
||||
LOCAL(start:Start);
|
||||
NETWORK(network:NetworkManager);
|
||||
RECORD(record:GameRecord);
|
||||
LOCAL(start:Start);
|
||||
NETWORK(network:NetworkManager);
|
||||
RECORD(record:GameRecord);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ 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);
|
||||
}
|
||||
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new HumanControl(id, index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,34 +8,35 @@ 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();
|
||||
}
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result):
|
||||
updateProgress(result);
|
||||
case _:
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result):
|
||||
updateProgress(result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,26 +5,27 @@ import flash.events.Event;
|
||||
import ru.m.tankz.engine.ICaller;
|
||||
|
||||
class StageCaller implements ICaller {
|
||||
private var stage:Stage;
|
||||
private var event:String;
|
||||
private var calback:Void->Void;
|
||||
|
||||
public function new(stage:Stage, ?event:String) {
|
||||
this.stage = stage;
|
||||
this.event = event != null ? event : Event.ENTER_FRAME;
|
||||
}
|
||||
private var stage:Stage;
|
||||
private var event:String;
|
||||
private var calback:Void -> Void;
|
||||
|
||||
private function onEvent(_):Void {
|
||||
calback();
|
||||
}
|
||||
public function new(stage:Stage, ?event:String) {
|
||||
this.stage = stage;
|
||||
this.event = event != null ? event : Event.ENTER_FRAME;
|
||||
}
|
||||
|
||||
public function start(calback:Void->Void):Void {
|
||||
this.calback = calback;
|
||||
stage.addEventListener(event, onEvent);
|
||||
}
|
||||
private function onEvent(_):Void {
|
||||
calback();
|
||||
}
|
||||
|
||||
public function stop():Void {
|
||||
stage.removeEventListener(event, onEvent);
|
||||
calback = null;
|
||||
}
|
||||
public function start(calback:Void -> Void):Void {
|
||||
this.calback = calback;
|
||||
stage.addEventListener(event, onEvent);
|
||||
}
|
||||
|
||||
public function stop():Void {
|
||||
stage.removeEventListener(event, onEvent);
|
||||
calback = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class NetworkControl extends HumanControl {
|
||||
@:provide private var network:NetworkManager;
|
||||
|
||||
override public function action(action:TankAction):Void {
|
||||
if (tankId > -1) {
|
||||
network.action(tankId, action);
|
||||
@:provide private var network:NetworkManager;
|
||||
|
||||
override public function action(action:TankAction):Void {
|
||||
if (tankId > -1) {
|
||||
network.action(tankId, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,45 +10,45 @@ 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 var network:NetworkManager;
|
||||
|
||||
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);
|
||||
}
|
||||
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 onConnectionState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
network.joinGame(network.room.game.id);
|
||||
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 _:
|
||||
}
|
||||
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)});
|
||||
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);
|
||||
}
|
||||
super.onStart(start);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,166 +28,172 @@ import ru.m.tankz.storage.SettingsStorage;
|
||||
typedef ClientConnection = IConnection<Request, Response>;
|
||||
|
||||
enum ConnectionState {
|
||||
OFFLINE;
|
||||
CONNECT;
|
||||
CONNECTED;
|
||||
LOGIN;
|
||||
ONLINE(user:User);
|
||||
ERROR(error:Dynamic);
|
||||
OFFLINE;
|
||||
CONNECT;
|
||||
CONNECTED;
|
||||
LOGIN;
|
||||
ONLINE(user:User);
|
||||
ERROR(error:Dynamic);
|
||||
}
|
||||
|
||||
@:provide class NetworkManager {
|
||||
private static inline var TAG = "NetworkManager";
|
||||
|
||||
public var state(default, null):ConnectionState;
|
||||
public var room(default, null):RoomProto;
|
||||
public var user(default, null):UserProto;
|
||||
private static inline var TAG = "NetworkManager";
|
||||
|
||||
public var stateSignal:Signal<ConnectionState>;
|
||||
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||
public var roomSignal:Signal<RoomProto>;
|
||||
public var gameEventSignal:Signal<GameEventResponse>;
|
||||
public var state(default, null):ConnectionState;
|
||||
public var room(default, null):RoomProto;
|
||||
public var user(default, null):UserProto;
|
||||
|
||||
@:provide private var connection:ClientConnection;
|
||||
@:provide private var storage:NetworkStorage;
|
||||
@:provide private var settings:SettingsStorage;
|
||||
public var stateSignal:Signal<ConnectionState>;
|
||||
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||
public var roomSignal:Signal<RoomProto>;
|
||||
public var gameEventSignal:Signal<GameEventResponse>;
|
||||
|
||||
private var reconnectTimer:Timer;
|
||||
private var reconnectDelay:Int;
|
||||
@:provide private var connection:ClientConnection;
|
||||
@:provide private var storage:NetworkStorage;
|
||||
@:provide private var settings:SettingsStorage;
|
||||
|
||||
public function new() {
|
||||
reconnectDelay = 500;
|
||||
stateSignal = new Signal();
|
||||
listRoomSignal = new Signal();
|
||||
roomSignal = new Signal();
|
||||
gameEventSignal = new Signal();
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
if (settings.enableNetwork) {
|
||||
connect();
|
||||
}
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
private var reconnectTimer:Timer;
|
||||
private var reconnectDelay:Int;
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value):
|
||||
if (value) {
|
||||
connect();
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
L.d(TAG, 'State: ${value}');
|
||||
state = value;
|
||||
stateSignal.emit(value);
|
||||
}
|
||||
|
||||
public function login(name:String, uuid:String = null):Void {
|
||||
updateState(LOGIN);
|
||||
connection.send(new Request().setLogin(new LoginRequest().setUuid(uuid).setName(name)));
|
||||
}
|
||||
|
||||
public function logout():Void {
|
||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||
}
|
||||
|
||||
public function listGame(subscribe:Bool):Void {
|
||||
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||
}
|
||||
|
||||
public function createGame(type:String, level:Int):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type)
|
||||
.setLevel(level))));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId)
|
||||
.setRestore(restore))));
|
||||
}
|
||||
|
||||
public function selectSlot(slot:SlotProto):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||
}
|
||||
|
||||
public function startGame():Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||
}
|
||||
|
||||
public function action(tankId:Int, action:TankAction):Void {
|
||||
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(new GameEventProto().setTime(0)
|
||||
.setEvent(Serializer.run(GameEvent.ACTION(tankId, action))))));
|
||||
}
|
||||
|
||||
private function connect():Void {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.stop();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
reconnectTimer = null;
|
||||
updateState(CONNECT);
|
||||
connection.connect().catchError(function(error) {});
|
||||
}
|
||||
|
||||
private function reconnect():Void {
|
||||
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||
if (reconnectTimer == null) {
|
||||
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private function disconnect():Void {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
updateState(switch event {
|
||||
case CONNECTED: CONNECTED;
|
||||
case DISCONNECTED: OFFLINE;
|
||||
case ERROR(error): ERROR(error);
|
||||
});
|
||||
switch event {
|
||||
case CONNECTED:
|
||||
public function new() {
|
||||
reconnectDelay = 500;
|
||||
var user = storage.user;
|
||||
if (user != null) {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
case DISCONNECTED | ERROR(_):
|
||||
stateSignal = new Signal();
|
||||
listRoomSignal = new Signal();
|
||||
roomSignal = new Signal();
|
||||
gameEventSignal = new Signal();
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
if (settings.enableNetwork) {
|
||||
reconnect();
|
||||
connect();
|
||||
}
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value):
|
||||
if (value) {
|
||||
connect();
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onResponse(packet:Response):Void {
|
||||
if (packet.hasLogin()) {
|
||||
this.user = packet.login.user;
|
||||
var user = {
|
||||
uuid: this.user.uuid,
|
||||
name: this.user.name,
|
||||
};
|
||||
storage.user = user;
|
||||
updateState(ONLINE(user));
|
||||
} else if (packet.hasLogout()) {
|
||||
storage.user = null;
|
||||
updateState(CONNECTED);
|
||||
} else if (packet.hasRoomList()) {
|
||||
listRoomSignal.emit(packet.roomList.rooms);
|
||||
} else if (packet.hasRoom()) {
|
||||
room = packet.room.room;
|
||||
roomSignal.emit(room);
|
||||
} else if (packet.hasGameEvent()) {
|
||||
gameEventSignal.emit(packet.gameEvent);
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
L.d(TAG, 'State: ${value}');
|
||||
state = value;
|
||||
stateSignal.emit(value);
|
||||
}
|
||||
|
||||
public function login(name:String, uuid:String = null):Void {
|
||||
updateState(LOGIN);
|
||||
connection.send(new Request().setLogin(
|
||||
new LoginRequest()
|
||||
.setUuid(uuid)
|
||||
.setName(name)
|
||||
));
|
||||
}
|
||||
|
||||
public function logout():Void {
|
||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||
}
|
||||
|
||||
public function listGame(subscribe:Bool):Void {
|
||||
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||
}
|
||||
|
||||
public function createGame(type:String, level:Int):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type).setLevel(level))));
|
||||
}
|
||||
|
||||
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||
}
|
||||
|
||||
public function selectSlot(slot:SlotProto):Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||
}
|
||||
|
||||
public function startGame():Void {
|
||||
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||
}
|
||||
|
||||
public function action(tankId:Int, action:TankAction):Void {
|
||||
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
|
||||
new GameEventProto().setTime(0).setEvent(
|
||||
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||
)))
|
||||
);
|
||||
}
|
||||
|
||||
private function connect():Void {
|
||||
if (reconnectTimer != null) {
|
||||
reconnectTimer.stop();
|
||||
reconnectTimer = null;
|
||||
}
|
||||
reconnectTimer = null;
|
||||
updateState(CONNECT);
|
||||
connection.connect().catchError(function(error) {});
|
||||
}
|
||||
|
||||
private function reconnect():Void {
|
||||
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||
if (reconnectTimer == null) {
|
||||
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private function disconnect():Void {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
updateState(switch event {
|
||||
case CONNECTED: CONNECTED;
|
||||
case DISCONNECTED: OFFLINE;
|
||||
case ERROR(error): ERROR(error);
|
||||
});
|
||||
switch event {
|
||||
case CONNECTED:
|
||||
reconnectDelay = 500;
|
||||
var user = storage.user;
|
||||
if (user != null) {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
case DISCONNECTED | ERROR(_):
|
||||
if (settings.enableNetwork) {
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onResponse(packet:Response):Void {
|
||||
if (packet.hasLogin()) {
|
||||
this.user = packet.login.user;
|
||||
var user = {
|
||||
uuid: this.user.uuid,
|
||||
name: this.user.name,
|
||||
};
|
||||
storage.user = user;
|
||||
updateState(ONLINE(user));
|
||||
} else if (packet.hasLogout()) {
|
||||
storage.user = null;
|
||||
updateState(CONNECTED);
|
||||
} else if (packet.hasRoomList()) {
|
||||
listRoomSignal.emit(packet.roomList.rooms);
|
||||
} else if (packet.hasRoom()) {
|
||||
room = packet.room.room;
|
||||
roomSignal.emit(room);
|
||||
} else if (packet.hasGameEvent()) {
|
||||
gameEventSignal.emit(packet.gameEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,35 +5,38 @@ import ru.m.animate.Animate;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
|
||||
class AnimateBundle {
|
||||
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
||||
var template:String = 'resources/image/animate/${name}/%index%.png';
|
||||
var frames = [
|
||||
for (i in sequence)
|
||||
({
|
||||
image:Assets.getBitmapData(StringTools.replace(template, '%index%', Std.string(i))), length:1
|
||||
})
|
||||
];
|
||||
return new OnceAnimate(frames);
|
||||
}
|
||||
|
||||
public static function tankSpawn():OnceAnimate {
|
||||
return buildAnimate('appear', [0, 1, 2, 3, 3, 4, 5, 5, 6]);
|
||||
}
|
||||
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
||||
var template:String = 'resources/image/animate/${name}/%index%.png';
|
||||
var frames = [for (i in sequence) ({
|
||||
image: Assets.getBitmapData(StringTools.replace(template, '%index%', Std.string(i))),
|
||||
length: 1
|
||||
})];
|
||||
return new OnceAnimate(frames);
|
||||
}
|
||||
|
||||
public static function tankBoom():OnceAnimate {
|
||||
return buildAnimate('boom', [0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9]);
|
||||
}
|
||||
public static function tankSpawn():OnceAnimate {
|
||||
return buildAnimate('appear', [
|
||||
0, 1, 2, 3, 3, 4, 5, 5, 6
|
||||
]);
|
||||
}
|
||||
|
||||
public static function bulletBoom():OnceAnimate {
|
||||
return buildAnimate('boom-sm', [0, 1, 1, 0, 0, 1]);
|
||||
}
|
||||
public static function tankBoom():OnceAnimate {
|
||||
return buildAnimate('boom', [
|
||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
||||
]);
|
||||
}
|
||||
|
||||
public static function tankProtect():Animate {
|
||||
return new Animate([
|
||||
for (i in 0...2)
|
||||
({
|
||||
image:Assets.getBitmapData('resources/image/animate/protect/${i}.png'), length:5
|
||||
})
|
||||
]);
|
||||
}
|
||||
public static function bulletBoom():OnceAnimate {
|
||||
return buildAnimate('boom-sm', [
|
||||
0, 1, 1, 0, 0, 1
|
||||
]);
|
||||
}
|
||||
|
||||
public static function tankProtect():Animate {
|
||||
return new Animate([for (i in 0...2) ({
|
||||
image: Assets.getBitmapData('resources/image/animate/protect/${i}.png'),
|
||||
length: 5
|
||||
})]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ 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;
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
public function draw():Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
|
||||
@@ -23,281 +23,281 @@ import ru.m.tankz.render.item.EagleRenderItem;
|
||||
import ru.m.tankz.render.item.IRenderItem;
|
||||
import ru.m.tankz.render.item.TankRenderItem;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using ru.m.display.DisplayObjectContainerExtender;
|
||||
|
||||
class Render extends SpriteView 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;
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
|
||||
private var container:Sprite;
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
private var entryLayer:Sprite;
|
||||
private var upLayer:Sprite;
|
||||
private var upperLayer:Sprite;
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var items:Map<Int, IRenderItem>;
|
||||
private var paused:Bool;
|
||||
private var container:Sprite;
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
private var entryLayer:Sprite;
|
||||
private var upLayer:Sprite;
|
||||
private var upperLayer:Sprite;
|
||||
|
||||
@:provide private static var animateManager:AnimateManager;
|
||||
private var items:Map<Int, IRenderItem>;
|
||||
private var paused:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
items = new Map();
|
||||
container = new Sprite();
|
||||
content.addChild(container);
|
||||
backgroundLayer = new Sprite();
|
||||
groundLayer = new Sprite();
|
||||
entryLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
upperLayer = new Sprite();
|
||||
container.addChild(backgroundLayer);
|
||||
container.addChild(groundLayer);
|
||||
container.addChild(entryLayer);
|
||||
container.addChild(upLayer);
|
||||
container.addChild(upperLayer);
|
||||
reset();
|
||||
}
|
||||
@:provide private static var animateManager:AnimateManager;
|
||||
|
||||
private function get_mapWidth():Float {
|
||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||
}
|
||||
|
||||
private function get_mapHeight():Float {
|
||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||
}
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
drawBackground();
|
||||
toRedraw();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
drawBackground();
|
||||
toRedraw();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.lineStyle(2, 0xcccccc);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
super.redraw();
|
||||
var scale = Math.min(width / mapWidth, height / mapHeight);
|
||||
container.scaleX = container.scaleY = scale;
|
||||
container.x = (width - (mapWidth * scale)) / 2;
|
||||
container.y = (height - (mapHeight * scale)) / 2;
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
public function new() {
|
||||
super();
|
||||
items = new Map();
|
||||
container = new Sprite();
|
||||
content.addChild(container);
|
||||
backgroundLayer = new Sprite();
|
||||
groundLayer = new Sprite();
|
||||
entryLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
upperLayer = new Sprite();
|
||||
container.addChild(backgroundLayer);
|
||||
container.addChild(groundLayer);
|
||||
container.addChild(entryLayer);
|
||||
container.addChild(upLayer);
|
||||
container.addChild(upperLayer);
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
if (!paused) {
|
||||
draw();
|
||||
private function get_mapWidth():Float {
|
||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||
}
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
while (layer.numChildren > 0) {
|
||||
layer.removeChildAt(0);
|
||||
private function get_mapHeight():Float {
|
||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
for (item in items.iterator()) {
|
||||
item.dispose();
|
||||
}
|
||||
items = new Map();
|
||||
clearLayer(entryLayer);
|
||||
clearLayer(groundLayer);
|
||||
clearLayer(upLayer);
|
||||
clearLayer(upperLayer);
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
animateManager.playing = true;
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case PAUSE(paused):
|
||||
this.paused = paused;
|
||||
animateManager.playing = !paused;
|
||||
case SPAWN(BRICK(bricks)):
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
drawBackground();
|
||||
for (brick in bricks) {
|
||||
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||
var config = config.getBrick(brick.type);
|
||||
items[brick.id] = item;
|
||||
if (config.layer > 2) {
|
||||
upLayer.addChild(item.view);
|
||||
} else {
|
||||
groundLayer.addChild(item.view);
|
||||
}
|
||||
}
|
||||
case SPAWN(EAGLE(id, rect, teamId)):
|
||||
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
var item = new TankRenderItem(rect);
|
||||
var tankConfig = config.getTank(info.type);
|
||||
item.color = info.color;
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.boat = info.boat;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, skin, color)):
|
||||
var item = new BulletRenderItem(rect);
|
||||
item.color = color;
|
||||
item.skin = skin;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case SPAWN(BONUS(id, rect, type)):
|
||||
var item = new BonusRenderItem(rect, type);
|
||||
items.set(id, item);
|
||||
upperLayer.addChild(item.view);
|
||||
item.update();
|
||||
case MOVE(EAGLE(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case MOVE(BULLET(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case MOVE(TANK(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
cast(item, TankRenderItem).moves = true;
|
||||
}
|
||||
case STOP(TANK(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
cast(item, TankRenderItem).moves = false;
|
||||
}
|
||||
case CHANGE(TANK(id, type, hits, bonus, boat)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.skin = config.getTank(type).skin;
|
||||
item.hits = hits;
|
||||
item.bonus = bonus;
|
||||
item.boat = boat;
|
||||
}
|
||||
case CHANGE(TANK_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(EAGLE_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:EagleRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(BRICK(id, type)):
|
||||
if (items.exists(id)) {
|
||||
var item:BrickRenderItem = cast items[id];
|
||||
item.type = type;
|
||||
}
|
||||
case DESTROY(TANK(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
var rect = item.rect;
|
||||
// move boom
|
||||
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||
playAnimate(point, AnimateBundle.bulletBoom());
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(EAGLE(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroyCell(x, y);
|
||||
case DESTROY(BRICK(id, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroy();
|
||||
case _:
|
||||
toRedraw();
|
||||
return config;
|
||||
}
|
||||
#if cpp
|
||||
flash.Lib.current.stage.invalidate();
|
||||
#end
|
||||
}
|
||||
|
||||
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||
animate.x = point.x - animate.width / 2;
|
||||
animate.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
return animate.play().then(function(animate:Animate):Void {
|
||||
// ToDo: clean animates on reset
|
||||
if (upperLayer.contains(animate)) {
|
||||
upperLayer.removeChildSafety(animate);
|
||||
}
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
drawBackground();
|
||||
toRedraw();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.lineStyle(2, 0xcccccc);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
super.redraw();
|
||||
var scale = Math.min(width / mapWidth, height / mapHeight);
|
||||
container.scaleX = container.scaleY = scale;
|
||||
container.x = (width - (mapWidth * scale)) / 2;
|
||||
container.y = (height - (mapHeight * scale)) / 2;
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
}
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
if (!paused) {
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
while (layer.numChildren > 0) {
|
||||
layer.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
for (item in items.iterator()) {
|
||||
item.dispose();
|
||||
}
|
||||
items = new Map();
|
||||
clearLayer(entryLayer);
|
||||
clearLayer(groundLayer);
|
||||
clearLayer(upLayer);
|
||||
clearLayer(upperLayer);
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
animateManager.playing = true;
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case PAUSE(paused):
|
||||
this.paused = paused;
|
||||
animateManager.playing = !paused;
|
||||
case SPAWN(BRICK(bricks)):
|
||||
drawBackground();
|
||||
for (brick in bricks) {
|
||||
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||
var config = config.getBrick(brick.type);
|
||||
items[brick.id] = item;
|
||||
if (config.layer > 2) {
|
||||
upLayer.addChild(item.view);
|
||||
} else {
|
||||
groundLayer.addChild(item.view);
|
||||
}
|
||||
}
|
||||
case SPAWN(EAGLE(id, rect, teamId)):
|
||||
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
var item = new TankRenderItem(rect);
|
||||
var tankConfig = config.getTank(info.type);
|
||||
item.color = info.color;
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.boat = info.boat;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, skin, color)):
|
||||
var item = new BulletRenderItem(rect);
|
||||
item.color = color;
|
||||
item.skin = skin;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case SPAWN(BONUS(id, rect, type)):
|
||||
var item = new BonusRenderItem(rect, type);
|
||||
items.set(id, item);
|
||||
upperLayer.addChild(item.view);
|
||||
item.update();
|
||||
case MOVE(EAGLE(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case MOVE(BULLET(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
}
|
||||
case MOVE(TANK(id, position)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
item.move(position);
|
||||
cast(item, TankRenderItem).moves = true;
|
||||
}
|
||||
case STOP(TANK(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
cast(item, TankRenderItem).moves = false;
|
||||
}
|
||||
case CHANGE(TANK(id, type, hits, bonus, boat)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.skin = config.getTank(type).skin;
|
||||
item.hits = hits;
|
||||
item.bonus = bonus;
|
||||
item.boat = boat;
|
||||
}
|
||||
case CHANGE(TANK_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(EAGLE_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
var item:EagleRenderItem = cast items[id];
|
||||
item.protect = state;
|
||||
}
|
||||
case CHANGE(BRICK(id, type)):
|
||||
if (items.exists(id)) {
|
||||
var item:BrickRenderItem = cast items[id];
|
||||
item.type = type;
|
||||
}
|
||||
case DESTROY(TANK(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
var rect = item.rect;
|
||||
// move boom
|
||||
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||
playAnimate(point, AnimateBundle.bulletBoom());
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(EAGLE(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroyCell(x, y);
|
||||
case DESTROY(BRICK(id, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroy();
|
||||
case _:
|
||||
}
|
||||
#if cpp
|
||||
flash.Lib.current.stage.invalidate();
|
||||
#end
|
||||
}
|
||||
|
||||
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||
animate.x = point.x - animate.width / 2;
|
||||
animate.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
return animate.play().then(function(animate:Animate):Void {
|
||||
// ToDo: clean animates on reset
|
||||
if (upperLayer.contains(animate)) {
|
||||
upperLayer.removeChildSafety(animate);
|
||||
}
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,25 @@ 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 eagleImage(death:Bool = false):BitmapData {
|
||||
var suffix = death ? '-death' : '';
|
||||
return Assets.getBitmapData('resources/image/eagle/eagle${suffix}.png');
|
||||
}
|
||||
|
||||
public static function bonusImage(type:BonusType):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||
}
|
||||
public static function tankImage(skin:String, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/tank/${skin}-${frame}.png');
|
||||
}
|
||||
|
||||
public static function bulletImage(skin:String):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bullet/${skin}.png');
|
||||
}
|
||||
public static function bonusImage(type:BonusType):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||
}
|
||||
|
||||
public static function brickImage(type:BrickType, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/map/${type}${frame > 0 ? ("-" + frame) : ""}.png');
|
||||
}
|
||||
public static function bulletImage(skin:String):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bullet/${skin}.png');
|
||||
}
|
||||
|
||||
public static function brickImage(type:BrickType, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/map/${type}${frame > 0 ? ("-" + frame) : ""}.png');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,26 +7,26 @@ import flash.display.PixelSnapping;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BitmapRenderItem extends RenderItem {
|
||||
public var image(default, set):BitmapData;
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
private var bitmap:Bitmap;
|
||||
private var bitmap:Bitmap;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.NEVER, false);
|
||||
}
|
||||
|
||||
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;
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.NEVER, false);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,31 +4,31 @@ 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 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);
|
||||
public function new(rect:Rectangle, type:BonusType) {
|
||||
super(rect);
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
alpha += d;
|
||||
view.alpha = alpha;
|
||||
if (alpha <= 0 || alpha >= 1.5) {
|
||||
d = -d;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,107 +7,112 @@ import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class BrickBitmapBundle {
|
||||
private var data:Map<String, BitmapData>;
|
||||
|
||||
public function new() {
|
||||
data = new Map();
|
||||
}
|
||||
private var data:Map<String, BitmapData>;
|
||||
|
||||
private function resolve(type:BrickType, cells:Array<GridPoint>, frame:Int):BitmapData {
|
||||
return switch cells.length {
|
||||
case 0:
|
||||
null;
|
||||
case 4:
|
||||
type == "none" ? null : RenderUtil.brickImage(type, frame);
|
||||
case _:
|
||||
var image = RenderUtil.brickImage(type, frame);
|
||||
var result = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
for (point in cells) {
|
||||
var rect = new flash.geom.Rectangle(point.x * image.width / 2, point.y * image.height / 2, image.width / 2,
|
||||
image.height / 2);
|
||||
result.draw(image, null, null, null, rect);
|
||||
public function new() {
|
||||
data = new Map();
|
||||
}
|
||||
|
||||
private function resolve(type:BrickType, cells:Array<GridPoint>, frame:Int):BitmapData {
|
||||
return switch cells.length {
|
||||
case 0:
|
||||
null;
|
||||
case 4:
|
||||
type == "none" ? null : RenderUtil.brickImage(type, frame);
|
||||
case _:
|
||||
var image = RenderUtil.brickImage(type, frame);
|
||||
var result = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
for (point in cells) {
|
||||
var rect = new flash.geom.Rectangle(
|
||||
point.x * image.width / 2,
|
||||
point.y * image.height / 2,
|
||||
image.width / 2,
|
||||
image.height / 2);
|
||||
result.draw(image, null, null, null, rect);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public function get(type:BrickType, cells:Array<GridPoint>, frame:Int = 0):BitmapData {
|
||||
var key:String = '${type}_${cells.map(function(point) return point.toString()).join(",")}_${frame}';
|
||||
if (!data.exists(key)) {
|
||||
data.set(key, resolve(type, cells, frame));
|
||||
public function get(type:BrickType, cells:Array<GridPoint>, frame:Int = 0):BitmapData {
|
||||
var key:String = '${type}_${cells.map(function(point) return point.toString()).join(",")}_${frame}';
|
||||
if (!data.exists(key)) {
|
||||
data.set(key, resolve(type, cells, frame));
|
||||
}
|
||||
return data.get(key);
|
||||
}
|
||||
return data.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
class BrickRenderItem extends BitmapRenderItem {
|
||||
private static var bundle:BrickBitmapBundle = new BrickBitmapBundle();
|
||||
|
||||
public var type(default, set):BrickType;
|
||||
private static var bundle:BrickBitmapBundle = new BrickBitmapBundle();
|
||||
|
||||
private var cells:Array<GridPoint>;
|
||||
public var type(default, set):BrickType;
|
||||
|
||||
private var frames:Int;
|
||||
private var currentFrame:Int;
|
||||
private var ticks:Int;
|
||||
private var cells:Array<GridPoint>;
|
||||
|
||||
private static function buildCells():Array<GridPoint> {
|
||||
return [
|
||||
new GridPoint(0, 0),
|
||||
new GridPoint(0, 1),
|
||||
new GridPoint(1, 0),
|
||||
new GridPoint(1, 1),
|
||||
];
|
||||
}
|
||||
private var frames:Int;
|
||||
private var currentFrame:Int;
|
||||
private var ticks:Int;
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
cells = buildCells();
|
||||
this.frames = 1;
|
||||
this.currentFrame = 0;
|
||||
this.ticks = 0;
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
frames = switch type {
|
||||
case "water": 2;
|
||||
case _: 1;
|
||||
}
|
||||
cells = buildCells();
|
||||
redraw();
|
||||
private static function buildCells():Array<GridPoint> {
|
||||
return [
|
||||
new GridPoint(0, 0),
|
||||
new GridPoint(0, 1),
|
||||
new GridPoint(1, 0),
|
||||
new GridPoint(1, 1),
|
||||
];
|
||||
}
|
||||
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 new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
cells = buildCells();
|
||||
this.frames = 1;
|
||||
this.currentFrame = 0;
|
||||
this.ticks = 0;
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
public function destroy():Void {
|
||||
cells = [];
|
||||
redraw();
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
image = bundle.get(type, cells, currentFrame);
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (frames > 1) {
|
||||
if (++ticks >= 30) {
|
||||
ticks = 0;
|
||||
currentFrame++;
|
||||
if (currentFrame >= frames) {
|
||||
currentFrame = 0;
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
frames = switch type {
|
||||
case "water": 2;
|
||||
case _: 1;
|
||||
}
|
||||
cells = buildCells();
|
||||
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 {
|
||||
image = bundle.get(type, cells, currentFrame);
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (frames > 1) {
|
||||
if (++ticks >= 30) {
|
||||
ticks = 0;
|
||||
currentFrame++;
|
||||
if (currentFrame >= frames) {
|
||||
currentFrame = 0;
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,23 +5,23 @@ import hw.view.utils.BitmapUtil;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BulletRenderItem extends BitmapRenderItem {
|
||||
public var color(default, default):Null<Color>;
|
||||
public var skin(default, set):String;
|
||||
public var color(default, default):Null<Color>;
|
||||
public var skin(default, set):String;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
var image = RenderUtil.bulletImage(skin);
|
||||
if (color != null) {
|
||||
image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
this.image = image;
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
var image = RenderUtil.bulletImage(skin);
|
||||
if (color != null) {
|
||||
image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
this.image = image;
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,50 +8,50 @@ 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;
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
return death;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ 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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,51 +5,42 @@ 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 var view(get, null):DisplayObject;
|
||||
public var content(get, null):DisplayObject;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
this.rect = rect.clone();
|
||||
}
|
||||
public var rect(default, null):Rectangle;
|
||||
|
||||
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 new(rect:Rectangle) {
|
||||
this.rect = rect.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public function update():Void {}
|
||||
private function get_view():DisplayObject {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
public function dispose():Void {}
|
||||
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 {}
|
||||
}
|
||||
|
||||
@@ -15,159 +15,159 @@ 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 boat(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
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 boat(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 boatView:Shape;
|
||||
private var nameView:TextField;
|
||||
private var container:Sprite;
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var boatView:Shape;
|
||||
private var nameView:TextField;
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
@: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);
|
||||
boatView = buildBoatView();
|
||||
boatView.visible = false;
|
||||
container.addChild(boatView);
|
||||
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;
|
||||
}
|
||||
|
||||
private function buildBoatView():Shape {
|
||||
var result = new Shape();
|
||||
result.graphics.lineStyle(4, Color.fromString("green"), 0.8);
|
||||
result.graphics.drawRoundRect(-1, -1, rect.width + 2, rect.height + 2, 10, 10);
|
||||
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;
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
container = new Sprite();
|
||||
container.addChild(bitmap);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
boatView = buildBoatView();
|
||||
boatView.visible = false;
|
||||
container.addChild(boatView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
}
|
||||
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();
|
||||
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;
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
private function set_hits(value:Int):Int {
|
||||
if (hits != value) {
|
||||
hits = value;
|
||||
redraw();
|
||||
private function buildBoatView():Shape {
|
||||
var result = new Shape();
|
||||
result.graphics.lineStyle(4, Color.fromString("green"), 0.8);
|
||||
result.graphics.drawRoundRect(-1, -1, rect.width + 2, rect.height + 2, 10, 10);
|
||||
return result;
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
private function set_bonus(value:Bool):Bool {
|
||||
if (bonus != value) {
|
||||
bonus = value;
|
||||
redraw();
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
private function set_boat(value:Bool):Bool {
|
||||
if (boat != value) {
|
||||
boat = value;
|
||||
boatView.visible = boat;
|
||||
override private function get_content():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
return boat;
|
||||
}
|
||||
|
||||
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) {
|
||||
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];
|
||||
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_boat(value:Bool):Bool {
|
||||
if (boat != value) {
|
||||
boat = value;
|
||||
boatView.visible = boat;
|
||||
}
|
||||
return boat;
|
||||
}
|
||||
|
||||
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) {
|
||||
frame = 0;
|
||||
}
|
||||
bitmap.bitmapData = images[frame];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,119 +10,119 @@ import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
@:provide class SoundManager implements GameListener {
|
||||
private static var TAG(default, never):String = "SoundManager";
|
||||
private static var TAG(default, never):String = "SoundManager";
|
||||
|
||||
#if flash
|
||||
private static var type:String = "mp3";
|
||||
#else
|
||||
private static var type:String = "ogg";
|
||||
#end
|
||||
#if flash
|
||||
private static var type:String = "mp3";
|
||||
#else
|
||||
private static var type:String = "ogg";
|
||||
#end
|
||||
|
||||
public var config(default, default):Config;
|
||||
public var volume(default, set):Float = 1;
|
||||
public var mute(default, set):Bool = false;
|
||||
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 channels:Array<SoundChannel>;
|
||||
private var transform:SoundTransform;
|
||||
|
||||
private var humanTanks:Array<Int>;
|
||||
private var humanBullets:Array<Int>;
|
||||
private var liveBonuses:Array<Int>;
|
||||
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;
|
||||
public function new() {
|
||||
channels = [];
|
||||
updateSoundTransform();
|
||||
}
|
||||
}
|
||||
|
||||
private function set_volume(value:Float):Float {
|
||||
if (volume != value) {
|
||||
volume = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
return volume;
|
||||
}
|
||||
|
||||
private function set_mute(value:Bool):Bool {
|
||||
if (mute != value) {
|
||||
mute = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
return mute;
|
||||
}
|
||||
|
||||
public function play(id:String):Void {
|
||||
// L.d(TAG, 'play: ${id}');
|
||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||
if (sound != null) {
|
||||
var channel = sound.play(0, 0, transform);
|
||||
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||
channels.push(channel);
|
||||
} else {
|
||||
L.w(TAG, 'Sound "${id}" not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function stopAll():Void {
|
||||
for (channel in channels) {
|
||||
channel.stop();
|
||||
}
|
||||
channels = [];
|
||||
}
|
||||
|
||||
private function onSoundComplete(event:Event):Void {
|
||||
channels.remove(event.currentTarget);
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
play("start");
|
||||
humanTanks = [];
|
||||
liveBonuses = [];
|
||||
humanBullets = [];
|
||||
case SPAWN(BULLET(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
play("shot");
|
||||
humanBullets.push(id);
|
||||
private function updateSoundTransform():Void {
|
||||
transform = new SoundTransform(mute ? 0 : volume);
|
||||
for (channel in channels) {
|
||||
channel.soundTransform = transform;
|
||||
}
|
||||
case SPAWN(TANK(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
humanTanks.push(id);
|
||||
}
|
||||
|
||||
private function set_volume(value:Float):Float {
|
||||
if (volume != value) {
|
||||
volume = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
case SPAWN(BONUS(id, _, type)):
|
||||
play("bonus_add");
|
||||
if (type == "live") {
|
||||
liveBonuses.push(id);
|
||||
return volume;
|
||||
}
|
||||
|
||||
private function set_mute(value:Bool):Bool {
|
||||
if (mute != value) {
|
||||
mute = value;
|
||||
updateSoundTransform();
|
||||
}
|
||||
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");
|
||||
return mute;
|
||||
}
|
||||
|
||||
public function play(id:String):Void {
|
||||
//L.d(TAG, 'play: ${id}');
|
||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||
if (sound != null) {
|
||||
var channel = sound.play(0, 0, transform);
|
||||
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||
channels.push(channel);
|
||||
} else {
|
||||
play("boom_bot");
|
||||
L.w(TAG, 'Sound "${id}" not found');
|
||||
}
|
||||
}
|
||||
|
||||
public function stopAll():Void {
|
||||
for (channel in channels) {
|
||||
channel.stop();
|
||||
}
|
||||
channels = [];
|
||||
}
|
||||
|
||||
private function onSoundComplete(event:Event):Void {
|
||||
channels.remove(event.currentTarget);
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_):
|
||||
play("start");
|
||||
humanTanks = [];
|
||||
liveBonuses = [];
|
||||
humanBullets = [];
|
||||
case SPAWN(BULLET(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
play("shot");
|
||||
humanBullets.push(id);
|
||||
}
|
||||
case SPAWN(TANK(id, _, playerId, _)):
|
||||
if (config.isHuman(playerId)) {
|
||||
humanTanks.push(id);
|
||||
}
|
||||
case SPAWN(BONUS(id, _, type)):
|
||||
play("bonus_add");
|
||||
if (type == "live") {
|
||||
liveBonuses.push(id);
|
||||
}
|
||||
case HIT(TANK(_, _)):
|
||||
play("bullet_hit");
|
||||
case HIT(CELL(_, _, shot)):
|
||||
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
||||
//play("bullet_block");
|
||||
}
|
||||
case DESTROY(TANK(id, _)):
|
||||
if (humanTanks.indexOf(id) > -1) {
|
||||
play("boom_player");
|
||||
} else {
|
||||
play("boom_bot");
|
||||
}
|
||||
case DESTROY(EAGLE(_, _)):
|
||||
play("boom_player");
|
||||
case DESTROY(BONUS(id, _)):
|
||||
play("bonus_get");
|
||||
if (liveBonuses.indexOf(id) > -1) {
|
||||
play("live");
|
||||
} else {
|
||||
play("bonus_get");
|
||||
}
|
||||
case _:
|
||||
}
|
||||
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 _:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ import hw.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
@:provide class GameStorage extends SharedObjectStorage {
|
||||
private static inline var VERSION = 1;
|
||||
@:provide class GameStorage extends SharedObjectStorage {
|
||||
|
||||
public function new() {
|
||||
super('game_${VERSION}');
|
||||
}
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
public function get(id:PackId):PackProgress {
|
||||
return exists(id) ? read(id) : new PackProgress(id);
|
||||
}
|
||||
public function new() {
|
||||
super('game_${VERSION}');
|
||||
}
|
||||
|
||||
public function set(progress:PackProgress):Void {
|
||||
write(progress.id, progress);
|
||||
}
|
||||
public function get(id:PackId):PackProgress {
|
||||
return exists(id) ? read(id) : new PackProgress(id);
|
||||
}
|
||||
|
||||
public function set(progress:PackProgress):Void {
|
||||
write(progress.id, progress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,19 @@ package ru.m.tankz.storage;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
|
||||
@:provide class NetworkStorage extends SharedObjectStorage {
|
||||
public var user(get, set):User;
|
||||
|
||||
public function new() {
|
||||
super("network");
|
||||
}
|
||||
public var user(get, set):User;
|
||||
|
||||
private inline function get_user():User {
|
||||
return read("user");
|
||||
}
|
||||
public function new() {
|
||||
super("network");
|
||||
}
|
||||
|
||||
private inline function set_user(value:User):User {
|
||||
write("user", value);
|
||||
return value;
|
||||
}
|
||||
private inline function get_user():User {
|
||||
return read("user");
|
||||
}
|
||||
|
||||
private inline function set_user(value:User):User {
|
||||
write("user", value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,37 +4,38 @@ import haxe.DynamicAccess;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
|
||||
@:provide class RecordStorage extends SharedObjectStorage {
|
||||
private static inline var VERSION = 1;
|
||||
@:provide class RecordStorage extends SharedObjectStorage {
|
||||
|
||||
public function new() {
|
||||
super('record_${VERSION}');
|
||||
}
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,102 +11,105 @@ import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
enum Setting {
|
||||
CONTROL(index:Int, value:Binding);
|
||||
DISPLAY_FPS(value:Bool);
|
||||
ENABLE_NETWORK(value:Bool);
|
||||
CONTROL(index:Int, value:Binding);
|
||||
DISPLAY_FPS(value:Bool);
|
||||
ENABLE_NETWORK(value:Bool);
|
||||
}
|
||||
|
||||
@:provide class SettingsStorage extends SharedObjectStorage {
|
||||
private static inline var VERSION = 4.1;
|
||||
|
||||
public var signal(default, null):Signal<Setting> = new Signal();
|
||||
private static inline var VERSION = 4.1;
|
||||
|
||||
public var displayFPS(get, set):Bool;
|
||||
public var signal(default, null):Signal<Setting> = new Signal();
|
||||
|
||||
private function get_displayFPS():Bool {
|
||||
return read("setting:display_fps");
|
||||
}
|
||||
public var displayFPS(get, set):Bool;
|
||||
|
||||
private function set_displayFPS(value:Bool):Bool {
|
||||
write("setting:display_fps", value);
|
||||
signal.emit(DISPLAY_FPS(value));
|
||||
return get_displayFPS();
|
||||
}
|
||||
private function get_displayFPS():Bool {
|
||||
return read("setting:display_fps");
|
||||
}
|
||||
|
||||
public var enableNetwork(get, set):Bool;
|
||||
private function set_displayFPS(value:Bool):Bool {
|
||||
write("setting:display_fps", value);
|
||||
signal.emit(DISPLAY_FPS(value));
|
||||
return get_displayFPS();
|
||||
}
|
||||
|
||||
private function get_enableNetwork():Bool {
|
||||
return read("setting:enable_network");
|
||||
}
|
||||
public var enableNetwork(get, set):Bool;
|
||||
|
||||
private function set_enableNetwork(value:Bool):Bool {
|
||||
write("setting:enable_network", value);
|
||||
signal.emit(ENABLE_NETWORK(value));
|
||||
return get_enableNetwork();
|
||||
}
|
||||
private function get_enableNetwork():Bool {
|
||||
return read("setting:enable_network");
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super('settings_${VERSION}');
|
||||
}
|
||||
private function set_enableNetwork(value:Bool):Bool {
|
||||
write("setting:enable_network", value);
|
||||
signal.emit(ENABLE_NETWORK(value));
|
||||
return get_enableNetwork();
|
||||
}
|
||||
|
||||
public function getBinding(index:Int):Binding {
|
||||
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||
}
|
||||
public function new() {
|
||||
super('settings_${VERSION}');
|
||||
}
|
||||
|
||||
public function saveBinding(index:Int, value:Binding) {
|
||||
write('action:$index', value);
|
||||
signal.emit(CONTROL(index, value));
|
||||
}
|
||||
public function getBinding(index:Int):Binding {
|
||||
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||
}
|
||||
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||
}
|
||||
public function saveBinding(index:Int, value:Binding) {
|
||||
write('action:$index', value);
|
||||
signal.emit(CONTROL(index, value));
|
||||
}
|
||||
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||
SHOT(0) => {device: device, action: KEY(0)},
|
||||
SHOT(1) => {device: device, action: KEY(1)},
|
||||
SHOT(2) => {device: device, action: KEY(2)},
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||
}
|
||||
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||
SHOT(0) => {device: device, action: KEY(0)},
|
||||
SHOT(1) => {device: device, action: KEY(1)},
|
||||
SHOT(2) => {device: device, action: KEY(2)},
|
||||
];
|
||||
}
|
||||
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => null,
|
||||
MOVE(Direction.RIGHT) => null,
|
||||
SHOT(0) => null,
|
||||
SHOT(1) => null,
|
||||
SHOT(2) => null,
|
||||
];
|
||||
}
|
||||
|
||||
private static var mobileDefaults:Map<Int, Binding> = [
|
||||
0 => buildDeviceBinding(SCREEN),
|
||||
];
|
||||
}
|
||||
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => null,
|
||||
MOVE(Direction.RIGHT) => null,
|
||||
SHOT(0) => null,
|
||||
SHOT(1) => null,
|
||||
SHOT(2) => null,
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
0 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.E)},
|
||||
],
|
||||
1 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_1)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_2)},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static var mobileDefaults:Map<Int, Binding> = [0 => buildDeviceBinding(SCREEN),];
|
||||
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
0 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.E)},
|
||||
],
|
||||
1 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_1)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_2)},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -11,35 +11,34 @@ import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
|
||||
@:template class ClientView extends VGroupView {
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var resources:IResources;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var resources:IResources;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
public function new():Void {
|
||||
super();
|
||||
resources.text.put('version', '${Const.VERSION}');
|
||||
resources.text.put('name', '${Const.NAME}');
|
||||
switcher = switcherView;
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
content.stage.stageFocusRect = false;
|
||||
bus.signal.connect(onDeviceAction);
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.ESCAPE), true]:
|
||||
switcher.change(MenuFrame.ID);
|
||||
case [KEYBOARD, KEY(Keyboard.M), true]:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case _:
|
||||
public function new():Void {
|
||||
super();
|
||||
resources.text.put('version', '${Const.VERSION}');
|
||||
resources.text.put('name', '${Const.NAME}');
|
||||
switcher = switcherView;
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
content.stage.stageFocusRect = false;
|
||||
bus.signal.connect(onDeviceAction);
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.ESCAPE), true]:
|
||||
switcher.change(MenuFrame.ID);
|
||||
case [KEYBOARD, KEY(Keyboard.M), true]:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,161 +33,161 @@ import ru.m.tankz.render.IRender;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class GameFrame extends FrameView<GameInit> implements GameListener {
|
||||
public static inline var ID = "game";
|
||||
public static inline var ID = "game";
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
@:view private var render:IRender;
|
||||
@:view private var teams:DataView<TeamState, TeamView>;
|
||||
@:view private var level:TextView;
|
||||
@:view private var gamepad(default, null):GamepadView;
|
||||
@:view private var render:IRender;
|
||||
@:view private var teams:DataView<TeamState, TeamView>;
|
||||
@:view private var level:TextView;
|
||||
@:view private var gamepad(default, null):GamepadView;
|
||||
|
||||
private var gamepadPlayerId:PlayerId;
|
||||
private var gamepadPlayerId:PlayerId;
|
||||
|
||||
private var game:IGame;
|
||||
private var recorder:GameRecord;
|
||||
private var game:IGame;
|
||||
private var recorder:GameRecord;
|
||||
|
||||
public function new() {
|
||||
super(id, new DefaultLayout());
|
||||
bus.connect(gamepad);
|
||||
}
|
||||
|
||||
override public function onShow(data:GameInit):Void {
|
||||
gamepad.visible = false;
|
||||
game = switch data {
|
||||
case LOCAL(start): new LocalGame(start);
|
||||
case NETWORK(network): new NetworkGame(network);
|
||||
case RECORD(record): new GamePlayer(record);
|
||||
public function new() {
|
||||
super(id, new DefaultLayout());
|
||||
bus.connect(gamepad);
|
||||
}
|
||||
soundManager.config = game.config;
|
||||
render.config = game.config;
|
||||
game.connect(render);
|
||||
game.connect(soundManager);
|
||||
game.connect(this);
|
||||
game.start();
|
||||
// TODO:
|
||||
for (control in game.controls) {
|
||||
if (Std.is(control, HumanControl)) {
|
||||
if (cast(control, HumanControl).hasDevice(SCREEN)) {
|
||||
gamepadPlayerId = control.playerId;
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.P), true]:
|
||||
game.pause = !game.pause;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
if (game != null) {
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
render.reset();
|
||||
}
|
||||
|
||||
private function findTeamView(id:TeamId):Null<TeamView> {
|
||||
for (view in teams.dataViews) {
|
||||
if (view.teamId == id) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findPlayerView(id:PlayerId):Null<PlayerView> {
|
||||
var teamView = findTeamView(id.team);
|
||||
if (teamView != null) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.playerId == id) {
|
||||
return view;
|
||||
override public function onShow(data:GameInit):Void {
|
||||
gamepad.visible = false;
|
||||
game = switch data {
|
||||
case LOCAL(start): new LocalGame(start);
|
||||
case NETWORK(network): new NetworkGame(network);
|
||||
case RECORD(record): new GamePlayer(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
level.text = start.level.toLevelLabel();
|
||||
teams.data = [for (team in start.state.teams) team];
|
||||
// TODO: PlayerState default tank?
|
||||
for (teamView in teams.dataViews) {
|
||||
for (playerView in teamView.dataViews) {
|
||||
var tank = game.config.getPlayerTank(playerView.playerId);
|
||||
playerView.tank = {
|
||||
type: tank.type,
|
||||
skin: tank.skin,
|
||||
hits: 0,
|
||||
bonus: false,
|
||||
boat: false,
|
||||
color: game.config.getColor(playerView.playerId),
|
||||
};
|
||||
}
|
||||
}
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(TEAM_SCORE(teamId, score)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case CHANGE(PLAYER_LIFE(playerId, life)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(PLAYER_SCORE(playerId, score)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
if (gamepadPlayerId != null && playerId == gamepadPlayerId) {
|
||||
var tankConfig = game.config.getTank(info.type);
|
||||
gamepad.weapons = tankConfig.weapons;
|
||||
}
|
||||
case PAUSE(paused):
|
||||
if (paused) {
|
||||
PausePopup.instance.show().then(function(action) {
|
||||
switch action {
|
||||
case EXIT:
|
||||
switcher.change(LevelFrame.ID, game.level.packId);
|
||||
case RESUME | null:
|
||||
game.pause = false;
|
||||
soundManager.config = game.config;
|
||||
render.config = game.config;
|
||||
game.connect(render);
|
||||
game.connect(soundManager);
|
||||
game.connect(this);
|
||||
game.start();
|
||||
// TODO:
|
||||
for (control in game.controls) {
|
||||
if (Std.is(control, HumanControl)) {
|
||||
if (cast(control, HumanControl).hasDevice(SCREEN)) {
|
||||
gamepadPlayerId = control.playerId;
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PausePopup.instance.close(null);
|
||||
}
|
||||
case COMPLETE(result):
|
||||
stop();
|
||||
switcher.change(ResultFrame.ID, result);
|
||||
case _:
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
stop();
|
||||
soundManager.stopAll();
|
||||
}
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.P), true]:
|
||||
game.pause = !game.pause;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
if (game != null) {
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
render.reset();
|
||||
}
|
||||
|
||||
private function findTeamView(id:TeamId):Null<TeamView> {
|
||||
for (view in teams.dataViews) {
|
||||
if (view.teamId == id) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findPlayerView(id:PlayerId):Null<PlayerView> {
|
||||
var teamView = findTeamView(id.team);
|
||||
if (teamView != null) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.playerId == id) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
level.text = start.level.toLevelLabel();
|
||||
teams.data = [for (team in start.state.teams) team];
|
||||
// TODO: PlayerState default tank?
|
||||
for (teamView in teams.dataViews) {
|
||||
for (playerView in teamView.dataViews) {
|
||||
var tank = game.config.getPlayerTank(playerView.playerId);
|
||||
playerView.tank = {
|
||||
type: tank.type,
|
||||
skin: tank.skin,
|
||||
hits: 0,
|
||||
bonus: false,
|
||||
boat: false,
|
||||
color: game.config.getColor(playerView.playerId),
|
||||
};
|
||||
}
|
||||
}
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(TEAM_SCORE(teamId, score)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case CHANGE(PLAYER_LIFE(playerId, life)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(PLAYER_SCORE(playerId, score)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
if (gamepadPlayerId != null && playerId == gamepadPlayerId) {
|
||||
var tankConfig = game.config.getTank(info.type);
|
||||
gamepad.weapons = tankConfig.weapons;
|
||||
}
|
||||
case PAUSE(paused):
|
||||
if (paused) {
|
||||
PausePopup.instance.show().then(function(action) {
|
||||
switch action {
|
||||
case EXIT:
|
||||
switcher.change(LevelFrame.ID, game.level.packId);
|
||||
case RESUME | null:
|
||||
game.pause = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PausePopup.instance.close(null);
|
||||
}
|
||||
case COMPLETE(result):
|
||||
stop();
|
||||
switcher.change(ResultFrame.ID, result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
stop();
|
||||
soundManager.stopAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,49 +15,49 @@ import ru.m.tankz.Type.PackId;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class LevelFrame extends FrameView<PackId> {
|
||||
public static inline var ID = "level";
|
||||
public static inline var ID = "level";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
@:view var header:LabelView;
|
||||
@:view var levels:DataView<LevelConfig, ButtonView>;
|
||||
@:view var header:LabelView;
|
||||
@:view var levels:DataView<LevelConfig, ButtonView>;
|
||||
|
||||
private var pack:LevelPack;
|
||||
private var config(get, never):Config;
|
||||
private var pack:LevelPack;
|
||||
private var config(get, never):Config;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function get_config():Config {
|
||||
return configBundle.get(pack.id.type);
|
||||
}
|
||||
|
||||
override public function onShow(data:PackId):Void {
|
||||
header.text = data.toPackLabel();
|
||||
pack = levelBundle.get(data);
|
||||
levels.data = pack.data;
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
||||
var progress = storage.get(pack.id);
|
||||
var result = new ButtonView();
|
||||
result.style = "button.level";
|
||||
var presetsLine = [for (p in config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||
result.text = '${level.id}\n${presetsLine}';
|
||||
result.disabled = !progress.isLevelAvailable(level.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||
if (storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||
switcher.change(StartFrame.ID, {
|
||||
state: new GameState(pack.id.type),
|
||||
level: level,
|
||||
});
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function get_config():Config {
|
||||
return configBundle.get(pack.id.type);
|
||||
}
|
||||
|
||||
override public function onShow(data:PackId):Void {
|
||||
header.text = data.toPackLabel();
|
||||
pack = levelBundle.get(data);
|
||||
levels.data = pack.data;
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
||||
var progress = storage.get(pack.id);
|
||||
var result = new ButtonView();
|
||||
result.style = "button.level";
|
||||
var presetsLine = [for (p in config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||
result.text = '${level.id}\n${presetsLine}';
|
||||
result.disabled = !progress.isLevelAvailable(level.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||
if (storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||
switcher.change(StartFrame.ID, {
|
||||
state: new GameState(pack.id.type),
|
||||
level: level,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,76 +19,76 @@ import ru.m.update.Updater;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class MenuFrame extends FrameView<Dynamic> {
|
||||
public static var ID(default, never):String = "menu";
|
||||
|
||||
@:provide static var gameInit:GameInit;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var network:NetworkManager;
|
||||
@:provide static var appUpdater:Updater;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
public static var ID(default, never):String = "menu";
|
||||
|
||||
@:view var packs:DataView<PackId, PackView>;
|
||||
@:view("update") var updateButton:ButtonView;
|
||||
@:view("network") var networkButton:ButtonView;
|
||||
@:provide static var gameInit:GameInit;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var network:NetworkManager;
|
||||
@:provide static var appUpdater:Updater;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
@:view var packs:DataView<PackId, PackView>;
|
||||
@:view("update") var updateButton:ButtonView;
|
||||
@:view("network") var networkButton:ButtonView;
|
||||
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
appUpdater.check().then(function(update:Bool) {
|
||||
updateButton.visible = update;
|
||||
if (update) {
|
||||
updateButton.text = 'Update ${appUpdater.bundle.version}';
|
||||
}
|
||||
}).catchError(function(error) {});
|
||||
var list = levelBundle.list();
|
||||
list.sort(function(a:PackId, b:PackId) return a.toPackLabel() > b.toPackLabel() ? 1 : -1);
|
||||
packs.data = list;
|
||||
networkButton.visible = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
super.onHide();
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value):
|
||||
networkButton.visible = value;
|
||||
case _:
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
}
|
||||
|
||||
private function startGame(packId:PackId):Void {
|
||||
gameInit = LOCAL({state: new GameState(packId.type), level: null});
|
||||
switcher.change(LevelFrame.ID, packId);
|
||||
}
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
appUpdater.check().then(function(update:Bool) {
|
||||
updateButton.visible = update;
|
||||
if (update) {
|
||||
updateButton.text = 'Update ${appUpdater.bundle.version}';
|
||||
}
|
||||
}).catchError(function(error) {});
|
||||
var list = levelBundle.list();
|
||||
list.sort(function(a:PackId, b:PackId) return a.toPackLabel() > b.toPackLabel() ? 1 : -1);
|
||||
packs.data = list;
|
||||
networkButton.visible = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
private function startNetwork():Void {
|
||||
switch network.state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
switcher.change(RoomFrame.ID, network.room);
|
||||
network.joinGame(network.room.game.id, true);
|
||||
} else {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
override public function onHide():Void {
|
||||
super.onHide();
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value): networkButton.visible = value;
|
||||
case _:
|
||||
}
|
||||
case CONNECTED:
|
||||
LoginPopup.instance.show().then(function(user):Void {
|
||||
if (user != null) {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
});
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function appUpdate():Void {
|
||||
appUpdater.download();
|
||||
}
|
||||
private function startGame(packId:PackId):Void {
|
||||
gameInit = LOCAL({state: new GameState(packId.type), level: null});
|
||||
switcher.change(LevelFrame.ID, packId);
|
||||
}
|
||||
|
||||
private function startNetwork():Void {
|
||||
switch network.state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
switcher.change(RoomFrame.ID, network.room);
|
||||
network.joinGame(network.room.game.id, true);
|
||||
} else {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
case CONNECTED:
|
||||
LoginPopup.instance.show().then(function(user):Void {
|
||||
if (user != null) {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
});
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function appUpdate():Void {
|
||||
appUpdater.download();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,21 @@ import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:template class RecordFrame extends FrameView<Dynamic> {
|
||||
public static var ID(default, never):String = "record";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
public static var ID(default, never):String = "record";
|
||||
|
||||
@:view var data:VListView<GameRecordInfo>;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
@:view var data:VListView<GameRecordInfo>;
|
||||
|
||||
override public function onShow(_:Dynamic):Void {
|
||||
var data = recordStorage.list();
|
||||
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||
this.data.data = data;
|
||||
}
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(_:Dynamic):Void {
|
||||
var data = recordStorage.list();
|
||||
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||
this.data.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,53 +15,51 @@ import ru.m.tankz.view.result.ResultPlayerView;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class ResultFrame extends FrameView<Result> {
|
||||
public static var ID(default, never):String = "result";
|
||||
public static var ID(default, never):String = "result";
|
||||
|
||||
@:view("result") var resultView:DataView<PlayerState, ResultPlayerView>;
|
||||
@:view("level") var levelLabel:LabelView;
|
||||
@:view("next") var nextButton:ButtonView;
|
||||
@:view("result") var resultView:DataView<PlayerState, ResultPlayerView>;
|
||||
@:view("level") var levelLabel:LabelView;
|
||||
@:view("next") var nextButton:ButtonView;
|
||||
|
||||
@:provide var frames:FrameSwitcher;
|
||||
@:provide var frames:FrameSwitcher;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
private var result:Result;
|
||||
|
||||
private var result:Result;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(data:Result):Void {
|
||||
result = data;
|
||||
resultView.data = result.state.humans;
|
||||
for (view in resultView.dataViews) {
|
||||
view.winner = view.data.id.team == data.winner;
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
levelLabel.text = data.level.toLevelLabel();
|
||||
nextButton.disabled = !gameStorage.get(result.level.packId)
|
||||
.isPresetAvailable(result.level.id + 1, result.state.presetId);
|
||||
nextButton.text = 'Next #${result.level.id + 1}';
|
||||
}
|
||||
|
||||
private function levels():Void {
|
||||
frames.change(LevelFrame.ID, result.level.packId);
|
||||
}
|
||||
override public function onShow(data:Result):Void {
|
||||
result = data;
|
||||
resultView.data = result.state.humans;
|
||||
for (view in resultView.dataViews) {
|
||||
view.winner = view.data.id.team == data.winner;
|
||||
}
|
||||
levelLabel.text = data.level.toLevelLabel();
|
||||
nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId);
|
||||
nextButton.text = 'Next #${result.level.id + 1}';
|
||||
}
|
||||
|
||||
private function restart():Void {
|
||||
result.state.clean();
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: result.level}));
|
||||
}
|
||||
private function levels():Void {
|
||||
frames.change(LevelFrame.ID, result.level.packId);
|
||||
}
|
||||
|
||||
private function next():Void {
|
||||
var pack = levelBundle.get(result.level.packId);
|
||||
if (pack.data.length > result.level.id + 1) {
|
||||
var level = pack.data[result.level.id + 1];
|
||||
var progress = gameStorage.get(pack.id);
|
||||
if (progress.isPresetAvailable(level.id, result.state.presetId)) {
|
||||
private function restart():Void {
|
||||
result.state.clean();
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: level}));
|
||||
}
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: result.level}));
|
||||
}
|
||||
|
||||
private function next():Void {
|
||||
var pack = levelBundle.get(result.level.packId);
|
||||
if (pack.data.length > result.level.id + 1) {
|
||||
var level = pack.data[result.level.id + 1];
|
||||
var progress = gameStorage.get(pack.id);
|
||||
if (progress.isPresetAvailable(level.id, result.state.presetId)) {
|
||||
result.state.clean();
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: level}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,36 +6,34 @@ import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
@:template class SettingsFrame extends FrameView<Dynamic> {
|
||||
public static var ID(default, never):String = "settings";
|
||||
public static var ID(default, never):String = "settings";
|
||||
|
||||
@:view("fps") var fpsButton:ToggleButtonView;
|
||||
@:view("network") var networkButton:ToggleButtonView;
|
||||
@:view("fps") var fpsButton:ToggleButtonView;
|
||||
@:view("network") var networkButton:ToggleButtonView;
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
fpsButton.on = settings.displayFPS;
|
||||
networkButton.on = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value):
|
||||
fpsButton.on = value;
|
||||
case ENABLE_NETWORK(value):
|
||||
networkButton.on = value;
|
||||
case _:
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
fpsButton.on = settings.displayFPS;
|
||||
networkButton.on = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value): fpsButton.on = value;
|
||||
case ENABLE_NETWORK(value): networkButton.on = value;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,115 +19,116 @@ using haxe.EnumTools.EnumValueTools;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class StartFrame extends FrameView<Start> {
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
private var progress:PackProgress;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
|
||||
@:view var header:LabelView;
|
||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||
@:view("teams") var teamsView:DataView<Array<PlayerControl>, DataView<PlayerControl, SlotView>>;
|
||||
private var progress:PackProgress;
|
||||
|
||||
private var humanIndex:Int = 0;
|
||||
private var humanTotal:Int = 2;
|
||||
@:view var header:LabelView;
|
||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||
@:view("teams") var teamsView:DataView<Array<PlayerControl>, DataView<PlayerControl, SlotView>>;
|
||||
|
||||
private var start:Start;
|
||||
private var humanIndex:Int = 0;
|
||||
private var humanTotal:Int = 2;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
private var start:Start;
|
||||
|
||||
override public function onShow(data:Start):Void {
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
this.progress = storage.get(start.level.packId);
|
||||
header.text = start.level.toLevelLabel();
|
||||
presetsView.data = start.state.config.presets;
|
||||
teamsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
private static function defaultControls(config:Config):Array<Array<PlayerControl>> {
|
||||
var result:Array<Array<PlayerControl>> = [];
|
||||
var preset = config.getPreset(0);
|
||||
var human = false;
|
||||
for (team in preset.teams) {
|
||||
if (team.id != "bot") { // ToDo:
|
||||
var controls:Array<PlayerControl> = [];
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
var control:PlayerControl = {
|
||||
playerId: playerId,
|
||||
color: config.getColor(playerId),
|
||||
controller: NONE,
|
||||
}
|
||||
if (!human) {
|
||||
control.controller = HUMAN(0);
|
||||
control.name = ControllerParser.defaultName(control.controller);
|
||||
human = true;
|
||||
}
|
||||
controls.push(control);
|
||||
}
|
||||
result.push(controls);
|
||||
}
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function teamViewFactory(index:Int, value:Array<PlayerControl>):DataView<PlayerControl, SlotView> {
|
||||
var result = new DataView();
|
||||
result.style = "light";
|
||||
result.geometry.padding = 5;
|
||||
result.factory = slotViewFactory;
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
override public function onShow(data:Start):Void {
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
this.progress = storage.get(start.level.packId);
|
||||
header.text = start.level.toLevelLabel();
|
||||
presetsView.data = start.state.config.presets;
|
||||
teamsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
|
||||
var result = new SlotView();
|
||||
result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
|
||||
result.control = value;
|
||||
result.tank = start.state.config.getPlayerTank(value.playerId).skin;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function setController(value:PlayerControl, controller:Controller):Void {
|
||||
switch controller {
|
||||
case NONE:
|
||||
case _:
|
||||
for (teamView in teamsView.dataViews) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.control.controller.equals(controller)) {
|
||||
view.control.controller = NONE;
|
||||
view.select.selected = NONE;
|
||||
view.control.name = null;
|
||||
private static function defaultControls(config:Config):Array<Array<PlayerControl>> {
|
||||
var result:Array<Array<PlayerControl>> = [];
|
||||
var preset = config.getPreset(0);
|
||||
var human = false;
|
||||
for (team in preset.teams) {
|
||||
if (team.id != "bot") { // ToDo:
|
||||
var controls:Array<PlayerControl> = [];
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
var control:PlayerControl = {
|
||||
playerId: playerId,
|
||||
color: config.getColor(playerId),
|
||||
controller: NONE,
|
||||
}
|
||||
if (!human) {
|
||||
control.controller = HUMAN(0);
|
||||
control.name = ControllerParser.defaultName(control.controller);
|
||||
human = true;
|
||||
}
|
||||
controls.push(control);
|
||||
}
|
||||
result.push(controls);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function teamViewFactory(index:Int, value:Array<PlayerControl>):DataView<PlayerControl, SlotView> {
|
||||
var result = new DataView();
|
||||
result.style = "light";
|
||||
result.geometry.padding = 5;
|
||||
result.factory = slotViewFactory;
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
|
||||
var result = new SlotView();
|
||||
result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
|
||||
result.control = value;
|
||||
result.tank = start.state.config.getPlayerTank(value.playerId).skin;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function setController(value:PlayerControl, controller:Controller):Void {
|
||||
switch controller {
|
||||
case NONE:
|
||||
case _:
|
||||
for (teamView in teamsView.dataViews) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.control.controller.equals(controller)) {
|
||||
view.control.controller = NONE;
|
||||
view.select.selected = NONE;
|
||||
view.control.name = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
value.controller = controller;
|
||||
value.name = ControllerParser.defaultName(controller);
|
||||
}
|
||||
|
||||
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
||||
var result = new ButtonView();
|
||||
result.style = 'button${!progress.isPresetCompleted(start.level.id, value.id) ? ".active" : ""}';
|
||||
result.geometry.height = "100%";
|
||||
result.text = value.name == "default" ? "start" : value.name;
|
||||
result.disabled = !progress.isPresetAvailable(start.level.id, value.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onPresetSelect(value:GamePreset):Void {
|
||||
if (progress.isPresetAvailable(start.level.id, value.id)) {
|
||||
start.state.presetId = value.id;
|
||||
var controls = [];
|
||||
for (item in teamsView.data) {
|
||||
controls = controls.concat(item);
|
||||
}
|
||||
start.state.controls = controls;
|
||||
switcher.change(GameFrame.ID, LOCAL(start));
|
||||
}
|
||||
}
|
||||
value.controller = controller;
|
||||
value.name = ControllerParser.defaultName(controller);
|
||||
}
|
||||
|
||||
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
||||
var result = new ButtonView();
|
||||
result.style = 'button${!progress.isPresetCompleted(start.level.id, value.id) ? ".active" : ""}';
|
||||
result.geometry.height = "100%";
|
||||
result.text = value.name == "default" ? "start" : value.name;
|
||||
result.disabled = !progress.isPresetAvailable(start.level.id, value.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onPresetSelect(value:GamePreset):Void {
|
||||
if (progress.isPresetAvailable(start.level.id, value.id)) {
|
||||
start.state.presetId = value.id;
|
||||
var controls = [];
|
||||
for (item in teamsView.data) {
|
||||
controls = controls.concat(item);
|
||||
}
|
||||
start.state.controls = controls;
|
||||
switcher.change(GameFrame.ID, LOCAL(start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,53 +8,55 @@ import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class KeyboardMap {
|
||||
private var data:Map<Int, String>;
|
||||
|
||||
public function new() {
|
||||
this.data = new Map();
|
||||
var data = Assets.getText("resources/keyboard.txt");
|
||||
for (line in data.split("\n")) {
|
||||
var arr = line.split("\t");
|
||||
if (arr.length == 2) {
|
||||
this.data.set(Std.parseInt(arr[1]), arr[0]);
|
||||
}
|
||||
private 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;
|
||||
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);
|
||||
}
|
||||
public static function getName(key:Int):String {
|
||||
if (instance == null) instance = new KeyboardMap();
|
||||
return key == -1 ? "(NONE)" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||
}
|
||||
}
|
||||
|
||||
class ViewUtil {
|
||||
public static function toLevelLabel(level:LevelConfig, oneline:Bool = false):String {
|
||||
var result:Array<String> = ['${level.packId.type} #${level.id}'];
|
||||
if (level.name != null) {
|
||||
result.push(level.name);
|
||||
|
||||
public static function toLevelLabel(level:LevelConfig, oneline:Bool = false):String {
|
||||
var result:Array<String> = ['${level.packId.type} #${level.id}'];
|
||||
if (level.name != null) {
|
||||
result.push(level.name);
|
||||
}
|
||||
return result.join(oneline ? " " : "\n");
|
||||
}
|
||||
return result.join(oneline ? " " : "\n");
|
||||
}
|
||||
|
||||
public static function toPackLabel(packId:PackId, separator = " #"):String {
|
||||
return packId.name != PackId.DEFAULT ? '${packId.type}${separator}${packId.name}' : packId.type;
|
||||
}
|
||||
|
||||
public static function toActionLabel(action:TankAction):String {
|
||||
return switch (action) {
|
||||
case MOVE(d): 'MOVE_$d';
|
||||
case SHOT(w): 'SHOT_$w';
|
||||
case x: '$x';
|
||||
public static function toPackLabel(packId:PackId, separator=" #"):String {
|
||||
return packId.name != PackId.DEFAULT ? '${packId.type}${separator}${packId.name}' : packId.type;
|
||||
}
|
||||
}
|
||||
|
||||
public static function toBindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
public static function toActionLabel(action:TankAction):String {
|
||||
return switch (action) {
|
||||
case MOVE(d): 'MOVE_$d';
|
||||
case SHOT(w): 'SHOT_$w';
|
||||
case x: '$x';
|
||||
}
|
||||
}
|
||||
|
||||
public static function toBindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,55 +9,56 @@ import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
|
||||
@:template class NetworkStateView extends HGroupView {
|
||||
@:view("state") var stateView:SpriteView;
|
||||
@:view("user") var userLabel:LabelView;
|
||||
@:view("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
|
||||
@:provide static var network:NetworkManager;
|
||||
@:view("state") var stateView:SpriteView;
|
||||
@:view("user") var userLabel:LabelView;
|
||||
@:view("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
|
||||
public function new():Void {
|
||||
super();
|
||||
network.stateSignal.connect(onConnectionChange);
|
||||
}
|
||||
@:provide static var network:NetworkManager;
|
||||
|
||||
private function onConnectionChange(state:ConnectionState):Void {
|
||||
visible = true;
|
||||
stateView.visible = true;
|
||||
userLabel.text = "";
|
||||
loginButton.visible = false;
|
||||
logoutButton.visible = false;
|
||||
var skin:SpriteSkin = cast stateView.skin;
|
||||
switch state {
|
||||
case OFFLINE:
|
||||
skin.background.color = "black";
|
||||
stateView.visible = false;
|
||||
visible = false;
|
||||
case CONNECT:
|
||||
skin.background.color = "yellow";
|
||||
case CONNECTED:
|
||||
skin.background.color = "gray";
|
||||
loginButton.visible = true;
|
||||
case LOGIN:
|
||||
skin.background.color = "yellow";
|
||||
case ONLINE(user):
|
||||
skin.background.color = "green";
|
||||
userLabel.text = user.name;
|
||||
logoutButton.visible = true;
|
||||
case ERROR(error):
|
||||
skin.background.color = "red";
|
||||
userLabel.text = Std.string(error).substr(0, 10);
|
||||
public function new():Void {
|
||||
super();
|
||||
network.stateSignal.connect(onConnectionChange);
|
||||
}
|
||||
stateView.toRedraw();
|
||||
}
|
||||
|
||||
private function login():Void {
|
||||
LoginPopup.instance.show().then(function(user:User):Void {
|
||||
L.d("Login", 'user: $user');
|
||||
});
|
||||
}
|
||||
private function onConnectionChange(state:ConnectionState):Void {
|
||||
visible = true;
|
||||
stateView.visible = true;
|
||||
userLabel.text = "";
|
||||
loginButton.visible = false;
|
||||
logoutButton.visible = false;
|
||||
var skin:SpriteSkin = cast stateView.skin;
|
||||
switch state {
|
||||
case OFFLINE:
|
||||
skin.background.color = "black";
|
||||
stateView.visible = false;
|
||||
visible = false;
|
||||
case CONNECT:
|
||||
skin.background.color = "yellow";
|
||||
case CONNECTED:
|
||||
skin.background.color = "gray";
|
||||
loginButton.visible = true;
|
||||
case LOGIN:
|
||||
skin.background.color = "yellow";
|
||||
case ONLINE(user):
|
||||
skin.background.color = "green";
|
||||
userLabel.text = user.name;
|
||||
logoutButton.visible = true;
|
||||
case ERROR(error):
|
||||
skin.background.color = "red";
|
||||
userLabel.text = Std.string(error).substr(0, 10);
|
||||
}
|
||||
stateView.toRedraw();
|
||||
}
|
||||
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
}
|
||||
private function login():Void {
|
||||
LoginPopup.instance.show().then(function(user:User):Void {
|
||||
L.d("Login", 'user: $user');
|
||||
});
|
||||
}
|
||||
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,28 +9,29 @@ import ru.m.tankz.Type;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class PackView extends VGroupView {
|
||||
public var data(default, set):PackId;
|
||||
|
||||
@:view var label:LabelView;
|
||||
@:view var state:LabelView;
|
||||
public var data(default, set):PackId;
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:view var label:LabelView;
|
||||
@:view var state:LabelView;
|
||||
|
||||
private function set_data(value:PackId):PackId {
|
||||
if (data != value) {
|
||||
data = value;
|
||||
label.text = data.toPackLabel("\n");
|
||||
var progress = gameStorage.get(data).progress;
|
||||
var total = levelBundle.get(data).data.length;
|
||||
state.text = '${progress}/${total}';
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
private function set_data(value:PackId):PackId {
|
||||
if (data != value) {
|
||||
data = value;
|
||||
label.text = data.toPackLabel("\n");
|
||||
var progress = gameStorage.get(data).progress;
|
||||
var total = levelBundle.get(data).data.length;
|
||||
state.text = '${progress}/${total}';
|
||||
}
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static function factory(index:Int, value:PackId):PackView {
|
||||
var result = new PackView();
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
public static function factory(index:Int, value:PackId):PackView {
|
||||
var result = new PackView();
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,38 +9,38 @@ import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:template class RecordView extends HGroupView implements IListItemView<GameRecordInfo> {
|
||||
@:view var date:LabelView;
|
||||
@:view var type:LabelView;
|
||||
@:view var level:LabelView;
|
||||
@:view var preset:LabelView;
|
||||
@:view var date:LabelView;
|
||||
@:view var type:LabelView;
|
||||
@:view var level:LabelView;
|
||||
@:view var preset:LabelView;
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):GameRecordInfo;
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):GameRecordInfo;
|
||||
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
||||
if (data != value) {
|
||||
data = value;
|
||||
date.text = data.date.toString();
|
||||
type.text = data.type;
|
||||
level.text = Std.string(data.levelId);
|
||||
preset.text = Std.string(data.presetId);
|
||||
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
||||
if (data != value) {
|
||||
data = value;
|
||||
date.text = data.date.toString();
|
||||
type.text = data.type;
|
||||
level.text = Std.string(data.levelId);
|
||||
preset.text = Std.string(data.presetId);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private function play():Void {
|
||||
var record = recordStorage.read(data.id);
|
||||
switcher.change(GameFrame.ID, RECORD(record));
|
||||
}
|
||||
private function play():Void {
|
||||
var record = recordStorage.read(data.id);
|
||||
switcher.change(GameFrame.ID, RECORD(record));
|
||||
}
|
||||
|
||||
private function delete():Void {
|
||||
recordStorage.delete(data.id);
|
||||
// ToDo:
|
||||
var list = cast(parent.parent.parent, ListView<Dynamic>);
|
||||
list.data.splice(item_index, 1);
|
||||
list.toUpdate();
|
||||
}
|
||||
private function delete():Void {
|
||||
recordStorage.delete(data.id);
|
||||
// ToDo:
|
||||
var list = cast(parent.parent.parent, ListView<Dynamic>);
|
||||
list.data.splice(item_index, 1);
|
||||
list.toUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,38 +10,39 @@ import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
|
||||
@:template class SlotView extends HGroupView {
|
||||
@:view("tank") public var tankView:ImageView;
|
||||
@:view("slot") public var slotLabel:LabelView;
|
||||
@:view("select") public var select:SelectView<Controller>;
|
||||
|
||||
public var control(default, set):PlayerControl;
|
||||
public var tank(default, set):String;
|
||||
@:view("tank") public var tankView:ImageView;
|
||||
@:view("slot") public var slotLabel:LabelView;
|
||||
@:view("select") public var select:SelectView<Controller>;
|
||||
|
||||
private function set_control(value:PlayerControl):PlayerControl {
|
||||
control = value;
|
||||
slotLabel.text = '${control.playerId.team} #${control.playerId.index}';
|
||||
var skin:SpriteSkin = cast slotLabel.skin;
|
||||
skin.border.color = value.color;
|
||||
skin.border.alpha = 0.8;
|
||||
skin.background.color = value.color;
|
||||
skin.background.alpha = 0.2;
|
||||
select.selected = control.controller;
|
||||
tankView.color = value.color;
|
||||
return control;
|
||||
}
|
||||
public var control(default, set):PlayerControl;
|
||||
public var tank(default, set):String;
|
||||
|
||||
private function set_tank(value:String):String {
|
||||
if (tank != value) {
|
||||
tank = value;
|
||||
tankView.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
|
||||
private function set_control(value:PlayerControl):PlayerControl {
|
||||
control = value;
|
||||
slotLabel.text = '${control.playerId.team} #${control.playerId.index}';
|
||||
var skin:SpriteSkin = cast slotLabel.skin;
|
||||
skin.border.color = value.color;
|
||||
skin.border.alpha = 0.8;
|
||||
skin.background.color = value.color;
|
||||
skin.background.alpha = 0.2;
|
||||
select.selected = control.controller;
|
||||
tankView.color = value.color;
|
||||
return control;
|
||||
}
|
||||
return tank;
|
||||
}
|
||||
|
||||
private function onControllerSelect(value:Controller):Void {
|
||||
select.currentView.style = switch value {
|
||||
case HUMAN(_): "button.active";
|
||||
case _: "button";
|
||||
private function set_tank(value:String):String {
|
||||
if (tank != value) {
|
||||
tank = value;
|
||||
tankView.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
|
||||
}
|
||||
return tank;
|
||||
}
|
||||
|
||||
private function onControllerSelect(value:Controller):Void {
|
||||
select.currentView.style = switch value {
|
||||
case HUMAN(_): "button.active";
|
||||
case _: "button";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,20 @@ import ru.m.tankz.render.RenderUtil;
|
||||
import ru.m.tankz.Type.TankInfo;
|
||||
|
||||
class TankView extends ImageView {
|
||||
public var tank(null, set):TankInfo;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
style = "icon.tank";
|
||||
fillType = FillType.CONTAIN;
|
||||
}
|
||||
public var tank(null, set):TankInfo;
|
||||
|
||||
private function set_tank(value:TankInfo):TankInfo {
|
||||
if (value != null) {
|
||||
color = value.color;
|
||||
image = RenderUtil.tankImage(value.skin);
|
||||
public function new() {
|
||||
super();
|
||||
style = "icon.tank";
|
||||
fillType = FillType.CONTAIN;
|
||||
}
|
||||
|
||||
private function set_tank(value:TankInfo):TankInfo {
|
||||
if (value != null) {
|
||||
color = value.color;
|
||||
image = RenderUtil.tankImage(value.skin);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,45 +7,46 @@ import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.common.TankView;
|
||||
|
||||
@:template class PlayerView extends VGroupView {
|
||||
@:view("title") public var titleView:LabelView;
|
||||
@:view("tank") public var tankView:TankView;
|
||||
@:view("life") public var lifeLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
public var playerId(default, default):PlayerId;
|
||||
public var state(null, set):PlayerState;
|
||||
public var tank(null, set):TankInfo;
|
||||
public var life(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
@:view("title") public var titleView:LabelView;
|
||||
@:view("tank") public var tankView:TankView;
|
||||
@:view("life") public var lifeLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
private function set_state(value:PlayerState):PlayerState {
|
||||
playerId = value.id;
|
||||
titleView.text = value.name != null ? value.name : playerId.format();
|
||||
life = value.life;
|
||||
score = value.score;
|
||||
tank = value.tank;
|
||||
return state;
|
||||
}
|
||||
public var playerId(default, default):PlayerId;
|
||||
public var state(null, set):PlayerState;
|
||||
public var tank(null, set):TankInfo;
|
||||
public var life(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
|
||||
private function set_tank(value:TankInfo):TankInfo {
|
||||
tank = value;
|
||||
tankView.tank = tank;
|
||||
return tank;
|
||||
}
|
||||
private function set_state(value:PlayerState):PlayerState {
|
||||
playerId = value.id;
|
||||
titleView.text = value.name != null ? value.name : playerId.format();
|
||||
life = value.life;
|
||||
score = value.score;
|
||||
tank = value.tank;
|
||||
return state;
|
||||
}
|
||||
|
||||
private function set_life(value:Int):Int {
|
||||
lifeLabel.text = '${value}';
|
||||
return value;
|
||||
}
|
||||
private function set_tank(value:TankInfo):TankInfo {
|
||||
tank = value;
|
||||
tankView.tank = tank;
|
||||
return tank;
|
||||
}
|
||||
|
||||
private function set_score(value:Int):Int {
|
||||
scoreLabel.text = '${value}$';
|
||||
return value;
|
||||
}
|
||||
private function set_life(value:Int):Int {
|
||||
lifeLabel.text = '${value}';
|
||||
return value;
|
||||
}
|
||||
|
||||
public static function factory(index:Int, data:PlayerState):PlayerView {
|
||||
var result = new PlayerView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
private function set_score(value:Int):Int {
|
||||
scoreLabel.text = '${value}$';
|
||||
return value;
|
||||
}
|
||||
|
||||
public static function factory(index:Int, data:PlayerState):PlayerView {
|
||||
var result = new PlayerView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,31 +5,32 @@ import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class TeamView extends DataView<PlayerState, PlayerView> {
|
||||
public var teamId(default, default):TeamId;
|
||||
public var state(default, set):TeamState;
|
||||
|
||||
private function new():Void {
|
||||
super();
|
||||
factory = PlayerView.factory;
|
||||
layout.margin = 5;
|
||||
geometry.width = "100%";
|
||||
}
|
||||
public var teamId(default, default):TeamId;
|
||||
public var state(default, set):TeamState;
|
||||
|
||||
private function set_state(value:TeamState):TeamState {
|
||||
teamId = value.id;
|
||||
var players = [for (player in value.players) player].filter(function(player) return player.life > 0);
|
||||
if (value.life > 0) {
|
||||
var teamState = new PlayerState([value.id, -1]);
|
||||
teamState.life = value.life;
|
||||
players.unshift(teamState);
|
||||
private function new():Void {
|
||||
super();
|
||||
factory = PlayerView.factory;
|
||||
layout.margin = 5;
|
||||
geometry.width = "100%";
|
||||
}
|
||||
data = players;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static inline function viewFactory(index:Int, data:TeamState):TeamView {
|
||||
var result = new TeamView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
private function set_state(value:TeamState):TeamState {
|
||||
teamId = value.id;
|
||||
var players = [for (player in value.players) player].filter(function(player) return player.life > 0);
|
||||
if (value.life > 0) {
|
||||
var teamState = new PlayerState([value.id, -1]);
|
||||
teamState.life = value.life;
|
||||
players.unshift(teamState);
|
||||
}
|
||||
data = players;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static inline function viewFactory(index:Int, data:TeamState):TeamView {
|
||||
var result = new TeamView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import ru.m.geom.Circle;
|
||||
import ru.m.geom.Point;
|
||||
|
||||
class CircleActionArea implements IActionArea {
|
||||
public var action(default, null):DeviceAction;
|
||||
public var circle(default, null):Circle;
|
||||
public var action(default, null):DeviceAction;
|
||||
public var circle(default, null):Circle;
|
||||
|
||||
public function new(action:DeviceAction, circle:Circle) {
|
||||
this.action = action;
|
||||
this.circle = circle;
|
||||
}
|
||||
public function new(action:DeviceAction, circle:Circle) {
|
||||
this.action = action;
|
||||
this.circle = circle;
|
||||
}
|
||||
|
||||
public function contain(point:Point):Bool {
|
||||
return circle.contain(point);
|
||||
}
|
||||
public function contain(point:Point):Bool {
|
||||
return circle.contain(point);
|
||||
}
|
||||
|
||||
public function draw(graphics:Graphics):Void {
|
||||
graphics.drawCircle(circle.x, circle.y, circle.radius);
|
||||
}
|
||||
public function draw(graphics:Graphics):Void {
|
||||
graphics.drawCircle(circle.x, circle.y, circle.radius);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,27 +5,38 @@ import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class DefaultActionAreaBuilder implements IActionAreaBuilder {
|
||||
public function new() {}
|
||||
public function new() {
|
||||
}
|
||||
|
||||
public function build(width:Float, height:Float):Array<IActionArea> {
|
||||
var areas:Array<IActionArea> = [];
|
||||
var size = Math.min(width, height) / 7;
|
||||
var padding = size / 2;
|
||||
// top
|
||||
areas.push(new RectangleActionArea(DIRECTION(Direction.TOP),
|
||||
new Rectangle(padding + size, height - size * 3 - padding, size, size)));
|
||||
// left
|
||||
areas.push(new RectangleActionArea(DIRECTION(Direction.LEFT),
|
||||
new Rectangle(padding, height - size * 2 - padding, size, size)));
|
||||
// bottom
|
||||
areas.push(new RectangleActionArea(DIRECTION(Direction.BOTTOM),
|
||||
new Rectangle(padding + size, height - size - padding, size, size)));
|
||||
// right
|
||||
areas.push(new RectangleActionArea(DIRECTION(Direction.RIGHT),
|
||||
new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)));
|
||||
// button
|
||||
areas.push(new RectangleActionArea(KEY(0),
|
||||
new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)));
|
||||
return areas;
|
||||
}
|
||||
public function build(width:Float, height:Float):Array<IActionArea> {
|
||||
var areas:Array<IActionArea> = [];
|
||||
var size = Math.min(width, height) / 7;
|
||||
var padding = size / 2;
|
||||
// top
|
||||
areas.push(new RectangleActionArea(
|
||||
DIRECTION(Direction.TOP),
|
||||
new Rectangle(padding + size, height - size * 3 - padding, size, size)
|
||||
));
|
||||
// left
|
||||
areas.push(new RectangleActionArea(
|
||||
DIRECTION(Direction.LEFT),
|
||||
new Rectangle(padding, height - size * 2 - padding, size, size)
|
||||
));
|
||||
// bottom
|
||||
areas.push(new RectangleActionArea(
|
||||
DIRECTION(Direction.BOTTOM),
|
||||
new Rectangle(padding + size, height - size - padding, size, size)
|
||||
));
|
||||
// right
|
||||
areas.push(new RectangleActionArea(
|
||||
DIRECTION(Direction.RIGHT),
|
||||
new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
|
||||
));
|
||||
// button
|
||||
areas.push(new RectangleActionArea(
|
||||
KEY(0),
|
||||
new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
|
||||
));
|
||||
return areas;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,31 +6,32 @@ import hw.view.skin.ISkin;
|
||||
import ru.m.control.DeviceAction;
|
||||
|
||||
@:style class GamepadSkin implements ISkin<GamepadView> {
|
||||
@:style(0xffffff) public var color(default, default):Null<Color>;
|
||||
@:style(0x00ff00) public var activeColor(default, default):Null<Color>;
|
||||
|
||||
public function new(?color:Color) {
|
||||
this.color = color;
|
||||
}
|
||||
@:style(0xffffff) public var color(default, default):Null<Color>;
|
||||
@:style(0x00ff00) public var activeColor(default, default):Null<Color>;
|
||||
|
||||
public function draw(view:GamepadView):Void {
|
||||
var actives = [for (item in view.activeAreas.iterator()) item];
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
for (area in view.areas) {
|
||||
switch area.action {
|
||||
case KEY(code):
|
||||
if (view.weapons.length < code + 1) {
|
||||
continue;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
var color = actives.indexOf(area) > -1 ? activeColor : color;
|
||||
graphics.lineStyle(2, color);
|
||||
graphics.beginFill(color, 0.2);
|
||||
area.draw(graphics);
|
||||
public function new(?color:Color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:GamepadView):Void {
|
||||
var actives = [for (item in view.activeAreas.iterator()) item];
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
for (area in view.areas) {
|
||||
switch area.action {
|
||||
case KEY(code):
|
||||
if (view.weapons.length < code + 1) {
|
||||
continue;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
var color = actives.indexOf(area) > -1 ? activeColor : color;
|
||||
graphics.lineStyle(2, color);
|
||||
graphics.beginFill(color, 0.2);
|
||||
area.draw(graphics);
|
||||
}
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,116 +12,117 @@ import ru.m.geom.Point;
|
||||
import ru.m.tankz.config.Config;
|
||||
|
||||
class GamepadView extends SpriteView implements IControlDevice {
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public var areas(default, null):Array<IActionArea>;
|
||||
public var activeAreas(default, null):Map<Int, IActionArea>;
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public var weapons(default, set):Array<WeaponConfig>;
|
||||
public var areas(default, null):Array<IActionArea>;
|
||||
public var activeAreas(default, null):Map<Int, IActionArea>;
|
||||
|
||||
private function set_weapons(value:Array<WeaponConfig>):Array<WeaponConfig> {
|
||||
weapons = value;
|
||||
toRedraw();
|
||||
return weapons;
|
||||
}
|
||||
public var weapons(default, set):Array<WeaponConfig>;
|
||||
|
||||
private var builder:IActionAreaBuilder;
|
||||
|
||||
private var actionLayer:Sprite;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
style = "gamepad";
|
||||
type = SCREEN;
|
||||
builder = new SmartActionAreaBuilder();
|
||||
signal = new Signal2();
|
||||
areas = [];
|
||||
weapons = [];
|
||||
activeAreas = new Map();
|
||||
skin = new GamepadSkin();
|
||||
actionLayer = new Sprite();
|
||||
actionLayer.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
actionLayer.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
content.addChild(actionLayer);
|
||||
}
|
||||
|
||||
private function onMouseDown(event:MouseEvent):Void {
|
||||
onMouseMove(event);
|
||||
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onMouseMove(event:MouseEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(-1, point);
|
||||
}
|
||||
|
||||
private function onMouseUp(event:MouseEvent):Void {
|
||||
endTouch(-1);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onTouchBegin(event:TouchEvent):Void {
|
||||
onTouchMove(event);
|
||||
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
|
||||
private function onTouchMove(event:TouchEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(event.touchPointID, point);
|
||||
}
|
||||
|
||||
private function onTouchEnd(event:TouchEvent):Void {
|
||||
endTouch(event.touchPointID);
|
||||
if (Lambda.count(activeAreas) == 0) {
|
||||
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateTouch(pointID:Int, point:Point):Void {
|
||||
if (activeAreas.exists(pointID)) {
|
||||
var area = activeAreas[pointID];
|
||||
if (!area.contain(point)) {
|
||||
activeAreas.remove(pointID);
|
||||
signal.emit(area.action, false);
|
||||
private function set_weapons(value:Array<WeaponConfig>):Array<WeaponConfig> {
|
||||
weapons = value;
|
||||
toRedraw();
|
||||
}
|
||||
} else {
|
||||
for (area in areas) {
|
||||
if (area.contain(point)) {
|
||||
activeAreas[pointID] = area;
|
||||
signal.emit(area.action, true);
|
||||
toRedraw();
|
||||
break;
|
||||
return weapons;
|
||||
}
|
||||
|
||||
private var builder:IActionAreaBuilder;
|
||||
|
||||
private var actionLayer:Sprite;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
style = "gamepad";
|
||||
type = SCREEN;
|
||||
builder = new SmartActionAreaBuilder();
|
||||
signal = new Signal2();
|
||||
areas = [];
|
||||
weapons = [];
|
||||
activeAreas = new Map();
|
||||
skin = new GamepadSkin();
|
||||
actionLayer = new Sprite();
|
||||
actionLayer.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
actionLayer.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
content.addChild(actionLayer);
|
||||
}
|
||||
|
||||
private function onMouseDown(event:MouseEvent):Void {
|
||||
onMouseMove(event);
|
||||
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onMouseMove(event:MouseEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(-1, point);
|
||||
}
|
||||
|
||||
private function onMouseUp(event:MouseEvent):Void {
|
||||
endTouch(-1);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onTouchBegin(event:TouchEvent):Void {
|
||||
onTouchMove(event);
|
||||
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
|
||||
private function onTouchMove(event:TouchEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(event.touchPointID, point);
|
||||
}
|
||||
|
||||
private function onTouchEnd(event:TouchEvent):Void {
|
||||
endTouch(event.touchPointID);
|
||||
if (Lambda.count(activeAreas) == 0) {
|
||||
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function endTouch(pointID:Int):Void {
|
||||
if (activeAreas.exists(pointID)) {
|
||||
signal.emit(activeAreas[pointID].action, false);
|
||||
activeAreas.remove(pointID);
|
||||
toRedraw();
|
||||
private function updateTouch(pointID:Int, point:Point):Void {
|
||||
if (activeAreas.exists(pointID)) {
|
||||
var area = activeAreas[pointID];
|
||||
if (!area.contain(point)) {
|
||||
activeAreas.remove(pointID);
|
||||
signal.emit(area.action, false);
|
||||
toRedraw();
|
||||
}
|
||||
} else {
|
||||
for (area in areas) {
|
||||
if (area.contain(point)) {
|
||||
activeAreas[pointID] = area;
|
||||
signal.emit(area.action, true);
|
||||
toRedraw();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
areas = builder.build(width, height);
|
||||
actionLayer.graphics.clear();
|
||||
actionLayer.graphics.beginFill(0, 0.0);
|
||||
actionLayer.graphics.drawRect(0, 0, width, height);
|
||||
actionLayer.graphics.endFill();
|
||||
}
|
||||
private function endTouch(pointID:Int):Void {
|
||||
if (activeAreas.exists(pointID)) {
|
||||
signal.emit(activeAreas[pointID].action, false);
|
||||
activeAreas.remove(pointID);
|
||||
toRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
actionLayer.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
actionLayer.removeEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
stage = null;
|
||||
}
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
areas = builder.build(width, height);
|
||||
actionLayer.graphics.clear();
|
||||
actionLayer.graphics.beginFill(0, 0.0);
|
||||
actionLayer.graphics.drawRect(0, 0, width, height);
|
||||
actionLayer.graphics.endFill();
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
actionLayer.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
actionLayer.removeEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
stage = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import ru.m.control.DeviceAction;
|
||||
import ru.m.geom.Point;
|
||||
|
||||
interface IActionArea {
|
||||
public var action(default, null):DeviceAction;
|
||||
public function contain(point:Point):Bool;
|
||||
public function draw(graphics:Graphics):Void;
|
||||
public var action(default, null):DeviceAction;
|
||||
public function contain(point:Point):Bool;
|
||||
public function draw(graphics:Graphics):Void;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package ru.m.tankz.view.gamepad;
|
||||
|
||||
interface IActionAreaBuilder {
|
||||
public function build(width:Float, height:Float):Array<IActionArea>;
|
||||
public function build(width:Float, height:Float):Array<IActionArea>;
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class RectangleActionArea implements IActionArea {
|
||||
public var action(default, null):DeviceAction;
|
||||
public var rectangle(default, null):Rectangle;
|
||||
public var action(default, null):DeviceAction;
|
||||
public var rectangle(default, null):Rectangle;
|
||||
|
||||
public function new(action:DeviceAction, rectangle:Rectangle) {
|
||||
this.action = action;
|
||||
this.rectangle = rectangle;
|
||||
}
|
||||
public function new(action:DeviceAction, rectangle:Rectangle) {
|
||||
this.action = action;
|
||||
this.rectangle = rectangle;
|
||||
}
|
||||
|
||||
public function contain(point:Point):Bool {
|
||||
return rectangle.contain(point);
|
||||
}
|
||||
public function contain(point:Point):Bool {
|
||||
return rectangle.contain(point);
|
||||
}
|
||||
|
||||
public function draw(graphics:Graphics):Void {
|
||||
graphics.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
}
|
||||
public function draw(graphics:Graphics):Void {
|
||||
graphics.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user