232 Commits

Author SHA1 Message Date
27120bbed5 build(docker): add docker builder 2026-04-06 14:26:15 +03:00
03d6e1f822 feat(editor): update editor ui 2024-06-01 20:39:21 +03:00
648d15fc88 feat(client): update game ui 2024-05-30 18:54:19 +03:00
d6af58875d feat(client): update elements sizes 2024-05-30 16:14:03 +03:00
16a5adefad feat(client): add render scaling 2024-05-29 15:19:18 +03:00
682eaa677c refactor: update to haxework 2.1.0 2024-05-27 11:31:35 +03:00
4319d66c61 build: add any scripts 2024-05-27 11:09:02 +03:00
f6f729e8d4 build: update haxework version 2023-01-04 10:54:04 +03:00
a39b02bfe7 refactor(server): use cpp target instead of neko 2023-01-02 14:36:44 +03:00
1cfc98dd57 refactor: update dependencies 2023-01-01 13:33:34 +03:00
ee846f6219 [rework] add base game class 2019-12-26 13:58:02 +03:00
e353d97415 [level] add death levels 2019-12-05 22:37:10 +03:00
2b49fafa0b [client] PackView progress 2019-11-21 17:47:46 +03:00
b33b853747 [client] update to template macro 2019-11-19 21:54:43 +03:00
8e3e6bdb6c [editor] remove unused provides 2019-11-19 18:01:10 +03:00
d9d385b0ef [client] use class provide macro 2019-11-18 18:01:26 +03:00
8c16b5ba90 [client] add AnimationManager 2019-11-14 16:51:05 +03:00
1aaa69f2d7 [build] confiigure build dir 2019-11-10 17:14:36 +03:00
6240846f0c [client] icon button size for mobile devices 2019-10-31 17:58:58 +03:00
70e6565e1f [client] add PausePopup 2019-10-30 22:16:06 +03:00
fffb6a3214 update 2019-10-23 17:53:19 +03:00
04bea46b3b [common] add LevelPackMeta 2019-10-22 18:00:36 +03:00
4da06e52e5 [work] update worklist 2019-10-17 21:36:46 +03:00
8878a825b8 [client] update bullet images 2019-10-09 17:57:22 +03:00
7de1897b32 [build] android keystore 2019-10-08 17:52:16 +03:00
d670722674 [common] weapon delay param 2019-10-07 17:29:20 +03:00
e7d031db58 [client] update boat bonus image 2019-10-04 17:55:54 +03:00
71087286b2 [client] render: fixes 2019-10-03 17:25:52 +03:00
757bc87426 [editor] build fix 2019-10-01 22:28:51 +03:00
1b5eef810c [client] render: fix empty brick render 2019-10-01 22:09:22 +03:00
cfa1475cf6 [client] compare versions in updater 2019-09-30 21:42:33 +03:00
1e79fcfacb [common] add ICaller; [client] rework BrickRenderItem 2019-09-29 20:34:51 +03:00
b34cb41bff [common] update game rework 2019-09-29 12:23:58 +03:00
d2aff5f2ee [common] add CachedLevelBundle; [client] add NetworkStateView 2019-09-23 14:26:38 +03:00
beda5e6c5f [client] display fps setting 2019-09-22 20:29:25 +03:00
50c4aebc0f up version 2019-09-17 20:11:32 +03:00
30325f6d16 [common] add boat bonus
[client] add active style to gamepad buttons
2019-09-16 14:41:12 +03:00
bddb590d30 [common] update Point, add GridPoint 2019-09-12 17:43:08 +03:00
de831fcb26 up version 2019-09-11 21:05:15 +03:00
5645fb6d0f [client] add PackView 2019-09-11 17:52:09 +03:00
bab588e6fb [editor] update 2019-09-10 19:47:35 +03:00
2565b6017a [editor] update 2019-09-10 17:56:51 +03:00
112cd7ba2f up version 2019-09-09 21:44:29 +03:00
77ddd78d84 [editor] support level pack edit 2019-09-09 17:56:08 +03:00
4fa5cf84fa [editor] add PackListFrame 2019-09-06 16:23:31 +03:00
40bdf6a5cc [build] downgrade lime,openfl (perfomance); remove yield 2019-09-05 22:02:54 +03:00
47039bbaa5 [build] up dependencies versions 2019-09-05 10:45:07 +03:00
4d7fcb4b4b [client] Updater update 2019-09-04 22:46:06 +03:00
5f24e85deb [build] app gulp-haxetool version 2019-09-03 21:05:36 +03:00
42fd008a54 [build] fixes for windows 2019-09-03 20:57:28 +03:00
c2b0618c93 [build] update publish task 2019-09-02 17:07:31 +03:00
94f72f71e3 [build] up openfl and lime versions 2019-09-02 01:00:32 +03:00
bb4b928c89 Merge remote-tracking branch 'origin/windows' into develop 2019-09-01 23:15:07 +03:00
d67d4e5709 [editor] fix 2019-08-30 16:06:45 +03:00
a4bbeb2573 up version 2019-08-30 15:52:23 +03:00
e032c25e1a [client] add Updater 2019-08-29 17:43:09 +03:00
d9cce32bb8 [common] saveState param in PlayerConfig 2019-08-28 17:54:41 +03:00
10d5e0df40 [gulp] add windows target 2019-08-28 07:24:19 +03:00
0f3392aa0c [client] gamepad: update SmartActionAreaBuilder 2019-08-27 21:17:26 +03:00
9d4558ca47 [client] GameView rework 2019-08-27 17:35:22 +03:00
6609756065 [work] update list 2019-08-26 23:04:38 +03:00
605935528b [gulp] add publish task 2019-08-26 14:44:51 +03:00
f072d8dc6e [client] add android build 2019-08-23 14:57:12 +03:00
00cd404a98 up version 2019-08-21 21:27:24 +03:00
d47be9ea8a [common] config: add bonus spwan interval 2019-08-19 20:57:36 +03:00
2d70a5652b [comon] ArmorEagleBonus improve 2019-08-18 15:57:29 +03:00
bbf1438728 [work] update work list 2019-08-16 22:39:49 +03:00
c0496f2e7c [client] bullet skins 2019-08-14 18:00:56 +03:00
636be8611f [common] weapon queue & bullet layer 2019-08-13 21:53:47 +03:00
48f9c433e2 [common] multiple weapon support 2019-08-13 16:41:57 +03:00
314f5a480c [common] add tank weapon array 2019-08-12 22:02:28 +03:00
46f2abab05 [client] screen gamepad as default on mobile devices 2019-08-07 17:47:11 +03:00
883f14fb76 up version 2019-08-06 21:40:01 +03:00
cc151322d8 [common] add ice brick logic 2019-08-06 17:47:00 +03:00
de64e2813e [common] add ArmorEagleBonus 2019-08-06 16:19:38 +03:00
db80c151bb [common] add bonuses classes 2019-08-05 23:02:04 +03:00
ef971e03b9 Merge branch 'develop' of bitbucket.org:infernalgames/tankz into develop 2019-08-02 17:50:47 +03:00
f10da93a12 [client] add result styles 2019-08-02 17:48:34 +03:00
e63b41ae8a up version 2019-08-01 22:21:19 +03:00
43a34cce39 [client] update ResultFrame 2019-08-01 17:15:16 +03:00
b9b5453f89 [client] update ResultFrame 2019-07-31 17:59:13 +03:00
f5af6716d5 up version 2019-07-29 21:50:48 +03:00
7125cc1e9f [client] rework GamePanel 2019-07-29 17:57:33 +03:00
8a3ceec1ee up version 2019-07-26 14:23:10 +03:00
523f334c1b [client] text.box style update 2019-07-26 12:04:59 +03:00
a547b68dc0 [client] SettingsEditor fixes 2019-07-24 17:32:48 +03:00
45cabc1926 up version 2019-07-23 17:38:31 +03:00
42138cd4ad [client] improve GamepadView 2019-07-23 17:37:59 +03:00
e8e3a6f1b3 [client] improve StartFrame 2019-07-23 16:39:43 +03:00
6d5148e0a5 up version 2019-07-22 23:01:40 +03:00
262221d969 [editor] update to haxework 2019-07-22 22:59:18 +03:00
9eccb263c0 [client] remake panel 2019-07-22 17:45:38 +03:00
ba90b90cd3 [client] update to haxework 2019-07-18 20:38:28 +03:00
94340bddb1 [client] fixes 2019-07-18 14:32:37 +03:00
3361d252ee [client] update to haxework 2019-07-17 21:08:00 +03:00
637772f2dd [client] fix AppTheme 2019-07-17 17:48:34 +03:00
f703c76c21 [client] update to haxework 2019-07-16 17:56:31 +03:00
5fe307a218 [client] update to haxework 2019-07-13 16:14:54 +03:00
670a11d6ba [client] update to haxework 2019-07-10 19:59:02 +03:00
1ec1c3baae [client] add AppTheme 2019-07-09 17:45:07 +03:00
24f5b0c218 [client] replace and macros in templates 2019-07-09 12:04:17 +03:00
b7bc1d244f [common] PlayerControl update 2019-06-28 16:42:39 +03:00
fbc9238d2f [client] update frames 2019-06-27 11:59:28 +03:00
eb7c311bb6 up version 2019-06-25 20:22:14 +03:00
9640414ba4 [editor] update Frames 2019-06-25 17:36:31 +03:00
bc95ca03e2 [client] update Frames 2019-06-24 22:09:52 +03:00
d0ebf05f1c [client] add GameInit 2019-06-24 18:04:01 +03:00
91dd84a437 [common] add PackId 2019-06-20 16:18:54 +03:00
1b36016a1a [common] fix load old level format 2019-06-20 11:16:17 +03:00
db0adbac30 [client] control settings rework 2019-06-19 22:35:11 +03:00
948648b313 [work] update 2019-06-19 17:23:09 +03:00
73822dc95a [client] add JoystickDevice 2019-06-18 20:47:04 +03:00
282bc68734 [client] DeviceType in SettingsEditor 2019-06-18 17:50:47 +03:00
2ff374abb6 [client] add ControlBus 2019-06-18 12:14:04 +03:00
f999c66fea [client] use touch events in GamepadView 2019-06-17 20:43:14 +03:00
2b3f368e0f [client] add screen gamepad 2019-06-17 17:33:35 +03:00
c0ab953115 [all] fixes for LevelPack 2019-06-17 11:45:33 +03:00
e39de4467d [common] added LevelPack 2019-06-14 16:06:22 +03:00
4c3f1ca0fc [common] clock bonus freeze team instead tanks 2019-06-14 12:47:20 +03:00
7fa5a4e048 [client] fix GamePlayer 2019-06-13 21:42:13 +03:00
dc1279f636 [editor] MapFrame rework 2019-06-13 16:23:22 +03:00
5798fa9db7 [editor] rename packages 2019-06-13 11:02:54 +03:00
c534cf20fd [common] add death mode map 2019-06-12 21:45:28 +03:00
38e14c9269 [editor] custom map size fix 2019-06-11 19:59:53 +03:00
a66b72ba22 [common] add map size 2019-06-11 17:29:18 +03:00
2c42d993ca [common] fix bullet and tank collision with bricks under bonus 2019-06-11 15:56:00 +03:00
a49d673f25 [client] fix tank destroy zero score label 2019-06-11 15:31:13 +03:00
ee5de9f3db [client] update CreateGamePopup 2019-06-10 21:30:30 +03:00
94b3a94cbb [server] join game after relogin 2019-06-10 16:12:08 +03:00
caab6ba3a3 up version 2019-06-07 18:41:10 +03:00
7f70c49b87 Merge branch 'develop' 2019-06-07 17:31:32 +03:00
8f50da64c2 [client] add tanks players names to render 2019-06-07 17:31:00 +03:00
982ca09a23 up version 2019-06-06 20:04:38 +03:00
dbf30decae [client] fix control 2019-06-06 17:38:37 +03:00
abd1b834d7 [client] game room frames update 2019-06-05 11:37:25 +03:00
6ad9076987 [client] add CreateGamePopup 2019-06-04 14:41:21 +03:00
78bbf5264e [proto] add rooms and slots 2019-06-04 12:13:27 +03:00
4c8ae66624 [connection] send queue in NekoConnection 2019-06-03 11:23:20 +03:00
5a3d5b974e [common] ticker update 2019-06-02 22:09:13 +03:00
fb9a28c126 [network] update 2019-05-31 15:47:16 +03:00
7115ea8ac2 [common] fix null color 2019-05-30 16:03:46 +03:00
01417f5bbd up version 2019-05-30 15:25:33 +03:00
abf944418e [common] add PlayerControl presets 2019-05-30 15:24:26 +03:00
c7946ef1da [common] PacketQueue fix 2019-05-29 16:09:46 +03:00
241499bc2d [common] add Ticker 2019-05-29 11:22:25 +03:00
74297dd9c7 [common] refactor ControlFactory 2019-05-28 21:50:05 +03:00
31cb20bf85 [common] add BaseControlFactory 2019-05-28 19:42:46 +03:00
1d95de02e1 [common] update for network 2019-05-28 17:03:04 +03:00
ba13111a8e [common] GameRunner extend from Game 2019-05-27 17:59:59 +03:00
94b19a1c26 up version 2019-05-24 16:04:36 +03:00
50a0cee044 [network] update 2019-05-24 15:43:00 +03:00
26ad5f47cd [client] add GameRoomFrame 2019-05-23 17:57:54 +03:00
864d5f3335 [common] binary message in ws connection 2019-05-23 11:43:35 +03:00
4b426183e8 [client] add GameListFrame 2019-05-22 17:25:51 +03:00
a5722dfa9d [common] add DesktopConnection 2019-05-21 17:44:48 +03:00
7984d8282c [client] update SoundManager 2019-05-20 22:02:13 +03:00
17823ede11 [core] disable autospawn bonuses 2019-05-20 17:20:44 +03:00
5db3ae1af0 [client] set FPS to 60 2019-05-20 17:11:50 +03:00
bbe2aeb7fb [editor] refactor MapEditView 2019-05-20 13:00:04 +03:00
09b188cf24 [build] disable editor 2019-05-17 16:24:29 +03:00
11f8fc6190 [render] add protect view 2019-05-17 16:10:10 +03:00
96e608c36f [render] bricks and cells from GameEvent 2019-05-17 12:55:32 +03:00
3c116db135 [render] use only GameEvent for redraw 2019-05-16 23:27:27 +03:00
efe826110c [render] spawn eagle from GameEvent 2019-05-16 21:25:53 +03:00
c1ff14111d [client] update render 2019-05-16 17:13:12 +03:00
cd7dd1984b [common] add GameEvent.MOVE 2019-05-15 15:15:07 +03:00
686c659c84 [editor] fix 2019-05-14 21:19:20 +03:00
797dfca2be [client] fix RecordStorage for linux 2019-05-14 17:16:57 +03:00
aa10825b12 [common] update GameEvent 2019-05-14 12:24:29 +03:00
608ed3acc4 [client] update RecordFrame 2019-05-13 22:35:16 +03:00
03b461f082 [common] implement GameEvent.DESTORY.CELL 2019-05-13 21:56:28 +03:00
cbb28f4158 [client] add position to IGamePanel 2019-05-13 19:32:52 +03:00
13240677b0 [client] refactored GameFrame 2019-05-13 17:34:53 +03:00
b0ae85334b [common] enity id 2019-05-08 16:40:58 +03:00
183c6c16f1 [client] add RecordFrame 2019-05-07 17:21:01 +03:00
a7f286dc42 [common] build bonus with EntityBuilder 2019-05-06 20:40:43 +03:00
20b60009e3 [common] build tank and bullet with EntityBulder 2019-05-06 17:53:34 +03:00
d6b572aead [common] add EntityBuilder 2019-05-06 16:21:45 +03:00
d11d0ac53f [common] add engine interface 2019-05-05 21:18:36 +03:00
ab02460b11 [common] add GameRecorder and GamePlayer 2019-04-30 17:26:54 +03:00
fc18e2e0b7 [common] add GameRunner 2019-04-30 12:17:28 +03:00
363a48bb1b [common] update Game with GameEvent 2019-04-26 17:28:36 +03:00
e9de677ceb [common] update GameEvent 2019-04-25 17:21:03 +03:00
5ff7b19475 [common] add GameEvent 2019-04-22 17:40:36 +03:00
7ddba8f69b use dispatcher macro 2019-04-22 10:36:39 +03:00
b86e0ddd20 [comon] remove change signal from engine 2019-04-19 16:20:01 +03:00
a3f3de3af5 [engine] fix position fix 2019-04-17 22:38:37 +03:00
4a4ca463c3 [client] update LevelPopup 2019-04-08 21:45:52 +03:00
13d01293f6 [common] diffilicity presets support 2019-04-08 14:53:44 +03:00
d0104e4361 up version 2019-04-05 16:51:03 +03:00
c3db9f2414 [client] update SoundManager 2019-04-05 16:29:17 +03:00
f34d35e03a up version 2019-04-04 20:41:54 +03:00
9868d27bc3 up version 2019-04-04 20:11:33 +03:00
c0b4b2a4c1 [common] add GameProgress 2019-04-04 17:12:00 +03:00
9dc0a4ce06 [client] add universal LevelFrame 2019-04-03 17:23:15 +03:00
c58735ea43 up version 2019-04-02 23:32:41 +03:00
4e2b65c225 [common] add gun bonus 2019-04-02 23:22:21 +03:00
663935bd75 [client] update clock, helmet bonuses images 2019-04-02 22:06:58 +03:00
d1ed17d1d7 [client] settings editor fix 2019-04-02 17:42:08 +03:00
135ad0d992 [client] update storages 2019-03-29 11:50:16 +03:00
8fb1d6132d [common] Player state life fix 2019-03-28 20:50:27 +03:00
f60feea6e8 [common] PlayerState update 2019-03-28 17:38:51 +03:00
d7b7744eb8 [client] add preloader 2019-03-28 15:59:46 +03:00
2eb606aa21 [engine] fix tank position 2019-03-28 12:18:40 +03:00
a86c4fc447 [common] add dota levels 2019-03-28 10:28:33 +03:00
1ea216fd20 up version 2019-03-27 23:56:36 +03:00
121c470b00 [common] add dota levels 2019-03-27 17:39:41 +03:00
404dd77806 [client] use LabelView for score in render 2019-03-26 22:20:07 +03:00
d2f23e7777 up version 2019-03-26 21:34:59 +03:00
fd0e2382d0 [client] add death game panel 2019-03-26 17:37:33 +03:00
e609dafedc [common] add GameDispatcher 2019-03-26 11:23:44 +03:00
a948dfbaad [editor] tanks colors 2019-03-25 21:17:39 +03:00
5b804c6902 [client] add colorize param to PlayerView 2019-03-25 17:56:41 +03:00
556cd2f1a9 [common] add deathmatch mode 2019-03-25 17:42:20 +03:00
7d570336a5 [client] update haxework 2019-03-25 16:45:54 +03:00
a9b591a7ca [editor] add ColorView 2019-03-25 16:01:37 +03:00
216e1aa476 [client] add font 2019-03-22 15:47:47 +03:00
4d8de90419 [client] rename frame => view 2019-03-21 20:26:28 +03:00
0b17fbf804 [common] add hard bot 2019-03-21 17:45:03 +03:00
c6639e11b1 [core] add color to PlayerState 2019-03-21 12:22:01 +03:00
e6f9aa8ba1 [client] apply LayoutSkin 2019-03-20 17:36:15 +03:00
2c191d932c [client] apply GeometrySkin 2019-03-19 22:47:24 +03:00
d52b94d095 [client] ResultFrame update 2019-03-17 14:12:13 +03:00
c67385576e [client] add ResultFrame 2019-03-15 16:15:47 +03:00
f09e70c5f8 [client] add linux taskbar icon 2019-03-14 22:37:28 +03:00
0f5cf7fdc5 [client] fix app icon 2019-03-14 21:26:57 +03:00
426b2718bb [common] game update 2019-03-14 17:49:47 +03:00
8ea862a118 [common] add GameState 2019-03-14 12:58:00 +03:00
1f87a71833 [build] disable server build 2019-03-13 21:17:31 +03:00
56c2cd9437 [client] small fixes 2019-03-13 21:10:46 +03:00
85e5f9a553 [common] add GameStart 2019-03-13 17:11:20 +03:00
d9915120d4 [client] update haxework. ep8 2019-03-13 13:06:48 +03:00
419 changed files with 18548 additions and 13759 deletions

