Compare commits
107 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 27120bbed5 | |||
| 03d6e1f822 | |||
| 648d15fc88 | |||
| d6af58875d | |||
| 16a5adefad | |||
| 682eaa677c | |||
| 4319d66c61 | |||
| f6f729e8d4 | |||
| a39b02bfe7 | |||
| 1cfc98dd57 | |||
| ee846f6219 | |||
| e353d97415 | |||
| 2b49fafa0b | |||
| b33b853747 | |||
| 8e3e6bdb6c | |||
| d9d385b0ef | |||
| 8c16b5ba90 | |||
| 1aaa69f2d7 | |||
| 6240846f0c | |||
| 70e6565e1f | |||
| fffb6a3214 | |||
| 04bea46b3b | |||
| 4da06e52e5 | |||
| 8878a825b8 | |||
| 7de1897b32 | |||
| d670722674 | |||
| e7d031db58 | |||
| 71087286b2 | |||
| 757bc87426 | |||
| 1b5eef810c | |||
| cfa1475cf6 | |||
| 1e79fcfacb | |||
| b34cb41bff | |||
| d2aff5f2ee | |||
| beda5e6c5f | |||
| 50c4aebc0f | |||
| 30325f6d16 | |||
| bddb590d30 | |||
| de831fcb26 | |||
| 5645fb6d0f | |||
| bab588e6fb | |||
| 2565b6017a | |||
| 112cd7ba2f | |||
| 77ddd78d84 | |||
| 4fa5cf84fa | |||
| 40bdf6a5cc | |||
| 47039bbaa5 | |||
| 4d7fcb4b4b | |||
| 5f24e85deb | |||
| 42fd008a54 | |||
| c2b0618c93 | |||
| 94f72f71e3 | |||
| bb4b928c89 | |||
| d67d4e5709 | |||
| a4bbeb2573 | |||
| e032c25e1a | |||
| d9cce32bb8 | |||
| 10d5e0df40 | |||
| 0f3392aa0c | |||
| 9d4558ca47 | |||
| 6609756065 | |||
| 605935528b | |||
| f072d8dc6e | |||
| 00cd404a98 | |||
| d47be9ea8a | |||
| 2d70a5652b | |||
| bbf1438728 | |||
| c0496f2e7c | |||
| 636be8611f | |||
| 48f9c433e2 | |||
| 314f5a480c | |||
| 46f2abab05 | |||
| 883f14fb76 | |||
| cc151322d8 | |||
| de64e2813e | |||
| db80c151bb | |||
| ef971e03b9 | |||
| f10da93a12 | |||
| e63b41ae8a | |||
| 43a34cce39 | |||
| b9b5453f89 | |||
| f5af6716d5 | |||
| 7125cc1e9f | |||
| 8a3ceec1ee | |||
| 523f334c1b | |||
| a547b68dc0 | |||
| 45cabc1926 | |||
| 42138cd4ad | |||
| e8e3a6f1b3 | |||
| 6d5148e0a5 | |||
| 262221d969 | |||
| 9eccb263c0 | |||
| ba90b90cd3 | |||
| 94340bddb1 | |||
| 3361d252ee | |||
| 637772f2dd | |||
| f703c76c21 | |||
| 5fe307a218 | |||
| 670a11d6ba | |||
| 1ec1c3baae | |||
| 24f5b0c218 | |||
| b7bc1d244f | |||
| fbc9238d2f | |||
| eb7c311bb6 | |||
| 9640414ba4 | |||
| bc95ca03e2 | |||
| d0ebf05f1c |
@@ -4,6 +4,9 @@ root = true
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
|
||||
10
.env.default
Normal file
10
.env.default
Normal 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
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
build/
|
||||
target/
|
||||
src-gen/
|
||||
out/
|
||||
@@ -12,3 +13,5 @@ config.json
|
||||
/node_modules
|
||||
/log
|
||||
/ansible/*.retry
|
||||
.npmrc
|
||||
.env
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
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`
|
||||
|
||||
28
Dockerfile
Normal file
28
Dockerfile
Normal 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
9
README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Tankz
|
||||
|
||||
## Play
|
||||
|
||||
https://shmyga.ru/tankz/html5/index.html
|
||||
|
||||
## Packages
|
||||
|
||||
https://git.shmyga.ru/InfernalGames/-/packages/generic/tankz
|
||||
30
WORK.md
30
WORK.md
@@ -1,12 +1,20 @@
|
||||
* **shovel** bonus with armor bricks
|
||||
* bonuses in dota/death mod
|
||||
* death game bonus
|
||||
* tanks and bullets speed balancing
|
||||
* result frame update (next game select, only human player info)
|
||||
* network game series
|
||||
* map packs (create in editor, import in game, save imported in local storage)
|
||||
* update bots
|
||||
* improve bonuses system
|
||||
* gamepad support
|
||||
* screen gamepad on mobiles
|
||||
* resize render on mobiles
|
||||
* [bug] game progress broken
|
||||
* clean player state on lose in classic type
|
||||
* network series
|
||||
* bot upgrade
|
||||
* game config validate
|
||||
* mine z-order
|
||||
* mine spawn position
|
||||
* mine spawn on other mine
|
||||
* double rocket
|
||||
* display ammo count (panel)
|
||||
* display ammo count (screen gamepad)
|
||||
* bonus ammo
|
||||
* game panel rework
|
||||
* game state: config, map, entities, players
|
||||
* game menu pack progress
|
||||
* game save
|
||||
* balloons: change mute, network, pause
|
||||
* settings: mute, pause, reset device actions
|
||||
* game view: toggle panel on mobile
|
||||
|
||||
@@ -5,11 +5,11 @@ project_user: holop
|
||||
deploy_user: "{{ project_user }}"
|
||||
deploy_project: "{{ project_name }}"
|
||||
deploy_repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||
deploy_repo_version: master
|
||||
deploy_repo_version: develop
|
||||
deploy_npm: yes
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
service_work_dir: "{{ deploy_current_dir }}/target/server/neko"
|
||||
service_command: "/usr/bin/neko {{ service_work_dir }}/{{ project_name }}.n {{ service_host }}"
|
||||
service_work_dir: "{{ deploy_current_dir }}/target/server/cpp"
|
||||
service_command: "{{ service_work_dir }}/{{ project_name }} {{ service_host }}"
|
||||
service_user: www-data
|
||||
service_control_user: "{{ project_user }}"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
all:
|
||||
hosts: shmyga.ru
|
||||
vars:
|
||||
service_host: 172.31.1.100
|
||||
service_host: 213.139.208.180
|
||||
config_src: "/home/holop/tankz/config.json"
|
||||
|
||||
2
ansible/roles/build/defaults/main.yml
Normal file
2
ansible/roles/build/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
config_src: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json"
|
||||
config_dest: "{{ deploy_release_dir }}/config.json"
|
||||
@@ -1,11 +1,11 @@
|
||||
---
|
||||
- name: "Copy config"
|
||||
copy:
|
||||
src: "{{ deploy_release_dir }}/config.{{ inventory_hostname }}.json"
|
||||
dest: "{{ deploy_release_dir }}/config.json"
|
||||
src: "{{ config_src }}"
|
||||
dest: "{{ config_dest }}"
|
||||
remote_src: true
|
||||
|
||||
- name: "Gulp build"
|
||||
command: "/usr/local/lib/npm/bin/gulp default --host shmyga.ru"
|
||||
command: "{{ deploy_release_dir }}/node_modules/.bin/gulp default --host shmyga.ru"
|
||||
args:
|
||||
chdir: "{{ deploy_release_dir }}"
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"SdkDir": "C:\\sdk",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
"SdkDir": "C:\\sdk",
|
||||
"BuildDir": null,
|
||||
"PublishDir": "",
|
||||
"PublishUrl": "https://shmyga.ru/repo/tankz",
|
||||
"Develop": false,
|
||||
"Key": {
|
||||
"store": "keystore.jks",
|
||||
"pass": null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"SdkDir": "/home/holop/sdk",
|
||||
"SSH": {
|
||||
"PrivateKey": null,
|
||||
"Passphrase": null
|
||||
}
|
||||
}
|
||||
22
docker-compose.yaml
Normal file
22
docker-compose.yaml
Normal 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
|
||||
124
gulpfile.js
124
gulpfile.js
@@ -1,49 +1,51 @@
|
||||
const gulp = require('gulp');
|
||||
const zip = require('gulp-zip');
|
||||
const foreach = require('gulp-foreach');
|
||||
const gulpClean = require('gulp-clean');
|
||||
const Config = require('./config.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 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 = '32';
|
||||
//Haxe.VERSION = '4.0.0-rc.2';
|
||||
if (Config.SdkDir) {
|
||||
Sdk.dir = Config.SdkDir;
|
||||
}
|
||||
|
||||
if (Config.BuildDir) {
|
||||
Haxe.buildDir = Config.BuildDir;
|
||||
}
|
||||
|
||||
exports.clean = function clean() {
|
||||
return gulp.src('target/*', {read: false}).pipe(gulpClean());
|
||||
};
|
||||
|
||||
exports.generate = function generate() {
|
||||
return new Haxe().haxelib(['run', 'protohx', 'generate', 'protohx.json']).then(({stdout}) => {
|
||||
if (stdout.indexOf('FAIL') > -1) {
|
||||
throw stdout;
|
||||
}
|
||||
});
|
||||
exports.setup = function setup() {
|
||||
const builder = Project.Builder.new(
|
||||
client.config,
|
||||
Project.Platform.ANDROID,
|
||||
client.buildSystem,
|
||||
);
|
||||
return builder.prepare();
|
||||
};
|
||||
|
||||
exports.levels = function () {
|
||||
return gulp.src("./src/common/level/*").pipe(foreach(function (stream, file) {
|
||||
const type = file.path.substr(file.path.lastIndexOf("/") + 1);
|
||||
gulp.src("./src/common/level/" + type + "/*").pipe(foreach(function (stream, file) {
|
||||
const name = file.path.substr(file.path.lastIndexOf("/") + 1);
|
||||
gulp.src("./src/common/level/" + type + "/" + name + "/*")
|
||||
.pipe(zip(`${type}_${name}.zip`))
|
||||
.pipe(gulp.dest("./target/levels"));
|
||||
}));
|
||||
return stream;
|
||||
}));
|
||||
exports.generate = function generate() {
|
||||
return exports.setup().then(() =>
|
||||
new Haxe()
|
||||
.haxelib(["run", "protohx", "generate", "protohx.json"])
|
||||
.then(({ stdout }) => {
|
||||
if (stdout.indexOf("FAIL") > -1) {
|
||||
throw stdout;
|
||||
}
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* ToDo:
|
||||
* windows target
|
||||
* window exe package (innosetup)
|
||||
* base config
|
||||
*/
|
||||
const config = new Project.Config({
|
||||
meta: {
|
||||
@@ -53,19 +55,19 @@ const config = new Project.Config({
|
||||
pack: 'ru.m.tankz',
|
||||
author: 'shmyga <shmyga.z@gmail.com>',
|
||||
company: 'MegaLoMania',
|
||||
version: packageInfo.version,
|
||||
version: packageInfo.version + (Config.Develop ? '-SNAPSHOT' : ''),
|
||||
},
|
||||
key: Config.Key,
|
||||
libs: packageInfo.haxeDependencies,
|
||||
sources: [
|
||||
'src/common/haxe',
|
||||
'src-gen/haxe',
|
||||
],
|
||||
assets: [
|
||||
'src/common/resources',
|
||||
'target/levels'
|
||||
'src/common/resources/config',
|
||||
],
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
'proto_debug',
|
||||
],
|
||||
macros: [
|
||||
`CompilationOption.set('build','${dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss')}')`,
|
||||
@@ -84,19 +86,23 @@ const client = new Project(
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
Project.Platform.WINDOWS,
|
||||
Project.Platform.ANDROID,
|
||||
],
|
||||
config.branch({
|
||||
name: 'client',
|
||||
sources: ['src/client/haxe'],
|
||||
sources: [
|
||||
'src/client/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.Client',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
'src/common/resources/level',
|
||||
'src/client/resources',
|
||||
],
|
||||
meta: {
|
||||
width: 1024,
|
||||
height: 768,
|
||||
height: 576,
|
||||
},
|
||||
flags: [
|
||||
//'proto_debug',
|
||||
@@ -109,7 +115,6 @@ const client = new Project(
|
||||
`CompilationOption.set('port',${port})`,
|
||||
]
|
||||
}),
|
||||
module.exports.generate
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
@@ -120,10 +125,14 @@ const editor = new Project(
|
||||
[
|
||||
Project.Platform.FLASH,
|
||||
Project.Platform.HTML5,
|
||||
Project.Platform.LINUX,
|
||||
],
|
||||
config.branch({
|
||||
name: 'editor',
|
||||
sources: ['src/client/haxe', 'src/editor/haxe'],
|
||||
sources: [
|
||||
'src/client/haxe',
|
||||
'src/editor/haxe',
|
||||
],
|
||||
main: 'ru.m.tankz.editor.Editor',
|
||||
preloader: 'ru.m.tankz.Preloader',
|
||||
assets: [
|
||||
@@ -132,8 +141,9 @@ const editor = new Project(
|
||||
],
|
||||
meta: {
|
||||
filename: 'editor',
|
||||
pack: 'ru.m.tankz.editor',
|
||||
width: 1024,
|
||||
height: 850,
|
||||
height: 768,
|
||||
},
|
||||
flags: [
|
||||
//'dev_layout',
|
||||
@@ -146,31 +156,59 @@ const editor = new Project(
|
||||
*/
|
||||
const server = new Project(
|
||||
Project.BuildSystem.HAXE,
|
||||
Project.Platform.NEKO,
|
||||
Project.Platform.CPP,
|
||||
config.branch({
|
||||
name: 'server',
|
||||
sources: ['src/server/haxe'],
|
||||
main: 'ru.m.tankz.server.Server',
|
||||
assets: [
|
||||
'src/common/resources/level',
|
||||
]
|
||||
}),
|
||||
module.exports.generate
|
||||
).bind(module, gulp);
|
||||
|
||||
/**
|
||||
* publish
|
||||
*/
|
||||
module.exports.publish = publish(packageInfo.name, packageInfo.version, Config.PublishDir, Config.PublishUrl);
|
||||
|
||||
/**
|
||||
* default
|
||||
*/
|
||||
module.exports.default = gulp.series(
|
||||
const defaultSeries = [
|
||||
exports.clean,
|
||||
exports.levels,
|
||||
exports.generate,
|
||||
module.exports['client:flash:build'],
|
||||
module.exports['client:flash:html'],
|
||||
module.exports['client:html5:build'],
|
||||
module.exports['client:linux:build'],
|
||||
module.exports['client:linux:deb'],
|
||||
//module.exports['client:android:build'],
|
||||
|
||||
module.exports['editor:flash:build'],
|
||||
module.exports['editor:flash:html'],
|
||||
module.exports['editor:html5:build'],
|
||||
|
||||
module.exports['server:neko:build'],
|
||||
module.exports['server:cpp:build'],
|
||||
];
|
||||
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(
|
||||
module.exports['client:linux:build'],
|
||||
module.exports['client:linux:archive'],
|
||||
module.exports['client:linux:deb'],
|
||||
|
||||
module.exports['client:android:build'],
|
||||
);
|
||||
}
|
||||
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(
|
||||
module.exports['client:windows:build'],
|
||||
module.exports['client:windows:archive'],
|
||||
module.exports['client:windows:installer'],
|
||||
);
|
||||
}
|
||||
|
||||
defaultSeries.push(
|
||||
exports.publish,
|
||||
);
|
||||
|
||||
module.exports.default = gulp.series(defaultSeries);
|
||||
|
||||
5
hxformat.json
Normal file
5
hxformat.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"indentation": {
|
||||
"character": " "
|
||||
}
|
||||
}
|
||||
14162
package-lock.json
generated
14162
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@@ -1,28 +1,25 @@
|
||||
{
|
||||
"name": "tankz",
|
||||
"version": "0.15.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-foreach": "^0.1.0",
|
||||
"gulp-haxetool": "^0.0.19",
|
||||
"gulp-zip": "^5.0.0",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"haxework": "git@bitbucket.org:shmyga/haxework.git",
|
||||
"lime": "7.5.0",
|
||||
"openfl": "8.9.1",
|
||||
"hxcpp": "4.0.8",
|
||||
"promhx": "1.1.0",
|
||||
"protohx": "0.4.6",
|
||||
"yaml": "1.3.0",
|
||||
"orm": "2.1.0",
|
||||
"yield": "2.0.0",
|
||||
"haxe-crypto": "0.0.7",
|
||||
"svg": "1.1.2"
|
||||
}
|
||||
"name": "tankz",
|
||||
"version": "0.18.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"dateformat": "^3.0.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-add": "0.0.2",
|
||||
"gulp-clean": "^0.4.0",
|
||||
"gulp-haxetool": "^0.1.9",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"haxeDependencies": {
|
||||
"haxework": "2.1.0",
|
||||
"lime": "8.0.0",
|
||||
"openfl": "9.2.0",
|
||||
"hxcpp": "4.2.1",
|
||||
"protohx": "0.4.6",
|
||||
"orm": "2.1.0",
|
||||
"haxe-crypto": "0.0.8",
|
||||
"svg": "1.1.3",
|
||||
"formatter": "1.16.0"
|
||||
},
|
||||
"haxe": "4.2.5"
|
||||
}
|
||||
|
||||
7
scripts/build
Executable file
7
scripts/build
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
cd "$(dirname $(dirname "$0"))" || exit
|
||||
|
||||
source .env
|
||||
mkdir -p "$SDK_PATH" "$PUBLISH_PATH" "$BUILD_PATH" "$TARGET_PATH" "src-gen"
|
||||
docker compose run --rm --user $(id -u):$(id -g) --build --remove-orphans builder
|
||||
12
scripts/format
Executable file
12
scripts/format
Executable 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
13
scripts/lint
Executable 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
32
scripts/publish
Executable 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
5
scripts/setup
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
cd "$(dirname $(dirname "$0"))" || exit
|
||||
|
||||
npm ci
|
||||
31
sql/init.sql
31
sql/init.sql
@@ -1,31 +0,0 @@
|
||||
-- mysql -u shmyga -pxkbp8jh9z2 armageddon --protocol TCP
|
||||
CREATE USER 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||
|
||||
DROP DATABASE IF EXISTS armageddon;
|
||||
CREATE DATABASE IF NOT EXISTS armageddon;
|
||||
GRANT ALL ON armageddon.* TO 'shmyga'@'localhost' IDENTIFIED BY 'xkbp8jh9z2';
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS armageddon.account;
|
||||
CREATE TABLE IF NOT EXISTS armageddon.account (
|
||||
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
login VARCHAR(255) UNIQUE,
|
||||
password VARCHAR(32)
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS armageddon.person;
|
||||
CREATE TABLE IF NOT EXISTS armageddon.person (
|
||||
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
account_id INT UNSIGNED NOT NULL,
|
||||
name VARCHAR(255),
|
||||
|
||||
CONSTRAINT person_2_account FOREIGN KEY (account_id) REFERENCES armageddon.account(id)
|
||||
MATCH SIMPLE ON DELETE CASCADE ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
INSERT INTO armageddon.account (id,login,password) VALUES(1,'shmyga', 'd48cc4eb42c058869ae90daef9606e43');
|
||||
INSERT INTO armageddon.person (id,account_id,name) VALUES(1,1,'-=Shmyga=-');
|
||||
|
||||
INSERT INTO armageddon.account (id,login,password) VALUES(2,'a', md5('a'));
|
||||
INSERT INTO armageddon.person (id,account_id,name) VALUES(2,2,'a');
|
||||
|
||||
44
src/client/haxe/ru/m/Device.hx
Normal file
44
src/client/haxe/ru/m/Device.hx
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package ru.m.animate;
|
||||
|
||||
import flash.display.PixelSnapping;
|
||||
import haxe.Timer;
|
||||
import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
|
||||
import flash.display.PixelSnapping;
|
||||
|
||||
typedef Frame = {
|
||||
var image:BitmapData;
|
||||
@@ -13,35 +11,18 @@ typedef Frame = {
|
||||
|
||||
class Animate extends Bitmap {
|
||||
|
||||
private static var timer:Timer;
|
||||
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 playing(default, default):Bool;
|
||||
public var frames(default, set):Array<Frame>;
|
||||
|
||||
private var sequence:Array<BitmapData>;
|
||||
private var index:Int;
|
||||
|
||||
@:provide private static var manager:AnimateManager;
|
||||
|
||||
public function new(?frames:Array<Frame>) {
|
||||
super(null, PixelSnapping.AUTO, true);
|
||||
this.frames = frames == null ? [] : frames;
|
||||
init();
|
||||
instances.push(this);
|
||||
manager.add(this);
|
||||
}
|
||||
|
||||
public function set_frames(value:Array<Frame>):Array<Frame> {
|
||||
@@ -59,14 +40,7 @@ class Animate extends Bitmap {
|
||||
return frames;
|
||||
}
|
||||
|
||||
public function set_playing(value:Bool):Bool {
|
||||
if (playing != value) {
|
||||
playing = value;
|
||||
}
|
||||
return playing;
|
||||
}
|
||||
|
||||
private function update():Void {
|
||||
public function update():Void {
|
||||
if (++index >= sequence.length) {
|
||||
index = 0;
|
||||
}
|
||||
@@ -77,8 +51,6 @@ class Animate extends Bitmap {
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
if (instances.indexOf(this) > -1) {
|
||||
instances.remove(this);
|
||||
}
|
||||
manager.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
34
src/client/haxe/ru/m/animate/AnimateManager.hx
Normal file
34
src/client/haxe/ru/m/animate/AnimateManager.hx
Normal file
@@ -0,0 +1,34 @@
|
||||
package ru.m.animate;
|
||||
|
||||
@:provide class AnimateManager {
|
||||
public var playing(default, default):Bool;
|
||||
|
||||
private var timer:Timer;
|
||||
private var animations:Array<Animate>;
|
||||
|
||||
public function new() {
|
||||
animations = [];
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
}
|
||||
|
||||
public function update():Void {
|
||||
if (playing) {
|
||||
for (animation in animations) {
|
||||
if (animation.playing) {
|
||||
animation.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add(animate:Animate):Void {
|
||||
animations.push(animate);
|
||||
}
|
||||
|
||||
public function remove(animate:Animate):Void {
|
||||
if (animations.indexOf(animate) > -1) {
|
||||
animations.remove(animate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package ru.m.animate;
|
||||
import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
|
||||
|
||||
class OnceAnimate extends Animate {
|
||||
|
||||
private var deferred:Deferred<Animate>;
|
||||
@@ -14,13 +13,14 @@ class OnceAnimate extends Animate {
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
override private function update():Void {
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (index == 0) {
|
||||
playing = false;
|
||||
if (deferred != null) {
|
||||
deferred.resolve(this);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
import ru.m.control.IControlBus;
|
||||
|
||||
class ControlBus implements IControlBus {
|
||||
|
||||
@@ -3,5 +3,6 @@ package ru.m.control;
|
||||
enum DeviceType {
|
||||
NONE;
|
||||
KEYBOARD;
|
||||
SCREEN;
|
||||
GAMEPAD(id:Int);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
|
||||
interface IControlBus {
|
||||
public var devices(default, null):Array<IControlDevice>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
|
||||
interface IControlDevice {
|
||||
public var type(default, null):DeviceType;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.control;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
import lime.ui.Joystick;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.m.control;
|
||||
|
||||
import flash.display.Stage;
|
||||
import flash.events.KeyboardEvent;
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
import ru.m.control.DeviceAction;
|
||||
|
||||
class KeyboardDevice implements IControlDevice {
|
||||
|
||||
@@ -5,10 +5,18 @@ import flash.display.DisplayObjectContainer;
|
||||
|
||||
class DisplayObjectContainerExtender {
|
||||
|
||||
public static function childrenIterator():Iterator<DisplayObject> {
|
||||
throw "Not implemented";
|
||||
}
|
||||
|
||||
public static function removeChildSafety(self:DisplayObjectContainer, child:DisplayObject):DisplayObject {
|
||||
if (self.contains(child)) {
|
||||
return self.removeChild(child);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function containsRecursivle(child:DisplayObject):Bool {
|
||||
throw "Not implemented";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,42 @@
|
||||
package ru.m.skin;
|
||||
|
||||
import format.SVG;
|
||||
import haxework.color.Color;
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.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;
|
||||
private var color:Color;
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
@:style(null) private var svg:String;
|
||||
@:style(0) private var color:Null<Color>;
|
||||
@:style(false) private var solid:Null<Bool>;
|
||||
|
||||
private var svgs:Map<ButtonState, SVG>;
|
||||
|
||||
public function new(svg:String, color:Color) {
|
||||
public function new(?svg:String, ?color:Color, ?solid:Bool) {
|
||||
this.svg = svg;
|
||||
this.color = color;
|
||||
init();
|
||||
this.solid = solid;
|
||||
init(solid);
|
||||
}
|
||||
|
||||
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 {
|
||||
svgs = new Map<ButtonState, SVG>();
|
||||
svgs.set(ButtonState.UP, buildSVG(color));
|
||||
svgs.set(ButtonState.DOWN, buildSVG(ColorUtil.diff(color, -24)));
|
||||
svgs.set(ButtonState.OVER, buildSVG(ColorUtil.diff(color, 24)));
|
||||
svgs.set(ButtonState.DISABLED, buildSVG(ColorUtil.grey(color)));
|
||||
private function init(solid:Bool):Void {
|
||||
var color = color;
|
||||
if (solid) {
|
||||
color = color.multiply(1.5);
|
||||
}
|
||||
svgs = new Map();
|
||||
svgs.set(UP, buildSVG(color));
|
||||
svgs.set(DOWN, buildSVG(color.diff(-24)));
|
||||
svgs.set(OVER, buildSVG(color.diff(24)));
|
||||
svgs.set(DISABLED, buildSVG(color.grey()));
|
||||
}
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
@@ -37,7 +45,10 @@ class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
graphics.beginFill(0, 0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
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));
|
||||
graphics.lineStyle();
|
||||
graphics.endFill();
|
||||
|
||||
200
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal file
200
src/client/haxe/ru/m/tankz/AppTheme.hx
Normal 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),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +1,60 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import ru.m.animate.AnimateManager;
|
||||
import flash.Lib;
|
||||
import haxework.animate.Animate;
|
||||
import haxework.log.TraceLogger;
|
||||
import haxework.view.Root;
|
||||
import hw.animate.Animate;
|
||||
import hw.log.TraceLogger;
|
||||
import hw.net.manage.LoaderManager;
|
||||
import hw.view.Root;
|
||||
import hw.view.popup.PopupManager;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.view.ClientView;
|
||||
|
||||
class Client {
|
||||
private static inline var TAG = "Tankz";
|
||||
|
||||
@:provide private static var settings:SettingsStorage;
|
||||
|
||||
public static function main() {
|
||||
L.push(new TraceLogger());
|
||||
#if flash
|
||||
L.push(new haxework.log.JSLogger());
|
||||
L.push(new hw.log.JSLogger());
|
||||
#end
|
||||
#if debug
|
||||
//L.push(new haxework.log.SocketLogger());
|
||||
//L.push(new hw.log.SocketLogger());
|
||||
#end
|
||||
// ToDo: fix @:provide macro
|
||||
PopupManager;
|
||||
LoaderManager;
|
||||
GameStorage;
|
||||
AnimateManager;
|
||||
//
|
||||
Const.init();
|
||||
Init.init();
|
||||
Animate.bind(Lib.current.stage);
|
||||
// TODO:
|
||||
// Animate.bind(Lib.current.stage);
|
||||
L.d(TAG, 'Debug: ${Const.DEBUG}');
|
||||
L.i(TAG, 'Version: ${Const.VERSION}');
|
||||
L.i(TAG, 'Build: ${Const.BUILD}');
|
||||
L.i(TAG, 'Mobile: ${Device.isMobile()}');
|
||||
#if linux
|
||||
LinuxIcon.apply();
|
||||
#end
|
||||
Style.register();
|
||||
var view:ClientView = new ClientView();
|
||||
Root.bind(view);
|
||||
view.launch();
|
||||
|
||||
#if debug
|
||||
var fps = new openfl.display.FPS(0, 0, 0x00ff00);
|
||||
fps.visible = settings.displayFPS;
|
||||
Lib.current.addChild(fps);
|
||||
#end
|
||||
|
||||
settings.signal.connect(function(setting) {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value):
|
||||
fps.visible = value;
|
||||
case _:
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ class Const {
|
||||
public static var FPS:Int;
|
||||
public static var BUILD:String;
|
||||
public static var VERSION:String;
|
||||
public static var NAME:String;
|
||||
public static var DEBUG:Bool;
|
||||
|
||||
public static function init():Void {
|
||||
FPS = Std.parseInt(Lib.current.stage.application.meta.get("fps"));
|
||||
BUILD = CompilationOption.get("build");
|
||||
VERSION = Lib.current.stage.application.meta.get("version");
|
||||
NAME = Lib.current.stage.application.meta.get("name");
|
||||
DEBUG = Capabilities.isDebugger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.Lib;
|
||||
import haxework.animate.FadeAnimate;
|
||||
import haxework.animate.UnFadeAnimate;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.resources.Resources;
|
||||
import haxework.view.popup.PopupManager;
|
||||
import hw.animate.FadeAnimate;
|
||||
import hw.animate.UnFadeAnimate;
|
||||
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;
|
||||
@@ -13,33 +13,24 @@ 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.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.bundle.LevelBundle;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.Request;
|
||||
import ru.m.tankz.proto.pack.Response;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.NetworkStorage;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
class Init {
|
||||
|
||||
@:provide static var resources:IResources;
|
||||
@:provide static var theme:ITheme;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var settingsStorage:SettingsStorage;
|
||||
@:provide static var multiplayerStorage:NetworkStorage;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var networkManager:NetworkManager;
|
||||
@:provide static var popupManager:PopupManager;
|
||||
@:provide static var connection:IConnection<Request, Response>;
|
||||
@:provide static var bus:IControlBus;
|
||||
@:provide static var updater:Updater;
|
||||
|
||||
private static function buildConnection():IConnection<Request, Response> {
|
||||
var host:String = CompilationOption.get("host");
|
||||
@@ -55,25 +46,21 @@ class Init {
|
||||
}
|
||||
|
||||
public static function init():Void {
|
||||
resources = new Resources();
|
||||
levelBundle = new LevelBundle();
|
||||
theme = new AppTheme();
|
||||
levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
|
||||
levelBundle.load();
|
||||
configBundle = new ConfigBundle();
|
||||
settingsStorage = new SettingsStorage();
|
||||
multiplayerStorage = new NetworkStorage();
|
||||
gameStorage = new GameStorage();
|
||||
recordStorage = new RecordStorage();
|
||||
soundManager = new SoundManager();
|
||||
popupManager = new PopupManager();
|
||||
|
||||
popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100);
|
||||
popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100);
|
||||
|
||||
connection = buildConnection();
|
||||
networkManager = new NetworkManager();
|
||||
|
||||
bus = new ControlBus();
|
||||
bus.connect(new KeyboardDevice(Lib.current.stage));
|
||||
|
||||
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
|
||||
|
||||
for (device in Gamepad.devices) {
|
||||
trace('gamepad', device);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.Lib;
|
||||
import haxework.view.core.Size;
|
||||
import hw.view.geometry.Size;
|
||||
import ru.m.tankz.AppTheme;
|
||||
|
||||
class Progress extends Sprite {
|
||||
|
||||
@@ -105,10 +106,10 @@ class Preloader extends Sprite {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
Lib.current.stage.color = Style.lightColor;
|
||||
Lib.current.stage.color = AppTheme.COLORS.light;
|
||||
progress = new Progress();
|
||||
progress.color = Style.darkColor;
|
||||
progress.backColor = Style.lightColor;
|
||||
progress.color = AppTheme.COLORS.dark;
|
||||
progress.backColor = AppTheme.COLORS.light;
|
||||
progress.size = [200, 200];
|
||||
addChild(progress);
|
||||
onResize(null);
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
package ru.m.tankz;
|
||||
|
||||
import flash.text.Font;
|
||||
import flash.text.FontType;
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.view.core.Geometry;
|
||||
import haxework.view.core.HAlign;
|
||||
import haxework.view.core.VAlign;
|
||||
import haxework.view.ITextView;
|
||||
import haxework.view.layout.Layout;
|
||||
import haxework.view.skin.ISkin;
|
||||
import haxework.view.skin.Skin;
|
||||
import openfl.Assets;
|
||||
import ru.m.skin.ButtonSVGSkin;
|
||||
|
||||
class Style {
|
||||
|
||||
@:provide private static var resources:IResources;
|
||||
|
||||
public static var lightColor = 0x95937D;
|
||||
public static var darkColor = 0x777564;
|
||||
public static var textColor = 0xE7E0BB;
|
||||
public static var activeColor = 0xFFFF00;
|
||||
public static var borderColor = ColorUtil.multiply(lightColor, 1.5);
|
||||
|
||||
public static var baseFontSize = 18;
|
||||
public static var bigFontSize = 22;
|
||||
public static var veryBigFontSize = 24;
|
||||
|
||||
public static var fontFamily = "Courirer New";
|
||||
public static var fontEmbed = false;
|
||||
|
||||
public static function text(color):ISkin<ITextView> {
|
||||
return Skin.text(color, baseFontSize, fontFamily, fontEmbed);
|
||||
}
|
||||
|
||||
public static function registerButton(name:String, resource:String):Void {
|
||||
resources.skin.put('button.$name', [
|
||||
Skin.size(42, 42),
|
||||
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||
]);
|
||||
resources.skin.put('button.$name.small', [
|
||||
Skin.size(32, 32),
|
||||
new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), lightColor),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function textBox(color:Int):SkinSet {
|
||||
return [
|
||||
Skin.color(0x000000, 0.1),
|
||||
Skin.border(lightColor, 1, 2),
|
||||
Skin.text(color, baseFontSize, fontFamily, fontEmbed),
|
||||
];
|
||||
}
|
||||
|
||||
public static function register(font:Font = null):Void {
|
||||
resources.color.put("light", lightColor);
|
||||
resources.color.put("dark", darkColor);
|
||||
if (font == null) {
|
||||
font = Font.enumerateFonts()[0];
|
||||
}
|
||||
if (font == null) {
|
||||
font = Font.enumerateFonts(true)[0];
|
||||
}
|
||||
fontFamily = font == null ? "Courirer New" : font.fontName;
|
||||
fontEmbed = font == null ? false : switch font.fontType {
|
||||
case DEVICE: false;
|
||||
case _: true;
|
||||
};
|
||||
resources.skin.put("light", [
|
||||
Skin.color(lightColor),
|
||||
]);
|
||||
resources.skin.put("dark", [
|
||||
Skin.color(darkColor),
|
||||
]);
|
||||
resources.skin.put("font", [
|
||||
Skin.text(textColor, 0, fontFamily, fontEmbed),
|
||||
]);
|
||||
resources.skin.put("text", [
|
||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||
]);
|
||||
resources.skin.put("scroll.vertical", [
|
||||
haxework.view.skin.Skin.scrollVertical(lightColor, darkColor),
|
||||
]);
|
||||
resources.skin.put("text.header", [
|
||||
Skin.color(0x000000, 0.1),
|
||||
Skin.border(lightColor, 1, 2),
|
||||
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||
Skin.geometry(new Geometry().setPadding([50, 8]).setMargin([0, 0, 0, 30])),
|
||||
]);
|
||||
resources.skin.put("button", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, bigFontSize, fontFamily, fontEmbed),
|
||||
Skin.size(250, 50),
|
||||
]);
|
||||
resources.skin.put("text.box", [
|
||||
Skin.color(0x000000, 0.1),
|
||||
Skin.border(lightColor, 1, 2),
|
||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||
]);
|
||||
resources.skin.put("text.box.active", [
|
||||
Skin.color(0x55aa55),
|
||||
Skin.border(0x88dd88, 1, 2),
|
||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||
]);
|
||||
resources.skin.put("button.simple", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||
]);
|
||||
resources.skin.put("button.simple.active", [
|
||||
Skin.buttonColor(lightColor, activeColor),
|
||||
Skin.text(activeColor, baseFontSize, fontFamily, fontEmbed),
|
||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||
]);
|
||||
resources.skin.put("button.tab", [
|
||||
Skin.tabColor(lightColor),
|
||||
Skin.text(textColor, baseFontSize, fontFamily, fontEmbed),
|
||||
Skin.geometry(new Geometry().setPadding([25, 8])),
|
||||
]);
|
||||
resources.skin.put("border", [
|
||||
Skin.border(borderColor, 1, 2),
|
||||
]);
|
||||
resources.skin.put("scroll", [
|
||||
Skin.scrollVertical(lightColor, ColorUtil.diff(lightColor, 128)),
|
||||
]);
|
||||
resources.skin.put("button.level", [
|
||||
Skin.buttonColor(lightColor),
|
||||
Skin.text(textColor, veryBigFontSize, fontFamily, fontEmbed),
|
||||
Skin.size(64, 64),
|
||||
]);
|
||||
|
||||
resources.skin.put("container", [
|
||||
Skin.geometry(new Geometry().setSize("100%", "100%")),
|
||||
Skin.layout(new Layout().setAlign(CENTER, MIDDLE)),
|
||||
Skin.color(darkColor),
|
||||
]);
|
||||
resources.skin.put("panel", [
|
||||
Skin.geometry(new Geometry().setSize("100%", -1).setPadding([10, 5])),
|
||||
Skin.layout(new Layout().setAlign(NONE, MIDDLE)),
|
||||
Skin.color(lightColor),
|
||||
]);
|
||||
resources.skin.put("window", [
|
||||
Skin.color(darkColor),
|
||||
Skin.border(borderColor, 1, 2),
|
||||
Skin.geometry(new Geometry().setPadding(2)),
|
||||
]);
|
||||
resources.skin.put("window.close", [
|
||||
Skin.size(36, 36),
|
||||
new ButtonSVGSkin(Assets.getText("resources/image/icon/window-close-solid.svg"), lightColor),
|
||||
]);
|
||||
resources.skin.put("line", [
|
||||
Skin.color(borderColor),
|
||||
]);
|
||||
|
||||
registerButton("settings", "cog-solid.svg");
|
||||
registerButton("close", "times-circle-solid.svg");
|
||||
registerButton("next", "arrow-alt-circle-right-solid.svg");
|
||||
registerButton("start", "play-circle-solid.svg");
|
||||
registerButton("login", "sign-in-solid.svg");
|
||||
registerButton("logout", "sign-out-solid.svg");
|
||||
}
|
||||
}
|
||||
33
src/client/haxe/ru/m/tankz/bundle/ClientLevelSource.hx
Normal file
33
src/client/haxe/ru/m/tankz/bundle/ClientLevelSource.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class ConfigBundle implements IConfigBundle {
|
||||
|
||||
public function get(type:GameType):Config {
|
||||
if (!_cache.exists(type)) {
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('resources/config/${type}.yaml'), Parser.options().useObjects());
|
||||
var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
|
||||
_cache.set(type, Config.fromSource(type, source));
|
||||
}
|
||||
return _cache.get(type);
|
||||
|
||||
@@ -1,19 +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 new() {}
|
||||
|
||||
public function get(id:PackId):LevelPack {
|
||||
var bytes = Assets.getBytes('levels/${id}.zip');
|
||||
return {
|
||||
id: id,
|
||||
data: LevelUtil.unpack(bytes),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
|
||||
class HumanControl extends Control {
|
||||
|
||||
@:provide static var storage:SettingsStorage;
|
||||
@@ -18,7 +20,7 @@ class HumanControl extends Control {
|
||||
private var binding:Map<DeviceType, Map<DeviceAction, TankAction>>;
|
||||
|
||||
private var moveQueue:Array<Direction>;
|
||||
private var shotTimer:Timer;
|
||||
private var shotTimers:Map<Int, Timer>;
|
||||
|
||||
public function new(playerId:PlayerId, controlIndex:Int) {
|
||||
super(playerId);
|
||||
@@ -32,6 +34,16 @@ class HumanControl extends Control {
|
||||
binding.get(bind.device).set(bind.action, action);
|
||||
}
|
||||
moveQueue = [];
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function hasDevice(device:DeviceType):Bool {
|
||||
for (d in binding.keys()) {
|
||||
if (d.equals(device)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function onDeviceAction(device:DeviceType, action:DeviceAction, on:Bool):Void {
|
||||
@@ -49,10 +61,10 @@ class HumanControl extends Control {
|
||||
super.stop();
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
moveQueue = [];
|
||||
if (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
for (timer in shotTimers) {
|
||||
timer.stop();
|
||||
}
|
||||
shotTimers = new Map();
|
||||
}
|
||||
|
||||
public function toggleAction(action:TankAction, on:Bool):Void {
|
||||
@@ -66,17 +78,19 @@ class HumanControl extends Control {
|
||||
moveQueue.remove(direction);
|
||||
}
|
||||
updateMove();
|
||||
case TankAction.SHOT:
|
||||
case TankAction.SHOT(weapon):
|
||||
if (on) {
|
||||
if (shotTimer == null) {
|
||||
shotTimer = new Timer(300);
|
||||
shotTimer.run = shot;
|
||||
shot();
|
||||
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 (shotTimer != null) {
|
||||
shotTimer.stop();
|
||||
shotTimer = null;
|
||||
if (shotTimers.exists(weapon)) {
|
||||
shotTimers.get(weapon).stop();
|
||||
shotTimers.remove(weapon);
|
||||
}
|
||||
}
|
||||
case TankAction.STOP:
|
||||
@@ -96,7 +110,9 @@ class HumanControl extends Control {
|
||||
}
|
||||
}
|
||||
|
||||
private function shot():Void {
|
||||
action(SHOT);
|
||||
private function shooter(weapon:Int):Void -> Void {
|
||||
return function():Void {
|
||||
action(SHOT(weapon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
11
src/client/haxe/ru/m/tankz/game/GameInit.hx
Normal file
@@ -0,0 +1,11 @@
|
||||
package ru.m.tankz.game;
|
||||
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
|
||||
enum GameInit {
|
||||
LOCAL(start:Start);
|
||||
NETWORK(network:NetworkManager);
|
||||
RECORD(record:GameRecord);
|
||||
}
|
||||
@@ -1,32 +1,42 @@
|
||||
package ru.m.tankz.local;
|
||||
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.record.GameRecorder;
|
||||
import ru.m.tankz.local.LocalControlFactory;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class LocalGame extends GameRunner {
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
private var recorder:GameRecorder;
|
||||
|
||||
public function new(state:GameState, level:LevelConfig) {
|
||||
super(state, level);
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
public function new(start:Start) {
|
||||
super(start);
|
||||
controlFactory = new LocalControlFactory();
|
||||
recorder = new GameRecorder();
|
||||
connect(recorder);
|
||||
}
|
||||
|
||||
override public function onGameEvent(event:GameEvent):Void {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case GameEvent.COMPLETE(_, _):
|
||||
disconnect(recorder);
|
||||
recorder.onGameEvent(event); //ToDo:
|
||||
recordStorage.save(recorder.record);
|
||||
case 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
src/client/haxe/ru/m/tankz/local/StageCaller.hx
Normal file
31
src/client/haxe/ru/m/tankz/local/StageCaller.hx
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
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.game.GameState;
|
||||
import ru.m.tankz.network.NetworkControlFactory;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
@@ -14,7 +14,7 @@ class NetworkGame extends Game {
|
||||
private var network:NetworkManager;
|
||||
|
||||
public function new(network:NetworkManager) {
|
||||
super(new GameState(network.room.game.type, 0), null);
|
||||
super(network.room.game.type);
|
||||
this.network = network;
|
||||
this.controlFactory = new NetworkControlFactory();
|
||||
network.gameEventSignal.connect(onGameEventProto);
|
||||
@@ -38,12 +38,12 @@ class NetworkGame extends Game {
|
||||
}
|
||||
}
|
||||
|
||||
override public function start():Void {
|
||||
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) {
|
||||
state.controls.push({playerId: [slot.slot.team, slot.slot.index], control: "human-0"});
|
||||
start.state.controls.push({playerId: [slot.slot.team, slot.slot.index], controller: HUMAN(0)});
|
||||
}
|
||||
super.start();
|
||||
super.onStart(start);
|
||||
}
|
||||
|
||||
override public function dispose():Void {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package ru.m.tankz.network;
|
||||
|
||||
import ru.m.tankz.proto.game.GameEventProto;
|
||||
import ru.m.tankz.proto.room.SlotProto;
|
||||
import ru.m.tankz.proto.room.SlotRequest;
|
||||
import haxe.Serializer;
|
||||
import haxework.signal.Signal;
|
||||
import hw.signal.Signal;
|
||||
import ru.m.connect.IConnection;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
import ru.m.tankz.proto.game.GameEventProto;
|
||||
import ru.m.tankz.proto.pack.GameEventRequest;
|
||||
import ru.m.tankz.proto.pack.GameEventResponse;
|
||||
import ru.m.tankz.proto.pack.LoginRequest;
|
||||
@@ -21,8 +19,11 @@ 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>;
|
||||
|
||||
@@ -35,7 +36,9 @@ enum ConnectionState {
|
||||
ERROR(error:Dynamic);
|
||||
}
|
||||
|
||||
class NetworkManager {
|
||||
@:provide class NetworkManager {
|
||||
|
||||
private static inline var TAG = "NetworkManager";
|
||||
|
||||
public var state(default, null):ConnectionState;
|
||||
public var room(default, null):RoomProto;
|
||||
@@ -48,6 +51,7 @@ class NetworkManager {
|
||||
|
||||
@:provide private var connection:ClientConnection;
|
||||
@:provide private var storage:NetworkStorage;
|
||||
@:provide private var settings:SettingsStorage;
|
||||
|
||||
private var reconnectTimer:Timer;
|
||||
private var reconnectDelay:Int;
|
||||
@@ -61,10 +65,26 @@ class NetworkManager {
|
||||
updateState(OFFLINE);
|
||||
connection.handler.connect(onConnectionEvent);
|
||||
connection.receiveHandler.connect(onResponse);
|
||||
connect();
|
||||
if (settings.enableNetwork) {
|
||||
connect();
|
||||
}
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value):
|
||||
if (value) {
|
||||
connect();
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function updateState(value:ConnectionState):Void {
|
||||
L.d(TAG, 'State: ${value}');
|
||||
state = value;
|
||||
stateSignal.emit(value);
|
||||
}
|
||||
@@ -131,6 +151,10 @@ class NetworkManager {
|
||||
}
|
||||
}
|
||||
|
||||
private function disconnect():Void {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
updateState(switch event {
|
||||
case CONNECTED: CONNECTED;
|
||||
@@ -145,7 +169,9 @@ class NetworkManager {
|
||||
login(user.name, user.uuid);
|
||||
}
|
||||
case DISCONNECTED | ERROR(_):
|
||||
reconnect();
|
||||
if (settings.enableNetwork) {
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import haxework.view.IView;
|
||||
import hw.view.IView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import hw.view.utils.DrawUtil;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import haxe.Timer;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.SpriteView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.SpriteView;
|
||||
import promhx.Promise;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.animate.AnimateManager;
|
||||
import ru.m.animate.OnceAnimate;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.config.Config;
|
||||
@@ -31,6 +33,7 @@ class Render extends SpriteView implements IRender {
|
||||
private var mapWidth(get, null):Float;
|
||||
private var mapHeight(get, null):Float;
|
||||
|
||||
private var container:Sprite;
|
||||
private var backgroundLayer:Sprite;
|
||||
private var groundLayer:Sprite;
|
||||
private var entryLayer:Sprite;
|
||||
@@ -38,20 +41,25 @@ class Render extends SpriteView implements IRender {
|
||||
private var upperLayer:Sprite;
|
||||
|
||||
private var items:Map<Int, IRenderItem>;
|
||||
private var paused:Bool;
|
||||
|
||||
@:provide private static var animateManager:AnimateManager;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
items = new Map();
|
||||
container = new Sprite();
|
||||
content.addChild(container);
|
||||
backgroundLayer = new Sprite();
|
||||
groundLayer = new Sprite();
|
||||
entryLayer = new Sprite();
|
||||
upLayer = new Sprite();
|
||||
upperLayer = new Sprite();
|
||||
content.addChild(backgroundLayer);
|
||||
content.addChild(groundLayer);
|
||||
content.addChild(entryLayer);
|
||||
content.addChild(upLayer);
|
||||
content.addChild(upperLayer);
|
||||
container.addChild(backgroundLayer);
|
||||
container.addChild(groundLayer);
|
||||
container.addChild(entryLayer);
|
||||
container.addChild(upLayer);
|
||||
container.addChild(upperLayer);
|
||||
reset();
|
||||
}
|
||||
|
||||
@@ -65,15 +73,15 @@ class Render extends SpriteView implements IRender {
|
||||
|
||||
private function set_config(value:Config):Config {
|
||||
config = value;
|
||||
setContentSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
toRedraw();
|
||||
return config;
|
||||
}
|
||||
|
||||
private function set_gridSize(value:GridSize):GridSize {
|
||||
gridSize = value;
|
||||
setContentSize(mapWidth, mapHeight, "render");
|
||||
drawBackground();
|
||||
toRedraw();
|
||||
return gridSize;
|
||||
}
|
||||
|
||||
@@ -81,10 +89,19 @@ class Render extends SpriteView implements IRender {
|
||||
var g:Graphics = backgroundLayer.graphics;
|
||||
g.clear();
|
||||
g.beginFill(0x000000);
|
||||
g.lineStyle(2, 0xcccccc);
|
||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
||||
g.endFill();
|
||||
}
|
||||
|
||||
override public function redraw():Void {
|
||||
super.redraw();
|
||||
var scale = Math.min(width / mapWidth, height / mapHeight);
|
||||
container.scaleX = container.scaleY = scale;
|
||||
container.x = (width - (mapWidth * scale)) / 2;
|
||||
container.y = (height - (mapHeight * scale)) / 2;
|
||||
}
|
||||
|
||||
public function draw():Void {
|
||||
for (item in items) {
|
||||
item.update();
|
||||
@@ -92,7 +109,9 @@ class Render extends SpriteView implements IRender {
|
||||
}
|
||||
|
||||
private function onEnterFrame(event:Event):Void {
|
||||
draw();
|
||||
if (!paused) {
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
private function clearLayer(layer:DisplayObjectContainer) {
|
||||
@@ -115,11 +134,15 @@ class Render extends SpriteView implements IRender {
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(_, level):
|
||||
gridSize = level.size;
|
||||
case START(start):
|
||||
animateManager.playing = true;
|
||||
gridSize = start.level.size;
|
||||
content.addEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case COMPLETE(_, _):
|
||||
case COMPLETE(_):
|
||||
content.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
|
||||
case PAUSE(paused):
|
||||
this.paused = paused;
|
||||
animateManager.playing = !paused;
|
||||
case SPAWN(BRICK(bricks)):
|
||||
drawBackground();
|
||||
for (brick in bricks) {
|
||||
@@ -144,13 +167,16 @@ class Render extends SpriteView implements IRender {
|
||||
item.skin = tankConfig.skin;
|
||||
item.hits = info.hits;
|
||||
item.bonus = info.bonus;
|
||||
item.boat = info.boat;
|
||||
item.name = info.name == null ? "" : info.name;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
playAnimate(item.rect.center, AnimateBundle.tankSpawn());
|
||||
case SPAWN(BULLET(id, rect, playerId, piercing)):
|
||||
var item = new BulletRenderItem(rect, piercing);
|
||||
case SPAWN(BULLET(id, rect, playerId, skin, color)):
|
||||
var item = new BulletRenderItem(rect);
|
||||
item.color = color;
|
||||
item.skin = skin;
|
||||
items.set(id, item);
|
||||
entryLayer.addChild(item.view);
|
||||
item.update();
|
||||
@@ -180,12 +206,13 @@ class Render extends SpriteView implements IRender {
|
||||
var item = items[id];
|
||||
cast(item, TankRenderItem).moves = false;
|
||||
}
|
||||
case CHANGE(TANK(id, type, hits, bonus)):
|
||||
case CHANGE(TANK(id, type, hits, bonus, boat)):
|
||||
if (items.exists(id)) {
|
||||
var item:TankRenderItem = cast items[id];
|
||||
item.skin = config.getTank(type).skin;
|
||||
item.hits = hits;
|
||||
item.bonus = bonus;
|
||||
item.boat = boat;
|
||||
}
|
||||
case CHANGE(TANK_PROTECT(id, state)):
|
||||
if (items.exists(id)) {
|
||||
@@ -207,9 +234,7 @@ class Render extends SpriteView implements IRender {
|
||||
var item = items[id];
|
||||
entryLayer.removeChild(item.view);
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
if (shot.score != null) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(BULLET(id)):
|
||||
@@ -226,18 +251,14 @@ class Render extends SpriteView implements IRender {
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
playAnimate(item.rect.center, AnimateBundle.tankBoom());
|
||||
if (shot.score != null) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
showScore(item.rect.center, shot.score);
|
||||
cast(item, EagleRenderItem).death = true;
|
||||
}
|
||||
case DESTROY(BONUS(id, shot)):
|
||||
if (items.exists(id)) {
|
||||
var item = items[id];
|
||||
upperLayer.removeChild(item.view);
|
||||
if (shot.score != null) {
|
||||
showScore(item.rect.center, shot.score);
|
||||
}
|
||||
showScore(item.rect.center, shot.score);
|
||||
items.remove(id);
|
||||
}
|
||||
case DESTROY(CELL(id, x, y, shot)):
|
||||
@@ -266,15 +287,17 @@ class Render extends SpriteView implements IRender {
|
||||
});
|
||||
}
|
||||
|
||||
private function showScore(point:Point, score:Int):Void {
|
||||
var view:LabelView = new LabelView();
|
||||
view.skinId = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
private function showScore(point:Point, score:Null<Int>):Void {
|
||||
if (score != null && score != 0) {
|
||||
var view:LabelView = new LabelView();
|
||||
view.style = "text";
|
||||
view.text = Std.string(score);
|
||||
view.update();
|
||||
view.redraw();
|
||||
view.x = point.x - view.width / 2;
|
||||
view.y = point.y - view.height / 2;
|
||||
upperLayer.addChild(view.content);
|
||||
Timer.delay(function() upperLayer.removeChildSafety(view.content), 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
29
src/client/haxe/ru/m/tankz/render/RenderUtil.hx
Normal file
@@ -0,0 +1,29 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class RenderUtil {
|
||||
|
||||
public static function eagleImage(death:Bool = false):BitmapData {
|
||||
var suffix = death ? '-death' : '';
|
||||
return Assets.getBitmapData('resources/image/eagle/eagle${suffix}.png');
|
||||
}
|
||||
|
||||
public static function tankImage(skin:String, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/tank/${skin}-${frame}.png');
|
||||
}
|
||||
|
||||
public static function bonusImage(type:BonusType):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bonus/${type}.png');
|
||||
}
|
||||
|
||||
public static function bulletImage(skin:String):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/bullet/${skin}.png');
|
||||
}
|
||||
|
||||
public static function brickImage(type:BrickType, frame:Int = 0):BitmapData {
|
||||
return Assets.getBitmapData('resources/image/map/${type}${frame > 0 ? ("-" + frame) : ""}.png');
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,28 @@ import flash.display.Bitmap;
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.PixelSnapping;
|
||||
import openfl.Assets;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BitmapRenderItem extends RenderItem {
|
||||
public var image(default, set):String;
|
||||
public var image(default, set):BitmapData;
|
||||
|
||||
private var bitmapData:BitmapData;
|
||||
private var bitmap:Bitmap;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.AUTO, true);
|
||||
this.bitmap = new Bitmap(null, PixelSnapping.NEVER, false);
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private function set_image(value:String):String {
|
||||
private function set_image(value:BitmapData):BitmapData {
|
||||
if (image != value) {
|
||||
image = value;
|
||||
bitmapData = Assets.getBitmapData(image);
|
||||
bitmap.bitmapData = bitmapData;
|
||||
bitmap.bitmapData = image;
|
||||
bitmap.width = rect.width;
|
||||
bitmap.height = rect.height;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class BonusRenderItem extends BitmapRenderItem {
|
||||
private function set_type(value:BonusType):BonusType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
image = 'resources/image/bonus/${type}.png';
|
||||
image = RenderUtil.bonusImage(type);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,88 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.Shape;
|
||||
import openfl.Assets;
|
||||
import openfl.display.DisplayObject;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.GridPoint;
|
||||
import ru.m.geom.Rectangle;
|
||||
import ru.m.tankz.Type.BrickType;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
enum BrickState {
|
||||
UNBROKEN;
|
||||
BROKEN;
|
||||
DESTROYED;
|
||||
}
|
||||
class BrickBitmapBundle {
|
||||
|
||||
class BrickRenderItem extends RenderItem {
|
||||
private var data:Map<String, BitmapData>;
|
||||
|
||||
public var type(default, set):BrickType;
|
||||
public var state(get, never):BrickState;
|
||||
|
||||
private var image:BitmapData;
|
||||
private var shape:Shape;
|
||||
private var cells:Array<Point>;
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
this.shape = new Shape();
|
||||
cells = [
|
||||
new Point(0, 0),
|
||||
new Point(0, 1),
|
||||
new Point(1, 0),
|
||||
new Point(1, 1),
|
||||
];
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
public function new() {
|
||||
data = new Map();
|
||||
}
|
||||
|
||||
private function get_state():BrickState {
|
||||
private function resolve(type:BrickType, cells:Array<GridPoint>, frame:Int):BitmapData {
|
||||
return switch cells.length {
|
||||
case 0: DESTROYED;
|
||||
case 4: UNBROKEN;
|
||||
case _: BROKEN;
|
||||
case 0:
|
||||
null;
|
||||
case 4:
|
||||
type == "none" ? null : RenderUtil.brickImage(type, frame);
|
||||
case _:
|
||||
var image = RenderUtil.brickImage(type, frame);
|
||||
var result = new BitmapData(image.width, image.height, true, 0x00000000);
|
||||
for (point in cells) {
|
||||
var rect = new flash.geom.Rectangle(
|
||||
point.x * image.width / 2,
|
||||
point.y * image.height / 2,
|
||||
image.width / 2,
|
||||
image.height / 2);
|
||||
result.draw(image, null, null, null, rect);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return shape;
|
||||
public function get(type:BrickType, cells:Array<GridPoint>, frame:Int = 0):BitmapData {
|
||||
var key:String = '${type}_${cells.map(function(point) return point.toString()).join(",")}_${frame}';
|
||||
if (!data.exists(key)) {
|
||||
data.set(key, resolve(type, cells, frame));
|
||||
}
|
||||
return data.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
class BrickRenderItem extends BitmapRenderItem {
|
||||
|
||||
private static var bundle:BrickBitmapBundle = new BrickBitmapBundle();
|
||||
|
||||
public var type(default, set):BrickType;
|
||||
|
||||
private var cells:Array<GridPoint>;
|
||||
|
||||
private var frames:Int;
|
||||
private var currentFrame:Int;
|
||||
private var ticks:Int;
|
||||
|
||||
private static function buildCells():Array<GridPoint> {
|
||||
return [
|
||||
new GridPoint(0, 0),
|
||||
new GridPoint(0, 1),
|
||||
new GridPoint(1, 0),
|
||||
new GridPoint(1, 1),
|
||||
];
|
||||
}
|
||||
|
||||
public function new(rect:Rectangle, type:BrickType) {
|
||||
super(rect);
|
||||
cells = buildCells();
|
||||
this.frames = 1;
|
||||
this.currentFrame = 0;
|
||||
this.ticks = 0;
|
||||
this.type = type;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_type(value:BrickType):BrickType {
|
||||
if (type != value) {
|
||||
type = value;
|
||||
image = Assets.getBitmapData('resources/image/map/${type}.png');
|
||||
frames = switch type {
|
||||
case "water": 2;
|
||||
case _: 1;
|
||||
}
|
||||
cells = buildCells();
|
||||
redraw();
|
||||
}
|
||||
return type;
|
||||
@@ -68,24 +99,20 @@ class BrickRenderItem extends RenderItem {
|
||||
}
|
||||
|
||||
public function redraw():Void {
|
||||
shape.graphics.clear();
|
||||
if (type == "none") return;
|
||||
switch state {
|
||||
case UNBROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
shape.graphics.drawRect(0, 0, rect.width, rect.height);
|
||||
shape.graphics.endFill();
|
||||
case BROKEN:
|
||||
shape.graphics.beginBitmapFill(image);
|
||||
for (point in cells) {
|
||||
var x = point.x * (rect.width / 2);
|
||||
var y = point.y * (rect.width / 2);
|
||||
var width = rect.width / 2;
|
||||
var height = rect.height / 2;
|
||||
shape.graphics.drawRect(x, y, width, height);
|
||||
image = bundle.get(type, cells, currentFrame);
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (frames > 1) {
|
||||
if (++ticks >= 30) {
|
||||
ticks = 0;
|
||||
currentFrame++;
|
||||
if (currentFrame >= frames) {
|
||||
currentFrame = 0;
|
||||
}
|
||||
shape.graphics.endFill();
|
||||
case DESTROYED:
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package ru.m.tankz.render.item;
|
||||
|
||||
import hw.color.Color;
|
||||
import hw.view.utils.BitmapUtil;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
class BulletRenderItem extends BitmapRenderItem {
|
||||
public var piercing(default, set):Int = -1;
|
||||
public var color(default, default):Null<Color>;
|
||||
public var skin(default, set):String;
|
||||
|
||||
public function new(rect:Rectangle, piercing:Int) {
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
this.piercing = piercing;
|
||||
move(rect.position);
|
||||
}
|
||||
|
||||
private function set_piercing(value:Int):Int {
|
||||
if (piercing != value) {
|
||||
piercing = value;
|
||||
var type = piercing > 0 ? 'piercing' : 'normal';
|
||||
image = 'resources/image/bullet/${type}.png';
|
||||
private function set_skin(value:String):String {
|
||||
if (skin != value) {
|
||||
skin = value;
|
||||
var image = RenderUtil.bulletImage(skin);
|
||||
if (color != null) {
|
||||
image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
this.image = image;
|
||||
}
|
||||
return piercing;
|
||||
return skin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Sprite;
|
||||
import haxework.color.Color;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import hw.color.Color;
|
||||
import hw.view.utils.BitmapUtil;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
@@ -35,8 +35,8 @@ class EagleRenderItem extends BitmapRenderItem {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
if (protect) {
|
||||
protectView.x = (bitmapData.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (bitmapData.height - protectView.frames[0].image.height) / 2;
|
||||
protectView.x = (image.width - protectView.frames[0].image.width) / 2;
|
||||
protectView.y = (image.height - protectView.frames[0].image.height) / 2;
|
||||
}
|
||||
protectView.visible = protect;
|
||||
protectView.playing = protect;
|
||||
@@ -47,10 +47,9 @@ class EagleRenderItem extends BitmapRenderItem {
|
||||
private function set_death(value:Bool):Bool {
|
||||
if (death != value) {
|
||||
death = value;
|
||||
var suffix = death ? '-death' : '';
|
||||
image = 'resources/image/eagle/eagle${suffix}.png';
|
||||
image = RenderUtil.eagleImage(death);
|
||||
if (!color.zero) {
|
||||
bitmap.bitmapData = bitmapData = BitmapUtil.colorize(bitmapData, color);
|
||||
bitmap.bitmapData = image = BitmapUtil.colorize(image, color);
|
||||
}
|
||||
}
|
||||
return death;
|
||||
|
||||
@@ -2,14 +2,15 @@ package ru.m.tankz.render.item;
|
||||
|
||||
import flash.display.BitmapData;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.Shape;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
import flash.text.TextFieldAutoSize;
|
||||
import flash.text.TextFormat;
|
||||
import haxework.color.Color;
|
||||
import haxework.text.BitmapTextField;
|
||||
import haxework.view.utils.BitmapUtil;
|
||||
import openfl.Assets;
|
||||
import hw.color.Color;
|
||||
import hw.text.BitmapTextField;
|
||||
import hw.view.theme.ITheme;
|
||||
import hw.view.utils.BitmapUtil;
|
||||
import ru.m.animate.Animate;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
@@ -18,6 +19,7 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
public var skin(default, set):String;
|
||||
public var hits(default, set):Int;
|
||||
public var bonus(default, set):Bool;
|
||||
public var boat(default, set):Bool;
|
||||
public var moves(default, set):Bool;
|
||||
public var protect(default, set):Bool;
|
||||
public var name(default, set):String;
|
||||
@@ -26,8 +28,11 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
private var images:Array<BitmapData>;
|
||||
private var frame:Int;
|
||||
private var protectView:Animate;
|
||||
private var boatView:Shape;
|
||||
private var nameView:TextField;
|
||||
|
||||
@:provide static var theme:ITheme;
|
||||
|
||||
public function new(rect:Rectangle) {
|
||||
super(rect);
|
||||
container = new Sprite();
|
||||
@@ -35,6 +40,9 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
protectView = AnimateBundle.tankProtect();
|
||||
protectView.visible = false;
|
||||
container.addChild(protectView);
|
||||
boatView = buildBoatView();
|
||||
boatView.visible = false;
|
||||
container.addChild(boatView);
|
||||
nameView = buildNameView();
|
||||
container.addChild(nameView);
|
||||
move(rect.position);
|
||||
@@ -42,14 +50,21 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
|
||||
private function buildNameView():TextField {
|
||||
var result = new BitmapTextField();
|
||||
result.defaultTextFormat = new TextFormat(Style.fontFamily, 10, 0xffffff);
|
||||
result.embedFonts = Style.fontEmbed;
|
||||
result.defaultTextFormat = new TextFormat(theme.font.name, 10, 0xffffff);
|
||||
result.embedFonts = theme.font.embed;
|
||||
result.autoSize = TextFieldAutoSize.LEFT;
|
||||
result.shadowColor = 0x000000;
|
||||
result.stroke = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function buildBoatView():Shape {
|
||||
var result = new Shape();
|
||||
result.graphics.lineStyle(4, Color.fromString("green"), 0.8);
|
||||
result.graphics.drawRoundRect(-1, -1, rect.width + 2, rect.height + 2, 10, 10);
|
||||
return result;
|
||||
}
|
||||
|
||||
override private function get_view():DisplayObject {
|
||||
return container;
|
||||
}
|
||||
@@ -59,8 +74,8 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
}
|
||||
|
||||
private function redraw():Void {
|
||||
var image1 = Assets.getBitmapData('resources/image/tank/${skin}-0.png');
|
||||
var image2 = Assets.getBitmapData('resources/image/tank/${skin}-1.png');
|
||||
var image1 = RenderUtil.tankImage(skin, 0);
|
||||
var image2 = RenderUtil.tankImage(skin, 1);
|
||||
var color1:Color = switch hits {
|
||||
case 1: 0x869C43;
|
||||
case 2: 0xDEAF80;
|
||||
@@ -106,6 +121,14 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
return bonus;
|
||||
}
|
||||
|
||||
private function set_boat(value:Bool):Bool {
|
||||
if (boat != value) {
|
||||
boat = value;
|
||||
boatView.visible = boat;
|
||||
}
|
||||
return boat;
|
||||
}
|
||||
|
||||
private function set_protect(value:Bool):Bool {
|
||||
if (protect != value) {
|
||||
protect = value;
|
||||
@@ -141,7 +164,7 @@ class TankRenderItem extends BitmapRenderItem {
|
||||
super.update();
|
||||
if (moves) {
|
||||
frame++;
|
||||
if (frame > images.length - 1) {
|
||||
if (frame >= images.length) {
|
||||
frame = 0;
|
||||
}
|
||||
bitmap.bitmapData = images[frame];
|
||||
|
||||
@@ -9,7 +9,7 @@ import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.IGame;
|
||||
|
||||
class SoundManager implements GameListener {
|
||||
@:provide class SoundManager implements GameListener {
|
||||
private static var TAG(default, never):String = "SoundManager";
|
||||
|
||||
#if flash
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class GameStorage extends SharedObjectStorage {
|
||||
@:provide class GameStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
|
||||
class NetworkStorage extends SharedObjectStorage {
|
||||
@:provide class NetworkStorage extends SharedObjectStorage {
|
||||
|
||||
public var user(get, set):User;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import haxe.DynamicAccess;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
|
||||
@:yield class RecordStorage extends SharedObjectStorage {
|
||||
@:provide class RecordStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 1;
|
||||
|
||||
@@ -23,17 +23,19 @@ import ru.m.tankz.game.record.GameRecord;
|
||||
super.delete('${id}.info');
|
||||
}
|
||||
|
||||
public function iterator():Iterator<GameRecordInfo> {
|
||||
public function list():Array<GameRecordInfo> {
|
||||
var result = [];
|
||||
var data:DynamicAccess<String> = so.data;
|
||||
for (id in data.keys()) {
|
||||
try {
|
||||
if (StringTools.endsWith(id, '.info')) {
|
||||
@yield return read(id);
|
||||
result.push(read(id));
|
||||
}
|
||||
} catch (error:Dynamic) {
|
||||
L.w("RecordStorage", 'read ', error);
|
||||
delete(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,50 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.storage.SharedObjectStorage;
|
||||
import haxework.utils.ObjectUtil;
|
||||
import hw.signal.Signal;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
import hw.utils.ObjectUtil;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.control.Binding;
|
||||
import ru.m.tankz.control.Control;
|
||||
|
||||
class SettingsStorage extends SharedObjectStorage {
|
||||
enum Setting {
|
||||
CONTROL(index:Int, value:Binding);
|
||||
DISPLAY_FPS(value:Bool);
|
||||
ENABLE_NETWORK(value:Bool);
|
||||
}
|
||||
|
||||
private static inline var VERSION = 3;
|
||||
@:provide class SettingsStorage extends SharedObjectStorage {
|
||||
|
||||
private static inline var VERSION = 4.1;
|
||||
|
||||
public var signal(default, null):Signal<Setting> = new Signal();
|
||||
|
||||
public var displayFPS(get, set):Bool;
|
||||
|
||||
private function get_displayFPS():Bool {
|
||||
return read("setting:display_fps");
|
||||
}
|
||||
|
||||
private function set_displayFPS(value:Bool):Bool {
|
||||
write("setting:display_fps", value);
|
||||
signal.emit(DISPLAY_FPS(value));
|
||||
return get_displayFPS();
|
||||
}
|
||||
|
||||
public var enableNetwork(get, set):Bool;
|
||||
|
||||
private function get_enableNetwork():Bool {
|
||||
return read("setting:enable_network");
|
||||
}
|
||||
|
||||
private function set_enableNetwork(value:Bool):Bool {
|
||||
write("setting:enable_network", value);
|
||||
signal.emit(ENABLE_NETWORK(value));
|
||||
return get_enableNetwork();
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super('settings_${VERSION}');
|
||||
@@ -23,44 +56,60 @@ class SettingsStorage extends SharedObjectStorage {
|
||||
|
||||
public function saveBinding(index:Int, value:Binding) {
|
||||
write('action:$index', value);
|
||||
signal.emit(CONTROL(index, value));
|
||||
}
|
||||
|
||||
public static function getDefaultBinding(index:Int):Binding {
|
||||
return ObjectUtil.clone(defaults.exists(index) ? defaults.get(index) : defaults.get(-1));
|
||||
var binding = (Device.isMobile() ? mobileDefaults : defaults).get(index);
|
||||
return binding != null ? ObjectUtil.clone(binding) : buildEmpty();
|
||||
}
|
||||
|
||||
public static function buildGamepadBinding(id:Int):Binding {
|
||||
var device = GAMEPAD(id);
|
||||
public static function buildDeviceBinding(device:DeviceType):Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => {device: device, action: DIRECTION(Direction.TOP)},
|
||||
MOVE(Direction.LEFT) => {device: device, action: DIRECTION(Direction.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: device, action: DIRECTION(Direction.BOTTOM)},
|
||||
MOVE(Direction.RIGHT) => {device: device, action: DIRECTION(Direction.RIGHT)},
|
||||
SHOT => {device: device, action: KEY(0)},
|
||||
SHOT(0) => {device: device, action: KEY(0)},
|
||||
SHOT(1) => {device: device, action: KEY(1)},
|
||||
SHOT(2) => {device: device, action: KEY(2)},
|
||||
];
|
||||
}
|
||||
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
-1 => [
|
||||
public static function buildEmpty():Binding {
|
||||
return [
|
||||
MOVE(Direction.TOP) => null,
|
||||
MOVE(Direction.LEFT) => null,
|
||||
MOVE(Direction.BOTTOM) => null,
|
||||
MOVE(Direction.RIGHT) => null,
|
||||
SHOT => null,
|
||||
],
|
||||
SHOT(0) => null,
|
||||
SHOT(1) => null,
|
||||
SHOT(2) => null,
|
||||
];
|
||||
}
|
||||
|
||||
private static var mobileDefaults:Map<Int, Binding> = [
|
||||
0 => buildDeviceBinding(SCREEN),
|
||||
];
|
||||
|
||||
private static var defaults:Map<Int, Binding> = [
|
||||
0 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.W)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.A)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.S)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.D)},
|
||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.SPACE)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.Q)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.E)},
|
||||
],
|
||||
1 => [
|
||||
MOVE(Direction.TOP) => {device: KEYBOARD, action: KEY(Keyboard.UP)},
|
||||
MOVE(Direction.LEFT) => {device: KEYBOARD, action: KEY(Keyboard.LEFT)},
|
||||
MOVE(Direction.BOTTOM) => {device: KEYBOARD, action: KEY(Keyboard.DOWN)},
|
||||
MOVE(Direction.RIGHT) => {device: KEYBOARD, action: KEY(Keyboard.RIGHT)},
|
||||
SHOT => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||
SHOT(0) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_0)},
|
||||
SHOT(1) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_1)},
|
||||
SHOT(2) => {device: KEYBOARD, action: KEY(Keyboard.NUMPAD_2)},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,85 +1,44 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import ru.m.tankz.game.IGame;
|
||||
import flash.events.KeyboardEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import haxework.resources.IResources;
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import hw.resources.IResources;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.group.VGroupView;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
|
||||
@:template class ClientView extends VGroupView {
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
@:view var username:LabelView;
|
||||
@:view("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var resources:IResources;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var game:IGame;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
public function init():Void {
|
||||
public function new():Void {
|
||||
super();
|
||||
resources.text.put('version', '${Const.VERSION}');
|
||||
resources.text.put('name', '${Const.NAME}');
|
||||
switcher = switcherView;
|
||||
network.stateSignal.connect(onConnectionState);
|
||||
onConnectionState(network.state);
|
||||
}
|
||||
|
||||
public function launch():Void {
|
||||
content.stage.stageFocusRect = false;
|
||||
content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void {
|
||||
switch event.keyCode {
|
||||
case Keyboard.ESCAPE:
|
||||
switcher.change(StartFrame.ID);
|
||||
case Keyboard.M:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case Keyboard.P:
|
||||
if (game != null) {
|
||||
game.pause = !game.pause;
|
||||
}
|
||||
}
|
||||
});
|
||||
switcher.change(StartFrame.ID);
|
||||
bus.signal.connect(onDeviceAction);
|
||||
switcher.change(MenuFrame.ID);
|
||||
}
|
||||
|
||||
private function onConnectionState(state:ConnectionState):Void {
|
||||
L.d("ClientView", 'onConnectionState: ${state}');
|
||||
switch state {
|
||||
case ONLINE(user):
|
||||
username.text = user.name;
|
||||
logoutButton.visible = true;
|
||||
loginButton.visible = false;
|
||||
case CONNECTED:
|
||||
username.text = "";
|
||||
logoutButton.visible = false;
|
||||
loginButton.visible = true;
|
||||
case ERROR(error):
|
||||
//L.e("ClientView", 'onConnectionState: ERROR', error);
|
||||
L.w("ClientView", 'onConnectionState: ERROR');
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.ESCAPE), true]:
|
||||
switcher.change(MenuFrame.ID);
|
||||
case [KEYBOARD, KEY(Keyboard.M), true]:
|
||||
soundManager.mute = !soundManager.mute;
|
||||
case _:
|
||||
username.text = "";
|
||||
logoutButton.visible = false;
|
||||
loginButton.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function login():Void {
|
||||
LoginPopup.instance.show().then(function(user:User):Void {
|
||||
L.d("Login", 'user: $user');
|
||||
});
|
||||
}
|
||||
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
}
|
||||
|
||||
private function close():Void {
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,20 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.frame.FrameSwitcher
|
||||
- $type: hw.view.frame.FrameSwitcher
|
||||
id: switcher
|
||||
geometry.size.stretch: true
|
||||
skinId: dark
|
||||
views:
|
||||
- id: start
|
||||
$type: ru.m.tankz.view.StartFrame
|
||||
- id: level
|
||||
$type: ru.m.tankz.view.LevelFrame
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.GameFrame
|
||||
- id: result
|
||||
$type: ru.m.tankz.view.ResultFrame
|
||||
- id: settings
|
||||
$type: ru.m.tankz.view.SettingsFrame
|
||||
- id: record
|
||||
$type: ru.m.tankz.view.RecordFrame
|
||||
- id: room_list
|
||||
$type: ru.m.tankz.view.network.RoomListFrame
|
||||
- id: room
|
||||
$type: ru.m.tankz.view.network.RoomFrame
|
||||
- $type: haxework.view.HGroupView
|
||||
skinId: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: settings
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.settings
|
||||
+onPress: $code:switcher.change('settings')
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 50%
|
||||
- id: username
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text
|
||||
- id: login
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.login
|
||||
+onPress: $code:login()
|
||||
- id: logout
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.logout
|
||||
+onPress: $code:logout()
|
||||
visible: false
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.width: 50%
|
||||
- id: close
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.close
|
||||
+onPress: $code:close()
|
||||
geometry.stretch: true
|
||||
style: dark
|
||||
factory:
|
||||
_menu_: {$class: ru.m.tankz.view.MenuFrame}
|
||||
_level_: {$class: ru.m.tankz.view.LevelFrame}
|
||||
_start_: {$class: ru.m.tankz.view.StartFrame}
|
||||
_game_: {$class: ru.m.tankz.view.GameFrame}
|
||||
_result_: {$class: ru.m.tankz.view.ResultFrame}
|
||||
_settings_: {$class: ru.m.tankz.view.SettingsFrame}
|
||||
_record_: {$class: ru.m.tankz.view.RecordFrame}
|
||||
_room_list_: {$class: ru.m.tankz.view.network.RoomListFrame}
|
||||
_room_: {$class: ru.m.tankz.view.network.RoomFrame}
|
||||
- $type: ru.m.tankz.view.common.NetworkStateView
|
||||
geometry.position: absolute
|
||||
geometry.hAlign: center
|
||||
geometry.margin.top: 2
|
||||
|
||||
@@ -1,109 +1,193 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.VGroupView;
|
||||
import hw.view.text.TextView;
|
||||
import ru.m.tankz.view.popup.PausePopup;
|
||||
import flash.ui.Keyboard;
|
||||
import ru.m.control.DeviceAction;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import hw.view.group.GroupView;
|
||||
import hw.view.layout.DefaultLayout;
|
||||
import hw.view.data.DataView;
|
||||
import hw.view.form.LabelView;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlBus;
|
||||
import ru.m.tankz.control.HumanControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.GameState.TeamState;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.game.record.GamePlayer;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.local.LocalGame;
|
||||
import ru.m.tankz.network.NetworkGame;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.game.GameView;
|
||||
import ru.m.tankz.view.GamepadView;
|
||||
import ru.m.tankz.view.gamepad.GamepadView;
|
||||
import ru.m.tankz.view.game.TeamView;
|
||||
import ru.m.tankz.view.game.PlayerView;
|
||||
import ru.m.tankz.render.IRender;
|
||||
|
||||
@:template class GameFrame extends VGroupView implements GameListener {
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class GameFrame extends FrameView<GameInit> implements GameListener {
|
||||
public static inline var ID = "game";
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
@:view("game") private var gameView(default, null):GameView;
|
||||
@:view private var gamepad(default, null):GamepadView;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var soundManager:SoundManager;
|
||||
@:provide var state:GameState;
|
||||
@:provide var record:GameRecord;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide static var soundManager:SoundManager;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
@:provide var game:IGame;
|
||||
@:provide static var bus:IControlBus;
|
||||
|
||||
public function init():Void {
|
||||
@:view private var render:IRender;
|
||||
@:view private var teams:DataView<TeamState, TeamView>;
|
||||
@:view private var level:TextView;
|
||||
@:view private var gamepad(default, null):GamepadView;
|
||||
|
||||
private var gamepadPlayerId:PlayerId;
|
||||
|
||||
private var game:IGame;
|
||||
private var recorder:GameRecord;
|
||||
|
||||
public function new() {
|
||||
super(id, new DefaultLayout());
|
||||
bus.connect(gamepad);
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
override public function onShow(data:GameInit):Void {
|
||||
gamepad.visible = false;
|
||||
// ToDo:
|
||||
for (i in 0...1) {
|
||||
for (bind in settings.getBinding(i)) {
|
||||
switch bind.device {
|
||||
case GAMEPAD(GamepadView.ID):
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
case _:
|
||||
game = switch data {
|
||||
case LOCAL(start): new LocalGame(start);
|
||||
case NETWORK(network): new NetworkGame(network);
|
||||
case RECORD(record): new GamePlayer(record);
|
||||
}
|
||||
soundManager.config = game.config;
|
||||
render.config = game.config;
|
||||
game.connect(render);
|
||||
game.connect(soundManager);
|
||||
game.connect(this);
|
||||
game.start();
|
||||
// TODO:
|
||||
for (control in game.controls) {
|
||||
if (Std.is(control, HumanControl)) {
|
||||
if (cast(control, HumanControl).hasDevice(SCREEN)) {
|
||||
gamepadPlayerId = control.playerId;
|
||||
gamepad.visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
gameView.type = game.type;
|
||||
soundManager.config = game.config;
|
||||
gameView.render.config = game.config;
|
||||
game.connect(gameView.render);
|
||||
game.connect(soundManager);
|
||||
if (gameView.panel != null) {
|
||||
game.connect(gameView.panel);
|
||||
}
|
||||
game.connect(this);
|
||||
game.start();
|
||||
bus.signal.connect(onDeviceAction);
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
if (game != null) {
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
gameView.render.reset();
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case COMPLETE(state, winner):
|
||||
this.state = state;
|
||||
updateProgress(game, winner);
|
||||
stop();
|
||||
switcher.change(ResultFrame.ID);
|
||||
private function onDeviceAction(type:DeviceType, action:DeviceAction, state:Bool):Void {
|
||||
switch [type, action, state] {
|
||||
case [KEYBOARD, KEY(Keyboard.P), true]:
|
||||
game.pause = !game.pause;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo:
|
||||
private static function updateProgress(game:IGame, winner:TeamId):Void {
|
||||
var complete = true;
|
||||
for (rule in game.config.game.complete) {
|
||||
if (rule.team != null && rule.team != winner) {
|
||||
complete = false;
|
||||
private function stop():Void {
|
||||
bus.signal.disconnect(onDeviceAction);
|
||||
if (game != null) {
|
||||
game.dispose();
|
||||
game = null;
|
||||
}
|
||||
render.reset();
|
||||
}
|
||||
|
||||
private function findTeamView(id:TeamId):Null<TeamView> {
|
||||
for (view in teams.dataViews) {
|
||||
if (view.teamId == id) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
if (complete) {
|
||||
var progress = gameStorage.get(new PackId(game.state.type));
|
||||
progress.completeLevel(game.level.id, game.state.presetId);
|
||||
gameStorage.set(progress);
|
||||
return null;
|
||||
}
|
||||
|
||||
private function findPlayerView(id:PlayerId):Null<PlayerView> {
|
||||
var teamView = findTeamView(id.team);
|
||||
if (teamView != null) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.playerId == id) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(start):
|
||||
level.text = start.level.toLevelLabel();
|
||||
teams.data = [for (team in start.state.teams) team];
|
||||
// TODO: PlayerState default tank?
|
||||
for (teamView in teams.dataViews) {
|
||||
for (playerView in teamView.dataViews) {
|
||||
var tank = game.config.getPlayerTank(playerView.playerId);
|
||||
playerView.tank = {
|
||||
type: tank.type,
|
||||
skin: tank.skin,
|
||||
hits: 0,
|
||||
bonus: false,
|
||||
boat: false,
|
||||
color: game.config.getColor(playerView.playerId),
|
||||
};
|
||||
}
|
||||
}
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(TEAM_SCORE(teamId, score)):
|
||||
var view = findPlayerView([teamId, -1]);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case CHANGE(PLAYER_LIFE(playerId, life)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.life = life;
|
||||
}
|
||||
case CHANGE(PLAYER_SCORE(playerId, score)):
|
||||
var view = findPlayerView(playerId);
|
||||
if (view != null) {
|
||||
view.score = score;
|
||||
}
|
||||
case SPAWN(TANK(id, rect, playerId, info)):
|
||||
if (gamepadPlayerId != null && playerId == gamepadPlayerId) {
|
||||
var tankConfig = game.config.getTank(info.type);
|
||||
gamepad.weapons = tankConfig.weapons;
|
||||
}
|
||||
case PAUSE(paused):
|
||||
if (paused) {
|
||||
PausePopup.instance.show().then(function(action) {
|
||||
switch action {
|
||||
case EXIT:
|
||||
switcher.change(LevelFrame.ID, game.level.packId);
|
||||
case RESUME | null:
|
||||
game.pause = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PausePopup.instance.close(null);
|
||||
}
|
||||
case COMPLETE(result):
|
||||
stop();
|
||||
switcher.change(ResultFrame.ID, result);
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
public function onHide():Void {
|
||||
override public function onHide():Void {
|
||||
stop();
|
||||
soundManager.stopAll();
|
||||
}
|
||||
|
||||
public function close():Void {
|
||||
switcher.change(LevelFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,48 @@
|
||||
---
|
||||
style: container
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
layout.overflow: true
|
||||
- id: game
|
||||
$type: hw.view.group.HGroupView
|
||||
geometry.stretch: true
|
||||
views:
|
||||
- id: game
|
||||
$type: ru.m.tankz.view.game.GameView
|
||||
- id: left
|
||||
$type: hw.view.group.GroupView
|
||||
layout.vAlign: middle
|
||||
geometry.height: 100%
|
||||
geometry.width: 15%
|
||||
- id: render
|
||||
$type: ru.m.tankz.render.Render
|
||||
style: render
|
||||
geometry.height: 100%
|
||||
geometry.width: 70%
|
||||
- id: right
|
||||
$type: hw.view.group.VGroupView
|
||||
geometry.height: 100%
|
||||
geometry.width: 15%
|
||||
geometry.padding: 5
|
||||
layout.vAlign: top
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: level
|
||||
$type: hw.view.text.TextView
|
||||
style: text.box
|
||||
geometry.width: 100%
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.height: 30%
|
||||
- id: teams
|
||||
$type: hw.view.data.DataView
|
||||
layout.margin: 3
|
||||
geometry.width: 100%
|
||||
factory: ~TeamView.viewFactory
|
||||
- id: gamepad
|
||||
$type: ru.m.tankz.view.GamepadView
|
||||
$type: ru.m.tankz.view.gamepad.GamepadView
|
||||
geometry.position: absolute
|
||||
geometry.size.stretch: true
|
||||
geometry.stretch: true
|
||||
visible: false
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.bars
|
||||
geometry.position: absolute
|
||||
geometry.hAlign: left
|
||||
geometry.vAlign: top
|
||||
geometry.margin: 10
|
||||
+onPress: ~function(_) game.pause = true
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Stage;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.events.TouchEvent;
|
||||
import haxework.signal.Signal;
|
||||
import haxework.view.skin.ISkin;
|
||||
import haxework.view.SpriteView;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.control.DeviceType;
|
||||
import ru.m.control.IControlDevice;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.geom.Rectangle;
|
||||
|
||||
typedef ActionArea = {
|
||||
var action:DeviceAction;
|
||||
var rect:Rectangle;
|
||||
}
|
||||
|
||||
class GamepadSkin implements ISkin<GamepadView> {
|
||||
|
||||
public var color(default, default):Int;
|
||||
|
||||
public function new(color:Int = 0) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:GamepadView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(0, 0.0);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
graphics.endFill();
|
||||
graphics.lineStyle(2, color);
|
||||
graphics.beginFill(color, 0.2);
|
||||
for (area in view.areas) {
|
||||
graphics.drawRect(area.rect.x, area.rect.y, area.rect.width, area.rect.height);
|
||||
}
|
||||
graphics.lineStyle();
|
||||
}
|
||||
}
|
||||
|
||||
class GamepadView extends SpriteView implements IControlDevice {
|
||||
public static var ID(default, never):Int = -128;
|
||||
|
||||
public var type(default, null):DeviceType;
|
||||
public var signal(default, null):Signal2<DeviceAction, Bool>;
|
||||
|
||||
public var areas(default, null):Array<ActionArea>;
|
||||
public var currentAreas(default, null):Map<Int, ActionArea>;
|
||||
|
||||
private var stage:Stage;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
type = GAMEPAD(ID);
|
||||
signal = new Signal2();
|
||||
areas = [];
|
||||
currentAreas = new Map();
|
||||
skin = [new GamepadSkin(0x00ff00)];
|
||||
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||
content.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
|
||||
}
|
||||
|
||||
private function onMouseDown(event:MouseEvent):Void {
|
||||
onMouseMove(event);
|
||||
stage = content.stage;
|
||||
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onMouseMove(event:MouseEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(-1, point);
|
||||
}
|
||||
|
||||
private function onMouseUp(event:MouseEvent):Void {
|
||||
endTouch(-1);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
}
|
||||
|
||||
private function onTouchBegin(event:TouchEvent):Void {
|
||||
onTouchMove(event);
|
||||
stage = content.stage;
|
||||
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
|
||||
private function onTouchMove(event:TouchEvent):Void {
|
||||
var point = new Point(event.localX, event.localY);
|
||||
updateTouch(event.touchPointID, point);
|
||||
}
|
||||
|
||||
private function onTouchEnd(event:TouchEvent):Void {
|
||||
endTouch(event.touchPointID);
|
||||
if (Lambda.count(currentAreas) == 0) {
|
||||
stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
|
||||
stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateTouch(pointID:Int, point:Point):Void {
|
||||
if (currentAreas.exists(pointID)) {
|
||||
var area = currentAreas[pointID];
|
||||
if (!area.rect.contain(point)) {
|
||||
currentAreas.remove(pointID);
|
||||
signal.emit(area.action, false);
|
||||
}
|
||||
}
|
||||
for (area in areas) {
|
||||
if (area.rect.contain(point)) {
|
||||
currentAreas[pointID] = area;
|
||||
signal.emit(area.action, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function endTouch(pointID:Int):Void {
|
||||
if (currentAreas.exists(pointID)) {
|
||||
signal.emit(currentAreas[pointID].action, false);
|
||||
currentAreas.remove(pointID);
|
||||
}
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
areas = [];
|
||||
var size = Math.min(width, height) / 7;
|
||||
var padding = size / 2;
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.TOP),
|
||||
rect: new Rectangle(padding + size, height - size * 3 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.LEFT),
|
||||
rect: new Rectangle(padding, height - size * 2 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.BOTTOM),
|
||||
rect: new Rectangle(padding + size, height - size - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: DIRECTION(Direction.RIGHT),
|
||||
rect: new Rectangle(padding + size * 2, height - size * 2 - padding, size, size)
|
||||
});
|
||||
areas.push({
|
||||
action: KEY(0),
|
||||
rect: new Rectangle(width - size * 1.5 - padding, height - size * 2 - padding, size, size)
|
||||
});
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
stage = null;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +1,63 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.ButtonView;
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import hw.view.data.DataView;
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.local.LocalGame;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.popup.LevelPopup;
|
||||
import ru.m.tankz.Type.PackId;
|
||||
|
||||
@:template class LevelFrame extends VGroupView {
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class LevelFrame extends FrameView<PackId> {
|
||||
public static inline var ID = "level";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
@:provide static var configBundle:IConfigBundle;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
@:view var header:LabelView;
|
||||
@:view var levels:DataView<LevelConfig, ButtonView>;
|
||||
|
||||
@:provide var state:GameState;
|
||||
@:provide var game:IGame;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var levelBundle:ILevelBundle;
|
||||
@:provide var storage:GameStorage;
|
||||
|
||||
private var pack:LevelPack;
|
||||
private var levelPopup:LevelPopup;
|
||||
private var config(get, never):Config;
|
||||
|
||||
public function onShow():Void {
|
||||
header.text = state.type;
|
||||
pack = levelBundle.get(new PackId(state.type));
|
||||
levels.data = pack.data;
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function start(level:LevelConfig, preset:GamePreset, control:ControlPreset):Void {
|
||||
state.presetId = preset.id;
|
||||
state.controls = control.values;
|
||||
game = new LocalGame(state, level);
|
||||
switcher.change(GameFrame.ID);
|
||||
private function get_config():Config {
|
||||
return configBundle.get(pack.id.type);
|
||||
}
|
||||
|
||||
override public function onShow(data:PackId):Void {
|
||||
header.text = data.toPackLabel();
|
||||
pack = levelBundle.get(data);
|
||||
levels.data = pack.data;
|
||||
}
|
||||
|
||||
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
||||
var progress = storage.get(pack.id);
|
||||
var result = new ButtonView();
|
||||
result.skinId = "button.level";
|
||||
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||
result.style = "button.level";
|
||||
var presetsLine = [for (p in config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||
result.text = '${level.id}\n${presetsLine}';
|
||||
result.disabled = !progress.isLevelAvailable(level.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||
if (!storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||
return;
|
||||
if (storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||
switcher.change(StartFrame.ID, {
|
||||
state: new GameState(pack.id.type),
|
||||
level: level,
|
||||
});
|
||||
}
|
||||
if (levelPopup == null) {
|
||||
levelPopup = new LevelPopup();
|
||||
}
|
||||
levelPopup.setData(
|
||||
level,
|
||||
state.config.presets,
|
||||
state.config.controls,
|
||||
storage.get(pack.id)
|
||||
);
|
||||
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: header
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.header
|
||||
- id: levels
|
||||
$type: haxework.view.DataView
|
||||
geometry.size.width: 100%
|
||||
$type: hw.view.data.DataView
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
overflow.y: scroll
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
$type: hw.view.layout.TailLayout
|
||||
rowSize: 10
|
||||
margin: 5
|
||||
factory: $this:levelViewFactory
|
||||
+onItemSelect: $this:onLevelSelect
|
||||
factory: ~levelViewFactory
|
||||
+onItemSelect: ~onLevelSelect
|
||||
geometry.padding: 10
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
94
src/client/haxe/ru/m/tankz/view/MenuFrame.hx
Normal file
94
src/client/haxe/ru/m/tankz/view/MenuFrame.hx
Normal file
@@ -0,0 +1,94 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import hw.view.data.DataView;
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.common.PackView;
|
||||
import ru.m.tankz.view.network.RoomFrame;
|
||||
import ru.m.tankz.view.network.RoomListFrame;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class MenuFrame extends FrameView<Dynamic> {
|
||||
|
||||
public static var ID(default, never):String = "menu";
|
||||
|
||||
@:provide static var gameInit:GameInit;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var network:NetworkManager;
|
||||
@:provide static var appUpdater:Updater;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
@:view var packs:DataView<PackId, PackView>;
|
||||
@:view("update") var updateButton:ButtonView;
|
||||
@:view("network") var networkButton:ButtonView;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
appUpdater.check().then(function(update:Bool) {
|
||||
updateButton.visible = update;
|
||||
if (update) {
|
||||
updateButton.text = 'Update ${appUpdater.bundle.version}';
|
||||
}
|
||||
}).catchError(function(error) {});
|
||||
var list = levelBundle.list();
|
||||
list.sort(function(a:PackId, b:PackId) return a.toPackLabel() > b.toPackLabel() ? 1 : -1);
|
||||
packs.data = list;
|
||||
networkButton.visible = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
super.onHide();
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case ENABLE_NETWORK(value): networkButton.visible = value;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function startGame(packId:PackId):Void {
|
||||
gameInit = LOCAL({state: new GameState(packId.type), level: null});
|
||||
switcher.change(LevelFrame.ID, packId);
|
||||
}
|
||||
|
||||
private function startNetwork():Void {
|
||||
switch network.state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
switcher.change(RoomFrame.ID, network.room);
|
||||
network.joinGame(network.room.game.id, true);
|
||||
} else {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
case CONNECTED:
|
||||
LoginPopup.instance.show().then(function(user):Void {
|
||||
if (user != null) {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
});
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function appUpdate():Void {
|
||||
appUpdater.download();
|
||||
}
|
||||
}
|
||||
61
src/client/haxe/ru/m/tankz/view/MenuFrame.yaml
Normal file
61
src/client/haxe/ru/m/tankz/view/MenuFrame.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
views:
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- $type: hw.view.group.VGroupView
|
||||
geometry.width: 100%
|
||||
layout.margin: 10
|
||||
layout.hAlign: center
|
||||
views:
|
||||
- $type: hw.view.form.LabelView
|
||||
text: $r:text:name
|
||||
style: font
|
||||
font.size: 100
|
||||
geometry.margin.bottom: 30
|
||||
- id: packs
|
||||
$type: hw.view.data.DataView
|
||||
geometry.width: 100%
|
||||
layout:
|
||||
$type: hw.view.layout.TailLayout
|
||||
rowSize: 2
|
||||
margin: 10
|
||||
factory: ~ru.m.tankz.view.common.PackView.factory
|
||||
+onDataSelect: ~startGame
|
||||
- $type: hw.view.SpriteView
|
||||
style: line
|
||||
geometry.width: 250
|
||||
geometry.margin: [0, 10]
|
||||
visible: false
|
||||
- $type: hw.view.form.ButtonView
|
||||
+onPress: ~switcher.change('record')
|
||||
text: Records
|
||||
visible: false
|
||||
- id: network
|
||||
$type: hw.view.form.ButtonView
|
||||
+onPress: ~startNetwork()
|
||||
text: Network (alpha)
|
||||
visible: false
|
||||
- $type: hw.view.form.LabelView
|
||||
geometry.hAlign: right
|
||||
geometry.vAlign: top
|
||||
geometry.position: absolute
|
||||
geometry.margin: [0, 20, 20, 0]
|
||||
style: text.box
|
||||
text: $r:text:version
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- id: settings
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.settings
|
||||
+onPress: ~switcher.change('settings')
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- id: update
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.active
|
||||
+onPress: ~appUpdate()
|
||||
visible: false
|
||||
@@ -1,28 +1,27 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.list.ListView;
|
||||
import haxework.view.list.VListView;
|
||||
import haxework.view.VGroupView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import hw.view.list.VListView;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:template class RecordFrame extends VGroupView {
|
||||
@:template class RecordFrame extends FrameView<Dynamic> {
|
||||
|
||||
public static var ID(default, never):String = "record";
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var recordStorage:RecordStorage;
|
||||
|
||||
@:view var data:VListView<GameRecordInfo>;
|
||||
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var record:GameRecord;
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
var data = Lambda.array(recordStorage);
|
||||
override public function onShow(_:Dynamic):Void {
|
||||
var data = recordStorage.list();
|
||||
data.sort(function(a:GameRecordInfo, b:GameRecordInfo) return Std.int(b.date.getTime() - a.date.getTime()));
|
||||
this.data.data = data;
|
||||
}
|
||||
|
||||
private function onRecordSelect(item:IListItemView<GameRecordInfo>):Void {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
geometry.padding: 20
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
- $type: hw.view.form.LabelView
|
||||
style: text.header
|
||||
text: Records
|
||||
- id: data
|
||||
$type: haxework.view.list.VListView
|
||||
factory: $code:function() return new ru.m.tankz.view.common.RecordView()
|
||||
+onItemSelect: $this:onRecordSelect
|
||||
$type: hw.view.list.VListView
|
||||
factory: ~function() return new ru.m.tankz.view.common.RecordView()
|
||||
geometry.margin.top: 20
|
||||
geometry.size.stretch: true
|
||||
geometry.stretch: true
|
||||
scroll:
|
||||
$type: haxework.view.list.VScrollBarView
|
||||
skinId: scroll
|
||||
$type: hw.view.list.VScrollBarView
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
@@ -1,46 +1,65 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.GameRunner;
|
||||
import hw.view.data.DataView;
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import ru.m.tankz.view.common.LifeView;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.view.result.ResultPlayerView;
|
||||
|
||||
@:template class ResultFrame extends VGroupView {
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class ResultFrame extends FrameView<Result> {
|
||||
public static var ID(default, never):String = "result";
|
||||
|
||||
@:view("result") var resultView:DataView<PlayerState, LifeView>;
|
||||
@:view("result") var resultView:DataView<PlayerState, ResultPlayerView>;
|
||||
@:view("level") var levelLabel:LabelView;
|
||||
@:view("next") var nextButton:ButtonView;
|
||||
|
||||
@:provide var frames:FrameSwitcher;
|
||||
@:provide var state:GameState;
|
||||
@:provide var game:IGame;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
|
||||
private function playerViewFactory(index:Int, player:PlayerState) {
|
||||
var view = new LifeView();
|
||||
var playerConfig = state.config.getPlayer(player.id);
|
||||
var tankType = playerConfig.tanks[0].type;
|
||||
var tankConfig = state.config.getTank(tankType);
|
||||
view.tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||
view.color = state.getPlayerColor(player.id);
|
||||
view.life = player.frags;
|
||||
view.score = player.score;
|
||||
return view;
|
||||
private var result:Result;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
public function onShow() {
|
||||
resultView.data = Lambda.array(state.players);
|
||||
//levelLabel.text = 'Level ${state.levelId}'; // ToDo: level?
|
||||
override public function onShow(data:Result):Void {
|
||||
result = data;
|
||||
resultView.data = result.state.humans;
|
||||
for (view in resultView.dataViews) {
|
||||
view.winner = view.data.id.team == data.winner;
|
||||
}
|
||||
levelLabel.text = data.level.toLevelLabel();
|
||||
nextButton.disabled = !gameStorage.get(result.level.packId).isPresetAvailable(result.level.id + 1, result.state.presetId);
|
||||
nextButton.text = 'Next #${result.level.id + 1}';
|
||||
}
|
||||
|
||||
private function next() {
|
||||
//ToDo: next level?
|
||||
private function levels():Void {
|
||||
frames.change(LevelFrame.ID, result.level.packId);
|
||||
}
|
||||
|
||||
private function close() {
|
||||
frames.change(LevelFrame.ID);
|
||||
private function restart():Void {
|
||||
result.state.clean();
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: result.level}));
|
||||
}
|
||||
|
||||
private function next():Void {
|
||||
var pack = levelBundle.get(result.level.packId);
|
||||
if (pack.data.length > result.level.id + 1) {
|
||||
var level = pack.data[result.level.id + 1];
|
||||
var progress = gameStorage.get(pack.id);
|
||||
if (progress.isPresetAvailable(level.id, result.state.presetId)) {
|
||||
result.state.clean();
|
||||
frames.change(GameFrame.ID, LOCAL({state: result.state, level: level}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,41 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.header
|
||||
font.align: center
|
||||
- id: result
|
||||
$type: haxework.view.DataView
|
||||
factory: $this:playerViewFactory
|
||||
geometry.margin.top: 20
|
||||
$type: hw.view.data.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
hAlign: right
|
||||
margin: 10
|
||||
$type: hw.view.layout.TailLayout
|
||||
factory: ~ru.m.tankz.view.result.ResultPlayerView.factory
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
overflow.y: scroll
|
||||
geometry.margin.top: 20
|
||||
layout.margin: 5
|
||||
layout.hAlign: center
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- id: restart
|
||||
$type: hw.view.form.ButtonView
|
||||
style: panel_button
|
||||
text: Restart
|
||||
+onPress: ~restart()
|
||||
- id: next
|
||||
$type: hw.view.form.ButtonView
|
||||
style: panel_button
|
||||
text: Next
|
||||
+onPress: ~next()
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~levels()
|
||||
|
||||
@@ -1,7 +1,39 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.VGroupView;
|
||||
import hw.view.form.ToggleButtonView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
@:template class SettingsFrame extends VGroupView {
|
||||
@:template class SettingsFrame extends FrameView<Dynamic> {
|
||||
public static var ID(default, never):String = "settings";
|
||||
|
||||
@:view("fps") var fpsButton:ToggleButtonView;
|
||||
@:view("network") var networkButton:ToggleButtonView;
|
||||
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var settings:SettingsStorage;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override public function onShow(data:Dynamic):Void {
|
||||
super.onShow(data);
|
||||
fpsButton.on = settings.displayFPS;
|
||||
networkButton.on = settings.enableNetwork;
|
||||
settings.signal.connect(onSettingChange);
|
||||
}
|
||||
|
||||
override public function onHide():Void {
|
||||
settings.signal.disconnect(onSettingChange);
|
||||
}
|
||||
|
||||
private function onSettingChange(setting:Setting):Void {
|
||||
switch setting {
|
||||
case DISPLAY_FPS(value): fpsButton.on = value;
|
||||
case ENABLE_NETWORK(value): networkButton.on = value;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,52 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
geometry.padding: 20
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
skinId: text.header
|
||||
- $type: hw.view.form.LabelView
|
||||
style: text.header
|
||||
text: Settings
|
||||
- $type: haxework.view.ScrollView
|
||||
geometry.size.stretch: true
|
||||
scroll:
|
||||
$type: haxework.view.list.VScrollBarView
|
||||
skinId: scroll.vertical
|
||||
view:
|
||||
$type: haxework.view.GroupView
|
||||
geometry.size.stretch: true
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
vAlign: top
|
||||
margin: 20
|
||||
overflow: true
|
||||
views:
|
||||
- id: settings0
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 0
|
||||
- id: settings1
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 1
|
||||
- $type: hw.view.group.VGroupView
|
||||
geometry.stretch: true
|
||||
layout.hAlign: center
|
||||
overflow.y: scroll
|
||||
views:
|
||||
- $type: hw.view.group.GroupView
|
||||
geometry.width: 100%
|
||||
layout:
|
||||
$type: hw.view.layout.TailLayout
|
||||
vAlign: top
|
||||
margin: 20
|
||||
views:
|
||||
- id: settings0
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 0
|
||||
- id: settings1
|
||||
$type: ru.m.tankz.view.settings.SettingsEditor
|
||||
controlIndex: 1
|
||||
- $type: hw.view.group.GroupView
|
||||
geometry.width: 100%
|
||||
geometry.margin.top: 20
|
||||
layout:
|
||||
$type: hw.view.layout.TailLayout
|
||||
hAlign: center
|
||||
margin: 20
|
||||
views:
|
||||
- id: fps
|
||||
$type: hw.view.form.ToggleButtonView
|
||||
text: Display FPS
|
||||
+onPress: ~function(button) settings.displayFPS = !cast(button,ToggleButtonView).on
|
||||
- id: network
|
||||
$type: hw.view.form.ToggleButtonView
|
||||
geometry.margin.top: 20
|
||||
text: Enable Network
|
||||
+onPress: ~function(button) settings.enableNetwork = !cast(button,ToggleButtonView).on
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 100%
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("menu")
|
||||
|
||||
@@ -1,56 +1,134 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.Type.GameType;
|
||||
import ru.m.tankz.view.network.RoomListFrame;
|
||||
import ru.m.tankz.view.network.RoomFrame;
|
||||
import ru.m.tankz.view.popup.FontPopup;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
import hw.view.data.DataView;
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.PackProgress;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.view.common.SlotView;
|
||||
|
||||
@:template class StartFrame extends VGroupView {
|
||||
using haxe.EnumTools.EnumValueTools;
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class StartFrame extends FrameView<Start> {
|
||||
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
@:provide var state:GameState;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide static var switcher:FrameSwitcher;
|
||||
@:provide static var storage:GameStorage;
|
||||
|
||||
private var fontPopup:FontPopup;
|
||||
private var progress:PackProgress;
|
||||
|
||||
private function startGame(type:GameType):Void {
|
||||
state = new GameState(type);
|
||||
switcher.change(LevelFrame.ID);
|
||||
@:view var header:LabelView;
|
||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||
@:view("teams") var teamsView:DataView<Array<PlayerControl>, DataView<PlayerControl, SlotView>>;
|
||||
|
||||
private var humanIndex:Int = 0;
|
||||
private var humanTotal:Int = 2;
|
||||
|
||||
private var start:Start;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private function startNetwork():Void {
|
||||
switch network.state {
|
||||
case ONLINE(user):
|
||||
if (network.room != null) {
|
||||
switcher.change(RoomFrame.ID);
|
||||
network.joinGame(network.room.game.id, true);
|
||||
} else {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
}
|
||||
case CONNECTED:
|
||||
LoginPopup.instance.show().then(function(user):Void {
|
||||
if (user != null) {
|
||||
switcher.change(RoomListFrame.ID);
|
||||
override public function onShow(data:Start):Void {
|
||||
super.onShow(data);
|
||||
start = data;
|
||||
this.progress = storage.get(start.level.packId);
|
||||
header.text = start.level.toLevelLabel();
|
||||
presetsView.data = start.state.config.presets;
|
||||
teamsView.data = defaultControls(start.state.config);
|
||||
}
|
||||
|
||||
private static function defaultControls(config:Config):Array<Array<PlayerControl>> {
|
||||
var result:Array<Array<PlayerControl>> = [];
|
||||
var preset = config.getPreset(0);
|
||||
var human = false;
|
||||
for (team in preset.teams) {
|
||||
if (team.id != "bot") { // ToDo:
|
||||
var controls:Array<PlayerControl> = [];
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
var control:PlayerControl = {
|
||||
playerId: playerId,
|
||||
color: config.getColor(playerId),
|
||||
controller: NONE,
|
||||
}
|
||||
});
|
||||
case _:
|
||||
if (!human) {
|
||||
control.controller = HUMAN(0);
|
||||
control.name = ControllerParser.defaultName(control.controller);
|
||||
human = true;
|
||||
}
|
||||
controls.push(control);
|
||||
}
|
||||
result.push(controls);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private function choiceFont():Void {
|
||||
if (fontPopup == null) {
|
||||
fontPopup = new FontPopup();
|
||||
private function teamViewFactory(index:Int, value:Array<PlayerControl>):DataView<PlayerControl, SlotView> {
|
||||
var result = new DataView();
|
||||
result.style = "light";
|
||||
result.geometry.padding = 5;
|
||||
result.factory = slotViewFactory;
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function slotViewFactory(index:Int, value:PlayerControl):SlotView {
|
||||
var result = new SlotView();
|
||||
result.select.onSelect.connect(function(controller:Controller) setController(value, controller));
|
||||
result.control = value;
|
||||
result.tank = start.state.config.getPlayerTank(value.playerId).skin;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function setController(value:PlayerControl, controller:Controller):Void {
|
||||
switch controller {
|
||||
case NONE:
|
||||
case _:
|
||||
for (teamView in teamsView.dataViews) {
|
||||
for (view in teamView.dataViews) {
|
||||
if (view.control.controller.equals(controller)) {
|
||||
view.control.controller = NONE;
|
||||
view.select.selected = NONE;
|
||||
view.control.name = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
value.controller = controller;
|
||||
value.name = ControllerParser.defaultName(controller);
|
||||
}
|
||||
|
||||
private function presetViewFactory(index:Int, value:GamePreset):ButtonView {
|
||||
var result = new ButtonView();
|
||||
result.style = 'button${!progress.isPresetCompleted(start.level.id, value.id) ? ".active" : ""}';
|
||||
result.geometry.height = "100%";
|
||||
result.text = value.name == "default" ? "start" : value.name;
|
||||
result.disabled = !progress.isPresetAvailable(start.level.id, value.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
private function onPresetSelect(value:GamePreset):Void {
|
||||
if (progress.isPresetAvailable(start.level.id, value.id)) {
|
||||
start.state.presetId = value.id;
|
||||
var controls = [];
|
||||
for (item in teamsView.data) {
|
||||
controls = controls.concat(item);
|
||||
}
|
||||
start.state.controls = controls;
|
||||
switcher.change(GameFrame.ID, LOCAL(start));
|
||||
}
|
||||
fontPopup
|
||||
.show()
|
||||
.then(function(font) Style.register(font))
|
||||
.catchError(function(e) {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,40 @@
|
||||
---
|
||||
views:
|
||||
- $type: haxework.view.VGroupView
|
||||
skinId: container
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: haxework.view.LabelView
|
||||
text: Tank'z
|
||||
skinId: font
|
||||
fontSize: 100
|
||||
geometry.margin.bottom: 30
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('classic')
|
||||
text: Classic
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('dota')
|
||||
text: DotA
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startGame('death')
|
||||
text: DeathMatch
|
||||
- $type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:switcher.change('record')
|
||||
text: Records
|
||||
- id: network
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button
|
||||
+onPress: $code:startNetwork()
|
||||
text: Network
|
||||
#disabled: true
|
||||
- $type: haxework.view.LabelView
|
||||
geometry.hAlign: right
|
||||
geometry.vAlign: top
|
||||
geometry.padding: [20, 5]
|
||||
geometry.position: absolute
|
||||
geometry.margin: [0, 20, 20, 0]
|
||||
skinId: text.box
|
||||
text: $r:text:version
|
||||
- $type: hw.view.group.VGroupView
|
||||
style: container
|
||||
views:
|
||||
- id: header
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.header
|
||||
- id: teams
|
||||
$type: hw.view.data.DataView
|
||||
geometry.padding: 10
|
||||
geometry.width: 100%
|
||||
geometry.height: 100%
|
||||
layout.hAlign: center
|
||||
overflow.y: scroll
|
||||
factory: ~teamViewFactory
|
||||
layout:
|
||||
$type: hw.view.layout.TailLayout
|
||||
margin: 5
|
||||
rowSize: 2
|
||||
- $type: hw.view.group.HGroupView
|
||||
style: panel
|
||||
layout.margin: 10
|
||||
views:
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- id: presets
|
||||
$type: hw.view.data.DataView
|
||||
factory: ~presetViewFactory
|
||||
+onDataSelect: ~onPresetSelect
|
||||
geometry.height: 100%
|
||||
layout:
|
||||
$type: hw.view.layout.HorizontalLayout
|
||||
hAlign: center
|
||||
margin: 5
|
||||
- $type: hw.view.SpriteView
|
||||
geometry.width: 50%
|
||||
- $type: hw.view.form.ButtonView
|
||||
style: button.prev
|
||||
+onPress: ~switcher.change("level", start.level.packId)
|
||||
|
||||
62
src/client/haxe/ru/m/tankz/view/ViewUtil.hx
Normal file
62
src/client/haxe/ru/m/tankz/view/ViewUtil.hx
Normal file
@@ -0,0 +1,62 @@
|
||||
package ru.m.tankz.view;
|
||||
|
||||
import ru.m.tankz.Type.PackId;
|
||||
import openfl.Assets;
|
||||
import ru.m.control.DeviceAction;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Binding;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
class ViewUtil {
|
||||
|
||||
public static function toLevelLabel(level:LevelConfig, oneline:Bool = false):String {
|
||||
var result:Array<String> = ['${level.packId.type} #${level.id}'];
|
||||
if (level.name != null) {
|
||||
result.push(level.name);
|
||||
}
|
||||
return result.join(oneline ? " " : "\n");
|
||||
}
|
||||
|
||||
public static function toPackLabel(packId:PackId, separator=" #"):String {
|
||||
return packId.name != PackId.DEFAULT ? '${packId.type}${separator}${packId.name}' : packId.type;
|
||||
}
|
||||
|
||||
public static function toActionLabel(action:TankAction):String {
|
||||
return switch (action) {
|
||||
case MOVE(d): 'MOVE_$d';
|
||||
case SHOT(w): 'SHOT_$w';
|
||||
case x: '$x';
|
||||
}
|
||||
}
|
||||
|
||||
public static function toBindLabel(bind:BindAction):String {
|
||||
return bind == null ? "(NONE)" : Std.string(bind.device) + " " + switch bind.action {
|
||||
case KEY(code): KeyboardMap.getName(code);
|
||||
case DIRECTION(direction): Std.string(direction);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.ImageView;
|
||||
import haxework.view.LabelView;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.game.GameState;
|
||||
|
||||
@:template class LifeView extends HGroupView {
|
||||
@:provide static var currentState:GameState;
|
||||
|
||||
@:view("tank") public var tankImage:ImageView;
|
||||
@:view("life") public var lifeLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
public var state(null, set):PlayerState;
|
||||
public var tank(null, set):String;
|
||||
public var color(null, set):Int;
|
||||
public var life(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
|
||||
private inline function set_state(value:PlayerState):PlayerState {
|
||||
state = value;
|
||||
toUpdate();
|
||||
return state;
|
||||
}
|
||||
|
||||
private inline function set_tank(value:String):String {
|
||||
if (value != null && value != tank) {
|
||||
tank = value;
|
||||
tankImage.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
|
||||
}
|
||||
return tank;
|
||||
}
|
||||
|
||||
private inline function set_color(value:Int):Int {
|
||||
tankImage.color = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_life(value:Int):Int {
|
||||
lifeLabel.text = '${value}';
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_score(value:Int):Int {
|
||||
scoreLabel.text = '${value}$';
|
||||
return value;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (state != null && currentState != null) {
|
||||
var tankConfig = currentState.config.getTank(state.tank);
|
||||
tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||
color = currentState.config.getColor(state.id);
|
||||
life = state.life;
|
||||
score = state.score;
|
||||
}
|
||||
}
|
||||
|
||||
public static inline function factory(index:Int, data:PlayerState):LifeView {
|
||||
var result = new LifeView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
layout.margin: 5
|
||||
views:
|
||||
- id: tank
|
||||
$type: haxework.view.ImageView
|
||||
- id: life
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
- id: score
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [100, 38]
|
||||
64
src/client/haxe/ru/m/tankz/view/common/NetworkStateView.hx
Normal file
64
src/client/haxe/ru/m/tankz/view/common/NetworkStateView.hx
Normal file
@@ -0,0 +1,64 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.group.HGroupView;
|
||||
import hw.view.skin.SpriteSkin;
|
||||
import hw.view.SpriteView;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.view.popup.LoginPopup;
|
||||
|
||||
@:template class NetworkStateView extends HGroupView {
|
||||
|
||||
@:view("state") var stateView:SpriteView;
|
||||
@:view("user") var userLabel:LabelView;
|
||||
@:view("login") var loginButton:ButtonView;
|
||||
@:view("logout") var logoutButton:ButtonView;
|
||||
|
||||
@:provide static var network:NetworkManager;
|
||||
|
||||
public function new():Void {
|
||||
super();
|
||||
network.stateSignal.connect(onConnectionChange);
|
||||
}
|
||||
|
||||
private function onConnectionChange(state:ConnectionState):Void {
|
||||
visible = true;
|
||||
stateView.visible = true;
|
||||
userLabel.text = "";
|
||||
loginButton.visible = false;
|
||||
logoutButton.visible = false;
|
||||
var skin:SpriteSkin = cast stateView.skin;
|
||||
switch state {
|
||||
case OFFLINE:
|
||||
skin.background.color = "black";
|
||||
stateView.visible = false;
|
||||
visible = false;
|
||||
case CONNECT:
|
||||
skin.background.color = "yellow";
|
||||
case CONNECTED:
|
||||
skin.background.color = "gray";
|
||||
loginButton.visible = true;
|
||||
case LOGIN:
|
||||
skin.background.color = "yellow";
|
||||
case ONLINE(user):
|
||||
skin.background.color = "green";
|
||||
userLabel.text = user.name;
|
||||
logoutButton.visible = true;
|
||||
case ERROR(error):
|
||||
skin.background.color = "red";
|
||||
userLabel.text = Std.string(error).substr(0, 10);
|
||||
}
|
||||
stateView.toRedraw();
|
||||
}
|
||||
|
||||
private function login():Void {
|
||||
LoginPopup.instance.show().then(function(user:User):Void {
|
||||
L.d("Login", 'user: $user');
|
||||
});
|
||||
}
|
||||
|
||||
private function logout():Void {
|
||||
network.logout();
|
||||
}
|
||||
}
|
||||
34
src/client/haxe/ru/m/tankz/view/common/NetworkStateView.yaml
Normal file
34
src/client/haxe/ru/m/tankz/view/common/NetworkStateView.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
geometry.padding: [5, 2]
|
||||
layout.vAlign: middle
|
||||
visible: false
|
||||
skin:
|
||||
$type: hw.view.skin.SpriteSkin
|
||||
border.color: 0x95937D
|
||||
round: 10
|
||||
views:
|
||||
- id: state
|
||||
$type: hw.view.SpriteView
|
||||
geometry.width: 20
|
||||
geometry.height: 20
|
||||
visible: false
|
||||
skin:
|
||||
$type: hw.view.skin.SpriteSkin
|
||||
background.color: black
|
||||
border.color: 0xE7E0BB
|
||||
round: 20
|
||||
- id: user
|
||||
$type: hw.view.form.LabelView
|
||||
font.size: 14
|
||||
- id: login
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.small
|
||||
text: login
|
||||
+onPress: ~login()
|
||||
visible: false
|
||||
- id: logout
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.small
|
||||
text: logout
|
||||
+onPress: ~logout()
|
||||
visible: false
|
||||
37
src/client/haxe/ru/m/tankz/view/common/PackView.hx
Normal file
37
src/client/haxe/ru/m/tankz/view/common/PackView.hx
Normal file
@@ -0,0 +1,37 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.group.VGroupView;
|
||||
import ru.m.tankz.bundle.ILevelBundle;
|
||||
import ru.m.tankz.storage.GameStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
using ru.m.tankz.view.ViewUtil;
|
||||
|
||||
@:template class PackView extends VGroupView {
|
||||
|
||||
public var data(default, set):PackId;
|
||||
|
||||
@:view var label:LabelView;
|
||||
@:view var state:LabelView;
|
||||
|
||||
@:provide static var gameStorage:GameStorage;
|
||||
@:provide static var levelBundle:ILevelBundle;
|
||||
|
||||
private function set_data(value:PackId):PackId {
|
||||
if (data != value) {
|
||||
data = value;
|
||||
label.text = data.toPackLabel("\n");
|
||||
var progress = gameStorage.get(data).progress;
|
||||
var total = levelBundle.get(data).data.length;
|
||||
state.text = '${progress}/${total}';
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static function factory(index:Int, value:PackId):PackView {
|
||||
var result = new PackView();
|
||||
result.data = value;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
9
src/client/haxe/ru/m/tankz/view/common/PackView.yaml
Normal file
9
src/client/haxe/ru/m/tankz/view/common/PackView.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
style: button.pack
|
||||
views:
|
||||
- id: label
|
||||
$type: hw.view.form.LabelView
|
||||
font.size: 4h
|
||||
- id: state
|
||||
$type: hw.view.form.LabelView
|
||||
font.size: 3.5h
|
||||
@@ -1,119 +0,0 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import haxework.resources.IResources;
|
||||
import haxework.color.ColorUtil;
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.skin.ISkin;
|
||||
import haxework.view.ToggleButtonView;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type.TeamId;
|
||||
|
||||
class TeamButton extends ToggleButtonView {
|
||||
public var team(default, set):TeamId;
|
||||
|
||||
private function set_team(value:TeamId):TeamId {
|
||||
if (team != value) {
|
||||
team = value;
|
||||
text = team.substr(0, 1).toUpperCase() + team.substr(1);
|
||||
}
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
class TeamSkin implements ISkin<TeamButton> {
|
||||
|
||||
@:provide private static var resources:IResources;
|
||||
|
||||
public var color(default, default):Int;
|
||||
|
||||
public function new(color:Int) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public function draw(view:TeamButton):Void {
|
||||
view.fontColor = view.on ? 0xffffff : resources.color.get("dark");
|
||||
var graphics = view.content.graphics;
|
||||
graphics.beginFill(view.on ? color : resources.color.get("light"));
|
||||
graphics.lineStyle(2, color, 0.5);
|
||||
graphics.drawRoundRect(0, 0, view.width, view.height, 5, 5);
|
||||
graphics.endFill();
|
||||
graphics.lineStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@:template class PlayerView extends HGroupView {
|
||||
private static inline var TEAM_NONE:TeamId = "none";
|
||||
|
||||
public var item_index(default, set):Int;
|
||||
public var data(default, set):Array<PlayerState>;
|
||||
public var colorize:Bool;
|
||||
|
||||
@:view var label(default, null):LabelView;
|
||||
@:view var teams(default, null):DataView<TeamId, ToggleButtonView>;
|
||||
|
||||
@:provide var state:GameState;
|
||||
|
||||
private var player:PlayerState;
|
||||
|
||||
private function teamViewFactory(index:Int, team:TeamId) {
|
||||
var view = new TeamButton();
|
||||
var color = getTeamColor(team);
|
||||
view.skin = [Style.text(color), new TeamSkin(color)];
|
||||
view.geometry.padding = [10, 5];
|
||||
view.team = team;
|
||||
view.on = team == TEAM_NONE;
|
||||
return view;
|
||||
}
|
||||
|
||||
private function set_data(value:Array<PlayerState>):Array<PlayerState> {
|
||||
data = value;
|
||||
teams.data = [TEAM_NONE].concat([for (team in state.preset.teams) team.id]);
|
||||
return data;
|
||||
}
|
||||
|
||||
private function getTeamColor(teamId:TeamId):Int {
|
||||
var color = 0xaaaaaa;
|
||||
for (team in state.preset.teams) {
|
||||
if (team.id == teamId) {
|
||||
if (!team.color.zero) color = team.color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
private function set_item_index(value:Int):Int {
|
||||
item_index = value;
|
||||
label.text = 'Player ${item_index+1}';
|
||||
return item_index;
|
||||
}
|
||||
|
||||
private function onTeamSelect(team:TeamId) {
|
||||
if (player != null) {
|
||||
player.controller = NONE;
|
||||
player.color = 0;
|
||||
player = null;
|
||||
}
|
||||
for (p in data) {
|
||||
if (p.id.team == team) {
|
||||
switch (p.controller) {
|
||||
case NONE:
|
||||
player = p;
|
||||
player.controller = HUMAN(item_index);
|
||||
if (colorize) {
|
||||
player.color = ColorUtil.multiply(state.config.getTeam(team).color, 1.7);
|
||||
}
|
||||
break;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (view in teams.views) {
|
||||
var button = cast(view, TeamButton);
|
||||
button.on = team == button.team;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
geometry.margin: 5
|
||||
layout.margin: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: label
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text
|
||||
- id: teams
|
||||
$type: haxework.view.DataView
|
||||
factory: $this:teamViewFactory
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 5
|
||||
margin: 3
|
||||
+onDataSelect: $this:onTeamSelect
|
||||
@@ -1,11 +1,10 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import ru.m.tankz.game.record.GamePlayer;
|
||||
import ru.m.tankz.game.IGame;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.list.ListView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.group.HGroupView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.list.ListView;
|
||||
import ru.m.tankz.game.GameInit;
|
||||
import ru.m.tankz.game.record.GameRecord;
|
||||
import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@@ -20,7 +19,6 @@ import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
@:provide var recordStorage:RecordStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var game:IGame;
|
||||
|
||||
private function set_data(value:GameRecordInfo):GameRecordInfo {
|
||||
if (data != value) {
|
||||
@@ -35,8 +33,7 @@ import ru.m.tankz.storage.RecordStorage;
|
||||
|
||||
private function play():Void {
|
||||
var record = recordStorage.read(data.id);
|
||||
game = new GamePlayer(record);
|
||||
switcher.change(GameFrame.ID);
|
||||
switcher.change(GameFrame.ID, RECORD(record));
|
||||
}
|
||||
|
||||
private function delete():Void {
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
---
|
||||
geometry.size.height: 38
|
||||
geometry.height: 38
|
||||
layout.margin: 5
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: play
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.start.small
|
||||
+onPress: $code:play()
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.start.small
|
||||
+onPress: ~play()
|
||||
- id: date
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [250, 38]
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
- id: type
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [250, 38]
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 200
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
- id: preset
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.fixed: [50, 38]
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 100
|
||||
- id: delete
|
||||
$type: haxework.view.ButtonView
|
||||
skinId: button.close.small
|
||||
+onPress: $code:delete()
|
||||
$type: hw.view.form.ButtonView
|
||||
style: button.close.small
|
||||
+onPress: ~delete()
|
||||
|
||||
48
src/client/haxe/ru/m/tankz/view/common/SlotView.hx
Normal file
48
src/client/haxe/ru/m/tankz/view/common/SlotView.hx
Normal file
@@ -0,0 +1,48 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import openfl.Assets;
|
||||
import hw.view.ImageView;
|
||||
import hw.view.form.LabelView;
|
||||
import hw.view.form.SelectView;
|
||||
import hw.view.group.HGroupView;
|
||||
import hw.view.skin.SpriteSkin;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.PlayerControl;
|
||||
|
||||
@:template class SlotView extends HGroupView {
|
||||
|
||||
@:view("tank") public var tankView:ImageView;
|
||||
@:view("slot") public var slotLabel:LabelView;
|
||||
@:view("select") public var select:SelectView<Controller>;
|
||||
|
||||
public var control(default, set):PlayerControl;
|
||||
public var tank(default, set):String;
|
||||
|
||||
private function set_control(value:PlayerControl):PlayerControl {
|
||||
control = value;
|
||||
slotLabel.text = '${control.playerId.team} #${control.playerId.index}';
|
||||
var skin:SpriteSkin = cast slotLabel.skin;
|
||||
skin.border.color = value.color;
|
||||
skin.border.alpha = 0.8;
|
||||
skin.background.color = value.color;
|
||||
skin.background.alpha = 0.2;
|
||||
select.selected = control.controller;
|
||||
tankView.color = value.color;
|
||||
return control;
|
||||
}
|
||||
|
||||
private function set_tank(value:String):String {
|
||||
if (tank != value) {
|
||||
tank = value;
|
||||
tankView.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
|
||||
}
|
||||
return tank;
|
||||
}
|
||||
|
||||
private function onControllerSelect(value:Controller):Void {
|
||||
select.currentView.style = switch value {
|
||||
case HUMAN(_): "button.active";
|
||||
case _: "button";
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/client/haxe/ru/m/tankz/view/common/SlotView.yaml
Normal file
26
src/client/haxe/ru/m/tankz/view/common/SlotView.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
geometry.padding: 2
|
||||
layout.margin: 10
|
||||
layout.vAlign: middle
|
||||
views:
|
||||
- id: tank
|
||||
$type: hw.view.ImageView
|
||||
style: icon.tank
|
||||
- id: slot
|
||||
$type: hw.view.form.LabelView
|
||||
style: text.box
|
||||
geometry.width: 150
|
||||
- id: select
|
||||
$type: hw.view.form.SelectView<ru.m.tankz.control.Controller>
|
||||
geometry.width: 150
|
||||
labelBuilder: |
|
||||
~function(controller) {
|
||||
var result = ControllerParser.defaultName(controller);
|
||||
return result == null ? "None" : result;
|
||||
}
|
||||
data:
|
||||
- ~ru.m.tankz.control.Controller.NONE
|
||||
- ~ru.m.tankz.control.Controller.HUMAN(0)
|
||||
- ~ru.m.tankz.control.Controller.HUMAN(1)
|
||||
selected: ~ru.m.tankz.control.Controller.NONE
|
||||
+onSelect: ~onControllerSelect
|
||||
25
src/client/haxe/ru/m/tankz/view/common/TankView.hx
Normal file
25
src/client/haxe/ru/m/tankz/view/common/TankView.hx
Normal file
@@ -0,0 +1,25 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import hw.view.utils.DrawUtil.FillType;
|
||||
import hw.view.ImageView;
|
||||
import ru.m.tankz.render.RenderUtil;
|
||||
import ru.m.tankz.Type.TankInfo;
|
||||
|
||||
class TankView extends ImageView {
|
||||
|
||||
public var tank(null, set):TankInfo;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
style = "icon.tank";
|
||||
fillType = FillType.CONTAIN;
|
||||
}
|
||||
|
||||
private function set_tank(value:TankInfo):TankInfo {
|
||||
if (value != null) {
|
||||
color = value.color;
|
||||
image = RenderUtil.tankImage(value.skin);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.Type.PlayerId;
|
||||
import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
|
||||
public var position(default, null):Direction = Direction.RIGHT;
|
||||
|
||||
@:view var bot:LifeView;
|
||||
@:view var player1:LifeView;
|
||||
@:view var player2:LifeView;
|
||||
@:view var level:LabelView;
|
||||
|
||||
private var player1Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 0);
|
||||
private var player2Id:PlayerId = new PlayerId(ClassicGame.HUMAN, 1);
|
||||
|
||||
public function refresh(state:GameState):Void {
|
||||
bot.life = state.getTeamLife(ClassicGame.BOT);
|
||||
player1.life = state.getPlayerLife(player1Id);
|
||||
player1.score = state.getPlayerScore(player1Id);
|
||||
if (state.getPlayerLife(player2Id) > 0) {
|
||||
player2.visible = true;
|
||||
player2.life = state.getPlayerLife(player2Id);
|
||||
player2.score = state.getPlayerScore(player2Id);
|
||||
} else {
|
||||
player2.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state, level):
|
||||
this.level.text = 'Level ${level.id}';
|
||||
refresh(state);
|
||||
case CHANGE(TEAM_LIFE(teamId, life)):
|
||||
if (teamId == ClassicGame.BOT) {
|
||||
bot.life = life;
|
||||
}
|
||||
case CHANGE(PLAYER_LIFE(playerId, life)):
|
||||
if (playerId == player1Id) {
|
||||
player1.life = life;
|
||||
} else if (playerId == player2Id) {
|
||||
player2.life = life;
|
||||
}
|
||||
case CHANGE(PLAYER_SCORE(playerId, score)):
|
||||
if (playerId == player1Id) {
|
||||
player1.score = score;
|
||||
} else if (playerId == player2Id) {
|
||||
player2.score = score;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: left
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.size.width: 100%
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.height: 50%
|
||||
- id: bot
|
||||
$type: ru.m.tankz.view.common.LifeView
|
||||
tank: ba
|
||||
scoreLabel.visible: false
|
||||
- id: player1
|
||||
$type: ru.m.tankz.view.common.LifeView
|
||||
tank: pa
|
||||
color: 0xFFFF00
|
||||
- id: player2
|
||||
$type: ru.m.tankz.view.common.LifeView
|
||||
tank: pa
|
||||
color: 0x15C040
|
||||
@@ -1,28 +0,0 @@
|
||||
package ru.m.tankz.view.game;
|
||||
|
||||
import haxework.view.DataView;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.VGroupView;
|
||||
import ru.m.geom.Direction;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.view.common.LifeView;
|
||||
|
||||
@:template class DeathGamePanel extends VGroupView implements IGamePanel {
|
||||
public var position(default, null):Direction = Direction.RIGHT;
|
||||
|
||||
@:view var level:LabelView;
|
||||
@:view var players:DataView<PlayerState, LifeView>;
|
||||
|
||||
public function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case START(state, level):
|
||||
this.level.text = 'Level ${level.id}';
|
||||
players.data = Lambda.array(state.players);
|
||||
case _:
|
||||
for (view in players.views) {
|
||||
view.toUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
geometry.padding: 5
|
||||
geometry.size.height: 100%
|
||||
layout.margin: 5
|
||||
layout.hAlign: right
|
||||
views:
|
||||
- id: level
|
||||
$type: haxework.view.LabelView
|
||||
skinId: text.box
|
||||
geometry.size.height: 38
|
||||
geometry.size.width: 100%
|
||||
- $type: haxework.view.SpriteView
|
||||
geometry.size.height: 50%
|
||||
- id: players
|
||||
$type: haxework.view.DataView
|
||||
layout:
|
||||
$type: haxework.view.layout.VerticalLayout
|
||||
factory: $code:ru.m.tankz.view.common.LifeView.factory
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user