Compare commits
284 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 112cd7ba2f | |||
| 77ddd78d84 | |||
| 4fa5cf84fa | |||
| 40bdf6a5cc | |||
| 47039bbaa5 | |||
| 4d7fcb4b4b | |||
| 5f24e85deb | |||
| 42fd008a54 | |||
| c2b0618c93 | |||
| 94f72f71e3 | |||
| bb4b928c89 | |||
| d67d4e5709 | |||
| a4bbeb2573 | |||
| e032c25e1a | |||
| d9cce32bb8 | |||
| 10d5e0df40 | |||
| 0f3392aa0c | |||
| 9d4558ca47 | |||
| 6609756065 | |||
| 605935528b | |||
| f072d8dc6e | |||
| 00cd404a98 | |||
| d47be9ea8a | |||
| 2d70a5652b | |||
| bbf1438728 | |||
| c0496f2e7c | |||
| 636be8611f | |||
| 48f9c433e2 | |||
| 314f5a480c | |||
| 46f2abab05 | |||
| 883f14fb76 | |||
| cc151322d8 | |||
| de64e2813e | |||
| db80c151bb | |||
| ef971e03b9 | |||
| f10da93a12 | |||
| e63b41ae8a | |||
| 43a34cce39 | |||
| b9b5453f89 | |||
| f5af6716d5 | |||
| 7125cc1e9f | |||
| 8a3ceec1ee | |||
| 523f334c1b | |||
| a547b68dc0 | |||
| 45cabc1926 | |||
| 42138cd4ad | |||
| e8e3a6f1b3 | |||
| 6d5148e0a5 | |||
| 262221d969 | |||
| 9eccb263c0 | |||
| ba90b90cd3 | |||
| 94340bddb1 | |||
| 3361d252ee | |||
| 637772f2dd | |||
| f703c76c21 | |||
| 5fe307a218 | |||
| 670a11d6ba | |||
| 1ec1c3baae | |||
| 24f5b0c218 | |||
| b7bc1d244f | |||
| fbc9238d2f | |||
| eb7c311bb6 | |||
| 9640414ba4 | |||
| bc95ca03e2 | |||
| d0ebf05f1c | |||
| 91dd84a437 | |||
| 1b36016a1a | |||
| db0adbac30 | |||
| 948648b313 | |||
| 73822dc95a | |||
| 282bc68734 | |||
| 2ff374abb6 | |||
| f999c66fea | |||
| 2b3f368e0f | |||
| c0ab953115 | |||
| e39de4467d | |||
| 4c3f1ca0fc | |||
| 7fa5a4e048 | |||
| dc1279f636 | |||
| 5798fa9db7 | |||
| c534cf20fd | |||
| 38e14c9269 | |||
| a66b72ba22 | |||
| 2c42d993ca | |||
| a49d673f25 | |||
| ee5de9f3db | |||
| 94b3a94cbb | |||
| caab6ba3a3 | |||
| 7f70c49b87 | |||
| 8f50da64c2 | |||
| 982ca09a23 | |||
| dbf30decae | |||
| abd1b834d7 | |||
| 6ad9076987 | |||
| 78bbf5264e | |||
| 4c8ae66624 | |||
| 5a3d5b974e | |||
| fb9a28c126 | |||
| 7115ea8ac2 | |||
| 01417f5bbd | |||
| abf944418e | |||
| c7946ef1da | |||
| 241499bc2d | |||
| 74297dd9c7 | |||
| 31cb20bf85 | |||
| 1d95de02e1 | |||
| ba13111a8e | |||
| 94b19a1c26 | |||
| 50a0cee044 | |||
| 26ad5f47cd | |||
| 864d5f3335 | |||
| 4b426183e8 | |||
| a5722dfa9d | |||
| 7984d8282c | |||
| 17823ede11 | |||
| 5db3ae1af0 | |||
| bbe2aeb7fb | |||
| 09b188cf24 | |||
| 11f8fc6190 | |||
| 96e608c36f | |||
| 3c116db135 | |||
| efe826110c | |||
| c1ff14111d | |||
| cd7dd1984b | |||
| 686c659c84 | |||
| 797dfca2be | |||
| aa10825b12 | |||
| 608ed3acc4 | |||
| 03b461f082 | |||
| cbb28f4158 | |||
| 13240677b0 | |||
| b0ae85334b | |||
| 183c6c16f1 | |||
| a7f286dc42 | |||
| 20b60009e3 | |||
| d6b572aead | |||
| d11d0ac53f | |||
| ab02460b11 | |||
| fc18e2e0b7 | |||
| 363a48bb1b | |||
| e9de677ceb | |||
| 5ff7b19475 | |||
| 7ddba8f69b | |||
| b86e0ddd20 | |||
| a3f3de3af5 | |||
| 4a4ca463c3 | |||
| 13d01293f6 | |||
| d0104e4361 | |||
| c3db9f2414 | |||
| f34d35e03a | |||
| 9868d27bc3 | |||
| c0b4b2a4c1 | |||
| 9dc0a4ce06 | |||
| c58735ea43 | |||
| 4e2b65c225 | |||
| 663935bd75 | |||
| d1ed17d1d7 | |||
| 135ad0d992 | |||
| 8fb1d6132d | |||
| f60feea6e8 | |||
| d7b7744eb8 | |||
| 2eb606aa21 | |||
| a86c4fc447 | |||
| 1ea216fd20 | |||
| 121c470b00 | |||
| 404dd77806 | |||
| d2f23e7777 | |||
| fd0e2382d0 | |||
| e609dafedc | |||
| a948dfbaad | |||
| 5b804c6902 | |||
| 556cd2f1a9 | |||
| 7d570336a5 | |||
| a9b591a7ca | |||
| 216e1aa476 | |||
| 4d8de90419 | |||
| 0b17fbf804 | |||
| c6639e11b1 | |||
| e6f9aa8ba1 | |||
| 2c191d932c | |||
| d52b94d095 | |||
| c67385576e | |||
| f09e70c5f8 | |||
| 0f5cf7fdc5 | |||
| 426b2718bb | |||
| 8ea862a118 | |||
| 1f87a71833 | |||
| 56c2cd9437 | |||
| 85e5f9a553 | |||
| d9915120d4 | |||
| 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 |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,6 +9,6 @@ out/
|
||||
.idea/
|
||||
.ideaDataSources/
|
||||
config.json
|
||||
package-lock.json
|
||||
/node_modules
|
||||
/log
|
||||
/ansible/*.retry
|
||||
|
||||
44
CHANGELOG.md
Normal file
44
CHANGELOG.md
Normal file
@@ -0,0 +1,44 @@
|
||||
0.17.0
|
||||
------
|
||||
* Improved `ResultFrame`
|
||||
* Improved bonuses
|
||||
* Set `DeviceType.SCREEN` as default on mobile devices
|
||||
|
||||
0.16.0
|
||||
------
|
||||
* Added `GamepadView` for sensor control
|
||||
* Added `AppTheme`
|
||||
* Replace `LevelPopup` with `StartFrame`
|
||||
* Added `LevelPack`
|
||||
* Added scrolls to lists
|
||||
* Fixed `GameView` size for small screens
|
||||
|
||||
0.15.0
|
||||
------
|
||||
* Added display tank player name in `Render`
|
||||
* Fixed join game after relogin
|
||||
* Updated `CreateGamePopup` for any screen sizes
|
||||
* Fixed tank destroy zero score label
|
||||
* Added custom size map support
|
||||
* Fixed clock bonus for spawned tanks
|
||||
|
||||
0.14.0
|
||||
------
|
||||
* Added `CreateGamePopup`
|
||||
* Fixed null tank color
|
||||
* Updated `Ticker`
|
||||
|
||||
0.13.0
|
||||
------
|
||||
* Added `Ticker`
|
||||
* Fixed `PacketQueue` stream reading
|
||||
* Added `PlayerControl` and `ControlPreset`
|
||||
* Added `BaseControlFactory`
|
||||
|
||||
0.12.0
|
||||
------
|
||||
* Added `GameRoomFrame`
|
||||
* Improved websocket connection with using binary protocol instead of text
|
||||
* Added `GameListFrame`
|
||||
* Added `DesktopConnection` for linux client build
|
||||
* Updated `SoundManager`
|
||||
84
WORK.md
84
WORK.md
@@ -1,62 +1,22 @@
|
||||
* build
|
||||
* gulp 100%
|
||||
* linux 100%
|
||||
* deb-package 100%
|
||||
* windows 0%
|
||||
* exe-package 0% (inno setup)
|
||||
|
||||
* deploy
|
||||
* capistrano 100%
|
||||
|
||||
* ui
|
||||
* auth frame 0%
|
||||
* select game frame 30% (classic 1/2 player, dota singe/coop/vs)
|
||||
* select level frame 10%
|
||||
* game frame 50%
|
||||
|
||||
* engine
|
||||
* config 100%
|
||||
* map 100%
|
||||
* tanks 100%
|
||||
* bullets 100%
|
||||
* boxes 100%
|
||||
* map changes 100%
|
||||
* bonuses 0%
|
||||
* eagle 100%
|
||||
|
||||
* game
|
||||
* classic
|
||||
* state 50%
|
||||
* bot 50%
|
||||
* player: 50%
|
||||
* dota
|
||||
* state 50%
|
||||
* bot 10%
|
||||
* player 0%
|
||||
|
||||
* state
|
||||
* score 0%
|
||||
* save/load 0%
|
||||
* export/import 0%
|
||||
|
||||
* render
|
||||
* map 100%
|
||||
* tanks 100%
|
||||
* bullet 100%
|
||||
* calc redraw 50%
|
||||
* animations
|
||||
* tank spawn 0%
|
||||
* tank move 100%
|
||||
* map water 0%
|
||||
* bullet boom 90%
|
||||
* tank boom 90%
|
||||
* bonuses 0%
|
||||
* html5 50%
|
||||
|
||||
* proto
|
||||
...
|
||||
|
||||
* editor
|
||||
* open 0%
|
||||
* edit 0%
|
||||
* save 0%
|
||||
* bonuses
|
||||
* death game bonuses
|
||||
* boat bonus
|
||||
* tanks and bullets speed balancing
|
||||
* game series
|
||||
* network series
|
||||
* map packs
|
||||
* create in editor
|
||||
* import in game
|
||||
* save imported in local storage
|
||||
* database
|
||||
* cache
|
||||
* improve bots
|
||||
* A star
|
||||
* game config validate
|
||||
* additional weapon
|
||||
* mine
|
||||
* display count
|
||||
* bonus ammo
|
||||
* screen gamepad (button enabled, count label)
|
||||
* ui:
|
||||
* game frame layouts
|
||||
|
||||
11
ansible/ansible.cfg
Normal file
11
ansible/ansible.cfg
Normal file
@@ -0,0 +1,11 @@
|
||||
[defaults]
|
||||
hash_behaviour = merge
|
||||
host_key_checking = False
|
||||
#callback_whitelist = profile_tasks
|
||||
display_skipped_hosts = False
|
||||
stdout_callback = yaml
|
||||
bin_ansible_callbacks = True
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
||||
ssh_args = -o ForwardAgent=yes
|
||||
14
ansible/deploy.yml
Normal file
14
ansible/deploy.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
ansible_user: "{{ deploy_user }}"
|
||||
roles:
|
||||
- ansible-deploy
|
||||
- build
|
||||
post_tasks:
|
||||
- include_role:
|
||||
name: ansible-deploy
|
||||
tasks_from: complete.yml
|
||||
- include_role:
|
||||
name: service
|
||||
tasks_from: restart.yml
|
||||
2
ansible/dev/inventory.yml
Normal file
2
ansible/dev/inventory.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
hosts: localhost
|
||||
15
ansible/group_vars/all.yml
Normal file
15
ansible/group_vars/all.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
project_name: tankz
|
||||
project_user: holop
|
||||
|
||||
deploy_user: "{{ project_user }}"
|
||||
deploy_project: "{{ project_name }}"
|
||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||
deploy_repo_version: develop
|
||||
deploy_npm: yes
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
service_work_dir: "{{ deploy_current_dir }}/target/server/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,35 +0,0 @@
|
||||
const gulp = require('gulp');
|
||||
const yargs = require('yargs');
|
||||
const Haxe = require('../tasks/haxe');
|
||||
const FlashPlayer = require('../tasks/flashplayer');
|
||||
const version = require('./version');
|
||||
const prepare = require('./prepare');
|
||||
const debug = require('../tasks/debug');
|
||||
|
||||
|
||||
const build = (platform) => function build() {
|
||||
const argv = yargs.argv;
|
||||
return gulp.src('.')
|
||||
.pipe(new Haxe().openfl({
|
||||
command: 'build',
|
||||
platform: platform,
|
||||
version: version,
|
||||
values: {
|
||||
build_editor: true
|
||||
},
|
||||
debug: argv.dev,
|
||||
}))
|
||||
.pipe(gulp.dest(`target/${platform}`));
|
||||
};
|
||||
|
||||
|
||||
const testFlash = function() {
|
||||
const argv = yargs.argv;
|
||||
return build('flash')()
|
||||
.pipe(new FlashPlayer().run(argv.dev))
|
||||
.pipe(debug());
|
||||
};
|
||||
|
||||
|
||||
exports['editor:flash'] = gulp.series(prepare(Haxe.ID), build('flash'));
|
||||
exports['editor:flash:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), testFlash);
|
||||
@@ -1,32 +0,0 @@
|
||||
const AdobeAir = require('../tasks/adobeAir');
|
||||
const Haxe = require('../tasks/haxe');
|
||||
const FlashPlayer = require('../tasks/flashplayer');
|
||||
const packageInfo = require('../package.json');
|
||||
|
||||
|
||||
const prepareOne = (value) => {
|
||||
switch (value) {
|
||||
case Haxe.ID:
|
||||
const haxe = new Haxe();
|
||||
return haxe.prepare().then(() => haxe.install(packageInfo.haxeDependencies));
|
||||
case AdobeAir.ID:
|
||||
return new AdobeAir().prepare();
|
||||
case FlashPlayer.ID:
|
||||
return new FlashPlayer().prepare();
|
||||
default:
|
||||
throw Error(`Unknown target: ${value}`)
|
||||
}
|
||||
};
|
||||
|
||||
const prepare = (...targets) => function prepare() {
|
||||
const tasks = targets.map((target) => prepareOne(target));
|
||||
return Promise.all(tasks);
|
||||
};
|
||||
|
||||
|
||||
const update = () => {
|
||||
return new Haxe().upgrade();
|
||||
};
|
||||
|
||||
module.exports = prepare;
|
||||
module.exports.update = update;
|
||||
@@ -1,43 +0,0 @@
|
||||
const gulp = require('gulp');
|
||||
const yargs = require('yargs');
|
||||
const Haxe = require('../tasks/haxe');
|
||||
const FlashPlayer = require('../tasks/flashplayer');
|
||||
const Neko = require('../tasks/neko');
|
||||
const version = require('./version');
|
||||
const prepare = require('./prepare');
|
||||
const debug = require('../tasks/debug');
|
||||
|
||||
|
||||
const build = () => function build() {
|
||||
const argv = yargs.argv;
|
||||
return gulp.src('.')
|
||||
.pipe(new Haxe().build({
|
||||
platform: 'neko',
|
||||
version: version,
|
||||
lib: [
|
||||
'protohx',
|
||||
'orm',
|
||||
'haxework:git',
|
||||
],
|
||||
cp: [
|
||||
'src/common/haxe',
|
||||
'src/server/haxe',
|
||||
'src-gen/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
outputFile: 'tankz.n',
|
||||
debug: argv.dev,
|
||||
}))
|
||||
.pipe(gulp.dest('target'));
|
||||
};
|
||||
|
||||
const test = (build) => function test() {
|
||||
const argv = yargs.argv;
|
||||
return build()
|
||||
.pipe(new Neko().run(argv.dev))
|
||||
.pipe(debug());
|
||||
};
|
||||
|
||||
|
||||
exports['server'] = gulp.series(prepare(Haxe.ID), build());
|
||||
exports['server:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), test(build()));
|
||||
@@ -1,2 +0,0 @@
|
||||
const packageInfo = require('../package.json');
|
||||
module.exports = packageInfo.version;
|
||||
11
capfile
11
capfile
@@ -1,11 +0,0 @@
|
||||
require 'capistrano/setup'
|
||||
require 'capistrano/deploy'
|
||||
require 'capistrano/scm/git'
|
||||
install_plugin Capistrano::SCM::Git
|
||||
require 'capistrano/scm/git-with-submodules'
|
||||
install_plugin Capistrano::SCM::Git::WithSubmodules
|
||||
require 'capistrano/npm'
|
||||
require 'capistrano/gulp'
|
||||
require 'airbrussh/capistrano'
|
||||
|
||||
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"SdkDir": "C:\\sdk",
|
||||
"PublishDir": "",
|
||||
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{
|
||||
"SdkDir": "/home/holop/sdk",
|
||||
"PublishDir": "/opt/repo/tankz",
|
||||
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
|
||||
@@ -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
|
||||
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 \
|
||||
-c ru.m.tankz.db \
|
||||
-a ru.m.tankz.db
|
||||
196
gulpfile.js
196
gulpfile.js
@@ -1,36 +1,188 @@
|
||||
"use strict";
|
||||
const os = require('os');
|
||||
const gulp = require('gulp');
|
||||
const clean = require('gulp-clean');
|
||||
const Sdk = require('./tasks/sdk');
|
||||
const FlashPlayer = require('./tasks/flashplayer');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const Config = require('./config.json');
|
||||
const prepare = require('./build/prepare');
|
||||
|
||||
//FlashPlayer.VERSION = '25.0.0.171';
|
||||
const packageInfo = require('./package.json');
|
||||
const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
|
||||
const dateformat = require('dateformat');
|
||||
const argv = require('yargs').argv;
|
||||
const publish = require('./tasks/gulp-publish');
|
||||
|
||||
if (Config.SdkDir) {
|
||||
Sdk.dir = Config.SdkDir;
|
||||
}
|
||||
|
||||
exports.clean = () => {
|
||||
return gulp.src('target/*', {read: false}).pipe(clean());
|
||||
exports.clean = function clean() {
|
||||
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
||||
};
|
||||
|
||||
const merge = (value) => {
|
||||
if (typeof value === 'string') {
|
||||
value = require(value);
|
||||
}
|
||||
for (let key in value) if (value.hasOwnProperty(key)) {
|
||||
exports[key] = value[key];
|
||||
exports.generate = function generate() {
|
||||
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => {
|
||||
if (stdout.indexOf('FAIL') > -1) {
|
||||
throw stdout;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.update = prepare.update;
|
||||
merge('./build/prepare');
|
||||
merge('./build/client');
|
||||
merge('./build/editor');
|
||||
merge('./build/server');
|
||||
/**
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
title: 'Tank\'z',
|
||||
filename: 'tankz',
|
||||
icon: 'src/client/resources/icon.png',
|
||||
pack: 'ru.m.tankz',
|
||||
author: 'shmyga <shmyga.z@gmail.com>',
|
||||
company: 'MegaLoMania',
|
||||
version: packageInfo.version,
|
||||
},
|
||||
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.WINDOWS,
|
||||
Project.Platform.ANDROID,
|
||||
],
|
||||
config.branch({
|
||||
name: 'client',
|
||||
sources: [
|
||||
//'src/fixes/haxe',
|
||||
'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})`,
|
||||
]
|
||||
}),
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* editor
|
||||
*/
|
||||
const editor = new Project(
|
||||
Project.BuildSystem.OPENFL,
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
],
|
||||
config.branch({
|
||||
name: 'editor',
|
||||
sources: [
|
||||
//'src/fixes/haxe',
|
||||
'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: 768,
|
||||
},
|
||||
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',
|
||||
}),
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
|
||||
|
||||
/**
|
||||
* default
|
||||
*/
|
||||
const defaultSeries = [
|
||||
exports.clean,
|
||||
exports.generate,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:flash:html'],
|
||||
module.exports['client:html5:build'],
|
||||
|
||||
module.exports['editor:flash:build'],
|
||||
module.exports['editor:flash:html'],
|
||||
module.exports['editor:html5:build'],
|
||||
|
||||
module.exports['server:neko:build'],
|
||||
];
|
||||
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(
|
||||
module.exports['client:linux:build'],
|
||||
module.exports['client:linux:archive'],
|
||||
module.exports['client:linux:deb'],
|
||||
|
||||
module.exports['client:android:build'],
|
||||
);
|
||||
}
|
||||
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(
|
||||
module.exports['client:windows:build'],
|
||||
module.exports['client:windows:archive'],
|
||||
module.exports['client:windows:installer'],
|
||||
);
|
||||
}
|
||||
|
||||
defaultSeries.push(
|
||||
exports.publish,
|
||||
);
|
||||
|
||||
module.exports.default = gulp.series(defaultSeries);
|
||||
|
||||
7337
package-lock.json
generated
Normal file
7337
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@@ -1,42 +1,25 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.6.0",
|
||||
"version": "0.17.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"ansi-colors": "^1.0.1",
|
||||
"async": "^2.6.0",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"download": "^6.2.5",
|
||||
"fancy-log": "^1.3.2",
|
||||
"fs-extra": "^5.0.0",
|
||||
"got": "^8.0.1",
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"gulp-babel": "^7.0.0",
|
||||
"gulp-clean": "^0.3.2",
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-debian": "^0.1.9",
|
||||
"gulp-run": "^1.7.1",
|
||||
"gulp-template": "^5.0.0",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"gulp-webserver": "^0.9.1",
|
||||
"plugin-error": "^0.1.2",
|
||||
"progress": "^2.0.0",
|
||||
"promise-streams": "^2.1.1",
|
||||
"rmdir": "^1.2.0",
|
||||
"tar": "^4.2.0",
|
||||
"tmp-file": "^2.0.1",
|
||||
"unzip-stream": "^0.2.1",
|
||||
"vinyl-fs": "^3.0.1",
|
||||
"yargs": "^10.0.3"
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "0.1.0",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"lime": "6.0.1",
|
||||
"openfl": "7.0.0",
|
||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||
"lime": "7.5.0",
|
||||
"openfl": "8.9.1",
|
||||
"hxcpp": "4.0.52",
|
||||
"promhx": "1.1.0",
|
||||
"protohx": "0.4.6",
|
||||
"yaml": "1.3.0",
|
||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||
"orm": "2.1.0"
|
||||
"orm": "2.1.0",
|
||||
"haxe-crypto": "0.0.7",
|
||||
"svg": "1.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
28
project.xml
28
project.xml
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/>
|
||||
<app main="ru.m.tankz.Client" path="target" file="tankz"/>
|
||||
<source path="src/common/haxe"/>
|
||||
<source path="src/client/haxe"/>
|
||||
<source path="src-gen/haxe"/>
|
||||
<assets path="src/client/resources" rename="resources" include="*"/>
|
||||
<haxelib name="lime" version="6.0.1"/>
|
||||
<haxelib name="openfl" version="7.0.0"/>
|
||||
<haxelib name="promhx" version="1.1.0"/>
|
||||
<haxelib name="protohx" version="0.4.6"/>
|
||||
<haxelib name="haxework" version="git"/>
|
||||
<haxelib name="yaml" version="1.3.0"/>
|
||||
<window fps="30"/>
|
||||
<window width="1024" height="768" unless="html5"/>
|
||||
<haxeflag name="-D" value="swf-gpu"/>
|
||||
<haxeflag name="-D" value="native-trace"/>
|
||||
<!--<haxeflag name="-D" value="proto_debug"/>-->
|
||||
<haxeflag name="-dce" value="no"/>
|
||||
<haxeflag name="-D" value="dom"/>
|
||||
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
|
||||
|
||||
<section if="build_editor">
|
||||
<app main="ru.m.tankz.editor.Editor" path="target" file="editor"/>
|
||||
<source path="src/editor/haxe"/>
|
||||
</section>
|
||||
</project>
|
||||
@@ -3,6 +3,7 @@
|
||||
"protoFiles": [
|
||||
"src/common/proto/core.proto",
|
||||
"src/common/proto/game.proto",
|
||||
"src/common/proto/room.proto",
|
||||
"src/common/proto/pack.proto"
|
||||
],
|
||||
"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 |
31
sql/init.sql
31
sql/init.sql
@@ -1,31 +0,0 @@
|
||||
-- mysql -u shmyga -pxkbp8jh9z2 armageddon --protocol TCP
|
||||
CREATE USER 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||
|
||||
DROP DATABASE IF EXISTS armageddon;
|
||||
CREATE DATABASE IF NOT EXISTS armageddon;
|
||||
GRANT ALL ON armageddon.* TO 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS armageddon.account;
|
||||
CREATE TABLE IF NOT EXISTS armageddon.account (
|
||||
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
login VARCHAR(255) UNIQUE,
|
||||
password VARCHAR(32)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS armageddon.person;
|
||||
CREATE TABLE IF NOT EXISTS armageddon.person (
|
||||
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
account_id INT UNSIGNED NOT NULL,
|
||||
name VARCHAR(255),
|
||||
|
||||
CONSTRAINT person_2_account FOREIGN KEY (account_id) REFERENCES armageddon.account(id)
|
||||
MATCH SIMPLE ON DELETE CASCADE ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
INSERT INTO armageddon.account (id,login,password) VALUES(1,'shmyga', 'd48cc4eb42c058869ae90daef9606e43');
|
||||
INSERT INTO armageddon.person (id,account_id,name) VALUES(1,1,'-=Shmyga=-');
|
||||
|
||||
INSERT INTO armageddon.account (id,login,password) VALUES(2,'a', md5('a'));
|
||||
INSERT INTO armageddon.person (id,account_id,name) VALUES(2,2,'a');
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Type=Application
|
||||
Comment=Tank'z game
|
||||
Exec=bash -c 'cd "/usr/share/tankz" && ./tankz'
|
||||
Icon=/usr/share/tankz/resources/images/tank/player/tank_p3_0-0.png
|
||||
Name=Tank'z
|
||||
Categories=Game
|
||||
Terminal=false
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"pWidth": 100, "pHeight": 100,
|
||||
"views": [
|
||||
{
|
||||
"id": "state", "@type": "haxework.gui.LabelView", "@style": "label",
|
||||
"pWidth": 100, "height": 20
|
||||
},
|
||||
{
|
||||
"id": "render", "@type": "ru.m.tankz.render.Render",
|
||||
"contentSize": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"pWidth": 100, "pHeight": 100,
|
||||
"views": [
|
||||
{
|
||||
"id":"levels", "@type":"haxework.gui.list.VListView<Int>",
|
||||
"factory": "@class:ru.m.tankz.view.frames.list.LevelView",
|
||||
"pWidth":100,
|
||||
"pHeight":100,
|
||||
"paddings":10,
|
||||
"scroll":{
|
||||
"@type":"haxework.gui.list.VScrollView",
|
||||
"width":10, "pHeight":100,
|
||||
"skin":{"@type":"haxework.gui.list.VScrollSkin"}
|
||||
},
|
||||
"skin": {
|
||||
"@type": "haxework.gui.skin.ColorSkin",
|
||||
"color": "0x000000", "alpha": 0.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"pWidth": 100, "pHeight": 100,
|
||||
"views": [
|
||||
{
|
||||
"@type": "haxework.gui.ImageView",
|
||||
"image": "@asset:image:resources/images/logo/logo.png",
|
||||
"contentSize": true, "bottomMargin": 15
|
||||
},
|
||||
{
|
||||
"@type": "haxework.gui.LabelView", "@style": "label",
|
||||
"fontSize": 20, "topMargin": 15,
|
||||
"contentSize": true,
|
||||
"text": "Classic"
|
||||
},
|
||||
{
|
||||
"id": "classic_1p",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "1 Player",
|
||||
"@style": "button"
|
||||
},
|
||||
{
|
||||
"id": "classic_2p",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "2 Player",
|
||||
"@style": "button"
|
||||
},
|
||||
{
|
||||
"@type": "haxework.gui.LabelView", "@style": "label",
|
||||
"fontSize": 20, "topMargin": 15,
|
||||
"contentSize": true,
|
||||
"text": "DotA"
|
||||
},
|
||||
{
|
||||
"id": "dota_1p",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "1 Player",
|
||||
"@style": "button"
|
||||
},
|
||||
{
|
||||
"id": "dota_2p_coop",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "2 COOP",
|
||||
"@style": "button"
|
||||
},
|
||||
{
|
||||
"id": "dota_2p_vs",
|
||||
"@type": "haxework.gui.ButtonView",
|
||||
"text": "2 VS",
|
||||
"@style": "button"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"@type": "haxework.gui.VGroupView",
|
||||
"pWidth": 100, "pHeight": 100,
|
||||
"views": [
|
||||
{
|
||||
"id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher",
|
||||
"pWidth": 100, "pHeight": 100,
|
||||
"skin": {
|
||||
"@type": "haxework.gui.skin.BitmapSkin",
|
||||
"image": "@asset:image:resources/images/background.png",
|
||||
"fillType": "REPEAT"
|
||||
},
|
||||
"views": [
|
||||
{
|
||||
"id": "start",
|
||||
"@type": "ru.m.tankz.view.frames.StartFrame"
|
||||
},
|
||||
{
|
||||
"id": "level",
|
||||
"@type": "ru.m.tankz.view.frames.LevelFrame"
|
||||
},
|
||||
{
|
||||
"id": "game",
|
||||
"@type": "ru.m.tankz.view.frames.GameFrame"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"@type": "haxework.gui.LabelView",
|
||||
"inLayout": false,
|
||||
"contentSize": true,
|
||||
"vAlign": "BOTTOM",
|
||||
"hAlign": "RIGHT",
|
||||
"text": "@res:text:version",
|
||||
"@style": "label"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"level": {
|
||||
"width": 440, "height": 44,
|
||||
"margins": 5,
|
||||
"views": [
|
||||
{
|
||||
"id": "label",
|
||||
"@type": "haxework.gui.LabelView",
|
||||
"pWidth": 100, "pHeight": 100, "text": "",
|
||||
"@style": "label"
|
||||
}
|
||||
],
|
||||
"skin": {
|
||||
"@type": "haxework.gui.skin.ColorSkin",
|
||||
"color": "0x000000", "alpha": 0.2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"button": {
|
||||
"width":250, "height":60,
|
||||
"skin": {
|
||||
"@type": "haxework.gui.skin.ButtonBitmapSkin",
|
||||
"upImage": "@asset:image:resources/images/control/button_normal.png",
|
||||
"downImage": "@asset:image:resources/images/control/button_down.png",
|
||||
"overImage": "@asset:image:resources/images/control/button_over.png",
|
||||
"fillType": "NINEPATH"
|
||||
},
|
||||
"fontFamily":"@res:text:font", "fontEmbed":true, "fontColor":"0xE7E0BB", "fontSize":20
|
||||
},
|
||||
|
||||
"label": {
|
||||
"fontColor": "0xffffff",
|
||||
"fontEmbed": false,
|
||||
"fontFamily": "@res:text:fontName",
|
||||
"fontSize": 16,
|
||||
"shadowColor": "0x000000"
|
||||
},
|
||||
|
||||
"input": {
|
||||
"fontColor": "0xffffff",
|
||||
"fontEmbed": false,
|
||||
"fontFamily": "@res:text:fontName",
|
||||
"fontSize": 16,
|
||||
"shadowColor": "0x000000",
|
||||
"skin": {
|
||||
"@type": "haxework.gui.skin.ColorSkin",
|
||||
"color": "0x000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/client/haxe/ru/m/Device.hx
Normal file
42
src/client/haxe/ru/m/Device.hx
Normal file
@@ -0,0 +1,42 @@
|
||||
package ru.m;
|
||||
|
||||
@:enum abstract Platform(String) from String to String {
|
||||
var ANDROID = "android";
|
||||
var LINUX = "linux";
|
||||
var WINDOWS = "windows";
|
||||
}
|
||||
|
||||
class Device {
|
||||
|
||||
public static var platform(get, null):Platform;
|
||||
|
||||
private static function get_platform():Platform {
|
||||
#if android
|
||||
return ANDROID;
|
||||
#elseif linux
|
||||
return LINUX;
|
||||
#elseif windows
|
||||
return WINDOWS;
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
private static var MOBILES(default, never):Array<String> = [
|
||||
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
||||
];
|
||||
|
||||
public static function isMobile():Bool {
|
||||
#if android
|
||||
return true;
|
||||
#elseif js
|
||||
var userAgent = js.Browser.navigator.userAgent;
|
||||
for (mobile in MOBILES) {
|
||||
if (userAgent.indexOf(mobile) > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#end
|
||||
return false;
|
||||
}
|
||||
}
|
||||
82
src/client/haxe/ru/m/Updater.hx
Normal file
82
src/client/haxe/ru/m/Updater.hx
Normal file
@@ -0,0 +1,82 @@
|
||||
package ru.m;
|
||||
|
||||
import haxework.net.JsonLoader;
|
||||
import openfl.Lib;
|
||||
import openfl.net.URLRequest;
|
||||
import promhx.Promise;
|
||||
import ru.m.Device;
|
||||
|
||||
@:enum abstract PackageType(String) from String to String {
|
||||
var APK = "apk";
|
||||
var DEB = "deb";
|
||||
var EXE = "exe";
|
||||
var ARCHIVE = "archive";
|
||||
}
|
||||
|
||||
typedef PackageInfo = {
|
||||
var platform:Platform;
|
||||
var type:PackageType;
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
}
|
||||
|
||||
typedef PackagesBundle = {
|
||||
var name:String;
|
||||
var version:String;
|
||||
var packages:Array<PackageInfo>;
|
||||
}
|
||||
|
||||
class Updater {
|
||||
|
||||
private static inline var TAG = "Update";
|
||||
|
||||
public var type(get, null):PackageType;
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
|
||||
private var url:String;
|
||||
private var version:String;
|
||||
|
||||
public function new(version:String, url:String) {
|
||||
this.url = url;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private function get_type():PackageType {
|
||||
return switch Device.platform {
|
||||
case ANDROID: APK;
|
||||
case LINUX: DEB;
|
||||
case WINDOWS: EXE;
|
||||
case _: null;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveBundle():Promise<PackagesBundle> {
|
||||
return bundle != null ? Promise.promise(bundle) : new JsonLoader().GET(url).then(function(bundle) {
|
||||
this.bundle = bundle;
|
||||
return this.bundle;
|
||||
});
|
||||
}
|
||||
|
||||
public function check():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
|
||||
this.bundle = bundle;
|
||||
return bundle.version != version && Lambda.exists(bundle.packages, function(item) {
|
||||
return item.platform == Device.platform && item.type == type;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function download():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle) {
|
||||
for (item in bundle.packages) {
|
||||
if (item.platform == Device.platform && item.type == type) {
|
||||
L.i(TAG, 'download: ${item.url}');
|
||||
Lib.getURL(new URLRequest(item.url));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,11 @@ import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
|
||||
typedef Frame = {
|
||||
var image:BitmapData;
|
||||
var length:Int;
|
||||
}
|
||||
|
||||
class Animate extends Bitmap {
|
||||
|
||||
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 frames(default, set):Array<BitmapData>;
|
||||
public var frames(default, set):Array<Frame>;
|
||||
|
||||
private var sequence:Array<BitmapData>;
|
||||
private var index:Int;
|
||||
|
||||
public function new(?frames:Array<BitmapData>) {
|
||||
public function new(?frames:Array<Frame>) {
|
||||
super(null, PixelSnapping.AUTO, true);
|
||||
this.frames = frames == null ? [] : frames;
|
||||
init();
|
||||
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) {
|
||||
frames = value;
|
||||
bitmapData = frames[0];
|
||||
index = 0;
|
||||
for (frame in frames) {
|
||||
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||
}
|
||||
bitmapData = sequence[0];
|
||||
} else {
|
||||
bitmapData = null;
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
@@ -56,10 +67,10 @@ class Animate extends Bitmap {
|
||||
}
|
||||
|
||||
private function update():Void {
|
||||
if (++index >= frames.length) {
|
||||
if (++index >= sequence.length) {
|
||||
index = 0;
|
||||
}
|
||||
var nextBitmapData = frames[index];
|
||||
var nextBitmapData = sequence[index];
|
||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||
bitmapData = nextBitmapData;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package ru.m.animate;
|
||||
|
||||
import promhx.Deferred;
|
||||
import flash.display.BitmapData;
|
||||
import promhx.Promise;
|
||||
|
||||
|
||||
@@ -9,10 +8,6 @@ class OnceAnimate extends Animate {
|
||||
|
||||
private var deferred:Deferred<Animate>;
|
||||
|
||||
public function new(frames:Array<BitmapData>) {
|
||||
super(frames);
|
||||
}
|
||||
|
||||
public function play():Promise<Animate> {
|
||||
deferred = new Deferred();
|
||||
playing = true;
|
||||
|
||||
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
43
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
@@ -0,0 +1,43 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.control.IControlBus;
|
||||
|
||||
class ControlBus implements IControlBus {
|
||||
|
||||
private static inline var TAG = "control";
|
||||
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
|
||||
private var connections:Map<DeviceType, DeviceAction->Bool->Void>;
|
||||
|
||||
public function new() {
|
||||
devices = [];
|
||||
signal = new Signal3();
|
||||
devicesSignal = new Signal();
|
||||
connections = new Map();
|
||||
}
|
||||
|
||||
public function connect(device:IControlDevice):Void {
|
||||
var connector = function(action:DeviceAction, on:Bool):Void {
|
||||
//L.d("TAG", '${device.type}, ${action}, ${on}');
|
||||
signal.emit(device.type, action, on);
|
||||
}
|
||||
connections.set(device.type, connector);
|
||||
device.signal.connect(connector);
|
||||
devices.push(device);
|
||||
devicesSignal.emit(devices);
|
||||
}
|
||||
|
||||
public function disconnect(device:IControlDevice):Void {
|
||||
if (connections.exists(device.type)) {
|
||||
device.signal.disconnect(connections.get(device.type));
|
||||
connections.remove(device.type);
|
||||
devices.remove(device);
|
||||
devicesSignal.emit(devices);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceAction.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
enum DeviceAction {
|
||||
DIRECTION(direction:Direction);
|
||||
KEY(code:Int);
|
||||
}
|
||||
8
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
8
src/client/haxe/ru/m/control/DeviceType.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package ru.m.control;
|
||||
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
13
src/client/haxe/ru/m/control/IControlBus.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
|
||||
interface IControlBus {
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
public var signal(default, null):Signal3<DeviceType, DeviceAction, Bool>;
|
||||
public var devicesSignal(default, null):Signal<Array<IControlDevice>>;
|
||||
|
||||
public function connect(device:IControlDevice):Void;
|
||||
public function disconnect(device:IControlDevice):Void;
|
||||
}
|
||||
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
10
src/client/haxe/ru/m/control/IControlDevice.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
|
||||
interface IControlDevice {
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public function dispose():Void;
|
||||
}
|
||||
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
62
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
@@ -0,0 +1,62 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import lime.ui.Joystick;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.geom.Direction;
|
||||
|
||||
class JoystickDevice implements IControlDevice {
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
private var joystick:Joystick;
|
||||
private var axisState:Map<Int, Direction>;
|
||||
|
||||
public function new(joystick:Joystick) {
|
||||
this.joystick = joystick;
|
||||
type = GAMEPAD(joystick.id);
|
||||
signal = new Signal2();
|
||||
axisState = new Map();
|
||||
joystick.onButtonDown.add(onButtonDown);
|
||||
joystick.onButtonUp.add(onButtonUp);
|
||||
joystick.onAxisMove.add(onAxisMove);
|
||||
}
|
||||
|
||||
private function onButtonDown(code:Int):Void {
|
||||
signal.emit(KEY(code), true);
|
||||
}
|
||||
|
||||
private function onButtonUp(code:Int):Void {
|
||||
signal.emit(KEY(code), false);
|
||||
}
|
||||
|
||||
private function onAxisMove(axis:Int, position:Float):Void {
|
||||
var direction:Direction = switch [axis, position] {
|
||||
case [0, 1]: Direction.RIGHT;
|
||||
case [0, -1]: Direction.LEFT;
|
||||
case [1, 1]: Direction.BOTTOM;
|
||||
case [1, -1]: Direction.TOP;
|
||||
case _: null;
|
||||
}
|
||||
if (direction != null) {
|
||||
axisState.set(axis, direction);
|
||||
signal.emit(DIRECTION(direction), true);
|
||||
} else if (position == 0) {
|
||||
if (axisState.exists(axis)) {
|
||||
signal.emit(DIRECTION(axisState.get(axis)), false);
|
||||
axisState.remove(axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
if (joystick != null) {
|
||||
joystick.onButtonDown.remove(onButtonDown);
|
||||
joystick.onButtonUp.remove(onButtonUp);
|
||||
joystick.onAxisMove.remove(onAxisMove);
|
||||
joystick = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
38
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
@@ -0,0 +1,38 @@
|
||||
package ru.m.control;
|
||||
|
||||
import flash.display.Stage;
|
||||
import flash.events.KeyboardEvent;
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.control.DeviceAction;
|
||||
|
||||
class KeyboardDevice implements IControlDevice {
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
private var stage:Stage;
|
||||
|
||||
public function new(stage:Stage) {
|
||||
this.stage = stage;
|
||||
type = DeviceType.KEYBOARD;
|
||||
signal = new Signal2();
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
signal.emit(KEY(event.keyCode), true);
|
||||
}
|
||||
|
||||
private function onKeyUp(event:KeyboardEvent):Void {
|
||||
signal.emit(KEY(event.keyCode), false);
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
if (stage != null) {
|
||||
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
stage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ru.m.display;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
|
||||
class DisplayObjectContainerExtender {
|
||||
|
||||
public static function childrenIterator():Iterator<DisplayObject> {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||
if (self.contains(child)) {
|
||||
return self.removeChild(child);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
||||
throw "Not implemented";
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package ru.m.draw;
|
||||
|
||||
import flash.geom.ColorTransform;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
|
||||
class BitmapUtil {
|
||||
|
||||
public static function colorize(data: BitmapData, color: Color):BitmapData {
|
||||
if (color.zero) return data;
|
||||
var result = data.clone();
|
||||
var transform = new ColorTransform(color.red / 255, color.green / 255, color.blue / 255, 1, 0, 0, 0, 0);
|
||||
result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package ru.m.draw;
|
||||
|
||||
abstract Color(Int) {
|
||||
public var alpha(get, never):Int;
|
||||
public var red(get, never):Int;
|
||||
public var green(get, never):Int;
|
||||
public var blue(get, never):Int;
|
||||
public var zero(get, never):Bool;
|
||||
|
||||
public inline function new(value:Int) {
|
||||
this = value;
|
||||
}
|
||||
|
||||
private inline function get_alpha():Int {
|
||||
return (this >> 24) & 255;
|
||||
}
|
||||
|
||||
private inline function get_red():Int {
|
||||
return (this >> 16) & 255;
|
||||
}
|
||||
|
||||
private inline function get_green():Int {
|
||||
return (this >> 8) & 255;
|
||||
}
|
||||
|
||||
private inline function get_blue():Int {
|
||||
return this & 255;
|
||||
}
|
||||
|
||||
private inline function get_zero():Bool {
|
||||
return this == 0;
|
||||
}
|
||||
|
||||
@:from
|
||||
static public inline function fromInt(value:Int):Color {
|
||||
return new Color(value);
|
||||
}
|
||||
|
||||
@:from
|
||||
static public inline function fromString(value:String):Color {
|
||||
return new Color(Std.parseInt('0x${value.split('#').pop()}'));
|
||||
}
|
||||
|
||||
public function toString():String {
|
||||
return 'Color(${red},${green},${blue})';
|
||||
}
|
||||
}
|
||||
56
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
56
src/client/haxe/ru/m/skin/ButtonSVGSkin.hx
Normal file
@@ -0,0 +1,56 @@
|
||||
package ru.m.skin;
|
||||
|
||||
import format.SVG;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.skin.ISkin;
|
||||
|
||||
using StringTools;
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
@:style(false) private var solid:Null<Bool>;
|
||||
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
|
||||
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
this.solid = solid;
|
||||
init(solid);
|
||||
}
|
||||
|
||||
private inline function buildSVG(color:Color):SVG {
|
||||
return new SVG(svg.replace("currentColor", '#${color}'));
|
||||
}
|
||||
|
||||
private function init(solid:Bool):Void {
|
||||
var color = color;
|
||||
if (solid) {
|
||||
color = color.multiply(1.5);
|
||||
}
|
||||
svgs = new Map();
|
||||
svgs.set(UP, buildSVG(color));
|
||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
var svg = svgs.get(view.state);
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.beginFill(color);
|
||||
if (!solid) {
|
||||
graphics.lineStyle(2, color.multiply(1.5));
|
||||
}
|
||||
// ToDo: padding
|
||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
162
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
162
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
@@ -0,0 +1,162 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.text.TextFormatAlign;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.geometry.Box;
|
||||
import haxework.view.geometry.HAlign;
|
||||
import haxework.view.geometry.SizeValue;
|
||||
import haxework.view.geometry.VAlign;
|
||||
import haxework.view.theme.ITheme;
|
||||
import haxework.view.theme.Theme;
|
||||
import haxework.view.utils.DrawUtil;
|
||||
import openfl.Assets;
|
||||
import ru.m.skin.ButtonSVGSkin;
|
||||
|
||||
using haxework.color.ColorUtil;
|
||||
|
||||
class AppTheme extends Theme {
|
||||
|
||||
public static var COLORS(default, never):ThemeColors = {
|
||||
light: 0x95937D,
|
||||
dark: 0x777564,
|
||||
text: 0xE7E0BB,
|
||||
active: 0xFFFF00,
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super({embed: true}, COLORS);
|
||||
}
|
||||
|
||||
override private function reload():Void {
|
||||
super.reload();
|
||||
register(new Style("light", [
|
||||
"skin.background.color" => colors.light,
|
||||
]));
|
||||
|
||||
register(new Style("dark", [
|
||||
"skin.background.color" => colors.dark,
|
||||
]));
|
||||
|
||||
register(new Style("font", [
|
||||
"_" => null,
|
||||
], ["text"]));
|
||||
|
||||
register(new Style("text.header", [
|
||||
"font.size" => fontSize.big,
|
||||
"font.align" => TextFormatAlign.CENTER,
|
||||
"skin.background.color" => Color.fromInt(0x000000),
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.border.color" => colors.light,
|
||||
"geometry.padding" => Box.fromArray([50, 8]),
|
||||
"geometry.margin" => Box.fromArray([0, 0, 30, 30]),
|
||||
], ["text"]));
|
||||
|
||||
register(new Style("button.menu", [
|
||||
"font.size" => fontSize.big,
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
"geometry.width" => SizeValue.fromInt(250),
|
||||
"geometry.height" => SizeValue.fromInt(50),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("text.box", [
|
||||
"skin.background.color" => Color.fromInt(0x000000),
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.border.color" => colors.light,
|
||||
"geometry.padding" => Box.fromArray([15, 8]),
|
||||
], ["text"]));
|
||||
|
||||
register(new Style("text.box.active", [
|
||||
"skin.background.color" => Color.fromInt(0x55aa55),
|
||||
"skin.background.alpha" => 1,
|
||||
"skin.border.color" => Color.fromInt(0x88dd88),
|
||||
], ["text.box"]));
|
||||
|
||||
register(new Style("button.level", [
|
||||
"font.size" => fontSize.veryBig,
|
||||
"geometry.width" => SizeValue.fromInt(64),
|
||||
"geometry.height" => SizeValue.fromInt(64),
|
||||
"geometry.padding" => Box.fromFloat(0),
|
||||
], ["button"]));
|
||||
|
||||
register(new Style("container", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromString("100%"),
|
||||
"layout.hAlign" => HAlign.CENTER,
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["dark"]));
|
||||
|
||||
register(new Style("panel", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.padding" => Box.fromArray([10, 5]),
|
||||
"layout.vAlign" => VAlign.MIDDLE,
|
||||
], ["light"]));
|
||||
|
||||
register(new Style("window", [
|
||||
"geometry.padding" => Box.fromFloat(2),
|
||||
], ["dark", "border"]));
|
||||
|
||||
register(new Style("line", [
|
||||
"geometry.width" => SizeValue.fromString("100%"),
|
||||
"geometry.height" => SizeValue.fromInt(2),
|
||||
], ["border"]));
|
||||
|
||||
register(new Style("window.close", [
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), colors.light),
|
||||
"geometry.width" => SizeValue.fromInt(36),
|
||||
"geometry.height" => SizeValue.fromInt(36),
|
||||
]));
|
||||
|
||||
register(new Style("icon.tank", [
|
||||
"geometry.width" => SizeValue.fromInt(42),
|
||||
"geometry.height" => SizeValue.fromInt(42),
|
||||
"skin.fillType" => FillType.DEFAULT,
|
||||
]));
|
||||
|
||||
var green:Color = 0x00ff00;
|
||||
var red:Color = 0xff0000;
|
||||
register(new Style("result.winner", [
|
||||
"skin.border.color" => green,
|
||||
], ["light"]));
|
||||
register(new Style("result.loser", [
|
||||
"skin.border.color" => red,
|
||||
], ["light"]));
|
||||
register(new Style("player.winner", [
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.background.color" => green,
|
||||
]));
|
||||
register(new Style("player.loser", [
|
||||
"skin.background.alpha" => 0.1,
|
||||
"skin.background.color" => red,
|
||||
]));
|
||||
|
||||
registerButton("settings", "cog-solid.svg");
|
||||
registerButton("close", "times-circle-solid.svg");
|
||||
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||
registerButton("prev", "arrow-alt-circle-left-solid.svg");
|
||||
registerButton("start", "play-circle-solid.svg");
|
||||
registerButton("login", "sign-in-solid.svg");
|
||||
registerButton("logout", "sign-out-solid.svg");
|
||||
|
||||
registerButton("keyboard", "keyboard-light.svg", true);
|
||||
registerButton("backspace", "backspace-light.svg", true);
|
||||
registerButton("tablet-android-alt", "tablet-android-alt-light.svg", true);
|
||||
|
||||
register(new Style("gamepad", [
|
||||
"skin.color" => colors.active,
|
||||
]));
|
||||
}
|
||||
|
||||
private function registerButton(name:String, resource:String, solid:Bool = false):Void {
|
||||
register(new Style('button.$name', [
|
||||
"geometry.width" => SizeValue.fromInt(42),
|
||||
"geometry.height" => SizeValue.fromInt(42),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
|
||||
]));
|
||||
register(new Style('button.$name.small', [
|
||||
"geometry.width" => SizeValue.fromInt(32),
|
||||
"geometry.height" => SizeValue.fromInt(32),
|
||||
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light, solid),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +1,38 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import ru.m.tankz.game.ClassicGame;
|
||||
import ru.m.tankz.game.DotaGame;
|
||||
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 flash.Lib;
|
||||
import haxework.animate.Animate;
|
||||
import haxework.log.TraceLogger;
|
||||
import haxework.view.Root;
|
||||
import ru.m.tankz.view.ClientView;
|
||||
|
||||
@:template("layout/main.json", "layout/styles.json")
|
||||
class MainView extends VGroupView implements ViewBuilder {}
|
||||
|
||||
class Client implements IConnectionHandler {
|
||||
|
||||
class Client {
|
||||
private static inline var TAG = "Tankz";
|
||||
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
#if flash
|
||||
L.push(new JSLogger());
|
||||
L.push(new haxework.log.JSLogger());
|
||||
#end
|
||||
#if debug
|
||||
L.push(new SocketLogger());
|
||||
//L.push(new haxework.log.SocketLogger());
|
||||
#end
|
||||
Const.init();
|
||||
L.d(TAG, "Debug: " + Const.DEBUG);
|
||||
L.i(TAG, "Version: " + Const.VERSION);
|
||||
L.i(TAG, "Build: " + Const.BUILD);
|
||||
new Client();
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
Init.init();
|
||||
Animate.bind(Lib.current.stage);
|
||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
|
||||
//Provider.get(IConnection).handler.addListener(this);
|
||||
view = new MainView();
|
||||
Provider.set(IFrameSwitcher, view.switcher);
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.content.stage.stageFocusRect = false;
|
||||
//view.logout.onPress = this;
|
||||
view.switcher.change(StartFrame.ID);
|
||||
view.launch();
|
||||
|
||||
view.content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||
if (event.keyCode == Keyboard.ESCAPE) {
|
||||
view.switcher.change(StartFrame.ID);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
#if debug
|
||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||
Lib.current.addChild(fps);
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package ru.m.tankz;
|
||||
import flash.Lib;
|
||||
import flash.system.Capabilities;
|
||||
|
||||
|
||||
class Const {
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
@@ -11,9 +10,9 @@ class Const {
|
||||
public static var DEBUG:Bool;
|
||||
|
||||
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");
|
||||
VERSION = Lib.current.stage.application.config.version;
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
}
|
||||
101
src/client/haxe/ru/m/tankz/Init.hx
Normal file
101
src/client/haxe/ru/m/tankz/Init.hx
Normal file
@@ -0,0 +1,101 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.Lib;
|
||||
import haxework.animate.FadeAnimate;
|
||||
import haxework.animate.UnFadeAnimate;
|
||||
import haxework.net.manage.ILoaderManager;
|
||||
import haxework.net.manage.LoaderManager;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.resources.Resources;
|
||||
import haxework.view.popup.PopupManager;
|
||||
import haxework.view.theme.ITheme;
|
||||
import lime.ui.Gamepad;
|
||||
import lime.ui.Joystick;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.control.ControlBus;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.control.JoystickDevice;
|
||||
import ru.m.control.KeyboardDevice;
|
||||
import ru.m.tankz.bundle.ConfigBundle;
|
||||
import ru.m.tankz.bundle.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 theme:ITheme;
|
||||
@:provide static var resources:IResources;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var settingsStorage:SettingsStorage;
|
||||
@:provide static var multiplayerStorage:NetworkStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var networkManager:NetworkManager;
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
@:provide static var loaderManager:ILoaderManager;
|
||||
@:provide static var updater:Updater;
|
||||
|
||||
private static function buildConnection():IConnection<Request, Response> {
|
||||
var host:String = CompilationOption.get("host");
|
||||
var port:Int = CompilationOption.get("port");
|
||||
L.d("Init", 'connect to $host:$port');
|
||||
#if flash
|
||||
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 {
|
||||
theme = new AppTheme();
|
||||
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();
|
||||
|
||||
bus = new ControlBus();
|
||||
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||
|
||||
loaderManager = new LoaderManager();
|
||||
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
|
||||
|
||||
for (device in Gamepad.devices) {
|
||||
trace('gamepad', device);
|
||||
}
|
||||
Gamepad.onConnect.add(function(device) {
|
||||
trace('connect gamepad', device);
|
||||
});
|
||||
|
||||
for (device in Joystick.devices) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
}
|
||||
Joystick.onConnect.add(function(device) {
|
||||
bus.connect(new JoystickDevice(device));
|
||||
});
|
||||
}
|
||||
}
|
||||
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
27
src/client/haxe/ru/m/tankz/LinuxIcon.hx
Normal file
@@ -0,0 +1,27 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.filters.ColorMatrixFilter;
|
||||
import flash.geom.Point;
|
||||
import flash.Lib;
|
||||
import openfl.Assets;
|
||||
|
||||
class LinuxIcon {
|
||||
|
||||
private static function prepareIcon(bitmap:BitmapData):BitmapData {
|
||||
var matrix:Array<Float> = [];
|
||||
matrix = matrix.concat([0, 0, 1, 0, 0]);
|
||||
matrix = matrix.concat([0, 1, 0, 0, 0]);
|
||||
matrix = matrix.concat([1, 0, 0, 0, 0]);
|
||||
matrix = matrix.concat([0, 0, 0, 1, 0]);
|
||||
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
|
||||
var bitmap:BitmapData = bitmap.clone();
|
||||
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static function apply() {
|
||||
var icon = Assets.getBitmapData("resources/icon.png");
|
||||
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
|
||||
}
|
||||
}
|
||||
142
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
142
src/client/haxe/ru/m/tankz/Preloader.hx
Normal file
@@ -0,0 +1,142 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.Lib;
|
||||
import haxework.view.geometry.Size;
|
||||
import ru.m.tankz.AppTheme;
|
||||
|
||||
class Progress extends Sprite {
|
||||
|
||||
public var color(default, set):Int = 0;
|
||||
public var backColor(default, set):Int = 0;
|
||||
public var progress(default, set):Float = 0;
|
||||
public var size(default, set):Size = [0, 0];
|
||||
public var radius(get, null):Float;
|
||||
|
||||
private var maskShape:Shape;
|
||||
private var toRedraw:Bool;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
maskShape = new Shape();
|
||||
addChild(maskShape);
|
||||
mask = maskShape;
|
||||
}
|
||||
|
||||
private inline function get_radius():Float {
|
||||
return Math.min(size.width, size.height) / 2;
|
||||
}
|
||||
|
||||
private function set_color(value:Int):Int {
|
||||
if (color != value) {
|
||||
color = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_backColor(value:Int):Int {
|
||||
if (backColor != value) {
|
||||
backColor = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_progress(value:Float):Float {
|
||||
if (progress != value) {
|
||||
progress = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
private function set_size(value:Size):Size {
|
||||
if (size != value) {
|
||||
size = value;
|
||||
toRedraw = true;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (toRedraw) {
|
||||
redraw();
|
||||
redrawMask();
|
||||
toRedraw = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
graphics.clear();
|
||||
graphics.beginFill(color);
|
||||
graphics.drawCircle(radius, radius, radius);
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawCircle(radius, radius, radius / 2);
|
||||
graphics.endFill();
|
||||
}
|
||||
|
||||
public function redrawMask():Void {
|
||||
maskShape.graphics.clear();
|
||||
maskShape.graphics.beginFill(0x00ff00);
|
||||
maskShape.graphics.moveTo(radius, radius);
|
||||
var sides = 6;
|
||||
var rotation = (-(Math.PI) / 2);
|
||||
var r = radius / Math.cos(1/sides * Math.PI);
|
||||
var lineToRadians = function(rads:Float):Void {
|
||||
maskShape.graphics.lineTo(Math.cos(rads) * r + radius, Math.sin(rads) * r + radius);
|
||||
};
|
||||
var sidesToDraw:Int = Math.floor(progress * sides);
|
||||
for (i in 0...sidesToDraw + 1) {
|
||||
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
|
||||
}
|
||||
if (progress * sides != sidesToDraw) {
|
||||
lineToRadians(progress * (Math.PI * 2) + rotation);
|
||||
}
|
||||
maskShape.graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
class Preloader extends Sprite {
|
||||
|
||||
private var progress:Progress;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
Lib.current.stage.color = AppTheme.COLORS.light;
|
||||
progress = new Progress();
|
||||
progress.color = AppTheme.COLORS.dark;
|
||||
progress.backColor = AppTheme.COLORS.light;
|
||||
progress.size = [200, 200];
|
||||
addChild(progress);
|
||||
onResize(null);
|
||||
Lib.current.stage.addEventListener(Event.RESIZE, onResize);
|
||||
Lib.current.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
Lib.current.stage.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
addEventListener(Event.COMPLETE, onComplete);
|
||||
}
|
||||
|
||||
private function onResize(event:Event):Void {
|
||||
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
|
||||
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
progress.update();
|
||||
}
|
||||
|
||||
private function onProgress(event:ProgressEvent):Void {
|
||||
progress.progress = event.bytesLoaded / event.bytesTotal;
|
||||
}
|
||||
|
||||
private function onComplete(event:Event):Void {
|
||||
progress.update();
|
||||
Lib.current.stage.removeEventListener(Event.RESIZE, onResize);
|
||||
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
Lib.current.stage.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||
removeEventListener(Event.COMPLETE, onComplete);
|
||||
}
|
||||
}
|
||||
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/config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
}
|
||||
return _cache.get(type);
|
||||
}
|
||||
}
|
||||
42
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
42
src/client/haxe/ru/m/tankz/bundle/LevelBundle.hx
Normal file
@@ -0,0 +1,42 @@
|
||||
package ru.m.tankz.bundle;
|
||||
|
||||
import openfl.Assets;
|
||||
import openfl.utils.AssetType;
|
||||
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, LevelPack> = new Map();
|
||||
|
||||
public function new() {}
|
||||
|
||||
private function resolve(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('resources/level/${id}.zip');
|
||||
return {
|
||||
id: id,
|
||||
data: LevelUtil.unpack(bytes).map(function(level) {
|
||||
level.packId = id;
|
||||
return level;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
public function get(id:PackId):LevelPack {
|
||||
if (!_cache.exists(id)) {
|
||||
_cache.set(id, resolve(id));
|
||||
}
|
||||
return _cache.get(id);
|
||||
}
|
||||
|
||||
public function list():Array<PackId> {
|
||||
var result = [];
|
||||
for (path in Assets.list(AssetType.BINARY)) {
|
||||
if (StringTools.startsWith(path, "resources/level")) {
|
||||
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
12
src/client/haxe/ru/m/tankz/control/Binding.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
typedef BindAction = {
|
||||
var device:DeviceType;
|
||||
var action:DeviceAction;
|
||||
}
|
||||
|
||||
typedef Binding = Map<TankAction, BindAction>;
|
||||
@@ -1,63 +1,98 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import flash.events.FocusEvent;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.Lib;
|
||||
import flash.ui.Keyboard;
|
||||
import haxe.Timer;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
typedef KeyBinding = Map<Int, TankAction>;
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
private var keyBinding:KeyBinding;
|
||||
private var moveQueue:Array<Int>;
|
||||
private var shotTimer:Timer;
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
this.keyBinding = resolve(controlIndex);
|
||||
moveQueue = new Array<Int>();
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
||||
var config = storage.getBinding(controlIndex);
|
||||
binding = new Map();
|
||||
for (action in config.keys()) {
|
||||
var bind = config.get(action);
|
||||
if (!binding.exists(bind.device)) {
|
||||
binding.set(bind.device, new Map());
|
||||
}
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
moveQueue = [];
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
private function onKeyDown(event:KeyboardEvent):Void {
|
||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||
case TankAction.MOVE(direction):
|
||||
if (moveQueue.indexOf(event.keyCode) == -1) {
|
||||
moveQueue.unshift(event.keyCode);
|
||||
updateMove();
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
case TankAction.SHOT:
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(300);
|
||||
shotTimer.run = shot;
|
||||
shot();
|
||||
}
|
||||
case _:
|
||||
return false;
|
||||
}
|
||||
if (event.keyCode == Keyboard.U) {
|
||||
action(TankAction.UPGRADE);
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
if (binding.exists(device) && binding[device].exists(action)) {
|
||||
toggleAction(binding[device][action], on);
|
||||
}
|
||||
}
|
||||
|
||||
private function onKeyUp(event:KeyboardEvent):Void {
|
||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
||||
case TankAction.MOVE(direction):
|
||||
moveQueue.remove(event.keyCode);
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
override public function start():Void {
|
||||
super.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
case _:
|
||||
|
||||
override public function stop():Void {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
switch action {
|
||||
case TankAction.MOVE(direction):
|
||||
if (on) {
|
||||
if (moveQueue.indexOf(direction) == -1) {
|
||||
moveQueue.unshift(direction);
|
||||
}
|
||||
} else {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (!shotTimers.exists(weapon)) {
|
||||
var timer = new Timer(300);
|
||||
timer.run = shooter(weapon);
|
||||
timer.run();
|
||||
shotTimers.set(weapon, timer);
|
||||
}
|
||||
} else {
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
}
|
||||
case TankAction.STOP:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,40 +103,15 @@ class HumanControl extends Control {
|
||||
|
||||
private function updateMove():Void {
|
||||
if (moveQueue.length == 0) {
|
||||
action(TankAction.STOP);
|
||||
action(STOP);
|
||||
} else {
|
||||
switch (keyBinding.get(moveQueue[0])) {
|
||||
case TankAction.MOVE(direction):
|
||||
action(TankAction.MOVE(direction));
|
||||
case _:
|
||||
}
|
||||
action(MOVE(moveQueue[0]));
|
||||
}
|
||||
}
|
||||
|
||||
private function shot():Void {
|
||||
action(TankAction.SHOT);
|
||||
}
|
||||
|
||||
private static function resolve(controlIndex:Int):KeyBinding {
|
||||
switch (controlIndex) {
|
||||
case 0:
|
||||
return [
|
||||
Keyboard.A => TankAction.MOVE(Direction.LEFT),
|
||||
Keyboard.S => TankAction.MOVE(Direction.BOTTOM),
|
||||
Keyboard.W => TankAction.MOVE(Direction.TOP),
|
||||
Keyboard.D => TankAction.MOVE(Direction.RIGHT),
|
||||
Keyboard.SPACE => TankAction.SHOT
|
||||
];
|
||||
case 1:
|
||||
return [
|
||||
Keyboard.LEFT => TankAction.MOVE(Direction.LEFT),
|
||||
Keyboard.DOWN => TankAction.MOVE(Direction.BOTTOM),
|
||||
Keyboard.UP => TankAction.MOVE(Direction.TOP),
|
||||
Keyboard.RIGHT => TankAction.MOVE(Direction.RIGHT),
|
||||
Keyboard.NUMPAD_0 => TankAction.SHOT
|
||||
];
|
||||
case x:
|
||||
throw 'Invalid control index ${x}';
|
||||
private function shooter(weapon:Int):Void -> Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
@@ -0,0 +1,11 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
|
||||
enum GameInit {
|
||||
LOCAL(start:Start);
|
||||
NETWORK(network:NetworkManager);
|
||||
RECORD(record:GameRecord);
|
||||
}
|
||||
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
13
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalControlFactory extends BaseControlFactory {
|
||||
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new HumanControl(id, index);
|
||||
}
|
||||
}
|
||||
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
41
src/client/haxe/ru/m/tankz/local/LocalGame.hx
Normal file
@@ -0,0 +1,41 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import ru.m.tankz.local.LocalControlFactory;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalGame extends GameRunner {
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case COMPLETE(result): updateProgress(result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function updateProgress(result:Result):Void {
|
||||
var complete = false;
|
||||
var humansTeams:Array<TeamId> = [];
|
||||
for (control in controls) {
|
||||
if (Std.is(control, HumanControl) && humansTeams.indexOf(control.playerId.team) == -1) {
|
||||
humansTeams.push(control.playerId.team);
|
||||
}
|
||||
}
|
||||
if (humansTeams.length == 1 && result.winner == humansTeams[0]) {
|
||||
var progress = gameStorage.get(result.level.packId);
|
||||
progress.completeLevel(result.level.id, result.state.presetId);
|
||||
gameStorage.set(progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
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.control.Controller;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.network.NetworkControlFactory;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||
|
||||
class NetworkGame extends Game {
|
||||
|
||||
private var network:NetworkManager;
|
||||
|
||||
public function new(network:NetworkManager) {
|
||||
super(network.room.game.type);
|
||||
this.network = network;
|
||||
this.controlFactory = new NetworkControlFactory();
|
||||
network.gameEventSignal.connect(onGameEventProto);
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
}
|
||||
|
||||
private function onGameEventProto(game:GameEventResponse):Void {
|
||||
var time = game.event.time;
|
||||
var eventStr = game.event.event;
|
||||
var event:GameEvent = Unserializer.run(eventStr);
|
||||
gameEventSignal.emit(event);
|
||||
}
|
||||
|
||||
private function onConnectionState(state:ConnectionState):Void {
|
||||
switch state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
network.joinGame(network.room.game.id);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
override private function onStart(start:Start):Void {
|
||||
var slot:RoomSlotProto = Lambda.find(network.room.slots, function(slot:RoomSlotProto) return slot.hasUser() && slot.user.uuid == network.user.uuid);
|
||||
if (slot != null) {
|
||||
start.state.controls.push({playerId: [slot.slot.team, slot.slot.index], controller: HUMAN(0)});
|
||||
}
|
||||
super.onStart(start);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
super.dispose();
|
||||
network.gameEventSignal.disconnect(onGameEventProto);
|
||||
network.stateSignal.disconnect(onConnectionState);
|
||||
}
|
||||
}
|
||||
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(); // ToDo: disable network
|
||||
}
|
||||
|
||||
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
|
||||
})]);
|
||||
}
|
||||
}
|
||||
12
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
12
src/client/haxe/ru/m/tankz/render/IRender.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import haxework.view.IView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
interface IRender extends IView<Dynamic> extends GameListener {
|
||||
public var config(default, set):Config;
|
||||
public var gridSize(default, set):GridSize;
|
||||
public function draw():Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
@@ -1,18 +1,35 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.geom.Point;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.render.RenderItem;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
import haxework.gui.SpriteView;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import haxe.Timer;
|
||||
import haxework.view.form.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;
|
||||
public var gridSize(default, set):GridSize;
|
||||
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
@@ -20,8 +37,7 @@ class Render extends SpriteView implements EngineListener {
|
||||
private var upLayer:Sprite;
|
||||
private var upperLayer:Sprite;
|
||||
|
||||
private var background:Sprite;
|
||||
private var items:Map<String, RenderItem<Dynamic, Dynamic>>;
|
||||
private var items:Map<Int, IRenderItem>;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
@@ -31,167 +47,230 @@ class Render extends SpriteView implements EngineListener {
|
||||
entryLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
upperLayer = new Sprite();
|
||||
contentAsSprite.addChild(backgroundLayer);
|
||||
contentAsSprite.addChild(groundLayer);
|
||||
contentAsSprite.addChild(entryLayer);
|
||||
contentAsSprite.addChild(upLayer);
|
||||
contentAsSprite.addChild(upperLayer);
|
||||
content.addChild(backgroundLayer);
|
||||
content.addChild(groundLayer);
|
||||
content.addChild(entryLayer);
|
||||
content.addChild(upLayer);
|
||||
content.addChild(upperLayer);
|
||||
reset();
|
||||
}
|
||||
|
||||
private function drawBackground(game:Engine):Void {
|
||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
||||
private function get_mapWidth():Float {
|
||||
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||
}
|
||||
|
||||
private function get_mapHeight():Float {
|
||||
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||
}
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
private function drawBackground():Void {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
if (contentSize) {
|
||||
width = mapWidth;
|
||||
height = mapHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public function draw(game:Engine):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);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
}
|
||||
if (background == null) {
|
||||
drawBackground(game);
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
draw();
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
||||
while (layer.numChildren > 0) {
|
||||
layer.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
for (item in items.iterator()) {
|
||||
item.dispose();
|
||||
}
|
||||
items = new Map();
|
||||
if (background != null) {
|
||||
backgroundLayer.removeChild(background);
|
||||
background = null;
|
||||
}
|
||||
clearLayer(entryLayer);
|
||||
clearLayer(groundLayer);
|
||||
clearLayer(upLayer);
|
||||
clearLayer(upperLayer);
|
||||
}
|
||||
|
||||
public function onSpawn(entity:EntityType):Void {
|
||||
switch(entity) {
|
||||
case EntityType.TANK(tank):
|
||||
var item = new TankItem(tank);
|
||||
items.set(tank.key, item);
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case SPAWN(BRICK(bricks)):
|
||||
drawBackground();
|
||||
for (brick in bricks) {
|
||||
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||
var config = config.getBrick(brick.type);
|
||||
items[brick.id] = item;
|
||||
if (config.layer > 2) {
|
||||
upLayer.addChild(item.view);
|
||||
} else {
|
||||
groundLayer.addChild(item.view);
|
||||
}
|
||||
}
|
||||
case SPAWN(EAGLE(id, rect, teamId)):
|
||||
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playTankSpawn(tank.rect.center);
|
||||
case EntityType.BULLET(bullet):
|
||||
var item = new BulletItem(bullet);
|
||||
items.set(bullet.key, item);
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
var item = new TankRenderItem(rect);
|
||||
var tankConfig = config.getTank(info.type);
|
||||
item.color = info.color;
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.EAGLE(eagle):
|
||||
var item = new EagleItem(eagle);
|
||||
items.set(eagle.key, item);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, skin)):
|
||||
var item = new BulletRenderItem(rect, skin);
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
case EntityType.BONUS(bonus):
|
||||
var item = new BonusItem(bonus);
|
||||
items.set(bonus.key, item);
|
||||
entryLayer.addChild(item.view);
|
||||
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());
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
var rect = item.rect;
|
||||
// move boom
|
||||
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||
playAnimate(point, AnimateBundle.bulletBoom());
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(EAGLE(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
showScore(item.rect.center, shot.score);
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroyCell(x, y);
|
||||
case DESTROY(BRICK(id, shot)):
|
||||
var item:BrickRenderItem = cast items.get(id);
|
||||
item.destroy();
|
||||
case _:
|
||||
}
|
||||
#if cpp
|
||||
flash.Lib.current.stage.invalidate();
|
||||
#end
|
||||
}
|
||||
|
||||
public function onCollision(entity:EntityType, with:EntityType):Void {
|
||||
|
||||
}
|
||||
|
||||
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 EntityType.BONUS(bonus):
|
||||
if (items.exists(bonus.key)) {
|
||||
entryLayer.removeChild(items.get(bonus.key).view);
|
||||
items.remove(bonus.key);
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function playTankSpawn(point:Point):Void {
|
||||
var arr = [
|
||||
0, 1, 2, 3, 3, 4, 5, 5, 6
|
||||
];
|
||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/appear/appear-${i}.png')];
|
||||
var animate = new OnceAnimate(frames);
|
||||
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||
animate.x = point.x - animate.width / 2;
|
||||
animate.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
animate.play().then(function(animate) {
|
||||
upperLayer.removeChild(animate);
|
||||
return animate.play().then(function(animate:Animate):Void {
|
||||
// ToDo: clean animates on reset
|
||||
if (upperLayer.contains(animate)) {
|
||||
upperLayer.removeChildSafety(animate);
|
||||
}
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private function 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.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
animate.play().then(function(animate) {
|
||||
upperLayer.removeChild(animate);
|
||||
animate.dispose();
|
||||
});
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
}
|
||||
|
||||
private function playTankBoom(point:Point):Void {
|
||||
var arr = [
|
||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
||||
];
|
||||
var frames = [for (i in arr) Assets.getBitmapData('resources/images/tank/kaboom/kaboom-${i}.png')];
|
||||
var animate = new OnceAnimate(frames);
|
||||
animate.x = point.x - animate.width / 2;
|
||||
animate.y = point.y - animate.height / 2;
|
||||
upperLayer.addChild(animate);
|
||||
animate.play().then(function(animate) {
|
||||
upperLayer.removeChild(animate);
|
||||
animate.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import openfl.display.BitmapData;
|
||||
import ru.m.draw.Color;
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import openfl.Assets;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.draw.BitmapUtil;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
import ru.m.tankz.core.Tank;
|
||||
import ru.m.tankz.map.Brick;
|
||||
|
||||
|
||||
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;
|
||||
private var type: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;
|
||||
if (value.config.type > 0) {
|
||||
g.beginBitmapFill(image);
|
||||
g.drawRect(0, 0, value.rect.width, value.rect.height);
|
||||
for (c in value.cells) {
|
||||
if (c.destroyed) {
|
||||
g.beginFill(0x000000);
|
||||
g.drawRect(c.rect.x - value.rect.x, c.rect.y - value.rect.y, c.rect.width, c.rect.height);
|
||||
}
|
||||
}
|
||||
g.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var b = value.broken;
|
||||
var t = value.config.type;
|
||||
if (b != broken || t != type) {
|
||||
broken = b;
|
||||
type = t;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
private function getImage():String {
|
||||
return 'resources/images/map/map_${value.config.type}.png';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AnimateItem<T:TRectangle> extends RenderItem<T, Animate> {
|
||||
|
||||
public function new(value:T) {
|
||||
super(value);
|
||||
view = new Animate();
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
view.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TankItem extends RenderItem<Tank, Sprite> {
|
||||
|
||||
private var type:String;
|
||||
private var hits:Int;
|
||||
|
||||
private var tankView:Animate;
|
||||
|
||||
public function new(value:Tank) {
|
||||
super(value);
|
||||
view = new Sprite();
|
||||
tankView = new Animate();
|
||||
view.addChild(tankView);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var colors:Array<Color> = [value.color, value.bonus ? 0xff00aa : value.color];
|
||||
var frames = [for (frame in getFrames()) BitmapUtil.colorize(Assets.getBitmapData(frame), colors.shift())];
|
||||
tankView.frames = [
|
||||
frames[0], frames[0], frames[0],
|
||||
frames[1], frames[1], frames[1],
|
||||
];
|
||||
}
|
||||
|
||||
private function getFrames():Array<String> {
|
||||
var frame0 = 'resources/image/tank/${value.config.skin}-0.png';
|
||||
var frame1 = 'resources/image/tank/${value.config.skin}-1.png';
|
||||
return [frame1, frame0];
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
var t = value.config.type;
|
||||
var h = value.hits;
|
||||
if (t != this.type || h != this.hits) {
|
||||
this.type = t;
|
||||
this.hits = h;
|
||||
redraw();
|
||||
}
|
||||
tankView.playing = (value.mx !=0 || value.my != 0);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
if (tankView != null) {
|
||||
tankView.dispose();
|
||||
tankView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BulletItem extends BitmapItem<Bullet> {
|
||||
|
||||
override private function getImage():String {
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BonusItem extends AnimateItem<Bonus> {
|
||||
|
||||
public function new(value:Bonus) {
|
||||
super(value);
|
||||
redraw();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
var image = Assets.getBitmapData('resources/image/bonus/${value.bonusType}.png');
|
||||
var empty = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
view.frames = [for (i in 0...15) image].concat([for (i in 0...15) empty]);
|
||||
view.playing = true;
|
||||
}
|
||||
}
|
||||
25
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
25
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
@@ -0,0 +1,25 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class RenderUtil {
|
||||
|
||||
public static function eagleImage(death:Bool = false):BitmapData {
|
||||
var suffix = death ? '-death' : '';
|
||||
return Assets.getBitmapData('resources/image/eagle/eagle${suffix}.png');
|
||||
}
|
||||
|
||||
public static function tankImage(skin:String, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/tank/${skin}-${frame}.png');
|
||||
}
|
||||
|
||||
public static function bonusImage(type:BonusType):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||
}
|
||||
|
||||
public static function bulletImage(skin:String):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bullet/${skin}.png');
|
||||
}
|
||||
}
|
||||
32
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
32
src/client/haxe/ru/m/tankz/render/item/BitmapRenderItem.hx
Normal file
@@ -0,0 +1,32 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.PixelSnapping;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BitmapRenderItem extends RenderItem {
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
private var bitmap:Bitmap;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.AUTO, true);
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
bitmap.bitmapData = image;
|
||||
bitmap.width = rect.width;
|
||||
bitmap.height = rect.height;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
34
src/client/haxe/ru/m/tankz/render/item/BonusRenderItem.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class BonusRenderItem extends BitmapRenderItem {
|
||||
|
||||
public var type(default, set):BonusType;
|
||||
private var d = -0.05;
|
||||
private var alpha = 1.0;
|
||||
|
||||
public function new(rect:Rectangle, type:BonusType) {
|
||||
super(rect);
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_type(value:BonusType):BonusType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
image = RenderUtil.bonusImage(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
alpha += d;
|
||||
view.alpha = alpha;
|
||||
if (alpha <= 0 || alpha >= 1.5) {
|
||||
d = -d;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
96
src/client/haxe/ru/m/tankz/render/item/BrickRenderItem.hx
Normal file
@@ -0,0 +1,96 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Shape;
|
||||
import openfl.Assets;
|
||||
import openfl.display.DisplayObject;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type.BrickType;
|
||||
|
||||
enum BrickState {
|
||||
UNBROKEN;
|
||||
BROKEN;
|
||||
DESTROYED;
|
||||
}
|
||||
|
||||
class BrickRenderItem extends RenderItem {
|
||||
|
||||
public var type(default, set):BrickType;
|
||||
public var state(get, never):BrickState;
|
||||
|
||||
private var image:BitmapData;
|
||||
private var shape:Shape;
|
||||
private var cells:Array<Point>;
|
||||
|
||||
private static function buildCells():Array<Point> {
|
||||
return [
|
||||
new Point(0, 0),
|
||||
new Point(0, 1),
|
||||
new Point(1, 0),
|
||||
new Point(1, 1),
|
||||
];
|
||||
}
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
this.shape = new Shape();
|
||||
cells = buildCells();
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function get_state():BrickState {
|
||||
return switch cells.length {
|
||||
case 0: DESTROYED;
|
||||
case 4: UNBROKEN;
|
||||
case _: BROKEN;
|
||||
}
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return shape;
|
||||
}
|
||||
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
cells = buildCells();
|
||||
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
||||
redraw();
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public function destroyCell(x:Int, y:Int):Void {
|
||||
cells = cells.filter(function(point) return !(point.x == x && point.y == y));
|
||||
redraw();
|
||||
}
|
||||
|
||||
public function destroy():Void {
|
||||
cells = [];
|
||||
redraw();
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
shape.graphics.clear();
|
||||
if (type == "none") return;
|
||||
switch state {
|
||||
case UNBROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
shape.graphics.drawRect(0, 0, rect.width, rect.height);
|
||||
shape.graphics.endFill();
|
||||
case BROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
for (point in cells) {
|
||||
var x = point.x * (rect.width / 2);
|
||||
var y = point.y * (rect.width / 2);
|
||||
var width = rect.width / 2;
|
||||
var height = rect.height / 2;
|
||||
shape.graphics.drawRect(x, y, width, height);
|
||||
}
|
||||
shape.graphics.endFill();
|
||||
case DESTROYED:
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
21
src/client/haxe/ru/m/tankz/render/item/BulletRenderItem.hx
Normal file
@@ -0,0 +1,21 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BulletRenderItem extends BitmapRenderItem {
|
||||
public var skin(default, set):String;
|
||||
|
||||
public function new(rect:Rectangle, skin:String) {
|
||||
super(rect);
|
||||
this.skin = skin;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
image = RenderUtil.bulletImage(skin);
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
57
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
57
src/client/haxe/ru/m/tankz/render/item/EagleRenderItem.hx
Normal file
@@ -0,0 +1,57 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class EagleRenderItem extends BitmapRenderItem {
|
||||
public var color(default, default):Color;
|
||||
public var death(default, set):Bool = true;
|
||||
public var protect(default, set):Bool;
|
||||
|
||||
private var container:Sprite;
|
||||
private var protectView:Animate;
|
||||
|
||||
public function new(rect:Rectangle, color:Color) {
|
||||
super(rect);
|
||||
this.color = color;
|
||||
container = new Sprite();
|
||||
container.addChild(bitmap);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
death = false;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
private function set_protect(value:Bool):Bool {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
protectView.x = (image.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (image.height - protectView.frames[0].image.height) / 2;
|
||||
}
|
||||
protectView.visible = protect;
|
||||
protectView.playing = protect;
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
private function set_death(value:Bool):Bool {
|
||||
if (death != value) {
|
||||
death = value;
|
||||
image = RenderUtil.eagleImage(death);
|
||||
if (!color.zero) {
|
||||
bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
}
|
||||
return death;
|
||||
}
|
||||
}
|
||||
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
13
src/client/haxe/ru/m/tankz/render/item/IRenderItem.hx
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
interface IRenderItem {
|
||||
public var view(get, null):DisplayObject;
|
||||
public var rect(default, null):Rectangle;
|
||||
public function move(position:Position):Void;
|
||||
public function update():Void;
|
||||
public function dispose():Void;
|
||||
}
|
||||
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
46
src/client/haxe/ru/m/tankz/render/item/RenderItem.hx
Normal file
@@ -0,0 +1,46 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class RenderItem implements IRenderItem {
|
||||
|
||||
public var view(get, null):DisplayObject;
|
||||
public var content(get, null):DisplayObject;
|
||||
|
||||
public var rect(default, null):Rectangle;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
this.rect = rect.clone();
|
||||
}
|
||||
|
||||
private function get_view():DisplayObject {
|
||||
throw "Not Implemented";
|
||||
}
|
||||
|
||||
private function get_content():DisplayObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function move(position:Position):Void {
|
||||
view.x = rect.x = position.x;
|
||||
view.y = rect.y = position.y;
|
||||
if (position.direction != null) {
|
||||
rect.direction = position.direction;
|
||||
if (content != null) {
|
||||
content.rotation = rect.direction.angle;
|
||||
content.x = - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
content.y = - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
} else {
|
||||
view.rotation = rect.direction.angle;
|
||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
||||
view.y = rect.y - rect.height * (rect.direction.x + 1) / 2 - rect.height * (rect.direction.y + 1) / 2 + 1.5 * rect.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update():Void {}
|
||||
|
||||
public function dispose():Void {}
|
||||
}
|
||||
152
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
152
src/client/haxe/ru/m/tankz/render/item/TankRenderItem.hx
Normal file
@@ -0,0 +1,152 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import haxework.color.Color;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.view.theme.ITheme;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class TankRenderItem extends BitmapRenderItem {
|
||||
public var color(default, default):Color;
|
||||
public var skin(default, set):String;
|
||||
public var hits(default, set):Int;
|
||||
public var bonus(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
|
||||
private var container:Sprite;
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var nameView:TextField;
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
container = new Sprite();
|
||||
container.addChild(bitmap);
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function buildNameView():TextField {
|
||||
var result = new BitmapTextField();
|
||||
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
||||
result.embedFonts = theme.font.embed;
|
||||
result.autoSize = TextFieldAutoSize.LEFT;
|
||||
result.shadowColor = 0x000000;
|
||||
result.stroke = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
|
||||
override private function get_content():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = RenderUtil.tankImage(skin, 0);
|
||||
var image2 = RenderUtil.tankImage(skin, 1);
|
||||
var color1:Color = switch hits {
|
||||
case 1: 0x869C43;
|
||||
case 2: 0xDEAF80;
|
||||
case 3: 0x5EA67A;
|
||||
case _: color;
|
||||
}
|
||||
var color2:Color = color1;
|
||||
if (bonus) {
|
||||
color1 = 0xff00aa;
|
||||
}
|
||||
if (!color1.zero) {
|
||||
image1 = BitmapUtil.colorize(image1, color1);
|
||||
}
|
||||
if (!color1.zero) {
|
||||
image2 = BitmapUtil.colorize(image2, color2);
|
||||
}
|
||||
images = [for (i in 0...6) image1].concat([for (i in 0...6) image2]);
|
||||
frame = 0;
|
||||
bitmap.bitmapData = images[frame];
|
||||
}
|
||||
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
redraw();
|
||||
}
|
||||
return skin;
|
||||
}
|
||||
|
||||
private function set_hits(value:Int):Int {
|
||||
if (hits != value) {
|
||||
hits = value;
|
||||
redraw();
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
private function set_bonus(value:Bool):Bool {
|
||||
if (bonus != value) {
|
||||
bonus = value;
|
||||
redraw();
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
private function set_protect(value:Bool):Bool {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
protectView.x = (images[0].width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (images[0].height - protectView.frames[0].image.height) / 2;
|
||||
}
|
||||
protectView.visible = protect;
|
||||
protectView.playing = protect;
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
private function set_moves(value:Bool):Bool {
|
||||
if (moves != value) {
|
||||
moves = value;
|
||||
bitmap.bitmapData = images[0];
|
||||
}
|
||||
return moves;
|
||||
}
|
||||
|
||||
private function set_name(value:String):String {
|
||||
if (name != value) {
|
||||
name = value;
|
||||
nameView.text = name;
|
||||
nameView.x = (rect.width - nameView.width) / 2;
|
||||
nameView.y = -nameView.height / 2; //(rect.height - nameView.height) / 2;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (moves) {
|
||||
frame++;
|
||||
if (frame > images.length - 1) {
|
||||
frame = 0;
|
||||
}
|
||||
bitmap.bitmapData = images[frame];
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user