Compare commits
78 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 |
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
|
||||||
|
|||||||
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
|
||||||
140
build/client.js
140
build/client.js
@@ -1,140 +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, values) => function build() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().openfl({
|
|
||||||
command: 'build',
|
|
||||||
platform: platform,
|
|
||||||
version: version,
|
|
||||||
debug: argv.dev,
|
|
||||||
values: values
|
|
||||||
}))
|
|
||||||
.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:html5-dom'] = gulp.series(prepare(Haxe.ID), generate(), build('html5', {dom:true}));
|
|
||||||
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 = (dom) => function() {
|
|
||||||
return gulp.series(
|
|
||||||
build('html5', {dom:dom}),
|
|
||||||
() => 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:html5-dom:test'] = gulp.series(prepare(Haxe.ID), testHtml5(true));
|
|
||||||
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
|
|
||||||
129
gulpfile.js
129
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
44
package.json
44
package.json
@@ -1,43 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.7.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": "1.1.2"
|
"yield": "2.0.0",
|
||||||
|
"haxe-crypto": "0.0.7",
|
||||||
|
"svg": "1.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
project.xml
30
project.xml
@@ -1,30 +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"/>
|
|
||||||
<haxelib name="yield" version="1.1.2"/>
|
|
||||||
<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"/>-->
|
|
||||||
<haxeflag name="--macro" value="yield.parser.Parser.auto()"/>
|
|
||||||
<!--<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,17 +0,0 @@
|
|||||||
package ru.m.draw;
|
|
||||||
|
|
||||||
import flash.geom.ColorTransform;
|
|
||||||
import flash.geom.Rectangle;
|
|
||||||
import flash.display.BitmapData;
|
|
||||||
|
|
||||||
|
|
||||||
class BitmapUtil {
|
|
||||||
|
|
||||||
public static function colorize(data: BitmapData, color: Color):BitmapData {
|
|
||||||
if (color.zero) return data;
|
|
||||||
var result = data.clone();
|
|
||||||
var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0);
|
|
||||||
result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package ru.m.draw;
|
|
||||||
|
|
||||||
abstract Color(Int) {
|
|
||||||
public var alpha(get, never):Int;
|
|
||||||
public var red(get, never):Int;
|
|
||||||
public var green(get, never):Int;
|
|
||||||
public var blue(get, never):Int;
|
|
||||||
public var zero(get, never):Bool;
|
|
||||||
|
|
||||||
public inline function new(value:Int) {
|
|
||||||
this = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_alpha():Int {
|
|
||||||
return (this >> 24) & 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_red():Int {
|
|
||||||
return (this >> 16) & 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_green():Int {
|
|
||||||
return (this >> 8) & 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_blue():Int {
|
|
||||||
return this & 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_zero():Bool {
|
|
||||||
return this == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:from
|
|
||||||
static public inline function fromInt(value:Int):Color {
|
|
||||||
return new Color(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@:from
|
|
||||||
static public inline function fromString(value:String):Color {
|
|
||||||
return new Color(Std.parseInt('0x${value.split('#').pop()}'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toString():String {
|
|
||||||
return 'Color(${red},${green},${blue})';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,41 +1,21 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.Lib;
|
||||||
|
import haxework.animate.Animate;
|
||||||
|
import ru.m.tankz.frame.StartFrame;
|
||||||
|
import flash.ui.Keyboard;
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.text.Font;
|
import flash.text.Font;
|
||||||
import flash.ui.Keyboard;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
|
||||||
import haxework.gui.Root;
|
import haxework.gui.Root;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.log.TraceLogger;
|
import haxework.log.TraceLogger;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import haxework.resources.IResources;
|
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.frame.StartFrame;
|
|
||||||
import ru.m.tankz.game.ClassicGame;
|
|
||||||
import ru.m.tankz.game.DotaGame;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.PacketBuilder;
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
|
||||||
#if flash import haxework.log.JSLogger; #end
|
#if flash import haxework.log.JSLogger; #end
|
||||||
#if debug import haxework.log.SocketLogger; #end
|
#if debug import haxework.log.SocketLogger; #end
|
||||||
|
|
||||||
|
class Client {
|
||||||
interface ClientViewLayout {
|
|
||||||
var switcher(default, null):IFrameSwitcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml')
|
|
||||||
class ClientView extends VGroupView implements ClientViewLayout implements ViewBuilder {}
|
|
||||||
|
|
||||||
class Client implements IConnectionHandler {
|
|
||||||
|
|
||||||
private static inline var TAG = 'Tankz';
|
private static inline var TAG = 'Tankz';
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
@@ -44,69 +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();
|
||||||
|
Init.init();
|
||||||
|
Animate.bind(Lib.current.stage);
|
||||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
new Client();
|
Style.register();
|
||||||
}
|
var view:ClientView = new ClientView();
|
||||||
|
|
||||||
|
|
||||||
private var view:ClientView;
|
|
||||||
|
|
||||||
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 ClientView();
|
|
||||||
Provider.set(IFrameSwitcher, view.switcher);
|
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.content.stage.stageFocusRect = false;
|
view.launch();
|
||||||
//view.logout.onPress = this;
|
}
|
||||||
|
}
|
||||||
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
|
||||||
if (event.keyCode == Keyboard.ESCAPE) {
|
@:template class ClientView extends VGroupView {
|
||||||
view.switcher.change(StartFrame.ID);
|
private static inline var TAG = 'Tankz';
|
||||||
}
|
|
||||||
});
|
@:view private var switcher(default, null):FrameSwitcher;
|
||||||
|
@:provide var resources:IResources;
|
||||||
Provider.setFactory(IConfigBundle, ConfigBundle);
|
|
||||||
Provider.setFactory(ILevelBundle, LevelBundle);
|
public function init():Void {
|
||||||
Provider.setFactory(SaveStorage, SaveStorage);
|
var font:Font = Font.enumerateFonts()[0];
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
resources.text.put('font', 'Bookman Old Style');
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||||
|
Provider.set(FrameSwitcher, switcher);
|
||||||
view.switcher.change(StartFrame.ID);
|
}
|
||||||
}
|
|
||||||
|
public function launch():Void {
|
||||||
public function onPress(view:ButtonView):Void {
|
content.stage.stageFocusRect = false;
|
||||||
switch (view.id) {
|
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
case 'logout':
|
if (event.keyCode == Keyboard.ESCAPE) {
|
||||||
Provider.get(IConnection).disconnect();
|
switcher.change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
public function onConnected():Void {}
|
|
||||||
|
|
||||||
public function onDisconnected():Void {
|
|
||||||
//view.switcher.change(AuthFrame.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onError(error:Dynamic):Void {
|
|
||||||
L.e(TAG, '', error);
|
|
||||||
//view.switcher.change(AuthFrame.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +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/image/ui/background.png"
|
|
||||||
fillType: REPEAT
|
|
||||||
views:
|
|
||||||
- id: start
|
|
||||||
$type: ru.m.tankz.frame.StartFrame
|
|
||||||
- id: level
|
|
||||||
$type: ru.m.tankz.frame.LevelFrame
|
|
||||||
- id: game
|
|
||||||
$type: ru.m.tankz.frame.GameFrame
|
|
||||||
- $type: haxework.gui.LabelView
|
|
||||||
$style: label
|
|
||||||
inLayout: false
|
|
||||||
contentSize: true
|
|
||||||
vAlign: BOTTOM
|
|
||||||
hAlign: RIGHT
|
|
||||||
text: "@res:text:version"
|
|
||||||
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)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
button:
|
|
||||||
width: 250
|
|
||||||
height: 60
|
|
||||||
skin:
|
|
||||||
$type: haxework.gui.skin.ButtonBitmapSkin
|
|
||||||
upImage: "@asset:image:resources/image/ui/button/normal.png"
|
|
||||||
downImage: "@asset:image:resources/image/ui/button/down.png"
|
|
||||||
overImage: "@asset:image:resources/image/ui/button/over.png"
|
|
||||||
fillType: NINEPATH
|
|
||||||
fontFamily: "@res:text:font"
|
|
||||||
fontEmbed: true
|
|
||||||
fontColor: "#E7E0BB"
|
|
||||||
fontSize: 20
|
|
||||||
|
|
||||||
label:
|
|
||||||
fontColor: "#ffffff"
|
|
||||||
fontEmbed: false
|
|
||||||
fontFamily: Courirer New
|
|
||||||
fontSize: 16
|
|
||||||
shadowColor: 0x000000
|
|
||||||
@@ -1,30 +1,22 @@
|
|||||||
package ru.m.tankz.bundle;
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import yaml.Parser;
|
import yaml.Parser;
|
||||||
import yaml.Yaml;
|
import yaml.Yaml;
|
||||||
|
|
||||||
|
|
||||||
typedef ConfigSource = {
|
|
||||||
var game:GameConfig;
|
|
||||||
var map: MapConfig;
|
|
||||||
var bricks: Array<BrickConfig>;
|
|
||||||
var presets: Array<GamePreset>;
|
|
||||||
var points: Array<SpawnPoint>;
|
|
||||||
var tanks: Array<TankConfig>;
|
|
||||||
var bonuses: Array<BonusConfig>;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConfigBundle implements IConfigBundle {
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
|
||||||
private static function convert(raw:Dynamic):ConfigSource {
|
private var _cache:Map<GameType, Config> = new Map();
|
||||||
return raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get(type:GameType):Config {
|
public function get(type:GameType):Config {
|
||||||
var source = convert(Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()));
|
if (!_cache.exists(type)) {
|
||||||
return new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses);
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,22 +5,23 @@ import flash.events.KeyboardEvent;
|
|||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.tankz.control.ActionConfig;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
typedef KeyBinding = Map<Int, TankAction>;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -81,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}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
package ru.m.tankz.frame;
|
|
||||||
|
|
||||||
import flash.events.Event;
|
|
||||||
import haxe.ds.Option;
|
|
||||||
import haxe.Timer;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
|
||||||
import haxework.gui.LabelView;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import protohx.Message;
|
|
||||||
import ru.m.connect.IConnection;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.game.GameSave;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
|
||||||
import ru.m.tankz.render.Render;
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
|
||||||
|
|
||||||
|
|
||||||
interface GameFrameLayout {
|
|
||||||
var state(default, null):LabelView;
|
|
||||||
var render(default, null):Render;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml")
|
|
||||||
class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout {
|
|
||||||
|
|
||||||
private static inline var TAG = "GameFrame";
|
|
||||||
|
|
||||||
public static inline var ID = "game";
|
|
||||||
|
|
||||||
private var game:Game;
|
|
||||||
private var timer:Timer;
|
|
||||||
|
|
||||||
public function init():Void {}
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
start(Provider.get(GameSave));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function start(save:GameSave):Void {
|
|
||||||
game = Provider.build(Game, save.state.type);
|
|
||||||
if (game == null) {
|
|
||||||
throw 'Unsupported game type "${save.state.type}"';
|
|
||||||
}
|
|
||||||
game.engine.listeners.push(render);
|
|
||||||
game.start(save).then(onGameStateChange).endThen(onGameComplete);
|
|
||||||
content.addEventListener(Event.ENTER_FRAME, redraw);
|
|
||||||
//Provider.get(IConnection).packetHandler.addListener(this);
|
|
||||||
render.draw(game.engine);
|
|
||||||
timer = new Timer(10);
|
|
||||||
timer.run = updateEngine;
|
|
||||||
state.text = stateString(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function stop():Void {
|
|
||||||
//Provider.get(IConnection).packetHandler.removeListener(this);
|
|
||||||
if (timer != null) {
|
|
||||||
timer.stop();
|
|
||||||
timer = null;
|
|
||||||
}
|
|
||||||
content.removeEventListener(Event.ENTER_FRAME, redraw);
|
|
||||||
if (game != null) {
|
|
||||||
game.dispose();
|
|
||||||
game = null;
|
|
||||||
}
|
|
||||||
render.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function stateString(game:Game):String {
|
|
||||||
if (game.state == null) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
var result:Array<String> = [];
|
|
||||||
result.push('Level: ${game.state.level}');
|
|
||||||
for (team in game.teams) {
|
|
||||||
if (game.state.loser == team.id) {
|
|
||||||
result.push('${team.id}: LOSE');
|
|
||||||
} else if (team.life > -1) {
|
|
||||||
result.push('${team.id}: ${team.life}');
|
|
||||||
} else {
|
|
||||||
for (player in team.players) {
|
|
||||||
if (player.life > -1) {
|
|
||||||
result.push('${player.id.team}${player.id.index}: ${player.life}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '[ ${result.join(' | ')} ]';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameStateChange(s:GameState):GameState {
|
|
||||||
state.text = stateString(game);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameComplete(result:Option<GameState>):Void {
|
|
||||||
switch (result) {
|
|
||||||
case Option.Some(s):
|
|
||||||
state.text = stateString(game);
|
|
||||||
case Option.None:
|
|
||||||
}
|
|
||||||
switch (game.next()) {
|
|
||||||
case Option.Some(s):
|
|
||||||
var save = game.save();
|
|
||||||
Provider.get(SaveStorage).write(save);
|
|
||||||
stop();
|
|
||||||
start(save);
|
|
||||||
case Option.None:
|
|
||||||
Provider.get(IFrameSwitcher).change(StartFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onHide():Void {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateEngine():Void {
|
|
||||||
game.engine.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function redraw(_):Void {
|
|
||||||
render.draw(game.engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onGameUpdateResponse(packet:GameUpdateResponse):Void {
|
|
||||||
//engine.updateFromChanges(packet.changes);
|
|
||||||
render.draw(game.engine);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPacket(packet:Message):Void {}
|
|
||||||
}
|
|
||||||
@@ -1,12 +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,36 +0,0 @@
|
|||||||
package ru.m.tankz.frame;
|
|
||||||
|
|
||||||
import ru.m.tankz.game.GameSave;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
|
||||||
import haxework.gui.list.ListView;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
|
|
||||||
|
|
||||||
interface LevelFrameLayout {
|
|
||||||
var levels(default, null):ListView<Int>;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/LevelFrame.yaml", "ru/m/tankz/Style.yaml")
|
|
||||||
class LevelFrame extends VGroupView implements ViewBuilder implements LevelFrameLayout {
|
|
||||||
public static inline var ID = "level";
|
|
||||||
|
|
||||||
public function init():Void {
|
|
||||||
levels.dispatcher.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
var state:GameState = Provider.get(GameSave).state;
|
|
||||||
var c = Provider.get(IConfigBundle).get(state.type).game.levels;
|
|
||||||
levels.data = [for (i in 0...c) i];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onListItemClick(item:IListItemView<Int>):Void {
|
|
||||||
Provider.get(GameSave).state.level = item.data;
|
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
pWidth: 100
|
|
||||||
pHeight: 100
|
|
||||||
views:
|
|
||||||
- id: levels
|
|
||||||
$type: haxework.gui.list.VListView<Int>
|
|
||||||
factory: "@class:ru.m.tankz.frame.level.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: "#000000"
|
|
||||||
alpha: 0
|
|
||||||
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
|
||||||
@@ -1,70 +1,29 @@
|
|||||||
package ru.m.tankz.frame;
|
package ru.m.tankz.frame;
|
||||||
|
|
||||||
import ru.m.tankz.storage.SaveStorage;
|
import ru.m.tankz.frame.classic.ClassicLevelFrame;
|
||||||
import ru.m.tankz.game.GameSave;
|
import ru.m.tankz.frame.dota.DotaLevelFrame;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
import haxework.gui.ViewBuilder;
|
import ru.m.tankz.storage.SaveStorage;
|
||||||
import haxework.provider.Provider;
|
|
||||||
import ru.m.tankz.game.ClassicGame;
|
|
||||||
import ru.m.tankz.game.DotaGame;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
|
@:template class StartFrame extends VGroupView {
|
||||||
|
|
||||||
interface StartFrameLayout {
|
public static var ID(default, never):String = "start";
|
||||||
var classic_1p(default, null):ButtonView;
|
|
||||||
var classic_2p(default, null):ButtonView;
|
|
||||||
var classic_load(default, null):ButtonView;
|
|
||||||
var dota_1p(default, null):ButtonView;
|
|
||||||
var dota_2p_coop(default, null):ButtonView;
|
|
||||||
var dota_2p_vs(default, null):ButtonView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:template("ru/m/tankz/frame/StartFrame.yaml", "ru/m/tankz/Style.yaml")
|
@:provide var frameSwitcher:FrameSwitcher;
|
||||||
class StartFrame extends VGroupView implements ViewBuilder implements StartFrameLayout {
|
@:provide var storage:SaveStorage;
|
||||||
|
|
||||||
public static inline var ID = "start";
|
|
||||||
|
|
||||||
public function init():Void {
|
|
||||||
classic_1p.onPress = this;
|
|
||||||
classic_2p.onPress = this;
|
|
||||||
classic_load.onPress = this;
|
|
||||||
dota_1p.onPress = this;
|
|
||||||
dota_2p_coop.onPress = this;
|
|
||||||
dota_2p_vs.onPress = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onShow():Void {
|
|
||||||
classic_load.visible = Provider.get(SaveStorage).read(ClassicGame.TYPE) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
public function onPress(view:ButtonView):Void {
|
||||||
switch (view.id) {
|
switch (view.id) {
|
||||||
case 'classic_1p':
|
case 'classic':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER1);
|
frameSwitcher.change(ClassicLevelFrame.ID);
|
||||||
case 'classic_2p':
|
case 'dota':
|
||||||
startGame(ClassicGame.TYPE, ClassicGame.PLAYER2);
|
frameSwitcher.change(DotaLevelFrame.ID);
|
||||||
case 'classic_load':
|
case 'network':
|
||||||
loadGame(ClassicGame.TYPE);
|
//frameSwitcher.change(NetworkFrame.ID);
|
||||||
case 'dota_1p':
|
case 'settings':
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER1);
|
frameSwitcher.change(SettingsFrame.ID);
|
||||||
case 'dota_2p_coop':
|
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_COOP);
|
|
||||||
case 'dota_2p_vs':
|
|
||||||
startGame(DotaGame.TYPE, DotaGame.PLAYER2_VS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function startGame(type:GameType, presetId:PresetId):Void {
|
|
||||||
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
|
|
||||||
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadGame(type:GameType):Void {
|
|
||||||
var save:GameSave = Provider.get(SaveStorage).read(type);
|
|
||||||
Provider.set(GameSave, save);
|
|
||||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,45 @@
|
|||||||
---
|
---
|
||||||
pWidth: 100
|
geometry.size.stretch: true
|
||||||
pHeight: 100
|
layout.hAlign: center
|
||||||
|
layout.vAlign: middle
|
||||||
views:
|
views:
|
||||||
- $type: haxework.gui.ImageView
|
- $type: haxework.gui.ImageView
|
||||||
image: "@asset:image:resources/image/ui/logo.png"
|
image: $asset:image:resources/image/ui/logo.png
|
||||||
contentSize: true
|
geometry.margin.bottom: 15
|
||||||
bottomMargin: 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
|
- $type: haxework.gui.LabelView
|
||||||
$style: label
|
skinId: text
|
||||||
fontSize: 20
|
geometry.position: absolute
|
||||||
topMargin: 15
|
geometry.margin.right: 10
|
||||||
contentSize: true
|
geometry.margin.bottom: 10
|
||||||
text: Classic
|
geometry.vAlign: bottom
|
||||||
- id: classic_1p
|
geometry.hAlign: right
|
||||||
|
text: $r:text:version
|
||||||
|
- id: settings
|
||||||
$type: haxework.gui.ButtonView
|
$type: haxework.gui.ButtonView
|
||||||
text: 1 Player
|
geometry.position: absolute
|
||||||
$style: button
|
geometry.margin.left: 10
|
||||||
- id: classic_2p
|
geometry.margin.bottom: 10
|
||||||
$type: haxework.gui.ButtonView
|
geometry.vAlign: bottom
|
||||||
text: 2 Player
|
geometry.hAlign: left
|
||||||
$style: button
|
skinId: button.settings
|
||||||
- id: classic_load
|
+onPress: $this:onPress
|
||||||
$type: haxework.gui.ButtonView
|
|
||||||
text: Load
|
|
||||||
$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
|
|
||||||
|
|||||||
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.frame.level;
|
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("ru/m/tankz/frame/level/LevelView.yaml", "ru/m/tankz/Style.yaml")
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import ru.m.draw.BitmapUtil;
|
import haxework.gui.utils.BitmapUtil;
|
||||||
import ru.m.draw.Color;
|
import haxework.color.Color;
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
@@ -9,7 +9,6 @@ import ru.m.animate.OnceAnimate;
|
|||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
|
||||||
class AnimateBundle {
|
class AnimateBundle {
|
||||||
|
|
||||||
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
||||||
|
|||||||
@@ -3,16 +3,21 @@ package ru.m.tankz.render;
|
|||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
|
import flash.text.TextField;
|
||||||
|
import flash.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.Animate;
|
||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.Engine;
|
||||||
import ru.m.tankz.render.RenderItem;
|
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,10 +52,7 @@ 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 {
|
||||||
@@ -96,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 {
|
||||||
@@ -125,7 +128,7 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onChange(entity:EntityType, ?change:EntityChange):Void {}
|
public function onChange(entity:EntityType, change:EntityChange):Void {}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||||
switch [entity, with] {
|
switch [entity, with] {
|
||||||
@@ -137,13 +140,16 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
playAnimate(tank.rect.center, AnimateBundle.tankBoom());
|
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)) {
|
||||||
@@ -156,6 +162,9 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
if (items.exists(bonus.key)) {
|
if (items.exists(bonus.key)) {
|
||||||
upperLayer.removeChild(items.get(bonus.key).view);
|
upperLayer.removeChild(items.get(bonus.key).view);
|
||||||
items.remove(bonus.key);
|
items.remove(bonus.key);
|
||||||
|
if (bonus.config.score > 0) {
|
||||||
|
showScore(bonus.rect.center, bonus.config.score);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
@@ -166,8 +175,23 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
animate.play().then(function(animate:Animate):Void {
|
animate.play().then(function(animate:Animate):Void {
|
||||||
upperLayer.removeChild(animate);
|
// ToDo: clean animates on reset
|
||||||
|
if (upperLayer.contains(animate)) {
|
||||||
|
upperLayer.removeChild(animate);
|
||||||
|
}
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function showScore(point:Point, score:Int):Void {
|
||||||
|
var view:TextField = new TextField();
|
||||||
|
view.embedFonts = true;
|
||||||
|
var font:String = Provider.get(IResources).text.get('font');
|
||||||
|
view.defaultTextFormat = new TextFormat(font, 28, 0xffffff);
|
||||||
|
view.text = Std.string(score);
|
||||||
|
view.x = point.x - view.textWidth / 2;
|
||||||
|
view.y = point.y - view.textHeight / 2;
|
||||||
|
upperLayer.addChild(view);
|
||||||
|
Timer.delay(function() upperLayer.removeChild(view), 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import flash.display.Shape;
|
|||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.core.Bonus;
|
import ru.m.tankz.core.Bonus;
|
||||||
import ru.m.tankz.core.Bullet;
|
import ru.m.tankz.core.Bullet;
|
||||||
@@ -15,7 +14,6 @@ import ru.m.tankz.core.Tank;
|
|||||||
import ru.m.tankz.map.Brick;
|
import ru.m.tankz.map.Brick;
|
||||||
import ru.m.tankz.Type.BrickType;
|
import ru.m.tankz.Type.BrickType;
|
||||||
|
|
||||||
|
|
||||||
typedef TRectangle = {
|
typedef TRectangle = {
|
||||||
var rect(default, null):Rectangle;
|
var rect(default, null):Rectangle;
|
||||||
}
|
}
|
||||||
@@ -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 {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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 _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import flash.net.SharedObject;
|
import flash.net.SharedObject;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.game.GameSave;
|
|
||||||
|
|
||||||
|
|
||||||
class SaveStorage {
|
class SaveStorage {
|
||||||
@@ -15,19 +15,19 @@ class SaveStorage {
|
|||||||
so = SharedObject.getLocal('tankz');
|
so = SharedObject.getLocal('tankz');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read(type:GameType):Null<GameSave> {
|
public function read(type:GameType):Null<GameState> {
|
||||||
var data:String = Reflect.getProperty(so.data, type);
|
var data:String = Reflect.getProperty(so.data, type);
|
||||||
L.d(TAG, 'read: ${data}');
|
L.d(TAG, 'read: ${data}');
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
return GameSave.fromYaml(data);
|
return GameState.fromYaml(data);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(save:GameSave):Void {
|
public function write(save:GameState):Void {
|
||||||
var data:String = save.toYaml();
|
var data:String = save.toYaml();
|
||||||
L.d(TAG, 'write: ${data}');
|
L.d(TAG, 'write: ${data}');
|
||||||
so.setProperty(save.state.type, data);
|
so.setProperty(save.type, data);
|
||||||
so.flush();
|
so.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx
Normal file
67
src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import flash.net.SharedObject;
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
|
import ru.m.tankz.control.Control.TankAction;
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsStorage {
|
||||||
|
|
||||||
|
private static var TAG(default, never):String = 'SettingsStorage';
|
||||||
|
|
||||||
|
private var so:SharedObject;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
so = SharedObject.getLocal('settings');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read(index: Int):Null<ActionConfig> {
|
||||||
|
var data:String = Reflect.getProperty(so.data, Std.string(index));
|
||||||
|
L.d(TAG, 'read: ${data}');
|
||||||
|
if (data != null) {
|
||||||
|
try {
|
||||||
|
return ActionConfig.loads(data);
|
||||||
|
} catch (error:Dynamic) {
|
||||||
|
L.w(TAG, "read", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getDefault(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function write(index: Int, data: ActionConfig):Void {
|
||||||
|
L.d(TAG, 'write: ${data}');
|
||||||
|
so.setProperty(Std.string(index), data.dumps());
|
||||||
|
so.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDefault(index: Int): ActionConfig {
|
||||||
|
return (defaults.exists(index) ? defaults.get(index) : empty).clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static var defaults: Map<Int, ActionConfig> = [
|
||||||
|
0 => new ActionConfig([
|
||||||
|
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
||||||
|
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
||||||
|
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
||||||
|
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
||||||
|
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
||||||
|
]),
|
||||||
|
1 => new ActionConfig([
|
||||||
|
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
||||||
|
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
||||||
|
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
||||||
|
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
||||||
|
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
|
||||||
|
private static var empty: ActionConfig = new ActionConfig([
|
||||||
|
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
||||||
|
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
||||||
|
{action:TankAction.SHOT, key:-1},
|
||||||
|
]);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user