Compare commits
219 Commits
0.3.0
...
event_prot
| Author | SHA1 | Date | |
|---|---|---|---|
| 59e9ced333 | |||
| 94b3a94cbb | |||
| caab6ba3a3 | |||
| 7f70c49b87 | |||
| 8f50da64c2 | |||
| 982ca09a23 | |||
| dbf30decae | |||
| abd1b834d7 | |||
| 6ad9076987 | |||
| 78bbf5264e | |||
| 4c8ae66624 | |||
| 5a3d5b974e | |||
| fb9a28c126 | |||
| 7115ea8ac2 | |||
| 01417f5bbd | |||
| abf944418e | |||
| c7946ef1da | |||
| 241499bc2d | |||
| 74297dd9c7 | |||
| 31cb20bf85 | |||
| 1d95de02e1 | |||
| ba13111a8e | |||
| 94b19a1c26 | |||
| 50a0cee044 | |||
| 26ad5f47cd | |||
| 864d5f3335 | |||
| 4b426183e8 | |||
| a5722dfa9d | |||
| 7984d8282c | |||
| 17823ede11 | |||
| 5db3ae1af0 | |||
| bbe2aeb7fb | |||
| 09b188cf24 | |||
| 11f8fc6190 | |||
| 96e608c36f | |||
| 3c116db135 | |||
| efe826110c | |||
| c1ff14111d | |||
| cd7dd1984b | |||
| 686c659c84 | |||
| 797dfca2be | |||
| aa10825b12 | |||
| 608ed3acc4 | |||
| 03b461f082 | |||
| cbb28f4158 | |||
| 13240677b0 | |||
| b0ae85334b | |||
| 183c6c16f1 | |||
| a7f286dc42 | |||
| 20b60009e3 | |||
| d6b572aead | |||
| d11d0ac53f | |||
| ab02460b11 | |||
| fc18e2e0b7 | |||
| 363a48bb1b | |||
| e9de677ceb | |||
| 5ff7b19475 | |||
| 7ddba8f69b | |||
| b86e0ddd20 | |||
| a3f3de3af5 | |||
| 4a4ca463c3 | |||
| 13d01293f6 | |||
| d0104e4361 | |||
| c3db9f2414 | |||
| f34d35e03a | |||
| 9868d27bc3 | |||
| c0b4b2a4c1 | |||
| 9dc0a4ce06 | |||
| c58735ea43 | |||
| 4e2b65c225 | |||
| 663935bd75 | |||
| d1ed17d1d7 | |||
| 135ad0d992 | |||
| 8fb1d6132d | |||
| f60feea6e8 | |||
| d7b7744eb8 | |||
| 2eb606aa21 | |||
| a86c4fc447 | |||
| 1ea216fd20 | |||
| 121c470b00 | |||
| 404dd77806 | |||
| d2f23e7777 | |||
| fd0e2382d0 | |||
| e609dafedc | |||
| a948dfbaad | |||
| 5b804c6902 | |||
| 556cd2f1a9 | |||
| 7d570336a5 | |||
| a9b591a7ca | |||
| 216e1aa476 | |||
| 4d8de90419 | |||
| 0b17fbf804 | |||
| c6639e11b1 | |||
| e6f9aa8ba1 | |||
| 2c191d932c | |||
| d52b94d095 | |||
| c67385576e | |||
| f09e70c5f8 | |||
| 0f5cf7fdc5 | |||
| 426b2718bb | |||
| 8ea862a118 | |||
| 1f87a71833 | |||
| 56c2cd9437 | |||
| 85e5f9a553 | |||
| d9915120d4 | |||
| 4863f37eef | |||
| c9ec4395ee | |||
| b62956cc95 | |||
| b2ba4362fe | |||
| 7cca35195d | |||
| d4a9c720d6 | |||
| d2383fc4f0 | |||
| 74322ca6a4 | |||
| a6323edb36 | |||
| 2d4c56d04c | |||
| e3d3359019 | |||
| 2aa1c82aea | |||
| 45af6c2a50 | |||
| d6cf708035 | |||
| 085431fe73 | |||
| 95148a9b0b | |||
| a24d610b05 | |||
| f8bba85eb4 | |||
| 80f2ac25ad | |||
| 17e4f1f172 | |||
| af5aa6b8e6 | |||
| 1fd1c669a0 | |||
| 122c54a0de | |||
| ac1df9a9a4 | |||
| d0c796aab2 | |||
| 17289fde92 | |||
| 7d27f0cd35 | |||
| a64463ddc6 | |||
| 007621c48c | |||
| 33b0693a4e | |||
| 13c1299bf0 | |||
| fbdf018422 | |||
| 8800fe48ee | |||
| 2be44de710 | |||
| 9269bde518 | |||
| 4c8181b3ea | |||
| 61852ab47e | |||
| 914a4dcf3b | |||
| 8f3fb4474c | |||
| 08ef40b736 | |||
| 0048d6fc92 | |||
| caae1216d0 | |||
| 2255a806b9 | |||
| 0eb150eb8b | |||
| 01f811ebd2 | |||
| c70eed8a06 | |||
| b12b26b87e | |||
| 836eebaf11 | |||
| 92a2628e90 | |||
| d2360fde25 | |||
| c603753226 | |||
| c8448b7848 | |||
| 6d2a1a002b | |||
| f6ebec32ca | |||
| 7a57f22967 | |||
| dd2c1eb9d2 | |||
| e657fb16bd | |||
| f7bf5e2b0e | |||
| 51f07bd330 | |||
| 2183c0710c | |||
| e9212a889d | |||
| 0d4ac4e3e5 | |||
| df99ff817a | |||
| 2705afc327 | |||
| 5330be142c | |||
| 73c46d821e | |||
| 0565eec871 | |||
| d895fb70f7 | |||
| 45fab2c0b5 | |||
| 634f5ad2d0 | |||
| 34e5ac2b9e | |||
| 336896b37e | |||
| c9698f1f5c | |||
| dd447656f8 | |||
| db2339ab3a | |||
| 8d3308d74a | |||
| 22e7965442 | |||
| 2e856c1256 | |||
| 5b04242aab | |||
| a127777e49 | |||
| 11aea59cf8 | |||
| 5456a01551 | |||
| a93a67161d | |||
| 52a4e44e47 | |||
| 79039ae79e | |||
| 1ae84cf5a8 | |||
| 032fa0c0ad | |||
| 1f8b43ba5d | |||
| 4fc0ae103e | |||
| bd86412d83 | |||
| 592e59e01f | |||
| 05b6fe4a56 | |||
| f68e5d160f | |||
| d279d52b09 | |||
| a1ed498bf5 | |||
| 41c5610f9a | |||
| 5c57454998 | |||
| a7effef412 | |||
| dd1014e230 | |||
| 89ac9fd225 | |||
| 3096fba7c5 | |||
| baf696a3e1 | |||
| 5daf4fafc7 | |||
| db59377cb2 | |||
| 1f6e4fbc3d | |||
| db5b805276 | |||
| 38538b9147 | |||
| 15d830a0d4 | |||
| feb5bafe72 | |||
| b36fd77d74 | |||
| 421f925a60 | |||
| ad4744cfef | |||
| 1c9ccf0fb8 | |||
| e0ceff68f9 |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Editor configuration, see http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
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
|
||||||
|
|||||||
77
WORK.md
77
WORK.md
@@ -1,46 +1,73 @@
|
|||||||
* build
|
* build
|
||||||
* gulp 100%
|
* gulp 100%
|
||||||
|
* linux 100%
|
||||||
|
* deb-package 100%
|
||||||
|
* windows 0%
|
||||||
|
* exe-package 0% (inno setup)
|
||||||
|
|
||||||
* deploy
|
* deploy
|
||||||
* capistrano 100%
|
* capistrano 100%
|
||||||
|
|
||||||
* ui
|
* ui
|
||||||
* login frame
|
* auth frame 0%
|
||||||
* select person frame (autoselect)
|
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
||||||
* game mode frame (single, start server, find server)
|
* select level frame 10%
|
||||||
* game frame
|
* game frame 50%
|
||||||
|
|
||||||
* engine
|
* engine
|
||||||
* config 90%
|
* config 100%
|
||||||
* map 80%
|
* map 100%
|
||||||
* tanks 30%
|
* tanks 100%
|
||||||
* bullets 30%
|
* bullets 100%
|
||||||
* boxes 0%
|
* boxes 100%
|
||||||
* map changes 50%
|
* map changes 100%
|
||||||
* bonuses 0%
|
* bonuses 100%
|
||||||
* eagle 0%
|
* eagle 100%
|
||||||
|
|
||||||
* game
|
* game
|
||||||
* classic
|
* classic
|
||||||
* state 0%
|
* state 50%
|
||||||
* bot 5%
|
* bot 50%
|
||||||
* player: 50%
|
* human 100%
|
||||||
|
* dota
|
||||||
|
* state 50%
|
||||||
|
* bot 10%
|
||||||
|
* human 100%
|
||||||
|
|
||||||
|
* bonus
|
||||||
|
* star 50%
|
||||||
|
* grenade 0%
|
||||||
|
* helm 0%
|
||||||
|
* clock 0%
|
||||||
|
* shovel 0%
|
||||||
|
|
||||||
|
* state
|
||||||
|
* score 0%
|
||||||
|
* human tank 0%
|
||||||
|
* save/load 0%
|
||||||
|
* export/import 0%
|
||||||
|
|
||||||
* render
|
* render
|
||||||
* map 100%
|
* map 100%
|
||||||
* tanks 100%
|
* tanks 100%
|
||||||
* bullet 100%
|
* bullet 100%
|
||||||
* calc redraw 20%
|
* calc redraw 50%
|
||||||
* animations
|
* animations
|
||||||
* tank spawn
|
* tank spawn 0%
|
||||||
* bullet boom
|
* tank move 100%
|
||||||
* tank boom
|
* map water 100%
|
||||||
* bonuses
|
* bullet boom 90%
|
||||||
* html5
|
* tank boom 90%
|
||||||
|
* bonuses 100%
|
||||||
|
* html5 50%
|
||||||
|
|
||||||
* proto
|
* proto
|
||||||
|
...
|
||||||
|
|
||||||
|
* editor
|
||||||
* webapp
|
* level
|
||||||
* angular app 0%
|
* open 100%
|
||||||
* google analytics 0%
|
* edit 50%
|
||||||
|
* save 100%
|
||||||
|
* tank
|
||||||
|
* color 10%
|
||||||
11
ansible/ansible.cfg
Normal file
11
ansible/ansible.cfg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[defaults]
|
||||||
|
hash_behaviour = merge
|
||||||
|
host_key_checking = False
|
||||||
|
#callback_whitelist = profile_tasks
|
||||||
|
display_skipped_hosts = False
|
||||||
|
stdout_callback = yaml
|
||||||
|
bin_ansible_callbacks = True
|
||||||
|
|
||||||
|
[ssh_connection]
|
||||||
|
pipelining = True
|
||||||
|
ssh_args = -o ForwardAgent=yes
|
||||||
14
ansible/deploy.yml
Normal file
14
ansible/deploy.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
vars:
|
||||||
|
ansible_user: "{{ deploy_user }}"
|
||||||
|
roles:
|
||||||
|
- ansible-deploy
|
||||||
|
- build
|
||||||
|
post_tasks:
|
||||||
|
- include_role:
|
||||||
|
name: ansible-deploy
|
||||||
|
tasks_from: complete.yml
|
||||||
|
- include_role:
|
||||||
|
name: service
|
||||||
|
tasks_from: restart.yml
|
||||||
2
ansible/dev/inventory.yml
Normal file
2
ansible/dev/inventory.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
hosts: localhost
|
||||||
15
ansible/group_vars/all.yml
Normal file
15
ansible/group_vars/all.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
project_name: tankz
|
||||||
|
project_user: holop
|
||||||
|
|
||||||
|
deploy_user: "{{ project_user }}"
|
||||||
|
deploy_project: "{{ project_name }}"
|
||||||
|
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||||
|
deploy_repo_version: master
|
||||||
|
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 --host shmyga.ru"
|
||||||
|
args:
|
||||||
|
chdir: "{{ deploy_release_dir }}"
|
||||||
6
ansible/roles/service/defaults/main.yml
Normal file
6
ansible/roles/service/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
service_name: null
|
||||||
|
service_description: "{{ service_name }} service"
|
||||||
|
service_work_dir: null
|
||||||
|
service_command: null
|
||||||
|
service_user: null
|
||||||
|
service_control_user: null
|
||||||
21
ansible/roles/service/tasks/main.yml
Normal file
21
ansible/roles/service/tasks/main.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: "Install {{ service_name }} systemd unit file"
|
||||||
|
template:
|
||||||
|
src: "template/service.j2"
|
||||||
|
dest: "/etc/systemd/system/{{ service_name }}.service"
|
||||||
|
|
||||||
|
- name: "Start {{ service_name }} service"
|
||||||
|
systemd:
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
name: "{{ service_name }}"
|
||||||
|
daemon_reload: yes
|
||||||
|
|
||||||
|
- name: "Add sudoers record for {{ service_name }} service"
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/sudoers.d/{{ service_name }}
|
||||||
|
state: present
|
||||||
|
create: yes
|
||||||
|
regexp: "^{{ service_control_user }} ALL="
|
||||||
|
line: "{{ service_control_user }} ALL= NOPASSWD: /bin/systemctl * {{ service_name }}"
|
||||||
|
validate: "/usr/sbin/visudo -cf %s"
|
||||||
11
ansible/roles/service/tasks/restart.yml
Normal file
11
ansible/roles/service/tasks/restart.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
# - name: "Restart {{ service_name }} service"
|
||||||
|
# systemd:
|
||||||
|
# enabled: yes
|
||||||
|
# state: restarted
|
||||||
|
# name: "{{ service_name }}"
|
||||||
|
|
||||||
|
- name: "Restart {{ service_name }} service"
|
||||||
|
command: "sudo /bin/systemctl restart {{ service_name }}"
|
||||||
|
args:
|
||||||
|
warn: no
|
||||||
15
ansible/roles/service/template/service.j2
Normal file
15
ansible/roles/service/template/service.j2
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description={{ service_description }}
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
PIDFile=/var/run/{{ service_name }}.pid
|
||||||
|
WorkingDirectory={{ service_work_dir }}
|
||||||
|
User={{ service_user }}
|
||||||
|
Group={{ service_user }}
|
||||||
|
ExecStart={{ service_command }}
|
||||||
|
TimeoutSec=300
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
3
ansible/roles/setup/tasks/apt.yml
Normal file
3
ansible/roles/setup/tasks/apt.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
- name: "Install neko package"
|
||||||
|
apt:
|
||||||
|
name: neko
|
||||||
2
ansible/roles/setup/tasks/main.yml
Normal file
2
ansible/roles/setup/tasks/main.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- import_tasks: apt.yml
|
||||||
|
when: ansible_distribution|lower == 'ubuntu'
|
||||||
1
ansible/roles/user/keys/shmyga.pub
Normal file
1
ansible/roles/user/keys/shmyga.pub
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCot1zSeqj7Tj5/7aNMzXAuXQPPxudYFV9z6M03dPijh2bXyHDcXk53xUO8XY5R4GyLhvAn98axbPM++urKY8BXuQqAG36soI7iZJ/KcPY1EKDwVBeZneFC/wMc8HMT0hj9+uHcGAMtmklIgPPkawzLxbEh6oAY4H8Vvz08qyco6suYB5NjkpFwVMf9Xa2Fj8rTodKpPRDBh/Xk+5bh11RKL6b9WcwuwpKU8zl2qZiqNfjr0H+sKEk7ohcYvzSCltLdKJcoKbiCcnrnBJT5/JpGWeAbA2MMmvmt/dJrHykd1CbmXW2DuG4tIlwMb5xU739PoKCePctK1retb8TrWOLT shmyga@shmyga-desktop
|
||||||
40
ansible/roles/user/tasks/main.yml
Normal file
40
ansible/roles/user/tasks/main.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# barin
|
||||||
|
- name: Make barin group
|
||||||
|
group:
|
||||||
|
name: barin
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Make barin user
|
||||||
|
user:
|
||||||
|
name: barin
|
||||||
|
group: barin
|
||||||
|
password: '$6$mbw5KZWwtrRUy$eFcMNTW.QzG1Em45r5hZf/qri4hKAHImozWuW4/pYnDK.tOrVKrXTKYfRDtYEFRgCgVVg0zuPvyq/xn0KiKlz0'
|
||||||
|
groups: www-data,sudo,adm
|
||||||
|
|
||||||
|
- name: Set up authorized_keys for the barin user
|
||||||
|
authorized_key:
|
||||||
|
user: barin
|
||||||
|
key: '{{ item }}'
|
||||||
|
with_file:
|
||||||
|
- keys/shmyga.pub
|
||||||
|
|
||||||
|
|
||||||
|
# holop
|
||||||
|
- name: Make holop group
|
||||||
|
group:
|
||||||
|
name: holop
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Make holop user
|
||||||
|
user:
|
||||||
|
name: holop
|
||||||
|
group: holop
|
||||||
|
password: '$6$B/7g0xlcXFCIHk$hzSjb8KLll7YrTsp3z640sxNixNAkLpm6UUdZgWPh0Ffy7Ue18AiXTzkDdGTaTH6Woz4kvgVDSggnKGTU6u03.'
|
||||||
|
groups: www-data
|
||||||
|
|
||||||
|
- name: Set up authorized_keys for the holop user
|
||||||
|
authorized_key:
|
||||||
|
user: holop
|
||||||
|
key: '{{ item }}'
|
||||||
|
with_file:
|
||||||
|
- keys/shmyga.pub
|
||||||
1
ansible/roles/user/vars/main.yml
Normal file
1
ansible/roles/user/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ansible_become: yes
|
||||||
8
ansible/service.yml
Normal file
8
ansible/service.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
vars:
|
||||||
|
ansible_user: "{{ deploy_user }}"
|
||||||
|
tasks:
|
||||||
|
- include_role:
|
||||||
|
name: service
|
||||||
|
tasks_from: restart.yml
|
||||||
16
ansible/setup.yml
Normal file
16
ansible/setup.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
- hosts:
|
||||||
|
- all
|
||||||
|
pre_tasks:
|
||||||
|
- include_role:
|
||||||
|
name: ansible-deploy
|
||||||
|
tasks_from: facts.yml
|
||||||
|
roles:
|
||||||
|
- geerlingguy.nodejs
|
||||||
|
- setup
|
||||||
|
- service
|
||||||
|
vars:
|
||||||
|
nodejs_version: 9.x
|
||||||
|
nodejs_npm_global_packages: [gulp-cli]
|
||||||
|
vars_files:
|
||||||
|
- vars/barin.yml
|
||||||
4
ansible/user.yml
Normal file
4
ansible/user.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
- hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
roles:
|
||||||
|
- user
|
||||||
4
ansible/vars/barin.yml
Normal file
4
ansible/vars/barin.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
ansible_user: barin
|
||||||
|
ansible_become_pass: 1234!QAZ
|
||||||
|
ansible_become: yes
|
||||||
137
build/client.js
137
build/client.js
@@ -1,137 +0,0 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const concat = require('gulp-concat');
|
|
||||||
const uglify = require('gulp-uglify');
|
|
||||||
const babel = require('gulp-babel');
|
|
||||||
const template = require('gulp-template');
|
|
||||||
const yargs = require('yargs');
|
|
||||||
const Haxe = require('../tasks/haxe');
|
|
||||||
const FlashPlayer = require('../tasks/flashplayer');
|
|
||||||
const version = require('./version');
|
|
||||||
const prepare = require('./prepare');
|
|
||||||
const debug = require('../tasks/debug');
|
|
||||||
const webserver = require('gulp-webserver');
|
|
||||||
const run = require('gulp-run');
|
|
||||||
const tail = require('../tasks/tail');
|
|
||||||
const deb = require('gulp-debian');
|
|
||||||
|
|
||||||
|
|
||||||
const generate = () => function generate() {
|
|
||||||
return new Haxe().haxelib([
|
|
||||||
'run', 'protohx', 'generate', 'protohx.json'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const build = (platform) => function build() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().openfl({
|
|
||||||
command: 'build',
|
|
||||||
platform: platform,
|
|
||||||
version: version,
|
|
||||||
debug: argv.dev,
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(`target/${platform}`));
|
|
||||||
};
|
|
||||||
|
|
||||||
const flashIndex = function() {
|
|
||||||
return gulp.src('src/client/html/index.html')
|
|
||||||
.pipe(template({
|
|
||||||
scripts: ['app.min.js'],
|
|
||||||
swf: 'tankz.swf'
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest('target/flash'))
|
|
||||||
};
|
|
||||||
|
|
||||||
const flashJs = function() {
|
|
||||||
const src = [
|
|
||||||
'src/client/html/js/*.js'
|
|
||||||
];
|
|
||||||
return gulp.src(src)
|
|
||||||
.pipe(babel({presets: ['es2015']}))
|
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(concat('app.min.js'))
|
|
||||||
.pipe(gulp.dest('target/flash'))
|
|
||||||
};
|
|
||||||
|
|
||||||
const webapp = function () {
|
|
||||||
return gulp.src('src/webapp/*').pipe(gulp.dest('target'));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const buildDeb = gulp.series(
|
|
||||||
() => gulp.src('src/client/debian/**/*').pipe(gulp.dest('target/debian')),
|
|
||||||
() => gulp.src('target/linux/**/*').pipe(gulp.dest('target/debian/usr/share/tankz')),
|
|
||||||
() => gulp.src('target/debian/*')
|
|
||||||
.pipe(deb({
|
|
||||||
package: 'tankz',
|
|
||||||
version: version,
|
|
||||||
section: 'base',
|
|
||||||
priority: 'optional',
|
|
||||||
architecture: 'all',
|
|
||||||
maintainer: 'shmyga <shmyga.z@gmail.com>',
|
|
||||||
description: 'Tank\'z',
|
|
||||||
changelog: [],
|
|
||||||
postinst: [
|
|
||||||
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
|
|
||||||
' update-menus\n' +
|
|
||||||
'fi'
|
|
||||||
],
|
|
||||||
_target: '/',
|
|
||||||
_out: 'target',
|
|
||||||
_clean: false,
|
|
||||||
_verbose: true
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
exports['client:flash:html'] = gulp.parallel(flashIndex, flashJs);
|
|
||||||
exports['client:flash'] = gulp.series(prepare(Haxe.ID), generate(), build('flash'), exports['client:flash:html']);
|
|
||||||
exports['client:html5'] = gulp.series(prepare(Haxe.ID), generate(), build('html5'));
|
|
||||||
exports['client:linux'] = gulp.series(prepare(Haxe.ID), generate(), build('linux'));
|
|
||||||
exports['client:webapp'] = webapp;
|
|
||||||
exports['client:deb'] = buildDeb;
|
|
||||||
exports['client'] = gulp.series(
|
|
||||||
prepare(Haxe.ID),
|
|
||||||
generate(),
|
|
||||||
gulp.parallel(build('flash'), build('html5'), build('linux')),
|
|
||||||
exports['client:flash:html'],
|
|
||||||
webapp,
|
|
||||||
buildDeb,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const testFlash = function() {
|
|
||||||
const argv = yargs.argv;
|
|
||||||
return build('flash')()
|
|
||||||
.pipe(new FlashPlayer().run(argv.dev))
|
|
||||||
.pipe(debug());
|
|
||||||
};
|
|
||||||
|
|
||||||
const testHtml5 = function() {
|
|
||||||
return gulp.series(
|
|
||||||
build('html5'),
|
|
||||||
() => gulp.src('target/html5').pipe(webserver({
|
|
||||||
host: 'localhost', port: 3000,
|
|
||||||
open: true,
|
|
||||||
fallback: 'index.html'
|
|
||||||
}))
|
|
||||||
)();
|
|
||||||
};
|
|
||||||
|
|
||||||
const testLinux = gulp.series(
|
|
||||||
build('linux'),
|
|
||||||
() => gulp.src('target/linux/tankz')
|
|
||||||
.pipe(run('./tankz', {cwd: 'target/linux', verbosity: 1}))
|
|
||||||
.pipe(tail(debug.log))
|
|
||||||
.pipe(gulp.dest('target/log'))
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports['client:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
|
||||||
exports['client:html5:test'] = gulp.series(prepare(Haxe.ID), testHtml5);
|
|
||||||
exports['client:linux:test'] = gulp.series(prepare(Haxe.ID), testLinux);
|
|
||||||
exports['client:test'] = exports['client:flash:test'];
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,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
|
|
||||||
2
gen.sh
2
gen.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
haxelib run protohx generate protohx.json
|
haxelib run protohx generate protohx.json
|
||||||
haxelib run orm mysql://shmyga:xkbp8jh9z2@localhost:3306/armageddon \
|
haxelib run orm mysql://shmyga:password@localhost:3306/armageddon \
|
||||||
-s src-gen/haxe \
|
-s src-gen/haxe \
|
||||||
-c ru.m.tankz.db \
|
-c ru.m.tankz.db \
|
||||||
-a ru.m.tankz.db
|
-a ru.m.tankz.db
|
||||||
168
gulpfile.js
168
gulpfile.js
@@ -1,35 +1,159 @@
|
|||||||
"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');
|
||||||
//FlashPlayer.VERSION = '25.0.0.171';
|
const dateformat = require('dateformat');
|
||||||
|
const argv = require('yargs').argv;
|
||||||
|
|
||||||
|
// ToDo: update default in gulp-haxetool
|
||||||
|
FlashPlayer.VERSION = '32';
|
||||||
|
//Haxe.VERSION = '4.0.0-rc.2';
|
||||||
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/server');
|
* window exe package (innosetup)
|
||||||
|
*/
|
||||||
|
const config = new Project.Config({
|
||||||
|
meta: {
|
||||||
|
title: 'Tank\'z',
|
||||||
|
filename: 'tankz',
|
||||||
|
icon: 'src/client/resources/icon.png',
|
||||||
|
pack: 'ru.m.tankz',
|
||||||
|
author: 'shmyga <shmyga.z@gmail.com>',
|
||||||
|
company: 'MegaLoMania',
|
||||||
|
version: packageInfo.version,
|
||||||
|
},
|
||||||
|
libs: packageInfo.haxeDependencies,
|
||||||
|
sources: [
|
||||||
|
'src/common/haxe',
|
||||||
|
'src-gen/haxe',
|
||||||
|
],
|
||||||
|
assets: [
|
||||||
|
'src/common/resources'
|
||||||
|
],
|
||||||
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
|
],
|
||||||
|
macros: [
|
||||||
|
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = argv.host || 'localhost';
|
||||||
|
const port = argv.port || 5000;
|
||||||
|
|
||||||
exports.default = gulp.series(exports.clean, exports.client);
|
/**
|
||||||
|
* 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',
|
||||||
|
preloader: 'ru.m.tankz.Preloader',
|
||||||
|
assets: [
|
||||||
|
'src/client/resources',
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
width: 1024,
|
||||||
|
height: 768,
|
||||||
|
},
|
||||||
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
|
//'dom',
|
||||||
|
//'dev_layout',
|
||||||
|
//'bitmap_text',
|
||||||
|
],
|
||||||
|
macros: [
|
||||||
|
`CompilationOption.set('host','${host}')`,
|
||||||
|
`CompilationOption.set('port',${port})`,
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
module.exports.generate
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* editor
|
||||||
|
*/
|
||||||
|
const editor = new Project(
|
||||||
|
Project.BuildSystem.OPENFL,
|
||||||
|
[
|
||||||
|
Project.Platform.FLASH,
|
||||||
|
Project.Platform.HTML5,
|
||||||
|
],
|
||||||
|
config.branch({
|
||||||
|
name: 'editor',
|
||||||
|
sources: ['src/client/haxe', 'src/editor/haxe'],
|
||||||
|
main: 'ru.m.tankz.editor.Editor',
|
||||||
|
preloader: 'ru.m.tankz.Preloader',
|
||||||
|
assets: [
|
||||||
|
'src/client/resources',
|
||||||
|
'src/editor/resources',
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
filename: 'editor',
|
||||||
|
width: 1024,
|
||||||
|
height: 850,
|
||||||
|
},
|
||||||
|
flags: [
|
||||||
|
//'dev_layout',
|
||||||
|
]
|
||||||
|
})
|
||||||
|
).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',
|
||||||
|
}),
|
||||||
|
module.exports.generate
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default
|
||||||
|
*/
|
||||||
|
module.exports.default = gulp.series(
|
||||||
|
exports.clean,
|
||||||
|
module.exports['client:flash:build'],
|
||||||
|
module.exports['client:flash:html'],
|
||||||
|
module.exports['client:html5:build'],
|
||||||
|
module.exports['client:linux:build'],
|
||||||
|
module.exports['client:linux:deb'],
|
||||||
|
//module.exports['client:android:build'],
|
||||||
|
|
||||||
|
module.exports['editor:flash:build'],
|
||||||
|
module.exports['editor:flash:html'],
|
||||||
|
module.exports['editor:html5:build'],
|
||||||
|
|
||||||
|
module.exports['server:neko:build'],
|
||||||
|
);
|
||||||
|
|||||||
6719
package-lock.json
generated
Normal file
6719
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
63
package.json
63
package.json
@@ -1,41 +1,26 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.3.0",
|
"version": "0.14.2",
|
||||||
"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.19",
|
||||||
"fancy-log": "^1.3.2",
|
"yargs": "^13.2.4"
|
||||||
"fs-extra": "^5.0.0",
|
},
|
||||||
"got": "^8.0.1",
|
"haxeDependencies": {
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||||
"gulp-babel": "^7.0.0",
|
"lime": "7.5.0",
|
||||||
"gulp-clean": "^0.3.2",
|
"openfl": "8.9.1",
|
||||||
"gulp-concat": "^2.6.1",
|
"hxcpp": "4.0.8",
|
||||||
"gulp-debian": "^0.1.9",
|
"promhx": "1.1.0",
|
||||||
"gulp-run": "^1.7.1",
|
"protohx": "0.4.6",
|
||||||
"gulp-template": "^5.0.0",
|
"yaml": "1.3.0",
|
||||||
"gulp-uglify": "^3.0.0",
|
"orm": "2.1.0",
|
||||||
"gulp-webserver": "^0.9.1",
|
"yield": "2.0.0",
|
||||||
"plugin-error": "^0.1.2",
|
"haxe-crypto": "0.0.7",
|
||||||
"progress": "^2.0.0",
|
"svg": "1.1.2"
|
||||||
"promise-streams": "^2.1.1",
|
}
|
||||||
"tar": "^4.2.0",
|
|
||||||
"tmp-file": "^2.0.1",
|
|
||||||
"unzip-stream": "^0.2.1",
|
|
||||||
"vinyl-fs": "^3.0.1",
|
|
||||||
"yargs": "^10.0.3"
|
|
||||||
},
|
|
||||||
"haxeDependencies": {
|
|
||||||
"lime": "6.0.1",
|
|
||||||
"openfl": "7.0.0",
|
|
||||||
"promhx": "1.1.0",
|
|
||||||
"protohx": "0.4.6",
|
|
||||||
"yaml": "1.3.0",
|
|
||||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
|
||||||
"orm": "2.1.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
23
project.xml
23
project.xml
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<project>
|
|
||||||
<meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/>
|
|
||||||
<app main="ru.m.tankz.Client" path="target" file="tankz"/>
|
|
||||||
<source path="src/common/haxe"/>
|
|
||||||
<source path="src/client/haxe"/>
|
|
||||||
<source path="src-gen/haxe"/>
|
|
||||||
<assets path="src/client/resources" rename="resources" include="*"/>
|
|
||||||
<haxelib name="lime" version="6.0.1"/>
|
|
||||||
<haxelib name="openfl" version="7.0.0"/>
|
|
||||||
<haxelib name="promhx" version="1.1.0"/>
|
|
||||||
<haxelib name="protohx" version="0.4.6"/>
|
|
||||||
<haxelib name="haxework" version="git"/>
|
|
||||||
<haxelib name="yaml" version="1.3.0"/>
|
|
||||||
<window fps="30"/>
|
|
||||||
<window width="1024" height="768" unless="html5"/>
|
|
||||||
<haxeflag name="-D" value="swf-gpu"/>
|
|
||||||
<haxeflag name="-D" value="native-trace"/>
|
|
||||||
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
|
||||||
<haxeflag name="-dce" value="no"/>
|
|
||||||
<haxeflag name="-D" value="dom"/>
|
|
||||||
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
|
||||||
</project>
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"protoFiles": [
|
"protoFiles": [
|
||||||
"src/common/proto/core.proto",
|
"src/common/proto/core.proto",
|
||||||
"src/common/proto/game.proto",
|
"src/common/proto/game.proto",
|
||||||
|
"src/common/proto/room.proto",
|
||||||
"src/common/proto/pack.proto"
|
"src/common/proto/pack.proto"
|
||||||
],
|
],
|
||||||
"cleanOut": true,
|
"cleanOut": true,
|
||||||
|
|||||||
BIN
resources/11756.png
Normal file
BIN
resources/11756.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
resources/60016.png
Normal file
BIN
resources/60016.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
@@ -1,9 +0,0 @@
|
|||||||
[Desktop Entry]
|
|
||||||
Encoding=UTF-8
|
|
||||||
Type=Application
|
|
||||||
Comment=Tank'z game
|
|
||||||
Exec=bash -c 'cd "/usr/share/tankz" && ./tankz'
|
|
||||||
Icon=/usr/share/tankz/resources/images/tank/player/tank_p3_0-0.png
|
|
||||||
Name=Tank'z
|
|
||||||
Categories=Game
|
|
||||||
Terminal=false
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "state", "@type": "haxework.gui.LabelView", "@style": "label",
|
|
||||||
"pWidth": 100, "height": 20
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "render", "@type": "ru.m.tankz.render.Render",
|
|
||||||
"contentSize": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id":"levels", "@type":"haxework.gui.list.VListView<Int>",
|
|
||||||
"factory": "@class:ru.m.tankz.view.frames.list.LevelView",
|
|
||||||
"pWidth":100,
|
|
||||||
"pHeight":100,
|
|
||||||
"paddings":10,
|
|
||||||
"scroll":{
|
|
||||||
"@type":"haxework.gui.list.VScrollView",
|
|
||||||
"width":10, "pHeight":100,
|
|
||||||
"skin":{"@type":"haxework.gui.list.VScrollSkin"}
|
|
||||||
},
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000", "alpha": 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.ImageView",
|
|
||||||
"image": "@asset:image:resources/images/logo/logo.png",
|
|
||||||
"contentSize": true, "bottomMargin": 15
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "start_1p",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "1 Player",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "start_2p",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "2 Player",
|
|
||||||
"@style": "button"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "dota",
|
|
||||||
"@type": "haxework.gui.ButtonView",
|
|
||||||
"text": "DotA",
|
|
||||||
"@style": "button"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"@type": "haxework.gui.VGroupView",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher",
|
|
||||||
"pWidth": 100, "pHeight": 100,
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.BitmapSkin",
|
|
||||||
"image": "@asset:image:resources/images/background.png",
|
|
||||||
"fillType": "REPEAT"
|
|
||||||
},
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "start",
|
|
||||||
"@type": "ru.m.tankz.view.frames.StartFrame"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "level",
|
|
||||||
"@type": "ru.m.tankz.view.frames.LevelFrame"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "game",
|
|
||||||
"@type": "ru.m.tankz.view.frames.GameFrame"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "haxework.gui.LabelView",
|
|
||||||
"inLayout": false,
|
|
||||||
"contentSize": true,
|
|
||||||
"vAlign": "BOTTOM",
|
|
||||||
"hAlign": "RIGHT",
|
|
||||||
"text": "@res:text:version",
|
|
||||||
"@style": "label"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"level": {
|
|
||||||
"width": 440, "height": 44,
|
|
||||||
"margins": 5,
|
|
||||||
"views": [
|
|
||||||
{
|
|
||||||
"id": "label",
|
|
||||||
"@type": "haxework.gui.LabelView",
|
|
||||||
"pWidth": 100, "pHeight": 100, "text": "",
|
|
||||||
"@style": "label"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000", "alpha": 0.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"button": {
|
|
||||||
"width":250, "height":60,
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ButtonBitmapSkin",
|
|
||||||
"upImage": "@asset:image:resources/images/control/button_normal.png",
|
|
||||||
"downImage": "@asset:image:resources/images/control/button_down.png",
|
|
||||||
"overImage": "@asset:image:resources/images/control/button_over.png",
|
|
||||||
"fillType": "NINEPATH"
|
|
||||||
},
|
|
||||||
"fontFamily":"@res:text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20
|
|
||||||
},
|
|
||||||
|
|
||||||
"label": {
|
|
||||||
"fontColor": "0xffffff",
|
|
||||||
"fontEmbed": false,
|
|
||||||
"fontFamily": "@res:text:fontName",
|
|
||||||
"fontSize": 16,
|
|
||||||
"shadowColor": "0x000000"
|
|
||||||
},
|
|
||||||
|
|
||||||
"input": {
|
|
||||||
"fontColor": "0xffffff",
|
|
||||||
"fontEmbed": false,
|
|
||||||
"fontFamily": "@res:text:fontName",
|
|
||||||
"fontSize": 16,
|
|
||||||
"shadowColor": "0x000000",
|
|
||||||
"skin": {
|
|
||||||
"@type": "haxework.gui.skin.ColorSkin",
|
|
||||||
"color": "0x000000"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,11 @@ import flash.display.Bitmap;
|
|||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
|
|
||||||
|
|
||||||
|
typedef Frame = {
|
||||||
|
var image:BitmapData;
|
||||||
|
var length:Int;
|
||||||
|
}
|
||||||
|
|
||||||
class Animate extends Bitmap {
|
class Animate extends Bitmap {
|
||||||
|
|
||||||
private static var timer:Timer;
|
private static var timer:Timer;
|
||||||
@@ -26,24 +31,30 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var a = new BitmapData(1, 1);
|
|
||||||
|
|
||||||
public var playing(default, set):Bool;
|
public var playing(default, set):Bool;
|
||||||
public var frames(default, set):Array<BitmapData>;
|
public var frames(default, set):Array<Frame>;
|
||||||
|
|
||||||
|
private var sequence:Array<BitmapData>;
|
||||||
private var index:Int;
|
private var index:Int;
|
||||||
|
|
||||||
public function new(?frames:Array<BitmapData>) {
|
public function new(?frames:Array<Frame>) {
|
||||||
super(null, PixelSnapping.AUTO, true);
|
super(null, PixelSnapping.AUTO, true);
|
||||||
this.frames = frames == null ? [] : frames;
|
this.frames = frames == null ? [] : frames;
|
||||||
init();
|
init();
|
||||||
instances.push(this);
|
instances.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_frames(value:Array<BitmapData>):Array<BitmapData> {
|
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||||
|
sequence = [];
|
||||||
|
index = 0;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
frames = value;
|
frames = value;
|
||||||
bitmapData = frames[0];
|
for (frame in frames) {
|
||||||
index = 0;
|
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||||
|
}
|
||||||
|
bitmapData = sequence[0];
|
||||||
|
} else {
|
||||||
|
bitmapData = null;
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
@@ -56,10 +67,10 @@ class Animate extends Bitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function update():Void {
|
private function update():Void {
|
||||||
if (++index >= frames.length) {
|
if (++index >= sequence.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
var nextBitmapData = frames[index];
|
var nextBitmapData = sequence[index];
|
||||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||||
bitmapData = nextBitmapData;
|
bitmapData = nextBitmapData;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.animate;
|
package ru.m.animate;
|
||||||
|
|
||||||
import promhx.Deferred;
|
import promhx.Deferred;
|
||||||
import flash.display.BitmapData;
|
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
|
|
||||||
|
|
||||||
@@ -9,10 +8,6 @@ class OnceAnimate extends Animate {
|
|||||||
|
|
||||||
private var deferred:Deferred<Animate>;
|
private var deferred:Deferred<Animate>;
|
||||||
|
|
||||||
public function new(frames:Array<BitmapData>) {
|
|
||||||
super(frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function play():Promise<Animate> {
|
public function play():Promise<Animate> {
|
||||||
deferred = new Deferred();
|
deferred = new Deferred();
|
||||||
playing = true;
|
playing = true;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package ru.m.display;
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import flash.display.DisplayObjectContainer;
|
||||||
|
|
||||||
|
class DisplayObjectContainerExtender {
|
||||||
|
|
||||||
|
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||||
|
if (self.contains(child)) {
|
||||||
|
return self.removeChild(child);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
45
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package ru.m.skin;
|
||||||
|
|
||||||
|
import format.SVG;
|
||||||
|
import haxework.color.Color;
|
||||||
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.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)));
|
||||||
|
svgs.set(ButtonState.DISABLED, buildSVG(ColorUtil.grey(color)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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,100 +1,39 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import ru.m.tankz.game.ClassicGame;
|
import flash.Lib;
|
||||||
import ru.m.tankz.game.DotaGame;
|
import haxework.animate.Animate;
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import flash.ui.Keyboard;
|
|
||||||
import flash.events.KeyboardEvent;
|
|
||||||
import flash.text.Font;
|
|
||||||
import ru.m.tankz.view.frames.StartFrame;
|
|
||||||
import haxework.log.SocketLogger;
|
|
||||||
import haxework.resources.Resources;
|
|
||||||
import haxework.resources.IResources;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.ViewBuilder;
|
|
||||||
import haxework.gui.ButtonView;
|
|
||||||
import ru.m.tankz.PacketBuilder;
|
|
||||||
import haxework.log.JSLogger;
|
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
|
||||||
import haxework.provider.Provider;
|
|
||||||
import haxework.gui.frame.FrameSwitcher;
|
|
||||||
import haxework.gui.Root;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.connect.IConnection;
|
|
||||||
import haxework.log.TraceLogger;
|
import haxework.log.TraceLogger;
|
||||||
|
import haxework.view.Root;
|
||||||
|
import ru.m.tankz.view.ClientView;
|
||||||
|
|
||||||
@:template("layout/main.json", "layout/styles.json")
|
class Client {
|
||||||
class MainView extends VGroupView 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() {
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
#if flash
|
#if flash
|
||||||
L.push(new JSLogger());
|
L.push(new haxework.log.JSLogger());
|
||||||
#end
|
#end
|
||||||
#if debug
|
#if debug
|
||||||
L.push(new SocketLogger());
|
//L.push(new haxework.log.SocketLogger());
|
||||||
#end
|
#end
|
||||||
Const.init();
|
Const.init();
|
||||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
Init.init();
|
||||||
L.i(TAG, "Version: " + Const.VERSION);
|
Animate.bind(Lib.current.stage);
|
||||||
L.i(TAG, "Build: " + Const.BUILD);
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
new Client();
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
}
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
|
#if linux
|
||||||
|
LinuxIcon.apply();
|
||||||
private var view:MainView;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
Provider.setFactory(IResources, Resources);
|
|
||||||
|
|
||||||
var font:Font = Font.enumerateFonts()[0];
|
|
||||||
Provider.get(IResources).text.put("font", "Bookman Old Style");
|
|
||||||
Provider.get(IResources).text.put("version", 'v${Const.VERSION} b${Const.BUILD}');
|
|
||||||
|
|
||||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
|
||||||
#if flash
|
|
||||||
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection("localhost", 5001));
|
|
||||||
#elseif html5
|
|
||||||
Provider.set(IConnection, new ru.m.connect.js.JsConnection("localhost", 5001));
|
|
||||||
#end
|
#end
|
||||||
|
Style.register();
|
||||||
//Provider.get(IConnection).handler.addListener(this);
|
var view:ClientView = new ClientView();
|
||||||
view = new MainView();
|
|
||||||
Provider.set(IFrameSwitcher, view.switcher);
|
|
||||||
Root.bind(view);
|
Root.bind(view);
|
||||||
view.content.stage.stageFocusRect = false;
|
view.launch();
|
||||||
//view.logout.onPress = this;
|
|
||||||
view.switcher.change(StartFrame.ID);
|
|
||||||
|
|
||||||
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
#if debug
|
||||||
if (event.keyCode == Keyboard.ESCAPE) {
|
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||||
view.switcher.change(StartFrame.ID);
|
Lib.current.addChild(fps);
|
||||||
}
|
#end
|
||||||
});
|
|
||||||
|
|
||||||
Provider.setFactory(Game, ClassicGame, ClassicGame.TYPE);
|
|
||||||
Provider.setFactory(Game, DotaGame, DotaGame.TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onPress(view:ButtonView):Void {
|
|
||||||
switch (view.id) {
|
|
||||||
case "logout":
|
|
||||||
Provider.get(IConnection).disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,16 @@ package ru.m.tankz;
|
|||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import flash.system.Capabilities;
|
import flash.system.Capabilities;
|
||||||
|
|
||||||
|
|
||||||
class Const {
|
class Const {
|
||||||
public static var FPS:Int;
|
public static var FPS:Int;
|
||||||
public static var BUILD:String;
|
public static var BUILD:String;
|
||||||
public static var VERSION:String;
|
public static var VERSION:String;
|
||||||
public static var DEBUG:Bool;
|
public static var DEBUG:Bool;
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
FPS = 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 haxework.animate.FadeAnimate;
|
||||||
|
import haxework.animate.UnFadeAnimate;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.resources.Resources;
|
||||||
|
import haxework.view.popup.PopupManager;
|
||||||
|
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.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.GameStorage;
|
||||||
|
import ru.m.tankz.storage.NetworkStorage;
|
||||||
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
|
||||||
|
class Init {
|
||||||
|
|
||||||
|
@:provide static var resources:IResources;
|
||||||
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
@:provide static var configBundle:IConfigBundle;
|
||||||
|
@:provide static var settingsStorage:SettingsStorage;
|
||||||
|
@:provide static var multiplayerStorage:NetworkStorage;
|
||||||
|
@:provide static var gameStorage:GameStorage;
|
||||||
|
@:provide static var recordStorage:RecordStorage;
|
||||||
|
@:provide static var soundManager:SoundManager;
|
||||||
|
@:provide static var networkManager:NetworkManager;
|
||||||
|
@:provide static var popupManager:PopupManager;
|
||||||
|
@:provide static var connection:IConnection<Request, Response>;
|
||||||
|
|
||||||
|
private static function buildConnection():IConnection<Request, Response> {
|
||||||
|
var host:String = CompilationOption.get("host");
|
||||||
|
var port:Int = CompilationOption.get("port");
|
||||||
|
L.d("Init", 'connect to $host:$port');
|
||||||
|
#if flash
|
||||||
|
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||||
|
#elseif html5
|
||||||
|
return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||||
|
#else
|
||||||
|
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function init():Void {
|
||||||
|
resources = new Resources();
|
||||||
|
levelBundle = new LevelBundle();
|
||||||
|
configBundle = new ConfigBundle();
|
||||||
|
settingsStorage = new SettingsStorage();
|
||||||
|
multiplayerStorage = new NetworkStorage();
|
||||||
|
gameStorage = new GameStorage();
|
||||||
|
recordStorage = new RecordStorage();
|
||||||
|
soundManager = new SoundManager();
|
||||||
|
popupManager = new PopupManager();
|
||||||
|
|
||||||
|
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||||
|
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||||
|
|
||||||
|
connection = buildConnection();
|
||||||
|
networkManager = new NetworkManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import flash.filters.ColorMatrixFilter;
|
||||||
|
import flash.geom.Point;
|
||||||
|
import flash.Lib;
|
||||||
|
import openfl.Assets;
|
||||||
|
|
||||||
|
class LinuxIcon {
|
||||||
|
|
||||||
|
private static function prepareIcon(bitmap:BitmapData):BitmapData {
|
||||||
|
var matrix:Array<Float> = [];
|
||||||
|
matrix = matrix.concat([0, 0, 1, 0, 0]);
|
||||||
|
matrix = matrix.concat([0, 1, 0, 0, 0]);
|
||||||
|
matrix = matrix.concat([1, 0, 0, 0, 0]);
|
||||||
|
matrix = matrix.concat([0, 0, 0, 1, 0]);
|
||||||
|
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
|
||||||
|
var bitmap:BitmapData = bitmap.clone();
|
||||||
|
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function apply() {
|
||||||
|
var icon = Assets.getBitmapData("resources/icon.png");
|
||||||
|
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
|
||||||
|
}
|
||||||
|
}
|
||||||
141
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
141
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.display.Shape;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.events.Event;
|
||||||
|
import flash.events.ProgressEvent;
|
||||||
|
import flash.Lib;
|
||||||
|
import haxework.view.core.Size;
|
||||||
|
|
||||||
|
class Progress extends Sprite {
|
||||||
|
|
||||||
|
public var color(default, set):Int = 0;
|
||||||
|
public var backColor(default, set):Int = 0;
|
||||||
|
public var progress(default, set):Float = 0;
|
||||||
|
public var size(default, set):Size = [0, 0];
|
||||||
|
public var radius(get, null):Float;
|
||||||
|
|
||||||
|
private var maskShape:Shape;
|
||||||
|
private var toRedraw:Bool;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
maskShape = new Shape();
|
||||||
|
addChild(maskShape);
|
||||||
|
mask = maskShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_radius():Float {
|
||||||
|
return Math.min(size.width, size.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_color(value:Int):Int {
|
||||||
|
if (color != value) {
|
||||||
|
color = value;
|
||||||
|
toRedraw = true;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_backColor(value:Int):Int {
|
||||||
|
if (backColor != value) {
|
||||||
|
backColor = value;
|
||||||
|
toRedraw = true;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_progress(value:Float):Float {
|
||||||
|
if (progress != value) {
|
||||||
|
progress = value;
|
||||||
|
toRedraw = true;
|
||||||
|
}
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_size(value:Size):Size {
|
||||||
|
if (size != value) {
|
||||||
|
size = value;
|
||||||
|
toRedraw = true;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update():Void {
|
||||||
|
if (toRedraw) {
|
||||||
|
redraw();
|
||||||
|
redrawMask();
|
||||||
|
toRedraw = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redraw():Void {
|
||||||
|
graphics.clear();
|
||||||
|
graphics.beginFill(color);
|
||||||
|
graphics.drawCircle(radius, radius, radius);
|
||||||
|
graphics.beginFill(backColor);
|
||||||
|
graphics.drawCircle(radius, radius, radius / 2);
|
||||||
|
graphics.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redrawMask():Void {
|
||||||
|
maskShape.graphics.clear();
|
||||||
|
maskShape.graphics.beginFill(0x00ff00);
|
||||||
|
maskShape.graphics.moveTo(radius, radius);
|
||||||
|
var sides = 6;
|
||||||
|
var rotation = (-(Math.PI) / 2);
|
||||||
|
var r = radius / Math.cos(1/sides * Math.PI);
|
||||||
|
var lineToRadians = function(rads:Float):Void {
|
||||||
|
maskShape.graphics.lineTo(Math.cos(rads) * r + radius, Math.sin(rads) * r + radius);
|
||||||
|
};
|
||||||
|
var sidesToDraw:Int = Math.floor(progress * sides);
|
||||||
|
for (i in 0...sidesToDraw + 1) {
|
||||||
|
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
|
||||||
|
}
|
||||||
|
if (progress * sides != sidesToDraw) {
|
||||||
|
lineToRadians(progress * (Math.PI * 2) + rotation);
|
||||||
|
}
|
||||||
|
maskShape.graphics.endFill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Preloader extends Sprite {
|
||||||
|
|
||||||
|
private var progress:Progress;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
Lib.current.stage.color = Style.lightColor;
|
||||||
|
progress = new Progress();
|
||||||
|
progress.color = Style.darkColor;
|
||||||
|
progress.backColor = Style.lightColor;
|
||||||
|
progress.size = [200, 200];
|
||||||
|
addChild(progress);
|
||||||
|
onResize(null);
|
||||||
|
Lib.current.stage.addEventListener(Event.RESIZE, onResize);
|
||||||
|
Lib.current.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
|
Lib.current.stage.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
|
addEventListener(Event.COMPLETE, onComplete);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onResize(event:Event):Void {
|
||||||
|
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
|
||||||
|
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onEnterFrame(event:Event):Void {
|
||||||
|
progress.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onProgress(event:ProgressEvent):Void {
|
||||||
|
progress.progress = event.bytesLoaded / event.bytesTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onComplete(event:Event):Void {
|
||||||
|
progress.update();
|
||||||
|
Lib.current.stage.removeEventListener(Event.RESIZE, onResize);
|
||||||
|
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
|
Lib.current.stage.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
|
removeEventListener(Event.COMPLETE, onComplete);
|
||||||
|
}
|
||||||
|
}
|
||||||
164
src/client/haxe/ru/m/tankz/Style.hx
Normal file
164
src/client/haxe/ru/m/tankz/Style.hx
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.text.Font;
|
||||||
|
import flash.text.FontType;
|
||||||
|
import haxework.color.ColorUtil;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.view.core.Geometry;
|
||||||
|
import haxework.view.core.HAlign;
|
||||||
|
import haxework.view.core.VAlign;
|
||||||
|
import haxework.view.ITextView;
|
||||||
|
import haxework.view.layout.Layout;
|
||||||
|
import haxework.view.skin.ISkin;
|
||||||
|
import haxework.view.skin.Skin;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.skin.ButtonSVGSkin;
|
||||||
|
|
||||||
|
class Style {
|
||||||
|
|
||||||
|
@:provide private static var resources:IResources;
|
||||||
|
|
||||||
|
public static var lightColor = 0x95937D;
|
||||||
|
public static var darkColor = 0x777564;
|
||||||
|
public static var textColor = 0xE7E0BB;
|
||||||
|
public static var activeColor = 0xFFFF00;
|
||||||
|
public static var borderColor = ColorUtil.multiply(lightColor, 1.5);
|
||||||
|
|
||||||
|
public static var baseFontSize = 18;
|
||||||
|
public static var bigFontSize = 22;
|
||||||
|
public static var veryBigFontSize = 24;
|
||||||
|
|
||||||
|
public static var fontFamily = "Courirer New";
|
||||||
|
public static var fontEmbed = false;
|
||||||
|
|
||||||
|
public static function text(color):ISkin<ITextView> {
|
||||||
|
return Skin.text(color, baseFontSize, fontFamily, fontEmbed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function registerButton(name:String, resource:String):Void {
|
||||||
|
resources.skin.put('button.$name', [
|
||||||
|
Skin.size(64, 64),
|
||||||
|
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put('button.$name.small', [
|
||||||
|
Skin.size(32, 32),
|
||||||
|
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function textBox(color:Int):SkinSet {
|
||||||
|
return [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(color, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function register(font:Font = null):Void {
|
||||||
|
resources.color.put("light", lightColor);
|
||||||
|
resources.color.put("dark", darkColor);
|
||||||
|
if (font == null) {
|
||||||
|
font = Font.enumerateFonts()[0];
|
||||||
|
}
|
||||||
|
if (font == null) {
|
||||||
|
font = Font.enumerateFonts(true)[0];
|
||||||
|
}
|
||||||
|
fontFamily = font == null ? "Courirer New" : font.fontName;
|
||||||
|
fontEmbed = font == null ? false : switch font.fontType {
|
||||||
|
case DEVICE: false;
|
||||||
|
case _: true;
|
||||||
|
};
|
||||||
|
resources.skin.put("light", [
|
||||||
|
Skin.color(lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("dark", [
|
||||||
|
Skin.color(darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("font", [
|
||||||
|
Skin.text(textColor, 0, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text", [
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("scroll.vertical", [
|
||||||
|
haxework.view.skin.Skin.scrollVertical(lightColor, darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.header", [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([50, 8]).setMargin([0, 0, 0, 30])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.size(250, 50),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box", [
|
||||||
|
Skin.color(0x000000, 0.1),
|
||||||
|
Skin.border(lightColor, 1, 2),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("text.box.active", [
|
||||||
|
Skin.color(0x55aa55),
|
||||||
|
Skin.border(0x88dd88, 1, 2),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.simple", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.simple.active", [
|
||||||
|
Skin.buttonColor(lightColor, activeColor),
|
||||||
|
Skin.text(activeColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.tab", [
|
||||||
|
Skin.tabColor(lightColor),
|
||||||
|
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||||
|
]);
|
||||||
|
resources.skin.put("border", [
|
||||||
|
Skin.border(borderColor, 1, 2),
|
||||||
|
]);
|
||||||
|
resources.skin.put("scroll", [
|
||||||
|
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
||||||
|
]);
|
||||||
|
resources.skin.put("button.level", [
|
||||||
|
Skin.buttonColor(lightColor),
|
||||||
|
Skin.text(textColor, veryBigFontSize, fontFamily, fontEmbed),
|
||||||
|
Skin.size(64, 64),
|
||||||
|
]);
|
||||||
|
|
||||||
|
resources.skin.put("container", [
|
||||||
|
Skin.geometry(new Geometry().setSize("100%", "100%")),
|
||||||
|
Skin.layout(new Layout().setAlign(CENTER, MIDDLE)),
|
||||||
|
Skin.color(darkColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("panel", [
|
||||||
|
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([20, 10])),
|
||||||
|
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
||||||
|
Skin.color(lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("window", [
|
||||||
|
Skin.color(darkColor),
|
||||||
|
Skin.border(borderColor, 1, 2),
|
||||||
|
Skin.geometry(new Geometry().setPadding(2)),
|
||||||
|
]);
|
||||||
|
resources.skin.put("window.close", [
|
||||||
|
Skin.size(36, 36),
|
||||||
|
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
||||||
|
]);
|
||||||
|
resources.skin.put("line", [
|
||||||
|
Skin.color(borderColor),
|
||||||
|
]);
|
||||||
|
|
||||||
|
registerButton("settings", "cog-solid.svg");
|
||||||
|
registerButton("close", "times-circle-solid.svg");
|
||||||
|
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||||
|
registerButton("start", "play-circle-solid.svg");
|
||||||
|
registerButton("login", "sign-in-solid.svg");
|
||||||
|
registerButton("logout", "sign-out-solid.svg");
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx
Normal file
23
src/client/haxe/ru/m/tankz/bundle/ConfigBundle.hx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import yaml.Parser;
|
||||||
|
import yaml.Yaml;
|
||||||
|
|
||||||
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
|
||||||
|
private var _cache:Map<GameType, Config> = new Map();
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function get(type:GameType):Config {
|
||||||
|
if (!_cache.exists(type)) {
|
||||||
|
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
||||||
|
_cache.set(type, Config.fromSource(type, source));
|
||||||
|
}
|
||||||
|
return _cache.get(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
23
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.util.LevelUtil;
|
||||||
|
|
||||||
|
class LevelBundle implements ILevelBundle {
|
||||||
|
|
||||||
|
private var cache:Map<String, LevelConfig> = new Map();
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
||||||
|
var key = '${type}:${levelId}';
|
||||||
|
if (!cache.exists(key)) {
|
||||||
|
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
||||||
|
cache[key] = LevelUtil.loads(config, data);
|
||||||
|
cache[key].id = levelId;
|
||||||
|
}
|
||||||
|
return cache[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
27
src/client/haxe/ru/m/tankz/control/ActionConfig.hx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
|
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 KeyBinding();
|
||||||
|
for (item in data) {
|
||||||
|
result[item.key] = item.action;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,31 +1,39 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import ru.m.tankz.control.Control;
|
|
||||||
import haxe.Timer;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
import flash.ui.Keyboard;
|
|
||||||
import flash.events.KeyboardEvent;
|
import flash.events.KeyboardEvent;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
|
import haxe.Timer;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
typedef KeyBinding = Map<Int, TankAction>;
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
public static var TYPE(default, never):ControlType = 'human';
|
|
||||||
|
@:provide var storage: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(index:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super({type:TYPE, index:index});
|
super(playerId);
|
||||||
this.keyBinding = resolve(index);
|
this.keyBinding = storage.getActionConfig(controlIndex).asKeyBinding();
|
||||||
moveQueue = new Array<Int>();
|
moveQueue = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function start():Void {
|
||||||
|
super.start();
|
||||||
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);
|
||||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
}
|
||||||
|
|
||||||
|
override public function stop():Void {
|
||||||
|
super.stop();
|
||||||
|
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||||
|
Lib.current.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||||
|
moveQueue = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onKeyDown(event:KeyboardEvent):Void {
|
private function onKeyDown(event:KeyboardEvent):Void {
|
||||||
@@ -43,9 +51,6 @@ class HumanControl extends Control {
|
|||||||
}
|
}
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
if (event.keyCode == Keyboard.U) {
|
|
||||||
action(TankAction.LEVEL_UP(1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onKeyUp(event:KeyboardEvent):Void {
|
private function onKeyUp(event:KeyboardEvent):Void {
|
||||||
@@ -82,27 +87,4 @@ class HumanControl extends Control {
|
|||||||
private function shot():Void {
|
private function shot():Void {
|
||||||
action(TankAction.SHOT);
|
action(TankAction.SHOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function resolve(index:Int):KeyBinding {
|
|
||||||
switch (index) {
|
|
||||||
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 _:
|
|
||||||
throw 'Invalid control index ${index}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.BaseControlFactory;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.control.HumanControl;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class LocalControlFactory extends BaseControlFactory {
|
||||||
|
|
||||||
|
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||||
|
return new HumanControl(id, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
31
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
|
import ru.m.tankz.local.LocalControlFactory;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.GameRunner;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.record.GameRecorder;
|
||||||
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
|
class LocalGame extends GameRunner {
|
||||||
|
@:provide var recordStorage:RecordStorage;
|
||||||
|
private var recorder:GameRecorder;
|
||||||
|
|
||||||
|
public function new(state:GameState) {
|
||||||
|
super(state);
|
||||||
|
controlFactory = new LocalControlFactory();
|
||||||
|
recorder = new GameRecorder();
|
||||||
|
connect(recorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function onGameEvent(event:GameEvent):Void {
|
||||||
|
super.onGameEvent(event);
|
||||||
|
switch event {
|
||||||
|
case GameEvent.COMPLETE(_, _):
|
||||||
|
disconnect(recorder);
|
||||||
|
recorder.onGameEvent(event); //ToDo:
|
||||||
|
recordStorage.save(recorder.record);
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/tankz/network/NetworkControl.hx
Normal file
16
src/client/haxe/ru/m/tankz/network/NetworkControl.hx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.HumanControl;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
|
class NetworkControl extends HumanControl {
|
||||||
|
|
||||||
|
@:provide private var network:NetworkManager;
|
||||||
|
|
||||||
|
override public function action(action:TankAction):Void {
|
||||||
|
if (tankId > -1) {
|
||||||
|
network.action(tankId, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
16
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.control.BaseControlFactory;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class NetworkControlFactory extends BaseControlFactory {
|
||||||
|
|
||||||
|
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||||
|
return new NetworkControl(id, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function buildBot(id:PlayerId, type:String):Control {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
54
src/client/haxe/ru/m/tankz/network/NetworkGame.hx
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import haxe.Unserializer;
|
||||||
|
import ru.m.tankz.game.Game;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.network.NetworkControlFactory;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
|
|
||||||
|
class NetworkGame extends Game {
|
||||||
|
|
||||||
|
private var network:NetworkManager;
|
||||||
|
|
||||||
|
public function new(network:NetworkManager) {
|
||||||
|
super(new GameState(network.room.game.type, 0, network.room.game.level));
|
||||||
|
this.network = network;
|
||||||
|
this.controlFactory = new NetworkControlFactory();
|
||||||
|
network.gameEventSignal.connect(onGameEventProto);
|
||||||
|
network.stateSignal.connect(onConnectionState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onGameEventProto(game:GameEventResponse):Void {
|
||||||
|
var time = game.event.time;
|
||||||
|
var eventStr = game.event.event;
|
||||||
|
var event:GameEvent = Unserializer.run(eventStr);
|
||||||
|
gameEventSignal.emit(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionState(state:ConnectionState):Void {
|
||||||
|
switch state {
|
||||||
|
case ONLINE(user):
|
||||||
|
if (network.room != null) {
|
||||||
|
network.joinGame(network.room.game.id);
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function start():Void {
|
||||||
|
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||||
|
if (slot != null) {
|
||||||
|
state.controls.push({playerId: [slot.slot.team, slot.slot.index], control: "human-0"});
|
||||||
|
}
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function dispose():Void {
|
||||||
|
super.dispose();
|
||||||
|
network.gameEventSignal.disconnect(onGameEventProto);
|
||||||
|
network.stateSignal.disconnect(onConnectionState);
|
||||||
|
}
|
||||||
|
}
|
||||||
173
src/client/haxe/ru/m/tankz/network/NetworkManager.hx
Normal file
173
src/client/haxe/ru/m/tankz/network/NetworkManager.hx
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
|
import ru.m.tankz.proto.game.GameEventProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotRequest;
|
||||||
|
import haxe.Serializer;
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.connect.IConnection;
|
||||||
|
import ru.m.tankz.control.Control;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||||
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
|
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||||
|
import ru.m.tankz.proto.pack.Request;
|
||||||
|
import ru.m.tankz.proto.pack.Response;
|
||||||
|
import ru.m.tankz.proto.room.CreateRequest;
|
||||||
|
import ru.m.tankz.proto.room.JoinRequest;
|
||||||
|
import ru.m.tankz.proto.room.LeaveRequest;
|
||||||
|
import ru.m.tankz.proto.room.RoomListRequest;
|
||||||
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomRequest;
|
||||||
|
import ru.m.tankz.proto.room.StartRequest;
|
||||||
|
import ru.m.tankz.storage.NetworkStorage;
|
||||||
|
|
||||||
|
typedef ClientConnection = IConnection<Request, Response>;
|
||||||
|
|
||||||
|
enum ConnectionState {
|
||||||
|
OFFLINE;
|
||||||
|
CONNECT;
|
||||||
|
CONNECTED;
|
||||||
|
LOGIN;
|
||||||
|
ONLINE(user:User);
|
||||||
|
ERROR(error:Dynamic);
|
||||||
|
}
|
||||||
|
|
||||||
|
class NetworkManager {
|
||||||
|
|
||||||
|
public var state(default, null):ConnectionState;
|
||||||
|
public var room(default, null):RoomProto;
|
||||||
|
public var user(default, null):UserProto;
|
||||||
|
|
||||||
|
public var stateSignal:Signal<ConnectionState>;
|
||||||
|
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||||
|
public var roomSignal:Signal<RoomProto>;
|
||||||
|
public var gameEventSignal:Signal<GameEventResponse>;
|
||||||
|
|
||||||
|
@:provide private var connection:ClientConnection;
|
||||||
|
@:provide private var storage:NetworkStorage;
|
||||||
|
|
||||||
|
private var reconnectTimer:Timer;
|
||||||
|
private var reconnectDelay:Int;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
reconnectDelay = 500;
|
||||||
|
stateSignal = new Signal();
|
||||||
|
listRoomSignal = new Signal();
|
||||||
|
roomSignal = new Signal();
|
||||||
|
gameEventSignal = new Signal();
|
||||||
|
updateState(OFFLINE);
|
||||||
|
connection.handler.connect(onConnectionEvent);
|
||||||
|
connection.receiveHandler.connect(onResponse);
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateState(value:ConnectionState):Void {
|
||||||
|
state = value;
|
||||||
|
stateSignal.emit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(name:String, uuid:String = null):Void {
|
||||||
|
updateState(LOGIN);
|
||||||
|
connection.send(new Request().setLogin(
|
||||||
|
new LoginRequest()
|
||||||
|
.setUuid(uuid)
|
||||||
|
.setName(name)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout():Void {
|
||||||
|
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listGame(subscribe:Bool):Void {
|
||||||
|
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createGame(type:String, level:Int):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type).setLevel(level))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId).setRestore(restore))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectSlot(slot:SlotProto):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leaveGame():Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startGame():Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
|
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
|
||||||
|
new GameEventProto().setTime(0).setEvent(
|
||||||
|
Serializer.run(GameEvent.ACTION(tankId, action))
|
||||||
|
)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function connect():Void {
|
||||||
|
if (reconnectTimer != null) {
|
||||||
|
reconnectTimer.stop();
|
||||||
|
reconnectTimer = null;
|
||||||
|
}
|
||||||
|
reconnectTimer = null;
|
||||||
|
updateState(CONNECT);
|
||||||
|
connection.connect().catchError(function(error) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function reconnect():Void {
|
||||||
|
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||||
|
if (reconnectTimer == null) {
|
||||||
|
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
|
updateState(switch event {
|
||||||
|
case CONNECTED: CONNECTED;
|
||||||
|
case DISCONNECTED: OFFLINE;
|
||||||
|
case ERROR(error): ERROR(error);
|
||||||
|
});
|
||||||
|
switch event {
|
||||||
|
case CONNECTED:
|
||||||
|
reconnectDelay = 500;
|
||||||
|
var user = storage.user;
|
||||||
|
if (user != null) {
|
||||||
|
login(user.name, user.uuid);
|
||||||
|
}
|
||||||
|
case DISCONNECTED | ERROR(_):
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onResponse(packet:Response):Void {
|
||||||
|
if (packet.hasLogin()) {
|
||||||
|
this.user = packet.login.user;
|
||||||
|
var user = {
|
||||||
|
uuid: this.user.uuid,
|
||||||
|
name: this.user.name,
|
||||||
|
};
|
||||||
|
storage.user = user;
|
||||||
|
updateState(ONLINE(user));
|
||||||
|
} else if (packet.hasLogout()) {
|
||||||
|
storage.user = null;
|
||||||
|
updateState(CONNECTED);
|
||||||
|
} else if (packet.hasRoomList()) {
|
||||||
|
listRoomSignal.emit(packet.roomList.rooms);
|
||||||
|
} else if (packet.hasRoom()) {
|
||||||
|
room = packet.room.room;
|
||||||
|
roomSignal.emit(room);
|
||||||
|
} else if (packet.hasGameEvent()) {
|
||||||
|
gameEventSignal.emit(packet.gameEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/client/haxe/ru/m/tankz/render/AnimateBundle.hx
Normal file
42
src/client/haxe/ru/m/tankz/render/AnimateBundle.hx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
|
||||||
|
class AnimateBundle {
|
||||||
|
|
||||||
|
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
||||||
|
var template:String = 'resources/image/animate/${name}/%index%.png';
|
||||||
|
var frames = [for (i in sequence) ({
|
||||||
|
image: Assets.getBitmapData(StringTools.replace(template, '%index%', Std.string(i))),
|
||||||
|
length: 1
|
||||||
|
})];
|
||||||
|
return new OnceAnimate(frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankSpawn():OnceAnimate {
|
||||||
|
return buildAnimate('appear', [
|
||||||
|
0, 1, 2, 3, 3, 4, 5, 5, 6
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankBoom():OnceAnimate {
|
||||||
|
return buildAnimate('boom', [
|
||||||
|
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function bulletBoom():OnceAnimate {
|
||||||
|
return buildAnimate('boom-sm', [
|
||||||
|
0, 1, 1, 0, 0, 1
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tankProtect():Animate {
|
||||||
|
return new Animate([for (i in 0...2) ({
|
||||||
|
image: Assets.getBitmapData('resources/image/animate/protect/${i}.png'),
|
||||||
|
length: 5
|
||||||
|
})]);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
11
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import haxework.view.IView;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
|
interface IRender extends IView<Dynamic> extends GameListener {
|
||||||
|
public var config(default, set):Config;
|
||||||
|
public function draw():Void;
|
||||||
|
public function reset():Void;
|
||||||
|
}
|
||||||
@@ -1,22 +1,31 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import ru.m.geom.Point;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.animate.OnceAnimate;
|
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import ru.m.tankz.core.EntityType;
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import Type.ValueType;
|
|
||||||
import ru.m.tankz.render.RenderItem;
|
|
||||||
import ru.m.tankz.engine.Engine;
|
|
||||||
import ru.m.tankz.core.Bullet;
|
|
||||||
import ru.m.tankz.core.Tank;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import haxework.gui.SpriteView;
|
import flash.display.Sprite;
|
||||||
|
import flash.events.Event;
|
||||||
|
import haxe.Timer;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.SpriteView;
|
||||||
|
import promhx.Promise;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.OnceAnimate;
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.render.item.BonusRenderItem;
|
||||||
|
import ru.m.tankz.render.item.BrickRenderItem;
|
||||||
|
import ru.m.tankz.render.item.BulletRenderItem;
|
||||||
|
import ru.m.tankz.render.item.EagleRenderItem;
|
||||||
|
import ru.m.tankz.render.item.IRenderItem;
|
||||||
|
import ru.m.tankz.render.item.TankRenderItem;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
using ru.m.display.DisplayObjectContainerExtender;
|
||||||
|
|
||||||
|
class Render extends SpriteView implements IRender {
|
||||||
|
|
||||||
class Render extends SpriteView implements EngineListener {
|
public var config(default, set):Config;
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
@@ -24,8 +33,7 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
private var upLayer:Sprite;
|
private var upLayer:Sprite;
|
||||||
private var upperLayer:Sprite;
|
private var upperLayer:Sprite;
|
||||||
|
|
||||||
private var background:Sprite;
|
private var items:Map<Int, IRenderItem>;
|
||||||
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
|
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
@@ -35,45 +43,37 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function drawBackground(game:Engine):Void {
|
private function set_config(value:Config):Config {
|
||||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
config = value;
|
||||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
setContentSize(config.mapWidth, config.mapHeight);
|
||||||
|
drawBackground();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function drawBackground():Void {
|
||||||
var g:Graphics = backgroundLayer.graphics;
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
g.drawRect(0, 0, config.mapWidth, config.mapHeight);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
if (contentSize) {
|
|
||||||
width = mapWidth;
|
|
||||||
height = mapHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:Engine):Void {
|
public function draw():Void {
|
||||||
for (brick in game.map.bricks) if (brick.config.type > 0) {
|
|
||||||
if (!items.exists(brick.key)) {
|
|
||||||
items[brick.key] = new BrickItem(brick);
|
|
||||||
if (brick.config.layer > 2) {
|
|
||||||
upLayer.addChild(items[brick.key].view);
|
|
||||||
} else {
|
|
||||||
groundLayer.addChild(items[brick.key].view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
item.update();
|
item.update();
|
||||||
}
|
}
|
||||||
if (background == null) {
|
}
|
||||||
drawBackground(game);
|
|
||||||
}
|
private function onEnterFrame(event:Event):Void {
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clearLayer(layer:DisplayObjectContainer) {
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
@@ -81,95 +81,178 @@ class Render extends SpriteView implements EngineListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function reset():Void {
|
public function reset():Void {
|
||||||
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
for (item in items.iterator()) {
|
for (item in items.iterator()) {
|
||||||
item.dispose();
|
item.dispose();
|
||||||
}
|
}
|
||||||
items = new Map();
|
items = new Map();
|
||||||
if (background != null) {
|
|
||||||
backgroundLayer.removeChild(background);
|
|
||||||
background = null;
|
|
||||||
}
|
|
||||||
clearLayer(entryLayer);
|
clearLayer(entryLayer);
|
||||||
clearLayer(groundLayer);
|
clearLayer(groundLayer);
|
||||||
clearLayer(upLayer);
|
clearLayer(upLayer);
|
||||||
|
clearLayer(upperLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSpawn(entity:EntityType):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
switch(entity) {
|
switch event {
|
||||||
case EntityType.TANK(tank):
|
case START(_):
|
||||||
var item = new TankItem(tank);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
items.set(tank.key, item);
|
case COMPLETE(_, _):
|
||||||
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
|
case SPAWN(BRICK(bricks)):
|
||||||
|
drawBackground();
|
||||||
|
for (brick in bricks) {
|
||||||
|
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||||
|
var config = config.getBrick(brick.type);
|
||||||
|
items[brick.id] = item;
|
||||||
|
if (config.layer > 2) {
|
||||||
|
upLayer.addChild(item.view);
|
||||||
|
} else {
|
||||||
|
groundLayer.addChild(item.view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case SPAWN(EAGLE(id, rect, teamId)):
|
||||||
|
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||||
|
items.set(id, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case EntityType.BULLET(bullet):
|
case SPAWN(TANK(id, rect, playerId, info)):
|
||||||
var item = new BulletItem(bullet);
|
var item = new TankRenderItem(rect);
|
||||||
items.set(bullet.key, item);
|
var tankConfig = config.getTank(info.type);
|
||||||
|
item.color = info.color;
|
||||||
|
item.skin = tankConfig.skin;
|
||||||
|
item.hits = info.hits;
|
||||||
|
item.bonus = info.bonus;
|
||||||
|
item.name = info.name == null ? "" : info.name;
|
||||||
|
items.set(id, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case EntityType.EAGLE(eagle):
|
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||||
var item = new EagleItem(eagle);
|
case SPAWN(BULLET(id, rect, playerId, piercing)):
|
||||||
items.set(eagle.key, item);
|
var item = new BulletRenderItem(rect, piercing);
|
||||||
|
items.set(id, item);
|
||||||
entryLayer.addChild(item.view);
|
entryLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
|
case SPAWN(BONUS(id, rect, type)):
|
||||||
|
var item = new BonusRenderItem(rect, type);
|
||||||
|
items.set(id, item);
|
||||||
|
upperLayer.addChild(item.view);
|
||||||
|
item.update();
|
||||||
|
case MOVE(EAGLE(id, position)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
|
}
|
||||||
|
case MOVE(BULLET(id, position)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
|
}
|
||||||
|
case MOVE(TANK(id, position)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
|
cast(item, TankRenderItem).moves = true;
|
||||||
|
}
|
||||||
|
case STOP(TANK(id)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
cast(item, TankRenderItem).moves = false;
|
||||||
|
}
|
||||||
|
case CHANGE(TANK(id, type, hits, bonus)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:TankRenderItem = cast items[id];
|
||||||
|
item.skin = config.getTank(type).skin;
|
||||||
|
item.hits = hits;
|
||||||
|
item.bonus = bonus;
|
||||||
|
}
|
||||||
|
case CHANGE(TANK_PROTECT(id, state)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:TankRenderItem = cast items[id];
|
||||||
|
item.protect = state;
|
||||||
|
}
|
||||||
|
case CHANGE(EAGLE_PROTECT(id, state)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:EagleRenderItem = cast items[id];
|
||||||
|
item.protect = state;
|
||||||
|
}
|
||||||
|
case CHANGE(BRICK(id, type)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:BrickRenderItem = cast items[id];
|
||||||
|
item.type = type;
|
||||||
|
}
|
||||||
|
case DESTROY(TANK(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
entryLayer.removeChild(item.view);
|
||||||
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(BULLET(id)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
entryLayer.removeChild(item.view);
|
||||||
|
var rect = item.rect;
|
||||||
|
// move boom
|
||||||
|
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||||
|
playAnimate(point, AnimateBundle.bulletBoom());
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(EAGLE(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
|
cast(item, EagleRenderItem).death = true;
|
||||||
|
}
|
||||||
|
case DESTROY(BONUS(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
upperLayer.removeChild(item.view);
|
||||||
|
if (shot.score != 0) {
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
}
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(CELL(id, x, y, shot)):
|
||||||
|
var item:BrickRenderItem = cast items.get(id);
|
||||||
|
item.destroyCell(x, y);
|
||||||
|
case DESTROY(BRICK(id, shot)):
|
||||||
|
var item:BrickRenderItem = cast items.get(id);
|
||||||
|
item.destroy();
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
|
#if cpp
|
||||||
|
flash.Lib.current.stage.invalidate();
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onDestroy(entity:EntityType):Void {
|
|
||||||
switch(entity) {
|
|
||||||
case EntityType.TANK(tank):
|
|
||||||
if (items.exists(tank.key)) {
|
|
||||||
entryLayer.removeChild(items.get(tank.key).view);
|
|
||||||
items.remove(tank.key);
|
|
||||||
playTankBoom(tank.rect.center);
|
|
||||||
}
|
|
||||||
case EntityType.BULLET(bullet):
|
|
||||||
if (items.exists(bullet.key)) {
|
|
||||||
entryLayer.removeChild(items.get(bullet.key).view);
|
|
||||||
items.remove(bullet.key);
|
|
||||||
playBulletBoom(bullet.rect.center.add(new Point(bullet.rect.width * bullet.rect.direction.x, bullet.rect.height * bullet.rect.direction.y)));
|
|
||||||
}
|
|
||||||
case EntityType.EAGLE(eagle):
|
|
||||||
if (items.exists(eagle.key)) {
|
|
||||||
cast(items.get(eagle.key), EagleItem).destoyed = true;
|
|
||||||
items.get(eagle.key).redraw();
|
|
||||||
playTankBoom(eagle.rect.center);
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function playBulletBoom(point:Point):Void {
|
|
||||||
var arr = [
|
|
||||||
0, 1, 1, 0, 0, 1
|
|
||||||
];
|
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/bullet/boom/boom-${i}.png')];
|
|
||||||
var animate = new OnceAnimate(frames);
|
|
||||||
animate.x = point.x - animate.width / 2;
|
animate.x = point.x - animate.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
animate.play().then(function(animate) {
|
return animate.play().then(function(animate:Animate):Void {
|
||||||
upperLayer.removeChild(animate);
|
// ToDo: clean animates on reset
|
||||||
|
if (upperLayer.contains(animate)) {
|
||||||
|
upperLayer.removeChildSafety(animate);
|
||||||
|
}
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function playTankBoom(point:Point):Void {
|
private function showScore(point:Point, score:Int):Void {
|
||||||
var arr = [
|
var view:LabelView = new LabelView();
|
||||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
view.skinId = "text";
|
||||||
];
|
view.text = Std.string(score);
|
||||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/kaboom/kaboom-${i}.png')];
|
view.update();
|
||||||
var animate = new OnceAnimate(frames);
|
view.redraw();
|
||||||
animate.x = point.x - animate.width / 2;
|
view.x = point.x - view.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
view.y = point.y - view.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(view.content);
|
||||||
animate.play().then(function(animate) {
|
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||||
upperLayer.removeChild(animate);
|
|
||||||
animate.dispose();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,190 +0,0 @@
|
|||||||
package ru.m.tankz.render;
|
|
||||||
|
|
||||||
import ru.m.animate.Animate;
|
|
||||||
import ru.m.tankz.core.Eagle;
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import flash.display.Shape;
|
|
||||||
import ru.m.geom.Direction;
|
|
||||||
import ru.m.geom.Rectangle;
|
|
||||||
import ru.m.tankz.core.Bullet;
|
|
||||||
import ru.m.tankz.map.Brick;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.tankz.core.Tank;
|
|
||||||
import flash.display.Bitmap;
|
|
||||||
|
|
||||||
|
|
||||||
typedef TRectangle = {
|
|
||||||
var rect(default, null):Rectangle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RenderItem<T:TRectangle, D:DisplayObject> {
|
|
||||||
|
|
||||||
public var value(default, null):T;
|
|
||||||
public var view(default, null):D;
|
|
||||||
|
|
||||||
public function new(value:T) {
|
|
||||||
this.value = value;
|
|
||||||
this.view = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function redraw():Void {}
|
|
||||||
|
|
||||||
public function update():Void {
|
|
||||||
var rect = value.rect;
|
|
||||||
view.rotation = calcRotate(rect.direction);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BitmapItem<T:TRectangle> extends RenderItem<T, Bitmap> {
|
|
||||||
|
|
||||||
public function new(value:T) {
|
|
||||||
super(value);
|
|
||||||
this.view = new Bitmap();
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function redraw():Void {
|
|
||||||
view.bitmapData = Assets.getBitmapData(getImage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getImage():String {
|
|
||||||
return 'ERROR';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BrickItem extends RenderItem<Brick, Shape> {
|
|
||||||
|
|
||||||
private var broken:Int;
|
|
||||||
|
|
||||||
public function new(value:Brick) {
|
|
||||||
super(value);
|
|
||||||
this.view = new Shape();
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function redraw():Void {
|
|
||||||
var image = Assets.getBitmapData(getImage());
|
|
||||||
var g = view.graphics;
|
|
||||||
g.clear();
|
|
||||||
if (value.destroyed) return;
|
|
||||||
g.beginBitmapFill(image);
|
|
||||||
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
|
||||||
for (c in value.cells) {
|
|
||||||
if (c.destroyed) {
|
|
||||||
g.beginFill(0x000000);
|
|
||||||
g.drawRect(c.rect.x - value.rect.x, c.rect.y - value.rect.y, c.rect.width, c.rect.height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g.endFill();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
var b = value.broken;
|
|
||||||
if (b != this.broken) {
|
|
||||||
this.broken = b;
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getImage():String {
|
|
||||||
return 'resources/images/map/map_${value.config.type}.png';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class TankItem extends RenderItem<Tank, Animate> {
|
|
||||||
|
|
||||||
private var type:String;
|
|
||||||
private var hits:Int;
|
|
||||||
|
|
||||||
public function new(value:Tank) {
|
|
||||||
super(value);
|
|
||||||
view = new Animate();
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function redraw():Void {
|
|
||||||
view.frames = getFrames().map(function(s) return Assets.getBitmapData(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getFrames():Array<String> {
|
|
||||||
var team = value.playerId.team;
|
|
||||||
var group = value.config.group;
|
|
||||||
var index = value.playerId.index;
|
|
||||||
if (team == 'radiant') {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
if (team == 'dire') {
|
|
||||||
index = 1;
|
|
||||||
}
|
|
||||||
if (team == 'human' || team == 'radiant' || team == 'dire') {
|
|
||||||
group = 'player';
|
|
||||||
}
|
|
||||||
if (team == 'bot') {
|
|
||||||
index = value.hits;
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-0.png',
|
|
||||||
'resources/images/tank/${group}/tank_${group.charAt(0)}${value.config.type}_${index}-1.png',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
var t = value.config.type;
|
|
||||||
var h = value.hits;
|
|
||||||
if (t != this.type || h != this.hits) {
|
|
||||||
this.type = t;
|
|
||||||
this.hits = h;
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
view.playing = (value.mx !=0 || value.my != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function dispose():Void {
|
|
||||||
if (view != null) {
|
|
||||||
view.dispose();
|
|
||||||
view = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class BulletItem extends BitmapItem<Bullet> {
|
|
||||||
|
|
||||||
override private function getImage():String {
|
|
||||||
return 'resources/images/bullet/bullet_${value.config.piercing > 1 ? 1 : 0}.png';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class EagleItem extends BitmapItem<Eagle> {
|
|
||||||
|
|
||||||
public var destoyed(default, default):Bool;
|
|
||||||
|
|
||||||
override private function getImage():String {
|
|
||||||
return 'resources/images/eagle/eagle-${destoyed ? 1 : 0}.png';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
33
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
33
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.Bitmap;
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import flash.display.PixelSnapping;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
class BitmapRenderItem extends RenderItem {
|
||||||
|
public var image(default, set):String;
|
||||||
|
|
||||||
|
private var bitmapData:BitmapData;
|
||||||
|
private var bitmap:Bitmap;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle) {
|
||||||
|
super(rect);
|
||||||
|
this.bitmap = new Bitmap(null, PixelSnapping.AUTO, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_view():DisplayObject {
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_image(value:String):String {
|
||||||
|
if (image != value) {
|
||||||
|
image = value;
|
||||||
|
bitmapData = Assets.getBitmapData(image);
|
||||||
|
bitmap.bitmapData = bitmapData;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
class BonusRenderItem extends BitmapRenderItem {
|
||||||
|
|
||||||
|
public var type(default, set):BonusType;
|
||||||
|
private var d = -0.05;
|
||||||
|
private var alpha = 1.0;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle, type:BonusType) {
|
||||||
|
super(rect);
|
||||||
|
this.type = type;
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_type(value:BonusType):BonusType {
|
||||||
|
if (type != value) {
|
||||||
|
type = value;
|
||||||
|
image = 'resources/image/bonus/${type}.png';
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
alpha += d;
|
||||||
|
view.alpha = alpha;
|
||||||
|
if (alpha <= 0 || alpha >= 1.5) {
|
||||||
|
d = -d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
91
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import flash.display.Shape;
|
||||||
|
import openfl.Assets;
|
||||||
|
import openfl.display.DisplayObject;
|
||||||
|
import ru.m.geom.Point;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
import ru.m.tankz.Type.BrickType;
|
||||||
|
|
||||||
|
enum BrickState {
|
||||||
|
UNBROKEN;
|
||||||
|
BROKEN;
|
||||||
|
DESTROYED;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BrickRenderItem extends RenderItem {
|
||||||
|
|
||||||
|
public var type(default, set):BrickType;
|
||||||
|
public var state(get, never):BrickState;
|
||||||
|
|
||||||
|
private var image:BitmapData;
|
||||||
|
private var shape:Shape;
|
||||||
|
private var cells:Array<Point>;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle, type:BrickType) {
|
||||||
|
super(rect);
|
||||||
|
this.shape = new Shape();
|
||||||
|
cells = [
|
||||||
|
new Point(0, 0),
|
||||||
|
new Point(0, 1),
|
||||||
|
new Point(1, 0),
|
||||||
|
new Point(1, 1),
|
||||||
|
];
|
||||||
|
this.type = type;
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_state():BrickState {
|
||||||
|
return switch cells.length {
|
||||||
|
case 0: DESTROYED;
|
||||||
|
case 4: UNBROKEN;
|
||||||
|
case _: BROKEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_view():DisplayObject {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_type(value:BrickType):BrickType {
|
||||||
|
if (type != value) {
|
||||||
|
type = value;
|
||||||
|
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroyCell(x:Int, y:Int):Void {
|
||||||
|
cells = cells.filter(function(point) return !(point.x == x && point.y == y));
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy():Void {
|
||||||
|
cells = [];
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redraw():Void {
|
||||||
|
shape.graphics.clear();
|
||||||
|
if (type == "none") return;
|
||||||
|
switch state {
|
||||||
|
case UNBROKEN:
|
||||||
|
shape.graphics.beginBitmapFill(image);
|
||||||
|
shape.graphics.drawRect(0, 0, rect.width, rect.height);
|
||||||
|
shape.graphics.endFill();
|
||||||
|
case BROKEN:
|
||||||
|
shape.graphics.beginBitmapFill(image);
|
||||||
|
for (point in cells) {
|
||||||
|
var x = point.x * (rect.width / 2);
|
||||||
|
var y = point.y * (rect.width / 2);
|
||||||
|
var width = rect.width / 2;
|
||||||
|
var height = rect.height / 2;
|
||||||
|
shape.graphics.drawRect(x, y, width, height);
|
||||||
|
}
|
||||||
|
shape.graphics.endFill();
|
||||||
|
case DESTROYED:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
22
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
class BulletRenderItem extends BitmapRenderItem {
|
||||||
|
public var piercing(default, set):Int = -1;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle, piercing:Int) {
|
||||||
|
super(rect);
|
||||||
|
this.piercing = piercing;
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_piercing(value:Int):Int {
|
||||||
|
if (piercing != value) {
|
||||||
|
piercing = value;
|
||||||
|
var type = piercing > 0 ? 'piercing' : 'normal';
|
||||||
|
image = 'resources/image/bullet/${type}.png';
|
||||||
|
}
|
||||||
|
return piercing;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
58
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import haxework.color.Color;
|
||||||
|
import haxework.view.utils.BitmapUtil;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
class EagleRenderItem extends BitmapRenderItem {
|
||||||
|
public var color(default, default):Color;
|
||||||
|
public var death(default, set):Bool = true;
|
||||||
|
public var protect(default, set):Bool;
|
||||||
|
|
||||||
|
private var container:Sprite;
|
||||||
|
private var protectView:Animate;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle, color:Color) {
|
||||||
|
super(rect);
|
||||||
|
this.color = color;
|
||||||
|
container = new Sprite();
|
||||||
|
container.addChild(bitmap);
|
||||||
|
protectView = AnimateBundle.tankProtect();
|
||||||
|
protectView.visible = false;
|
||||||
|
container.addChild(protectView);
|
||||||
|
death = false;
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_view():DisplayObject {
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_protect(value:Bool):Bool {
|
||||||
|
if (protect != value) {
|
||||||
|
protect = value;
|
||||||
|
if (protect) {
|
||||||
|
protectView.x = (bitmapData.width - protectView.frames[0].image.width) / 2;
|
||||||
|
protectView.y = (bitmapData.height - protectView.frames[0].image.height) / 2;
|
||||||
|
}
|
||||||
|
protectView.visible = protect;
|
||||||
|
protectView.playing = protect;
|
||||||
|
}
|
||||||
|
return protect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_death(value:Bool):Bool {
|
||||||
|
if (death != value) {
|
||||||
|
death = value;
|
||||||
|
var suffix = death ? '-death' : '';
|
||||||
|
image = 'resources/image/eagle/eagle${suffix}.png';
|
||||||
|
if (!color.zero) {
|
||||||
|
bitmap.bitmapData = bitmapData = BitmapUtil.colorize(bitmapData, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return death;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import ru.m.geom.Position;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
interface IRenderItem {
|
||||||
|
public var view(get, null):DisplayObject;
|
||||||
|
public var rect(default, null):Rectangle;
|
||||||
|
public function move(position:Position):Void;
|
||||||
|
public function update():Void;
|
||||||
|
public function dispose():Void;
|
||||||
|
}
|
||||||
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import ru.m.geom.Position;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
class RenderItem implements IRenderItem {
|
||||||
|
|
||||||
|
public var view(get, null):DisplayObject;
|
||||||
|
public var content(get, null):DisplayObject;
|
||||||
|
|
||||||
|
public var rect(default, null):Rectangle;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle) {
|
||||||
|
this.rect = rect.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_view():DisplayObject {
|
||||||
|
throw "Not Implemented";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_content():DisplayObject {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function move(position:Position):Void {
|
||||||
|
view.x = rect.x = position.x;
|
||||||
|
view.y = rect.y = position.y;
|
||||||
|
if (position.direction != null) {
|
||||||
|
rect.direction = position.direction;
|
||||||
|
if (content != null) {
|
||||||
|
content.rotation = rect.direction.angle;
|
||||||
|
content.x = - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||||
|
content.y = - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||||
|
} else {
|
||||||
|
view.rotation = rect.direction.angle;
|
||||||
|
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||||
|
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update():Void {}
|
||||||
|
|
||||||
|
public function dispose():Void {}
|
||||||
|
}
|
||||||
150
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
150
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import flash.display.BitmapData;
|
||||||
|
import flash.display.DisplayObject;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.text.TextField;
|
||||||
|
import flash.text.TextFieldAutoSize;
|
||||||
|
import flash.text.TextFormat;
|
||||||
|
import haxework.color.Color;
|
||||||
|
import haxework.text.BitmapTextField;
|
||||||
|
import haxework.view.utils.BitmapUtil;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
|
class TankRenderItem extends BitmapRenderItem {
|
||||||
|
public var color(default, default):Color;
|
||||||
|
public var skin(default, set):String;
|
||||||
|
public var hits(default, set):Int;
|
||||||
|
public var bonus(default, set):Bool;
|
||||||
|
public var moves(default, set):Bool;
|
||||||
|
public var protect(default, set):Bool;
|
||||||
|
public var name(default, set):String;
|
||||||
|
|
||||||
|
private var container:Sprite;
|
||||||
|
private var images:Array<BitmapData>;
|
||||||
|
private var frame:Int;
|
||||||
|
private var protectView:Animate;
|
||||||
|
private var nameView:TextField;
|
||||||
|
|
||||||
|
public function new(rect:Rectangle) {
|
||||||
|
super(rect);
|
||||||
|
container = new Sprite();
|
||||||
|
container.addChild(bitmap);
|
||||||
|
protectView = AnimateBundle.tankProtect();
|
||||||
|
protectView.visible = false;
|
||||||
|
container.addChild(protectView);
|
||||||
|
nameView = buildNameView();
|
||||||
|
container.addChild(nameView);
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildNameView():TextField {
|
||||||
|
var result = new BitmapTextField();
|
||||||
|
result.defaultTextFormat = new TextFormat(Style.fontFamily, 10, 0xffffff);
|
||||||
|
result.embedFonts = Style.fontEmbed;
|
||||||
|
result.autoSize = TextFieldAutoSize.LEFT;
|
||||||
|
result.shadowColor = 0x000000;
|
||||||
|
result.stroke = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_view():DisplayObject {
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_content():DisplayObject {
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function redraw():Void {
|
||||||
|
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
||||||
|
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
||||||
|
var color1:Color = switch hits {
|
||||||
|
case 1: 0x869C43;
|
||||||
|
case 2: 0xDEAF80;
|
||||||
|
case 3: 0x5EA67A;
|
||||||
|
case _: color;
|
||||||
|
}
|
||||||
|
var color2:Color = color1;
|
||||||
|
if (bonus) {
|
||||||
|
color1 = 0xff00aa;
|
||||||
|
}
|
||||||
|
if (!color1.zero) {
|
||||||
|
image1 = BitmapUtil.colorize(image1, color1);
|
||||||
|
}
|
||||||
|
if (!color1.zero) {
|
||||||
|
image2 = BitmapUtil.colorize(image2, color2);
|
||||||
|
}
|
||||||
|
images = [for (i in 0...6) image1].concat([for (i in 0...6) image2]);
|
||||||
|
frame = 0;
|
||||||
|
bitmap.bitmapData = images[frame];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_skin(value:String):String {
|
||||||
|
if (skin != value) {
|
||||||
|
skin = value;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_hits(value:Int):Int {
|
||||||
|
if (hits != value) {
|
||||||
|
hits = value;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
return hits;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_bonus(value:Bool):Bool {
|
||||||
|
if (bonus != value) {
|
||||||
|
bonus = value;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_protect(value:Bool):Bool {
|
||||||
|
if (protect != value) {
|
||||||
|
protect = value;
|
||||||
|
if (protect) {
|
||||||
|
protectView.x = (images[0].width - protectView.frames[0].image.width) / 2;
|
||||||
|
protectView.y = (images[0].height - protectView.frames[0].image.height) / 2;
|
||||||
|
}
|
||||||
|
protectView.visible = protect;
|
||||||
|
protectView.playing = protect;
|
||||||
|
}
|
||||||
|
return protect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_moves(value:Bool):Bool {
|
||||||
|
if (moves != value) {
|
||||||
|
moves = value;
|
||||||
|
bitmap.bitmapData = images[0];
|
||||||
|
}
|
||||||
|
return moves;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_name(value:String):String {
|
||||||
|
if (name != value) {
|
||||||
|
name = value;
|
||||||
|
nameView.text = name;
|
||||||
|
nameView.x = (rect.width - nameView.width) / 2;
|
||||||
|
nameView.y = -nameView.height / 2; //(rect.height - nameView.height) / 2;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
if (moves) {
|
||||||
|
frame++;
|
||||||
|
if (frame > images.length - 1) {
|
||||||
|
frame = 0;
|
||||||
|
}
|
||||||
|
bitmap.bitmapData = images[frame];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
128
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
128
src/client/haxe/ru/m/tankz/sound/SoundManager.hx
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
package ru.m.tankz.sound;
|
||||||
|
|
||||||
|
import flash.events.Event;
|
||||||
|
import flash.media.Sound;
|
||||||
|
import flash.media.SoundChannel;
|
||||||
|
import flash.media.SoundTransform;
|
||||||
|
import openfl.utils.Assets;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
|
class SoundManager implements GameListener {
|
||||||
|
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 var config(default, default):Config;
|
||||||
|
public var volume(default, set):Float = 1;
|
||||||
|
public var mute(default, set):Bool = false;
|
||||||
|
|
||||||
|
private var channels:Array<SoundChannel>;
|
||||||
|
private var transform:SoundTransform;
|
||||||
|
|
||||||
|
private var humanTanks:Array<Int>;
|
||||||
|
private var humanBullets:Array<Int>;
|
||||||
|
private var liveBonuses:Array<Int>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
channels = [];
|
||||||
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateSoundTransform():Void {
|
||||||
|
transform = new SoundTransform(mute ? 0 : volume);
|
||||||
|
for (channel in channels) {
|
||||||
|
channel.soundTransform = transform;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_volume(value:Float):Float {
|
||||||
|
if (volume != value) {
|
||||||
|
volume = value;
|
||||||
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_mute(value:Bool):Bool {
|
||||||
|
if (mute != value) {
|
||||||
|
mute = value;
|
||||||
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
return mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function play(id:String):Void {
|
||||||
|
//L.d(TAG, 'play: ${id}');
|
||||||
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||||
|
if (sound != null) {
|
||||||
|
var channel = sound.play(0, 0, transform);
|
||||||
|
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||||
|
channels.push(channel);
|
||||||
|
} else {
|
||||||
|
L.w(TAG, 'Sound "${id}" not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stopAll():Void {
|
||||||
|
for (channel in channels) {
|
||||||
|
channel.stop();
|
||||||
|
}
|
||||||
|
channels = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onSoundComplete(event:Event):Void {
|
||||||
|
channels.remove(event.currentTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
|
switch event {
|
||||||
|
case START(_):
|
||||||
|
play("start");
|
||||||
|
humanTanks = [];
|
||||||
|
liveBonuses = [];
|
||||||
|
humanBullets = [];
|
||||||
|
case SPAWN(BULLET(id, _, playerId, _)):
|
||||||
|
if (config.isHuman(playerId)) {
|
||||||
|
play("shot");
|
||||||
|
humanBullets.push(id);
|
||||||
|
}
|
||||||
|
case SPAWN(TANK(id, _, playerId, _)):
|
||||||
|
if (config.isHuman(playerId)) {
|
||||||
|
humanTanks.push(id);
|
||||||
|
}
|
||||||
|
case SPAWN(BONUS(id, _, type)):
|
||||||
|
play("bonus_add");
|
||||||
|
if (type == "live") {
|
||||||
|
liveBonuses.push(id);
|
||||||
|
}
|
||||||
|
case HIT(TANK(_, _)):
|
||||||
|
play("bullet_hit");
|
||||||
|
case HIT(CELL(_, _, shot)):
|
||||||
|
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
||||||
|
//play("bullet_block");
|
||||||
|
}
|
||||||
|
case DESTROY(TANK(id, _)):
|
||||||
|
if (humanTanks.indexOf(id) > -1) {
|
||||||
|
play("boom_player");
|
||||||
|
} else {
|
||||||
|
play("boom_bot");
|
||||||
|
}
|
||||||
|
case DESTROY(EAGLE(_, _)):
|
||||||
|
play("boom_player");
|
||||||
|
case DESTROY(BONUS(id, _)):
|
||||||
|
play("bonus_get");
|
||||||
|
if (liveBonuses.indexOf(id) > -1) {
|
||||||
|
play("live");
|
||||||
|
} else {
|
||||||
|
play("bonus_get");
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/client/haxe/ru/m/tankz/storage/GameStorage.hx
Normal file
22
src/client/haxe/ru/m/tankz/storage/GameStorage.hx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import haxework.storage.SharedObjectStorage;
|
||||||
|
import ru.m.tankz.game.GameProgress;
|
||||||
|
import ru.m.tankz.Type.GameType;
|
||||||
|
|
||||||
|
class GameStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
private static inline var VERSION = 1;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super('game_${VERSION}');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(type:GameType):GameProgress {
|
||||||
|
return exists(type) ? read(type) : new GameProgress(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set(progress:GameProgress):Void {
|
||||||
|
write(progress.type, progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
21
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import haxework.storage.SharedObjectStorage;
|
||||||
|
|
||||||
|
class NetworkStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
public var user(get, set):User;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super("network");
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_user():User {
|
||||||
|
return read("user");
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_user(value:User):User {
|
||||||
|
write("user", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/client/haxe/ru/m/tankz/storage/RecordStorage.hx
Normal file
39
src/client/haxe/ru/m/tankz/storage/RecordStorage.hx
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import haxe.DynamicAccess;
|
||||||
|
import haxework.storage.SharedObjectStorage;
|
||||||
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
|
|
||||||
|
@:yield class RecordStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
private static inline var VERSION = 1;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super('record_${VERSION}');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(record:GameRecord):Void {
|
||||||
|
L.d("RecordStorage", 'save $record');
|
||||||
|
write('${record.info.id}.info', record.info);
|
||||||
|
write(record.info.id, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function delete(id:String):Void {
|
||||||
|
super.delete(id);
|
||||||
|
super.delete('${id}.info');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function iterator():Iterator<GameRecordInfo> {
|
||||||
|
var data:DynamicAccess<String> = so.data;
|
||||||
|
for (id in data.keys()) {
|
||||||
|
try {
|
||||||
|
if (StringTools.endsWith(id, '.info')) {
|
||||||
|
@yield return read(id);
|
||||||
|
}
|
||||||
|
} catch (error:Dynamic) {
|
||||||
|
L.w("RecordStorage", 'read ', error);
|
||||||
|
delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx
Normal file
52
src/client/haxe/ru/m/tankz/storage/SettingsStorage.hx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
import haxework.storage.SharedObjectStorage;
|
||||||
|
import haxework.utils.ObjectUtil;
|
||||||
|
import ru.m.geom.Direction;
|
||||||
|
import ru.m.tankz.control.ActionConfig;
|
||||||
|
import ru.m.tankz.control.Control.TankAction;
|
||||||
|
|
||||||
|
class SettingsStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super("settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActionConfig(index:Int):ActionConfig {
|
||||||
|
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setActionConffig(index:Int, value:ActionConfig) {
|
||||||
|
write('action:$index', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDefaultActionConfig(index:Int):ActionConfig {
|
||||||
|
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
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},
|
||||||
|
]);
|
||||||
|
}
|
||||||
85
src/client/haxe/ru/m/tankz/view/ClientView.hx
Normal file
85
src/client/haxe/ru/m/tankz/view/ClientView.hx
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
|
import flash.ui.Keyboard;
|
||||||
|
import haxework.resources.IResources;
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
|
|
||||||
|
@:template class ClientView extends VGroupView {
|
||||||
|
@:view("switcher") var switcherView:FrameSwitcher;
|
||||||
|
@:view var username:LabelView;
|
||||||
|
@:view("login") var loginButton:ButtonView;
|
||||||
|
@:view("logout") var logoutButton:ButtonView;
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var resources:IResources;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var soundManager:SoundManager;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
|
public function init():Void {
|
||||||
|
resources.text.put('version', '${Const.VERSION}');
|
||||||
|
switcher = switcherView;
|
||||||
|
network.stateSignal.connect(onConnectionState);
|
||||||
|
onConnectionState(network.state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch():Void {
|
||||||
|
content.stage.stageFocusRect = false;
|
||||||
|
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||||
|
switch event.keyCode {
|
||||||
|
case Keyboard.ESCAPE:
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
|
case Keyboard.M:
|
||||||
|
soundManager.mute = !soundManager.mute;
|
||||||
|
case Keyboard.P:
|
||||||
|
if (game != null) {
|
||||||
|
game.pause = !game.pause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionState(state:ConnectionState):Void {
|
||||||
|
L.d("ClientView", 'onConnectionState: ${state}');
|
||||||
|
switch state {
|
||||||
|
case ONLINE(user):
|
||||||
|
username.text = user.name;
|
||||||
|
logoutButton.visible = true;
|
||||||
|
loginButton.visible = false;
|
||||||
|
case CONNECTED:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = true;
|
||||||
|
case ERROR(error):
|
||||||
|
//L.e("ClientView", 'onConnectionState: ERROR', error);
|
||||||
|
L.w("ClientView", 'onConnectionState: ERROR');
|
||||||
|
case _:
|
||||||
|
username.text = "";
|
||||||
|
logoutButton.visible = false;
|
||||||
|
loginButton.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function login():Void {
|
||||||
|
LoginPopup.instance.show().then(function(user:User):Void {
|
||||||
|
L.d("Login", 'user: $user');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function logout():Void {
|
||||||
|
network.logout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function close():Void {
|
||||||
|
switcher.change(StartFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/client/haxe/ru/m/tankz/view/ClientView.yaml
Executable file
51
src/client/haxe/ru/m/tankz/view/ClientView.yaml
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.frame.FrameSwitcher
|
||||||
|
id: switcher
|
||||||
|
geometry.size.stretch: true
|
||||||
|
skinId: dark
|
||||||
|
views:
|
||||||
|
- id: start
|
||||||
|
$type: ru.m.tankz.view.StartFrame
|
||||||
|
- id: level
|
||||||
|
$type: ru.m.tankz.view.LevelFrame
|
||||||
|
- id: game
|
||||||
|
$type: ru.m.tankz.view.GameFrame
|
||||||
|
- id: result
|
||||||
|
$type: ru.m.tankz.view.ResultFrame
|
||||||
|
- id: settings
|
||||||
|
$type: ru.m.tankz.view.SettingsFrame
|
||||||
|
- id: record
|
||||||
|
$type: ru.m.tankz.view.RecordFrame
|
||||||
|
- id: room_list
|
||||||
|
$type: ru.m.tankz.view.network.RoomListFrame
|
||||||
|
- id: room
|
||||||
|
$type: ru.m.tankz.view.network.RoomFrame
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
skinId: panel
|
||||||
|
layout.margin: 10
|
||||||
|
views:
|
||||||
|
- id: settings
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.settings
|
||||||
|
+onPress: $code:switcher.change('settings')
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: username
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text
|
||||||
|
- id: login
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.login
|
||||||
|
+onPress: $code:login()
|
||||||
|
- id: logout
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.logout
|
||||||
|
+onPress: $code:logout()
|
||||||
|
visible: false
|
||||||
|
- $type: haxework.view.SpriteView
|
||||||
|
geometry.size.width: 50%
|
||||||
|
- id: close
|
||||||
|
$type: haxework.view.ButtonView
|
||||||
|
skinId: button.close
|
||||||
|
+onPress: $code:close()
|
||||||
94
src/client/haxe/ru/m/tankz/view/GameFrame.hx
Normal file
94
src/client/haxe/ru/m/tankz/view/GameFrame.hx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxe.ds.Option;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.sound.SoundManager;
|
||||||
|
import ru.m.tankz.storage.GameStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.view.game.GameView;
|
||||||
|
|
||||||
|
@:template class GameFrame extends VGroupView implements GameListener {
|
||||||
|
public static inline var ID = "game";
|
||||||
|
|
||||||
|
private static inline var TAG = "GameFrame";
|
||||||
|
|
||||||
|
@:view("game") private var gameView(default, null):GameView;
|
||||||
|
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
@:provide var soundManager:SoundManager;
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var record:GameRecord;
|
||||||
|
@:provide("next") var nextState:GameState;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var gameStorage:GameStorage;
|
||||||
|
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
gameView.type = game.type;
|
||||||
|
soundManager.config = game.config;
|
||||||
|
gameView.render.config = game.config;
|
||||||
|
game.connect(gameView.render);
|
||||||
|
game.connect(soundManager);
|
||||||
|
if (gameView.panel != null) {
|
||||||
|
game.connect(gameView.panel);
|
||||||
|
}
|
||||||
|
game.connect(this);
|
||||||
|
game.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function stop():Void {
|
||||||
|
if (game != null) {
|
||||||
|
game.dispose();
|
||||||
|
game = null;
|
||||||
|
}
|
||||||
|
gameView.render.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
|
switch event {
|
||||||
|
case GameEvent.COMPLETE(state, winner):
|
||||||
|
this.state = state;
|
||||||
|
nextState = switch next(winner) {
|
||||||
|
case Some(s):
|
||||||
|
// ToDo:
|
||||||
|
var progress = gameStorage.get(game.type);
|
||||||
|
progress.completeLevel(state.levelId, state.presetId);
|
||||||
|
gameStorage.set(progress);
|
||||||
|
s;
|
||||||
|
case None:
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
stop();
|
||||||
|
switcher.change(ResultFrame.ID);
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToDo:
|
||||||
|
private function next(winner:TeamId):Option<GameState> {
|
||||||
|
for (rule in game.config.game.complete) {
|
||||||
|
if (rule.team != null && rule.team != winner) {
|
||||||
|
return Option.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var level = state.levelId + 1;
|
||||||
|
if (level >= game.config.game.levels) level = 0;
|
||||||
|
return Option.Some(new GameState(game.type, state.presetId, level, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onHide():Void {
|
||||||
|
stop();
|
||||||
|
soundManager.stopAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function close():Void {
|
||||||
|
switcher.change(LevelFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/client/haxe/ru/m/tankz/view/GameFrame.yaml
Normal file
7
src/client/haxe/ru/m/tankz/view/GameFrame.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
views:
|
||||||
|
- id: game
|
||||||
|
$type: ru.m.tankz.view.game.GameView
|
||||||
70
src/client/haxe/ru/m/tankz/view/LevelFrame.hx
Normal file
70
src/client/haxe/ru/m/tankz/view/LevelFrame.hx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.local.LocalGame;
|
||||||
|
import ru.m.tankz.storage.GameStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.view.popup.LevelPopup;
|
||||||
|
|
||||||
|
@:template class LevelFrame extends VGroupView {
|
||||||
|
public static inline var ID = "level";
|
||||||
|
|
||||||
|
@:view var header:LabelView;
|
||||||
|
@:view var levels:DataView<LevelId, ButtonView>;
|
||||||
|
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var levelBundle:ILevelBundle;
|
||||||
|
@:provide var storage:GameStorage;
|
||||||
|
|
||||||
|
private var levelPopup:LevelPopup;
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
header.text = state.type;
|
||||||
|
levels.data = [for (i in 0...state.config.game.levels) i];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||||
|
state.levelId = level.id;
|
||||||
|
state.presetId = preset.id;
|
||||||
|
state.controls = control.values;
|
||||||
|
game = new LocalGame(state);
|
||||||
|
switcher.change(GameFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function levelViewFactory(index:Int, levelId:LevelId):ButtonView {
|
||||||
|
var progress = storage.get(state.type);
|
||||||
|
var result = new ButtonView();
|
||||||
|
result.skinId = "button.level";
|
||||||
|
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(levelId, p.id) ? '*' : '_'].join('');
|
||||||
|
result.text = '${levelId}\n${presetsLine}';
|
||||||
|
result.disabled = !progress.isLevelAvailable(levelId);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onLevelSelect(index:Int, levelId:LevelId, view:ButtonView):Void {
|
||||||
|
if (!storage.get(state.type).isLevelAvailable(levelId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (levelPopup == null) {
|
||||||
|
levelPopup = new LevelPopup();
|
||||||
|
}
|
||||||
|
var level = levelBundle.get(state.type, state.config, levelId);
|
||||||
|
levelPopup.setData(
|
||||||
|
level,
|
||||||
|
state.config.presets,
|
||||||
|
state.config.controls,
|
||||||
|
storage.get(state.type)
|
||||||
|
);
|
||||||
|
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/client/haxe/ru/m/tankz/view/LevelFrame.yaml
Normal file
18
src/client/haxe/ru/m/tankz/view/LevelFrame.yaml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
views:
|
||||||
|
- id: header
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text.header
|
||||||
|
- id: levels
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
geometry.size.width: 100%
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.TailLayout
|
||||||
|
rowSize: 10
|
||||||
|
margin: 5
|
||||||
|
factory: $this:levelViewFactory
|
||||||
|
+onItemSelect: $this:onLevelSelect
|
||||||
|
geometry.padding: 10
|
||||||
28
src/client/haxe/ru/m/tankz/view/RecordFrame.hx
Normal file
28
src/client/haxe/ru/m/tankz/view/RecordFrame.hx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.list.ListView;
|
||||||
|
import haxework.view.list.VListView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
|
import ru.m.tankz.storage.RecordStorage;
|
||||||
|
|
||||||
|
@:template class RecordFrame extends VGroupView {
|
||||||
|
public static var ID(default, never):String = "record";
|
||||||
|
|
||||||
|
@:view var data:VListView<GameRecordInfo>;
|
||||||
|
|
||||||
|
@:provide var recordStorage:RecordStorage;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var record:GameRecord;
|
||||||
|
|
||||||
|
public function onShow():Void {
|
||||||
|
var data = Lambda.array(recordStorage);
|
||||||
|
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||||
|
this.data.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/client/haxe/ru/m/tankz/view/RecordFrame.yaml
Normal file
18
src/client/haxe/ru/m/tankz/view/RecordFrame.yaml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
geometry.padding: 20
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
skinId: text.header
|
||||||
|
text: Records
|
||||||
|
- id: data
|
||||||
|
$type: haxework.view.list.VListView
|
||||||
|
factory: $code:function() return new ru.m.tankz.view.common.RecordView()
|
||||||
|
+onItemSelect: $this:onRecordSelect
|
||||||
|
geometry.margin.top: 20
|
||||||
|
geometry.size.stretch: true
|
||||||
|
scroll:
|
||||||
|
$type: haxework.view.list.VScrollBarView
|
||||||
|
skinId: scroll
|
||||||
51
src/client/haxe/ru/m/tankz/view/ResultFrame.hx
Normal file
51
src/client/haxe/ru/m/tankz/view/ResultFrame.hx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxework.view.ButtonView;
|
||||||
|
import haxework.view.DataView;
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.LabelView;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.GameRunner;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
import ru.m.tankz.view.common.LifeView;
|
||||||
|
|
||||||
|
@:template class ResultFrame extends VGroupView {
|
||||||
|
public static var ID(default, never):String = "result";
|
||||||
|
|
||||||
|
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
||||||
|
@:view("level") var levelLabel:LabelView;
|
||||||
|
|
||||||
|
@:provide var frames:FrameSwitcher;
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide("next") var nextState:GameState;
|
||||||
|
@:provide var game:IGame;
|
||||||
|
|
||||||
|
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||||
|
var view = new LifeView();
|
||||||
|
var playerConfig = state.config.getPlayer(player.id);
|
||||||
|
var tankType = playerConfig.tanks[0].type;
|
||||||
|
var tankConfig = state.config.getTank(tankType);
|
||||||
|
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||||
|
view.color = state.getPlayerColor(player.id);
|
||||||
|
view.life = player.frags;
|
||||||
|
view.score = player.score;
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onShow() {
|
||||||
|
resultView.data = Lambda.array(state.players);
|
||||||
|
levelLabel.text = 'Level ${state.levelId}';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function next() {
|
||||||
|
if (nextState != null) {
|
||||||
|
game = new GameRunner(nextState);
|
||||||
|
frames.change(GameFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function close() {
|
||||||
|
frames.change(LevelFrame.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/tankz/view/ResultFrame.yaml
Normal file
16
src/client/haxe/ru/m/tankz/view/ResultFrame.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
views:
|
||||||
|
- id: level
|
||||||
|
$type: haxework.view.LabelView
|
||||||
|
skinId: text.header
|
||||||
|
- id: result
|
||||||
|
$type: haxework.view.DataView
|
||||||
|
factory: $this:playerViewFactory
|
||||||
|
geometry.margin.top: 20
|
||||||
|
layout:
|
||||||
|
$type: haxework.view.layout.VerticalLayout
|
||||||
|
hAlign: right
|
||||||
|
margin: 10
|
||||||
7
src/client/haxe/ru/m/tankz/view/SettingsFrame.hx
Normal file
7
src/client/haxe/ru/m/tankz/view/SettingsFrame.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
|
||||||
|
@:template class SettingsFrame extends VGroupView {
|
||||||
|
public static var ID(default, never):String = "settings";
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/view/SettingsFrame.yaml
Normal file
15
src/client/haxe/ru/m/tankz/view/SettingsFrame.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.VGroupView
|
||||||
|
skinId: container
|
||||||
|
views:
|
||||||
|
- $type: haxework.view.LabelView
|
||||||
|
skinId: text.header
|
||||||
|
text: Settings
|
||||||
|
- $type: haxework.view.HGroupView
|
||||||
|
layout.margin: 20
|
||||||
|
views:
|
||||||
|
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
|
controlIndex: 0
|
||||||
|
- $type: ru.m.tankz.view.settings.SettingsEditor
|
||||||
|
controlIndex: 1
|
||||||
56
src/client/haxe/ru/m/tankz/view/StartFrame.hx
Normal file
56
src/client/haxe/ru/m/tankz/view/StartFrame.hx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package ru.m.tankz.view;
|
||||||
|
|
||||||
|
import haxework.view.frame.FrameSwitcher;
|
||||||
|
import haxework.view.VGroupView;
|
||||||
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.network.NetworkManager;
|
||||||
|
import ru.m.tankz.Type.GameType;
|
||||||
|
import ru.m.tankz.view.network.RoomListFrame;
|
||||||
|
import ru.m.tankz.view.network.RoomFrame;
|
||||||
|
import ru.m.tankz.view.popup.FontPopup;
|
||||||
|
import ru.m.tankz.view.popup.LoginPopup;
|
||||||
|
|
||||||
|
@:template class StartFrame extends VGroupView {
|
||||||
|
|
||||||
|
public static var ID(default, never):String = "start";
|
||||||
|
|
||||||
|
@:provide var state:GameState;
|
||||||
|
@:provide var switcher:FrameSwitcher;
|
||||||
|
@:provide var network:NetworkManager;
|
||||||
|
|
||||||
|
private var fontPopup:FontPopup;
|
||||||
|
|
||||||
|
private function startGame(type:GameType):Void {
|
||||||
|
state = new GameState(type);
|
||||||
|
switcher.change(LevelFrame.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function startNetwork():Void {
|
||||||
|
switch network.state {
|
||||||
|
case ONLINE(user):
|
||||||
|
if (network.room != null) {
|
||||||
|
switcher.change(RoomFrame.ID);
|
||||||
|
network.joinGame(network.room.game.id, true);
|
||||||
|
} else {
|
||||||
|
switcher.change(RoomListFrame.ID);
|
||||||
|
}
|
||||||
|
case CONNECTED:
|
||||||
|
LoginPopup.instance.show().then(function(user):Void {
|
||||||
|
if (user != null) {
|
||||||
|
switcher.change(RoomListFrame.ID);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function choiceFont():Void {
|
||||||
|
if (fontPopup == null) {
|
||||||
|
fontPopup = new FontPopup();
|
||||||
|
}
|
||||||
|
fontPopup
|
||||||
|
.show()
|
||||||
|
.then(function(font) Style.register(font))
|
||||||
|
.catchError(function(e) {});
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user