Compare commits
148 Commits
0.13.0
...
ee4438f2b4
| Author | SHA1 | Date | |
|---|---|---|---|
| ee4438f2b4 | |||
| 4212d85d86 | |||
| 0b24c03068 | |||
| b24c71678e | |||
| c34308ed7c | |||
| a3be62eec7 | |||
| a2e9d16be9 | |||
| c95bb70369 | |||
| 03d6e1f822 | |||
| 648d15fc88 | |||
| d6af58875d | |||
| 16a5adefad | |||
| 682eaa677c | |||
| 4319d66c61 | |||
| f6f729e8d4 | |||
| a39b02bfe7 | |||
| 1cfc98dd57 | |||
| ee846f6219 | |||
| e353d97415 | |||
| 2b49fafa0b | |||
| b33b853747 | |||
| 8e3e6bdb6c | |||
| d9d385b0ef | |||
| 8c16b5ba90 | |||
| 1aaa69f2d7 | |||
| 6240846f0c | |||
| 70e6565e1f | |||
| fffb6a3214 | |||
| 04bea46b3b | |||
| 4da06e52e5 | |||
| 8878a825b8 | |||
| 7de1897b32 | |||
| d670722674 | |||
| e7d031db58 | |||
| 71087286b2 | |||
| 757bc87426 | |||
| 1b5eef810c | |||
| cfa1475cf6 | |||
| 1e79fcfacb | |||
| b34cb41bff | |||
| d2aff5f2ee | |||
| beda5e6c5f | |||
| 50c4aebc0f | |||
| 30325f6d16 | |||
| bddb590d30 | |||
| de831fcb26 | |||
| 5645fb6d0f | |||
| bab588e6fb | |||
| 2565b6017a | |||
| 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 |
@@ -4,6 +4,10 @@ root = true
|
|||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = off
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|||||||
24
.env.default
Normal file
24
.env.default
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
PROJECT=tankz
|
||||||
|
SDK_PATH=$HOME/sdk
|
||||||
|
PUBLISH_PATH=$HOME/public/$PROJECT
|
||||||
|
BUILD_PATH=./build
|
||||||
|
TARGET_PATH=./target
|
||||||
|
KEY_STORE=<keystore.jks>
|
||||||
|
KEY_PASS=<passphrase>
|
||||||
|
REPO=https://git.shmyga.ru/api/packages/InfernalGames
|
||||||
|
PUBLISH_USER=<username>
|
||||||
|
PUBLISH_PASSWORD=<passphrase>
|
||||||
|
|
||||||
|
DOCKER_REPO=git.shmyga.ru
|
||||||
|
DOCKER_GROUP=infernalgames
|
||||||
|
DOCKER_ROOT="$DOCKER_REPO/$DOCKER_GROUP"
|
||||||
|
VERSION=$(grep -m 1 'version' ./package.json | grep -oP '"version"\s*:\s*"\K\d+\.\d+.\d+')
|
||||||
|
DOCKER_PROJECTS=(
|
||||||
|
"$PROJECT-web:web"
|
||||||
|
)
|
||||||
|
DOCKER_ARGS=(
|
||||||
|
"PROJECT_NAME=$PROJECT"
|
||||||
|
)
|
||||||
|
|
||||||
|
NEKO_SDK="$SDK_PATH/neko/2.2.0"
|
||||||
|
HAXE_SDK="$SDK_PATH/haxe/4.2.5"
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
build/
|
||||||
target/
|
target/
|
||||||
src-gen/
|
src-gen/
|
||||||
out/
|
out/
|
||||||
@@ -12,3 +13,5 @@ config.json
|
|||||||
/node_modules
|
/node_modules
|
||||||
/log
|
/log
|
||||||
/ansible/*.retry
|
/ansible/*.retry
|
||||||
|
.npmrc
|
||||||
|
.env
|
||||||
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`
|
||||||
35
Dockerfile
Normal file
35
Dockerfile
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
FROM ubuntu:noble AS base
|
||||||
|
RUN apt update && apt install -y \
|
||||||
|
nodejs \
|
||||||
|
npm \
|
||||||
|
openjdk-11-jre \
|
||||||
|
protobuf-compiler \
|
||||||
|
jq
|
||||||
|
RUN node -v
|
||||||
|
RUN npm -v
|
||||||
|
|
||||||
|
FROM base AS builder
|
||||||
|
ENV GRADLE_USER_HOME=/sdk/gradle
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY gulpfile.js protohx.json ./
|
||||||
|
COPY tasks ./tasks
|
||||||
|
COPY config.example.json ./config.example.json
|
||||||
|
RUN --mount=type=secret,id=KEY_STORE \
|
||||||
|
cat /run/secrets/KEY_STORE > ./key.jks
|
||||||
|
RUN --mount=type=secret,id=KEY_PASS,env=KEY_PASS \
|
||||||
|
jq --arg key_pass "$KEY_PASS" \
|
||||||
|
'.SdkDir = "/sdk" | .PublishDir = "/app/publish" | .Key.store = "key.jks" | .Key.pass = $key_pass' \
|
||||||
|
config.example.json > config.json
|
||||||
|
COPY src ./src
|
||||||
|
#COPY dependencies ./dependencies
|
||||||
|
VOLUME ["/sdk", "/app/build", "/app/target", "/app/publish", "/app/src-gen"]
|
||||||
|
CMD ["npx", "gulp", "default"]
|
||||||
|
|
||||||
|
FROM hello-world AS web
|
||||||
|
ARG PROJECT_NAME
|
||||||
|
VOLUME ["/app/${PROJECT_NAME}"]
|
||||||
|
COPY ./target/client/html5 /app/${PROJECT_NAME}/html5
|
||||||
|
COPY ./target/client/flash /app/${PROJECT_NAME}/flash
|
||||||
|
CMD ["/hello"]
|
||||||
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Tank'z
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Play
|
||||||
|
|
||||||
|
https://shmyga.ru/tankz/html5/index.html
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
|
||||||
|
https://git.shmyga.ru/InfernalGames/tankz/releases
|
||||||
93
WORK.md
93
WORK.md
@@ -1,73 +1,20 @@
|
|||||||
* build
|
* death game bonus
|
||||||
* gulp 100%
|
* tanks and bullets speed balancing
|
||||||
* linux 100%
|
* clean player state on lose in classic type
|
||||||
* deb-package 100%
|
* network series
|
||||||
* windows 0%
|
* bot upgrade
|
||||||
* exe-package 0% (inno setup)
|
* game config validate
|
||||||
|
* mine z-order
|
||||||
* deploy
|
* mine spawn position
|
||||||
* capistrano 100%
|
* mine spawn on other mine
|
||||||
|
* double rocket
|
||||||
* ui
|
* display ammo count (panel)
|
||||||
* auth frame 0%
|
* display ammo count (screen gamepad)
|
||||||
* select game frame 100% (classic 1/2 player, dota singe/coop/vs)
|
* bonus ammo
|
||||||
* select level frame 10%
|
* game panel rework
|
||||||
* game frame 50%
|
* game state: config, map, entities, players
|
||||||
|
* game menu pack progress
|
||||||
* engine
|
* game save
|
||||||
* config 100%
|
* balloons: change mute, network, pause
|
||||||
* map 100%
|
* settings: mute, pause, reset device actions
|
||||||
* tanks 100%
|
* game view: toggle panel on mobile
|
||||||
* bullets 100%
|
|
||||||
* boxes 100%
|
|
||||||
* map changes 100%
|
|
||||||
* bonuses 100%
|
|
||||||
* eagle 100%
|
|
||||||
|
|
||||||
* game
|
|
||||||
* classic
|
|
||||||
* state 50%
|
|
||||||
* bot 50%
|
|
||||||
* human 100%
|
|
||||||
* dota
|
|
||||||
* state 50%
|
|
||||||
* bot 10%
|
|
||||||
* human 100%
|
|
||||||
|
|
||||||
* bonus
|
|
||||||
* star 50%
|
|
||||||
* grenade 0%
|
|
||||||
* helm 0%
|
|
||||||
* clock 0%
|
|
||||||
* shovel 0%
|
|
||||||
|
|
||||||
* state
|
|
||||||
* score 0%
|
|
||||||
* human tank 0%
|
|
||||||
* save/load 0%
|
|
||||||
* export/import 0%
|
|
||||||
|
|
||||||
* render
|
|
||||||
* map 100%
|
|
||||||
* tanks 100%
|
|
||||||
* bullet 100%
|
|
||||||
* calc redraw 50%
|
|
||||||
* animations
|
|
||||||
* tank spawn 0%
|
|
||||||
* tank move 100%
|
|
||||||
* map water 100%
|
|
||||||
* bullet boom 90%
|
|
||||||
* tank boom 90%
|
|
||||||
* bonuses 100%
|
|
||||||
* html5 50%
|
|
||||||
|
|
||||||
* proto
|
|
||||||
...
|
|
||||||
|
|
||||||
* editor
|
|
||||||
* level
|
|
||||||
* open 100%
|
|
||||||
* edit 50%
|
|
||||||
* save 100%
|
|
||||||
* tank
|
|
||||||
* color 10%
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
[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
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
all:
|
|
||||||
hosts: localhost
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
project_name: tankz
|
|
||||||
project_user: holop
|
|
||||||
|
|
||||||
deploy_user: "{{ project_user }}"
|
|
||||||
deploy_project: "{{ project_name }}"
|
|
||||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
|
||||||
deploy_repo_version: master
|
|
||||||
deploy_npm: yes
|
|
||||||
|
|
||||||
service_name: "{{ project_name }}"
|
|
||||||
service_work_dir: "{{ deploy_current_dir }}/target/server/neko"
|
|
||||||
service_command: "/usr/bin/neko {{ service_work_dir }}/{{ project_name }}.n {{ service_host }}"
|
|
||||||
service_user: www-data
|
|
||||||
service_control_user: "{{ project_user }}"
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
all:
|
|
||||||
hosts: shmyga.ru
|
|
||||||
vars:
|
|
||||||
service_host: 172.31.1.100
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
- name: ansible-deploy
|
|
||||||
src: git@bitbucket.org:shmyga/ansible-deploy.git
|
|
||||||
version: master
|
|
||||||
scm: git
|
|
||||||
|
|
||||||
- name: geerlingguy.nodejs
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
---
|
|
||||||
- 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 }}"
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
service_name: null
|
|
||||||
service_description: "{{ service_name }} service"
|
|
||||||
service_work_dir: null
|
|
||||||
service_command: null
|
|
||||||
service_user: null
|
|
||||||
service_control_user: null
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
- 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"
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
---
|
|
||||||
# - 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
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
[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
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
- name: "Install neko package"
|
|
||||||
apt:
|
|
||||||
name: neko
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
- import_tasks: apt.yml
|
|
||||||
when: ansible_distribution|lower == 'ubuntu'
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCot1zSeqj7Tj5/7aNMzXAuXQPPxudYFV9z6M03dPijh2bXyHDcXk53xUO8XY5R4GyLhvAn98axbPM++urKY8BXuQqAG36soI7iZJ/KcPY1EKDwVBeZneFC/wMc8HMT0hj9+uHcGAMtmklIgPPkawzLxbEh6oAY4H8Vvz08qyco6suYB5NjkpFwVMf9Xa2Fj8rTodKpPRDBh/Xk+5bh11RKL6b9WcwuwpKU8zl2qZiqNfjr0H+sKEk7ohcYvzSCltLdKJcoKbiCcnrnBJT5/JpGWeAbA2MMmvmt/dJrHykd1CbmXW2DuG4tIlwMb5xU739PoKCePctK1retb8TrWOLT shmyga@shmyga-desktop
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
# 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 +0,0 @@
|
|||||||
ansible_become: yes
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: all
|
|
||||||
vars:
|
|
||||||
ansible_user: "{{ deploy_user }}"
|
|
||||||
tasks:
|
|
||||||
- include_role:
|
|
||||||
name: service
|
|
||||||
tasks_from: restart.yml
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
- hosts: all
|
|
||||||
gather_facts: no
|
|
||||||
roles:
|
|
||||||
- user
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
ansible_user: barin
|
|
||||||
ansible_become_pass: 1234!QAZ
|
|
||||||
ansible_become: yes
|
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
"SdkDir": "C:\\sdk",
|
"SdkDir": "C:\\sdk",
|
||||||
"SSH": {
|
"BuildDir": null,
|
||||||
"PrivateKey": null,
|
"PublishDir": "",
|
||||||
"Passphrase": null
|
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||||
}
|
"Develop": false,
|
||||||
|
"Key": {
|
||||||
|
"store": "keystore.jks",
|
||||||
|
"pass": null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"SdkDir": "/home/holop/sdk",
|
|
||||||
"SSH": {
|
|
||||||
"PrivateKey": null,
|
|
||||||
"Passphrase": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
23
docker-compose.yaml
Normal file
23
docker-compose.yaml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: $PROJECT
|
||||||
|
services:
|
||||||
|
builder:
|
||||||
|
container_name: $PROJECT-builder
|
||||||
|
image: infernal-games/$PROJECT-builder
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: builder
|
||||||
|
secrets:
|
||||||
|
- KEY_STORE
|
||||||
|
- KEY_PASS
|
||||||
|
volumes:
|
||||||
|
- ${SDK_PATH}:/sdk
|
||||||
|
- ${BUILD_PATH}:/app/build
|
||||||
|
- ${TARGET_PATH}:/app/target
|
||||||
|
- ${PUBLISH_PATH}:/app/publish
|
||||||
|
- ./src-gen:/app/src-gen
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
KEY_STORE:
|
||||||
|
file: $KEY_STORE
|
||||||
|
KEY_PASS:
|
||||||
|
environment: KEY_PASS
|
||||||
BIN
docs/Screenshot_2026-05-04_16-22-53.png
Normal file
BIN
docs/Screenshot_2026-05-04_16-22-53.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
267
gulpfile.js
267
gulpfile.js
@@ -1,156 +1,195 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require("gulp");
|
||||||
const gulpClean = require('gulp-clean');
|
const gulpClean = require("gulp-clean");
|
||||||
const Config = require('./config.json');
|
const Config = require("./config.json");
|
||||||
const packageInfo = require('./package.json');
|
const packageInfo = require("./package.json");
|
||||||
const {Sdk, Haxe, Project, FlashPlayer} = require('gulp-haxetool');
|
const { System, Sdk, Haxe, Project } = require("gulp-haxetool");
|
||||||
const dateformat = require('dateformat');
|
const dateformat = require("dateformat");
|
||||||
const argv = require('yargs').argv;
|
const argv = require("yargs").argv;
|
||||||
|
const publish = require("./tasks/gulp-publish");
|
||||||
|
|
||||||
|
Project.useRuffle();
|
||||||
|
|
||||||
|
if (packageInfo.haxe) {
|
||||||
|
Haxe.VERSION = packageInfo.haxe;
|
||||||
|
}
|
||||||
|
|
||||||
// ToDo: update default in gulp-haxetool
|
|
||||||
FlashPlayer.VERSION = '32';
|
|
||||||
//Haxe.VERSION = '4.0.0-rc.2';
|
|
||||||
if (Config.SdkDir) {
|
if (Config.SdkDir) {
|
||||||
Sdk.dir = Config.SdkDir;
|
Sdk.dir = Config.SdkDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config.BuildDir) {
|
||||||
|
Haxe.buildDir = Config.BuildDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.clean = function clean() {
|
exports.clean = function clean() {
|
||||||
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generate = function generate() {
|
exports.setup = function setup() {
|
||||||
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => {
|
const builder = Project.Builder.new(
|
||||||
if (stdout.indexOf('FAIL') > -1) {
|
client.config,
|
||||||
throw stdout;
|
Project.Platform.ANDROID,
|
||||||
|
client.buildSystem,
|
||||||
|
);
|
||||||
|
return builder.prepare();
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.generate = function generate() {
|
||||||
|
return exports.setup().then(() =>
|
||||||
|
new Haxe()
|
||||||
|
.haxelib(["run", "protohx", "generate", "protohx.json"])
|
||||||
|
.then(({ stdout }) => {
|
||||||
|
if (stdout.indexOf("FAIL") > -1) {
|
||||||
|
throw stdout;
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToDo:
|
* base config
|
||||||
* windows target
|
|
||||||
* window exe package (innosetup)
|
|
||||||
*/
|
*/
|
||||||
const config = new Project.Config({
|
const config = new Project.Config({
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Tank\'z',
|
title: "Tank'z",
|
||||||
filename: 'tankz',
|
filename: "tankz",
|
||||||
icon: 'src/client/resources/icon.png',
|
icon: "src/client/resources/icon.png",
|
||||||
pack: 'ru.m.tankz',
|
pack: "ru.m.tankz",
|
||||||
author: 'shmyga <shmyga.z@gmail.com>',
|
author: "shmyga <shmyga.z@gmail.com>",
|
||||||
company: 'MegaLoMania',
|
company: "MegaLoMania",
|
||||||
version: packageInfo.version,
|
version: packageInfo.version + (Config.Develop ? "-SNAPSHOT" : ""),
|
||||||
},
|
},
|
||||||
libs: packageInfo.haxeDependencies,
|
key: Config.Key,
|
||||||
sources: [
|
libs: packageInfo.haxeDependencies,
|
||||||
'src/common/haxe',
|
sources: ["src/common/haxe", "src-gen/haxe"],
|
||||||
'src-gen/haxe',
|
assets: ["src/common/resources/config"],
|
||||||
],
|
flags: ["proto_debug"],
|
||||||
assets: [
|
macros: [
|
||||||
'src/common/resources'
|
`CompilationOption.set('build','${dateformat(new Date(), "yyyy-mm-dd HH:MM:ss")}')`,
|
||||||
],
|
],
|
||||||
macros: [
|
|
||||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const host = argv.host || 'localhost';
|
const host = argv.host || "localhost";
|
||||||
const port = argv.port || 5000;
|
const port = argv.port || 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* client
|
* client
|
||||||
*/
|
*/
|
||||||
const client = new Project(
|
const client = new Project(
|
||||||
Project.BuildSystem.OPENFL,
|
Project.BuildSystem.OPENFL,
|
||||||
[
|
[
|
||||||
Project.Platform.FLASH,
|
Project.Platform.FLASH,
|
||||||
Project.Platform.HTML5,
|
Project.Platform.HTML5,
|
||||||
Project.Platform.LINUX,
|
Project.Platform.LINUX,
|
||||||
Project.Platform.ANDROID,
|
Project.Platform.WINDOWS,
|
||||||
|
Project.Platform.ANDROID,
|
||||||
|
],
|
||||||
|
config.branch({
|
||||||
|
name: "client",
|
||||||
|
sources: ["src/client/haxe"],
|
||||||
|
main: "ru.m.tankz.Client",
|
||||||
|
preloader: "ru.m.tankz.Preloader",
|
||||||
|
assets: ["src/common/resources/level", "src/client/resources"],
|
||||||
|
meta: {
|
||||||
|
width: 1024,
|
||||||
|
height: 576,
|
||||||
|
},
|
||||||
|
flags: [
|
||||||
|
//'proto_debug',
|
||||||
|
//'dom',
|
||||||
|
//'dev_layout',
|
||||||
|
//'bitmap_text',
|
||||||
],
|
],
|
||||||
config.branch({
|
macros: [
|
||||||
name: 'client',
|
`CompilationOption.set('host','${host}')`,
|
||||||
sources: ['src/client/haxe'],
|
`CompilationOption.set('port',${port})`,
|
||||||
main: 'ru.m.tankz.Client',
|
],
|
||||||
preloader: 'ru.m.tankz.Preloader',
|
}),
|
||||||
assets: [
|
|
||||||
'src/client/resources',
|
|
||||||
],
|
|
||||||
meta: {
|
|
||||||
width: 1024,
|
|
||||||
height: 768,
|
|
||||||
},
|
|
||||||
flags: [
|
|
||||||
//'proto_debug',
|
|
||||||
//'dom',
|
|
||||||
//'dev_layout',
|
|
||||||
//'bitmap_text',
|
|
||||||
],
|
|
||||||
macros: [
|
|
||||||
`CompilationOption.set('host','${host}')`,
|
|
||||||
`CompilationOption.set('port',${port})`,
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
module.exports.generate
|
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* editor
|
* editor
|
||||||
*/
|
*/
|
||||||
const editor = new Project(
|
const editor = new Project(
|
||||||
Project.BuildSystem.OPENFL,
|
Project.BuildSystem.OPENFL,
|
||||||
[
|
[Project.Platform.FLASH, Project.Platform.HTML5, Project.Platform.LINUX],
|
||||||
Project.Platform.FLASH,
|
config.branch({
|
||||||
Project.Platform.HTML5,
|
name: "editor",
|
||||||
|
sources: ["src/client/haxe", "src/editor/haxe"],
|
||||||
|
main: "ru.m.tankz.editor.Editor",
|
||||||
|
preloader: "ru.m.tankz.Preloader",
|
||||||
|
assets: ["src/client/resources", "src/editor/resources"],
|
||||||
|
meta: {
|
||||||
|
filename: "editor",
|
||||||
|
pack: "ru.m.tankz.editor",
|
||||||
|
width: 1024,
|
||||||
|
height: 768,
|
||||||
|
},
|
||||||
|
flags: [
|
||||||
|
//'dev_layout',
|
||||||
],
|
],
|
||||||
config.branch({
|
}),
|
||||||
name: 'editor',
|
|
||||||
sources: ['src/client/haxe', 'src/editor/haxe'],
|
|
||||||
main: 'ru.m.tankz.editor.Editor',
|
|
||||||
preloader: 'ru.m.tankz.Preloader',
|
|
||||||
assets: [
|
|
||||||
'src/client/resources',
|
|
||||||
'src/editor/resources',
|
|
||||||
],
|
|
||||||
meta: {
|
|
||||||
filename: 'editor',
|
|
||||||
width: 1024,
|
|
||||||
height: 850,
|
|
||||||
},
|
|
||||||
flags: [
|
|
||||||
//'dev_layout',
|
|
||||||
]
|
|
||||||
})
|
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server
|
* server
|
||||||
*/
|
*/
|
||||||
const server = new Project(
|
const server = new Project(
|
||||||
Project.BuildSystem.HAXE,
|
Project.BuildSystem.HAXE,
|
||||||
Project.Platform.NEKO,
|
Project.Platform.CPP,
|
||||||
config.branch({
|
config.branch({
|
||||||
name: 'server',
|
name: "server",
|
||||||
sources: ['src/server/haxe'],
|
sources: ["src/server/haxe"],
|
||||||
main: 'ru.m.tankz.server.Server',
|
main: "ru.m.tankz.server.Server",
|
||||||
}),
|
assets: ["src/common/resources/level"],
|
||||||
module.exports.generate
|
}),
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* publish
|
||||||
|
*/
|
||||||
|
module.exports.publish = publish(
|
||||||
|
packageInfo.name,
|
||||||
|
packageInfo.version,
|
||||||
|
Config.PublishDir,
|
||||||
|
Config.PublishUrl,
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default
|
* default
|
||||||
*/
|
*/
|
||||||
module.exports.default = gulp.series(
|
const defaultSeries = [
|
||||||
exports.clean,
|
exports.clean,
|
||||||
module.exports['client:flash:build'],
|
exports.generate,
|
||||||
module.exports['client:flash:html'],
|
module.exports["client:flash:build"],
|
||||||
module.exports['client:html5:build'],
|
module.exports["client:flash:html"],
|
||||||
module.exports['client:linux:build'],
|
module.exports["client:html5:build"],
|
||||||
module.exports['client:linux:deb'],
|
|
||||||
//module.exports['client:android:build'],
|
|
||||||
|
|
||||||
module.exports['editor:flash:build'],
|
module.exports["editor:flash:build"],
|
||||||
module.exports['editor:flash:html'],
|
module.exports["editor:flash:html"],
|
||||||
module.exports['editor:html5:build'],
|
module.exports["editor:html5:build"],
|
||||||
|
|
||||||
module.exports['server:neko:build'],
|
module.exports["server:cpp:build"],
|
||||||
);
|
];
|
||||||
|
|
||||||
|
if (System.isLinux) {
|
||||||
|
defaultSeries.push(
|
||||||
|
module.exports["client:linux:build"],
|
||||||
|
module.exports["client:linux:archive"],
|
||||||
|
module.exports["client:linux:deb"],
|
||||||
|
|
||||||
|
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);
|
||||||
|
|||||||
8
hxformat.json
Normal file
8
hxformat.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"indentation": {
|
||||||
|
"character": " "
|
||||||
|
},
|
||||||
|
"wrapping": {
|
||||||
|
"maxLineLength": 120
|
||||||
|
}
|
||||||
|
}
|
||||||
12652
package-lock.json
generated
12652
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@@ -1,26 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.13.0",
|
"version": "0.18.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-add": "0.0.2",
|
"gulp-add": "0.0.2",
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-haxetool": "^0.0.19",
|
"gulp-haxetool": "^0.2.1",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
"haxework": "2.1.1",
|
||||||
"lime": "7.5.0",
|
"lime": "8.0.0",
|
||||||
"openfl": "8.9.1",
|
"openfl": "9.2.0",
|
||||||
"hxcpp": "4.0.8",
|
"hxcpp": "4.2.1",
|
||||||
"promhx": "1.1.0",
|
"protohx": "0.4.6",
|
||||||
"protohx": "0.4.6",
|
"orm": "2.1.0",
|
||||||
"yaml": "1.3.0",
|
"haxe-crypto": "0.0.8",
|
||||||
"orm": "2.1.0",
|
"svg": "1.1.3",
|
||||||
"yield": "2.0.0",
|
"formatter": "1.16.0"
|
||||||
"haxe-crypto": "0.0.7",
|
},
|
||||||
"svg": "1.1.2"
|
"haxe": "4.2.5"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
"protoFiles": [
|
"protoFiles": [
|
||||||
"src/common/proto/core.proto",
|
"src/common/proto/core.proto",
|
||||||
"src/common/proto/game.proto",
|
"src/common/proto/game.proto",
|
||||||
|
"src/common/proto/room.proto",
|
||||||
"src/common/proto/pack.proto"
|
"src/common/proto/pack.proto"
|
||||||
],
|
],
|
||||||
"cleanOut": true,
|
"cleanOut": true,
|
||||||
"haxeOut": "src-gen/haxe",
|
"haxeOut": "src-gen/haxe",
|
||||||
"javaOut": null
|
"javaOut": null
|
||||||
}
|
}
|
||||||
|
|||||||
7
scripts/build
Executable file
7
scripts/build
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
|
||||||
|
source .env
|
||||||
|
mkdir -p "$SDK_PATH" "$PUBLISH_PATH" "$BUILD_PATH" "$TARGET_PATH" "src-gen"
|
||||||
|
docker compose run --rm --user $(id -u):$(id -g) --build --remove-orphans builder
|
||||||
45
scripts/docker-action
Executable file
45
scripts/docker-action
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
|
||||||
|
. .env
|
||||||
|
|
||||||
|
build () {
|
||||||
|
echo "build: $1"
|
||||||
|
. "$1/.env"
|
||||||
|
for PROJECT in "${DOCKER_PROJECTS[@]}"; do
|
||||||
|
IFS=: read -r PROJECT_NAME PROJECT_TARGET <<< "$PROJECT"
|
||||||
|
ARGS=("build")
|
||||||
|
for ARG in ${DOCKER_ARGS[@]}; do
|
||||||
|
ARGS+=("--build-arg" "$ARG")
|
||||||
|
done
|
||||||
|
if [ -n "$PROJECT_TARGET" ]; then
|
||||||
|
ARGS+=("--target" "$PROJECT_TARGET")
|
||||||
|
fi
|
||||||
|
ARGS+=("-t" "$DOCKER_GROUP/$PROJECT_NAME" ".")
|
||||||
|
ARGS+=("-f" "$1/Dockerfile")
|
||||||
|
echo "${ARGS[@]}"
|
||||||
|
docker "${ARGS[@]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
publish () {
|
||||||
|
echo "publish: $1"
|
||||||
|
. "$1/.env"
|
||||||
|
for PROJECT in "${DOCKER_PROJECTS[@]}"; do
|
||||||
|
IFS=: read -r PROJECT_NAME PROJECT_TARGET <<< "$PROJECT"
|
||||||
|
docker tag $DOCKER_GROUP/$PROJECT_NAME $DOCKER_ROOT/$PROJECT_NAME:$VERSION
|
||||||
|
docker tag $DOCKER_GROUP/$PROJECT_NAME $DOCKER_ROOT/$PROJECT_NAME:latest
|
||||||
|
docker push $DOCKER_ROOT/$PROJECT_NAME:$VERSION
|
||||||
|
docker push $DOCKER_ROOT/$PROJECT_NAME:latest
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFAULT_TARGETS="."
|
||||||
|
TARGETS="${@-$DEFAULT_TARGETS}"
|
||||||
|
|
||||||
|
DOCKER_ACTION="${DOCKER_ACTION-build}"
|
||||||
|
|
||||||
|
for TARGET in $TARGETS; do
|
||||||
|
$DOCKER_ACTION "$TARGET"
|
||||||
|
done
|
||||||
13
scripts/format
Executable file
13
scripts/format
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
|
||||||
|
source .env
|
||||||
|
source $NEKO_SDK/activate
|
||||||
|
source $HAXE_SDK/activate
|
||||||
|
haxelib install formatter
|
||||||
|
haxelib run formatter \
|
||||||
|
-s ./src/common/haxe \
|
||||||
|
-s ./src/client/haxe \
|
||||||
|
-s ./src/server/haxe \
|
||||||
|
-s ./src/editor/haxe
|
||||||
14
scripts/lint
Executable file
14
scripts/lint
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
|
||||||
|
source .env
|
||||||
|
source $NEKO_SDK/activate
|
||||||
|
source $HAXE_SDK/activate
|
||||||
|
haxelib install formatter
|
||||||
|
haxelib run formatter \
|
||||||
|
--check \
|
||||||
|
-s ./src/common/haxe \
|
||||||
|
-s ./src/client/haxe \
|
||||||
|
-s ./src/server/haxe \
|
||||||
|
-s ./src/editor/haxe
|
||||||
35
scripts/publish
Executable file
35
scripts/publish
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
source .env
|
||||||
|
|
||||||
|
VERSION=$(grep -m 1 'version' ./package.json | grep -oP '"version"\s*:\s*"\K\d+\.\d+\.\d+')
|
||||||
|
|
||||||
|
PACKAGES=(
|
||||||
|
"android/${PROJECT}_${VERSION}.apk"
|
||||||
|
"debian/${PROJECT}_${VERSION}_all.deb"
|
||||||
|
"archive/${PROJECT}_${VERSION}_linux.tar.gz"
|
||||||
|
"archive/${PROJECT}_${VERSION}_win.zip"
|
||||||
|
"installer/${PROJECT}_${VERSION}.exe"
|
||||||
|
)
|
||||||
|
|
||||||
|
for PACKAGE in "${PACKAGES[@]}"
|
||||||
|
do
|
||||||
|
if [ -f "${PUBLISH_PATH}/${PACKAGE}" ]; then
|
||||||
|
PACKAGE_NAME=$(basename "$PACKAGE")
|
||||||
|
echo "publish: $PACKAGE"
|
||||||
|
curl --user "${PUBLISH_USER}:${PUBLISH_PASSWORD}" -X DELETE \
|
||||||
|
"${REPO}/generic/${PROJECT}/${VERSION}/${PACKAGE_NAME}"
|
||||||
|
curl --user "${PUBLISH_USER}:${PUBLISH_PASSWORD}" \
|
||||||
|
--upload-file "${PUBLISH_PATH}/${PACKAGE}" \
|
||||||
|
"${REPO}/generic/${PROJECT}/${VERSION}/${PACKAGE_NAME}"
|
||||||
|
|
||||||
|
if [[ "$PACKAGE" == *.deb ]]; then
|
||||||
|
curl --user "${PUBLISH_USER}:${PUBLISH_PASSWORD}" -X DELETE \
|
||||||
|
"${REPO}/debian/pool/noble/main/${PROJECT}/${VERSION}/all"
|
||||||
|
curl --user "${PUBLISH_USER}:${PUBLISH_PASSWORD}" \
|
||||||
|
--upload-file "${PUBLISH_PATH}/${PACKAGE}" \
|
||||||
|
"${REPO}/debian/pool/noble/main/upload"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
5
scripts/setup
Executable file
5
scripts/setup
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
cd "$(dirname $(dirname "$0"))" || exit
|
||||||
|
|
||||||
|
npm ci
|
||||||
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');
|
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,84 +1,55 @@
|
|||||||
package ru.m.animate;
|
package ru.m.animate;
|
||||||
|
|
||||||
import flash.display.PixelSnapping;
|
|
||||||
import haxe.Timer;
|
|
||||||
import flash.display.Bitmap;
|
import flash.display.Bitmap;
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
|
import flash.display.PixelSnapping;
|
||||||
|
|
||||||
typedef Frame = {
|
typedef Frame = {
|
||||||
var image:BitmapData;
|
var image:BitmapData;
|
||||||
var length:Int;
|
var length:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Animate extends Bitmap {
|
class Animate extends Bitmap {
|
||||||
|
public var playing(default, default):Bool;
|
||||||
|
public var frames(default, set):Array<Frame>;
|
||||||
|
|
||||||
private static var timer:Timer;
|
private var sequence:Array<BitmapData>;
|
||||||
private static var instances:Array<Animate> = [];
|
private var index:Int;
|
||||||
|
|
||||||
private static function init():Void {
|
@:provide private static var manager:AnimateManager;
|
||||||
if (timer == null) {
|
|
||||||
timer = new Timer(30);
|
public function new(?frames:Array<Frame>) {
|
||||||
timer.run = updateAll;
|
super(null, PixelSnapping.AUTO, true);
|
||||||
}
|
this.frames = frames == null ? [] : frames;
|
||||||
|
manager.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||||
|
sequence = [];
|
||||||
|
index = 0;
|
||||||
|
if (value != null) {
|
||||||
|
frames = value;
|
||||||
|
for (frame in frames) {
|
||||||
|
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
||||||
|
}
|
||||||
|
bitmapData = sequence[0];
|
||||||
|
} else {
|
||||||
|
bitmapData = null;
|
||||||
}
|
}
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
|
||||||
private static function updateAll():Void {
|
public function update():Void {
|
||||||
for (instance in instances) {
|
if (++index >= sequence.length) {
|
||||||
if (instance.playing) {
|
index = 0;
|
||||||
instance.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
var nextBitmapData = sequence[index];
|
||||||
|
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
||||||
|
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
||||||
|
bitmapData = nextBitmapData;
|
||||||
|
}
|
||||||
|
|
||||||
public var playing(default, set):Bool;
|
public function dispose():Void {
|
||||||
public var frames(default, set):Array<Frame>;
|
manager.remove(this);
|
||||||
|
}
|
||||||
private var sequence:Array<BitmapData>;
|
|
||||||
private var index:Int;
|
|
||||||
|
|
||||||
public function new(?frames:Array<Frame>) {
|
|
||||||
super(null, PixelSnapping.AUTO, true);
|
|
||||||
this.frames = frames == null ? [] : frames;
|
|
||||||
init();
|
|
||||||
instances.push(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_frames(value:Array<Frame>):Array<Frame> {
|
|
||||||
sequence = [];
|
|
||||||
index = 0;
|
|
||||||
if (value != null) {
|
|
||||||
frames = value;
|
|
||||||
for (frame in frames) {
|
|
||||||
sequence = sequence.concat([for (i in 0...frame.length) frame.image]);
|
|
||||||
}
|
|
||||||
bitmapData = sequence[0];
|
|
||||||
} else {
|
|
||||||
bitmapData = null;
|
|
||||||
}
|
|
||||||
return frames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_playing(value:Bool):Bool {
|
|
||||||
if (playing != value) {
|
|
||||||
playing = value;
|
|
||||||
}
|
|
||||||
return playing;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function update():Void {
|
|
||||||
if (++index >= sequence.length) {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
var nextBitmapData = sequence[index];
|
|
||||||
x -= (nextBitmapData.width - bitmapData.width) / 2;
|
|
||||||
y -= (nextBitmapData.height - bitmapData.height) / 2;
|
|
||||||
bitmapData = nextBitmapData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dispose():Void {
|
|
||||||
if (instances.indexOf(this) > -1) {
|
|
||||||
instances.remove(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/client/haxe/ru/m/animate/AnimateManager.hx
Normal file
34
src/client/haxe/ru/m/animate/AnimateManager.hx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.m.animate;
|
||||||
|
|
||||||
|
@:provide class AnimateManager {
|
||||||
|
public var playing(default, default):Bool;
|
||||||
|
|
||||||
|
private var timer:Timer;
|
||||||
|
private var animations:Array<Animate>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
animations = [];
|
||||||
|
timer = new Timer(30);
|
||||||
|
timer.run = update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update():Void {
|
||||||
|
if (playing) {
|
||||||
|
for (animation in animations) {
|
||||||
|
if (animation.playing) {
|
||||||
|
animation.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(animate:Animate):Void {
|
||||||
|
animations.push(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove(animate:Animate):Void {
|
||||||
|
if (animations.indexOf(animate) > -1) {
|
||||||
|
animations.remove(animate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,24 +3,23 @@ package ru.m.animate;
|
|||||||
import promhx.Deferred;
|
import promhx.Deferred;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
|
|
||||||
|
|
||||||
class OnceAnimate extends Animate {
|
class OnceAnimate extends Animate {
|
||||||
|
private var deferred:Deferred<Animate>;
|
||||||
|
|
||||||
private var deferred:Deferred<Animate>;
|
public function play():Promise<Animate> {
|
||||||
|
deferred = new Deferred();
|
||||||
|
playing = true;
|
||||||
|
return deferred.promise();
|
||||||
|
}
|
||||||
|
|
||||||
public function play():Promise<Animate> {
|
override public function update():Void {
|
||||||
deferred = new Deferred();
|
super.update();
|
||||||
playing = true;
|
if (index == 0) {
|
||||||
return deferred.promise();
|
playing = false;
|
||||||
}
|
if (deferred != null) {
|
||||||
|
deferred.resolve(this);
|
||||||
override private function update():Void {
|
}
|
||||||
super.update();
|
dispose();
|
||||||
if (index == 0) {
|
|
||||||
playing = false;
|
|
||||||
if (deferred != null) {
|
|
||||||
deferred.resolve(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
42
src/client/haxe/ru/m/control/ControlBus.hx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import hw.signal.Signal;
|
||||||
|
import ru.m.control.IControlBus;
|
||||||
|
|
||||||
|
class ControlBus implements IControlBus {
|
||||||
|
private static inline var TAG = "control";
|
||||||
|
|
||||||
|
public var devices(default, null):Array<IControlDevice>;
|
||||||
|
|
||||||
|
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 hw.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 hw.signal.Signal;
|
||||||
|
|
||||||
|
interface IControlDevice {
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
public function dispose():Void;
|
||||||
|
}
|
||||||
61
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
61
src/client/haxe/ru/m/control/JoystickDevice.hx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import hw.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
37
src/client/haxe/ru/m/control/KeyboardDevice.hx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package ru.m.control;
|
||||||
|
|
||||||
|
import flash.display.Stage;
|
||||||
|
import flash.events.KeyboardEvent;
|
||||||
|
import hw.signal.Signal;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
|
||||||
|
class KeyboardDevice implements IControlDevice {
|
||||||
|
public var type(default, null):DeviceType;
|
||||||
|
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||||
|
|
||||||
|
private var stage:Stage;
|
||||||
|
|
||||||
|
public 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,21 @@
|
|||||||
|
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,45 +1,55 @@
|
|||||||
package ru.m.skin;
|
package ru.m.skin;
|
||||||
|
|
||||||
import format.SVG;
|
import format.SVG;
|
||||||
import haxework.color.Color;
|
import hw.color.Color;
|
||||||
import haxework.color.ColorUtil;
|
import hw.view.form.ButtonView;
|
||||||
import haxework.view.ButtonView;
|
import hw.view.skin.ISkin;
|
||||||
import haxework.view.skin.ISkin;
|
|
||||||
|
|
||||||
class ButtonSVGSkin implements ISkin<ButtonView> {
|
using StringTools;
|
||||||
|
using hw.color.ColorUtil;
|
||||||
|
|
||||||
private var svg:String;
|
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||||
private var color:Color;
|
@: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>;
|
private var svgs:Map<ButtonState, SVG>;
|
||||||
|
|
||||||
public function new(svg:String, color:Color) {
|
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||||
this.svg = svg;
|
this.svg = svg;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
init();
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
private inline function buildSVG(color:Color):SVG {
|
public function draw(view:ButtonView):Void {
|
||||||
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}'));
|
var svg = svgs.get(view.state);
|
||||||
}
|
var graphics = view.content.graphics;
|
||||||
|
graphics.beginFill(0, 0);
|
||||||
private function init():Void {
|
graphics.drawRect(0, 0, view.width, view.height);
|
||||||
svgs = new Map<ButtonState, SVG>();
|
graphics.beginFill(color);
|
||||||
svgs.set(ButtonState.UP, buildSVG(color));
|
if (!solid) {
|
||||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
graphics.lineStyle(2, color.multiply(1.5));
|
||||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
|
||||||
svgs.set(ButtonState.DISABLED, buildSVG(ColorUtil.grey(color)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function draw(view:ButtonView):Void {
|
|
||||||
var svg = svgs.get(view.state);
|
|
||||||
var graphics = view.content.graphics;
|
|
||||||
graphics.beginFill(0, 0);
|
|
||||||
graphics.drawRect(0, 0, view.width, view.height);
|
|
||||||
graphics.beginFill(color);
|
|
||||||
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5));
|
|
||||||
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
|
||||||
graphics.lineStyle();
|
|
||||||
graphics.endFill();
|
|
||||||
}
|
}
|
||||||
|
// ToDo: padding
|
||||||
|
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
|
||||||
|
graphics.lineStyle();
|
||||||
|
graphics.endFill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
178
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
178
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import flash.text.TextFormatAlign;
|
||||||
|
import hw.color.Color;
|
||||||
|
import hw.view.geometry.Box;
|
||||||
|
import hw.view.geometry.HAlign;
|
||||||
|
import hw.view.geometry.SizeValue;
|
||||||
|
import hw.view.geometry.VAlign;
|
||||||
|
import hw.view.theme.ITheme;
|
||||||
|
import hw.view.theme.Theme;
|
||||||
|
import hw.view.utils.DrawUtil;
|
||||||
|
import openfl.Assets;
|
||||||
|
import ru.m.skin.ButtonSVGSkin;
|
||||||
|
|
||||||
|
using hw.color.ColorUtil;
|
||||||
|
|
||||||
|
class AppTheme extends Theme {
|
||||||
|
public static var COLORS(default, never):ThemeColors = {
|
||||||
|
light: 0x95937D,
|
||||||
|
dark: 0x777564,
|
||||||
|
text: 0xE7E0BB,
|
||||||
|
active: 0xFFFF00,
|
||||||
|
}
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super({embed: true}, COLORS, {base: "3h", big: "4h", veryBig: "4.5h"});
|
||||||
|
}
|
||||||
|
|
||||||
|
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("button.small", [
|
||||||
|
"font.size" => SizeValue.fromString("3h"),
|
||||||
|
"geometry.padding" => Box.fromArray([8, 2]),
|
||||||
|
"skin.round" => 5,
|
||||||
|
], ["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.big,
|
||||||
|
"geometry.width" => SizeValue.fromString("12h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("12h"),
|
||||||
|
"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([20, 10]),
|
||||||
|
"layout.vAlign" => VAlign.MIDDLE,
|
||||||
|
], ["light"]));
|
||||||
|
|
||||||
|
register(new Style("panel_button",
|
||||||
|
["font.size" => fontSize.big, "geometry.height" => SizeValue.fromString("100%"),], ["button"]));
|
||||||
|
|
||||||
|
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.fromString("8h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("8h"),
|
||||||
|
]));
|
||||||
|
|
||||||
|
register(new Style("icon.tank", [
|
||||||
|
"geometry.width" => SizeValue.fromString("6h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("6h"),
|
||||||
|
"skin.fillType" => FillType.CONTAIN,
|
||||||
|
]));
|
||||||
|
|
||||||
|
var green:Color = 0x00ff00;
|
||||||
|
var red:Color = 0xff0000;
|
||||||
|
register(new Style("result.winner", [
|
||||||
|
"skin.border.color" => green,
|
||||||
|
"skin.border.alpha" => 0.5,
|
||||||
|
"skin.border.thickness" => 5,
|
||||||
|
"skin.round" => 10,
|
||||||
|
], ["light"]));
|
||||||
|
register(new Style("result.loser", [
|
||||||
|
"skin.border.color" => red,
|
||||||
|
"skin.border.alpha" => 0.5,
|
||||||
|
"skin.border.thickness" => 5,
|
||||||
|
"skin.round" => 10,
|
||||||
|
], ["light"]));
|
||||||
|
register(new Style("player.winner", ["skin.background.alpha" => 0.2, "skin.background.color" => green,]));
|
||||||
|
register(new Style("player.loser", ["skin.background.alpha" => 0.2, "skin.background.color" => red,]));
|
||||||
|
|
||||||
|
register(new Style("button.pack", [
|
||||||
|
"geometry.width" => SizeValue.fromString("35h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("20h"),
|
||||||
|
"geometry.padding" => Box.fromFloat(5),
|
||||||
|
"layout.hAlign" => HAlign.CENTER,
|
||||||
|
"layout.vAlign" => VAlign.MIDDLE,
|
||||||
|
"content.buttonMode" => true,
|
||||||
|
"content.mouseChildren" => false,
|
||||||
|
"skin.round" => 15,
|
||||||
|
], ["border", "light"]));
|
||||||
|
|
||||||
|
register(new Style("button.menu", ["geometry.padding" => Box.fromArray([20, 10]),]));
|
||||||
|
|
||||||
|
registerButton("settings", "cog-solid.svg");
|
||||||
|
registerButton("close", "times-circle-solid.svg");
|
||||||
|
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||||
|
registerButton("prev", "arrow-alt-circle-left-solid.svg");
|
||||||
|
registerButton("start", "play-circle-solid.svg");
|
||||||
|
registerButton("login", "sign-in-solid.svg");
|
||||||
|
registerButton("logout", "sign-out-solid.svg");
|
||||||
|
registerButton("bars", "bars-solid.svg");
|
||||||
|
|
||||||
|
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.text, "skin.activeColor" => colors.active,]));
|
||||||
|
|
||||||
|
register(new Style("render", ["skin.background.color" => colors.dark,]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerButton(name:String, resource:String, solid:Bool = false):Void {
|
||||||
|
register(new Style('button.$name', [
|
||||||
|
"geometry.width" => SizeValue.fromString("10h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("10h"),
|
||||||
|
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light,
|
||||||
|
solid),
|
||||||
|
]));
|
||||||
|
register(new Style('button.$name.small', [
|
||||||
|
"geometry.width" => SizeValue.fromString("7h"),
|
||||||
|
"geometry.height" => SizeValue.fromString("7h"),
|
||||||
|
"skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), colors.light,
|
||||||
|
solid),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +1,60 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
|
import ru.m.animate.AnimateManager;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import haxework.animate.Animate;
|
import hw.animate.Animate;
|
||||||
import haxework.log.TraceLogger;
|
import hw.log.TraceLogger;
|
||||||
import haxework.view.Root;
|
import hw.net.manage.LoaderManager;
|
||||||
|
import hw.view.Root;
|
||||||
|
import hw.view.popup.PopupManager;
|
||||||
|
import ru.m.tankz.storage.GameStorage;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.view.ClientView;
|
import ru.m.tankz.view.ClientView;
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
private static inline var TAG = "Tankz";
|
private static inline var TAG = "Tankz";
|
||||||
|
|
||||||
public static function main() {
|
@:provide private static var settings:SettingsStorage;
|
||||||
L.push(new TraceLogger());
|
|
||||||
#if flash
|
|
||||||
L.push(new haxework.log.JSLogger());
|
|
||||||
#end
|
|
||||||
#if debug
|
|
||||||
//L.push(new haxework.log.SocketLogger());
|
|
||||||
#end
|
|
||||||
Const.init();
|
|
||||||
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
|
|
||||||
Style.register();
|
|
||||||
var view:ClientView = new ClientView();
|
|
||||||
Root.bind(view);
|
|
||||||
view.launch();
|
|
||||||
|
|
||||||
#if debug
|
public static function main() {
|
||||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
L.push(new TraceLogger());
|
||||||
Lib.current.addChild(fps);
|
#if flash
|
||||||
#end
|
L.push(new hw.log.JSLogger());
|
||||||
}
|
#end
|
||||||
|
#if debug
|
||||||
|
// L.push(new hw.log.SocketLogger());
|
||||||
|
#end
|
||||||
|
// ToDo: fix @:provide macro
|
||||||
|
PopupManager;
|
||||||
|
LoaderManager;
|
||||||
|
GameStorage;
|
||||||
|
AnimateManager;
|
||||||
|
//
|
||||||
|
Const.init();
|
||||||
|
Init.init();
|
||||||
|
// TODO:
|
||||||
|
// Animate.bind(Lib.current.stage);
|
||||||
|
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||||
|
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||||
|
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||||
|
L.i(TAG, 'Mobile: ${Device.isMobile()}');
|
||||||
|
#if linux
|
||||||
|
LinuxIcon.apply();
|
||||||
|
#end
|
||||||
|
var view:ClientView = new ClientView();
|
||||||
|
Root.bind(view);
|
||||||
|
view.launch();
|
||||||
|
|
||||||
|
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||||
|
fps.visible = settings.displayFPS;
|
||||||
|
Lib.current.addChild(fps);
|
||||||
|
|
||||||
|
settings.signal.connect(function(setting) {
|
||||||
|
switch setting {
|
||||||
|
case DISPLAY_FPS(value):
|
||||||
|
fps.visible = value;
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ import flash.Lib;
|
|||||||
import flash.system.Capabilities;
|
import flash.system.Capabilities;
|
||||||
|
|
||||||
class Const {
|
class Const {
|
||||||
public static var FPS:Int;
|
public static var FPS:Int;
|
||||||
public static var BUILD:String;
|
public static var BUILD:String;
|
||||||
public static var VERSION:String;
|
public static var VERSION:String;
|
||||||
public static var DEBUG:Bool;
|
public static var NAME:String;
|
||||||
|
public static var DEBUG:Bool;
|
||||||
|
|
||||||
public static function init():Void {
|
public static function init():Void {
|
||||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||||
BUILD = CompilationOption.get("build");
|
BUILD = CompilationOption.get("build");
|
||||||
VERSION = Lib.current.stage.application.meta.get("version");
|
VERSION = Lib.current.stage.application.meta.get("version");
|
||||||
DEBUG = Capabilities.isDebugger;
|
NAME = Lib.current.stage.application.meta.get("name");
|
||||||
}
|
DEBUG = Capabilities.isDebugger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,78 @@
|
|||||||
package ru.m.tankz;
|
package ru.m.tankz;
|
||||||
|
|
||||||
import haxework.animate.FadeAnimate;
|
import flash.Lib;
|
||||||
import haxework.animate.UnFadeAnimate;
|
import hw.animate.FadeAnimate;
|
||||||
import haxework.resources.IResources;
|
import hw.animate.UnFadeAnimate;
|
||||||
import haxework.resources.Resources;
|
import hw.storage.SharedObjectStorage;
|
||||||
import haxework.view.popup.PopupManager;
|
import hw.view.popup.PopupManager;
|
||||||
|
import hw.view.theme.ITheme;
|
||||||
|
import lime.ui.Gamepad;
|
||||||
|
import lime.ui.Joystick;
|
||||||
import ru.m.connect.IConnection;
|
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.CachedLevelBundle;
|
||||||
|
import ru.m.tankz.bundle.ClientLevelSource;
|
||||||
import ru.m.tankz.bundle.ConfigBundle;
|
import ru.m.tankz.bundle.ConfigBundle;
|
||||||
import ru.m.tankz.bundle.IConfigBundle;
|
import ru.m.tankz.bundle.IConfigBundle;
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
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.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.update.Updater;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
|
||||||
import ru.m.tankz.storage.MultiplayerStorage;
|
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
|
||||||
|
|
||||||
class Init {
|
class Init {
|
||||||
|
@:provide static var theme:ITheme;
|
||||||
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
@:provide static var configBundle:IConfigBundle;
|
||||||
|
@:provide static var popupManager:PopupManager;
|
||||||
|
@:provide static var connection:IConnection<Request, Response>;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
@:provide static var updater:Updater;
|
||||||
|
|
||||||
@:provide static var resources:IResources;
|
private static function buildConnection():IConnection<Request, Response> {
|
||||||
@:provide static var levelBundle:ILevelBundle;
|
var host:String = CompilationOption.get("host");
|
||||||
@:provide static var configBundle:IConfigBundle;
|
var port:Int = CompilationOption.get("port");
|
||||||
@:provide static var settingsStorage:SettingsStorage;
|
L.d("Init", 'connect to $host:$port');
|
||||||
@:provide static var multiplayerStorage:MultiplayerStorage;
|
#if flash
|
||||||
@:provide static var gameStorage:GameStorage;
|
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
||||||
@:provide static var recordStorage:RecordStorage;
|
#elseif html5
|
||||||
@:provide static var soundManager:SoundManager;
|
return new ru.m.connect.js.JsConnection<Request, Response>(host,
|
||||||
@:provide static var networkManager:NetworkManager;
|
port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
||||||
@:provide static var popupManager:PopupManager;
|
#else
|
||||||
@:provide static var connection:IConnection<Request, Response>;
|
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
private static function buildConnection():IConnection<Request, Response> {
|
public static function init():Void {
|
||||||
var host:String = CompilationOption.get("host");
|
theme = new AppTheme();
|
||||||
var port:Int = CompilationOption.get("port");
|
levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
|
||||||
L.d("Init", 'connect to $host:$port');
|
levelBundle.load();
|
||||||
#if flash
|
configBundle = new ConfigBundle();
|
||||||
return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
|
|
||||||
#elseif html5
|
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||||
return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
|
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||||
#else
|
|
||||||
return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
|
connection = buildConnection();
|
||||||
#end
|
|
||||||
|
bus = new ControlBus();
|
||||||
|
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||||
|
|
||||||
|
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
|
||||||
|
|
||||||
|
for (device in Gamepad.devices) {
|
||||||
|
trace('gamepad', device);
|
||||||
}
|
}
|
||||||
|
Gamepad.onConnect.add(function(device) {
|
||||||
|
trace('connect gamepad', device);
|
||||||
|
});
|
||||||
|
|
||||||
public static function init():Void {
|
for (device in Joystick.devices) {
|
||||||
resources = new Resources();
|
bus.connect(new JoystickDevice(device));
|
||||||
levelBundle = new LevelBundle();
|
|
||||||
configBundle = new ConfigBundle();
|
|
||||||
settingsStorage = new SettingsStorage();
|
|
||||||
multiplayerStorage = new MultiplayerStorage();
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
Joystick.onConnect.add(function(device) {
|
||||||
|
bus.connect(new JoystickDevice(device));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,20 @@ import flash.Lib;
|
|||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
|
||||||
class LinuxIcon {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private static function prepareIcon(bitmap:BitmapData):BitmapData {
|
public static function apply() {
|
||||||
var matrix:Array<Float> = [];
|
var icon = Assets.getBitmapData("resources/icon.png");
|
||||||
matrix = matrix.concat([0, 0, 1, 0, 0]);
|
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,137 +5,136 @@ import flash.display.Sprite;
|
|||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.events.ProgressEvent;
|
import flash.events.ProgressEvent;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import haxework.view.core.Size;
|
import hw.view.geometry.Size;
|
||||||
|
import ru.m.tankz.AppTheme;
|
||||||
|
|
||||||
class Progress extends Sprite {
|
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;
|
||||||
|
|
||||||
public var color(default, set):Int = 0;
|
private var maskShape:Shape;
|
||||||
public var backColor(default, set):Int = 0;
|
private var toRedraw:Bool;
|
||||||
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;
|
public function new() {
|
||||||
private var toRedraw:Bool;
|
super();
|
||||||
|
maskShape = new Shape();
|
||||||
|
addChild(maskShape);
|
||||||
|
mask = maskShape;
|
||||||
|
}
|
||||||
|
|
||||||
public function new() {
|
private inline function get_radius():Float {
|
||||||
super();
|
return Math.min(size.width, size.height) / 2;
|
||||||
maskShape = new Shape();
|
}
|
||||||
addChild(maskShape);
|
|
||||||
mask = maskShape;
|
private function set_color(value:Int):Int {
|
||||||
|
if (color != value) {
|
||||||
|
color = value;
|
||||||
|
toRedraw = true;
|
||||||
}
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
private inline function get_radius():Float {
|
private function set_backColor(value:Int):Int {
|
||||||
return Math.min(size.width, size.height) / 2;
|
if (backColor != value) {
|
||||||
|
backColor = value;
|
||||||
|
toRedraw = true;
|
||||||
}
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
private function set_color(value:Int):Int {
|
private function set_progress(value:Float):Float {
|
||||||
if (color != value) {
|
if (progress != value) {
|
||||||
color = value;
|
progress = value;
|
||||||
toRedraw = true;
|
toRedraw = true;
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
private function set_backColor(value:Int):Int {
|
private function set_size(value:Size):Size {
|
||||||
if (backColor != value) {
|
if (size != value) {
|
||||||
backColor = value;
|
size = value;
|
||||||
toRedraw = true;
|
toRedraw = true;
|
||||||
}
|
|
||||||
return color;
|
|
||||||
}
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
private function set_progress(value:Float):Float {
|
public function update():Void {
|
||||||
if (progress != value) {
|
if (toRedraw) {
|
||||||
progress = value;
|
redraw();
|
||||||
toRedraw = true;
|
redrawMask();
|
||||||
}
|
toRedraw = false;
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function set_size(value:Size):Size {
|
public function redraw():Void {
|
||||||
if (size != value) {
|
graphics.clear();
|
||||||
size = value;
|
graphics.beginFill(color);
|
||||||
toRedraw = true;
|
graphics.drawCircle(radius, radius, radius);
|
||||||
}
|
graphics.beginFill(backColor);
|
||||||
return size;
|
graphics.drawCircle(radius, radius, radius / 2);
|
||||||
}
|
graphics.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
public function update():Void {
|
public function redrawMask():Void {
|
||||||
if (toRedraw) {
|
maskShape.graphics.clear();
|
||||||
redraw();
|
maskShape.graphics.beginFill(0x00ff00);
|
||||||
redrawMask();
|
maskShape.graphics.moveTo(radius, radius);
|
||||||
toRedraw = false;
|
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) {
|
||||||
public function redraw():Void {
|
lineToRadians(progress * (Math.PI * 2) + rotation);
|
||||||
graphics.clear();
|
|
||||||
graphics.beginFill(color);
|
|
||||||
graphics.drawCircle(radius, radius, radius);
|
|
||||||
graphics.beginFill(backColor);
|
|
||||||
graphics.drawCircle(radius, radius, radius / 2);
|
|
||||||
graphics.endFill();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function redrawMask():Void {
|
|
||||||
maskShape.graphics.clear();
|
|
||||||
maskShape.graphics.beginFill(0x00ff00);
|
|
||||||
maskShape.graphics.moveTo(radius, radius);
|
|
||||||
var sides = 6;
|
|
||||||
var rotation = (-(Math.PI) / 2);
|
|
||||||
var r = radius / Math.cos(1/sides * Math.PI);
|
|
||||||
var lineToRadians = function(rads:Float):Void {
|
|
||||||
maskShape.graphics.lineTo(Math.cos(rads) * r + radius, Math.sin(rads) * r + radius);
|
|
||||||
};
|
|
||||||
var sidesToDraw:Int = Math.floor(progress * sides);
|
|
||||||
for (i in 0...sidesToDraw + 1) {
|
|
||||||
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
|
|
||||||
}
|
|
||||||
if (progress * sides != sidesToDraw) {
|
|
||||||
lineToRadians(progress * (Math.PI * 2) + rotation);
|
|
||||||
}
|
|
||||||
maskShape.graphics.endFill();
|
|
||||||
}
|
}
|
||||||
|
maskShape.graphics.endFill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Preloader extends Sprite {
|
class Preloader extends Sprite {
|
||||||
|
private var progress:Progress;
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
public function new() {
|
private function onResize(event:Event):Void {
|
||||||
super();
|
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
|
||||||
Lib.current.stage.color = Style.lightColor;
|
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
|
||||||
progress = new Progress();
|
}
|
||||||
progress.color = Style.darkColor;
|
|
||||||
progress.backColor = Style.lightColor;
|
|
||||||
progress.size = [200, 200];
|
|
||||||
addChild(progress);
|
|
||||||
onResize(null);
|
|
||||||
Lib.current.stage.addEventListener(Event.RESIZE, onResize);
|
|
||||||
Lib.current.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
|
||||||
Lib.current.stage.addEventListener(ProgressEvent.PROGRESS, onProgress);
|
|
||||||
addEventListener(Event.COMPLETE, onComplete);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onResize(event:Event):Void {
|
private function onEnterFrame(event:Event):Void {
|
||||||
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
|
progress.update();
|
||||||
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function onEnterFrame(event:Event):Void {
|
private function onProgress(event:ProgressEvent):Void {
|
||||||
progress.update();
|
progress.progress = event.bytesLoaded / event.bytesTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onProgress(event:ProgressEvent):Void {
|
private function onComplete(event:Event):Void {
|
||||||
progress.progress = event.bytesLoaded / event.bytesTotal;
|
progress.update();
|
||||||
}
|
Lib.current.stage.removeEventListener(Event.RESIZE, onResize);
|
||||||
|
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
private function onComplete(event:Event):Void {
|
Lib.current.stage.removeEventListener(ProgressEvent.PROGRESS, onProgress);
|
||||||
progress.update();
|
removeEventListener(Event.COMPLETE, onComplete);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,152 +0,0 @@
|
|||||||
package ru.m.tankz;
|
|
||||||
|
|
||||||
import flash.text.Font;
|
|
||||||
import flash.text.FontType;
|
|
||||||
import haxework.color.ColorUtil;
|
|
||||||
import haxework.resources.IResources;
|
|
||||||
import haxework.view.core.Geometry;
|
|
||||||
import haxework.view.core.HAlign;
|
|
||||||
import haxework.view.core.VAlign;
|
|
||||||
import haxework.view.ITextView;
|
|
||||||
import haxework.view.layout.Layout;
|
|
||||||
import haxework.view.skin.ISkin;
|
|
||||||
import haxework.view.skin.Skin;
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.skin.ButtonSVGSkin;
|
|
||||||
|
|
||||||
class Style {
|
|
||||||
|
|
||||||
@:provide private static var resources:IResources;
|
|
||||||
|
|
||||||
public static var lightColor = 0x95937D;
|
|
||||||
public static var darkColor = 0x777564;
|
|
||||||
public static var textColor = 0xE7E0BB;
|
|
||||||
public static var activeColor = 0xFFFF00;
|
|
||||||
|
|
||||||
public static var baseFontSize = 18;
|
|
||||||
public static var bigFontSize = 22;
|
|
||||||
public static var veryBigFontSize = 24;
|
|
||||||
|
|
||||||
public static var fontFamily = "Courirer New";
|
|
||||||
public static var fontEmbed = false;
|
|
||||||
|
|
||||||
public static function text(color):ISkin<ITextView> {
|
|
||||||
return Skin.text(color, baseFontSize, fontFamily, fontEmbed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function registerButton(name:String, resource:String):Void {
|
|
||||||
resources.skin.put('button.$name', [
|
|
||||||
Skin.size(64, 64),
|
|
||||||
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put('button.$name.small', [
|
|
||||||
Skin.size(32, 32),
|
|
||||||
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function register(font:Font = null):Void {
|
|
||||||
resources.color.put("light", lightColor);
|
|
||||||
resources.color.put("dark", darkColor);
|
|
||||||
if (font == null) {
|
|
||||||
font = Font.enumerateFonts()[0];
|
|
||||||
}
|
|
||||||
if (font == null) {
|
|
||||||
font = Font.enumerateFonts(true)[0];
|
|
||||||
}
|
|
||||||
fontFamily = font == null ? "Courirer New" : font.fontName;
|
|
||||||
fontEmbed = font == null ? false : switch font.fontType {
|
|
||||||
case DEVICE: false;
|
|
||||||
case _: true;
|
|
||||||
};
|
|
||||||
resources.skin.put("light", [
|
|
||||||
Skin.color(lightColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put("dark", [
|
|
||||||
Skin.color(darkColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put("font", [
|
|
||||||
Skin.text(textColor, 0, fontFamily, fontEmbed),
|
|
||||||
]);
|
|
||||||
resources.skin.put("text", [
|
|
||||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
]);
|
|
||||||
resources.skin.put("scroll.vertical", [
|
|
||||||
haxework.view.skin.Skin.scrollVertical(lightColor, darkColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put("text.header", [
|
|
||||||
Skin.color(0x000000, 0.1),
|
|
||||||
Skin.border(lightColor, 1, 2),
|
|
||||||
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.geometry(new Geometry().setPadding([50, 8]).setMargin([0, 0, 0, 30])),
|
|
||||||
]);
|
|
||||||
resources.skin.put("button", [
|
|
||||||
Skin.buttonColor(lightColor),
|
|
||||||
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.size(250, 50),
|
|
||||||
]);
|
|
||||||
resources.skin.put("text.box", [
|
|
||||||
Skin.color(0x000000, 0.1),
|
|
||||||
Skin.border(lightColor, 1, 2),
|
|
||||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
]);
|
|
||||||
resources.skin.put("text.box.active", [
|
|
||||||
Skin.color(0x55aa55),
|
|
||||||
Skin.border(0x88dd88, 1, 2),
|
|
||||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
]);
|
|
||||||
resources.skin.put("button.simple", [
|
|
||||||
Skin.buttonColor(lightColor),
|
|
||||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
|
||||||
]);
|
|
||||||
resources.skin.put("button.simple.active", [
|
|
||||||
Skin.buttonColor(lightColor, activeColor),
|
|
||||||
Skin.text(activeColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
|
||||||
]);
|
|
||||||
resources.skin.put("button.tab", [
|
|
||||||
Skin.tabColor(lightColor),
|
|
||||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
|
||||||
]);
|
|
||||||
resources.skin.put("border", [
|
|
||||||
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
|
||||||
]);
|
|
||||||
resources.skin.put("scroll", [
|
|
||||||
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
|
||||||
]);
|
|
||||||
resources.skin.put("button.level", [
|
|
||||||
Skin.buttonColor(lightColor),
|
|
||||||
Skin.text(textColor, veryBigFontSize, fontFamily, fontEmbed),
|
|
||||||
Skin.size(64, 64),
|
|
||||||
]);
|
|
||||||
|
|
||||||
resources.skin.put("container", [
|
|
||||||
Skin.geometry(new Geometry().setSize("100%", "100%")),
|
|
||||||
Skin.layout(new Layout().setAlign(CENTER, MIDDLE)),
|
|
||||||
Skin.color(darkColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put("panel", [
|
|
||||||
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([20, 10])),
|
|
||||||
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
|
||||||
Skin.color(lightColor),
|
|
||||||
]);
|
|
||||||
resources.skin.put("window", [
|
|
||||||
Skin.color(darkColor),
|
|
||||||
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
|
|
||||||
Skin.geometry(new Geometry().setPadding(2)),
|
|
||||||
]);
|
|
||||||
resources.skin.put("window.close", [
|
|
||||||
Skin.size(36, 36),
|
|
||||||
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
|
||||||
]);
|
|
||||||
|
|
||||||
registerButton("settings", "cog-solid.svg");
|
|
||||||
registerButton("close", "times-circle-solid.svg");
|
|
||||||
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
|
||||||
registerButton("start", "play-circle-solid.svg");
|
|
||||||
registerButton("login", "sign-in-solid.svg");
|
|
||||||
registerButton("logout", "sign-out-solid.svg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
32
src/client/haxe/ru/m/tankz/bundle/ClientLevelSource.hx
Normal file
32
src/client/haxe/ru/m/tankz/bundle/ClientLevelSource.hx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.m.tankz.bundle;
|
||||||
|
|
||||||
|
import openfl.Assets;
|
||||||
|
import openfl.utils.AssetType;
|
||||||
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
import ru.m.tankz.util.LevelUtil;
|
||||||
|
|
||||||
|
class ClientLevelSource implements ILevelSource {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function resolveMeta(id:PackId):LevelPackMeta {
|
||||||
|
var bytes = Assets.getBytes('level/${id}.zip');
|
||||||
|
return LevelUtil.getMeta(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolve(id:PackId):LevelPack {
|
||||||
|
var bytes = Assets.getBytes('level/${id}.zip');
|
||||||
|
return LevelUtil.unpack(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list():Array<PackId> {
|
||||||
|
var result = [];
|
||||||
|
for (path in Assets.list(AssetType.BINARY)) {
|
||||||
|
if (StringTools.startsWith(path, "level")) {
|
||||||
|
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,16 +8,15 @@ import yaml.Parser;
|
|||||||
import yaml.Yaml;
|
import yaml.Yaml;
|
||||||
|
|
||||||
class ConfigBundle implements IConfigBundle {
|
class ConfigBundle implements IConfigBundle {
|
||||||
|
private var _cache:Map<GameType, Config> = new Map();
|
||||||
|
|
||||||
private var _cache:Map<GameType, Config> = new Map();
|
public function new() {}
|
||||||
|
|
||||||
public function new() {}
|
public function get(type:GameType):Config {
|
||||||
|
if (!_cache.exists(type)) {
|
||||||
public function get(type:GameType):Config {
|
var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
|
||||||
if (!_cache.exists(type)) {
|
_cache.set(type, Config.fromSource(type, source));
|
||||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects());
|
|
||||||
_cache.set(type, Config.fromSource(type, source));
|
|
||||||
}
|
|
||||||
return _cache.get(type);
|
|
||||||
}
|
}
|
||||||
|
return _cache.get(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package ru.m.tankz.bundle;
|
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.tankz.config.Config;
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
import ru.m.tankz.util.LevelUtil;
|
|
||||||
|
|
||||||
class LevelBundle implements ILevelBundle {
|
|
||||||
|
|
||||||
private var cache:Map<String, LevelConfig> = new Map();
|
|
||||||
|
|
||||||
public function new() {}
|
|
||||||
|
|
||||||
public function get(type:GameType, config:Config, levelId:LevelId):LevelConfig {
|
|
||||||
var key = '${type}:${levelId}';
|
|
||||||
if (!cache.exists(key)) {
|
|
||||||
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(levelId)}.txt');
|
|
||||||
cache[key] = LevelUtil.loads(config, data);
|
|
||||||
cache[key].id = levelId;
|
|
||||||
}
|
|
||||||
return cache[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import ru.m.tankz.control.Control.TankAction;
|
|
||||||
|
|
||||||
typedef ActionItem = {
|
|
||||||
public var action:TankAction;
|
|
||||||
public var key:Int;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef KeyBinding = Map<Int, TankAction>;
|
|
||||||
|
|
||||||
class ActionConfig {
|
|
||||||
|
|
||||||
public var data(default, null):Array<ActionItem>;
|
|
||||||
|
|
||||||
public function new(data:Array<ActionItem>) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function asKeyBinding():KeyBinding {
|
|
||||||
var result = new Map<Int, TankAction>();
|
|
||||||
for (item in data) {
|
|
||||||
result[item.key] = item.action;
|
|
||||||
}
|
|
||||||
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,81 +1,117 @@
|
|||||||
package ru.m.tankz.control;
|
package ru.m.tankz.control;
|
||||||
|
|
||||||
import flash.events.FocusEvent;
|
import flash.events.FocusEvent;
|
||||||
import flash.events.KeyboardEvent;
|
|
||||||
import flash.Lib;
|
|
||||||
import flash.ui.Keyboard;
|
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
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.control.Control;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
using haxe.EnumTools.EnumValueTools;
|
||||||
|
|
||||||
class HumanControl extends Control {
|
class HumanControl extends Control {
|
||||||
|
@:provide static var storage:SettingsStorage;
|
||||||
|
@:provide static var bus:IControlBus;
|
||||||
|
|
||||||
@:provide var storage:SettingsStorage;
|
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||||
|
|
||||||
private var keyBinding:KeyBinding;
|
private var moveQueue:Array<Direction>;
|
||||||
private var moveQueue:Array<Int>;
|
private var shotTimers:Map<Int, Timer>;
|
||||||
private var shotTimer:Timer;
|
|
||||||
|
|
||||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||||
super(playerId);
|
super(playerId);
|
||||||
this.keyBinding = storage.getActionConfig(controlIndex).asKeyBinding();
|
var config = storage.getBinding(controlIndex);
|
||||||
moveQueue = new Array<Int>();
|
binding = new Map();
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
for (action in config.keys()) {
|
||||||
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
|
var bind = config.get(action);
|
||||||
//Lib.current.stage.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
|
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 {
|
public function hasDevice(device:DeviceType):Bool {
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
for (d in binding.keys()) {
|
||||||
case TankAction.MOVE(direction):
|
if (d.equals(device)) {
|
||||||
if (moveQueue.indexOf(event.keyCode) == -1) {
|
return true;
|
||||||
moveQueue.unshift(event.keyCode);
|
}
|
||||||
updateMove();
|
|
||||||
}
|
|
||||||
case TankAction.SHOT:
|
|
||||||
if (shotTimer == null) {
|
|
||||||
shotTimer = new Timer(300);
|
|
||||||
shotTimer.run = shot;
|
|
||||||
shot();
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private function onKeyUp(event:KeyboardEvent):Void {
|
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||||
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) {
|
if (binding.exists(device) && binding[device].exists(action)) {
|
||||||
case TankAction.MOVE(direction):
|
toggleAction(binding[device][action], on);
|
||||||
moveQueue.remove(event.keyCode);
|
|
||||||
updateMove();
|
|
||||||
case TankAction.SHOT:
|
|
||||||
if (shotTimer != null) {
|
|
||||||
shotTimer.stop();
|
|
||||||
shotTimer = null;
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function onFocusOut(event:FocusEvent):Void {
|
override public function start():Void {
|
||||||
moveQueue = [];
|
super.start();
|
||||||
updateMove();
|
bus.signal.connect(onDeviceAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function stop():Void {
|
||||||
|
super.stop();
|
||||||
|
bus.signal.disconnect(onDeviceAction);
|
||||||
|
moveQueue = [];
|
||||||
|
for (timer in shotTimers) {
|
||||||
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
shotTimers = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
private function updateMove():Void {
|
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||||
if (moveQueue.length == 0) {
|
switch action {
|
||||||
action(TankAction.STOP);
|
case TankAction.MOVE(direction):
|
||||||
|
if (on) {
|
||||||
|
if (moveQueue.indexOf(direction) == -1) {
|
||||||
|
moveQueue.unshift(direction);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (keyBinding.get(moveQueue[0])) {
|
moveQueue.remove(direction);
|
||||||
case TankAction.MOVE(direction):
|
|
||||||
action(TankAction.MOVE(direction));
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
updateMove();
|
||||||
|
case TankAction.SHOT(weapon):
|
||||||
|
if (on) {
|
||||||
|
if (!shotTimers.exists(weapon)) {
|
||||||
|
// ToDo: weapon.config.delay
|
||||||
|
var timer = new Timer(350);
|
||||||
|
timer.run = shooter(weapon);
|
||||||
|
timer.run();
|
||||||
|
shotTimers.set(weapon, timer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (shotTimers.exists(weapon)) {
|
||||||
|
shotTimers.get(weapon).stop();
|
||||||
|
shotTimers.remove(weapon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case TankAction.STOP:
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function shot():Void {
|
private function onFocusOut(event:FocusEvent):Void {
|
||||||
action(TankAction.SHOT);
|
moveQueue = [];
|
||||||
|
updateMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateMove():Void {
|
||||||
|
if (moveQueue.length == 0) {
|
||||||
|
action(STOP);
|
||||||
|
} else {
|
||||||
|
action(MOVE(moveQueue[0]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function shooter(weapon:Int):Void->Void {
|
||||||
|
return function():Void {
|
||||||
|
action(SHOT(weapon));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
class LocalControlFactory extends BaseControlFactory {
|
|
||||||
|
|
||||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
|
||||||
return new HumanControl(id, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package ru.m.tankz.control;
|
|
||||||
|
|
||||||
import ru.m.tankz.Type;
|
|
||||||
|
|
||||||
class NetworkControlFactory extends BaseControlFactory {
|
|
||||||
|
|
||||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
|
||||||
return new NetworkControl(id, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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);
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package ru.m.tankz.game;
|
|
||||||
|
|
||||||
import ru.m.tankz.control.LocalControlFactory;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import ru.m.tankz.game.record.GameRecorder;
|
|
||||||
import ru.m.tankz.storage.RecordStorage;
|
|
||||||
|
|
||||||
class LocalGame extends GameRunner {
|
|
||||||
@:provide var recordStorage:RecordStorage;
|
|
||||||
private var recorder:GameRecorder;
|
|
||||||
|
|
||||||
public function new(state:GameState) {
|
|
||||||
super(state);
|
|
||||||
controlFactory = new LocalControlFactory();
|
|
||||||
recorder = new GameRecorder();
|
|
||||||
connect(recorder);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function onGameEvent(event:GameEvent):Void {
|
|
||||||
super.onGameEvent(event);
|
|
||||||
switch event {
|
|
||||||
case GameEvent.COMPLETE(_, _):
|
|
||||||
disconnect(recorder);
|
|
||||||
recorder.onGameEvent(event); //ToDo:
|
|
||||||
recordStorage.save(recorder.record);
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package ru.m.tankz.game;
|
|
||||||
|
|
||||||
import haxe.Unserializer;
|
|
||||||
import ru.m.tankz.control.NetworkControlFactory;
|
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
|
||||||
import ru.m.tankz.game.GameState;
|
|
||||||
import ru.m.tankz.network.NetworkManager;
|
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
|
||||||
|
|
||||||
class NetworkGame extends Game {
|
|
||||||
|
|
||||||
private var network:NetworkManager;
|
|
||||||
|
|
||||||
public function new(network:NetworkManager) {
|
|
||||||
super(new GameState(network.game.type, 0, network.game.level));
|
|
||||||
this.network = network;
|
|
||||||
this.controlFactory = new NetworkControlFactory();
|
|
||||||
network.gameEventSignal.connect(onGameEventProto);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onGameEventProto(game:GameEventResponse):Void {
|
|
||||||
var time = game.time;
|
|
||||||
var eventStr = game.event;
|
|
||||||
var event:GameEvent = Unserializer.run(eventStr);
|
|
||||||
gameEventSignal.emit(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function start():Void {
|
|
||||||
var player = Lambda.find(network.game.players, function(player) return player.user.uuid == network.user.uuid);
|
|
||||||
if (player != null) {
|
|
||||||
state.controls.push({playerId: [player.team, player.index], control: "human-0"});
|
|
||||||
}
|
|
||||||
super.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function dispose():Void {
|
|
||||||
super.dispose();
|
|
||||||
network.gameEventSignal.disconnect(onGameEventProto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
12
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
12
src/client/haxe/ru/m/tankz/local/LocalControlFactory.hx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/client/haxe/ru/m/tankz/local/StageCaller.hx
Normal file
30
src/client/haxe/ru/m/tankz/local/StageCaller.hx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package ru.m.tankz.local;
|
||||||
|
|
||||||
|
import flash.display.Stage;
|
||||||
|
import flash.events.Event;
|
||||||
|
import ru.m.tankz.engine.ICaller;
|
||||||
|
|
||||||
|
class StageCaller implements ICaller {
|
||||||
|
private var stage:Stage;
|
||||||
|
private var event:String;
|
||||||
|
private var calback:Void->Void;
|
||||||
|
|
||||||
|
public function new(stage:Stage, ?event:String) {
|
||||||
|
this.stage = stage;
|
||||||
|
this.event = event != null ? event : Event.ENTER_FRAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onEvent(_):Void {
|
||||||
|
calback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start(calback:Void->Void):Void {
|
||||||
|
this.calback = calback;
|
||||||
|
stage.addEventListener(event, onEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop():Void {
|
||||||
|
stage.removeEventListener(event, onEvent);
|
||||||
|
calback = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/network/NetworkControl.hx
Normal file
15
src/client/haxe/ru/m/tankz/network/NetworkControl.hx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
15
src/client/haxe/ru/m/tankz/network/NetworkControlFactory.hx
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,163 +1,193 @@
|
|||||||
package ru.m.tankz.network;
|
package ru.m.tankz.network;
|
||||||
|
|
||||||
import haxe.Serializer;
|
import haxe.Serializer;
|
||||||
import haxework.signal.Signal;
|
import hw.signal.Signal;
|
||||||
import ru.m.connect.IConnection;
|
import ru.m.connect.IConnection;
|
||||||
import ru.m.tankz.control.Control;
|
import ru.m.tankz.control.Control;
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.proto.core.GameProto;
|
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.proto.game.GameChangeProto;
|
import ru.m.tankz.proto.game.GameEventProto;
|
||||||
import ru.m.tankz.proto.pack.CreateGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.GameEventRequest;
|
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||||
import ru.m.tankz.proto.pack.JoinGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.LeaveGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.ListGameRequest;
|
|
||||||
import ru.m.tankz.proto.pack.LoginRequest;
|
import ru.m.tankz.proto.pack.LoginRequest;
|
||||||
import ru.m.tankz.proto.pack.LogoutRequest;
|
import ru.m.tankz.proto.pack.LogoutRequest;
|
||||||
import ru.m.tankz.proto.pack.Request;
|
import ru.m.tankz.proto.pack.Request;
|
||||||
import ru.m.tankz.proto.pack.Response;
|
import ru.m.tankz.proto.pack.Response;
|
||||||
import ru.m.tankz.proto.pack.StartGameRequest;
|
import ru.m.tankz.proto.room.CreateRequest;
|
||||||
import ru.m.tankz.storage.MultiplayerStorage;
|
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.SlotProto;
|
||||||
|
import ru.m.tankz.proto.room.SlotRequest;
|
||||||
|
import ru.m.tankz.proto.room.StartRequest;
|
||||||
|
import ru.m.tankz.storage.NetworkStorage;
|
||||||
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
|
||||||
typedef ClientConnection = IConnection<Request, Response>;
|
typedef ClientConnection = IConnection<Request, Response>;
|
||||||
|
|
||||||
enum ConnectionState {
|
enum ConnectionState {
|
||||||
OFFLINE;
|
OFFLINE;
|
||||||
CONNECT;
|
CONNECT;
|
||||||
CONNECTED;
|
CONNECTED;
|
||||||
LOGIN;
|
LOGIN;
|
||||||
ONLINE(user:User);
|
ONLINE(user:User);
|
||||||
ERROR(error:Dynamic);
|
ERROR(error:Dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkManager {
|
@:provide class NetworkManager {
|
||||||
|
private static inline var TAG = "NetworkManager";
|
||||||
|
|
||||||
public var state(default, null):ConnectionState;
|
public var state(default, null):ConnectionState;
|
||||||
public var game(default, null):GameProto;
|
public var room(default, null):RoomProto;
|
||||||
public var user(default, null):UserProto;
|
public var user(default, null):UserProto;
|
||||||
|
|
||||||
public var stateSignal:Signal<ConnectionState>;
|
public var stateSignal:Signal<ConnectionState>;
|
||||||
public var listGameSignal:Signal<Array<GameProto>>;
|
public var listRoomSignal:Signal<Array<RoomProto>>;
|
||||||
public var gameSignal:Signal<GameProto>;
|
public var roomSignal:Signal<RoomProto>;
|
||||||
public var gameUpdateSignal:Signal<Array<GameChangeProto>>;
|
public var gameEventSignal:Signal<GameEventResponse>;
|
||||||
public var gameEventSignal:Signal<GameEventResponse>;
|
|
||||||
|
|
||||||
@:provide private var connection:ClientConnection;
|
@:provide private var connection:ClientConnection;
|
||||||
@:provide private var storage:MultiplayerStorage;
|
@:provide private var storage:NetworkStorage;
|
||||||
|
@:provide private var settings:SettingsStorage;
|
||||||
|
|
||||||
public function new() {
|
private var reconnectTimer:Timer;
|
||||||
stateSignal = new Signal();
|
private var reconnectDelay:Int;
|
||||||
listGameSignal = new Signal();
|
|
||||||
gameSignal = new Signal();
|
public function new() {
|
||||||
gameUpdateSignal = new Signal();
|
reconnectDelay = 500;
|
||||||
gameEventSignal = new Signal();
|
stateSignal = new Signal();
|
||||||
updateState(OFFLINE);
|
listRoomSignal = new Signal();
|
||||||
connection.handler.connect(onConnectionEvent);
|
roomSignal = new Signal();
|
||||||
connection.receiveHandler.connect(onResponse);
|
gameEventSignal = new Signal();
|
||||||
|
updateState(OFFLINE);
|
||||||
|
connection.handler.connect(onConnectionEvent);
|
||||||
|
connection.receiveHandler.connect(onResponse);
|
||||||
|
if (settings.enableNetwork) {
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
settings.signal.connect(onSettingChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onSettingChange(setting:Setting):Void {
|
||||||
|
switch setting {
|
||||||
|
case ENABLE_NETWORK(value):
|
||||||
|
if (value) {
|
||||||
|
connect();
|
||||||
|
} else {
|
||||||
|
disconnect();
|
||||||
|
}
|
||||||
|
case _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateState(value:ConnectionState):Void {
|
||||||
|
L.d(TAG, 'State: ${value}');
|
||||||
|
state = value;
|
||||||
|
stateSignal.emit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function login(name:String, uuid:String = null):Void {
|
||||||
|
updateState(LOGIN);
|
||||||
|
connection.send(new Request().setLogin(new LoginRequest().setUuid(uuid).setName(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout():Void {
|
||||||
|
connection.send(new Request().setLogout(new LogoutRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listGame(subscribe:Bool):Void {
|
||||||
|
connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createGame(type:String, level:Int):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setCreate(new CreateRequest().setType(type)
|
||||||
|
.setLevel(level))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function joinGame(gameId:Int, restore:Bool = false):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setJoin(new JoinRequest().setGameId(gameId)
|
||||||
|
.setRestore(restore))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function selectSlot(slot:SlotProto):Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setSlot(new SlotRequest().setSlot(slot))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function leaveGame():Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startGame():Void {
|
||||||
|
connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function action(tankId:Int, action:TankAction):Void {
|
||||||
|
connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(new GameEventProto().setTime(0)
|
||||||
|
.setEvent(Serializer.run(GameEvent.ACTION(tankId, action))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function connect():Void {
|
||||||
|
if (reconnectTimer != null) {
|
||||||
|
reconnectTimer.stop();
|
||||||
|
reconnectTimer = null;
|
||||||
|
}
|
||||||
|
reconnectTimer = null;
|
||||||
|
updateState(CONNECT);
|
||||||
|
connection.connect().catchError(function(error) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function reconnect():Void {
|
||||||
|
reconnectDelay = Std.int(Math.min(reconnectDelay * 2, 10000));
|
||||||
|
if (reconnectTimer == null) {
|
||||||
|
reconnectTimer = Timer.delay(connect, reconnectDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function disconnect():Void {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||||
|
updateState(switch event {
|
||||||
|
case CONNECTED: CONNECTED;
|
||||||
|
case DISCONNECTED: OFFLINE;
|
||||||
|
case ERROR(error): ERROR(error);
|
||||||
|
});
|
||||||
|
switch event {
|
||||||
|
case CONNECTED:
|
||||||
|
reconnectDelay = 500;
|
||||||
var user = storage.user;
|
var user = storage.user;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
login(user.name, user.uuid);
|
login(user.name, user.uuid);
|
||||||
|
}
|
||||||
|
case DISCONNECTED | ERROR(_):
|
||||||
|
if (settings.enableNetwork) {
|
||||||
|
reconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function updateState(value:ConnectionState):Void {
|
private function onResponse(packet:Response):Void {
|
||||||
state = value;
|
if (packet.hasLogin()) {
|
||||||
stateSignal.emit(value);
|
this.user = packet.login.user;
|
||||||
}
|
var user = {
|
||||||
|
uuid: this.user.uuid,
|
||||||
public function login(name:String, uuid:String = null):Void {
|
name: this.user.name,
|
||||||
updateState(CONNECT);
|
};
|
||||||
connection.connect().then(function(c:ClientConnection) {
|
storage.user = user;
|
||||||
updateState(LOGIN);
|
updateState(ONLINE(user));
|
||||||
c.send(new Request().setLogin(
|
} else if (packet.hasLogout()) {
|
||||||
new LoginRequest()
|
storage.user = null;
|
||||||
.setUuid(uuid)
|
updateState(CONNECTED);
|
||||||
.setName(name)
|
} else if (packet.hasRoomList()) {
|
||||||
));
|
listRoomSignal.emit(packet.roomList.rooms);
|
||||||
}).catchError(function(error) {
|
} else if (packet.hasRoom()) {
|
||||||
updateState(ERROR(error));
|
room = packet.room.room;
|
||||||
});
|
roomSignal.emit(room);
|
||||||
}
|
} else if (packet.hasGameEvent()) {
|
||||||
|
gameEventSignal.emit(packet.gameEvent);
|
||||||
public function logout():Void {
|
|
||||||
connection.send(new Request().setLogout(new LogoutRequest()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function listGame():Void {
|
|
||||||
connection.send(new Request().setListGame(new ListGameRequest()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createGame(type:String, level:Int):Void {
|
|
||||||
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type).setLevel(level)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function joinGame(gameId:Int):Void {
|
|
||||||
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function leaveGame():Void {
|
|
||||||
connection.send(new Request().setLeaveGame(new LeaveGameRequest()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function startGame():Void {
|
|
||||||
connection.send(new Request().setStartGame(new StartGameRequest()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function action(tankId:Int, action:TankAction):Void {
|
|
||||||
connection.send(new Request().setGameEvent(new GameEventRequest().setTime(0).setEvent(
|
|
||||||
Serializer.run(GameEvent.ACTION(tankId, action))
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
|
||||||
updateState(switch event {
|
|
||||||
case CONNECTED:
|
|
||||||
L.d('Network', '$event');
|
|
||||||
CONNECTED;
|
|
||||||
case DISCONNECTED:
|
|
||||||
L.d('Network', '$event');
|
|
||||||
OFFLINE;
|
|
||||||
case ERROR(error):
|
|
||||||
L.e('Network', '$error', error);
|
|
||||||
ERROR(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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.hasListGame()) {
|
|
||||||
listGameSignal.emit(packet.listGame.games);
|
|
||||||
} else if (packet.hasCreateGame()) {
|
|
||||||
game = packet.createGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
} else if (packet.hasJoinGame()) {
|
|
||||||
game = packet.joinGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
} else if (packet.hasLeaveGame()) {
|
|
||||||
if (packet.leaveGame.user.uuid == user.uuid) {
|
|
||||||
game = null;
|
|
||||||
gameSignal.emit(null);
|
|
||||||
} else {
|
|
||||||
game = packet.leaveGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
}
|
|
||||||
} else if (packet.hasStartGame()) {
|
|
||||||
game = packet.startGame.game;
|
|
||||||
gameSignal.emit(game);
|
|
||||||
} else if (packet.hasGameEvent()) {
|
|
||||||
gameEventSignal.emit(packet.gameEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,38 +5,35 @@ import ru.m.animate.Animate;
|
|||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
|
|
||||||
class AnimateBundle {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private static function buildAnimate(name:String, sequence:Array<Int>):OnceAnimate {
|
public static function tankSpawn():OnceAnimate {
|
||||||
var template:String = 'resources/image/animate/${name}/%index%.png';
|
return buildAnimate('appear', [0, 1, 2, 3, 3, 4, 5, 5, 6]);
|
||||||
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 {
|
public static function tankBoom():OnceAnimate {
|
||||||
return buildAnimate('appear', [
|
return buildAnimate('boom', [0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9]);
|
||||||
0, 1, 2, 3, 3, 4, 5, 5, 6
|
}
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function tankBoom():OnceAnimate {
|
public static function bulletBoom():OnceAnimate {
|
||||||
return buildAnimate('boom', [
|
return buildAnimate('boom-sm', [0, 1, 1, 0, 0, 1]);
|
||||||
0, 1, 2, 3, 4, 4, 4, 1, 4, 4, 7, 7, 8, 9, 9
|
}
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function bulletBoom():OnceAnimate {
|
public static function tankProtect():Animate {
|
||||||
return buildAnimate('boom-sm', [
|
return new Animate([
|
||||||
0, 1, 1, 0, 0, 1
|
for (i in 0...2)
|
||||||
]);
|
({
|
||||||
}
|
image:Assets.getBitmapData('resources/image/animate/protect/${i}.png'), length:5
|
||||||
|
})
|
||||||
public static function tankProtect():Animate {
|
]);
|
||||||
return new Animate([for (i in 0...2) ({
|
}
|
||||||
image: Assets.getBitmapData('resources/image/animate/protect/${i}.png'),
|
|
||||||
length: 5
|
|
||||||
})]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
import haxework.view.IView;
|
import hw.view.IView;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
interface IRender extends IView<Dynamic> extends GameListener {
|
interface IRender extends IView<Dynamic> extends GameListener {
|
||||||
public var config(default, set):Config;
|
public var config(default, set):Config;
|
||||||
public function draw():Void;
|
public var gridSize(default, set):GridSize;
|
||||||
public function reset():Void;
|
public function draw():Void;
|
||||||
|
public function reset():Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package ru.m.tankz.render;
|
package ru.m.tankz.render;
|
||||||
|
|
||||||
|
import hw.view.utils.DrawUtil;
|
||||||
import flash.display.DisplayObjectContainer;
|
import flash.display.DisplayObjectContainer;
|
||||||
import flash.display.Graphics;
|
import flash.display.Graphics;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import haxework.view.LabelView;
|
import hw.view.form.LabelView;
|
||||||
import haxework.view.SpriteView;
|
import hw.view.SpriteView;
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
|
import ru.m.animate.AnimateManager;
|
||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
@@ -22,235 +24,280 @@ import ru.m.tankz.render.item.IRenderItem;
|
|||||||
import ru.m.tankz.render.item.TankRenderItem;
|
import ru.m.tankz.render.item.TankRenderItem;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
|
using ru.m.display.DisplayObjectContainerExtender;
|
||||||
|
|
||||||
class Render extends SpriteView implements IRender {
|
class Render extends SpriteView implements IRender {
|
||||||
|
public var config(default, set):Config;
|
||||||
|
public var gridSize(default, set):GridSize;
|
||||||
|
|
||||||
public var config(default, set):Config;
|
private var mapWidth(get, null):Float;
|
||||||
|
private var mapHeight(get, null):Float;
|
||||||
|
|
||||||
private var backgroundLayer:Sprite;
|
private var container:Sprite;
|
||||||
private var groundLayer:Sprite;
|
private var backgroundLayer:Sprite;
|
||||||
private var entryLayer:Sprite;
|
private var groundLayer:Sprite;
|
||||||
private var upLayer:Sprite;
|
private var entryLayer:Sprite;
|
||||||
private var upperLayer:Sprite;
|
private var upLayer:Sprite;
|
||||||
|
private var upperLayer:Sprite;
|
||||||
|
|
||||||
private var items:Map<Int, IRenderItem>;
|
private var items:Map<Int, IRenderItem>;
|
||||||
|
private var paused:Bool;
|
||||||
|
|
||||||
public function new() {
|
@:provide private static var animateManager:AnimateManager;
|
||||||
super();
|
|
||||||
items = new Map();
|
public function new() {
|
||||||
backgroundLayer = new Sprite();
|
super();
|
||||||
groundLayer = new Sprite();
|
items = new Map();
|
||||||
entryLayer = new Sprite();
|
container = new Sprite();
|
||||||
upLayer = new Sprite();
|
content.addChild(container);
|
||||||
upperLayer = new Sprite();
|
backgroundLayer = new Sprite();
|
||||||
content.addChild(backgroundLayer);
|
groundLayer = new Sprite();
|
||||||
content.addChild(groundLayer);
|
entryLayer = new Sprite();
|
||||||
content.addChild(entryLayer);
|
upLayer = new Sprite();
|
||||||
content.addChild(upLayer);
|
upperLayer = new Sprite();
|
||||||
content.addChild(upperLayer);
|
container.addChild(backgroundLayer);
|
||||||
reset();
|
container.addChild(groundLayer);
|
||||||
|
container.addChild(entryLayer);
|
||||||
|
container.addChild(upLayer);
|
||||||
|
container.addChild(upperLayer);
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_mapWidth():Float {
|
||||||
|
return config.map.cell.width * (gridSize != null ? gridSize.width : config.map.grid.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_mapHeight():Float {
|
||||||
|
return config.map.cell.height * (gridSize != null ? gridSize.height : config.map.grid.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_config(value:Config):Config {
|
||||||
|
config = value;
|
||||||
|
drawBackground();
|
||||||
|
toRedraw();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_gridSize(value:GridSize):GridSize {
|
||||||
|
gridSize = value;
|
||||||
|
drawBackground();
|
||||||
|
toRedraw();
|
||||||
|
return gridSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function drawBackground():Void {
|
||||||
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
|
g.clear();
|
||||||
|
g.beginFill(0x000000);
|
||||||
|
g.lineStyle(2, 0xcccccc);
|
||||||
|
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||||
|
g.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function redraw():Void {
|
||||||
|
super.redraw();
|
||||||
|
var scale = Math.min(width / mapWidth, height / mapHeight);
|
||||||
|
container.scaleX = container.scaleY = scale;
|
||||||
|
container.x = (width - (mapWidth * scale)) / 2;
|
||||||
|
container.y = (height - (mapHeight * scale)) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function draw():Void {
|
||||||
|
for (item in items) {
|
||||||
|
item.update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function set_config(value:Config):Config {
|
private function onEnterFrame(event:Event):Void {
|
||||||
return config = value;
|
if (!paused) {
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function drawBackground():Void {
|
private function clearLayer(layer:DisplayObjectContainer) {
|
||||||
var width = config.map.cellWidth * config.map.gridWidth;
|
while (layer.numChildren > 0) {
|
||||||
var height = config.map.cellHeight * config.map.gridHeight;
|
layer.removeChildAt(0);
|
||||||
var g:Graphics = backgroundLayer.graphics;
|
|
||||||
g.clear();
|
|
||||||
g.beginFill(0x000000);
|
|
||||||
g.drawRect(0, 0, width, height);
|
|
||||||
g.endFill();
|
|
||||||
setContentSize(width, height);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function draw():Void {
|
public function reset():Void {
|
||||||
for (item in items) {
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
item.update();
|
for (item in items.iterator()) {
|
||||||
}
|
item.dispose();
|
||||||
}
|
}
|
||||||
|
items = new Map();
|
||||||
|
clearLayer(entryLayer);
|
||||||
|
clearLayer(groundLayer);
|
||||||
|
clearLayer(upLayer);
|
||||||
|
clearLayer(upperLayer);
|
||||||
|
}
|
||||||
|
|
||||||
private function onEnterFrame(event:Event):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
draw();
|
switch event {
|
||||||
}
|
case START(start):
|
||||||
|
animateManager.playing = true;
|
||||||
private function clearLayer(layer:DisplayObjectContainer) {
|
gridSize = start.level.size;
|
||||||
while (layer.numChildren > 0) layer.removeChildAt(0);
|
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
}
|
case COMPLETE(_):
|
||||||
|
|
||||||
public function reset():Void {
|
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||||
for (item in items.iterator()) {
|
case PAUSE(paused):
|
||||||
item.dispose();
|
this.paused = paused;
|
||||||
|
animateManager.playing = !paused;
|
||||||
|
case SPAWN(BRICK(bricks)):
|
||||||
|
drawBackground();
|
||||||
|
for (brick in bricks) {
|
||||||
|
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
||||||
|
var config = config.getBrick(brick.type);
|
||||||
|
items[brick.id] = item;
|
||||||
|
if (config.layer > 2) {
|
||||||
|
upLayer.addChild(item.view);
|
||||||
|
} else {
|
||||||
|
groundLayer.addChild(item.view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
items = new Map();
|
case SPAWN(EAGLE(id, rect, teamId)):
|
||||||
clearLayer(entryLayer);
|
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
||||||
clearLayer(groundLayer);
|
items.set(id, item);
|
||||||
clearLayer(upLayer);
|
entryLayer.addChild(item.view);
|
||||||
clearLayer(upperLayer);
|
item.update();
|
||||||
}
|
case SPAWN(TANK(id, rect, playerId, info)):
|
||||||
|
var item = new TankRenderItem(rect);
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
var tankConfig = config.getTank(info.type);
|
||||||
switch event {
|
item.color = info.color;
|
||||||
case START(_):
|
item.skin = tankConfig.skin;
|
||||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
item.hits = info.hits;
|
||||||
case COMPLETE(_, _):
|
item.bonus = info.bonus;
|
||||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
item.boat = info.boat;
|
||||||
case SPAWN(BRICK(bricks)):
|
item.name = info.name == null ? "" : info.name;
|
||||||
drawBackground();
|
items.set(id, item);
|
||||||
for (brick in bricks) {
|
entryLayer.addChild(item.view);
|
||||||
var item:IRenderItem = new BrickRenderItem(brick.rect, brick.type);
|
item.update();
|
||||||
var config = config.getBrick(brick.type);
|
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||||
items[brick.id] = item;
|
case SPAWN(BULLET(id, rect, playerId, skin, color)):
|
||||||
if (config.layer > 2) {
|
var item = new BulletRenderItem(rect);
|
||||||
upLayer.addChild(item.view);
|
item.color = color;
|
||||||
} else {
|
item.skin = skin;
|
||||||
groundLayer.addChild(item.view);
|
items.set(id, item);
|
||||||
}
|
entryLayer.addChild(item.view);
|
||||||
}
|
item.update();
|
||||||
case SPAWN(EAGLE(id, rect, teamId)):
|
case SPAWN(BONUS(id, rect, type)):
|
||||||
var item = new EagleRenderItem(rect, config.getColor(new PlayerId(teamId, -1)));
|
var item = new BonusRenderItem(rect, type);
|
||||||
items.set(id, item);
|
items.set(id, item);
|
||||||
entryLayer.addChild(item.view);
|
upperLayer.addChild(item.view);
|
||||||
item.update();
|
item.update();
|
||||||
case SPAWN(TANK(id, rect, playerId, info)):
|
case MOVE(EAGLE(id, position)):
|
||||||
var item = new TankRenderItem(rect);
|
if (items.exists(id)) {
|
||||||
var tankConfig = config.getTank(info.type);
|
var item = items[id];
|
||||||
item.color = info.color;
|
item.move(position);
|
||||||
item.skin = tankConfig.skin;
|
|
||||||
item.hits = info.hits;
|
|
||||||
item.bonus = info.bonus;
|
|
||||||
items.set(id, item);
|
|
||||||
entryLayer.addChild(item.view);
|
|
||||||
item.update();
|
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
|
||||||
case SPAWN(BULLET(id, rect, playerId, piercing)):
|
|
||||||
var item = new BulletRenderItem(rect, piercing);
|
|
||||||
items.set(id, item);
|
|
||||||
entryLayer.addChild(item.view);
|
|
||||||
item.update();
|
|
||||||
case SPAWN(BONUS(id, rect, type)):
|
|
||||||
var item = new BonusRenderItem(rect, type);
|
|
||||||
items.set(id, item);
|
|
||||||
upperLayer.addChild(item.view);
|
|
||||||
item.update();
|
|
||||||
case MOVE(EAGLE(id, position)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
item.move(position);
|
|
||||||
}
|
|
||||||
case MOVE(BULLET(id, position)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
item.move(position);
|
|
||||||
}
|
|
||||||
case MOVE(TANK(id, position)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
item.move(position);
|
|
||||||
cast(item, TankRenderItem).moves = true;
|
|
||||||
}
|
|
||||||
case STOP(TANK(id)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
cast(item, TankRenderItem).moves = false;
|
|
||||||
}
|
|
||||||
case CHANGE(TANK(id, type, hits, bonus)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item:TankRenderItem = cast items[id];
|
|
||||||
item.skin = config.getTank(type).skin;
|
|
||||||
item.hits = hits;
|
|
||||||
item.bonus = bonus;
|
|
||||||
}
|
|
||||||
case CHANGE(TANK_PROTECT(id, state)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item:TankRenderItem = cast items[id];
|
|
||||||
item.protect = state;
|
|
||||||
}
|
|
||||||
case CHANGE(EAGLE_PROTECT(id, state)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item:EagleRenderItem = cast items[id];
|
|
||||||
item.protect = state;
|
|
||||||
}
|
|
||||||
case CHANGE(BRICK(id, type)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item:BrickRenderItem = cast items[id];
|
|
||||||
item.type = type;
|
|
||||||
}
|
|
||||||
case DESTROY(TANK(id, shot)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
entryLayer.removeChild(item.view);
|
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
|
||||||
if (shot.score != 0) {
|
|
||||||
showScore(item.rect.center, shot.score);
|
|
||||||
}
|
|
||||||
items.remove(id);
|
|
||||||
}
|
|
||||||
case DESTROY(BULLET(id)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
entryLayer.removeChild(item.view);
|
|
||||||
var rect = item.rect;
|
|
||||||
// move boom
|
|
||||||
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
|
||||||
playAnimate(point, AnimateBundle.bulletBoom());
|
|
||||||
items.remove(id);
|
|
||||||
}
|
|
||||||
case DESTROY(EAGLE(id, shot)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
|
||||||
if (shot.score != 0) {
|
|
||||||
showScore(item.rect.center, shot.score);
|
|
||||||
}
|
|
||||||
cast(item, EagleRenderItem).death = true;
|
|
||||||
}
|
|
||||||
case DESTROY(BONUS(id, shot)):
|
|
||||||
if (items.exists(id)) {
|
|
||||||
var item = items[id];
|
|
||||||
upperLayer.removeChild(item.view);
|
|
||||||
if (shot.score != 0) {
|
|
||||||
showScore(item.rect.center, shot.score);
|
|
||||||
}
|
|
||||||
items.remove(id);
|
|
||||||
}
|
|
||||||
case DESTROY(CELL(id, x, y, shot)):
|
|
||||||
var item:BrickRenderItem = cast items.get(id);
|
|
||||||
item.destroyCell(x, y);
|
|
||||||
case DESTROY(BRICK(id, shot)):
|
|
||||||
var item:BrickRenderItem = cast items.get(id);
|
|
||||||
item.destroy();
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
#if cpp
|
case MOVE(BULLET(id, position)):
|
||||||
flash.Lib.current.stage.invalidate();
|
if (items.exists(id)) {
|
||||||
#end
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
|
}
|
||||||
|
case MOVE(TANK(id, position)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
item.move(position);
|
||||||
|
cast(item, TankRenderItem).moves = true;
|
||||||
|
}
|
||||||
|
case STOP(TANK(id)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
cast(item, TankRenderItem).moves = false;
|
||||||
|
}
|
||||||
|
case CHANGE(TANK(id, type, hits, bonus, boat)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:TankRenderItem = cast items[id];
|
||||||
|
item.skin = config.getTank(type).skin;
|
||||||
|
item.hits = hits;
|
||||||
|
item.bonus = bonus;
|
||||||
|
item.boat = boat;
|
||||||
|
}
|
||||||
|
case CHANGE(TANK_PROTECT(id, state)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:TankRenderItem = cast items[id];
|
||||||
|
item.protect = state;
|
||||||
|
}
|
||||||
|
case CHANGE(EAGLE_PROTECT(id, state)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:EagleRenderItem = cast items[id];
|
||||||
|
item.protect = state;
|
||||||
|
}
|
||||||
|
case CHANGE(BRICK(id, type)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item:BrickRenderItem = cast items[id];
|
||||||
|
item.type = type;
|
||||||
|
}
|
||||||
|
case DESTROY(TANK(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
entryLayer.removeChild(item.view);
|
||||||
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(BULLET(id)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
entryLayer.removeChild(item.view);
|
||||||
|
var rect = item.rect;
|
||||||
|
// move boom
|
||||||
|
var point = rect.center.add(new Point(rect.width * rect.direction.x, rect.height * rect.direction.y));
|
||||||
|
playAnimate(point, AnimateBundle.bulletBoom());
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(EAGLE(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
cast(item, EagleRenderItem).death = true;
|
||||||
|
}
|
||||||
|
case DESTROY(BONUS(id, shot)):
|
||||||
|
if (items.exists(id)) {
|
||||||
|
var item = items[id];
|
||||||
|
upperLayer.removeChild(item.view);
|
||||||
|
showScore(item.rect.center, shot.score);
|
||||||
|
items.remove(id);
|
||||||
|
}
|
||||||
|
case DESTROY(CELL(id, x, y, shot)):
|
||||||
|
var item:BrickRenderItem = cast items.get(id);
|
||||||
|
item.destroyCell(x, y);
|
||||||
|
case DESTROY(BRICK(id, shot)):
|
||||||
|
var item:BrickRenderItem = cast items.get(id);
|
||||||
|
item.destroy();
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
|
#if cpp
|
||||||
|
flash.Lib.current.stage.invalidate();
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
private function playAnimate(point:Point, animate:OnceAnimate):Promise<Dynamic> {
|
||||||
animate.x = point.x - animate.width / 2;
|
animate.x = point.x - animate.width / 2;
|
||||||
animate.y = point.y - animate.height / 2;
|
animate.y = point.y - animate.height / 2;
|
||||||
upperLayer.addChild(animate);
|
upperLayer.addChild(animate);
|
||||||
return animate.play().then(function(animate:Animate):Void {
|
return animate.play().then(function(animate:Animate):Void {
|
||||||
// ToDo: clean animates on reset
|
// ToDo: clean animates on reset
|
||||||
if (upperLayer.contains(animate)) {
|
if (upperLayer.contains(animate)) {
|
||||||
upperLayer.removeChild(animate);
|
upperLayer.removeChildSafety(animate);
|
||||||
}
|
}
|
||||||
animate.dispose();
|
animate.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function showScore(point:Point, score:Int):Void {
|
private function showScore(point:Point, score:Null<Int>):Void {
|
||||||
var view:LabelView = new LabelView();
|
if (score != null && score != 0) {
|
||||||
view.skinId = "text";
|
var view:LabelView = new LabelView();
|
||||||
view.text = Std.string(score);
|
view.style = "text";
|
||||||
view.update();
|
view.text = Std.string(score);
|
||||||
view.redraw();
|
view.update();
|
||||||
view.x = point.x - view.width / 2;
|
view.redraw();
|
||||||
view.y = point.y - view.height / 2;
|
view.x = point.x - view.width / 2;
|
||||||
upperLayer.addChild(view.content);
|
view.y = point.y - view.height / 2;
|
||||||
Timer.delay(function() upperLayer.removeChild(view.content), 1000);
|
upperLayer.addChild(view.content);
|
||||||
|
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
28
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function brickImage(type:BrickType, frame:Int = 0):BitmapData {
|
||||||
|
return Assets.getBitmapData('resources/image/map/${type}${frame > 0 ? ("-" + frame) : ""}.png');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,30 +4,29 @@ import flash.display.Bitmap;
|
|||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.PixelSnapping;
|
import flash.display.PixelSnapping;
|
||||||
import openfl.Assets;
|
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class BitmapRenderItem extends RenderItem {
|
class BitmapRenderItem extends RenderItem {
|
||||||
public var image(default, set):String;
|
public var image(default, set):BitmapData;
|
||||||
|
|
||||||
private var bitmapData:BitmapData;
|
private var bitmap:Bitmap;
|
||||||
private var bitmap:Bitmap;
|
|
||||||
|
|
||||||
public function new(rect:Rectangle) {
|
public function new(rect:Rectangle) {
|
||||||
super(rect);
|
super(rect);
|
||||||
this.bitmap = new Bitmap(null, PixelSnapping.AUTO, true);
|
this.bitmap = new Bitmap(null, PixelSnapping.NEVER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
override private function get_view():DisplayObject {
|
override private function get_view():DisplayObject {
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_image(value:String):String {
|
private function set_image(value:BitmapData):BitmapData {
|
||||||
if (image != value) {
|
if (image != value) {
|
||||||
image = value;
|
image = value;
|
||||||
bitmapData = Assets.getBitmapData(image);
|
bitmap.bitmapData = image;
|
||||||
bitmap.bitmapData = bitmapData;
|
bitmap.width = rect.width;
|
||||||
}
|
bitmap.height = rect.height;
|
||||||
return image;
|
|
||||||
}
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,31 @@ import ru.m.geom.Rectangle;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class BonusRenderItem extends BitmapRenderItem {
|
class BonusRenderItem extends BitmapRenderItem {
|
||||||
|
public var type(default, set):BonusType;
|
||||||
|
|
||||||
public var type(default, set):BonusType;
|
private var d = -0.05;
|
||||||
private var d = -0.05;
|
private var alpha = 1.0;
|
||||||
private var alpha = 1.0;
|
|
||||||
|
|
||||||
public function new(rect:Rectangle, type:BonusType) {
|
public function new(rect:Rectangle, type:BonusType) {
|
||||||
super(rect);
|
super(rect);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
move(rect.position);
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_type(value:BonusType):BonusType {
|
||||||
|
if (type != value) {
|
||||||
|
type = value;
|
||||||
|
image = RenderUtil.bonusImage(type);
|
||||||
}
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
private function set_type(value:BonusType):BonusType {
|
override public function update():Void {
|
||||||
if (type != value) {
|
super.update();
|
||||||
type = value;
|
alpha += d;
|
||||||
image = 'resources/image/bonus/${type}.png';
|
view.alpha = alpha;
|
||||||
}
|
if (alpha <= 0 || alpha >= 1.5) {
|
||||||
return type;
|
d = -d;
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
alpha += d;
|
|
||||||
view.alpha = alpha;
|
|
||||||
if (alpha <= 0 || alpha >= 1.5) {
|
|
||||||
d = -d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,91 +1,113 @@
|
|||||||
package ru.m.tankz.render.item;
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import flash.display.Shape;
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import openfl.display.DisplayObject;
|
import ru.m.geom.GridPoint;
|
||||||
import ru.m.geom.Point;
|
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
import ru.m.tankz.Type.BrickType;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
enum BrickState {
|
class BrickBitmapBundle {
|
||||||
UNBROKEN;
|
private var data:Map<String, BitmapData>;
|
||||||
BROKEN;
|
|
||||||
DESTROYED;
|
public function new() {
|
||||||
|
data = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolve(type:BrickType, cells:Array<GridPoint>, frame:Int):BitmapData {
|
||||||
|
return switch cells.length {
|
||||||
|
case 0:
|
||||||
|
null;
|
||||||
|
case 4:
|
||||||
|
type == "none" ? null : RenderUtil.brickImage(type, frame);
|
||||||
|
case _:
|
||||||
|
var image = RenderUtil.brickImage(type, frame);
|
||||||
|
var result = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||||
|
for (point in cells) {
|
||||||
|
var rect = new flash.geom.Rectangle(point.x * image.width / 2, point.y * image.height / 2, image.width / 2,
|
||||||
|
image.height / 2);
|
||||||
|
result.draw(image, null, null, null, rect);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(type:BrickType, cells:Array<GridPoint>, frame:Int = 0):BitmapData {
|
||||||
|
var key:String = '${type}_${cells.map(function(point) return point.toString()).join(",")}_${frame}';
|
||||||
|
if (!data.exists(key)) {
|
||||||
|
data.set(key, resolve(type, cells, frame));
|
||||||
|
}
|
||||||
|
return data.get(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BrickRenderItem extends RenderItem {
|
class BrickRenderItem extends BitmapRenderItem {
|
||||||
|
private static var bundle:BrickBitmapBundle = new BrickBitmapBundle();
|
||||||
|
|
||||||
public var type(default, set):BrickType;
|
public var type(default, set):BrickType;
|
||||||
public var state(get, never):BrickState;
|
|
||||||
|
|
||||||
private var image:BitmapData;
|
private var cells:Array<GridPoint>;
|
||||||
private var shape:Shape;
|
|
||||||
private var cells:Array<Point>;
|
|
||||||
|
|
||||||
public function new(rect:Rectangle, type:BrickType) {
|
private var frames:Int;
|
||||||
super(rect);
|
private var currentFrame:Int;
|
||||||
this.shape = new Shape();
|
private var ticks:Int;
|
||||||
cells = [
|
|
||||||
new Point(0, 0),
|
private static function buildCells():Array<GridPoint> {
|
||||||
new Point(0, 1),
|
return [
|
||||||
new Point(1, 0),
|
new GridPoint(0, 0),
|
||||||
new Point(1, 1),
|
new GridPoint(0, 1),
|
||||||
];
|
new GridPoint(1, 0),
|
||||||
this.type = type;
|
new GridPoint(1, 1),
|
||||||
move(rect.position);
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function new(rect:Rectangle, type:BrickType) {
|
||||||
|
super(rect);
|
||||||
|
cells = buildCells();
|
||||||
|
this.frames = 1;
|
||||||
|
this.currentFrame = 0;
|
||||||
|
this.ticks = 0;
|
||||||
|
this.type = type;
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_type(value:BrickType):BrickType {
|
||||||
|
if (type != value) {
|
||||||
|
type = value;
|
||||||
|
frames = switch type {
|
||||||
|
case "water": 2;
|
||||||
|
case _: 1;
|
||||||
|
}
|
||||||
|
cells = buildCells();
|
||||||
|
redraw();
|
||||||
}
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
private function get_state():BrickState {
|
public function destroyCell(x:Int, y:Int):Void {
|
||||||
return switch cells.length {
|
cells = cells.filter(function(point) return !(point.x == x && point.y == y));
|
||||||
case 0: DESTROYED;
|
redraw();
|
||||||
case 4: UNBROKEN;
|
}
|
||||||
case _: BROKEN;
|
|
||||||
|
public function destroy():Void {
|
||||||
|
cells = [];
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redraw():Void {
|
||||||
|
image = bundle.get(type, cells, currentFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
if (frames > 1) {
|
||||||
|
if (++ticks >= 30) {
|
||||||
|
ticks = 0;
|
||||||
|
currentFrame++;
|
||||||
|
if (currentFrame >= frames) {
|
||||||
|
currentFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override private function get_view():DisplayObject {
|
|
||||||
return shape;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_type(value:BrickType):BrickType {
|
|
||||||
if (type != value) {
|
|
||||||
type = value;
|
|
||||||
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroyCell(x:Int, y:Int):Void {
|
|
||||||
cells = cells.filter(function(point) return !(point.x == x && point.y == y));
|
|
||||||
redraw();
|
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:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
package ru.m.tankz.render.item;
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
|
import hw.color.Color;
|
||||||
|
import hw.view.utils.BitmapUtil;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class BulletRenderItem extends BitmapRenderItem {
|
class BulletRenderItem extends BitmapRenderItem {
|
||||||
public var piercing(default, set):Int = -1;
|
public var color(default, default):Null<Color>;
|
||||||
|
public var skin(default, set):String;
|
||||||
|
|
||||||
public function new(rect:Rectangle, piercing:Int) {
|
public function new(rect:Rectangle) {
|
||||||
super(rect);
|
super(rect);
|
||||||
this.piercing = piercing;
|
move(rect.position);
|
||||||
move(rect.position);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function set_piercing(value:Int):Int {
|
private function set_skin(value:String):String {
|
||||||
if (piercing != value) {
|
if (skin != value) {
|
||||||
piercing = value;
|
skin = value;
|
||||||
var type = piercing > 0 ? 'piercing' : 'normal';
|
var image = RenderUtil.bulletImage(skin);
|
||||||
image = 'resources/image/bullet/${type}.png';
|
if (color != null) {
|
||||||
}
|
image = BitmapUtil.colorize(image, color);
|
||||||
return piercing;
|
}
|
||||||
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,57 +2,56 @@ package ru.m.tankz.render.item;
|
|||||||
|
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
import haxework.color.Color;
|
import hw.color.Color;
|
||||||
import haxework.view.utils.BitmapUtil;
|
import hw.view.utils.BitmapUtil;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class EagleRenderItem extends BitmapRenderItem {
|
class EagleRenderItem extends BitmapRenderItem {
|
||||||
public var color(default, default):Color;
|
public var color(default, default):Color;
|
||||||
public var death(default, set):Bool = true;
|
public var death(default, set):Bool = true;
|
||||||
public var protect(default, set):Bool;
|
public var protect(default, set):Bool;
|
||||||
|
|
||||||
private var container:Sprite;
|
private var container:Sprite;
|
||||||
private var protectView:Animate;
|
private var protectView:Animate;
|
||||||
|
|
||||||
public function new(rect:Rectangle, color:Color) {
|
public function new(rect:Rectangle, color:Color) {
|
||||||
super(rect);
|
super(rect);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
container = new Sprite();
|
container = new Sprite();
|
||||||
container.addChild(bitmap);
|
container.addChild(bitmap);
|
||||||
protectView = AnimateBundle.tankProtect();
|
protectView = AnimateBundle.tankProtect();
|
||||||
protectView.visible = false;
|
protectView.visible = false;
|
||||||
container.addChild(protectView);
|
container.addChild(protectView);
|
||||||
death = false;
|
death = false;
|
||||||
move(rect.position);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
override private function get_view():DisplayObject {
|
private function set_death(value:Bool):Bool {
|
||||||
return container;
|
if (death != value) {
|
||||||
}
|
death = value;
|
||||||
|
image = RenderUtil.eagleImage(death);
|
||||||
private function set_protect(value:Bool):Bool {
|
if (!color.zero) {
|
||||||
if (protect != value) {
|
bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
|
||||||
protect = value;
|
}
|
||||||
if (protect) {
|
|
||||||
protectView.x = (bitmapData.width - protectView.frames[0].image.width) / 2;
|
|
||||||
protectView.y = (bitmapData.height - protectView.frames[0].image.height) / 2;
|
|
||||||
}
|
|
||||||
protectView.visible = protect;
|
|
||||||
protectView.playing = protect;
|
|
||||||
}
|
|
||||||
return protect;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_death(value:Bool):Bool {
|
|
||||||
if (death != value) {
|
|
||||||
death = value;
|
|
||||||
var suffix = death ? '-death' : '';
|
|
||||||
image = 'resources/image/eagle/eagle${suffix}.png';
|
|
||||||
if (!color.zero) {
|
|
||||||
bitmap.bitmapData = bitmapData = BitmapUtil.colorize(bitmapData, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return death;
|
|
||||||
}
|
}
|
||||||
|
return death;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import ru.m.geom.Position;
|
|||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
interface IRenderItem {
|
interface IRenderItem {
|
||||||
public var view(get, null):DisplayObject;
|
public var view(get, null):DisplayObject;
|
||||||
public var rect(default, null):Rectangle;
|
public var rect(default, null):Rectangle;
|
||||||
public function move(position:Position):Void;
|
public function move(position:Position):Void;
|
||||||
public function update():Void;
|
public function update():Void;
|
||||||
public function dispose():Void;
|
public function dispose():Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,31 +5,51 @@ import ru.m.geom.Position;
|
|||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class RenderItem implements IRenderItem {
|
class RenderItem implements IRenderItem {
|
||||||
|
public var view(get, null):DisplayObject;
|
||||||
|
public var content(get, null):DisplayObject;
|
||||||
|
|
||||||
public var view(get, null):DisplayObject;
|
public var rect(default, null):Rectangle;
|
||||||
|
|
||||||
public var rect(default, null):Rectangle;
|
public function new(rect:Rectangle) {
|
||||||
|
this.rect = rect.clone();
|
||||||
|
}
|
||||||
|
|
||||||
public function new(rect:Rectangle) {
|
private function get_view():DisplayObject {
|
||||||
this.rect = rect.clone();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function get_view():DisplayObject {
|
public function update():Void {}
|
||||||
throw "Not Implemented";
|
|
||||||
}
|
|
||||||
|
|
||||||
public function move(position:Position):Void {
|
public function dispose():Void {}
|
||||||
view.x = rect.x = position.x;
|
|
||||||
view.y = rect.y = position.y;
|
|
||||||
if (position.direction != null) {
|
|
||||||
rect.direction = position.direction;
|
|
||||||
view.rotation = rect.direction.angle;
|
|
||||||
view.x = rect.x - rect.width * (rect.direction.x + 1) / 2 + rect.width * (rect.direction.y + 1) / 2 + 0.5 * rect.width;
|
|
||||||
view.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 {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +1,173 @@
|
|||||||
package ru.m.tankz.render.item;
|
package ru.m.tankz.render.item;
|
||||||
|
|
||||||
import flash.display.DisplayObject;
|
|
||||||
import flash.display.Sprite;
|
|
||||||
import flash.display.BitmapData;
|
import flash.display.BitmapData;
|
||||||
import haxework.color.Color;
|
import flash.display.DisplayObject;
|
||||||
import haxework.view.utils.BitmapUtil;
|
import flash.display.Shape;
|
||||||
import openfl.Assets;
|
import flash.display.Sprite;
|
||||||
|
import flash.text.TextField;
|
||||||
|
import flash.text.TextFieldAutoSize;
|
||||||
|
import flash.text.TextFormat;
|
||||||
|
import hw.color.Color;
|
||||||
|
import hw.text.BitmapTextField;
|
||||||
|
import hw.view.theme.ITheme;
|
||||||
|
import hw.view.utils.BitmapUtil;
|
||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.geom.Rectangle;
|
import ru.m.geom.Rectangle;
|
||||||
|
|
||||||
class TankRenderItem extends BitmapRenderItem {
|
class TankRenderItem extends BitmapRenderItem {
|
||||||
public var color(default, default):Color;
|
public var color(default, default):Color;
|
||||||
public var skin(default, set):String;
|
public var skin(default, set):String;
|
||||||
public var hits(default, set):Int;
|
public var hits(default, set):Int;
|
||||||
public var bonus(default, set):Bool;
|
public var bonus(default, set):Bool;
|
||||||
public var moves(default, set):Bool;
|
public var boat(default, set):Bool;
|
||||||
public var protect(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 container:Sprite;
|
||||||
private var images:Array<BitmapData>;
|
private var images:Array<BitmapData>;
|
||||||
private var frame:Int;
|
private var frame:Int;
|
||||||
private var protectView:Animate;
|
private var protectView:Animate;
|
||||||
|
private var boatView:Shape;
|
||||||
|
private var nameView:TextField;
|
||||||
|
|
||||||
public function new(rect:Rectangle) {
|
@:provide static var theme:ITheme;
|
||||||
super(rect);
|
|
||||||
container = new Sprite();
|
public function new(rect:Rectangle) {
|
||||||
container.addChild(bitmap);
|
super(rect);
|
||||||
protectView = AnimateBundle.tankProtect();
|
container = new Sprite();
|
||||||
protectView.visible = false;
|
container.addChild(bitmap);
|
||||||
container.addChild(protectView);
|
protectView = AnimateBundle.tankProtect();
|
||||||
move(rect.position);
|
protectView.visible = false;
|
||||||
|
container.addChild(protectView);
|
||||||
|
boatView = buildBoatView();
|
||||||
|
boatView.visible = false;
|
||||||
|
container.addChild(boatView);
|
||||||
|
nameView = buildNameView();
|
||||||
|
container.addChild(nameView);
|
||||||
|
move(rect.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildNameView():TextField {
|
||||||
|
var result = new BitmapTextField();
|
||||||
|
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
||||||
|
result.embedFonts = theme.font.embed;
|
||||||
|
result.autoSize = TextFieldAutoSize.LEFT;
|
||||||
|
result.shadowColor = 0x000000;
|
||||||
|
result.stroke = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildBoatView():Shape {
|
||||||
|
var result = new Shape();
|
||||||
|
result.graphics.lineStyle(4, Color.fromString("green"), 0.8);
|
||||||
|
result.graphics.drawRoundRect(-1, -1, rect.width + 2, rect.height + 2, 10, 10);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_view():DisplayObject {
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
override private function get_content():DisplayObject {
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function redraw():Void {
|
||||||
|
var image1 = RenderUtil.tankImage(skin, 0);
|
||||||
|
var image2 = RenderUtil.tankImage(skin, 1);
|
||||||
|
var color1:Color = switch hits {
|
||||||
|
case 1: 0x869C43;
|
||||||
|
case 2: 0xDEAF80;
|
||||||
|
case 3: 0x5EA67A;
|
||||||
|
case _: color;
|
||||||
}
|
}
|
||||||
|
var color2:Color = color1;
|
||||||
override private function get_view():DisplayObject {
|
if (bonus) {
|
||||||
return container;
|
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 redraw():Void {
|
private function set_skin(value:String):String {
|
||||||
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
if (skin != value) {
|
||||||
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
skin = value;
|
||||||
var color1:Color = switch hits {
|
redraw();
|
||||||
case 1: 0x869C43;
|
}
|
||||||
case 2: 0xDEAF80;
|
return skin;
|
||||||
case 3: 0x5EA67A;
|
}
|
||||||
case _: color;
|
|
||||||
}
|
private function set_hits(value:Int):Int {
|
||||||
var color2:Color = color1;
|
if (hits != value) {
|
||||||
if (bonus) {
|
hits = value;
|
||||||
color1 = 0xff00aa;
|
redraw();
|
||||||
}
|
}
|
||||||
if (!color1.zero) {
|
return hits;
|
||||||
image1 = BitmapUtil.colorize(image1, color1);
|
}
|
||||||
}
|
|
||||||
if (!color1.zero) {
|
private function set_bonus(value:Bool):Bool {
|
||||||
image2 = BitmapUtil.colorize(image2, color2);
|
if (bonus != value) {
|
||||||
}
|
bonus = value;
|
||||||
images = [for (i in 0...6) image1].concat([for (i in 0...6) image2]);
|
redraw();
|
||||||
|
}
|
||||||
|
return bonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_boat(value:Bool):Bool {
|
||||||
|
if (boat != value) {
|
||||||
|
boat = value;
|
||||||
|
boatView.visible = boat;
|
||||||
|
}
|
||||||
|
return boat;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_protect(value:Bool):Bool {
|
||||||
|
if (protect != value) {
|
||||||
|
protect = value;
|
||||||
|
if (protect) {
|
||||||
|
protectView.x = (images[0].width - protectView.frames[0].image.width) / 2;
|
||||||
|
protectView.y = (images[0].height - protectView.frames[0].image.height) / 2;
|
||||||
|
}
|
||||||
|
protectView.visible = protect;
|
||||||
|
protectView.playing = protect;
|
||||||
|
}
|
||||||
|
return protect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_moves(value:Bool):Bool {
|
||||||
|
if (moves != value) {
|
||||||
|
moves = value;
|
||||||
|
bitmap.bitmapData = images[0];
|
||||||
|
}
|
||||||
|
return moves;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_name(value:String):String {
|
||||||
|
if (name != value) {
|
||||||
|
name = value;
|
||||||
|
nameView.text = name;
|
||||||
|
nameView.x = (rect.width - nameView.width) / 2;
|
||||||
|
nameView.y = -nameView.height / 2; // (rect.height - nameView.height) / 2;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
if (moves) {
|
||||||
|
frame++;
|
||||||
|
if (frame >= images.length) {
|
||||||
frame = 0;
|
frame = 0;
|
||||||
bitmap.bitmapData = images[frame];
|
}
|
||||||
}
|
bitmap.bitmapData = images[frame];
|
||||||
|
|
||||||
private function set_skin(value:String):String {
|
|
||||||
if (skin != value) {
|
|
||||||
skin = value;
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
return skin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_hits(value:Int):Int {
|
|
||||||
if (hits != value) {
|
|
||||||
hits = value;
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
return hits;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_bonus(value:Bool):Bool {
|
|
||||||
if (bonus != value) {
|
|
||||||
bonus = value;
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
return bonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
|
||||||
super.update();
|
|
||||||
if (moves) {
|
|
||||||
frame++;
|
|
||||||
if (frame > images.length - 1) {
|
|
||||||
frame = 0;
|
|
||||||
}
|
|
||||||
bitmap.bitmapData = images[frame];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,120 +9,120 @@ import ru.m.tankz.config.Config;
|
|||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
class SoundManager implements GameListener {
|
@:provide class SoundManager implements GameListener {
|
||||||
private static var TAG(default, never):String = "SoundManager";
|
private static var TAG(default, never):String = "SoundManager";
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
private static var type:String = "mp3";
|
private static var type:String = "mp3";
|
||||||
#else
|
#else
|
||||||
private static var type:String = "ogg";
|
private static var type:String = "ogg";
|
||||||
#end
|
#end
|
||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var volume(default, set):Float = 1;
|
public var volume(default, set):Float = 1;
|
||||||
public var mute(default, set):Bool = false;
|
public var mute(default, set):Bool = false;
|
||||||
|
|
||||||
private var channels:Array<SoundChannel>;
|
private var channels:Array<SoundChannel>;
|
||||||
private var transform:SoundTransform;
|
private var transform:SoundTransform;
|
||||||
|
|
||||||
private var humanTanks:Array<Int>;
|
private var humanTanks:Array<Int>;
|
||||||
private var humanBullets:Array<Int>;
|
private var humanBullets:Array<Int>;
|
||||||
private var liveBonuses:Array<Int>;
|
private var liveBonuses:Array<Int>;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
channels = [];
|
channels = [];
|
||||||
updateSoundTransform();
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function updateSoundTransform():Void {
|
||||||
|
transform = new SoundTransform(mute ? 0 : volume);
|
||||||
|
for (channel in channels) {
|
||||||
|
channel.soundTransform = transform;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function updateSoundTransform():Void {
|
private function set_volume(value:Float):Float {
|
||||||
transform = new SoundTransform(mute ? 0 : volume);
|
if (volume != value) {
|
||||||
for (channel in channels) {
|
volume = value;
|
||||||
channel.soundTransform = transform;
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_mute(value:Bool):Bool {
|
||||||
|
if (mute != value) {
|
||||||
|
mute = value;
|
||||||
|
updateSoundTransform();
|
||||||
|
}
|
||||||
|
return mute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function play(id:String):Void {
|
||||||
|
// L.d(TAG, 'play: ${id}');
|
||||||
|
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
||||||
|
if (sound != null) {
|
||||||
|
var channel = sound.play(0, 0, transform);
|
||||||
|
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
||||||
|
channels.push(channel);
|
||||||
|
} else {
|
||||||
|
L.w(TAG, 'Sound "${id}" not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stopAll():Void {
|
||||||
|
for (channel in channels) {
|
||||||
|
channel.stop();
|
||||||
|
}
|
||||||
|
channels = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function onSoundComplete(event:Event):Void {
|
||||||
|
channels.remove(event.currentTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
|
switch event {
|
||||||
|
case START(_):
|
||||||
|
play("start");
|
||||||
|
humanTanks = [];
|
||||||
|
liveBonuses = [];
|
||||||
|
humanBullets = [];
|
||||||
|
case SPAWN(BULLET(id, _, playerId, _)):
|
||||||
|
if (config.isHuman(playerId)) {
|
||||||
|
play("shot");
|
||||||
|
humanBullets.push(id);
|
||||||
}
|
}
|
||||||
}
|
case SPAWN(TANK(id, _, playerId, _)):
|
||||||
|
if (config.isHuman(playerId)) {
|
||||||
private function set_volume(value:Float):Float {
|
humanTanks.push(id);
|
||||||
if (volume != value) {
|
|
||||||
volume = value;
|
|
||||||
updateSoundTransform();
|
|
||||||
}
|
}
|
||||||
return volume;
|
case SPAWN(BONUS(id, _, type)):
|
||||||
}
|
play("bonus_add");
|
||||||
|
if (type == "live") {
|
||||||
private function set_mute(value:Bool):Bool {
|
liveBonuses.push(id);
|
||||||
if (mute != value) {
|
|
||||||
mute = value;
|
|
||||||
updateSoundTransform();
|
|
||||||
}
|
}
|
||||||
return mute;
|
case HIT(TANK(_, _)):
|
||||||
}
|
play("bullet_hit");
|
||||||
|
case HIT(CELL(_, _, shot)):
|
||||||
public function play(id:String):Void {
|
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
||||||
//L.d(TAG, 'play: ${id}');
|
// play("bullet_block");
|
||||||
var sound:Sound = Assets.getSound('resources/sounds/${id}.${type}');
|
}
|
||||||
if (sound != null) {
|
case DESTROY(TANK(id, _)):
|
||||||
var channel = sound.play(0, 0, transform);
|
if (humanTanks.indexOf(id) > -1) {
|
||||||
channel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
|
play("boom_player");
|
||||||
channels.push(channel);
|
|
||||||
} else {
|
} else {
|
||||||
L.w(TAG, 'Sound "${id}" not found');
|
play("boom_bot");
|
||||||
}
|
}
|
||||||
}
|
case DESTROY(EAGLE(_, _)):
|
||||||
|
play("boom_player");
|
||||||
public function stopAll():Void {
|
case DESTROY(BONUS(id, _)):
|
||||||
for (channel in channels) {
|
// play("bonus_get");
|
||||||
channel.stop();
|
if (liveBonuses.indexOf(id) > -1) {
|
||||||
}
|
play("live");
|
||||||
channels = [];
|
} else {
|
||||||
}
|
play("bonus_get");
|
||||||
|
|
||||||
private function onSoundComplete(event:Event):Void {
|
|
||||||
channels.remove(event.currentTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
|
||||||
switch event {
|
|
||||||
case START(_):
|
|
||||||
play("start");
|
|
||||||
humanTanks = [];
|
|
||||||
liveBonuses = [];
|
|
||||||
humanBullets = [];
|
|
||||||
case SPAWN(BULLET(id, _, playerId, _)):
|
|
||||||
if (config.isHuman(playerId)) {
|
|
||||||
play("shot");
|
|
||||||
humanBullets.push(id);
|
|
||||||
}
|
|
||||||
case SPAWN(TANK(id, _, playerId, _)):
|
|
||||||
if (config.isHuman(playerId)) {
|
|
||||||
humanTanks.push(id);
|
|
||||||
}
|
|
||||||
case SPAWN(BONUS(id, _, type)):
|
|
||||||
play("bonus_add");
|
|
||||||
if (type == "live") {
|
|
||||||
liveBonuses.push(id);
|
|
||||||
}
|
|
||||||
case HIT(TANK(_, _)):
|
|
||||||
play("bullet_hit");
|
|
||||||
case HIT(CELL(_, _, shot)):
|
|
||||||
if (humanBullets.indexOf(shot.bulletId) > -1) {
|
|
||||||
//play("bullet_block");
|
|
||||||
}
|
|
||||||
case DESTROY(TANK(id, _)):
|
|
||||||
if (humanTanks.indexOf(id) > -1) {
|
|
||||||
play("boom_player");
|
|
||||||
} else {
|
|
||||||
play("boom_bot");
|
|
||||||
}
|
|
||||||
case DESTROY(EAGLE(_, _)):
|
|
||||||
play("boom_player");
|
|
||||||
case DESTROY(BONUS(id, _)):
|
|
||||||
play("bonus_get");
|
|
||||||
if (liveBonuses.indexOf(id) > -1) {
|
|
||||||
play("live");
|
|
||||||
} else {
|
|
||||||
play("bonus_get");
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import haxework.storage.SharedObjectStorage;
|
import hw.storage.SharedObjectStorage;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.PackProgress;
|
||||||
import ru.m.tankz.Type.GameType;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class GameStorage extends SharedObjectStorage {
|
@:provide class GameStorage extends SharedObjectStorage {
|
||||||
|
private static inline var VERSION = 1;
|
||||||
|
|
||||||
private static inline var VERSION = 1;
|
public function new() {
|
||||||
|
super('game_${VERSION}');
|
||||||
|
}
|
||||||
|
|
||||||
public function new() {
|
public function get(id:PackId):PackProgress {
|
||||||
super('game_${VERSION}');
|
return exists(id) ? read(id) : new PackProgress(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(type:GameType):GameProgress {
|
public function set(progress:PackProgress):Void {
|
||||||
return exists(type) ? read(type) : new GameProgress(type);
|
write(progress.id, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(progress:GameProgress):Void {
|
|
||||||
write(progress.type, progress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package ru.m.tankz.storage;
|
|
||||||
|
|
||||||
import haxework.storage.SharedObjectStorage;
|
|
||||||
|
|
||||||
class MultiplayerStorage extends SharedObjectStorage {
|
|
||||||
|
|
||||||
public var user(get, set):User;
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
super("multiplayer");
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function get_user():User {
|
|
||||||
return read("user");
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline function set_user(value:User):User {
|
|
||||||
write("user", value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
20
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
20
src/client/haxe/ru/m/tankz/storage/NetworkStorage.hx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
|
import hw.storage.SharedObjectStorage;
|
||||||
|
|
||||||
|
@:provide class NetworkStorage extends SharedObjectStorage {
|
||||||
|
public var user(get, set):User;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super("network");
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_user():User {
|
||||||
|
return read("user");
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function set_user(value:User):User {
|
||||||
|
write("user", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +1,40 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import haxe.DynamicAccess;
|
import haxe.DynamicAccess;
|
||||||
import haxework.storage.SharedObjectStorage;
|
import hw.storage.SharedObjectStorage;
|
||||||
import ru.m.tankz.game.record.GameRecord;
|
import ru.m.tankz.game.record.GameRecord;
|
||||||
|
|
||||||
@:yield class RecordStorage extends SharedObjectStorage {
|
@:provide class RecordStorage extends SharedObjectStorage {
|
||||||
|
private static inline var VERSION = 1;
|
||||||
|
|
||||||
private static inline var VERSION = 1;
|
public function new() {
|
||||||
|
super('record_${VERSION}');
|
||||||
|
}
|
||||||
|
|
||||||
public function new() {
|
public function save(record:GameRecord):Void {
|
||||||
super('record_${VERSION}');
|
L.d("RecordStorage", 'save $record');
|
||||||
}
|
write('${record.info.id}.info', record.info);
|
||||||
|
write(record.info.id, record);
|
||||||
|
}
|
||||||
|
|
||||||
public function save(record:GameRecord):Void {
|
override public function delete(id:String):Void {
|
||||||
L.d("RecordStorage", 'save $record');
|
super.delete(id);
|
||||||
write('${record.info.id}.info', record.info);
|
super.delete('${id}.info');
|
||||||
write(record.info.id, record);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override public function delete(id:String):Void {
|
public function list():Array<GameRecordInfo> {
|
||||||
super.delete(id);
|
var result = [];
|
||||||
super.delete('${id}.info');
|
var data:DynamicAccess<String> = so.data;
|
||||||
}
|
for (id in data.keys()) {
|
||||||
|
try {
|
||||||
public function iterator():Iterator<GameRecordInfo> {
|
if (StringTools.endsWith(id, '.info')) {
|
||||||
var data:DynamicAccess<String> = so.data;
|
result.push(read(id));
|
||||||
for (id in data.keys()) {
|
|
||||||
try {
|
|
||||||
if (StringTools.endsWith(id, '.info')) {
|
|
||||||
@yield return read(id);
|
|
||||||
}
|
|
||||||
} catch (error:Dynamic) {
|
|
||||||
L.w("RecordStorage", 'read ', error);
|
|
||||||
delete(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (error:Dynamic) {
|
||||||
|
L.w("RecordStorage", 'read ', error);
|
||||||
|
delete(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,112 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import flash.ui.Keyboard;
|
import flash.ui.Keyboard;
|
||||||
import haxework.storage.SharedObjectStorage;
|
import hw.signal.Signal;
|
||||||
import haxework.utils.ObjectUtil;
|
import hw.storage.SharedObjectStorage;
|
||||||
|
import hw.utils.ObjectUtil;
|
||||||
|
import ru.m.control.DeviceAction;
|
||||||
|
import ru.m.control.DeviceType;
|
||||||
import ru.m.geom.Direction;
|
import ru.m.geom.Direction;
|
||||||
import ru.m.tankz.control.ActionConfig;
|
import ru.m.tankz.control.Binding;
|
||||||
import ru.m.tankz.control.Control.TankAction;
|
import ru.m.tankz.control.Control;
|
||||||
|
|
||||||
class SettingsStorage extends SharedObjectStorage {
|
enum Setting {
|
||||||
|
CONTROL(index:Int, value:Binding);
|
||||||
public function new() {
|
DISPLAY_FPS(value:Bool);
|
||||||
super("settings");
|
ENABLE_NETWORK(value:Bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActionConfig(index:Int):ActionConfig {
|
@:provide class SettingsStorage extends SharedObjectStorage {
|
||||||
return exists('action:$index') ? read('action:$index') : getDefaultActionConfig(index);
|
private static inline var VERSION = 4.1;
|
||||||
}
|
|
||||||
|
public var signal(default, null):Signal<Setting> = new Signal();
|
||||||
public function setActionConffig(index:Int, value:ActionConfig) {
|
|
||||||
write('action:$index', value);
|
public var displayFPS(get, set):Bool;
|
||||||
}
|
|
||||||
|
private function get_displayFPS():Bool {
|
||||||
public static function getDefaultActionConfig(index:Int):ActionConfig {
|
return read("setting:display_fps");
|
||||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : empty);
|
}
|
||||||
}
|
|
||||||
|
private function set_displayFPS(value:Bool):Bool {
|
||||||
private static var defaults:Map<Int, ActionConfig> = [
|
write("setting:display_fps", value);
|
||||||
0 => new ActionConfig([
|
signal.emit(DISPLAY_FPS(value));
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.W},
|
return get_displayFPS();
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.A},
|
}
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.S},
|
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.D},
|
public var enableNetwork(get, set):Bool;
|
||||||
{action:TankAction.SHOT, key:Keyboard.SPACE},
|
|
||||||
]),
|
private function get_enableNetwork():Bool {
|
||||||
1 => new ActionConfig([
|
return read("setting:enable_network");
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:Keyboard.UP},
|
}
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:Keyboard.LEFT},
|
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:Keyboard.DOWN},
|
private function set_enableNetwork(value:Bool):Bool {
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:Keyboard.RIGHT},
|
write("setting:enable_network", value);
|
||||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
signal.emit(ENABLE_NETWORK(value));
|
||||||
]),
|
return get_enableNetwork();
|
||||||
];
|
}
|
||||||
|
|
||||||
private static var empty:ActionConfig = new ActionConfig([
|
public function new() {
|
||||||
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
super('settings_${VERSION}');
|
||||||
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
}
|
||||||
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
|
||||||
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
public function getBinding(index:Int):Binding {
|
||||||
{action:TankAction.SHOT, key:-1},
|
return exists('action:$index') ? read('action:$index') : getDefaultBinding(index);
|
||||||
]);
|
}
|
||||||
|
|
||||||
|
public function saveBinding(index:Int, value:Binding) {
|
||||||
|
write('action:$index', value);
|
||||||
|
signal.emit(CONTROL(index, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDefaultBinding(index:Int):Binding {
|
||||||
|
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||||
|
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||||
|
return [
|
||||||
|
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||||
|
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||||
|
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||||
|
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||||
|
SHOT(0) => {device: device, action: KEY(0)},
|
||||||
|
SHOT(1) => {device: device, action: KEY(1)},
|
||||||
|
SHOT(2) => {device: device, action: KEY(2)},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function buildEmpty():Binding {
|
||||||
|
return [
|
||||||
|
MOVE(Direction.TOP) => null,
|
||||||
|
MOVE(Direction.LEFT) => null,
|
||||||
|
MOVE(Direction.BOTTOM) => null,
|
||||||
|
MOVE(Direction.RIGHT) => null,
|
||||||
|
SHOT(0) => null,
|
||||||
|
SHOT(1) => null,
|
||||||
|
SHOT(2) => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static var mobileDefaults:Map<Int, Binding> = [0 => buildDeviceBinding(SCREEN),];
|
||||||
|
|
||||||
|
private static var defaults:Map<Int, Binding> = [
|
||||||
|
0 => [
|
||||||
|
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||||
|
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||||
|
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||||
|
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||||
|
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||||
|
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
|
||||||
|
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.E)},
|
||||||
|
],
|
||||||
|
1 => [
|
||||||
|
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||||
|
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||||
|
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||||
|
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||||
|
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||||
|
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_1)},
|
||||||
|
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_2)},
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user