Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4863f37eef | |||
| c9ec4395ee | |||
| b62956cc95 | |||
| b2ba4362fe | |||
| 7cca35195d | |||
| d4a9c720d6 | |||
| d2383fc4f0 | |||
| 74322ca6a4 | |||
| a6323edb36 | |||
| 2d4c56d04c | |||
| e3d3359019 | |||
| 2aa1c82aea | |||
| 45af6c2a50 | |||
| d6cf708035 | |||
| 085431fe73 | |||
| 95148a9b0b | |||
| a24d610b05 | |||
| f8bba85eb4 | |||
| 80f2ac25ad | |||
| 17e4f1f172 | |||
| af5aa6b8e6 | |||
| 1fd1c669a0 | |||
| 122c54a0de | |||
| ac1df9a9a4 | |||
| d0c796aab2 | |||
| 17289fde92 | |||
| 7d27f0cd35 | |||
| a64463ddc6 | |||
| 007621c48c | |||
| 33b0693a4e | |||
| 13c1299bf0 | |||
| fbdf018422 | |||
| 8800fe48ee | |||
| 2be44de710 | |||
| 9269bde518 | |||
| 4c8181b3ea | |||
| 61852ab47e | |||
| 914a4dcf3b | |||
| 8f3fb4474c | |||
| 08ef40b736 | |||
| 0048d6fc92 | |||
| caae1216d0 | |||
| 2255a806b9 | |||
| 0eb150eb8b | |||
| 01f811ebd2 | |||
| c70eed8a06 | |||
| b12b26b87e | |||
| 836eebaf11 | |||
| 92a2628e90 | |||
| d2360fde25 | |||
| c603753226 | |||
| c8448b7848 | |||
| 6d2a1a002b | |||
| f6ebec32ca | |||
| 7a57f22967 | |||
| dd2c1eb9d2 | |||
| e657fb16bd | |||
| f7bf5e2b0e | |||
| 51f07bd330 | |||
| 2183c0710c | |||
| e9212a889d | |||
| 0d4ac4e3e5 | |||
| df99ff817a | |||
| 2705afc327 | |||
| 5330be142c | |||
| 73c46d821e | |||
| 0565eec871 | |||
| d895fb70f7 | |||
| 45fab2c0b5 | |||
| 634f5ad2d0 | |||
| 34e5ac2b9e | |||
| 336896b37e | |||
| c9698f1f5c | |||
| dd447656f8 | |||
| db2339ab3a | |||
| 8d3308d74a | |||
| 22e7965442 | |||
| 2e856c1256 | |||
| 5b04242aab | |||
| a127777e49 | |||
| 11aea59cf8 | |||
| 5456a01551 | |||
| a93a67161d | |||
| 52a4e44e47 | |||
| 79039ae79e | |||
| 1ae84cf5a8 | |||
| 032fa0c0ad | |||
| 1f8b43ba5d | |||
| 4fc0ae103e | |||
| bd86412d83 | |||
| 592e59e01f | |||
| 05b6fe4a56 | |||
| f68e5d160f | |||
| d279d52b09 | |||
| a1ed498bf5 | |||
| 41c5610f9a | |||
| 5c57454998 | |||
| a7effef412 | |||
| dd1014e230 | |||
| 89ac9fd225 | |||
| 3096fba7c5 | |||
| baf696a3e1 | |||
| 5daf4fafc7 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,6 +9,6 @@ out/
|
|||||||
.idea/
|
.idea/
|
||||||
.ideaDataSources/
|
.ideaDataSources/
|
||||||
config.json
|
config.json
|
||||||
package-lock.json
|
|
||||||
/node_modules
|
/node_modules
|
||||||
/log
|
/log
|
||||||
|
/ansible/*.retry
|
||||||
|
|||||||
29
WORK.md
29
WORK.md
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
* ui
|
* ui
|
||||||
* auth frame 0%
|
* auth frame 0%
|
||||||
* select game frame 30% (classic 1/2 player, dota singe/coop/vs)
|
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
||||||
* select level frame 10%
|
* select level frame 10%
|
||||||
* game frame 50%
|
* game frame 50%
|
||||||
|
|
||||||
@@ -21,21 +21,29 @@
|
|||||||
* bullets 100%
|
* bullets 100%
|
||||||
* boxes 100%
|
* boxes 100%
|
||||||
* map changes 100%
|
* map changes 100%
|
||||||
* bonuses 0%
|
* bonuses 100%
|
||||||
* eagle 100%
|
* eagle 100%
|
||||||
|
|
||||||
* game
|
* game
|
||||||
* classic
|
* classic
|
||||||
* state 50%
|
* state 50%
|
||||||
* bot 50%
|
* bot 50%
|
||||||
* player: 50%
|
* human 100%
|
||||||
* dota
|
* dota
|
||||||
* state 50%
|
* state 50%
|
||||||
* bot 10%
|
* bot 10%
|
||||||
* player 0%
|
* human 100%
|
||||||
|
|
||||||
|
* bonus
|
||||||
|
* star 50%
|
||||||
|
* grenade 0%
|
||||||
|
* helm 0%
|
||||||
|
* clock 0%
|
||||||
|
* shovel 0%
|
||||||
|
|
||||||
* state
|
* state
|
||||||
* score 0%
|
* score 0%
|
||||||
|
* human tank 0%
|
||||||
* save/load 0%
|
* save/load 0%
|
||||||
* export/import 0%
|
* export/import 0%
|
||||||
|
|
||||||
@@ -47,16 +55,19 @@
|
|||||||
* animations
|
* animations
|
||||||
* tank spawn 0%
|
* tank spawn 0%
|
||||||
* tank move 100%
|
* tank move 100%
|
||||||
* map water 0%
|
* map water 100%
|
||||||
* bullet boom 90%
|
* bullet boom 90%
|
||||||
* tank boom 90%
|
* tank boom 90%
|
||||||
* bonuses 0%
|
* bonuses 100%
|
||||||
* html5 50%
|
* html5 50%
|
||||||
|
|
||||||
* proto
|
* proto
|
||||||
...
|
...
|
||||||
|
|
||||||
* editor
|
* editor
|
||||||
* open 0%
|
* level
|
||||||
* edit 0%
|
* open 100%
|
||||||
* save 0%
|
* edit 50%
|
||||||
|
* save 100%
|
||||||
|
* tank
|
||||||
|
* color 10%
|
||||||
9
ansible/ansible.cfg
Normal file
9
ansible/ansible.cfg
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[defaults]
|
||||||
|
hash_behaviour = merge
|
||||||
|
host_key_checking = False
|
||||||
|
#callback_whitelist = profile_tasks
|
||||||
|
display_skipped_hosts = False
|
||||||
|
|
||||||
|
[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: staging
|
||||||
|
deploy_npm: yes
|
||||||
|
|
||||||
|
service_name: "{{ project_name }}"
|
||||||
|
service_work_dir: "{{ deploy_current_dir }}/target/server/neko"
|
||||||
|
service_command: "/usr/bin/neko {{ service_work_dir }}/{{ project_name }}.n {{ service_host }}"
|
||||||
|
service_user: www-data
|
||||||
|
service_control_user: "{{ project_user }}"
|
||||||
4
ansible/prod/inventory.yml
Normal file
4
ansible/prod/inventory.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
all:
|
||||||
|
hosts: shmyga.ru
|
||||||
|
vars:
|
||||||
|
service_host: 172.31.1.100
|
||||||
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
|
||||||
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: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json"
|
||||||
|
dest: "{{ deploy_release_dir }}/config.json"
|
||||||
|
remote_src: true
|
||||||
|
|
||||||
|
- name: "Gulp build"
|
||||||
|
command: "/usr/local/lib/npm/bin/gulp default"
|
||||||
|
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
|
||||||
137
build/client.js
137
build/client.js
@@ -1,137 +0,0 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const concat = require('gulp-concat');
|
|
||||||
const uglify = require('gulp-uglify');
|
|
||||||
const babel = require('gulp-babel');
|
|
||||||
const template = require('gulp-template');
|
|
||||||
const yargs = require('yargs');
|
|
||||||
const Haxe = require('../tasks/haxe');
|
|
||||||
const FlashPlayer = require('../tasks/flashplayer');
|
|
||||||
const version = require('./version');
|
|
||||||
const prepare = require('./prepare');
|
|
||||||
const debug = require('../tasks/debug');
|
|
||||||
const webserver = require('gulp-webserver');
|
|
||||||
const run = require('gulp-run');
|
|
||||||
const tail = require('../tasks/tail');
|
|
||||||
const deb = require('gulp-debian');
|
|
||||||
|
|
||||||
|
|
||||||
const generate = () => function generate() {
|
|
||||||
return new Haxe().haxelib([
|
|
||||||
'run', 'protohx', 'generate', 'protohx.json'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const build = (platform) => function build() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().openfl({
|
|
||||||
command: 'build',
|
|
||||||
platform: platform,
|
|
||||||
version: version,
|
|
||||||
debug: argv.dev,
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(`target/${platform}`));
|
|
||||||
};
|
|
||||||
|
|
||||||
const flashIndex = function() {
|
|
||||||
return gulp.src('src/client/html/index.html')
|
|
||||||
.pipe(template({
|
|
||||||
scripts: ['app.min.js'],
|
|
||||||
swf: 'tankz.swf'
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest('target/flash'))
|
|
||||||
};
|
|
||||||
|
|
||||||
const flashJs = function() {
|
|
||||||
const src = [
|
|
||||||
'src/client/html/js/*.js'
|
|
||||||
];
|
|
||||||
return gulp.src(src)
|
|
||||||
.pipe(babel({presets: ['es2015']}))
|
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(concat('app.min.js'))
|
|
||||||
.pipe(gulp.dest('target/flash'))
|
|
||||||
};
|
|
||||||
|
|
||||||
const webapp = function () {
|
|
||||||
return gulp.src('src/webapp/*').pipe(gulp.dest('target'));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const buildDeb = gulp.series(
|
|
||||||
() => gulp.src('src/client/debian/**/*').pipe(gulp.dest('target/debian')),
|
|
||||||
() => gulp.src('target/linux/**/*').pipe(gulp.dest('target/debian/usr/share/tankz')),
|
|
||||||
() => gulp.src('target/debian/*')
|
|
||||||
.pipe(deb({
|
|
||||||
package: 'tankz',
|
|
||||||
version: version,
|
|
||||||
section: 'base',
|
|
||||||
priority: 'optional',
|
|
||||||
architecture: 'all',
|
|
||||||
maintainer: 'shmyga <shmyga.z@gmail.com>',
|
|
||||||
description: 'Tank\'z',
|
|
||||||
changelog: [],
|
|
||||||
postinst: [
|
|
||||||
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
|
|
||||||
' update-menus\n' +
|
|
||||||
'fi'
|
|
||||||
],
|
|
||||||
_target: '/',
|
|
||||||
_out: 'target',
|
|
||||||
_clean: false,
|
|
||||||
_verbose: true
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
exports['client:flash:html'] = gulp.parallel(flashIndex, flashJs);
|
|
||||||
exports['client:flash'] = gulp.series(prepare(Haxe.ID), generate(), build('flash'), exports['client:flash:html']);
|
|
||||||
exports['client:html5'] = gulp.series(prepare(Haxe.ID), generate(), build('html5'));
|
|
||||||
exports['client:linux'] = gulp.series(prepare(Haxe.ID), generate(), build('linux'));
|
|
||||||
exports['client:webapp'] = webapp;
|
|
||||||
exports['client:deb'] = buildDeb;
|
|
||||||
exports['client'] = gulp.series(
|
|
||||||
prepare(Haxe.ID),
|
|
||||||
generate(),
|
|
||||||
gulp.parallel(build('flash'), build('html5'), build('linux')),
|
|
||||||
exports['client:flash:html'],
|
|
||||||
webapp,
|
|
||||||
buildDeb,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const testFlash = function() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return build('flash')()
|
|
||||||
.pipe(new FlashPlayer().run(argv.dev))
|
|
||||||
.pipe(debug());
|
|
||||||
};
|
|
||||||
|
|
||||||
const testHtml5 = function() {
|
|
||||||
return gulp.series(
|
|
||||||
build('html5'),
|
|
||||||
() => gulp.src('target/html5').pipe(webserver({
|
|
||||||
host: 'localhost', port: 3000,
|
|
||||||
open: true,
|
|
||||||
fallback: 'index.html'
|
|
||||||
}))
|
|
||||||
)();
|
|
||||||
};
|
|
||||||
|
|
||||||
const testLinux = gulp.series(
|
|
||||||
build('linux'),
|
|
||||||
() => gulp.src('target/linux/tankz')
|
|
||||||
.pipe(run('./tankz', {cwd: 'target/linux', verbosity: 1}))
|
|
||||||
.pipe(tail(debug.log))
|
|
||||||
.pipe(gulp.dest('target/log'))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports['client:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
|
||||||
exports['client:html5:test'] = gulp.series(prepare(Haxe.ID), testHtml5);
|
|
||||||
exports['client:linux:test'] = gulp.series(prepare(Haxe.ID), testLinux);
|
|
||||||
exports['client:test'] = exports['client:flash:test'];
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const yargs = require('yargs');
|
|
||||||
const Haxe = require('../tasks/haxe');
|
|
||||||
const FlashPlayer = require('../tasks/flashplayer');
|
|
||||||
const version = require('./version');
|
|
||||||
const prepare = require('./prepare');
|
|
||||||
const debug = require('../tasks/debug');
|
|
||||||
|
|
||||||
|
|
||||||
const build = (platform) => function build() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().openfl({
|
|
||||||
command: 'build',
|
|
||||||
platform: platform,
|
|
||||||
version: version,
|
|
||||||
values: {
|
|
||||||
build_editor: true
|
|
||||||
},
|
|
||||||
debug: argv.dev,
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(`target/${platform}`));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const testFlash = function() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return build('flash')()
|
|
||||||
.pipe(new FlashPlayer().run(argv.dev))
|
|
||||||
.pipe(debug());
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
exports['editor:flash'] = gulp.series(prepare(Haxe.ID), build('flash'));
|
|
||||||
exports['editor:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
const AdobeAir = require('../tasks/adobeAir');
|
|
||||||
const Haxe = require('../tasks/haxe');
|
|
||||||
const FlashPlayer = require('../tasks/flashplayer');
|
|
||||||
const packageInfo = require('../package.json');
|
|
||||||
|
|
||||||
|
|
||||||
const prepareOne = (value) => {
|
|
||||||
switch (value) {
|
|
||||||
case Haxe.ID:
|
|
||||||
const haxe = new Haxe();
|
|
||||||
return haxe.prepare().then(() => haxe.install(packageInfo.haxeDependencies));
|
|
||||||
case AdobeAir.ID:
|
|
||||||
return new AdobeAir().prepare();
|
|
||||||
case FlashPlayer.ID:
|
|
||||||
return new FlashPlayer().prepare();
|
|
||||||
default:
|
|
||||||
throw Error(`Unknown target: ${value}`)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const prepare = (...targets) => function prepare() {
|
|
||||||
const tasks = targets.map((target) => prepareOne(target));
|
|
||||||
return Promise.all(tasks);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const update = () => {
|
|
||||||
return new Haxe().upgrade();
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = prepare;
|
|
||||||
module.exports.update = update;
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const yargs = require('yargs');
|
|
||||||
const Haxe = require('../tasks/haxe');
|
|
||||||
const FlashPlayer = require('../tasks/flashplayer');
|
|
||||||
const Neko = require('../tasks/neko');
|
|
||||||
const version = require('./version');
|
|
||||||
const prepare = require('./prepare');
|
|
||||||
const debug = require('../tasks/debug');
|
|
||||||
|
|
||||||
|
|
||||||
const build = () => function build() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().build({
|
|
||||||
platform: 'neko',
|
|
||||||
version: version,
|
|
||||||
lib: [
|
|
||||||
'protohx',
|
|
||||||
'orm',
|
|
||||||
'haxework:git',
|
|
||||||
],
|
|
||||||
cp: [
|
|
||||||
'src/common/haxe',
|
|
||||||
'src/server/haxe',
|
|
||||||
'src-gen/haxe',
|
|
||||||
],
|
|
||||||
main: 'ru.m.tankz.server.Server',
|
|
||||||
outputFile: 'tankz.n',
|
|
||||||
debug: argv.dev,
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest('target'));
|
|
||||||
};
|
|
||||||
|
|
||||||
const test = (build) => function test() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return build()
|
|
||||||
.pipe(new Neko().run(argv.dev))
|
|
||||||
.pipe(debug());
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
exports['server'] = gulp.series(prepare(Haxe.ID), build());
|
|
||||||
exports['server:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), test(build()));
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
const packageInfo = require('../package.json');
|
|
||||||
module.exports = packageInfo.version;
|
|
||||||
11
capfile
11
capfile
@@ -1,11 +0,0 @@
|
|||||||
require 'capistrano/setup'
|
|
||||||
require 'capistrano/deploy'
|
|
||||||
require 'capistrano/scm/git'
|
|
||||||
install_plugin Capistrano::SCM::Git
|
|
||||||
require 'capistrano/scm/git-with-submodules'
|
|
||||||
install_plugin Capistrano::SCM::Git::WithSubmodules
|
|
||||||
require 'capistrano/npm'
|
|
||||||
require 'capistrano/gulp'
|
|
||||||
require 'airbrussh/capistrano'
|
|
||||||
|
|
||||||
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
set :config_role, :app
|
|
||||||
set :config_path, -> { release_path }
|
|
||||||
set :config_type, 'json'
|
|
||||||
|
|
||||||
|
|
||||||
namespace :config do
|
|
||||||
task :setup do
|
|
||||||
config_role = fetch(:config_role)
|
|
||||||
config_path = fetch(:config_path)
|
|
||||||
config_type = fetch(:config_type)
|
|
||||||
on roles(config_role) do |server|
|
|
||||||
# stage = fetch(:stage)
|
|
||||||
execute "cd #{config_path} && cp config.#{server.hostname}.#{config_type} config.#{config_type}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
require_relative 'npm'
|
|
||||||
require_relative 'config'
|
|
||||||
|
|
||||||
app = 'tankz'
|
|
||||||
user = 'holop'
|
|
||||||
|
|
||||||
# git
|
|
||||||
set :application, app
|
|
||||||
set :repo_url, "git@bitbucket.org:infernalgames/#{app}.git"
|
|
||||||
set :user, user
|
|
||||||
set :deploy_to, "/home/#{user}/repo/#{app}"
|
|
||||||
|
|
||||||
# airbrussh
|
|
||||||
set :format, :airbrussh
|
|
||||||
set :format_options, command_output: false
|
|
||||||
|
|
||||||
# config
|
|
||||||
before 'deploy:updated', 'config:setup'
|
|
||||||
|
|
||||||
# npm
|
|
||||||
set :npm_target_path, -> { "/home/#{fetch(:user)}/npm" }
|
|
||||||
set :npm_flags, '--silent --no-spin'
|
|
||||||
set :npm_roles, :web
|
|
||||||
set :npm_env_variables, {}
|
|
||||||
|
|
||||||
# gulp
|
|
||||||
set :gulp_target_path, -> { release_path }
|
|
||||||
set :gulp_tasks, 'default'
|
|
||||||
set :gulp_flags, '--no-color'
|
|
||||||
set :gulp_roles, :web
|
|
||||||
before 'deploy:updated', 'gulp'
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
role :app, %w{localhost}
|
|
||||||
role :web, %w{localhost}
|
|
||||||
role :db, %w{localhost}
|
|
||||||
|
|
||||||
set :user, ENV['USER']
|
|
||||||
user = fetch(:user)
|
|
||||||
|
|
||||||
server 'localhost', ssh_options: { port: 22, user: user, forward_agent: true }
|
|
||||||
|
|
||||||
set :tmp_dir, "/home/#{user}/tmp"
|
|
||||||
set :branch, 'master'
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# host = '94.130.110.9'
|
|
||||||
host = 'shmyga.ru'
|
|
||||||
|
|
||||||
role :app, host
|
|
||||||
role :web, host
|
|
||||||
role :db, host
|
|
||||||
|
|
||||||
user = fetch(:user)
|
|
||||||
|
|
||||||
server host, ssh_options: { port: 22, user: user, forward_agent: true }
|
|
||||||
|
|
||||||
set :tmp_dir, "/home/#{user}/tmp"
|
|
||||||
set :branch, 'master'
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
set :npm_path, -> { release_path }
|
|
||||||
|
|
||||||
namespace :npm do
|
|
||||||
task :prepare do
|
|
||||||
npm_roles = fetch(:npm_roles)
|
|
||||||
on roles(npm_roles) do
|
|
||||||
npm_target_path = fetch(:npm_target_path)
|
|
||||||
npm_path = fetch(:npm_path)
|
|
||||||
execute "mkdir -p #{npm_target_path}"
|
|
||||||
execute "cp #{npm_path}/package.json #{npm_target_path}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
task :link do
|
|
||||||
npm_roles = fetch(:npm_roles)
|
|
||||||
on roles(npm_roles) do
|
|
||||||
npm_target_path = fetch(:npm_target_path)
|
|
||||||
npm_path = fetch(:npm_path)
|
|
||||||
execute "ln -s #{npm_target_path}/node_modules #{npm_path}/"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
before 'npm:install', 'npm:prepare'
|
|
||||||
after 'npm:install', 'npm:link'
|
|
||||||
6
gemfile
6
gemfile
@@ -1,6 +0,0 @@
|
|||||||
source 'https://rubygems.org'
|
|
||||||
gem 'capistrano', '~> 3.7.0'
|
|
||||||
gem 'capistrano-git-with-submodules', '~> 2.0'
|
|
||||||
gem 'capistrano-npm'
|
|
||||||
gem 'capistrano-gulp'
|
|
||||||
gem 'airbrussh', :require => false
|
|
||||||
127
gulpfile.js
127
gulpfile.js
@@ -1,36 +1,123 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const os = require('os');
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const clean = require('gulp-clean');
|
const gulpClean = require('gulp-clean');
|
||||||
const Sdk = require('./tasks/sdk');
|
|
||||||
const FlashPlayer = require('./tasks/flashplayer');
|
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const prepare = require('./build/prepare');
|
const packageInfo = require('./package.json');
|
||||||
|
const {Sdk, Haxe, Project, FlashPlayer} = require('gulp-haxetool');
|
||||||
|
const dateformat = require('dateformat');
|
||||||
|
|
||||||
//FlashPlayer.VERSION = '25.0.0.171';
|
|
||||||
|
|
||||||
|
// ToDo: update default in gulp-haxetool
|
||||||
|
FlashPlayer.VERSION = '31';
|
||||||
if (Config.SdkDir) {
|
if (Config.SdkDir) {
|
||||||
Sdk.dir = Config.SdkDir;
|
Sdk.dir = Config.SdkDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.clean = () => {
|
exports.clean = function clean() {
|
||||||
return gulp.src('target/*', {read: false}).pipe(clean());
|
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
||||||
};
|
};
|
||||||
|
|
||||||
const merge = (value) => {
|
exports.generate = function generate() {
|
||||||
if (typeof value === 'string') {
|
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => {
|
||||||
value = require(value);
|
if (stdout.indexOf('FAIL') > -1) {
|
||||||
}
|
throw stdout;
|
||||||
for (let key in value) if (value.hasOwnProperty(key)) {
|
|
||||||
exports[key] = value[key];
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = prepare.update;
|
/**
|
||||||
merge('./build/prepare');
|
* ToDo:
|
||||||
merge('./build/client');
|
* windows target
|
||||||
merge('./build/editor');
|
* window exe package (innosetup)
|
||||||
merge('./build/server');
|
*/
|
||||||
|
const config = new Project.Config({
|
||||||
|
meta: {
|
||||||
|
title: 'Tank\'z',
|
||||||
|
filename: 'tankz',
|
||||||
|
icon: 'src/client/resources/image/tank/pd-0.png',
|
||||||
|
pack: 'ru.m.tankz',
|
||||||
|
author: 'shmyga <shmyga.z@gmail.com>',
|
||||||
|
company: 'MegaLoMania',
|
||||||
|
version: packageInfo.version,
|
||||||
|
},
|
||||||
|
libs: packageInfo.haxeDependencies,
|
||||||
|
sources: [
|
||||||
|
'src/common/haxe',
|
||||||
|
'src-gen/haxe',
|
||||||
|
],
|
||||||
|
assets: [
|
||||||
|
'src/common/resources'
|
||||||
|
],
|
||||||
|
macros: [
|
||||||
|
//'yield.parser.Parser.auto()', // ToDo: bug with extraParams.hxml in yield library
|
||||||
|
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* client
|
||||||
|
*/
|
||||||
|
const client = new Project(
|
||||||
|
Project.BuildSystem.OPENFL,
|
||||||
|
[
|
||||||
|
Project.Platform.FLASH,
|
||||||
|
Project.Platform.HTML5,
|
||||||
|
Project.Platform.LINUX,
|
||||||
|
Project.Platform.ANDROID,
|
||||||
|
],
|
||||||
|
config.branch({
|
||||||
|
name: 'client',
|
||||||
|
sources: ['src/client/haxe'],
|
||||||
|
main: 'ru.m.tankz.Client',
|
||||||
|
assets: ['src/client/resources'],
|
||||||
|
flags: [
|
||||||
|
//'dom',
|
||||||
|
//'dev_layout',
|
||||||
|
//'bitmap_text',
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
module.exports.generate
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
exports.default = gulp.series(exports.clean, exports.client);
|
/**
|
||||||
|
* editor
|
||||||
|
*/
|
||||||
|
const editor = new Project(
|
||||||
|
Project.BuildSystem.OPENFL,
|
||||||
|
Project.Platform.FLASH,
|
||||||
|
config.branch({
|
||||||
|
name: 'editor',
|
||||||
|
sources: ['src/client/haxe', 'src/editor/haxe'],
|
||||||
|
main: 'ru.m.tankz.editor.Editor',
|
||||||
|
assets: ['src/client/resources'],
|
||||||
|
meta: {filename: 'editor'}
|
||||||
|
})
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* server
|
||||||
|
*/
|
||||||
|
const server = new Project(
|
||||||
|
Project.BuildSystem.HAXE,
|
||||||
|
Project.Platform.NEKO,
|
||||||
|
config.branch({
|
||||||
|
name: 'server',
|
||||||
|
sources: ['src/server/haxe'],
|
||||||
|
main: 'ru.m.tankz.server.Server',
|
||||||
|
})
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default
|
||||||
|
*/
|
||||||
|
module.exports.default = gulp.series(
|
||||||
|
exports.clean,
|
||||||
|
module.exports['client:flash:build'],
|
||||||
|
module.exports['client:html5:build'],
|
||||||
|
module.exports['client:linux:build'],
|
||||||
|
//module.exports['client:android:build'],
|
||||||
|
module.exports['editor:flash:build'],
|
||||||
|
module.exports['server:neko:build'],
|
||||||
|
module.exports['client:flash:html'],
|
||||||
|
module.exports['client:linux:deb'],
|
||||||
|
);
|
||||||
|
|||||||
6172
package-lock.json
generated
Normal file
6172
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@@ -1,42 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.5.0",
|
"version": "0.8.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^1.0.1",
|
"dateformat": "^3.0.3",
|
||||||
"async": "^2.6.0",
|
"gulp": "^4.0.0",
|
||||||
"babel-core": "^6.26.0",
|
"gulp-add": "0.0.2",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"gulp-clean": "^0.4.0",
|
||||||
"download": "^6.2.5",
|
"gulp-haxetool": "^0.0.14"
|
||||||
"fancy-log": "^1.3.2",
|
|
||||||
"fs-extra": "^5.0.0",
|
|
||||||
"got": "^8.0.1",
|
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
|
||||||
"gulp-babel": "^7.0.0",
|
|
||||||
"gulp-clean": "^0.3.2",
|
|
||||||
"gulp-concat": "^2.6.1",
|
|
||||||
"gulp-debian": "^0.1.9",
|
|
||||||
"gulp-run": "^1.7.1",
|
|
||||||
"gulp-template": "^5.0.0",
|
|
||||||
"gulp-uglify": "^3.0.0",
|
|
||||||
"gulp-webserver": "^0.9.1",
|
|
||||||
"plugin-error": "^0.1.2",
|
|
||||||
"progress": "^2.0.0",
|
|
||||||
"promise-streams": "^2.1.1",
|
|
||||||
"rmdir": "^1.2.0",
|
|
||||||
"tar": "^4.2.0",
|
|
||||||
"tmp-file": "^2.0.1",
|
|
||||||
"unzip-stream": "^0.2.1",
|
|
||||||
"vinyl-fs": "^3.0.1",
|
|
||||||
"yargs": "^10.0.3"
|
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
"lime": "6.0.1",
|
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||||
"openfl": "7.0.0",
|
"lime": "7.2.1",
|
||||||
|
"openfl": "8.8.0",
|
||||||
|
"hxcpp": "4.0.8",
|
||||||
"promhx": "1.1.0",
|
"promhx": "1.1.0",
|
||||||
"protohx": "0.4.6",
|
"protohx": "0.4.6",
|
||||||
"yaml": "1.3.0",
|
"yaml": "1.3.0",
|
||||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
"orm": "2.1.0",
|
||||||
"orm": "2.1.0"
|
"yield": "2.0.0",
|
||||||
|
"haxe-crypto": "0.0.7",
|
||||||
|
"svg": "1.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
project.xml
28
project.xml
@@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<project>
|
|
||||||
<meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/>
|
|
||||||
<app main="ru.m.tankz.Client" path="target" file="tankz"/>
|
|
||||||
<source path="src/common/haxe"/>
|
|
||||||
<source path="src/client/haxe"/>
|
|
||||||
<source path="src-gen/haxe"/>
|
|
||||||
<assets path="src/client/resources" rename="resources" include="*"/>
|
|
||||||
<haxelib name="lime" version="6.0.1"/>
|
|
||||||
<haxelib name="openfl" version="7.0.0"/>
|
|
||||||
<haxelib name="promhx" version="1.1.0"/>
|
|
||||||
<haxelib name="protohx" version="0.4.6"/>
|
|
||||||
<haxelib name="haxework" version="git"/>
|
|
||||||
<haxelib name="yaml" version="1.3.0"/>
|
|
||||||
<window fps="30"/>
|
|
||||||
<window width="1024" height="768" unless="html5"/>
|
|
||||||
<haxeflag name="-D" value="swf-gpu"/>
|
|
||||||
<haxeflag name="-D" value="native-trace"/>
|
|
||||||
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
|
||||||
<haxeflag name="-dce" value="no"/>
|
|
||||||
<haxeflag name="-D" value="dom"/>
|
|
||||||
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
|
||||||
|
|
||||||
<section if="build_editor">
|
|
||||||
<app main="ru.m.tankz.editor.Editor" path="target" file="editor"/>
|
|
||||||
<source path="src/editor/haxe"/>
|
|
||||||
</section>
|
|
||||||
</project>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
[Desktop Entry]
|
|
||||||
Encoding=UTF-8
|
|
||||||
Type=Application
|
|
||||||
Comment=Tank'z game
|
|
||||||
Exec=bash -c 'cd "/usr/share/tankz" && ./tankz'
|
|
||||||
Icon=/usr/share/tankz/resources/images/tank/player/tank_p3_0-0.png
|
|
||||||
Name=Tank'z
|
|
||||||
Categories=Game
|
|
||||||
Terminal=false
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "state", "@type": "haxework.gui.LabelView", "@style": "label",
|
|
||||||
"pWidth": 100, "height": 20
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "render", "@type": "ru.m.tankz.render.Render",
|
|
||||||
"contentSize": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id":"levels", "@type":"haxework.gui.list.VListView<Int>",
|
|
||||||
"factory": "@class:ru.m.tankz.view.frames.list.LevelView",
|
|
||||||
"pWidth":100,
|
|
||||||
"pHeight":100,
|
|
||||||
"paddings":10,
|
|
||||||
"scroll":{
|
|
||||||
"@type":"haxework.gui.list.VScrollView",
|
|
||||||
"width":10, "pHeight":100,
|
|
||||||
"skin":{"@type":"haxework.gui.list.VScrollSkin"}
|
|
||||||
},
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000", "alpha": 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.ImageView",
|
|
||||||
"image": "@asset:image:resources/images/logo/logo.png",
|
|
||||||
"contentSize": true, "bottomMargin": 15
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.LabelView", "@style": "label",
|
|
||||||
"fontSize": 20, "topMargin": 15,
|
|
||||||
"contentSize": true,
|
|
||||||
"text": "Classic"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "classic_1p",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "1 Player",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "classic_2p",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "2 Player",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.LabelView", "@style": "label",
|
|
||||||
"fontSize": 20, "topMargin": 15,
|
|
||||||
"contentSize": true,
|
|
||||||
"text": "DotA"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "dota_1p",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "1 Player",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "dota_2p_coop",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "2 COOP",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "dota_2p_vs",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "2 VS",
|
|
||||||
"@style": "button"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"@type": "haxework.gui.VGroupView",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.BitmapSkin",
|
|
||||||
"image": "@asset:image:resources/images/background.png",
|
|
||||||
"fillType": "REPEAT"
|
|
||||||
},
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "start",
|
|
||||||
"@type": "ru.m.tankz.view.frames.StartFrame"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "level",
|
|
||||||
"@type": "ru.m.tankz.view.frames.LevelFrame"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "game",
|
|
||||||
"@type": "ru.m.tankz.view.frames.GameFrame"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.LabelView",
|
|
||||||
"inLayout": false,
|
|
||||||
"contentSize": true,
|
|
||||||
"vAlign": "BOTTOM",
|
|
||||||
"hAlign": "RIGHT",
|
|
||||||
"text": "@res:text:version",
|
|
||||||
"@style": "label"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"level": {
|
|
||||||
"width": 440, "height": 44,
|
|
||||||
"margins": 5,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "label",
|
|
||||||
"@type": "haxework.gui.LabelView",
|
|
||||||
"pWidth": 100, "pHeight": 100, "text": "",
|
|
||||||
"@style": "label"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000", "alpha": 0.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"button": {
|
|
||||||
"width":250, "height":60,
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ButtonBitmapSkin",
|
|
||||||
"upImage": "@asset:image:resources/images/control/button_normal.png",
|
|
||||||
"downImage": "@asset:image:resources/images/control/button_down.png",
|
|
||||||
"overImage": "@asset:image:resources/images/control/button_over.png",
|
|
||||||
"fillType": "NINEPATH"
|
|
||||||
},
|
|
||||||
"fontFamily":"@res:text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20
|
|
||||||
},
|
|
||||||
|
|
||||||
"label": {
|
|
||||||
"fontColor": "0xffffff",
|
|
||||||
"fontEmbed": false,
|
|
||||||
"fontFamily": "@res:text:fontName",
|
|
||||||
"fontSize": 16,
|
|
||||||
"shadowColor": "0x000000"
|
|
||||||
},
|
|
||||||
|
|
||||||
"input": {
|
|
||||||
"fontColor": "0xffffff",
|
|
||||||
"fontEmbed": false,
|
|
||||||
"fontFamily": "@res:text:fontName",
|
|
||||||
"fontSize": 16,
|
|
||||||
"shadowColor": "0x000000",
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,11 @@ import flash.display.Bitmap;
|
|||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
|
|
||||||
|
|
||||||
|
typedef Frame = {
|
||||||
|
var image:BitmapData;
|
||||||
|
var length:Int;
|
||||||
|
}
|
||||||
|
|
||||||
class Animate extends Bitmap {
|
class Animate extends Bitmap {
|
||||||
|
|
||||||
private static var timer:Timer;
|
private static var timer:Timer;
|
||||||
@@ -26,24 +31,30 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var a = new BitmapData(1, 1);
|
|
||||||
|
|
||||||
public var playing(default, set):Bool;
|
public var playing(default, set):Bool;
|
||||||
public var frames(default, set):Array<BitmapData>;
|
public var frames(default, set):Array<Frame>;
|
||||||
|
|
||||||
|
private var sequence:Array<BitmapData>;
|
||||||
private var index:Int;
|
private var index:Int;
|
||||||
|
|
||||||
public function new(?frames:Array<BitmapData>) {
|
public function new(?frames:Array<Frame>) {
|
||||||
super(null, PixelSnapping.AUTO, true);
|
super(null, PixelSnapping.AUTO, true);
|
||||||
this.frames = frames == null ? [] : frames;
|
this.frames = frames == null ? [] : frames;
|
||||||
init();
|
init();
|
||||||
instances.push(this);
|
instances.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||||
|
sequence = [];
|
||||||
|
index = 0;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
frames = value;
|
frames = value;
|
||||||
bitmapData = frames[0];
|
for (frame in frames) {
|
||||||
index = 0;
|
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||||
|
}
|
||||||
|
bitmapData = sequence[0];
|
||||||
|
} else {
|
||||||
|
bitmapData = null;
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
@@ -56,10 +67,10 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function update():Void {
|
private function update():Void {
|
||||||
if (++index >= frames.length) {
|
if (++index >= sequence.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
var nextBitmapData = frames[index];
|
var nextBitmapData = sequence[index];
|
||||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||||
bitmapData = nextBitmapData;
|
bitmapData = nextBitmapData;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.animate;
|
package ru.m.animate;
|
||||||
|
|
||||||
import promhx.Deferred;
|
import promhx.Deferred;
|
||||||
import flash.display.BitmapData;
|
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
|
|
||||||
|
|
||||||
@@ -9,10 +8,6 @@ class OnceAnimate extends Animate {
|
|||||||
|
|
||||||
private var deferred:Deferred<Animate>;
|
private var deferred:Deferred<Animate>;
|
||||||
|
|
||||||
public function new(frames:Array<BitmapData>) {
|
|
||||||
super(frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function play():Promise<Animate> {
|
public function play():Promise<Animate> {
|
||||||
deferred = new Deferred();
|
deferred = new Deferred();
|
||||||
playing = true;
|
playing = true;
|
||||||
|
|||||||
44
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
44
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package ru.m.skin;
|
||||||
|
|
||||||
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.color.Color;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import format.SVG;
|
||||||
|
import haxework.gui.skin.ISkin;
|
||||||
|
|
||||||
|
class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||||
|
|
||||||
|
private var svg:String;
|
||||||
|
private var color:Color;
|
||||||
|
|
||||||
|
private var svgs:Map<ButtonState, SVG>;
|
||||||
|
|
||||||
|
public function new(svg:String, color:Color) {
|
||||||
|
this.svg = svg;
|
||||||
|
this.color = color;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function buildSVG(color:Color):SVG {
|
||||||
|
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function init():Void {
|
||||||
|
svgs = new Map<ButtonState, SVG>();
|
||||||
|
svgs.set(ButtonState.UP, buildSVG(color));
|
||||||
|
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||||
|
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5));
|
||||||
|
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||||
|
graphics.lineStyle();
|
||||||
|
graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,22 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import ru.m.tankz.game.ClassicGame;
|
import flash.Lib;
|
||||||
import ru.m.tankz.game.DotaGame;
|
import haxework.animate.Animate;
|
||||||
import ru.m.tankz.game.Game;
|
import ru.m.tankz.frame.StartFrame;
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.text.Font;
|
import flash.text.Font;
|
||||||
import ru.m.tankz.view.frames.StartFrame;
|
|
||||||
import haxework.log.SocketLogger;
|
|
||||||
import haxework.resources.Resources;
|
|
||||||
import haxework.resources.IResources;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import ru.m.tankz.PacketBuilder;
|
|
||||||
import haxework.log.JSLogger;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import haxework.gui.frame.FrameSwitcher;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import haxework.gui.Root;
|
import haxework.gui.Root;
|
||||||
import openfl.Assets;
|
import haxework.gui.VGroupView;
|
||||||
import ru.m.connect.IConnection;
|
|
||||||
import haxework.log.TraceLogger;
|
import haxework.log.TraceLogger;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
#if flash import haxework.log.JSLogger; #end
|
||||||
|
#if debug import haxework.log.SocketLogger; #end
|
||||||
|
|
||||||
@:template("layout/main.json", "layout/styles.json")
|
class Client {
|
||||||
class MainView extends VGroupView implements ViewBuilder {}
|
private static inline var TAG = 'Tankz';
|
||||||
|
|
||||||
class Client implements IConnectionHandler {
|
|
||||||
|
|
||||||
private static inline var TAG = "Tankz";
|
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
@@ -36,65 +24,41 @@ class Client implements IConnectionHandler {
|
|||||||
L.push(new JSLogger());
|
L.push(new JSLogger());
|
||||||
#end
|
#end
|
||||||
#if debug
|
#if debug
|
||||||
L.push(new SocketLogger());
|
//L.push(new SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
Init.init();
|
||||||
L.i(TAG, "Version: " + Const.VERSION);
|
Animate.bind(Lib.current.stage);
|
||||||
L.i(TAG, "Build: " + Const.BUILD);
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
new Client();
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
}
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
|
Style.register();
|
||||||
|
var view:ClientView = new ClientView();
|
||||||
private var view:MainView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
Provider.setFactory(IResources, Resources);
|
|
||||||
|
|
||||||
var font:Font = Font.enumerateFonts()[0];
|
|
||||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
|
||||||
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
|
|
||||||
|
|
||||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
|
||||||
#if flash
|
|
||||||
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection("localhost", 5001));
|
|
||||||
#elseif html5
|
|
||||||
Provider.set(IConnection, new ru.m.connect.js.JsConnection("localhost", 5001));
|
|
||||||
#end
|
|
||||||
|
|
||||||
//Provider.get(IConnection).handler.addListener(this);
|
|
||||||
view = new MainView();
|
|
||||||
Provider.set(IFrameSwitcher, view.switcher);
|
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.content.stage.stageFocusRect = false;
|
view.launch();
|
||||||
//view.logout.onPress = this;
|
}
|
||||||
view.switcher.change(StartFrame.ID);
|
}
|
||||||
|
|
||||||
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
@:template class ClientView extends VGroupView {
|
||||||
if (event.keyCode == Keyboard.ESCAPE) {
|
private static inline var TAG = 'Tankz';
|
||||||
view.switcher.change(StartFrame.ID);
|
|
||||||
}
|
@:view private var switcher(default, null):FrameSwitcher;
|
||||||
});
|
@:provide var resources:IResources;
|
||||||
|
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
public function init():Void {
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
var font:Font = Font.enumerateFonts()[0];
|
||||||
}
|
resources.text.put('font', 'Bookman Old Style');
|
||||||
|
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||||
public function onPress(view:ButtonView):Void {
|
Provider.set(FrameSwitcher, switcher);
|
||||||
switch (view.id) {
|
}
|
||||||
case "logout":
|
|
||||||
Provider.get(IConnection).disconnect();
|
public function launch():Void {
|
||||||
}
|
content.stage.stageFocusRect = false;
|
||||||
}
|
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
|
if (event.keyCode == Keyboard.ESCAPE) {
|
||||||
public function onConnected():Void {}
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
public function onDisconnected():Void {
|
});
|
||||||
//view.switcher.change(AuthFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
}
|
|
||||||
|
|
||||||
public function onError(error:Dynamic):Void {
|
|
||||||
L.e(TAG, "", error);
|
|
||||||
//view.switcher.change(AuthFrame.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/client/haxe/ru/m/tankz/ClientView.yaml
Executable file
30
src/client/haxe/ru/m/tankz/ClientView.yaml
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
skinId: light
|
||||||
|
views:
|
||||||
|
- id: switcher
|
||||||
|
$type: haxework.gui.frame.FrameSwitcher
|
||||||
|
skinId: dark
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: start
|
||||||
|
$type: ru.m.tankz.frame.StartFrame
|
||||||
|
# classic
|
||||||
|
- id: classic.level
|
||||||
|
$type: ru.m.tankz.frame.classic.ClassicLevelFrame
|
||||||
|
- id: classic.game
|
||||||
|
$type: ru.m.tankz.frame.classic.ClassicGameFrame
|
||||||
|
# dota
|
||||||
|
- id: dota.level
|
||||||
|
$type: ru.m.tankz.frame.dota.DotaLevelFrame
|
||||||
|
- id: dota.game
|
||||||
|
$type: ru.m.tankz.frame.dota.DotaGameFrame
|
||||||
|
# - id: network
|
||||||
|
# $type: ru.m.tankz.frame.NetworkFrame
|
||||||
|
- id: settings
|
||||||
|
$type: ru.m.tankz.frame.SettingsFrame
|
||||||
@@ -11,9 +11,9 @@ class Const {
|
|||||||
public static var DEBUG:Bool;
|
public static var DEBUG:Bool;
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
FPS = Lib.current.stage.application.config.fps;
|
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||||
BUILD = CompilationOption.get("build");
|
BUILD = CompilationOption.get("build");
|
||||||
VERSION = Lib.current.stage.application.config.version;
|
VERSION = Lib.current.stage.application.meta.get("version");
|
||||||
DEBUG = Capabilities.isDebugger;
|
DEBUG = Capabilities.isDebugger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
66
src/client/haxe/ru/m/tankz/Init.hx
Normal file
66
src/client/haxe/ru/m/tankz/Init.hx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.resources.Resources;
|
||||||
|
import ru.m.connect.IConnection;
|
||||||
|
import ru.m.tankz.bundle.ConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.bundle.LevelBundle;
|
||||||
|
import ru.m.tankz.control.ClientControlFactory;
|
||||||
|
import ru.m.tankz.control.IControlFactory;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.pack.Request;
|
||||||
|
import ru.m.tankz.proto.pack.Response;
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
import ru.m.tankz.storage.UserStorage;
|
||||||
|
#if flash
|
||||||
|
import flash.Lib;
|
||||||
|
#elseif html5
|
||||||
|
import js.Browser;
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
class Init {
|
||||||
|
|
||||||
|
private static function getHost():String {
|
||||||
|
#if flash
|
||||||
|
var url = Lib.current.loaderInfo.url;
|
||||||
|
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
|
||||||
|
if (r.match(url) && !(r.matched(1) == "app")) {
|
||||||
|
return r.matched(2);
|
||||||
|
} else {
|
||||||
|
return "localhost";
|
||||||
|
}
|
||||||
|
#elseif html5
|
||||||
|
return Browser.location.hostname;
|
||||||
|
#else
|
||||||
|
return "localhost";
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function init():Void {
|
||||||
|
Provider.setFactory(IResources, Resources);
|
||||||
|
Provider.setFactory(ILevelBundle, LevelBundle);
|
||||||
|
Provider.setFactory(IConfigBundle, ConfigBundle);
|
||||||
|
Provider.setFactory(SaveStorage, SaveStorage);
|
||||||
|
Provider.setFactory(UserStorage, UserStorage);
|
||||||
|
Provider.setFactory(SettingsStorage, SettingsStorage);
|
||||||
|
Provider.setFactory(SoundManager, SoundManager);
|
||||||
|
Provider.setFactory(NetworkManager, NetworkManager);
|
||||||
|
Provider.setFactory(IControlFactory, ClientControlFactory);
|
||||||
|
|
||||||
|
var host:String = getHost();
|
||||||
|
L.d('Init', 'host: ${host}');
|
||||||
|
#if flash
|
||||||
|
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response));
|
||||||
|
#elseif html5
|
||||||
|
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response));
|
||||||
|
#else
|
||||||
|
Provider.set(IConnection, new ru.m.connect.fake.FakeConnection<Request, Response>(Response));
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
}
|
||||||
63
src/client/haxe/ru/m/tankz/Style.hx
Normal file
63
src/client/haxe/ru/m/tankz/Style.hx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.gui.skin.Skin;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.skin.ButtonSVGSkin;
|
||||||
|
|
||||||
|
class Style {
|
||||||
|
|
||||||
|
@:provide private static var resources:IResources;
|
||||||
|
|
||||||
|
private static var lightColor = 0x95937D;
|
||||||
|
private static var darkColor = 0x777564;
|
||||||
|
private static var textColor = 0xE7E0BB;
|
||||||
|
private static var fontFamily = "Courirer New";
|
||||||
|
|
||||||
|
public static function register() {
|
||||||
|
resources.skin.put("light", [Skin.color(lightColor)]);
|
||||||
|
resources.skin.put("dark", [Skin.color(darkColor)]);
|
||||||
|
resources.skin.put("text", [Skin.text(textColor, 16, fontFamily)]);
|
||||||
|
resources.skin.put("button", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, 18, fontFamily),
|
||||||
|
Skin.size(250, 50)
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box", [
|
||||||
|
Skin.color(lightColor),
|
||||||
|
Skin.text(textColor, 16, fontFamily),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box.active", [
|
||||||
|
Skin.color(0x55aa55),
|
||||||
|
Skin.text(textColor, 16, fontFamily),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.simple", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, 16, fontFamily),
|
||||||
|
Skin.size(100, 38),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.tab", [
|
||||||
|
Skin.tabColor(lightColor),
|
||||||
|
Skin.text(textColor, 16, fontFamily),
|
||||||
|
Skin.size(200, 38),
|
||||||
|
]);
|
||||||
|
resources.skin.put("border", [
|
||||||
|
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.level", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, 24, fontFamily),
|
||||||
|
Skin.size(64, 64),
|
||||||
|
]);
|
||||||
|
|
||||||
|
resources.skin.put("button.settings", [
|
||||||
|
Skin.size(64, 64),
|
||||||
|
new ButtonSVGSkin(Assets.getText("resources/image/icon/cog-solid.svg"), lightColor)
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.close", [
|
||||||
|
Skin.size(64, 64),
|
||||||
|
new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx
Normal file
22
src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import yaml.Parser;
|
||||||
|
import yaml.Yaml;
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
|
||||||
|
private var _cache:Map<GameType, Config> = new Map();
|
||||||
|
|
||||||
|
public function get(type:GameType):Config {
|
||||||
|
if (!_cache.exists(type)) {
|
||||||
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
||||||
|
_cache.set(type, new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses));
|
||||||
|
}
|
||||||
|
return _cache.get(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
15
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.util.LevelUtil;
|
||||||
|
|
||||||
|
|
||||||
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
|
public function get(type:GameType, config:Config, level:Int):LevelConfig {
|
||||||
|
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt');
|
||||||
|
return LevelUtil.loads(config, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
41
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import haxe.Serializer;
|
||||||
|
import haxe.Unserializer;
|
||||||
|
import ru.m.tankz.control.Control.TankAction;
|
||||||
|
|
||||||
|
typedef ActionItem = {
|
||||||
|
public var action:TankAction;
|
||||||
|
public var key:Int;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef KeyBinding = Map<Int, TankAction>;
|
||||||
|
|
||||||
|
class ActionConfig {
|
||||||
|
|
||||||
|
public var data(default, null):Array<ActionItem>;
|
||||||
|
|
||||||
|
public function new(data:Array<ActionItem>) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asKeyBinding():KeyBinding {
|
||||||
|
var result = new Map<Int, TankAction>();
|
||||||
|
for (item in data) {
|
||||||
|
result[item.key] = item.action;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clone():ActionConfig {
|
||||||
|
return loads(dumps());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dumps():String {
|
||||||
|
return Serializer.run(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loads(value:String):ActionConfig {
|
||||||
|
return new Unserializer(value).unserialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/client/haxe/ru/m/tankz/control/ClientControlFactory.hx
Normal file
23
src/client/haxe/ru/m/tankz/control/ClientControlFactory.hx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.bot.BotControl;
|
||||||
|
|
||||||
|
|
||||||
|
class ClientControlFactory implements IControlFactory {
|
||||||
|
|
||||||
|
private var humanControlIndex:Int;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
humanControlIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function build(id:PlayerId, type:ControlType):Control {
|
||||||
|
return switch (type) {
|
||||||
|
case Control.HUMAN: new HumanControl(id, humanControlIndex++);
|
||||||
|
case Control.BOT: new BotControl(id);
|
||||||
|
case Control.NONE: null;
|
||||||
|
case _: throw 'Unsupported control type: "${type}"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/client/haxe/ru/m/tankz/control/ClientNetworkControl.hx
Normal file
14
src/client/haxe/ru/m/tankz/control/ClientNetworkControl.hx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
|
||||||
|
class ClientNetworkControl extends HumanControl {
|
||||||
|
|
||||||
|
@:provide private var network:NetworkManager;
|
||||||
|
|
||||||
|
override public function action(action:TankAction):Void {
|
||||||
|
network.action(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
import haxe.Timer;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
import flash.ui.Keyboard;
|
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
import haxe.Timer;
|
||||||
typedef KeyBinding = Map<Int, TankAction>;
|
import ru.m.tankz.control.ActionConfig;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
|
|
||||||
|
@:provide var settings: SettingsStorage;
|
||||||
|
|
||||||
private var keyBinding:KeyBinding;
|
private var keyBinding:KeyBinding;
|
||||||
private var moveQueue:Array<Int>;
|
private var moveQueue:Array<Int>;
|
||||||
private var shotTimer:Timer;
|
private var shotTimer:Timer;
|
||||||
|
|
||||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super(playerId);
|
super(playerId);
|
||||||
this.keyBinding = resolve(controlIndex);
|
this.keyBinding = settings.read(controlIndex).asKeyBinding();
|
||||||
moveQueue = new Array<Int>();
|
moveQueue = new Array<Int>();
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
@@ -44,7 +44,7 @@ class HumanControl extends Control {
|
|||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
if (event.keyCode == Keyboard.U) {
|
if (event.keyCode == Keyboard.U) {
|
||||||
action(TankAction.LEVEL_UP(1));
|
action(TankAction.UPGRADE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,27 +82,4 @@ class HumanControl extends Control {
|
|||||||
private function shot():Void {
|
private function shot():Void {
|
||||||
action(TankAction.SHOT);
|
action(TankAction.SHOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function resolve(controlIndex:Int):KeyBinding {
|
|
||||||
switch (controlIndex) {
|
|
||||||
case 0:
|
|
||||||
return [
|
|
||||||
Keyboard.A => TankAction.MOVE(Direction.LEFT),
|
|
||||||
Keyboard.S => TankAction.MOVE(Direction.BOTTOM),
|
|
||||||
Keyboard.W => TankAction.MOVE(Direction.TOP),
|
|
||||||
Keyboard.D => TankAction.MOVE(Direction.RIGHT),
|
|
||||||
Keyboard.SPACE => TankAction.SHOT
|
|
||||||
];
|
|
||||||
case 1:
|
|
||||||
return [
|
|
||||||
Keyboard.LEFT => TankAction.MOVE(Direction.LEFT),
|
|
||||||
Keyboard.DOWN => TankAction.MOVE(Direction.BOTTOM),
|
|
||||||
Keyboard.UP => TankAction.MOVE(Direction.TOP),
|
|
||||||
Keyboard.RIGHT => TankAction.MOVE(Direction.RIGHT),
|
|
||||||
Keyboard.NUMPAD_0 => TankAction.SHOT
|
|
||||||
];
|
|
||||||
case x:
|
|
||||||
throw 'Invalid control index ${x}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
108
src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx
Normal file
108
src/client/haxe/ru/m/tankz/frame/NetworkFrame.hx
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
|
import haxework.gui.IGroupView;
|
||||||
|
import haxework.gui.InputView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
|
import ru.m.tankz.proto.core.GameStateProto;
|
||||||
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
|
||||||
|
|
||||||
|
@:template class NetworkFrame extends VGroupView {
|
||||||
|
public static var ID(default, never):String = "network";
|
||||||
|
|
||||||
|
@:view var frameSwitcher(default, null):IFrameSwitcher;
|
||||||
|
|
||||||
|
@:view var loginFrame(default, null):IGroupView;
|
||||||
|
@:view var stateLabel(default, null):LabelView;
|
||||||
|
@:view var nameInput(default, null):InputView;
|
||||||
|
@:view var loginButton(default, null):ButtonView;
|
||||||
|
|
||||||
|
@:view var gameListFrame(default, null):IGroupView;
|
||||||
|
@:view var createGameButton(default, null):ButtonView;
|
||||||
|
@:view var gameList(default, null):ListView<GameInfoProto>;
|
||||||
|
|
||||||
|
@:view var gameFrame(default, null):IGroupView;
|
||||||
|
@:view var leaveGameButton(default, null):ButtonView;
|
||||||
|
@:view var startGameButton(default, null):ButtonView;
|
||||||
|
@:view var userList(default, null):ListView<UserProto>;
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var mainFrameSwitcher:IFrameSwitcher;
|
||||||
|
|
||||||
|
public function init():Void {
|
||||||
|
loginButton.onPress = this;
|
||||||
|
createGameButton.onPress = this;
|
||||||
|
leaveGameButton.onPress = this;
|
||||||
|
startGameButton.onPress = this;
|
||||||
|
gameList.dispatcher.addListener({
|
||||||
|
onListItemClick: function(item:IListItemView<GameInfoProto>):Void {
|
||||||
|
network.joinGame(item.data.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
nameInput.text = network.user.name;
|
||||||
|
onStateChange(network.state);
|
||||||
|
network.stateSignal.connect(onStateChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onStateChange(state:String):Void {
|
||||||
|
loginButton.disabled = !(state == "offline" || state == "error");
|
||||||
|
stateLabel.text = state;
|
||||||
|
if (state == 'online') {
|
||||||
|
gameList.data = [];
|
||||||
|
frameSwitcher.change(gameListFrame.id);
|
||||||
|
network.listGameSignal.connect(onListGame);
|
||||||
|
network.gameSignal.connect(onGame);
|
||||||
|
network.listGame();
|
||||||
|
} else {
|
||||||
|
frameSwitcher.change(loginFrame.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onListGame(games:Array<GameInfoProto>):Void {
|
||||||
|
gameList.data = games;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGame(game:GameInfoProto):Void {
|
||||||
|
if (game != null) {
|
||||||
|
userList.data = game.players;
|
||||||
|
frameSwitcher.change(gameFrame.id);
|
||||||
|
if (game.state == GameStateProto.STARTED) {
|
||||||
|
Provider.set(GameState, new GameState(ClassicGame.TYPE, ClassicGame.PLAYER1));
|
||||||
|
mainFrameSwitcher.change(GameFrame.ID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
frameSwitcher.change(gameListFrame.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
|
network.listGameSignal.disconnect(onListGame);
|
||||||
|
network.gameSignal.disconnect(onGame);
|
||||||
|
network.stateSignal.disconnect(onStateChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
switch (view.id) {
|
||||||
|
case 'loginButton':
|
||||||
|
network.login(nameInput.text);
|
||||||
|
case 'createGameButton':
|
||||||
|
network.createGame('classic');
|
||||||
|
case 'leaveGameButton':
|
||||||
|
network.leaveGame();
|
||||||
|
case 'startGameButton':
|
||||||
|
network.startGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
90
src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml
Normal file
90
src/client/haxe/ru/m/tankz/frame/NetworkFrame.yaml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
---
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: frameSwitcher
|
||||||
|
$type: haxework.gui.frame.FrameSwitcher
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
# login
|
||||||
|
- id: loginFrame
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: stateLabel
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
$style: label
|
||||||
|
text: offline
|
||||||
|
width: 200
|
||||||
|
height: 50
|
||||||
|
- id: nameInput
|
||||||
|
$type: haxework.gui.InputView
|
||||||
|
$style: label
|
||||||
|
width: 200
|
||||||
|
height: 50
|
||||||
|
text: User
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: '#444444'
|
||||||
|
- id: loginButton
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
$style: button
|
||||||
|
text: Login
|
||||||
|
# game list
|
||||||
|
- id: gameListFrame
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: createGameButton
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
$style: button
|
||||||
|
text: Create
|
||||||
|
- id: gameList
|
||||||
|
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.GameInfoProto>
|
||||||
|
factory: "@class:ru.m.tankz.frame.network.GameItemView"
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
paddings: 10
|
||||||
|
scroll:
|
||||||
|
$type: haxework.gui.list.VScrollView
|
||||||
|
width: 10
|
||||||
|
pHeight: 100
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.list.VScrollSkin
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0
|
||||||
|
# game
|
||||||
|
- id: gameFrame
|
||||||
|
$type: haxework.gui.VGroupView
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
views:
|
||||||
|
- id: startGameButton
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
$style: button
|
||||||
|
text: Start
|
||||||
|
- id: leaveGameButton
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
$style: button
|
||||||
|
text: Leave
|
||||||
|
- id: userList
|
||||||
|
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.UserProto>
|
||||||
|
factory: "@class:ru.m.tankz.frame.network.UserItemView"
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
paddings: 10
|
||||||
|
scroll:
|
||||||
|
$type: haxework.gui.list.VScrollView
|
||||||
|
width: 10
|
||||||
|
pHeight: 100
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.list.VScrollSkin
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0
|
||||||
18
src/client/haxe/ru/m/tankz/frame/SettingsFrame.hx
Normal file
18
src/client/haxe/ru/m/tankz/frame/SettingsFrame.hx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
|
||||||
|
@:template class SettingsFrame extends VGroupView {
|
||||||
|
|
||||||
|
public static var ID(default, never):String = "settings";
|
||||||
|
|
||||||
|
@:provide var frameSwitcher:FrameSwitcher;
|
||||||
|
|
||||||
|
@:view var close:ButtonView;
|
||||||
|
|
||||||
|
public function onPress(_):Void {
|
||||||
|
frameSwitcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/client/haxe/ru/m/tankz/frame/SettingsFrame.yaml
Normal file
29
src/client/haxe/ru/m/tankz/frame/SettingsFrame.yaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- $type: haxework.gui.LabelView
|
||||||
|
skinId: text
|
||||||
|
geometry.size.fixed.height: 20
|
||||||
|
text: Settings
|
||||||
|
- $type: haxework.gui.HGroupView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
views:
|
||||||
|
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
||||||
|
geometry.size.percent.width: 50
|
||||||
|
#geometry.size.percent.height: 100
|
||||||
|
controlIndex: 0
|
||||||
|
- $type: ru.m.tankz.frame.settings.SettingsEditor
|
||||||
|
geometry.size.percent.width: 50
|
||||||
|
#geometry.size.percent.height: 100
|
||||||
|
controlIndex: 1
|
||||||
|
- id: close
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
skinId: button.close
|
||||||
|
+onPress: $this:onPress
|
||||||
|
geometry.position: absolute
|
||||||
|
geometry.margin.left: 10
|
||||||
|
geometry.margin.bottom: 10
|
||||||
|
geometry.vAlign: bottom
|
||||||
|
geometry.hAlign: left
|
||||||
29
src/client/haxe/ru/m/tankz/frame/StartFrame.hx
Normal file
29
src/client/haxe/ru/m/tankz/frame/StartFrame.hx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
|
import ru.m.tankz.frame.classic.ClassicLevelFrame;
|
||||||
|
import ru.m.tankz.frame.dota.DotaLevelFrame;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
|
||||||
|
@:template class StartFrame extends VGroupView {
|
||||||
|
|
||||||
|
public static var ID(default, never):String = "start";
|
||||||
|
|
||||||
|
@:provide var frameSwitcher:FrameSwitcher;
|
||||||
|
@:provide var storage:SaveStorage;
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
switch (view.id) {
|
||||||
|
case 'classic':
|
||||||
|
frameSwitcher.change(ClassicLevelFrame.ID);
|
||||||
|
case 'dota':
|
||||||
|
frameSwitcher.change(DotaLevelFrame.ID);
|
||||||
|
case 'network':
|
||||||
|
//frameSwitcher.change(NetworkFrame.ID);
|
||||||
|
case 'settings':
|
||||||
|
frameSwitcher.change(SettingsFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/client/haxe/ru/m/tankz/frame/StartFrame.yaml
Normal file
45
src/client/haxe/ru/m/tankz/frame/StartFrame.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
geometry.size.stretch: true
|
||||||
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
|
views:
|
||||||
|
- $type: haxework.gui.ImageView
|
||||||
|
image: $asset:image:resources/image/ui/logo.png
|
||||||
|
geometry.margin.bottom: 15
|
||||||
|
- $type: haxework.gui.VGroupView
|
||||||
|
layout.margin: 3
|
||||||
|
views:
|
||||||
|
- id: classic
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
skinId: button
|
||||||
|
+onPress: $this:onPress
|
||||||
|
text: Classic
|
||||||
|
- id: dota
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
skinId: button
|
||||||
|
+onPress: $this:onPress
|
||||||
|
text: DotA
|
||||||
|
- id: network
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
skinId: button
|
||||||
|
+onPress: $this:onPress
|
||||||
|
text: Network (in developing)
|
||||||
|
fontColor: 0xff0000
|
||||||
|
visible: false
|
||||||
|
- $type: haxework.gui.LabelView
|
||||||
|
skinId: text
|
||||||
|
geometry.position: absolute
|
||||||
|
geometry.margin.right: 10
|
||||||
|
geometry.margin.bottom: 10
|
||||||
|
geometry.vAlign: bottom
|
||||||
|
geometry.hAlign: right
|
||||||
|
text: $r:text:version
|
||||||
|
- id: settings
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
geometry.position: absolute
|
||||||
|
geometry.margin.left: 10
|
||||||
|
geometry.margin.bottom: 10
|
||||||
|
geometry.vAlign: bottom
|
||||||
|
geometry.hAlign: left
|
||||||
|
skinId: button.settings
|
||||||
|
+onPress: $this:onPress
|
||||||
20
src/client/haxe/ru/m/tankz/frame/classic/ClassicGameFrame.hx
Executable file
20
src/client/haxe/ru/m/tankz/frame/classic/ClassicGameFrame.hx
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.m.tankz.frame.classic;
|
||||||
|
|
||||||
|
import ru.m.tankz.frame.common.IGamePanel;
|
||||||
|
import ru.m.tankz.render.Render;
|
||||||
|
import ru.m.tankz.frame.common.GameFrame;
|
||||||
|
|
||||||
|
@:template class ClassicGameFrame extends GameFrame {
|
||||||
|
public static inline var ID = "classic.game";
|
||||||
|
|
||||||
|
@:view("render") private var renderView(default, null):Render;
|
||||||
|
@:view("panel") private var panelView(default, null):IGamePanel;
|
||||||
|
|
||||||
|
override private function get_render():Render {
|
||||||
|
return renderView;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_panel():IGamePanel {
|
||||||
|
return panelView;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.HorizontalLayout
|
||||||
|
margin: 5
|
||||||
|
hAlign: center
|
||||||
|
vAlign: middle
|
||||||
|
views:
|
||||||
|
- id: render
|
||||||
|
$type: ru.m.tankz.render.Render
|
||||||
|
- id: panel
|
||||||
|
$type: ru.m.tankz.frame.classic.ClassicGamePanel
|
||||||
33
src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx
Normal file
33
src/client/haxe/ru/m/tankz/frame/classic/ClassicGamePanel.hx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.m.tankz.frame.classic;
|
||||||
|
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import ru.m.tankz.frame.common.IGamePanel;
|
||||||
|
import ru.m.tankz.frame.common.LifeView;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
|
|
||||||
|
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
|
||||||
|
|
||||||
|
@:view var bot:LifeView;
|
||||||
|
@:view var player1:LifeView;
|
||||||
|
@:view var player2:LifeView;
|
||||||
|
|
||||||
|
public var game:Game;
|
||||||
|
|
||||||
|
private function updateViews():Void {
|
||||||
|
bot.count.text = '${game.teams[ClassicGame.BOT].life}';
|
||||||
|
player1.count.text = '${game.teams[ClassicGame.HUMAN].players[0].state.life}';
|
||||||
|
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
|
||||||
|
player2.count.text = '${game.teams[ClassicGame.HUMAN].players[1].state.life}';
|
||||||
|
} else {
|
||||||
|
player2.count.text = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
if (game != null) {
|
||||||
|
updateViews();
|
||||||
|
}
|
||||||
|
super.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
geometry.padding: 5
|
||||||
|
layout.margin: 5
|
||||||
|
layout.hAlign: right
|
||||||
|
views:
|
||||||
|
- id: bot
|
||||||
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
|
image.image: $asset:image:resources/image/tank/ba-0.png
|
||||||
|
- id: player1
|
||||||
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
|
image.image: $asset:image:resources/image/tank/pa-0.png
|
||||||
|
image.color: 0xFFFF00
|
||||||
|
- id: player2
|
||||||
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
|
image.image: $asset:image:resources/image/tank/pa-0.png
|
||||||
|
image.color: 0x15C040
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package ru.m.tankz.frame.classic;
|
||||||
|
|
||||||
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
import haxework.gui.DataView;
|
||||||
|
import haxework.gui.ToggleButtonView;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.frame.common.LevelFrame;
|
||||||
|
import ru.m.tankz.preset.ClassicGame;
|
||||||
|
|
||||||
|
@:template class ClassicLevelFrame extends LevelFrame {
|
||||||
|
public static inline var ID = "classic.level";
|
||||||
|
|
||||||
|
@:view var presets(default, null):DataView<GamePreset>;
|
||||||
|
@:view var levels(default, null):DataView<Int>;
|
||||||
|
|
||||||
|
@:provide var frames:FrameSwitcher;
|
||||||
|
|
||||||
|
private function onShow():Void {
|
||||||
|
gameType = ClassicGame.TYPE;
|
||||||
|
levels.data = [for (i in 0...config.game.levels) i];
|
||||||
|
presets.data = config.presets;
|
||||||
|
setSelectedPreset(preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setSelectedPreset(preset:GamePreset) {
|
||||||
|
for (view in presets.views) {
|
||||||
|
cast(view, ToggleButtonView).on = view.id == preset.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function presetViewFactory(index:Int, preset:GamePreset):ToggleButtonView {
|
||||||
|
var view = new ToggleButtonView();
|
||||||
|
view.id = preset.id;
|
||||||
|
view.text = '${preset.id}';
|
||||||
|
resources.skin.bind("button.simple", view, "skin");
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function set_preset(value:GamePreset):GamePreset {
|
||||||
|
var result = super.set_preset(value);
|
||||||
|
setSelectedPreset(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override private function set_level(value:Int):Int {
|
||||||
|
var result = super.set_level(value);
|
||||||
|
frames.change(ClassicGameFrame.ID);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.VerticalLayout
|
||||||
|
hAlign: center
|
||||||
|
views:
|
||||||
|
- id: presets
|
||||||
|
$type: haxework.gui.DataView<GamePreset>
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.HorizontalLayout
|
||||||
|
hAlign: center
|
||||||
|
margin: 2
|
||||||
|
factory: $this:presetViewFactory
|
||||||
|
+onDataSelect: $code:function(value) preset = value
|
||||||
|
geometry.padding: 10
|
||||||
|
- id: levels
|
||||||
|
$type: haxework.gui.DataView<Int>
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onDataSelect: $code:function(value) level = value
|
||||||
|
geometry.padding: 10
|
||||||
104
src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx
Normal file
104
src/client/haxe/ru/m/tankz/frame/common/GameFrame.hx
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import flash.events.Event;
|
||||||
|
import haxe.ds.Option;
|
||||||
|
import haxe.Timer;
|
||||||
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
import haxework.gui.GroupView;
|
||||||
|
import ru.m.tankz.frame.common.IGamePanel;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.render.Render;
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
|
||||||
|
class GameFrame extends GroupView {
|
||||||
|
|
||||||
|
private static inline var TAG = "GameFrame";
|
||||||
|
|
||||||
|
private var render(get, null):Render;
|
||||||
|
private var panel(get, null):IGamePanel;
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var sound:SoundManager;
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var storage:SaveStorage;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
|
||||||
|
private var game:Game;
|
||||||
|
private var timer:Timer;
|
||||||
|
|
||||||
|
private function get_render():Render {
|
||||||
|
throw "Not implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_panel():IGamePanel {
|
||||||
|
throw "Not implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
start(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function start(state:GameState):Void {
|
||||||
|
game = new Game(state.type);
|
||||||
|
game.engine.connect(render);
|
||||||
|
game.engine.connect(sound);
|
||||||
|
game.start(state).then(onGameStateChange).endThen(onGameComplete);
|
||||||
|
timer = new Timer(10);
|
||||||
|
timer.run = updateEngine;
|
||||||
|
panel.game = game;
|
||||||
|
content.addEventListener(Event.ENTER_FRAME, _redraw);
|
||||||
|
render.draw(game.engine);
|
||||||
|
sound.play('start');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function stop():Void {
|
||||||
|
if (timer != null) {
|
||||||
|
timer.stop();
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
content.removeEventListener(Event.ENTER_FRAME, _redraw);
|
||||||
|
if (game != null) {
|
||||||
|
game.dispose();
|
||||||
|
game = null;
|
||||||
|
}
|
||||||
|
render.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameStateChange(s:GameState):GameState {
|
||||||
|
panel.toUpdate();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameComplete(result:Option<GameState>):Void {
|
||||||
|
switch (result) {
|
||||||
|
case Option.Some(s):
|
||||||
|
panel.toUpdate();
|
||||||
|
case Option.None:
|
||||||
|
}
|
||||||
|
switch (game.next()) {
|
||||||
|
case Option.Some(s):
|
||||||
|
var state = game.save();
|
||||||
|
this.state = state;
|
||||||
|
storage.write(state);
|
||||||
|
stop();
|
||||||
|
start(state);
|
||||||
|
case Option.None:
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateEngine():Void {
|
||||||
|
game.engine.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _redraw(_):Void {
|
||||||
|
render.draw(game.engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/client/haxe/ru/m/tankz/frame/common/IGamePanel.hx
Normal file
8
src/client/haxe/ru/m/tankz/frame/common/IGamePanel.hx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
import haxework.gui.IView;
|
||||||
|
|
||||||
|
interface IGamePanel extends IView<Dynamic> {
|
||||||
|
public var game:Game;
|
||||||
|
}
|
||||||
59
src/client/haxe/ru/m/tankz/frame/common/LevelFrame.hx
Normal file
59
src/client/haxe/ru/m/tankz/frame/common/LevelFrame.hx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.GroupView;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class LevelFrame extends GroupView {
|
||||||
|
|
||||||
|
public var gameType(default, set):GameType;
|
||||||
|
public var preset(default, set):GamePreset;
|
||||||
|
public var level(default, set):Int;
|
||||||
|
private var config(default, null):Config;
|
||||||
|
|
||||||
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var storage:SaveStorage;
|
||||||
|
@:provide var resources:IResources;
|
||||||
|
|
||||||
|
private function set_gameType(value:GameType):GameType {
|
||||||
|
if (gameType != value) {
|
||||||
|
gameType = value;
|
||||||
|
config = configBundle.get(gameType);
|
||||||
|
preset = config.presets[0];
|
||||||
|
}
|
||||||
|
return gameType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_preset(value:GamePreset):GamePreset {
|
||||||
|
if (preset != value) {
|
||||||
|
preset = value;
|
||||||
|
state = new GameState(gameType, preset.id);
|
||||||
|
for (team in value.teams) {
|
||||||
|
for (player in team.players) {
|
||||||
|
var playerId = new PlayerId(team.id, player.index);
|
||||||
|
state.control.set(playerId, player.control != null ? player.control : Control.BOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_level(value:Int):Int {
|
||||||
|
state.level = value;
|
||||||
|
return state.level;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function levelViewFactory(index:Int, level:Int):ButtonView {
|
||||||
|
var view = new ButtonView();
|
||||||
|
view.text = '${level}';
|
||||||
|
resources.skin.bind("button.level", view, "skin");
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
package ru.m.tankz.view.frames.list;
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.list.ListView.IListItemView;
|
import haxework.gui.list.ListView.IListItemView;
|
||||||
|
|
||||||
|
|
||||||
interface LevelViewLayout {
|
@:template class LevelView extends HGroupView implements IListItemView<Int> {
|
||||||
var label(default, null):LabelView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:template("layout/other.json@level", "layout/styles.json")
|
|
||||||
class LevelView extends HGroupView implements ViewBuilder implements IListItemView<Int> implements LevelViewLayout {
|
|
||||||
|
|
||||||
public var item_index(default, default):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):Int;
|
public var data(default, set):Int;
|
||||||
|
|
||||||
|
@:view var label(default, null):LabelView;
|
||||||
|
|
||||||
private function set_data(value:Int):Int {
|
private function set_data(value:Int):Int {
|
||||||
data = value;
|
data = value;
|
||||||
label.text = 'Level ${data}';
|
label.text = 'Level ${data}';
|
||||||
14
src/client/haxe/ru/m/tankz/frame/common/LevelView.yaml
Normal file
14
src/client/haxe/ru/m/tankz/frame/common/LevelView.yaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
geometry.size.width: 100%
|
||||||
|
geometry.size.height: 44
|
||||||
|
geometry.margin: 5
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
skinId: text
|
||||||
|
geometry.size.stretch: true
|
||||||
|
text: ""
|
||||||
|
skin:
|
||||||
|
- $type: haxework.gui.skin.ColorSkin
|
||||||
|
color: 0x000000
|
||||||
|
alpha: 0.2
|
||||||
10
src/client/haxe/ru/m/tankz/frame/common/LifeView.hx
Normal file
10
src/client/haxe/ru/m/tankz/frame/common/LifeView.hx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.ImageView;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
|
||||||
|
@:template class LifeView extends HGroupView {
|
||||||
|
@:view public var image:ImageView;
|
||||||
|
@:view public var count:LabelView;
|
||||||
|
}
|
||||||
9
src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml
Normal file
9
src/client/haxe/ru/m/tankz/frame/common/LifeView.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
layout.margin: 5
|
||||||
|
views:
|
||||||
|
- id: image
|
||||||
|
$type: haxework.gui.ImageView
|
||||||
|
- id: count
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
skinId: text.box
|
||||||
|
geometry.size.fixed: [50, 38]
|
||||||
65
src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx
Normal file
65
src/client/haxe/ru/m/tankz/frame/common/PlayerView.hx
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package ru.m.tankz.frame.common;
|
||||||
|
|
||||||
|
import haxework.color.Color;
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import haxework.gui.skin.Skin;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
@:template class PlayerView extends HGroupView implements IListItemView<PlayerId> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):PlayerId;
|
||||||
|
|
||||||
|
@:view("index") var indexLabel(default, null):LabelView;
|
||||||
|
@:view var control(default, null):ButtonView;
|
||||||
|
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var configBundle:IConfigBundle;
|
||||||
|
|
||||||
|
private function set_data(value:PlayerId):PlayerId {
|
||||||
|
data = value;
|
||||||
|
indexLabel.text = '${value.team} ${Std.string(data.index + 1)}';
|
||||||
|
var color = 0xffffff;
|
||||||
|
var config = configBundle.get(state.type);
|
||||||
|
var preset = config.getPreset(state.presetId);
|
||||||
|
for (team in preset.teams) {
|
||||||
|
if (team.id == data.team) {
|
||||||
|
color = team.color;
|
||||||
|
for (player in team.players) {
|
||||||
|
if (player.index == data.index) {
|
||||||
|
if (!player.color.zero) {
|
||||||
|
color = player.color;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
preset.teams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indexLabel.fontColor = color;
|
||||||
|
var controlType = state.control.get(value);
|
||||||
|
var image = Assets.getBitmapData('resources/image/ui/control/${controlType}.png');
|
||||||
|
control.skin = [Skin.buttonBitmap(image)];
|
||||||
|
indexLabel.update();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleControl():Void {
|
||||||
|
if (data != null && data.index > -1) {
|
||||||
|
var controlType = switch state.control.get(data) {
|
||||||
|
case Control.BOT: Control.HUMAN;
|
||||||
|
case Control.HUMAN: Control.BOT;
|
||||||
|
case _: Control.BOT;
|
||||||
|
}
|
||||||
|
state.control.set(data, controlType);
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml
Normal file
18
src/client/haxe/ru/m/tankz/frame/common/PlayerView.yaml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
geometry.size.width: 200
|
||||||
|
geometry.size.height: 44
|
||||||
|
geometry.margin: 5
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: index
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
geometry.size.stretch: true
|
||||||
|
skin:
|
||||||
|
- $type: haxework.gui.skin.ColorSkin
|
||||||
|
color: 0x000000
|
||||||
|
alpha: 0.2
|
||||||
|
shadow: true
|
||||||
|
shadowColor: 0x000000
|
||||||
|
- id: control
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
+onPress: $code:toggleControl()
|
||||||
21
src/client/haxe/ru/m/tankz/frame/dota/DotaGameFrame.hx
Executable file
21
src/client/haxe/ru/m/tankz/frame/dota/DotaGameFrame.hx
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.m.tankz.frame.dota;
|
||||||
|
|
||||||
|
import ru.m.tankz.frame.common.GameFrame;
|
||||||
|
import ru.m.tankz.frame.common.IGamePanel;
|
||||||
|
import ru.m.tankz.render.Render;
|
||||||
|
|
||||||
|
@:template class DotaGameFrame extends GameFrame {
|
||||||
|
|
||||||
|
public static inline var ID = "dota.game";
|
||||||
|
|
||||||
|
@:view("render") private var renderView(default, null):Render;
|
||||||
|
@:view("panel") private var panelView(default, null):IGamePanel;
|
||||||
|
|
||||||
|
override private function get_render():Render {
|
||||||
|
return renderView;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_panel():IGamePanel {
|
||||||
|
return panelView;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/client/haxe/ru/m/tankz/frame/dota/DotaGameFrame.yaml
Normal file
9
src/client/haxe/ru/m/tankz/frame/dota/DotaGameFrame.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.VerticalLayout
|
||||||
|
margin: 5
|
||||||
|
views:
|
||||||
|
- id: panel
|
||||||
|
$type: ru.m.tankz.frame.dota.DotaGamePanel
|
||||||
|
- id: render
|
||||||
|
$type: ru.m.tankz.render.Render
|
||||||
49
src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx
Normal file
49
src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.hx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package ru.m.tankz.frame.dota;
|
||||||
|
|
||||||
|
import ru.m.tankz.preset.DotaGame;
|
||||||
|
import ru.m.tankz.frame.common.LifeView;
|
||||||
|
import ru.m.tankz.frame.common.IGamePanel;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
|
||||||
|
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
|
||||||
|
|
||||||
|
@:view var radiant:LifeView;
|
||||||
|
@:view var dire:LifeView;
|
||||||
|
|
||||||
|
public var game:Game;
|
||||||
|
|
||||||
|
private function stateString(game:Game):String {
|
||||||
|
if (game == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
var result:Array<String> = [];
|
||||||
|
result.push('Level: ${game.state.level}');
|
||||||
|
for (team in game.teams) {
|
||||||
|
if (game.loser == team.id) {
|
||||||
|
result.push('${team.id}: LOSE');
|
||||||
|
} else if (team.life > 0) {
|
||||||
|
result.push('${team.id}: ${team.life}');
|
||||||
|
} else {
|
||||||
|
for (player in team.players) {
|
||||||
|
if (player.state.life > 0) {
|
||||||
|
result.push('${player.id.team}${player.id.index}: ${player.state.life}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '[ ${result.join(' | ')} ]';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateViews():Void {
|
||||||
|
radiant.count.text = '${game.teams[DotaGame.RADIANT].life}';
|
||||||
|
dire.count.text = '${game.teams[DotaGame.DIRE].life}';
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
if (game != null) {
|
||||||
|
updateViews();
|
||||||
|
}
|
||||||
|
super.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml
Normal file
14
src/client/haxe/ru/m/tankz/frame/dota/DotaGamePanel.yaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout.margin: 20
|
||||||
|
views:
|
||||||
|
- id: radiant
|
||||||
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
|
image.image: $asset:image:resources/image/tank/bc-0.png
|
||||||
|
image.color: 0xff4422
|
||||||
|
- $type: haxework.gui.SpriteView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
- id: dire
|
||||||
|
$type: ru.m.tankz.frame.common.LifeView
|
||||||
|
image.image: $asset:image:resources/image/tank/bc-0.png
|
||||||
|
image.color: 0x3284ff
|
||||||
42
src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx
Normal file
42
src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.hx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package ru.m.tankz.frame.dota;
|
||||||
|
|
||||||
|
import haxework.gui.DataView;
|
||||||
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
import ru.m.tankz.frame.common.LevelFrame;
|
||||||
|
import ru.m.tankz.frame.common.PlayerView;
|
||||||
|
import ru.m.tankz.preset.DotaGame;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
@:template class DotaLevelFrame extends LevelFrame {
|
||||||
|
public static inline var ID = "dota.level";
|
||||||
|
|
||||||
|
@:view var levels(default, null):DataView<Int>;
|
||||||
|
@:view var players(default, null):DataView<PlayerId>;
|
||||||
|
|
||||||
|
@:provide var frames:FrameSwitcher;
|
||||||
|
|
||||||
|
private function onShow():Void {
|
||||||
|
gameType = DotaGame.TYPE;
|
||||||
|
levels.data = [for (i in 0...config.game.levels) i];
|
||||||
|
var data = [];
|
||||||
|
for (team in preset.teams) {
|
||||||
|
for (p in team.players) {
|
||||||
|
data.push(new PlayerId(team.id, p.index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
players.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function playerViewFactory(index:Int, player:PlayerId):PlayerView {
|
||||||
|
var view = new PlayerView();
|
||||||
|
view.item_index = index;
|
||||||
|
view.data = player;
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function set_level(value:Int):Int {
|
||||||
|
var result = super.set_level(value);
|
||||||
|
frames.change(DotaGameFrame.ID);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.yaml
Normal file
20
src/client/haxe/ru/m/tankz/frame/dota/DotaLevelFrame.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.HorizontalLayout
|
||||||
|
views:
|
||||||
|
- id: players
|
||||||
|
$type: haxework.gui.DataView<PlayerId>
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.VerticalLayout
|
||||||
|
hAlign: center
|
||||||
|
factory: $this:playerViewFactory
|
||||||
|
geometry.padding: 10
|
||||||
|
- id: levels
|
||||||
|
$type: haxework.gui.DataView<Int>
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.TailLayout
|
||||||
|
rowSize: 5
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onDataSelect: $code:function(value) level = value
|
||||||
|
geometry.padding: 10
|
||||||
21
src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx
Executable file
21
src/client/haxe/ru/m/tankz/frame/network/GameItemView.hx
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.m.tankz.frame.network;
|
||||||
|
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
|
|
||||||
|
|
||||||
|
@:template class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):GameInfoProto;
|
||||||
|
|
||||||
|
@:view var label(default, null):LabelView;
|
||||||
|
|
||||||
|
private function set_data(value:GameInfoProto):GameInfoProto {
|
||||||
|
data = value;
|
||||||
|
label.text = '${data.type}';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml
Normal file
15
src/client/haxe/ru/m/tankz/frame/network/GameItemView.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
width: 440
|
||||||
|
height: 44
|
||||||
|
margins: 5
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
$style: label
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
text: ""
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0.2
|
||||||
21
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
21
src/client/haxe/ru/m/tankz/frame/network/UserItemView.hx
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.m.tankz.frame.network;
|
||||||
|
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView;
|
||||||
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
|
||||||
|
|
||||||
|
@:template class UserItemView extends HGroupView implements IListItemView<UserProto> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):UserProto;
|
||||||
|
|
||||||
|
@:view var label(default, null):LabelView;
|
||||||
|
|
||||||
|
private function set_data(value:UserProto):UserProto {
|
||||||
|
data = value;
|
||||||
|
label.text = '${data.uuid} -- ${data.name}';
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
15
src/client/haxe/ru/m/tankz/frame/network/UserItemView.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
width: 440
|
||||||
|
height: 44
|
||||||
|
margins: 5
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
$style: label
|
||||||
|
pWidth: 100
|
||||||
|
pHeight: 100
|
||||||
|
text: ""
|
||||||
|
skin:
|
||||||
|
$type: haxework.gui.skin.ColorSkin
|
||||||
|
color: "#000000"
|
||||||
|
alpha: 0.2
|
||||||
83
src/client/haxe/ru/m/tankz/frame/settings/ActionView.hx
Executable file
83
src/client/haxe/ru/m/tankz/frame/settings/ActionView.hx
Executable file
@@ -0,0 +1,83 @@
|
|||||||
|
package ru.m.tankz.frame.settings;
|
||||||
|
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.list.ListView.IListItemView;
|
||||||
|
import openfl.Assets;
|
||||||
|
import openfl.events.KeyboardEvent;
|
||||||
|
import promhx.Deferred;
|
||||||
|
import promhx.Promise;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
class KeyboardMap {
|
||||||
|
|
||||||
|
private var data:Map<Int, String>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
this.data = new Map();
|
||||||
|
var data = Assets.getText("resources/keyboard.txt");
|
||||||
|
for (line in data.split("\n")) {
|
||||||
|
var arr = line.split("\t");
|
||||||
|
if (arr.length == 2) {
|
||||||
|
this.data.set(Std.parseInt(arr[1]), arr[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static var instance: KeyboardMap;
|
||||||
|
|
||||||
|
public static function getName(key: Int): String {
|
||||||
|
if (instance == null) instance = new KeyboardMap();
|
||||||
|
return key == -1 ? "<NONE>" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
|
||||||
|
|
||||||
|
public var item_index(default, default):Int;
|
||||||
|
public var data(default, set):ActionItem;
|
||||||
|
|
||||||
|
@:view var action(default, null):LabelView;
|
||||||
|
@:view var key(default, null):LabelView;
|
||||||
|
|
||||||
|
private var editDeferred: Deferred<Int>;
|
||||||
|
|
||||||
|
private static function actionLabel(action: TankAction): String {
|
||||||
|
return switch (action) {
|
||||||
|
case TankAction.SHOT: "SHOT";
|
||||||
|
case TankAction.MOVE(d): 'MOVE_$d';
|
||||||
|
case x: '$x';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function keyLabel(key: Int): String {
|
||||||
|
return KeyboardMap.getName(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_data(value:ActionItem):ActionItem {
|
||||||
|
data = value;
|
||||||
|
action.text = actionLabel(data.action);
|
||||||
|
key.text = keyLabel(data.key);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit():Promise<Int> {
|
||||||
|
action.skinId = key.skinId = "text.box.active";
|
||||||
|
toRedraw();
|
||||||
|
editDeferred = new Deferred();
|
||||||
|
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
return editDeferred.promise();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onKeyDown(event: KeyboardEvent):Void {
|
||||||
|
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
action.skinId = key.skinId = "text.box";
|
||||||
|
toRedraw();
|
||||||
|
data.key = event.keyCode;
|
||||||
|
key.text = keyLabel(data.key);
|
||||||
|
editDeferred.resolve(data.key);
|
||||||
|
editDeferred = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/client/haxe/ru/m/tankz/frame/settings/ActionView.yaml
Normal file
12
src/client/haxe/ru/m/tankz/frame/settings/ActionView.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
geometry.margin: 5
|
||||||
|
layout.margin: 5
|
||||||
|
views:
|
||||||
|
- id: action
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
geometry.size.fixed: [200, 38]
|
||||||
|
skinId: text.box
|
||||||
|
- id: key
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
geometry.size.fixed: [200, 38]
|
||||||
|
skinId: text.box
|
||||||
75
src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.hx
Normal file
75
src/client/haxe/ru/m/tankz/frame/settings/SettingsEditor.hx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package ru.m.tankz.frame.settings;
|
||||||
|
|
||||||
|
import haxework.gui.ButtonView;
|
||||||
|
import haxework.gui.DataView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import promhx.Promise;
|
||||||
|
import ru.m.tankz.control.ActionConfig.ActionItem;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
|
||||||
|
@:template class SettingsEditor extends VGroupView {
|
||||||
|
|
||||||
|
public var controlIndex(default, set): Int;
|
||||||
|
|
||||||
|
@:view var label:LabelView;
|
||||||
|
@:view var list:DataView<ActionItem>;
|
||||||
|
@:view var change:ButtonView;
|
||||||
|
@:view var clear:ButtonView;
|
||||||
|
@:view var reset:ButtonView;
|
||||||
|
|
||||||
|
@:provide var storage: SettingsStorage;
|
||||||
|
|
||||||
|
private function set_controlIndex(value: Int): Int {
|
||||||
|
this.controlIndex = value;
|
||||||
|
label.text = 'Player ${controlIndex+1}';
|
||||||
|
list.data = storage.read(controlIndex).data;
|
||||||
|
return this.controlIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function viewFactory(index:Int, value:ActionItem) {
|
||||||
|
var view = new ActionView();
|
||||||
|
view.item_index = index;
|
||||||
|
view.data = value;
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPress(view:ButtonView):Void {
|
||||||
|
switch (view.id) {
|
||||||
|
case "change": _change();
|
||||||
|
case "clear": _clear();
|
||||||
|
case "reset": _reset();
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _change():Void {
|
||||||
|
var p: Promise<Int> = Promise.promise(0);
|
||||||
|
for (view in list.views) {
|
||||||
|
var v: ActionView = cast view;
|
||||||
|
if (v.data == null) break;
|
||||||
|
p = p.pipe(function(_):Promise<Int> return v.edit());
|
||||||
|
}
|
||||||
|
p.then(function(_) _save());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _clear():Void {
|
||||||
|
for (item in list.data) {
|
||||||
|
item.key = -1;
|
||||||
|
}
|
||||||
|
list.data = list.data;
|
||||||
|
list.toUpdate();
|
||||||
|
_save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _reset():Void {
|
||||||
|
list.data = SettingsStorage.getDefault(controlIndex).data;
|
||||||
|
list.toUpdate();
|
||||||
|
_save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _save():Void {
|
||||||
|
storage.write(controlIndex, new ActionConfig(list.data));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
layout.margin: 10
|
||||||
|
layout.hAlign: center
|
||||||
|
views:
|
||||||
|
- id: label
|
||||||
|
$type: haxework.gui.LabelView
|
||||||
|
skinId: text
|
||||||
|
- $type: haxework.gui.HGroupView
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: change
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
+onPress: $this:onPress
|
||||||
|
skinId: button.simple
|
||||||
|
text: Change
|
||||||
|
- id: clear
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
+onPress: $this:onPress
|
||||||
|
skinId: button.simple
|
||||||
|
text: Clear
|
||||||
|
- id: reset
|
||||||
|
$type: haxework.gui.ButtonView
|
||||||
|
+onPress: $this:onPress
|
||||||
|
skinId: button.simple
|
||||||
|
text: Reset
|
||||||
|
- id: list
|
||||||
|
$type: haxework.gui.DataView<ru.m.tankz.control.ActionItem>
|
||||||
|
layout:
|
||||||
|
$type: haxework.gui.layout.VerticalLayout
|
||||||
|
factory: $this:viewFactory
|
||||||
157
src/client/haxe/ru/m/tankz/network/NetworkManager.hx
Normal file
157
src/client/haxe/ru/m/tankz/network/NetworkManager.hx
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.tankz.proto.pack.GameRequest;
|
||||||
|
import ru.m.tankz.proto.core.GameProto;
|
||||||
|
import ru.m.tankz.proto.pack.StartGameRequest;
|
||||||
|
import ru.m.tankz.proto.game.GameChangeProto;
|
||||||
|
import ru.m.tankz.proto.game.GameActionTypeProto;
|
||||||
|
import ru.m.tankz.proto.pack.GameUpdateRequest;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.proto.pack.JoinGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.CreateGameRequest;
|
||||||
|
import ru.m.connect.IConnection;
|
||||||
|
import ru.m.tankz.proto.core.GameInfoProto;
|
||||||
|
import ru.m.tankz.proto.pack.ListGameRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
|
import ru.m.tankz.proto.pack.Request;
|
||||||
|
import ru.m.tankz.proto.pack.Response;
|
||||||
|
import ru.m.tankz.storage.UserStorage;
|
||||||
|
|
||||||
|
|
||||||
|
typedef ClientConnection = IConnection<Request, Response>;
|
||||||
|
|
||||||
|
class NetworkManager {
|
||||||
|
|
||||||
|
public var state(default, null):String;
|
||||||
|
public var stateSignal:Signal<String>;
|
||||||
|
public var listGameSignal:Signal<Array<GameInfoProto>>;
|
||||||
|
public var gameSignal:Signal<GameInfoProto>;
|
||||||
|
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
||||||
|
public var user(default, null):User;
|
||||||
|
public var game(default, set):NetworkGame;
|
||||||
|
|
||||||
|
@:provide private var connection:ClientConnection;
|
||||||
|
@:provide private var storage:UserStorage;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
stateSignal = new Signal<String>();
|
||||||
|
listGameSignal = new Signal<Array<GameInfoProto>>();
|
||||||
|
gameSignal = new Signal<GameInfoProto>();
|
||||||
|
gameUpdateSignal = new Signal<Array<GameChangeProto>>();
|
||||||
|
updateState('offline');
|
||||||
|
connection.handler.connect(onConnectionEvent);
|
||||||
|
connection.receiveHandler.connect(onResponse);
|
||||||
|
user = storage.read();
|
||||||
|
if (user == null) {
|
||||||
|
user = {name: 'User', uuid: null};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateState(value:String):Void {
|
||||||
|
state = value;
|
||||||
|
stateSignal.emit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(name:String):Void {
|
||||||
|
user.name = name;
|
||||||
|
updateState('connect...');
|
||||||
|
connection.connect().then(function(c:ClientConnection) {
|
||||||
|
updateState('login...');
|
||||||
|
c.send(new Request().setLogin(
|
||||||
|
new LoginRequest()
|
||||||
|
.setUuid(user.uuid)
|
||||||
|
.setName(user.name)
|
||||||
|
));
|
||||||
|
}).catchError(function(_) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listGame():Void {
|
||||||
|
connection.send(new Request().setListGame(new ListGameRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createGame(type:String):Void {
|
||||||
|
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function joinGame(gameId:Int):Void {
|
||||||
|
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leaveGame():Void {
|
||||||
|
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startGame():Void {
|
||||||
|
connection.send(new Request().setStartGame(new StartGameRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function action(action:TankAction):Void {
|
||||||
|
var update:GameUpdateRequest = switch action {
|
||||||
|
case TankAction.MOVE(direction):
|
||||||
|
new GameUpdateRequest()
|
||||||
|
.setType(GameActionTypeProto.MOVE)
|
||||||
|
.setDirectionX(direction.x)
|
||||||
|
.setDirectionY(direction.y);
|
||||||
|
case TankAction.STOP:
|
||||||
|
new GameUpdateRequest()
|
||||||
|
.setType(GameActionTypeProto.STOP);
|
||||||
|
case TankAction.SHOT:
|
||||||
|
new GameUpdateRequest()
|
||||||
|
.setType(GameActionTypeProto.SHOT);
|
||||||
|
case _: null;
|
||||||
|
}
|
||||||
|
if (update != null) {
|
||||||
|
connection.send(new Request().setUpdateGame(update));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
|
updateState(switch (event) {
|
||||||
|
case ConnectionEvent.CONNECTED:
|
||||||
|
L.d('Network', '$event');
|
||||||
|
'connected';
|
||||||
|
case ConnectionEvent.DISCONNECTED:
|
||||||
|
L.d('Network', '$event');
|
||||||
|
'offline';
|
||||||
|
case ConnectionEvent.ERROR(error):
|
||||||
|
L.e('Network', '$error', error);
|
||||||
|
'error';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onResponse(packet:Response):Void {
|
||||||
|
if (packet.hasLogin()) {
|
||||||
|
user = {
|
||||||
|
uuid: packet.login.user.uuid,
|
||||||
|
name: packet.login.user.name,
|
||||||
|
};
|
||||||
|
storage.write(user);
|
||||||
|
updateState('online');
|
||||||
|
} else if (packet.hasLogout()) {
|
||||||
|
user = null;
|
||||||
|
updateState('connected');
|
||||||
|
} else if (packet.hasListGame()) {
|
||||||
|
listGameSignal.emit(packet.listGame.games);
|
||||||
|
} else if (packet.hasCreateGame()) {
|
||||||
|
gameSignal.emit(packet.createGame.game);
|
||||||
|
} else if (packet.hasJoinGame()) {
|
||||||
|
gameSignal.emit(packet.joinGame.game);
|
||||||
|
} else if (packet.hasLeaveGame()) {
|
||||||
|
gameSignal.emit(null);
|
||||||
|
} else if (packet.hasStartGame()) {
|
||||||
|
gameSignal.emit(packet.startGame.game);
|
||||||
|
} else if (packet.hasUpdateGame()) {
|
||||||
|
gameUpdateSignal.emit(packet.updateGame.changes);
|
||||||
|
} else if (packet.hasGame()) {
|
||||||
|
game.load(packet.game.game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_game(value:NetworkGame):NetworkGame {
|
||||||
|
this.game = value;
|
||||||
|
connection.send(new Request().setGame(new GameRequest()));
|
||||||
|
return this.game;
|
||||||
|
}
|
||||||
|
}
|
||||||
70
src/client/haxe/ru/m/tankz/render/AnimateBundle.hx
Normal file
70
src/client/haxe/ru/m/tankz/render/AnimateBundle.hx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import haxework.gui.utils.BitmapUtil;
|
||||||
|
import haxework.color.Color;
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
import ru.m.tankz.core.Tank;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class AnimateBundle {
|
||||||
|
|
||||||
|
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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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
|
||||||
|
})]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankFrames(tank:Tank):Array<Frame> {
|
||||||
|
var color:Color = switch (tank.hits) {
|
||||||
|
case 1: 0x869C43;
|
||||||
|
case 2: 0xDEAF80;
|
||||||
|
case 3: 0x5EA67A;
|
||||||
|
case _: tank.color;
|
||||||
|
}
|
||||||
|
var colors:Array<Color> = [color, color];
|
||||||
|
if (tank.bonus) {
|
||||||
|
colors[1] = 0xff00aa;
|
||||||
|
}
|
||||||
|
return [for (i in 0...2) ({
|
||||||
|
image: BitmapUtil.colorize(Assets.getBitmapData('resources/image/tank/${tank.config.skin}-${i}.png'), colors[i]),
|
||||||
|
length: 3
|
||||||
|
})];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function bonusFrames(type:BonusType):Array<Frame> {
|
||||||
|
var image = Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||||
|
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||||
|
return [{image: image, length: 15}, {image: empty, length: 15}];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import ru.m.geom.Point;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.animate.OnceAnimate;
|
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import ru.m.tankz.core.EntityType;
|
|
||||||
import ru.m.tankz.render.RenderItem;
|
|
||||||
import ru.m.tankz.engine.Engine;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.text.TextField;
|
||||||
|
import flash.text.TextFormat;
|
||||||
|
import haxe.Timer;
|
||||||
import haxework.gui.SpriteView;
|
import haxework.gui.SpriteView;
|
||||||
|
import haxework.provider.Provider;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.engine.Engine;
|
||||||
|
import ru.m.tankz.render.RenderItem;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class Render extends SpriteView {
|
||||||
class Render extends SpriteView implements EngineListener {
|
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
@@ -31,11 +36,11 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
entryLayer = new Sprite();
|
entryLayer = new Sprite();
|
||||||
upLayer = new Sprite();
|
upLayer = new Sprite();
|
||||||
upperLayer = new Sprite();
|
upperLayer = new Sprite();
|
||||||
contentAsSprite.addChild(backgroundLayer);
|
content.addChild(backgroundLayer);
|
||||||
contentAsSprite.addChild(groundLayer);
|
content.addChild(groundLayer);
|
||||||
contentAsSprite.addChild(entryLayer);
|
content.addChild(entryLayer);
|
||||||
contentAsSprite.addChild(upLayer);
|
content.addChild(upLayer);
|
||||||
contentAsSprite.addChild(upperLayer);
|
content.addChild(upperLayer);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,20 +52,25 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
if (contentSize) {
|
setContentSize(mapWidth, mapHeight);
|
||||||
width = mapWidth;
|
|
||||||
height = mapHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:Engine):Void {
|
public function draw(game:Engine):Void {
|
||||||
for (brick in game.map.bricks) if (brick.config.type > 0) {
|
for (brick in game.map.bricks) if (brick.config.index > 0) {
|
||||||
if (!items.exists(brick.key)) {
|
if (!items.exists(brick.key)) {
|
||||||
items[brick.key] = new BrickItem(brick);
|
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
|
||||||
|
case 'ace' | 'bush': new BrickItem(brick);
|
||||||
|
case 'water': new BrickAnimateItem(brick);
|
||||||
|
case 'armor' | 'brick': new BrickBreakingItem(brick);
|
||||||
|
case x: null;
|
||||||
|
};
|
||||||
|
if (item != null) {
|
||||||
|
items[brick.key] = item;
|
||||||
if (brick.config.layer > 2) {
|
if (brick.config.layer > 2) {
|
||||||
upLayer.addChild(items[brick.key].view);
|
upLayer.addChild(item.view);
|
||||||
} else {
|
} else {
|
||||||
groundLayer.addChild(items[brick.key].view);
|
groundLayer.addChild(item.view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +98,7 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
clearLayer(entryLayer);
|
clearLayer(entryLayer);
|
||||||
clearLayer(groundLayer);
|
clearLayer(groundLayer);
|
||||||
clearLayer(upLayer);
|
clearLayer(upLayer);
|
||||||
|
clearLayer(upperLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function onSpawn(entity:EntityType):Void {
|
||||||
@@ -97,7 +108,7 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
items.set(tank.key, item);
|
items.set(tank.key, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
playTankSpawn(tank.rect.center);
|
playAnimate(tank.rect.center, AnimateBundle.tankSpawn());
|
||||||
case EntityType.BULLET(bullet):
|
case EntityType.BULLET(bullet):
|
||||||
var item = new BulletItem(bullet);
|
var item = new BulletItem(bullet);
|
||||||
items.set(bullet.key, item);
|
items.set(bullet.key, item);
|
||||||
@@ -108,80 +119,79 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
items.set(eagle.key, item);
|
items.set(eagle.key, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
|
case EntityType.BONUS(bonus):
|
||||||
|
var item = new BonusItem(bonus);
|
||||||
|
items.set(bonus.key, item);
|
||||||
|
upperLayer.addChild(item.view);
|
||||||
|
item.update();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
public function onChange(entity:EntityType, change:EntityChange):Void {}
|
||||||
|
|
||||||
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
|
switch [entity, with] {
|
||||||
|
case [EntityType.BULLET(_), EntityType.EAGLE(eagle)]:
|
||||||
|
if (eagle.death) {
|
||||||
|
playAnimate(eagle.rect.center, AnimateBundle.tankBoom());
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onDestroy(entity:EntityType):Void {
|
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
||||||
switch(entity) {
|
switch entity {
|
||||||
case EntityType.TANK(tank):
|
case EntityType.TANK(tank):
|
||||||
if (items.exists(tank.key)) {
|
if (items.exists(tank.key)) {
|
||||||
entryLayer.removeChild(items.get(tank.key).view);
|
entryLayer.removeChild(items.get(tank.key).view);
|
||||||
items.remove(tank.key);
|
items.remove(tank.key);
|
||||||
playTankBoom(tank.rect.center);
|
playAnimate(tank.rect.center, AnimateBundle.tankBoom());
|
||||||
|
if (tank.config.score > 0) {
|
||||||
|
showScore(tank.rect.center, tank.config.score);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case EntityType.BULLET(bullet):
|
case EntityType.BULLET(bullet):
|
||||||
if (items.exists(bullet.key)) {
|
if (items.exists(bullet.key)) {
|
||||||
entryLayer.removeChild(items.get(bullet.key).view);
|
entryLayer.removeChild(items.get(bullet.key).view);
|
||||||
items.remove(bullet.key);
|
items.remove(bullet.key);
|
||||||
playBulletBoom(bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y)));
|
var point = bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y));
|
||||||
|
playAnimate(point, AnimateBundle.bulletBoom());
|
||||||
|
}
|
||||||
|
case EntityType.BONUS(bonus):
|
||||||
|
if (items.exists(bonus.key)) {
|
||||||
|
upperLayer.removeChild(items.get(bonus.key).view);
|
||||||
|
items.remove(bonus.key);
|
||||||
|
if (bonus.config.score > 0) {
|
||||||
|
showScore(bonus.rect.center, bonus.config.score);
|
||||||
}
|
}
|
||||||
case EntityType.EAGLE(eagle):
|
|
||||||
if (items.exists(eagle.key)) {
|
|
||||||
cast(items.get(eagle.key), EagleItem).destoyed = true;
|
|
||||||
items.get(eagle.key).redraw();
|
|
||||||
playTankBoom(eagle.rect.center);
|
|
||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function playTankSpawn(point:Point):Void {
|
private function playAnimate(point:Point, animate:OnceAnimate):Void {
|
||||||
var arr = [
|
|
||||||
0, 1, 2, 3, 3, 4, 5, 5, 6
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/appear/appear-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
animate.x = point.x - animate.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
animate.play().then(function(animate) {
|
animate.play().then(function(animate:Animate):Void {
|
||||||
|
// ToDo: clean animates on reset
|
||||||
|
if (upperLayer.contains(animate)) {
|
||||||
upperLayer.removeChild(animate);
|
upperLayer.removeChild(animate);
|
||||||
|
}
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function playBulletBoom(point:Point):Void {
|
private function showScore(point:Point, score:Int):Void {
|
||||||
var arr = [
|
var view:TextField = new TextField();
|
||||||
0, 1, 1, 0, 0, 1
|
view.embedFonts = true;
|
||||||
];
|
var font:String = Provider.get(IResources).text.get('font');
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/bullet/boom/boom-${i}.png')];
|
view.defaultTextFormat = new TextFormat(font, 28, 0xffffff);
|
||||||
var animate = new OnceAnimate(frames);
|
view.text = Std.string(score);
|
||||||
animate.x = point.x - animate.width / 2;
|
view.x = point.x - view.textWidth / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
view.y = point.y - view.textHeight / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(view);
|
||||||
animate.play().then(function(animate) {
|
Timer.delay(function() upperLayer.removeChild(view), 1000);
|
||||||
upperLayer.removeChild(animate);
|
|
||||||
animate.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playTankBoom(point:Point):Void {
|
|
||||||
var arr = [
|
|
||||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/kaboom/kaboom-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
|
||||||
animate.y = point.y - animate.height / 2;
|
|
||||||
upperLayer.addChild(animate);
|
|
||||||
animate.play().then(function(animate) {
|
|
||||||
upperLayer.removeChild(animate);
|
|
||||||
animate.dispose();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import ru.m.tankz.control.Control;
|
import flash.display.Bitmap;
|
||||||
import flash.display.Sprite;
|
|
||||||
import ru.m.animate.Animate;
|
|
||||||
import ru.m.tankz.core.Eagle;
|
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.Shape;
|
import flash.display.Shape;
|
||||||
import ru.m.geom.Direction;
|
import flash.display.Sprite;
|
||||||
import ru.m.geom.Rectangle;
|
|
||||||
import ru.m.tankz.core.Bullet;
|
|
||||||
import ru.m.tankz.map.Brick;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
import ru.m.tankz.core.Bonus;
|
||||||
|
import ru.m.tankz.core.Bullet;
|
||||||
|
import ru.m.tankz.core.Eagle;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
import flash.display.Bitmap;
|
import ru.m.tankz.map.Brick;
|
||||||
|
import ru.m.tankz.Type.BrickType;
|
||||||
|
|
||||||
typedef TRectangle = {
|
typedef TRectangle = {
|
||||||
var rect(default, null):Rectangle;
|
var rect(default, null):Rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RenderItem<T:TRectangle, D:DisplayObject> {
|
class RenderItem<T:TRectangle, D:DisplayObject> {
|
||||||
|
|
||||||
public var value(default, null):T;
|
public var value(default, null):T;
|
||||||
@@ -34,25 +32,11 @@ class RenderItem<T:TRectangle, D:DisplayObject> {
|
|||||||
|
|
||||||
public function update():Void {
|
public function update():Void {
|
||||||
var rect = value.rect;
|
var rect = value.rect;
|
||||||
view.rotation = calcRotate(rect.direction);
|
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.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;
|
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function calcRotate(direction:Direction):Float {
|
|
||||||
return (if (direction == Direction.RIGHT) {
|
|
||||||
0;
|
|
||||||
} else if (direction == Direction.LEFT) {
|
|
||||||
180;
|
|
||||||
} else if (direction == Direction.TOP) {
|
|
||||||
270;
|
|
||||||
} else if (direction == Direction.BOTTOM) {
|
|
||||||
90;
|
|
||||||
} else {
|
|
||||||
0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {}
|
public function dispose():Void {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,10 +59,50 @@ class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BrickItem extends RenderItem<Brick, Shape> {
|
class BrickItem extends BitmapItem<Brick> {
|
||||||
|
private var type:BrickType;
|
||||||
|
|
||||||
|
public function new(value:Brick) {
|
||||||
|
super(value);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
var t = value.config.type;
|
||||||
|
if (t != type) {
|
||||||
|
type = t;
|
||||||
|
view.visible = t != 'none';
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function getImage():String {
|
||||||
|
return 'resources/image/map/${value.config.type}.png';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BrickAnimateItem extends AnimateItem<Brick> {
|
||||||
|
|
||||||
|
public function new(value:Brick) {
|
||||||
|
super(value);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function redraw():Void {
|
||||||
|
view.frames = [for (i in 0...2) ({
|
||||||
|
image: Assets.getBitmapData('resources/image/map/${value.config.type}-${i}.png'),
|
||||||
|
length: 15
|
||||||
|
})];
|
||||||
|
view.playing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BrickBreakingItem extends RenderItem<Brick, Shape> {
|
||||||
private var broken:Int;
|
private var broken:Int;
|
||||||
private var type:Int;
|
private var type:BrickType;
|
||||||
|
|
||||||
public function new(value:Brick) {
|
public function new(value:Brick) {
|
||||||
super(value);
|
super(value);
|
||||||
@@ -91,7 +115,7 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
|||||||
var g = view.graphics;
|
var g = view.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
if (value.destroyed) return;
|
if (value.destroyed) return;
|
||||||
if (value.config.type > 0) {
|
if (value.config.index > 0) {
|
||||||
g.beginBitmapFill(image);
|
g.beginBitmapFill(image);
|
||||||
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
||||||
for (c in value.cells) {
|
for (c in value.cells) {
|
||||||
@@ -116,7 +140,20 @@ class BrickItem extends RenderItem<Brick, Shape> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getImage():String {
|
private function getImage():String {
|
||||||
return 'resources/images/map/map_${value.config.type}.png';
|
return 'resources/image/map/${value.config.type}.png';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AnimateItem<T:TRectangle> extends RenderItem<T, Animate> {
|
||||||
|
|
||||||
|
public function new(value:T) {
|
||||||
|
super(value);
|
||||||
|
view = new Animate();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function dispose():Void {
|
||||||
|
view.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,68 +162,56 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
|||||||
|
|
||||||
private var type:String;
|
private var type:String;
|
||||||
private var hits:Int;
|
private var hits:Int;
|
||||||
|
private var protected:Bool;
|
||||||
|
private var frozen:Bool;
|
||||||
|
|
||||||
private var tankView:Animate;
|
private var tankView:Animate;
|
||||||
|
private var protectView:Animate;
|
||||||
|
|
||||||
public function new(value:Tank) {
|
public function new(value:Tank) {
|
||||||
super(value);
|
super(value);
|
||||||
view = new Sprite();
|
view = new Sprite();
|
||||||
if (value.playerId.type == Control.HUMAN) {
|
|
||||||
view.addChild(buildHumanMarkView(value));
|
|
||||||
}
|
|
||||||
tankView = new Animate();
|
tankView = new Animate();
|
||||||
view.addChild(tankView);
|
view.addChild(tankView);
|
||||||
|
protectView = AnimateBundle.tankProtect();
|
||||||
|
protectView.visible = false;
|
||||||
|
view.addChild(protectView);
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function buildHumanMarkView(tank:Tank):DisplayObject {
|
|
||||||
var view = new Shape();
|
|
||||||
view.graphics.beginFill(0x00aa00);
|
|
||||||
view.graphics.lineStyle(2, 0x00ff00);
|
|
||||||
view.graphics.drawCircle(0, 0, 23);
|
|
||||||
view.graphics.endFill();
|
|
||||||
view.x = tank.rect.width / 2;
|
|
||||||
view.y = tank.rect.height / 2;
|
|
||||||
view.alpha = 0.2;
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function redraw():Void {
|
override public function redraw():Void {
|
||||||
tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
tankView.frames = AnimateBundle.tankFrames(value);
|
||||||
|
if (value.protect.active) {
|
||||||
|
protectView.x = (tankView.frames[0].image.width - protectView.frames[0].image.width) / 2;
|
||||||
|
protectView.y = (tankView.frames[0].image.height - protectView.frames[0].image.height) / 2;
|
||||||
|
protectView.playing = true;
|
||||||
|
protectView.visible = true;
|
||||||
|
} else {
|
||||||
|
protectView.playing = false;
|
||||||
|
protectView.visible = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFrames():Array<String> {
|
private function getFrames():Array<String> {
|
||||||
var team = value.playerId.team;
|
var frame0 = 'resources/image/tank/${value.config.skin}-0.png';
|
||||||
var group = value.config.group;
|
var frame1 = 'resources/image/tank/${value.config.skin}-1.png';
|
||||||
var index = value.playerId.index;
|
return [frame1, frame0];
|
||||||
if (team == 'radiant') {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
if (team == 'dire') {
|
|
||||||
index = 1;
|
|
||||||
}
|
|
||||||
if (team == 'human' || team == 'radiant' || team == 'dire') {
|
|
||||||
group = 'player';
|
|
||||||
}
|
|
||||||
if (team == 'bot') {
|
|
||||||
index = value.hits;
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-0.png',
|
|
||||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-1.png',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function update():Void {
|
override public function update():Void {
|
||||||
super.update();
|
super.update();
|
||||||
var t = value.config.type;
|
var t = value.config.type;
|
||||||
var h = value.hits;
|
var h = value.hits;
|
||||||
if (t != this.type || h != this.hits) {
|
var p = value.protect.active;
|
||||||
|
var f = value.freezing.active;
|
||||||
|
if (t != type || h != hits || p != protected || f != frozen) {
|
||||||
this.type = t;
|
this.type = t;
|
||||||
this.hits = h;
|
this.hits = h;
|
||||||
|
this.protected = p;
|
||||||
|
this.frozen = f;
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
tankView.playing = (value.mx !=0 || value.my != 0);
|
tankView.playing = !value.freezing.active && (value.mx !=0 || value.my != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function dispose():Void {
|
override public function dispose():Void {
|
||||||
@@ -201,16 +226,46 @@ class TankItem extends RenderItem<Tank, Sprite> {
|
|||||||
class BulletItem extends BitmapItem<Bullet> {
|
class BulletItem extends BitmapItem<Bullet> {
|
||||||
|
|
||||||
override private function getImage():String {
|
override private function getImage():String {
|
||||||
return 'resources/images/bullet/bullet_${value.config.piercing > 1 ? 1 : 0}.png';
|
var type:String = 'normal';
|
||||||
|
if (value.config.piercing > 0) type = 'piercing';
|
||||||
|
return 'resources/image/bullet/${type}.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class EagleItem extends BitmapItem<Eagle> {
|
class EagleItem extends BitmapItem<Eagle> {
|
||||||
|
|
||||||
public var destoyed(default, default):Bool;
|
private var death:Bool;
|
||||||
|
private var protected:Bool;
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
var d = value.death;
|
||||||
|
var p = value.protect.active;
|
||||||
|
if (d != death || p != protected) {
|
||||||
|
death = d;
|
||||||
|
protected = p;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override private function getImage():String {
|
override private function getImage():String {
|
||||||
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
|
var suffix = value.death ? '-death' : value.protect.active ? '-protected' : '';
|
||||||
|
return 'resources/image/eagle/eagle${suffix}.png';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BonusItem extends AnimateItem<Bonus> {
|
||||||
|
|
||||||
|
public function new(value:Bonus) {
|
||||||
|
super(value);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function redraw():Void {
|
||||||
|
var image = Assets.getBitmapData('resources/image/bonus/${value.config.type}.png');
|
||||||
|
view.frames = AnimateBundle.bonusFrames(value.config.type);
|
||||||
|
view.playing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
70
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package ru.m.tankz.sound;
|
||||||
|
|
||||||
|
import openfl.media.Sound;
|
||||||
|
import openfl.utils.Assets;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.engine.Engine;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
|
class 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
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function play(id:String):Void {
|
||||||
|
//L.d(TAG, 'play: ${id}');
|
||||||
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||||
|
if (sound != null) {
|
||||||
|
sound.play();
|
||||||
|
} else {
|
||||||
|
L.w(TAG, 'Sound "${id}" not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onSpawn(entity:EntityType):Void {
|
||||||
|
switch entity {
|
||||||
|
case EntityType.BULLET(_.tank.playerId.team => 'human'):
|
||||||
|
play('shot');
|
||||||
|
case EntityType.BONUS(_):
|
||||||
|
play('bonus_add');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onChange(entity:EntityType, change:EntityChange):Void {
|
||||||
|
switch [entity, change] {
|
||||||
|
case [EntityType.TANK(_), EntityChange.HIT]:
|
||||||
|
play('bullet_hit');
|
||||||
|
//case [EntityType.TANK(_), EntityChange.LIVE_UP]:
|
||||||
|
// play('live');
|
||||||
|
case [EntityType.EAGLE(_), EntityChange.DEATH]:
|
||||||
|
play('boom_player');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
|
switch [entity, with] {
|
||||||
|
case [EntityType.BULLET(_), EntityType.CELL(cell)]:
|
||||||
|
//play('bullet_wall');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDestroy(entity:EntityType, ?playerId:PlayerId):Void {
|
||||||
|
switch entity {
|
||||||
|
case EntityType.TANK(_):
|
||||||
|
play('boom_bot');
|
||||||
|
case EntityType.BONUS(_):
|
||||||
|
play('bonus_get');
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user