12
.editorconfig Normal file
View File

@@ -0,0 +1,12 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.yaml]
indent_size = 2

10
.env.default Normal file
View File

@@ -0,0 +1,10 @@
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>

3
.gitignore vendored
View File

@@ -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
View 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`

28
Dockerfile Normal file
View File

@@ -0,0 +1,28 @@
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"]

9
README.md Normal file
View File

@@ -0,0 +1,9 @@
# Tankz
## Play
https://shmyga.ru/tankz/html5/index.html
## Packages
https://git.shmyga.ru/InfernalGames/-/packages/generic/tankz

93
WORK.md
View File

@@ -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%

View File

@@ -3,6 +3,8 @@ hash_behaviour = merge
host_key_checking = False host_key_checking = False
#callback_whitelist = profile_tasks #callback_whitelist = profile_tasks
display_skipped_hosts = False display_skipped_hosts = False
stdout_callback = yaml
bin_ansible_callbacks = True
[ssh_connection] [ssh_connection]
pipelining = True pipelining = True

View File

@@ -5,11 +5,11 @@ project_user: holop
deploy_user: "{{ project_user }}" deploy_user: "{{ project_user }}"
deploy_project: "{{ project_name }}" deploy_project: "{{ project_name }}"
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git" deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
deploy_repo_version: staging deploy_repo_version: develop
deploy_npm: yes deploy_npm: yes
service_name: "{{ project_name }}" service_name: "{{ project_name }}"
service_work_dir: "{{ deploy_current_dir }}/target/server/neko" service_work_dir: "{{ deploy_current_dir }}/target/server/cpp"
service_command: "/usr/bin/neko {{ service_work_dir }}/{{ project_name }}.n {{ service_host }}" service_command: "{{ service_work_dir }}/{{ project_name }} {{ service_host }}"
service_user: www-data service_user: www-data
service_control_user: "{{ project_user }}" service_control_user: "{{ project_user }}"

View File

@@ -1,4 +1,5 @@
all: all:
hosts: shmyga.ru hosts: shmyga.ru
vars: vars:
service_host: 172.31.1.100 service_host: 213.139.208.180
config_src: "/home/holop/tankz/config.json"

View File

@@ -0,0 +1,2 @@
config_src: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json"
config_dest: "{{ deploy_release_dir }}/config.json"

View File

@@ -1,11 +1,11 @@
--- ---
- name: "Copy config" - name: "Copy config"
copy: copy:
src: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json" src: "{{ config_src }}"
dest: "{{ deploy_release_dir }}/config.json" dest: "{{ config_dest }}"
remote_src: true remote_src: true
- name: "Gulp build" - name: "Gulp build"
command: "/usr/local/lib/npm/bin/gulp default" command: "{{ deploy_release_dir }}/node_modules/.bin/gulp default --host shmyga.ru"
args: args:
chdir: "{{ deploy_release_dir }}" chdir: "{{ deploy_release_dir }}"

View File

@@ -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
} }
} }

View File

@@ -1,7 +0,0 @@
{
"SdkDir": "/home/holop/sdk",
"SSH": {
"PrivateKey": null,
"Passphrase": null
}
}

22
docker-compose.yaml Normal file
View File

@@ -0,0 +1,22 @@
name: $PROJECT
services:
builder:
container_name: $PROJECT-builder
image: infernal-games/$PROJECT-builder
build:
context: .
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

2
gen.sh
View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
haxelib run protohx generate protohx.json haxelib run protohx generate protohx.json
haxelib run orm mysql://shmyga:xkbp8jh9z2@localhost:3306/armageddon \ haxelib run orm mysql://shmyga:password@localhost:3306/armageddon \
-s src-gen/haxe \ -s src-gen/haxe \
-c ru.m.tankz.db \ -c ru.m.tankz.db \
-a ru.m.tankz.db -a ru.m.tankz.db

View File

@@ -1,59 +1,82 @@
"use strict";
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 publish = require('./tasks/gulp-publish');
if (packageInfo.haxe) {
Haxe.VERSION = packageInfo.haxe;
}
// ToDo: update default in gulp-haxetool
FlashPlayer.VERSION = '31';
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.setup = function setup() {
const builder = Project.Builder.new(
client.config,
Project.Platform.ANDROID,
client.buildSystem,
);
return builder.prepare();
};
exports.generate = function generate() { exports.generate = function generate() {
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => { return exports.setup().then(() =>
if (stdout.indexOf('FAIL') > -1) { new Haxe()
.haxelib(["run", "protohx", "generate", "protohx.json"])
.then(({ stdout }) => {
if (stdout.indexOf("FAIL") > -1) {
throw stdout; 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/image/tank/pd-0.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' : ''),
}, },
key: Config.Key,
libs: packageInfo.haxeDependencies, libs: packageInfo.haxeDependencies,
sources: [ sources: [
'src/common/haxe', 'src/common/haxe',
'src-gen/haxe', 'src-gen/haxe',
], ],
assets: [ assets: [
'src/common/resources' 'src/common/resources/config',
],
flags: [
'proto_debug',
], ],
macros: [ macros: [
//'yield.parser.Parser.auto()', // ToDo: bug with extraParams.hxml in yield library
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`, `CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
] ]
}); });
const host = argv.host || 'localhost';
const port = argv.port || 5000;
/** /**
* client * client
*/ */
@@ -63,20 +86,35 @@ const client = new Project(
Project.Platform.FLASH, Project.Platform.FLASH,
Project.Platform.HTML5, Project.Platform.HTML5,
Project.Platform.LINUX, Project.Platform.LINUX,
Project.Platform.WINDOWS,
Project.Platform.ANDROID, Project.Platform.ANDROID,
], ],
config.branch({ config.branch({
name: 'client', name: 'client',
sources: ['src/client/haxe'], sources: [
'src/client/haxe',
],
main: 'ru.m.tankz.Client', main: 'ru.m.tankz.Client',
assets: ['src/client/resources'], preloader: 'ru.m.tankz.Preloader',
assets: [
'src/common/resources/level',
'src/client/resources',
],
meta: {
width: 1024,
height: 576,
},
flags: [ flags: [
//'proto_debug',
//'dom', //'dom',
//'dev_layout', //'dev_layout',
//'bitmap_text', //'bitmap_text',
], ],
macros: [
`CompilationOption.set('host','${host}')`,
`CompilationOption.set('port',${port})`,
]
}), }),
module.exports.generate
).bind(module, gulp); ).bind(module, gulp);
/** /**
@@ -84,13 +122,32 @@ const client = new Project(
*/ */
const editor = new Project( const editor = new Project(
Project.BuildSystem.OPENFL, Project.BuildSystem.OPENFL,
[
Project.Platform.FLASH, Project.Platform.FLASH,
Project.Platform.HTML5,
Project.Platform.LINUX,
],
config.branch({ config.branch({
name: 'editor', name: 'editor',
sources: ['src/client/haxe', 'src/editor/haxe'], sources: [
'src/client/haxe',
'src/editor/haxe',
],
main: 'ru.m.tankz.editor.Editor', main: 'ru.m.tankz.editor.Editor',
assets: ['src/client/resources'], preloader: 'ru.m.tankz.Preloader',
meta: {filename: 'editor'} assets: [
'src/client/resources',
'src/editor/resources',
],
meta: {
filename: 'editor',
pack: 'ru.m.tankz.editor',
width: 1024,
height: 768,
},
flags: [
//'dev_layout',
]
}) })
).bind(module, gulp); ).bind(module, gulp);
@@ -99,25 +156,59 @@ const editor = new Project(
*/ */
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',
]
}),
).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,
exports.generate,
module.exports['client:flash:build'], module.exports['client:flash:build'],
module.exports['client:html5:build'],
module.exports['client:linux:build'],
//module.exports['client:android:build'],
module.exports['editor:flash:build'],
module.exports['server:neko:build'],
module.exports['client:flash:html'], module.exports['client:flash:html'],
module.exports['client:html5:build'],
module.exports['editor:flash:build'],
module.exports['editor:flash:html'],
module.exports['editor:html5:build'],
module.exports['server: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: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);

5
hxformat.json Normal file
View File

@@ -0,0 +1,5 @@
{
"indentation": {
"character": " "
}
}

7254
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,25 +1,25 @@
{ {
"name": "tankz", "name": "tankz",
"version": "0.8.1", "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.14" "gulp-haxetool": "^0.1.9",
"yargs": "^13.2.4"
}, },
"haxeDependencies": { "haxeDependencies": {
"haxework": "git@bitbucket.org:shmyga/haxework.git", "haxework": "2.1.0",
"lime": "7.2.1", "lime": "8.0.0",
"openfl": "8.8.0", "openfl": "9.2.0",
"hxcpp": "4.0.8", "hxcpp": "4.2.1",
"promhx": "1.1.0",
"protohx": "0.4.6", "protohx": "0.4.6",
"yaml": "1.3.0",
"orm": "2.1.0", "orm": "2.1.0",
"yield": "2.0.0", "haxe-crypto": "0.0.8",
"haxe-crypto": "0.0.7", "svg": "1.1.3",
"svg": "1.1.2" "formatter": "1.16.0"
} },
"haxe": "4.2.5"
} }

View File

@@ -3,6 +3,7 @@
"protoFiles": [ "protoFiles": [
"src/common/proto/core.proto", "src/common/proto/core.proto",
"src/common/proto/game.proto", "src/common/proto/game.proto",
"src/common/proto/room.proto",
"src/common/proto/pack.proto" "src/common/proto/pack.proto"
], ],
"cleanOut": true, "cleanOut": true,

BIN
resources/11756.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
resources/60016.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

7
scripts/build Executable file
View 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

12
scripts/format Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
cd "$(dirname $(dirname "$0"))" || exit
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

13
scripts/lint Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
cd "$(dirname $(dirname "$0"))" || exit
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

32
scripts/publish Executable file
View File

@@ -0,0 +1,32 @@
#!/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+')
curl --user "${PUBLISH_USER}:${PUBLISH_PASSWORD}" -X DELETE \
"${REPO}/generic/${PROJECT}/${VERSION}"
PACKAGES=(
"android/${PROJECT}_${VERSION}.apk"
"debian/${PROJECT}_${VERSION}_all.deb"
"archive/${PROJECT}_${VERSION}_linux.tar.gz"
)
for PACKAGE in "${PACKAGES[@]}"
do
PACKAGE_NAME=$(basename "$PACKAGE")
echo "publish: $PACKAGE"
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
done

5
scripts/setup Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
cd "$(dirname $(dirname "$0"))" || exit
npm ci

View File

@@ -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');

View File

@@ -0,0 +1,44 @@
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
}
}

View File

@@ -1,10 +1,8 @@
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;
@@ -13,35 +11,18 @@ typedef Frame = {
class Animate extends Bitmap { class Animate extends Bitmap {
private static var timer:Timer; public var playing(default, default):Bool;
private static var instances:Array<Animate> = [];
private static function init():Void {
if (timer == null) {
timer = new Timer(30);
timer.run = updateAll;
}
}
private static function updateAll():Void {
for (instance in instances) {
if (instance.playing) {
instance.update();
}
}
}
public var playing(default, set):Bool;
public var frames(default, set):Array<Frame>; public var frames(default, set):Array<Frame>;
private var sequence:Array<BitmapData>; private var sequence:Array<BitmapData>;
private var index:Int; private var index:Int;
@:provide private static var manager:AnimateManager;
public function new(?frames:Array<Frame>) { public function new(?frames:Array<Frame>) {
super(null, PixelSnapping.AUTO, true); super(null, PixelSnapping.AUTO, true);
this.frames = frames == null ? [] : frames; this.frames = frames == null ? [] : frames;
init(); manager.add(this);
instances.push(this);
} }
public function set_frames(value:Array<Frame>):Array<Frame> { public function set_frames(value:Array<Frame>):Array<Frame> {
@@ -59,14 +40,7 @@ class Animate extends Bitmap {
return frames; return frames;
} }
public function set_playing(value:Bool):Bool { public function update():Void {
if (playing != value) {
playing = value;
}
return playing;
}
private function update():Void {
if (++index >= sequence.length) { if (++index >= sequence.length) {
index = 0; index = 0;
} }
@@ -77,8 +51,6 @@ class Animate extends Bitmap {
} }
public function dispose():Void { public function dispose():Void {
if (instances.indexOf(this) > -1) { manager.remove(this);
instances.remove(this);
}
} }
} }

View 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);
}
}
}

View File

@@ -3,7 +3,6 @@ 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>;
@@ -14,13 +13,14 @@ class OnceAnimate extends Animate {
return deferred.promise(); return deferred.promise();
} }
override private function update():Void { override public function update():Void {
super.update(); super.update();
if (index == 0) { if (index == 0) {
playing = false; playing = false;
if (deferred != null) { if (deferred != null) {
deferred.resolve(this); deferred.resolve(this);
} }
dispose();
} }
} }
} }

View File

@@ -0,0 +1,43 @@
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);
}
}
}

View File

@@ -0,0 +1,8 @@
package ru.m.control;
import ru.m.geom.Direction;
enum DeviceAction {
DIRECTION(direction:Direction);
KEY(code:Int);
}

View File

@@ -0,0 +1,8 @@
package ru.m.control;
enum DeviceType {
NONE;
KEYBOARD;
SCREEN;
GAMEPAD(id:Int);
}

View 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;
}

View 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;
}

View File

@@ -0,0 +1,62 @@
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;
}
}
}

View File

@@ -0,0 +1,38 @@
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;
}
}
}

View File

@@ -0,0 +1,22 @@
package ru.m.display;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
class DisplayObjectContainerExtender {
public static function childrenIterator():Iterator<DisplayObject> {
throw "Not implemented";
}
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
if (self.contains(child)) {
return self.removeChild(child);
}
return null;
}
public static function containsRecursivle(child:DisplayObject):Bool {
throw "Not implemented";
}
}

View File

@@ -1,33 +1,42 @@
package ru.m.skin; package ru.m.skin;
import haxework.color.ColorUtil;
import haxework.color.Color;
import haxework.gui.ButtonView;
import format.SVG; import format.SVG;
import haxework.gui.skin.ISkin; import hw.color.Color;
import hw.view.form.ButtonView;
import hw.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 { private inline function buildSVG(color:Color):SVG {
return new SVG(StringTools.replace(svg, "currentColor", '#${StringTools.hex(color)}')); return new SVG(svg.replace("currentColor", '#${color}'));
} }
private function init():Void { private function init(solid:Bool):Void {
svgs = new Map<ButtonState, SVG>(); var color = color;
svgs.set(ButtonState.UP, buildSVG(color)); if (solid) {
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24))); color = color.multiply(1.5);
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24))); }
svgs = new Map();
svgs.set(UP, buildSVG(color));
svgs.set(DOWN, buildSVG(color.diff(-24)));
svgs.set(OVER, buildSVG(color.diff(24)));
svgs.set(DISABLED, buildSVG(color.grey()));
} }
public function draw(view:ButtonView):Void { public function draw(view:ButtonView):Void {
@@ -36,7 +45,10 @@ class ButtonSVGSkin implements ISkin<ButtonView> {
graphics.beginFill(0, 0); graphics.beginFill(0, 0);
graphics.drawRect(0, 0, view.width, view.height); graphics.drawRect(0, 0, view.width, view.height);
graphics.beginFill(color); graphics.beginFill(color);
graphics.lineStyle(2, ColorUtil.multiply(color, 1.5)); if (!solid) {
graphics.lineStyle(2, color.multiply(1.5));
}
// ToDo: padding
svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8)); svg.render(graphics, 0, 0, Std.int(view.width * 0.8), Std.int(view.height * 0.8));
graphics.lineStyle(); graphics.lineStyle();
graphics.endFill(); graphics.endFill();

View File

@@ -0,0 +1,200 @@
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),
]));
}
}

View File

@@ -1,64 +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 ru.m.tankz.frame.StartFrame; import hw.log.TraceLogger;
import flash.ui.Keyboard; import hw.net.manage.LoaderManager;
import flash.events.KeyboardEvent; import hw.view.Root;
import flash.text.Font; import hw.view.popup.PopupManager;
import haxework.gui.frame.FrameSwitcher; import ru.m.tankz.storage.GameStorage;
import haxework.gui.Root; import ru.m.tankz.storage.SettingsStorage;
import haxework.gui.VGroupView; import ru.m.tankz.view.ClientView;
import haxework.log.TraceLogger;
import haxework.provider.Provider;
import haxework.resources.IResources;
#if flash import haxework.log.JSLogger; #end
#if debug import haxework.log.SocketLogger; #end
class Client { class Client {
private static inline var TAG = 'Tankz'; private static inline var TAG = "Tankz";
@:provide private static var settings:SettingsStorage;
public static function main() { public static function main() {
L.push(new TraceLogger()); L.push(new TraceLogger());
#if flash #if flash
L.push(new JSLogger()); L.push(new hw.log.JSLogger());
#end #end
#if debug #if debug
//L.push(new SocketLogger()); //L.push(new hw.log.SocketLogger());
#end #end
// ToDo: fix @:provide macro
PopupManager;
LoaderManager;
GameStorage;
AnimateManager;
//
Const.init(); Const.init();
Init.init(); Init.init();
Animate.bind(Lib.current.stage); // TODO:
// Animate.bind(Lib.current.stage);
L.d(TAG, 'Debug: ${Const.DEBUG}'); L.d(TAG, 'Debug: ${Const.DEBUG}');
L.i(TAG, 'Version: ${Const.VERSION}'); L.i(TAG, 'Version: ${Const.VERSION}');
L.i(TAG, 'Build: ${Const.BUILD}'); L.i(TAG, 'Build: ${Const.BUILD}');
Style.register(); L.i(TAG, 'Mobile: ${Device.isMobile()}');
#if linux
LinuxIcon.apply();
#end
var view:ClientView = new ClientView(); var view:ClientView = new ClientView();
Root.bind(view); Root.bind(view);
view.launch(); view.launch();
}
}
@:template class ClientView extends VGroupView { var fps = new openfl.display.FPS(0, 0, 0x00ff00);
private static inline var TAG = 'Tankz'; fps.visible = settings.displayFPS;
Lib.current.addChild(fps);
@:view private var switcher(default, null):FrameSwitcher; settings.signal.connect(function(setting) {
@:provide var resources:IResources; switch setting {
case DISPLAY_FPS(value):
public function init():Void { fps.visible = value;
var font:Font = Font.enumerateFonts()[0]; case _:
resources.text.put('font', 'Bookman Old Style');
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
Provider.set(FrameSwitcher, switcher);
}
public function launch():Void {
content.stage.stageFocusRect = false;
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
if (event.keyCode == Keyboard.ESCAPE) {
switcher.change(StartFrame.ID);
} }
}); });
switcher.change(StartFrame.ID);
} }
} }

View File

@@ -1,30 +0,0 @@
---
$type: haxework.gui.VGroupView
geometry.size.stretch: true
layout.hAlign: center
layout.vAlign: middle
skinId: light
views:
- id: switcher
$type: haxework.gui.frame.FrameSwitcher
skinId: dark
geometry.size.stretch: true
layout.hAlign: center
layout.vAlign: middle
views:
- id: start
$type: ru.m.tankz.frame.StartFrame
# classic
- id: classic.level
$type: ru.m.tankz.frame.classic.ClassicLevelFrame
- id: classic.game
$type: ru.m.tankz.frame.classic.ClassicGameFrame
# dota
- id: dota.level
$type: ru.m.tankz.frame.dota.DotaLevelFrame
- id: dota.game
$type: ru.m.tankz.frame.dota.DotaGameFrame
# - id: network
# $type: ru.m.tankz.frame.NetworkFrame
- id: settings
$type: ru.m.tankz.frame.SettingsFrame

View File

@@ -3,17 +3,18 @@ package ru.m.tankz;
import flash.Lib; import flash.Lib;
import flash.system.Capabilities; import flash.system.Capabilities;
class Const { class Const {
public static var FPS:Int; public static var FPS:Int;
public static var BUILD:String; public static var BUILD:String;
public static var VERSION:String; public static var VERSION:String;
public static var NAME:String;
public static var DEBUG:Bool; 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");
NAME = Lib.current.stage.application.meta.get("name");
DEBUG = Capabilities.isDebugger; DEBUG = Capabilities.isDebugger;
} }
} }

View File

@@ -1,66 +1,78 @@
package ru.m.tankz; package ru.m.tankz;
import ru.m.tankz.storage.SettingsStorage; import flash.Lib;
import haxework.provider.Provider; import hw.animate.FadeAnimate;
import haxework.resources.IResources; import hw.animate.UnFadeAnimate;
import haxework.resources.Resources; import hw.storage.SharedObjectStorage;
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.control.ClientControlFactory;
import ru.m.tankz.control.IControlFactory;
import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.proto.pack.Request; import ru.m.tankz.proto.pack.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.SaveStorage;
import ru.m.tankz.storage.UserStorage;
#if flash
import flash.Lib;
#elseif html5
import js.Browser;
#end
class Init { class Init {
private static function getHost():String { @: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;
private static function buildConnection():IConnection<Request, Response> {
var host:String = CompilationOption.get("host");
var port:Int = CompilationOption.get("port");
L.d("Init", 'connect to $host:$port');
#if flash #if flash
var url = Lib.current.loaderInfo.url; return new ru.m.connect.flash.FlashConnection<Request, Response>(host, port, Response);
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
if (r.match(url) && !(r.matched(1) == "app")) {
return r.matched(2);
} else {
return "localhost";
}
#elseif html5 #elseif html5
return Browser.location.hostname; return new ru.m.connect.js.JsConnection<Request, Response>(host, port + (ru.m.connect.js.JsConnection.isSecured() ? 1 : 0), Response);
#else #else
return "localhost"; return new ru.m.connect.desktop.DesktopConnection<Request, Response>(host, port, Response);
#end #end
} }
public static function init():Void { public static function init():Void {
Provider.setFactory(IResources, Resources); theme = new AppTheme();
Provider.setFactory(ILevelBundle, LevelBundle); levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
Provider.setFactory(IConfigBundle, ConfigBundle); levelBundle.load();
Provider.setFactory(SaveStorage, SaveStorage); configBundle = new ConfigBundle();
Provider.setFactory(UserStorage, UserStorage);
Provider.setFactory(SettingsStorage, SettingsStorage);
Provider.setFactory(SoundManager, SoundManager);
Provider.setFactory(NetworkManager, NetworkManager);
Provider.setFactory(IControlFactory, ClientControlFactory);
var host:String = getHost(); popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
L.d('Init', 'host: ${host}'); popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
#if flash
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection<Request, Response>(host, 5000, Response)); connection = buildConnection();
#elseif html5
Provider.set(IConnection, new ru.m.connect.js.JsConnection<Request, Response>(host, 5000, Response)); bus = new ControlBus();
#else bus.connect(new KeyboardDevice(Lib.current.stage));
Provider.set(IConnection, new ru.m.connect.fake.FakeConnection<Request, Response>(Response));
#end updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
for (device in Gamepad.devices) {
trace('gamepad', device);
}
Gamepad.onConnect.add(function(device) {
trace('connect gamepad', device);
});
for (device in Joystick.devices) {
bus.connect(new JoystickDevice(device));
}
Joystick.onConnect.add(function(device) {
bus.connect(new JoystickDevice(device));
});
} }
} }

View File

@@ -0,0 +1,27 @@
package ru.m.tankz;
import flash.display.BitmapData;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
import flash.Lib;
import openfl.Assets;
class LinuxIcon {
private static function prepareIcon(bitmap:BitmapData):BitmapData {
var matrix:Array<Float> = [];
matrix = matrix.concat([0, 0, 1, 0, 0]);
matrix = matrix.concat([0, 1, 0, 0, 0]);
matrix = matrix.concat([1, 0, 0, 0, 0]);
matrix = matrix.concat([0, 0, 0, 1, 0]);
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
var bitmap:BitmapData = bitmap.clone();
bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf);
return bitmap;
}
public static function apply() {
var icon = Assets.getBitmapData("resources/icon.png");
Lib.current.stage.window.setIcon(prepareIcon(icon).image);
}
}

View File

@@ -0,0 +1,142 @@
package ru.m.tankz;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.Lib;
import hw.view.geometry.Size;
import ru.m.tankz.AppTheme;
class Progress extends Sprite {
public var color(default, set):Int = 0;
public var backColor(default, set):Int = 0;
public var progress(default, set):Float = 0;
public var size(default, set):Size = [0, 0];
public var radius(get, null):Float;
private var maskShape:Shape;
private var toRedraw:Bool;
public function new() {
super();
maskShape = new Shape();
addChild(maskShape);
mask = maskShape;
}
private inline function get_radius():Float {
return Math.min(size.width, size.height) / 2;
}
private function set_color(value:Int):Int {
if (color != value) {
color = value;
toRedraw = true;
}
return color;
}
private function set_backColor(value:Int):Int {
if (backColor != value) {
backColor = value;
toRedraw = true;
}
return color;
}
private function set_progress(value:Float):Float {
if (progress != value) {
progress = value;
toRedraw = true;
}
return progress;
}
private function set_size(value:Size):Size {
if (size != value) {
size = value;
toRedraw = true;
}
return size;
}
public function update():Void {
if (toRedraw) {
redraw();
redrawMask();
toRedraw = false;
}
}
public function redraw():Void {
graphics.clear();
graphics.beginFill(color);
graphics.drawCircle(radius, radius, radius);
graphics.beginFill(backColor);
graphics.drawCircle(radius, radius, radius / 2);
graphics.endFill();
}
public function redrawMask():Void {
maskShape.graphics.clear();
maskShape.graphics.beginFill(0x00ff00);
maskShape.graphics.moveTo(radius, radius);
var sides = 6;
var rotation = (-(Math.PI) / 2);
var r = radius / Math.cos(1/sides * Math.PI);
var lineToRadians = function(rads:Float):Void {
maskShape.graphics.lineTo(Math.cos(rads) * r + radius, Math.sin(rads) * r + radius);
};
var sidesToDraw:Int = Math.floor(progress * sides);
for (i in 0...sidesToDraw + 1) {
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
}
if (progress * sides != sidesToDraw) {
lineToRadians(progress * (Math.PI * 2) + rotation);
}
maskShape.graphics.endFill();
}
}
class Preloader extends Sprite {
private var progress:Progress;
public function new() {
super();
Lib.current.stage.color = AppTheme.COLORS.light;
progress = new Progress();
progress.color = AppTheme.COLORS.dark;
progress.backColor = AppTheme.COLORS.light;
progress.size = [200, 200];
addChild(progress);
onResize(null);
Lib.current.stage.addEventListener(Event.RESIZE, onResize);
Lib.current.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
Lib.current.stage.addEventListener(ProgressEvent.PROGRESS, onProgress);
addEventListener(Event.COMPLETE, onComplete);
}
private function onResize(event:Event):Void {
progress.x = (Lib.current.stage.stageWidth - progress.size.width) / 2;
progress.y = (Lib.current.stage.stageHeight - progress.size.height) / 2;
}
private function onEnterFrame(event:Event):Void {
progress.update();
}
private function onProgress(event:ProgressEvent):Void {
progress.progress = event.bytesLoaded / event.bytesTotal;
}
private function onComplete(event:Event):Void {
progress.update();
Lib.current.stage.removeEventListener(Event.RESIZE, onResize);
Lib.current.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
Lib.current.stage.removeEventListener(ProgressEvent.PROGRESS, onProgress);
removeEventListener(Event.COMPLETE, onComplete);
}
}

View File

@@ -1,63 +0,0 @@
package ru.m.tankz;
import haxework.color.ColorUtil;
import haxework.gui.skin.Skin;
import haxework.resources.IResources;
import openfl.Assets;
import ru.m.skin.ButtonSVGSkin;
class Style {
@:provide private static var resources:IResources;
private static var lightColor = 0x95937D;
private static var darkColor = 0x777564;
private static var textColor = 0xE7E0BB;
private static var fontFamily = "Courirer New";
public static function register() {
resources.skin.put("light", [Skin.color(lightColor)]);
resources.skin.put("dark", [Skin.color(darkColor)]);
resources.skin.put("text", [Skin.text(textColor, 16, fontFamily)]);
resources.skin.put("button", [
Skin.buttonColor(lightColor),
Skin.text(textColor, 18, fontFamily),
Skin.size(250, 50)
]);
resources.skin.put("text.box", [
Skin.color(lightColor),
Skin.text(textColor, 16, fontFamily),
]);
resources.skin.put("text.box.active", [
Skin.color(0x55aa55),
Skin.text(textColor, 16, fontFamily),
]);
resources.skin.put("button.simple", [
Skin.buttonColor(lightColor),
Skin.text(textColor, 16, fontFamily),
Skin.size(100, 38),
]);
resources.skin.put("button.tab", [
Skin.tabColor(lightColor),
Skin.text(textColor, 16, fontFamily),
Skin.size(200, 38),
]);
resources.skin.put("border", [
Skin.border(ColorUtil.multiply(lightColor, 1.5), 1, 2),
]);
resources.skin.put("button.level", [
Skin.buttonColor(lightColor),
Skin.text(textColor, 24, fontFamily),
Skin.size(64, 64),
]);
resources.skin.put("button.settings", [
Skin.size(64, 64),
new ButtonSVGSkin(Assets.getText("resources/image/icon/cog-solid.svg"), lightColor)
]);
resources.skin.put("button.close", [
Skin.size(64, 64),
new ButtonSVGSkin(Assets.getText("resources/image/icon/times-circle-solid.svg"), lightColor)
]);
}
}

View File

@@ -0,0 +1,33 @@
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;
}
}

View File

@@ -7,15 +7,16 @@ import ru.m.tankz.Type;
import yaml.Parser; 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 get(type:GameType):Config { public function get(type:GameType):Config {
if (!_cache.exists(type)) { if (!_cache.exists(type)) {
var source:ConfigSource = Yaml.parse(Assets.getText('resources/${type}/config.yaml'), Parser.options().useObjects()); var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
_cache.set(type, new Config(type, source.game, source.map, source.bricks, source.presets, source.points, source.tanks, source.bonuses)); _cache.set(type, Config.fromSource(type, source));
} }
return _cache.get(type); return _cache.get(type);
} }

View File

@@ -1,15 +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 {
public function get(type:GameType, config:Config, level:Int):LevelConfig {
var data:String = Assets.getText('resources/${type}/levels/level${LevelUtil.formatLevel(level)}.txt');
return LevelUtil.loads(config, data);
}
}

View File

@@ -1,41 +0,0 @@
package ru.m.tankz.control;
import haxe.Serializer;
import haxe.Unserializer;
import ru.m.tankz.control.Control.TankAction;
typedef ActionItem = {
public var action:TankAction;
public var key:Int;
}
typedef KeyBinding = Map<Int, TankAction>;
class ActionConfig {
public var data(default, null):Array<ActionItem>;
public function new(data:Array<ActionItem>) {
this.data = data;
}
public function asKeyBinding():KeyBinding {
var result = new Map<Int, TankAction>();
for (item in data) {
result[item.key] = item.action;
}
return result;
}
public function clone():ActionConfig {
return loads(dumps());
}
public function dumps():String {
return Serializer.run(this);
}
public static function loads(value:String):ActionConfig {
return new Unserializer(value).unserialize();
}
}

View 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>;

View File

@@ -1,23 +0,0 @@
package ru.m.tankz.control;
import ru.m.tankz.Type;
import ru.m.tankz.bot.BotControl;
class ClientControlFactory implements IControlFactory {
private var humanControlIndex:Int;
public function new() {
humanControlIndex = 0;
}
public function build(id:PlayerId, type:ControlType):Control {
return switch (type) {
case Control.HUMAN: new HumanControl(id, humanControlIndex++);
case Control.BOT: new BotControl(id);
case Control.NONE: null;
case _: throw 'Unsupported control type: "${type}"';
}
}
}

View File

@@ -1,64 +1,99 @@
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 var settings: SettingsStorage; @:provide static var storage:SettingsStorage;
@:provide static var bus:IControlBus;
private var keyBinding:KeyBinding; private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
private var moveQueue:Array<Int>;
private var shotTimer:Timer; private var moveQueue:Array<Direction>;
private var shotTimers:Map<Int, Timer>;
public function new(playerId:PlayerId, controlIndex:Int) { public function new(playerId:PlayerId, controlIndex:Int) {
super(playerId); super(playerId);
this.keyBinding = settings.read(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;
} }
if (event.keyCode == Keyboard.U) {
action(TankAction.UPGRADE); private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
if (binding.exists(device) && binding[device].exists(action)) {
toggleAction(binding[device][action], on);
} }
} }
private function onKeyUp(event:KeyboardEvent):Void { override public function start():Void {
if (keyBinding.exists(event.keyCode)) switch (keyBinding.get(event.keyCode)) { super.start();
case TankAction.MOVE(direction): bus.signal.connect(onDeviceAction);
moveQueue.remove(event.keyCode);
updateMove();
case TankAction.SHOT:
if (shotTimer != null) {
shotTimer.stop();
shotTimer = null;
} }
case _:
override public function stop():Void {
super.stop();
bus.signal.disconnect(onDeviceAction);
moveQueue = [];
for (timer in shotTimers) {
timer.stop();
}
shotTimers = new Map();
}
public function toggleAction(action:TankAction, on:Bool):Void {
switch action {
case TankAction.MOVE(direction):
if (on) {
if (moveQueue.indexOf(direction) == -1) {
moveQueue.unshift(direction);
}
} else {
moveQueue.remove(direction);
}
updateMove();
case TankAction.SHOT(weapon):
if (on) {
if (!shotTimers.exists(weapon)) {
// 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:
} }
} }
@@ -69,17 +104,15 @@ class HumanControl extends Control {
private function updateMove():Void { private function updateMove():Void {
if (moveQueue.length == 0) { if (moveQueue.length == 0) {
action(TankAction.STOP); action(STOP);
} else { } else {
switch (keyBinding.get(moveQueue[0])) { action(MOVE(moveQueue[0]));
case TankAction.MOVE(direction):
action(TankAction.MOVE(direction));
case _:
}
} }
} }
private function shot():Void { private function shooter(weapon:Int):Void -> Void {
action(TankAction.SHOT); return function():Void {
action(SHOT(weapon));
}
} }
} }

View File

@@ -1,108 +0,0 @@
package ru.m.tankz.frame;
import haxework.gui.ButtonView;
import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.IGroupView;
import haxework.gui.InputView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import haxework.gui.VGroupView;
import haxework.provider.Provider;
import ru.m.tankz.game.GameState;
import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.preset.ClassicGame;
import ru.m.tankz.proto.core.GameInfoProto;
import ru.m.tankz.proto.core.GameStateProto;
import ru.m.tankz.proto.core.UserProto;
@:template class NetworkFrame extends VGroupView {
public static var ID(default, never):String = "network";
@:view var frameSwitcher(default, null):IFrameSwitcher;
@:view var loginFrame(default, null):IGroupView;
@:view var stateLabel(default, null):LabelView;
@:view var nameInput(default, null):InputView;
@:view var loginButton(default, null):ButtonView;
@:view var gameListFrame(default, null):IGroupView;
@:view var createGameButton(default, null):ButtonView;
@:view var gameList(default, null):ListView<GameInfoProto>;
@:view var gameFrame(default, null):IGroupView;
@:view var leaveGameButton(default, null):ButtonView;
@:view var startGameButton(default, null):ButtonView;
@:view var userList(default, null):ListView<UserProto>;
@:provide var network:NetworkManager;
@:provide var mainFrameSwitcher:IFrameSwitcher;
public function init():Void {
loginButton.onPress = this;
createGameButton.onPress = this;
leaveGameButton.onPress = this;
startGameButton.onPress = this;
gameList.dispatcher.addListener({
onListItemClick: function(item:IListItemView<GameInfoProto>):Void {
network.joinGame(item.data.id);
}
});
}
public function onShow():Void {
nameInput.text = network.user.name;
onStateChange(network.state);
network.stateSignal.connect(onStateChange);
}
private function onStateChange(state:String):Void {
loginButton.disabled = !(state == "offline" || state == "error");
stateLabel.text = state;
if (state == 'online') {
gameList.data = [];
frameSwitcher.change(gameListFrame.id);
network.listGameSignal.connect(onListGame);
network.gameSignal.connect(onGame);
network.listGame();
} else {
frameSwitcher.change(loginFrame.id);
}
}
private function onListGame(games:Array<GameInfoProto>):Void {
gameList.data = games;
}
private function onGame(game:GameInfoProto):Void {
if (game != null) {
userList.data = game.players;
frameSwitcher.change(gameFrame.id);
if (game.state == GameStateProto.STARTED) {
Provider.set(GameState, new GameState(ClassicGame.TYPE, ClassicGame.PLAYER1));
mainFrameSwitcher.change(GameFrame.ID);
}
} else {
frameSwitcher.change(gameListFrame.id);
}
}
public function onHide():Void {
network.listGameSignal.disconnect(onListGame);
network.gameSignal.disconnect(onGame);
network.stateSignal.disconnect(onStateChange);
}
public function onPress(view:ButtonView):Void {
switch (view.id) {
case 'loginButton':
network.login(nameInput.text);
case 'createGameButton':
network.createGame('classic');
case 'leaveGameButton':
network.leaveGame();
case 'startGameButton':
network.startGame();
}
}
}

View File

@@ -1,90 +0,0 @@
---
pWidth: 100
pHeight: 100
views:
- id: frameSwitcher
$type: haxework.gui.frame.FrameSwitcher
pWidth: 100
pHeight: 100
views:
# login
- id: loginFrame
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
views:
- id: stateLabel
$type: haxework.gui.LabelView
$style: label
text: offline
width: 200
height: 50
- id: nameInput
$type: haxework.gui.InputView
$style: label
width: 200
height: 50
text: User
skin:
$type: haxework.gui.skin.ColorSkin
color: '#444444'
- id: loginButton
$type: haxework.gui.ButtonView
$style: button
text: Login
# game list
- id: gameListFrame
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
views:
- id: createGameButton
$type: haxework.gui.ButtonView
$style: button
text: Create
- id: gameList
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.GameInfoProto>
factory: "@class:ru.m.tankz.frame.network.GameItemView"
pWidth: 100
pHeight: 100
paddings: 10
scroll:
$type: haxework.gui.list.VScrollView
width: 10
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0
# game
- id: gameFrame
$type: haxework.gui.VGroupView
pWidth: 100
pHeight: 100
views:
- id: startGameButton
$type: haxework.gui.ButtonView
$style: button
text: Start
- id: leaveGameButton
$type: haxework.gui.ButtonView
$style: button
text: Leave
- id: userList
$type: haxework.gui.list.VListView<ru.m.tankz.proto.core.UserProto>
factory: "@class:ru.m.tankz.frame.network.UserItemView"
pWidth: 100
pHeight: 100
paddings: 10
scroll:
$type: haxework.gui.list.VScrollView
width: 10
pHeight: 100
skin:
$type: haxework.gui.list.VScrollSkin
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0

View File

@@ -1,18 +0,0 @@
package ru.m.tankz.frame;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.ButtonView;
import haxework.gui.VGroupView;
@:template class SettingsFrame extends VGroupView {
public static var ID(default, never):String = "settings";
@:provide var frameSwitcher:FrameSwitcher;
@:view var close:ButtonView;
public function onPress(_):Void {
frameSwitcher.change(StartFrame.ID);
}
}

View File

@@ -1,29 +0,0 @@
---
geometry.size.stretch: true
layout.hAlign: center
layout.vAlign: middle
views:
- $type: haxework.gui.LabelView
skinId: text
geometry.size.fixed.height: 20
text: Settings
- $type: haxework.gui.HGroupView
geometry.size.width: 100%
views:
- $type: ru.m.tankz.frame.settings.SettingsEditor
geometry.size.percent.width: 50
#geometry.size.percent.height: 100
controlIndex: 0
- $type: ru.m.tankz.frame.settings.SettingsEditor
geometry.size.percent.width: 50
#geometry.size.percent.height: 100
controlIndex: 1
- id: close
$type: haxework.gui.ButtonView
skinId: button.close
+onPress: $this:onPress
geometry.position: absolute
geometry.margin.left: 10
geometry.margin.bottom: 10
geometry.vAlign: bottom
geometry.hAlign: left

View File

@@ -1,29 +0,0 @@
package ru.m.tankz.frame;
import ru.m.tankz.frame.classic.ClassicLevelFrame;
import ru.m.tankz.frame.dota.DotaLevelFrame;
import haxework.gui.ButtonView;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.VGroupView;
import ru.m.tankz.storage.SaveStorage;
@:template class StartFrame extends VGroupView {
public static var ID(default, never):String = "start";
@:provide var frameSwitcher:FrameSwitcher;
@:provide var storage:SaveStorage;
public function onPress(view:ButtonView):Void {
switch (view.id) {
case 'classic':
frameSwitcher.change(ClassicLevelFrame.ID);
case 'dota':
frameSwitcher.change(DotaLevelFrame.ID);
case 'network':
//frameSwitcher.change(NetworkFrame.ID);
case 'settings':
frameSwitcher.change(SettingsFrame.ID);
}
}
}

View File

@@ -1,45 +0,0 @@
---
geometry.size.stretch: true
layout.hAlign: center
layout.vAlign: middle
views:
- $type: haxework.gui.ImageView
image: $asset:image:resources/image/ui/logo.png
geometry.margin.bottom: 15
- $type: haxework.gui.VGroupView
layout.margin: 3
views:
- id: classic
$type: haxework.gui.ButtonView
skinId: button
+onPress: $this:onPress
text: Classic
- id: dota
$type: haxework.gui.ButtonView
skinId: button
+onPress: $this:onPress
text: DotA
- id: network
$type: haxework.gui.ButtonView
skinId: button
+onPress: $this:onPress
text: Network (in developing)
fontColor: 0xff0000
visible: false
- $type: haxework.gui.LabelView
skinId: text
geometry.position: absolute
geometry.margin.right: 10
geometry.margin.bottom: 10
geometry.vAlign: bottom
geometry.hAlign: right
text: $r:text:version
- id: settings
$type: haxework.gui.ButtonView
geometry.position: absolute
geometry.margin.left: 10
geometry.margin.bottom: 10
geometry.vAlign: bottom
geometry.hAlign: left
skinId: button.settings
+onPress: $this:onPress

View File

@@ -1,20 +0,0 @@
package ru.m.tankz.frame.classic;
import ru.m.tankz.frame.common.IGamePanel;
import ru.m.tankz.render.Render;
import ru.m.tankz.frame.common.GameFrame;
@:template class ClassicGameFrame extends GameFrame {
public static inline var ID = "classic.game";
@:view("render") private var renderView(default, null):Render;
@:view("panel") private var panelView(default, null):IGamePanel;
override private function get_render():Render {
return renderView;
}
override private function get_panel():IGamePanel {
return panelView;
}
}

View File

@@ -1,11 +0,0 @@
---
layout:
$type: haxework.gui.layout.HorizontalLayout
margin: 5
hAlign: center
vAlign: middle
views:
- id: render
$type: ru.m.tankz.render.Render
- id: panel
$type: ru.m.tankz.frame.classic.ClassicGamePanel

View File

@@ -1,33 +0,0 @@
package ru.m.tankz.frame.classic;
import haxework.gui.VGroupView;
import ru.m.tankz.frame.common.IGamePanel;
import ru.m.tankz.frame.common.LifeView;
import ru.m.tankz.game.Game;
import ru.m.tankz.preset.ClassicGame;
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
@:view var bot:LifeView;
@:view var player1:LifeView;
@:view var player2:LifeView;
public var game:Game;
private function updateViews():Void {
bot.count.text = '${game.teams[ClassicGame.BOT].life}';
player1.count.text = '${game.teams[ClassicGame.HUMAN].players[0].state.life}';
if (game.teams[ClassicGame.HUMAN].players[1] != null) {
player2.count.text = '${game.teams[ClassicGame.HUMAN].players[1].state.life}';
} else {
player2.count.text = "";
}
}
override public function update():Void {
if (game != null) {
updateViews();
}
super.update();
}
}

View File

@@ -1,16 +0,0 @@
---
geometry.padding: 5
layout.margin: 5
layout.hAlign: right
views:
- id: bot
$type: ru.m.tankz.frame.common.LifeView
image.image: $asset:image:resources/image/tank/ba-0.png
- id: player1
$type: ru.m.tankz.frame.common.LifeView
image.image: $asset:image:resources/image/tank/pa-0.png
image.color: 0xFFFF00
- id: player2
$type: ru.m.tankz.frame.common.LifeView
image.image: $asset:image:resources/image/tank/pa-0.png
image.color: 0x15C040

View File

@@ -1,51 +0,0 @@
package ru.m.tankz.frame.classic;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.DataView;
import haxework.gui.ToggleButtonView;
import ru.m.tankz.config.Config;
import ru.m.tankz.frame.common.LevelFrame;
import ru.m.tankz.preset.ClassicGame;
@:template class ClassicLevelFrame extends LevelFrame {
public static inline var ID = "classic.level";
@:view var presets(default, null):DataView<GamePreset>;
@:view var levels(default, null):DataView<Int>;
@:provide var frames:FrameSwitcher;
private function onShow():Void {
gameType = ClassicGame.TYPE;
levels.data = [for (i in 0...config.game.levels) i];
presets.data = config.presets;
setSelectedPreset(preset);
}
private function setSelectedPreset(preset:GamePreset) {
for (view in presets.views) {
cast(view, ToggleButtonView).on = view.id == preset.id;
}
}
private function presetViewFactory(index:Int, preset:GamePreset):ToggleButtonView {
var view = new ToggleButtonView();
view.id = preset.id;
view.text = '${preset.id}';
resources.skin.bind("button.simple", view, "skin");
return view;
}
override private function set_preset(value:GamePreset):GamePreset {
var result = super.set_preset(value);
setSelectedPreset(result);
return result;
}
override private function set_level(value:Int):Int {
var result = super.set_level(value);
frames.change(ClassicGameFrame.ID);
return result;
}
}

View File

@@ -1,23 +0,0 @@
---
layout:
$type: haxework.gui.layout.VerticalLayout
hAlign: center
views:
- id: presets
$type: haxework.gui.DataView<GamePreset>
layout:
$type: haxework.gui.layout.HorizontalLayout
hAlign: center
margin: 2
factory: $this:presetViewFactory
+onDataSelect: $code:function(value) preset = value
geometry.padding: 10
- id: levels
$type: haxework.gui.DataView<Int>
layout:
$type: haxework.gui.layout.TailLayout
rowSize: 10
margin: 5
factory: $this:levelViewFactory
+onDataSelect: $code:function(value) level = value
geometry.padding: 10

View File

@@ -1,104 +0,0 @@
package ru.m.tankz.frame.common;
import flash.events.Event;
import haxe.ds.Option;
import haxe.Timer;
import haxework.gui.frame.FrameSwitcher;
import haxework.gui.GroupView;
import ru.m.tankz.frame.common.IGamePanel;
import ru.m.tankz.game.Game;
import ru.m.tankz.game.GameState;
import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.render.Render;
import ru.m.tankz.sound.SoundManager;
import ru.m.tankz.storage.SaveStorage;
class GameFrame extends GroupView {
private static inline var TAG = "GameFrame";
private var render(get, null):Render;
private var panel(get, null):IGamePanel;
@:provide var network:NetworkManager;
@:provide var sound:SoundManager;
@:provide var state:GameState;
@:provide var storage:SaveStorage;
@:provide var switcher:FrameSwitcher;
private var game:Game;
private var timer:Timer;
private function get_render():Render {
throw "Not implemented";
}
private function get_panel():IGamePanel {
throw "Not implemented";
}
public function onShow():Void {
start(state);
}
private function start(state:GameState):Void {
game = new Game(state.type);
game.engine.connect(render);
game.engine.connect(sound);
game.start(state).then(onGameStateChange).endThen(onGameComplete);
timer = new Timer(10);
timer.run = updateEngine;
panel.game = game;
content.addEventListener(Event.ENTER_FRAME, _redraw);
render.draw(game.engine);
sound.play('start');
}
private function stop():Void {
if (timer != null) {
timer.stop();
timer = null;
}
content.removeEventListener(Event.ENTER_FRAME, _redraw);
if (game != null) {
game.dispose();
game = null;
}
render.reset();
}
private function onGameStateChange(s:GameState):GameState {
panel.toUpdate();
return s;
}
private function onGameComplete(result:Option<GameState>):Void {
switch (result) {
case Option.Some(s):
panel.toUpdate();
case Option.None:
}
switch (game.next()) {
case Option.Some(s):
var state = game.save();
this.state = state;
storage.write(state);
stop();
start(state);
case Option.None:
switcher.change(StartFrame.ID);
}
}
public function onHide():Void {
stop();
}
private function updateEngine():Void {
game.engine.update();
}
private function _redraw(_):Void {
render.draw(game.engine);
}
}

View File

@@ -1,8 +0,0 @@
package ru.m.tankz.frame.common;
import ru.m.tankz.game.Game;
import haxework.gui.IView;
interface IGamePanel extends IView<Dynamic> {
public var game:Game;
}

View File

@@ -1,59 +0,0 @@
package ru.m.tankz.frame.common;
import haxework.gui.ButtonView;
import haxework.gui.GroupView;
import haxework.resources.IResources;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.config.Config;
import ru.m.tankz.control.Control;
import ru.m.tankz.game.GameState;
import ru.m.tankz.storage.SaveStorage;
import ru.m.tankz.Type;
class LevelFrame extends GroupView {
public var gameType(default, set):GameType;
public var preset(default, set):GamePreset;
public var level(default, set):Int;
private var config(default, null):Config;
@:provide var configBundle:IConfigBundle;
@:provide var state:GameState;
@:provide var storage:SaveStorage;
@:provide var resources:IResources;
private function set_gameType(value:GameType):GameType {
if (gameType != value) {
gameType = value;
config = configBundle.get(gameType);
preset = config.presets[0];
}
return gameType;
}
private function set_preset(value:GamePreset):GamePreset {
if (preset != value) {
preset = value;
state = new GameState(gameType, preset.id);
for (team in value.teams) {
for (player in team.players) {
var playerId = new PlayerId(team.id, player.index);
state.control.set(playerId, player.control != null ? player.control : Control.BOT);
}
}
}
return preset;
}
private function set_level(value:Int):Int {
state.level = value;
return state.level;
}
private function levelViewFactory(index:Int, level:Int):ButtonView {
var view = new ButtonView();
view.text = '${level}';
resources.skin.bind("button.level", view, "skin");
return view;
}
}

View File

@@ -1,20 +0,0 @@
package ru.m.tankz.frame.common;
import haxework.gui.HGroupView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView.IListItemView;
@:template class LevelView extends HGroupView implements IListItemView<Int> {
public var item_index(default, default):Int;
public var data(default, set):Int;
@:view var label(default, null):LabelView;
private function set_data(value:Int):Int {
data = value;
label.text = 'Level ${data}';
return data;
}
}

View File

@@ -1,14 +0,0 @@
---
geometry.size.width: 100%
geometry.size.height: 44
geometry.margin: 5
views:
- id: label
$type: haxework.gui.LabelView
skinId: text
geometry.size.stretch: true
text: ""
skin:
- $type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.2

View File

@@ -1,10 +0,0 @@
package ru.m.tankz.frame.common;
import haxework.gui.LabelView;
import haxework.gui.ImageView;
import haxework.gui.HGroupView;
@:template class LifeView extends HGroupView {
@:view public var image:ImageView;
@:view public var count:LabelView;
}

View File

@@ -1,9 +0,0 @@
---
layout.margin: 5
views:
- id: image
$type: haxework.gui.ImageView
- id: count
$type: haxework.gui.LabelView
skinId: text.box
geometry.size.fixed: [50, 38]

View File

@@ -1,65 +0,0 @@
package ru.m.tankz.frame.common;
import haxework.color.Color;
import haxework.gui.ButtonView;
import haxework.gui.HGroupView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import haxework.gui.skin.Skin;
import openfl.Assets;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.control.Control;
import ru.m.tankz.game.GameState;
import ru.m.tankz.Type;
@:template class PlayerView extends HGroupView implements IListItemView<PlayerId> {
public var item_index(default, default):Int;
public var data(default, set):PlayerId;
@:view("index") var indexLabel(default, null):LabelView;
@:view var control(default, null):ButtonView;
@:provide var state:GameState;
@:provide var configBundle:IConfigBundle;
private function set_data(value:PlayerId):PlayerId {
data = value;
indexLabel.text = '${value.team} ${Std.string(data.index + 1)}';
var color = 0xffffff;
var config = configBundle.get(state.type);
var preset = config.getPreset(state.presetId);
for (team in preset.teams) {
if (team.id == data.team) {
color = team.color;
for (player in team.players) {
if (player.index == data.index) {
if (!player.color.zero) {
color = player.color;
}
break;
}
}
preset.teams;
}
}
indexLabel.fontColor = color;
var controlType = state.control.get(value);
var image = Assets.getBitmapData('resources/image/ui/control/${controlType}.png');
control.skin = [Skin.buttonBitmap(image)];
indexLabel.update();
return data;
}
public function toggleControl():Void {
if (data != null && data.index > -1) {
var controlType = switch state.control.get(data) {
case Control.BOT: Control.HUMAN;
case Control.HUMAN: Control.BOT;
case _: Control.BOT;
}
state.control.set(data, controlType);
this.data = data;
}
}
}

View File

@@ -1,18 +0,0 @@
---
geometry.size.width: 200
geometry.size.height: 44
geometry.margin: 5
layout.margin: 10
views:
- id: index
$type: haxework.gui.LabelView
geometry.size.stretch: true
skin:
- $type: haxework.gui.skin.ColorSkin
color: 0x000000
alpha: 0.2
shadow: true
shadowColor: 0x000000
- id: control
$type: haxework.gui.ButtonView
+onPress: $code:toggleControl()

View File

@@ -1,21 +0,0 @@
package ru.m.tankz.frame.dota;
import ru.m.tankz.frame.common.GameFrame;
import ru.m.tankz.frame.common.IGamePanel;
import ru.m.tankz.render.Render;
@:template class DotaGameFrame extends GameFrame {
public static inline var ID = "dota.game";
@:view("render") private var renderView(default, null):Render;
@:view("panel") private var panelView(default, null):IGamePanel;
override private function get_render():Render {
return renderView;
}
override private function get_panel():IGamePanel {
return panelView;
}
}

View File

@@ -1,9 +0,0 @@
---
layout:
$type: haxework.gui.layout.VerticalLayout
margin: 5
views:
- id: panel
$type: ru.m.tankz.frame.dota.DotaGamePanel
- id: render
$type: ru.m.tankz.render.Render

View File

@@ -1,49 +0,0 @@
package ru.m.tankz.frame.dota;
import ru.m.tankz.preset.DotaGame;
import ru.m.tankz.frame.common.LifeView;
import ru.m.tankz.frame.common.IGamePanel;
import haxework.gui.HGroupView;
import ru.m.tankz.game.Game;
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
@:view var radiant:LifeView;
@:view var dire:LifeView;
public var game:Game;
private function stateString(game:Game):String {
if (game == null) {
return '';
}
var result:Array<String> = [];
result.push('Level: ${game.state.level}');
for (team in game.teams) {
if (game.loser == team.id) {
result.push('${team.id}: LOSE');
} else if (team.life > 0) {
result.push('${team.id}: ${team.life}');
} else {
for (player in team.players) {
if (player.state.life > 0) {
result.push('${player.id.team}${player.id.index}: ${player.state.life}');
}
}
}
}
return '[ ${result.join(' | ')} ]';
}
private function updateViews():Void {
radiant.count.text = '${game.teams[DotaGame.RADIANT].life}';
dire.count.text = '${game.teams[DotaGame.DIRE].life}';
}
override public function update():Void {
if (game != null) {
updateViews();
}
super.update();
}
}

View File

@@ -1,14 +0,0 @@
---
geometry.size.width: 100%
layout.margin: 20
views:
- id: radiant
$type: ru.m.tankz.frame.common.LifeView
image.image: $asset:image:resources/image/tank/bc-0.png
image.color: 0xff4422
- $type: haxework.gui.SpriteView
geometry.size.width: 100%
- id: dire
$type: ru.m.tankz.frame.common.LifeView
image.image: $asset:image:resources/image/tank/bc-0.png
image.color: 0x3284ff

View File

@@ -1,42 +0,0 @@
package ru.m.tankz.frame.dota;
import haxework.gui.DataView;
import haxework.gui.frame.FrameSwitcher;
import ru.m.tankz.frame.common.LevelFrame;
import ru.m.tankz.frame.common.PlayerView;
import ru.m.tankz.preset.DotaGame;
import ru.m.tankz.Type;
@:template class DotaLevelFrame extends LevelFrame {
public static inline var ID = "dota.level";
@:view var levels(default, null):DataView<Int>;
@:view var players(default, null):DataView<PlayerId>;
@:provide var frames:FrameSwitcher;
private function onShow():Void {
gameType = DotaGame.TYPE;
levels.data = [for (i in 0...config.game.levels) i];
var data = [];
for (team in preset.teams) {
for (p in team.players) {
data.push(new PlayerId(team.id, p.index));
}
}
players.data = data;
}
private function playerViewFactory(index:Int, player:PlayerId):PlayerView {
var view = new PlayerView();
view.item_index = index;
view.data = player;
return view;
}
override private function set_level(value:Int):Int {
var result = super.set_level(value);
frames.change(DotaGameFrame.ID);
return result;
}
}

View File

@@ -1,20 +0,0 @@
---
layout:
$type: haxework.gui.layout.HorizontalLayout
views:
- id: players
$type: haxework.gui.DataView<PlayerId>
layout:
$type: haxework.gui.layout.VerticalLayout
hAlign: center
factory: $this:playerViewFactory
geometry.padding: 10
- id: levels
$type: haxework.gui.DataView<Int>
layout:
$type: haxework.gui.layout.TailLayout
rowSize: 5
margin: 5
factory: $this:levelViewFactory
+onDataSelect: $code:function(value) level = value
geometry.padding: 10

View File

@@ -1,21 +0,0 @@
package ru.m.tankz.frame.network;
import haxework.gui.HGroupView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import ru.m.tankz.proto.core.GameInfoProto;
@:template class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
public var item_index(default, default):Int;
public var data(default, set):GameInfoProto;
@:view var label(default, null):LabelView;
private function set_data(value:GameInfoProto):GameInfoProto {
data = value;
label.text = '${data.type}';
return data;
}
}

View File

@@ -1,15 +0,0 @@
---
width: 440
height: 44
margins: 5
views:
- id: label
$type: haxework.gui.LabelView
$style: label
pWidth: 100
pHeight: 100
text: ""
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0.2

View File

@@ -1,21 +0,0 @@
package ru.m.tankz.frame.network;
import haxework.gui.HGroupView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView;
import ru.m.tankz.proto.core.UserProto;
@:template class UserItemView extends HGroupView implements IListItemView<UserProto> {
public var item_index(default, default):Int;
public var data(default, set):UserProto;
@:view var label(default, null):LabelView;
private function set_data(value:UserProto):UserProto {
data = value;
label.text = '${data.uuid} -- ${data.name}';
return data;
}
}

View File

@@ -1,15 +0,0 @@
---
width: 440
height: 44
margins: 5
views:
- id: label
$type: haxework.gui.LabelView
$style: label
pWidth: 100
pHeight: 100
text: ""
skin:
$type: haxework.gui.skin.ColorSkin
color: "#000000"
alpha: 0.2

View File

@@ -1,83 +0,0 @@
package ru.m.tankz.frame.settings;
import haxework.gui.HGroupView;
import haxework.gui.LabelView;
import haxework.gui.list.ListView.IListItemView;
import openfl.Assets;
import openfl.events.KeyboardEvent;
import promhx.Deferred;
import promhx.Promise;
import ru.m.tankz.control.ActionConfig;
import ru.m.tankz.control.Control;
class KeyboardMap {
private var data:Map<Int, String>;
public function new() {
this.data = new Map();
var data = Assets.getText("resources/keyboard.txt");
for (line in data.split("\n")) {
var arr = line.split("\t");
if (arr.length == 2) {
this.data.set(Std.parseInt(arr[1]), arr[0]);
}
}
}
private static var instance: KeyboardMap;
public static function getName(key: Int): String {
if (instance == null) instance = new KeyboardMap();
return key == -1 ? "<NONE>" : instance.data.exists(key) ? instance.data.get(key) : Std.string(key);
}
}
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
public var item_index(default, default):Int;
public var data(default, set):ActionItem;
@:view var action(default, null):LabelView;
@:view var key(default, null):LabelView;
private var editDeferred: Deferred<Int>;
private static function actionLabel(action: TankAction): String {
return switch (action) {
case TankAction.SHOT: "SHOT";
case TankAction.MOVE(d): 'MOVE_$d';
case x: '$x';
}
}
private static function keyLabel(key: Int): String {
return KeyboardMap.getName(key);
}
private function set_data(value:ActionItem):ActionItem {
data = value;
action.text = actionLabel(data.action);
key.text = keyLabel(data.key);
return data;
}
public function edit():Promise<Int> {
action.skinId = key.skinId = "text.box.active";
toRedraw();
editDeferred = new Deferred();
content.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
return editDeferred.promise();
}
private function onKeyDown(event: KeyboardEvent):Void {
content.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
action.skinId = key.skinId = "text.box";
toRedraw();
data.key = event.keyCode;
key.text = keyLabel(data.key);
editDeferred.resolve(data.key);
editDeferred = null;
}
}

View File

@@ -1,12 +0,0 @@
---
geometry.margin: 5
layout.margin: 5
views:
- id: action
$type: haxework.gui.LabelView
geometry.size.fixed: [200, 38]
skinId: text.box
- id: key
$type: haxework.gui.LabelView
geometry.size.fixed: [200, 38]
skinId: text.box

View File

@@ -1,75 +0,0 @@
package ru.m.tankz.frame.settings;
import haxework.gui.ButtonView;
import haxework.gui.DataView;
import haxework.gui.LabelView;
import haxework.gui.VGroupView;
import promhx.Promise;
import ru.m.tankz.control.ActionConfig.ActionItem;
import ru.m.tankz.control.ActionConfig;
import ru.m.tankz.storage.SettingsStorage;
@:template class SettingsEditor extends VGroupView {
public var controlIndex(default, set): Int;
@:view var label:LabelView;
@:view var list:DataView<ActionItem>;
@:view var change:ButtonView;
@:view var clear:ButtonView;
@:view var reset:ButtonView;
@:provide var storage: SettingsStorage;
private function set_controlIndex(value: Int): Int {
this.controlIndex = value;
label.text = 'Player ${controlIndex+1}';
list.data = storage.read(controlIndex).data;
return this.controlIndex;
}
private function viewFactory(index:Int, value:ActionItem) {
var view = new ActionView();
view.item_index = index;
view.data = value;
return view;
}
public function onPress(view:ButtonView):Void {
switch (view.id) {
case "change": _change();
case "clear": _clear();
case "reset": _reset();
case _:
}
}
private function _change():Void {
var p: Promise<Int> = Promise.promise(0);
for (view in list.views) {
var v: ActionView = cast view;
if (v.data == null) break;
p = p.pipe(function(_):Promise<Int> return v.edit());
}
p.then(function(_) _save());
}
private function _clear():Void {
for (item in list.data) {
item.key = -1;
}
list.data = list.data;
list.toUpdate();
_save();
}
private function _reset():Void {
list.data = SettingsStorage.getDefault(controlIndex).data;
list.toUpdate();
_save();
}
private function _save():Void {
storage.write(controlIndex, new ActionConfig(list.data));
}
}

View File

@@ -1,29 +0,0 @@
layout.margin: 10
layout.hAlign: center
views:
- id: label
$type: haxework.gui.LabelView
skinId: text
- $type: haxework.gui.HGroupView
layout.margin: 10
views:
- id: change
$type: haxework.gui.ButtonView
+onPress: $this:onPress
skinId: button.simple
text: Change
- id: clear
$type: haxework.gui.ButtonView
+onPress: $this:onPress
skinId: button.simple
text: Clear
- id: reset
$type: haxework.gui.ButtonView
+onPress: $this:onPress
skinId: button.simple
text: Reset
- id: list
$type: haxework.gui.DataView<ru.m.tankz.control.ActionItem>
layout:
$type: haxework.gui.layout.VerticalLayout
factory: $this:viewFactory

View 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);
}

View File

@@ -0,0 +1,13 @@
package ru.m.tankz.local;
import ru.m.tankz.control.BaseControlFactory;
import ru.m.tankz.control.Control;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.Type;
class LocalControlFactory extends BaseControlFactory {
override private function buildHuman(id:PlayerId, index:Int):Control {
return new HumanControl(id, index);
}
}

View File

@@ -0,0 +1,42 @@
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);
}
}
}

View File

@@ -0,0 +1,31 @@
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;
}
}

View File

@@ -1,14 +1,16 @@
package ru.m.tankz.control; package ru.m.tankz.network;
import ru.m.tankz.control.HumanControl;
import ru.m.tankz.network.NetworkManager; import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.control.Control; import ru.m.tankz.control.Control;
class NetworkControl extends HumanControl {
class ClientNetworkControl extends HumanControl {
@:provide private var network:NetworkManager; @:provide private var network:NetworkManager;
override public function action(action:TankAction):Void { override public function action(action:TankAction):Void {
network.action(action); if (tankId > -1) {
network.action(tankId, action);
}
} }
} }

View File

@@ -0,0 +1,16 @@
package ru.m.tankz.network;
import ru.m.tankz.control.BaseControlFactory;
import ru.m.tankz.control.Control;
import ru.m.tankz.Type;
class NetworkControlFactory extends BaseControlFactory {
override private function buildHuman(id:PlayerId, index:Int):Control {
return new NetworkControl(id, index);
}
override private function buildBot(id:PlayerId, type:String):Control {
return null;
}
}

View 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);
}
}

View File

@@ -1,157 +1,199 @@
package ru.m.tankz.network; package ru.m.tankz.network;
import haxework.signal.Signal; import haxe.Serializer;
import ru.m.tankz.proto.pack.GameRequest; import hw.signal.Signal;
import ru.m.tankz.proto.core.GameProto;
import ru.m.tankz.proto.pack.StartGameRequest;
import ru.m.tankz.proto.game.GameChangeProto;
import ru.m.tankz.proto.game.GameActionTypeProto;
import ru.m.tankz.proto.pack.GameUpdateRequest;
import ru.m.tankz.control.Control;
import ru.m.tankz.proto.pack.JoinGameRequest;
import ru.m.tankz.proto.pack.LeaveGameRequest;
import ru.m.tankz.proto.pack.CreateGameRequest;
import ru.m.connect.IConnection; import ru.m.connect.IConnection;
import ru.m.tankz.proto.core.GameInfoProto; import ru.m.tankz.control.Control;
import ru.m.tankz.proto.pack.ListGameRequest; import ru.m.tankz.game.GameEvent;
import ru.m.tankz.proto.core.UserProto;
import ru.m.tankz.proto.game.GameEventProto;
import ru.m.tankz.proto.pack.GameEventRequest;
import ru.m.tankz.proto.pack.GameEventResponse;
import ru.m.tankz.proto.pack.LoginRequest; import ru.m.tankz.proto.pack.LoginRequest;
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.storage.UserStorage; import ru.m.tankz.proto.room.CreateRequest;
import ru.m.tankz.proto.room.JoinRequest;
import ru.m.tankz.proto.room.LeaveRequest;
import ru.m.tankz.proto.room.RoomListRequest;
import ru.m.tankz.proto.room.RoomProto;
import ru.m.tankz.proto.room.RoomRequest;
import ru.m.tankz.proto.room.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>;
class NetworkManager { enum ConnectionState {
OFFLINE;
CONNECT;
CONNECTED;
LOGIN;
ONLINE(user:User);
ERROR(error:Dynamic);
}
public var state(default, null):String; @:provide class NetworkManager {
public var stateSignal:Signal<String>;
public var listGameSignal:Signal<Array<GameInfoProto>>; private static inline var TAG = "NetworkManager";
public var gameSignal:Signal<GameInfoProto>;
public var gameUpdateSignal:Signal<Array<GameChangeProto>>; public var state(default, null):ConnectionState;
public var user(default, null):User; public var room(default, null):RoomProto;
public var game(default, set):NetworkGame; public var user(default, null):UserProto;
public var stateSignal:Signal<ConnectionState>;
public var listRoomSignal:Signal<Array<RoomProto>>;
public var roomSignal:Signal<RoomProto>;
public var gameEventSignal:Signal<GameEventResponse>;
@:provide private var connection:ClientConnection; @:provide private var connection:ClientConnection;
@:provide private var storage:UserStorage; @:provide private var storage:NetworkStorage;
@:provide private var settings:SettingsStorage;
private var reconnectTimer:Timer;
private var reconnectDelay:Int;
public function new() { public function new() {
stateSignal = new Signal<String>(); reconnectDelay = 500;
listGameSignal = new Signal<Array<GameInfoProto>>(); stateSignal = new Signal();
gameSignal = new Signal<GameInfoProto>(); listRoomSignal = new Signal();
gameUpdateSignal = new Signal<Array<GameChangeProto>>(); roomSignal = new Signal();
updateState('offline'); gameEventSignal = new Signal();
updateState(OFFLINE);
connection.handler.connect(onConnectionEvent); connection.handler.connect(onConnectionEvent);
connection.receiveHandler.connect(onResponse); connection.receiveHandler.connect(onResponse);
user = storage.read(); if (settings.enableNetwork) {
if (user == null) { connect();
user = {name: 'User', uuid: null}; }
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:String):Void { private function updateState(value:ConnectionState):Void {
L.d(TAG, 'State: ${value}');
state = value; state = value;
stateSignal.emit(value); stateSignal.emit(value);
} }
public function login(name:String):Void { public function login(name:String, uuid:String = null):Void {
user.name = name; updateState(LOGIN);
updateState('connect...'); connection.send(new Request().setLogin(
connection.connect().then(function(c:ClientConnection) {
updateState('login...');
c.send(new Request().setLogin(
new LoginRequest() new LoginRequest()
.setUuid(user.uuid) .setUuid(uuid)
.setName(user.name) .setName(name)
)); ));
}).catchError(function(_) {});
} }
public function listGame():Void { public function logout():Void {
connection.send(new Request().setListGame(new ListGameRequest())); connection.send(new Request().setLogout(new LogoutRequest()));
} }
public function createGame(type:String):Void { public function listGame(subscribe:Bool):Void {
connection.send(new Request().setCreateGame(new CreateGameRequest().setType(type))); connection.send(new Request().setRoomList(new RoomListRequest().setSubscribe(subscribe)));
} }
public function joinGame(gameId:Int):Void { public function createGame(type:String, level:Int):Void {
connection.send(new Request().setJoinGame(new JoinGameRequest().setGameId(gameId))); 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 { public function leaveGame():Void {
connection.send(new Request().setLeaveGame(new LeaveGameRequest())); connection.send(new Request().setRoom(new RoomRequest().setLeave(new LeaveRequest())));
} }
public function startGame():Void { public function startGame():Void {
connection.send(new Request().setStartGame(new StartGameRequest())); connection.send(new Request().setRoom(new RoomRequest().setStart(new StartRequest())));
} }
public function action(action:TankAction):Void { public function action(tankId:Int, action:TankAction):Void {
var update:GameUpdateRequest = switch action { connection.send(new Request().setGameEvent(new GameEventRequest().setEvent(
case TankAction.MOVE(direction): new GameEventProto().setTime(0).setEvent(
new GameUpdateRequest() Serializer.run(GameEvent.ACTION(tankId, action))
.setType(GameActionTypeProto.MOVE) )))
.setDirectionX(direction.x) );
.setDirectionY(direction.y);
case TankAction.STOP:
new GameUpdateRequest()
.setType(GameActionTypeProto.STOP);
case TankAction.SHOT:
new GameUpdateRequest()
.setType(GameActionTypeProto.SHOT);
case _: null;
} }
if (update != null) {
connection.send(new Request().setUpdateGame(update)); private function 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 { private function onConnectionEvent(event:ConnectionEvent):Void {
updateState(switch (event) { updateState(switch event {
case ConnectionEvent.CONNECTED: case CONNECTED: CONNECTED;
L.d('Network', '$event'); case DISCONNECTED: OFFLINE;
'connected'; case ERROR(error): ERROR(error);
case ConnectionEvent.DISCONNECTED:
L.d('Network', '$event');
'offline';
case ConnectionEvent.ERROR(error):
L.e('Network', '$error', error);
'error';
}); });
switch event {
case CONNECTED:
reconnectDelay = 500;
var user = storage.user;
if (user != null) {
login(user.name, user.uuid);
}
case DISCONNECTED | ERROR(_):
if (settings.enableNetwork) {
reconnect();
}
}
} }
private function onResponse(packet:Response):Void { private function onResponse(packet:Response):Void {
if (packet.hasLogin()) { if (packet.hasLogin()) {
user = { this.user = packet.login.user;
uuid: packet.login.user.uuid, var user = {
name: packet.login.user.name, uuid: this.user.uuid,
name: this.user.name,
}; };
storage.write(user); storage.user = user;
updateState('online'); updateState(ONLINE(user));
} else if (packet.hasLogout()) { } else if (packet.hasLogout()) {
user = null; storage.user = null;
updateState('connected'); updateState(CONNECTED);
} else if (packet.hasListGame()) { } else if (packet.hasRoomList()) {
listGameSignal.emit(packet.listGame.games); listRoomSignal.emit(packet.roomList.rooms);
} else if (packet.hasCreateGame()) { } else if (packet.hasRoom()) {
gameSignal.emit(packet.createGame.game); room = packet.room.room;
} else if (packet.hasJoinGame()) { roomSignal.emit(room);
gameSignal.emit(packet.joinGame.game); } else if (packet.hasGameEvent()) {
} else if (packet.hasLeaveGame()) { gameEventSignal.emit(packet.gameEvent);
gameSignal.emit(null);
} else if (packet.hasStartGame()) {
gameSignal.emit(packet.startGame.game);
} else if (packet.hasUpdateGame()) {
gameUpdateSignal.emit(packet.updateGame.changes);
} else if (packet.hasGame()) {
game.load(packet.game.game);
} }
} }
private function set_game(value:NetworkGame):NetworkGame {
this.game = value;
connection.send(new Request().setGame(new GameRequest()));
return this.game;
}
} }

Some files were not shown because too many files have changed in this diff Show More