style: format code
This commit is contained in:
@@ -4,13 +4,10 @@ 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
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
32
.vscode/launch.json
vendored
32
.vscode/launch.json
vendored
@@ -1,32 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"args": [
|
||||
"app:flash:test"
|
||||
],
|
||||
"name": "app:flash:test",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"server:cpp:test"
|
||||
],
|
||||
"name": "server:cpp:test",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"request": "launch",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node"
|
||||
}
|
||||
]
|
||||
}
|
||||
16
.vscode/settings.json
vendored
16
.vscode/settings.json
vendored
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"haxe.executable": {
|
||||
"path": "/home/shmyga/sdk/haxe/4.2.5/haxe",
|
||||
"env": {
|
||||
"HAXE_STD_PATH": "/home/shmyga/sdk/haxe/4.2.5/std",
|
||||
},
|
||||
},
|
||||
"haxe.configurations": [
|
||||
["build/app/flash/haxe/debug.hxml"],
|
||||
],
|
||||
"haxe.displayServer": {
|
||||
"arguments": [
|
||||
//"-v"
|
||||
],
|
||||
}
|
||||
}
|
||||
10
README.md
Normal file
10
README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
`.bashrc`
|
||||
```bash
|
||||
export NEKO_VERSION="2.2.0"
|
||||
export HAXE_VERSION="4.2.5"
|
||||
|
||||
export NEKO_SDK="$HOME/sdk/neko/$NEKO_VERSION"
|
||||
export HAXE_SDK="$HOME/sdk/haxe/$HAXE_VERSION"
|
||||
|
||||
alias haxe-activate=". $NEKO_SDK/activate && . $HAXE_SDK/activate"
|
||||
```
|
||||
5
hxformat.json
Normal file
5
hxformat.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"indentation": {
|
||||
"character": " "
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@
|
||||
"openfl": "9.2.0",
|
||||
"hxcpp": "4.2.1",
|
||||
"svg": "1.1.3",
|
||||
"protohx": "0.4.6"
|
||||
"protohx": "0.4.6",
|
||||
"formatter": "1.16.0"
|
||||
},
|
||||
"haxe": "4.2.5"
|
||||
}
|
||||
|
||||
46
puzzlez.code-workspace
Normal file
46
puzzlez.code-workspace
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"haxe.executable": {
|
||||
"path": "/home/shmyga/sdk/haxe/4.2.5/haxe",
|
||||
"env": {
|
||||
"HAXE_STD_PATH": "/home/shmyga/sdk/haxe/4.2.5/std"
|
||||
}
|
||||
},
|
||||
"haxe.configurations": [["build/app/flash/haxe/debug.hxml"]],
|
||||
"haxe.displayServer": {
|
||||
"arguments": [
|
||||
//"-v"
|
||||
]
|
||||
}
|
||||
},
|
||||
"extensions": {
|
||||
"recommendations": ["nadako.vshaxe"]
|
||||
},
|
||||
"launch": {
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"args": ["app:flash:test"],
|
||||
"name": "app:flash:test",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"request": "launch",
|
||||
"skipFiles": ["<node_internals>/**"],
|
||||
"type": "node"
|
||||
},
|
||||
{
|
||||
"args": ["server:cpp:test"],
|
||||
"name": "server:cpp:test",
|
||||
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
|
||||
"request": "launch",
|
||||
"skipFiles": ["<node_internals>/**"],
|
||||
"type": "node"
|
||||
}
|
||||
],
|
||||
"compounds": []
|
||||
}
|
||||
}
|
||||
8
scripts/format
Executable file
8
scripts/format
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/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/app/haxe -s ./src/server/haxe
|
||||
8
scripts/lint
Executable file
8
scripts/lint
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/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/app/haxe -s ./src/server/haxe
|
||||
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
|
||||
@@ -3,6 +3,7 @@ package ru.m;
|
||||
#if macro
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
|
||||
using haxe.macro.Tools;
|
||||
#end
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ enum abstract Platform(String) from String to String {
|
||||
}
|
||||
|
||||
class Device {
|
||||
|
||||
public static var platform(get, null):Platform;
|
||||
|
||||
private static function get_platform():Platform {
|
||||
@@ -34,9 +33,7 @@ class Device {
|
||||
#end
|
||||
}
|
||||
|
||||
private static var MOBILES(default, never):Array<String> = [
|
||||
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
||||
];
|
||||
private static var MOBILES(default, never):Array<String> = ["Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",];
|
||||
|
||||
public static function isMobile():Bool {
|
||||
#if android
|
||||
@@ -71,7 +68,6 @@ class Device {
|
||||
}
|
||||
|
||||
public static function toggleFullScreen():Void {
|
||||
Lib.current.stage.displayState = Lib.current.stage.displayState == StageDisplayState.NORMAL ?
|
||||
StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;
|
||||
Lib.current.stage.displayState = Lib.current.stage.displayState == StageDisplayState.NORMAL ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import openfl.net.FileReference;
|
||||
import openfl.utils.ByteArray;
|
||||
|
||||
class Callback<T> {
|
||||
private var success:T -> Void;
|
||||
private var fail:Dynamic -> Void;
|
||||
private var success:T->Void;
|
||||
private var fail:Dynamic->Void;
|
||||
|
||||
public function new(success: T -> Void, fail: Dynamic -> Void) {
|
||||
public function new(success:T->Void, fail:Dynamic->Void) {
|
||||
this.success = success;
|
||||
this.fail = fail;
|
||||
}
|
||||
@@ -24,26 +24,17 @@ class Callback<T> {
|
||||
|
||||
class ModernFileReference extends FileReference {
|
||||
#if android
|
||||
private static var fileUtilBrowse = lime.system.JNI.createStaticMethod(
|
||||
"ru.m.android.FileUtil",
|
||||
"browse",
|
||||
"(Lorg/haxe/lime/HaxeObject;)V"
|
||||
);
|
||||
private static var fileUtilBrowse = lime.system.JNI.createStaticMethod("ru.m.android.FileUtil", "browse", "(Lorg/haxe/lime/HaxeObject;)V");
|
||||
#end
|
||||
|
||||
override public function browse(?typeFilter:Array<FileFilter>):Bool {
|
||||
#if android
|
||||
fileUtilBrowse(new Callback<haxe.io.BytesData>(
|
||||
function(result:haxe.io.BytesData):Void {
|
||||
fileUtilBrowse(new Callback<haxe.io.BytesData>(function(result:haxe.io.BytesData):Void {
|
||||
data = ByteArray.fromBytesData(result);
|
||||
dispatchEvent(new flash.events.Event(flash.events.Event.COMPLETE));
|
||||
},
|
||||
function(error:Dynamic):Void {
|
||||
dispatchEvent(new flash.events.IOErrorEvent(
|
||||
flash.events.IOErrorEvent.IO_ERROR, false, false, Std.string(error)
|
||||
));
|
||||
}
|
||||
));
|
||||
}, function(error:Dynamic):Void {
|
||||
dispatchEvent(new flash.events.IOErrorEvent(flash.events.IOErrorEvent.IO_ERROR, false, false, Std.string(error)));
|
||||
}));
|
||||
return true;
|
||||
#else
|
||||
return super.browse(typeFilter);
|
||||
|
||||
76
src/app/haxe/ru/m/api/PixabayApi.hx
Normal file
76
src/app/haxe/ru/m/api/PixabayApi.hx
Normal file
@@ -0,0 +1,76 @@
|
||||
package ru.m.api;
|
||||
|
||||
import hw.net.JsonLoader;
|
||||
import promhx.Promise;
|
||||
|
||||
typedef PixabayImage = {
|
||||
var id:Int;
|
||||
var largeImageURL:String;
|
||||
var webformatURL:String;
|
||||
var previewURL:String;
|
||||
}
|
||||
|
||||
typedef PixabayResponse = {
|
||||
var total:Int;
|
||||
var totalHits:Int;
|
||||
var hits:Array<PixabayImage>;
|
||||
}
|
||||
|
||||
enum abstract PixabayCategory(String) from String to String {
|
||||
var FASHION = "fashion";
|
||||
var NATURE = "nature";
|
||||
var BACKGROUNDS = "backgrounds";
|
||||
var SCIENCE = "science";
|
||||
var EDUCATION = "education";
|
||||
var PEOPLE = "people";
|
||||
var FEELINGS = "feelings";
|
||||
var RELIGION = "religion";
|
||||
var HEALTH = "health";
|
||||
var PLACES = "places";
|
||||
var ANIMALS = "animals";
|
||||
var INDUSTRY = "industry";
|
||||
var FOOD = "food";
|
||||
var COMPUTER = "computer";
|
||||
var SPORTS = "sports";
|
||||
var TRANSPORTATION = "transportation";
|
||||
var TRAVEL = "travel";
|
||||
var BUILDINGS = "buildings";
|
||||
var BUSINESS = "business";
|
||||
var MUSIC = "music";
|
||||
}
|
||||
|
||||
enum abstract PixabayImageType(String) from String to String {
|
||||
var ALL = "all";
|
||||
var PHOTO = "photo";
|
||||
var ILLUSTRATION = "illustration";
|
||||
var VECTOR = "vector";
|
||||
}
|
||||
|
||||
class PixabayApi {
|
||||
private var baseUrl:String = "https://pixabay.com/api/";
|
||||
private var key:String;
|
||||
|
||||
public function new(key:String) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
private function buildRequest(queryMap:Map<String, Dynamic>):String {
|
||||
queryMap.set("key", key);
|
||||
var query = [for (k in queryMap.keys()) '${k}=${queryMap.get(k)}'].join("&");
|
||||
return '${baseUrl}?${query}';
|
||||
}
|
||||
|
||||
public function getPage(page:Int, perPage:Int, category:PixabayCategory = PixabayCategory.NATURE):Promise<PixabayResponse> {
|
||||
return new JsonLoader<PixabayResponse>().GET(buildRequest([
|
||||
"category" => category,
|
||||
"image_type" => PixabayImageType.PHOTO,
|
||||
"editors_choice" => true,
|
||||
"per_page" => perPage,
|
||||
"page" => page,
|
||||
]));
|
||||
}
|
||||
|
||||
public function get(id:Int):Promise<PixabayImage> {
|
||||
return new JsonLoader<PixabayResponse>().GET(buildRequest(["id" => id])).then((response:PixabayResponse) -> response.hits[0]);
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,9 @@ typedef UnsplashImage = {
|
||||
}
|
||||
|
||||
typedef UnsplashResponse = {
|
||||
var total: Int;
|
||||
var total_pages: Int;
|
||||
var results: Array<UnsplashImage>;
|
||||
var total:Int;
|
||||
var total_pages:Int;
|
||||
var results:Array<UnsplashImage>;
|
||||
}
|
||||
|
||||
class UnsplashApi {
|
||||
@@ -41,8 +41,7 @@ class UnsplashApi {
|
||||
}
|
||||
|
||||
public function getPage(page:Int, perPage:Int, query:String):Promise<UnsplashResponse> {
|
||||
return new JsonLoader<UnsplashResponse>()
|
||||
.GET(buildRequest([
|
||||
return new JsonLoader<UnsplashResponse>().GET(buildRequest([
|
||||
"per_page" => perPage,
|
||||
"page" => page,
|
||||
"order_by" => "relevant",
|
||||
@@ -52,11 +51,8 @@ class UnsplashApi {
|
||||
}
|
||||
|
||||
public function get(id:String):Promise<UnsplashImage> {
|
||||
var queryMap = [
|
||||
"client_id" => key,
|
||||
];
|
||||
var queryMap = ["client_id" => key,];
|
||||
var query = buildQuery(queryMap);
|
||||
return new JsonLoader<UnsplashImage>()
|
||||
.GET('${baseUrl}/photos/${id}?${query}');
|
||||
return new JsonLoader<UnsplashImage>().GET('${baseUrl}/photos/${id}?${query}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package ru.m.data;
|
||||
import promhx.Promise;
|
||||
|
||||
typedef Filter = Map<String, Dynamic>;
|
||||
|
||||
typedef Order = Array<{
|
||||
var field:String;
|
||||
@:optional var reverse:Bool;
|
||||
|
||||
@@ -2,6 +2,4 @@ package ru.m.event;
|
||||
|
||||
import flash.events.Event;
|
||||
|
||||
class GestureEvent extends Event {
|
||||
|
||||
}
|
||||
class GestureEvent extends Event {}
|
||||
|
||||
@@ -10,7 +10,6 @@ typedef Touch = {
|
||||
}
|
||||
|
||||
class GestureManager {
|
||||
|
||||
private var target:DisplayObject;
|
||||
private var touchesMap:Map<Int, Touch>;
|
||||
private var touches:Array<Touch>;
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package ru.m.pixabay;
|
||||
|
||||
import hw.net.JsonLoader;
|
||||
import promhx.Promise;
|
||||
|
||||
typedef PixabayImage = {
|
||||
var id:Int;
|
||||
var largeImageURL:String;
|
||||
var webformatURL:String;
|
||||
var previewURL:String;
|
||||
}
|
||||
|
||||
typedef PixabayResponse = {
|
||||
var total:Int;
|
||||
var totalHits:Int;
|
||||
var hits:Array<PixabayImage>;
|
||||
}
|
||||
|
||||
enum abstract PixabayCategory(String) from String to String {
|
||||
var FASHION = "fashion";
|
||||
var NATURE = "nature";
|
||||
var BACKGROUNDS = "backgrounds";
|
||||
var SCIENCE = "science";
|
||||
var EDUCATION = "education";
|
||||
var PEOPLE = "people";
|
||||
var FEELINGS = "feelings";
|
||||
var RELIGION = "religion";
|
||||
var HEALTH = "health";
|
||||
var PLACES = "places";
|
||||
var ANIMALS = "animals";
|
||||
var INDUSTRY = "industry";
|
||||
var FOOD = "food";
|
||||
var COMPUTER = "computer";
|
||||
var SPORTS = "sports";
|
||||
var TRANSPORTATION = "transportation";
|
||||
var TRAVEL = "travel";
|
||||
var BUILDINGS = "buildings";
|
||||
var BUSINESS = "business";
|
||||
var MUSIC = "music";
|
||||
}
|
||||
|
||||
enum abstract PixabayImageType(String) from String to String {
|
||||
var ALL = "all";
|
||||
var PHOTO = "photo";
|
||||
var ILLUSTRATION = "illustration";
|
||||
var VECTOR = "vector";
|
||||
}
|
||||
|
||||
class PixabayApi {
|
||||
private var baseUrl:String = "https://pixabay.com/api/";
|
||||
private var key:String;
|
||||
|
||||
public function new(key:String) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
private function buildRequest(queryMap:Map<String, Dynamic>):String {
|
||||
queryMap.set("key", key);
|
||||
var query = [for (k in queryMap.keys()) '${k}=${queryMap.get(k)}'].join("&");
|
||||
return '${baseUrl}?${query}';
|
||||
}
|
||||
|
||||
public function getPage(page:Int, perPage:Int, category:PixabayCategory = PixabayCategory.NATURE):Promise<PixabayResponse> {
|
||||
return new JsonLoader<PixabayResponse>()
|
||||
.GET(buildRequest([
|
||||
"category" => category,
|
||||
"image_type" => PixabayImageType.PHOTO,
|
||||
"editors_choice" => true,
|
||||
"per_page" => perPage,
|
||||
"page" => page,
|
||||
]));
|
||||
}
|
||||
|
||||
public function get(id:Int):Promise<PixabayImage> {
|
||||
return new JsonLoader<PixabayResponse>()
|
||||
.GET(buildRequest(["id" => id]))
|
||||
.then((response:PixabayResponse) -> response.hits[0]);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ typedef FileContent = {
|
||||
}
|
||||
|
||||
class FileUtil {
|
||||
|
||||
public static function browse():Promise<FileContent> {
|
||||
var d = new Deferred<FileContent>();
|
||||
var file = new ModernFileReference();
|
||||
@@ -24,7 +23,7 @@ class FileUtil {
|
||||
d.throwError(event);
|
||||
});
|
||||
file.addEventListener(ProgressEvent.PROGRESS, (event:ProgressEvent) -> {
|
||||
//trace('progress', '${event}');
|
||||
// trace('progress', '${event}');
|
||||
});
|
||||
file.addEventListener(Event.COMPLETE, (event:Event) -> {
|
||||
var f:ModernFileReference = cast event.target;
|
||||
|
||||
@@ -11,7 +11,6 @@ import promhx.Deferred;
|
||||
import promhx.Promise;
|
||||
|
||||
class ImageUtil {
|
||||
|
||||
public static function bytesToImage(bytes:Bytes):Promise<BitmapData> {
|
||||
var def = new Deferred();
|
||||
var loader = new Loader();
|
||||
|
||||
@@ -15,7 +15,6 @@ import ru.m.puzzlez.view.PuzzlezAppView;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
class PuzzlezApp {
|
||||
|
||||
@:provide static var updater:Updater;
|
||||
@:provide static var sourceBundle:ImageSourceBundle;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import openfl.Assets;
|
||||
import ru.m.skin.ButtonSVGSkin;
|
||||
|
||||
class PuzzlezTheme extends Theme {
|
||||
|
||||
private static var ICONS:Map<String, String> = [
|
||||
"close" => "times-circle-solid.svg",
|
||||
"setting" => "cog-solid.svg",
|
||||
@@ -23,9 +22,7 @@ class PuzzlezTheme extends Theme {
|
||||
|
||||
public function new() {
|
||||
super({embed: true}, {light: "gray"}, {base: "4h"});
|
||||
register(new Style("frame", [
|
||||
"geometry.padding" => Box.fromFloat(8),
|
||||
]));
|
||||
register(new Style("frame", ["geometry.padding" => Box.fromFloat(8),]));
|
||||
register(new Style("view", [
|
||||
"skin.background.color" => colors.light,
|
||||
"skin.border.color" => colors.border,
|
||||
@@ -33,9 +30,7 @@ class PuzzlezTheme extends Theme {
|
||||
"geometry.width" => SizeValue.fromString("50h"),
|
||||
"geometry.height" => SizeValue.fromString("40h"),
|
||||
]));
|
||||
register(new Style("text.error", [
|
||||
"font.color" => Color.fromString("red"),
|
||||
], "text"));
|
||||
register(new Style("text.error", ["font.color" => Color.fromString("red"),], "text"));
|
||||
register(new Style("icon", [
|
||||
"geometry.width" => SizeValue.fromString("8h"),
|
||||
"geometry.height" => SizeValue.fromString("8h"),
|
||||
@@ -43,32 +38,22 @@ class PuzzlezTheme extends Theme {
|
||||
"skin.color" => colors.light,
|
||||
]));
|
||||
for (key in ICONS.keys()) {
|
||||
register(new Style('icon.${key}', [
|
||||
"skin.svg" => Assets.getText('resources/icon/${ICONS.get(key)}'),
|
||||
]));
|
||||
register(new Style('icon.${key}', ["skin.svg" => Assets.getText('resources/icon/${ICONS.get(key)}'),]));
|
||||
}
|
||||
register(new Style("icon.small", [
|
||||
"geometry.width" => SizeValue.fromString("6h"),
|
||||
"geometry.height" => SizeValue.fromString("6h"),
|
||||
]));
|
||||
register(new Style("icon.red", [
|
||||
"skin.color" => 0xcc0000,
|
||||
]));
|
||||
register(new Style("icon.orange", [
|
||||
"skin.color" => 0xcc5500,
|
||||
]));
|
||||
register(new Style("icon.green", [
|
||||
"skin.color" => 0x00ff00,
|
||||
]));
|
||||
register(new Style("icon.red", ["skin.color" => 0xcc0000,]));
|
||||
register(new Style("icon.orange", ["skin.color" => 0xcc5500,]));
|
||||
register(new Style("icon.green", ["skin.color" => 0x00ff00,]));
|
||||
register(new Style("icon.control", [
|
||||
"geometry.hAlign" => HAlign.RIGHT,
|
||||
"geometry.vAlign" => VAlign.TOP,
|
||||
"geometry.margin" => Box.fromFloat(3),
|
||||
]));
|
||||
|
||||
register(new Style("button.red", [
|
||||
"skin.color" => 0xcc0000,
|
||||
], "button"));
|
||||
register(new Style("button.red", ["skin.color" => 0xcc0000,], "button"));
|
||||
|
||||
register(new Style("label.header", [
|
||||
"font.size" => SizeValue.fromString("5h"),
|
||||
|
||||
@@ -9,13 +9,12 @@ import ru.m.puzzlez.core.ImageValue;
|
||||
import ru.m.puzzlez.proto.game.ImageId;
|
||||
|
||||
abstract ImageData(ImageId) from ImageId {
|
||||
|
||||
private static var cache:Map<String, Promise<BitmapData>> = new Map();
|
||||
private static var storageCache:StorageCache = new StorageCache();
|
||||
|
||||
@:provide private var sourceBundle:ImageSourceBundle;
|
||||
|
||||
public function new(image: ImageId) {
|
||||
public function new(image:ImageId) {
|
||||
this = image;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import flash.geom.Matrix;
|
||||
import ru.m.puzzlez.render.part.IPartBuilder;
|
||||
|
||||
class CompleteView extends Shape {
|
||||
|
||||
public var parts:Array<PartView>;
|
||||
public var preset:GamePreset;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ typedef Result = {
|
||||
}
|
||||
|
||||
class ImagePartBuilder {
|
||||
|
||||
private var image:BitmapData;
|
||||
|
||||
public function new(image:BitmapData) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import ru.m.puzzlez.wrap.PointExt;
|
||||
import ru.m.puzzlez.wrap.RectangleExt;
|
||||
|
||||
class PartView extends Sprite {
|
||||
|
||||
public var id(default, null):Int;
|
||||
public var part(default, null):Part;
|
||||
public var position(default, set):Point;
|
||||
@@ -88,7 +87,6 @@ class PartView extends Sprite {
|
||||
}
|
||||
|
||||
class SpritePartView extends PartView {
|
||||
|
||||
@:provide static var builder:IPartBuilder;
|
||||
|
||||
override private function redraw():Void {
|
||||
|
||||
@@ -3,7 +3,6 @@ package ru.m.puzzlez.render;
|
||||
import hw.view.form.LabelView;
|
||||
|
||||
class ProgressView extends LabelView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
text = 'Loading...';
|
||||
|
||||
@@ -22,7 +22,6 @@ import ru.m.puzzlez.settings.Settings;
|
||||
import ru.m.puzzlez.wrap.PointExt;
|
||||
|
||||
class Render extends SpriteView implements IRender {
|
||||
|
||||
public var actions(default, null):Signal<GameAction>;
|
||||
public var scale(get, set):Float;
|
||||
public var manager(default, null):RenderManager;
|
||||
@@ -44,7 +43,7 @@ class Render extends SpriteView implements IRender {
|
||||
var result = tableView.scaleX = tableView.scaleY = value;
|
||||
tableView.x = (width - state.preset.tableRect.width * value) / 2;
|
||||
tableView.y = (height - state.preset.tableRect.height * value) / 2;
|
||||
//setSize(table.width, table.height, 'table');
|
||||
// setSize(table.width, table.height, 'table');
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -198,35 +197,21 @@ class Render extends SpriteView implements IRender {
|
||||
activePoint = tableView.globalToLocal(point);
|
||||
tableView.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
tableView.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
actions.emit(new GameAction()
|
||||
.setAction(Action.TAKE)
|
||||
.setPlayerId(playerId)
|
||||
.setPartId(activePart.id)
|
||||
);
|
||||
actions.emit(new GameAction().setAction(Action.TAKE).setPlayerId(playerId).setPartId(activePart.id));
|
||||
}
|
||||
}
|
||||
|
||||
private function onMouseMove(event:MouseEvent):Void {
|
||||
var newPoint:PointExt = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY));
|
||||
var partPosition = cast(activePart.position, PointExt).add(newPoint).subtract(activePoint);
|
||||
actions.emit(new GameAction()
|
||||
.setAction(Action.MOVE)
|
||||
.setPlayerId(playerId)
|
||||
.setPartId(activePart.id)
|
||||
.setPosition(partPosition)
|
||||
);
|
||||
actions.emit(new GameAction().setAction(Action.MOVE).setPlayerId(playerId).setPartId(activePart.id).setPosition(partPosition));
|
||||
activePoint = newPoint;
|
||||
}
|
||||
|
||||
private function onMouseUp(event:MouseEvent):Void {
|
||||
var newPoint:PointExt = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY));
|
||||
var partPosition = cast(activePart.position, PointExt).add(newPoint).subtract(activePoint);
|
||||
actions.emit(new GameAction()
|
||||
.setAction(Action.PUT)
|
||||
.setPlayerId(playerId)
|
||||
.setPartId(activePart.id)
|
||||
.setPosition(partPosition)
|
||||
);
|
||||
actions.emit(new GameAction().setAction(Action.PUT).setPlayerId(playerId).setPartId(activePart.id).setPosition(partPosition));
|
||||
tableView.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
|
||||
tableView.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||
activePart = null;
|
||||
|
||||
@@ -7,7 +7,6 @@ import flash.events.MouseEvent;
|
||||
import flash.geom.Point;
|
||||
|
||||
class RenderManager {
|
||||
|
||||
public var locked(default, default):Bool;
|
||||
|
||||
private var content:DisplayObject;
|
||||
|
||||
@@ -47,8 +47,7 @@ class RenderUtil {
|
||||
}
|
||||
|
||||
private static function buildPartGeometry(part:Part):{rect:Rectangle, drawRect:Rectangle} {
|
||||
var source = new Rectangle()
|
||||
.setX(part.rect.width * part.point.x)
|
||||
var source = new Rectangle().setX(part.rect.width * part.point.x)
|
||||
.setY(part.rect.height * part.point.y)
|
||||
.setWidth(part.rect.width)
|
||||
.setHeight(part.rect.height);
|
||||
@@ -60,8 +59,8 @@ class RenderUtil {
|
||||
rect.height += offset * 2;
|
||||
var drawRect = cast(source, RectangleExt).clone();
|
||||
drawRect.x = offset;
|
||||
drawRect.y = offset ;
|
||||
return {rect:rect, drawRect:drawRect};
|
||||
drawRect.y = offset;
|
||||
return {rect: rect, drawRect: drawRect};
|
||||
}
|
||||
|
||||
private static function drawShadow(source:BitmapData, path:DrawPath, values:Array<DrawSetting>):BitmapData {
|
||||
@@ -110,7 +109,7 @@ class RenderUtil {
|
||||
var image = new BitmapData(Std.int(geometry.rect.width), Std.int(geometry.rect.height), true, 0x00000000);
|
||||
image.draw(canvas, null, null, null, null, true);
|
||||
var shadedImage = drawShadow(image, path, shadowSettings);
|
||||
//var borderedImage = drawBorder(image, path, borderSettings);
|
||||
// var borderedImage = drawBorder(image, path, borderSettings);
|
||||
return {borderedImage: image, shadedImage: shadedImage};
|
||||
}
|
||||
|
||||
@@ -118,8 +117,7 @@ class RenderUtil {
|
||||
var s = Math.min(1, Math.min(target.width / source.width, target.height / source.height));
|
||||
var width = source.width * s;
|
||||
var height = source.height * s;
|
||||
return new Rectangle()
|
||||
.setX((target.width - width) / 2)
|
||||
return new Rectangle().setX((target.width - width) / 2)
|
||||
.setY((target.height - height) / 2)
|
||||
.setWidth(width)
|
||||
.setHeight(height);
|
||||
|
||||
@@ -8,16 +8,13 @@ import ru.m.puzzlez.proto.game.PartBounds;
|
||||
import ru.m.puzzlez.render.part.IPartBuilder;
|
||||
|
||||
class BasePartBuilder implements IPartBuilder {
|
||||
public function new() {}
|
||||
|
||||
public function new() {
|
||||
}
|
||||
|
||||
private function createAngle(path:DrawPath, x:Float, y:Float, first: Bool = false):Void {
|
||||
private function createAngle(path:DrawPath, x:Float, y:Float, first:Bool = false):Void {
|
||||
path.commands.push(first ? MOVE_TO(x, y) : LINE_TO(x, y));
|
||||
}
|
||||
|
||||
private function createBound(path:DrawPath, fromX:Float, fromY:Float, toX:Float, toY:Float, bound:PartBound):Void {
|
||||
}
|
||||
private function createBound(path:DrawPath, fromX:Float, fromY:Float, toX:Float, toY:Float, bound:PartBound):Void {}
|
||||
|
||||
public function build(rect:RectangleExt, bounds:PartBounds):DrawPath {
|
||||
var path = new DrawPath();
|
||||
|
||||
@@ -5,7 +5,6 @@ import ru.m.puzzlez.proto.game.BoundType;
|
||||
import ru.m.puzzlez.proto.game.PartBound;
|
||||
|
||||
class ClassicPartBuilder extends BasePartBuilder {
|
||||
|
||||
override private function createBound(path:DrawPath, fromX:Float, fromY:Float, toX:Float, toY:Float, bound:PartBound):Void {
|
||||
var dx = toX == fromX ? 0 : (toX - fromX) / Math.abs(toX - fromX);
|
||||
var dy = toY == fromY ? 0 : (toY - fromY) / Math.abs(toY - fromY);
|
||||
@@ -24,22 +23,36 @@ class ClassicPartBuilder extends BasePartBuilder {
|
||||
}
|
||||
switch bound.spike {
|
||||
case BoundType.IN | BoundType.OUT:
|
||||
path.commands.push(LINE_TO(
|
||||
fromX + spikeOffset * dx + spikeSideOffset * dy,
|
||||
fromY + spikeOffset * dy + spikeSideOffset * dx
|
||||
));
|
||||
path.commands.push(CURVE_TO(
|
||||
fromX + (spikeOffset * 0.7) * dx - spikeDepth * dy + spikeSideOffset * dy,
|
||||
fromY + spikeDepth * dx + (spikeOffset * 0.7) * dy + spikeSideOffset * dx,
|
||||
fromX + (spikeOffset + spikeWidth / 2) * dx - (spikeDepth * 1.1) * dy + spikeSideOffset * dy,
|
||||
fromY + (spikeDepth * 1.1) * dx + (spikeOffset + spikeWidth / 2) * dy + spikeSideOffset * dx
|
||||
));
|
||||
path.commands.push(CURVE_TO(
|
||||
fromX + (spikeOffset + spikeWidth + spikeOffset * 0.3) * dx - spikeDepth * dy + spikeSideOffset * dy,
|
||||
fromY + spikeDepth * dx + (spikeOffset + spikeWidth + spikeOffset * 0.3) * dy + spikeSideOffset * dx,
|
||||
fromX + (spikeOffset + spikeWidth) * dx + spikeSideOffset * dy,
|
||||
fromY + (spikeOffset + spikeWidth) * dy + spikeSideOffset * dx
|
||||
));
|
||||
path.commands.push(LINE_TO(fromX + spikeOffset * dx + spikeSideOffset * dy, fromY + spikeOffset * dy + spikeSideOffset * dx));
|
||||
path.commands.push(CURVE_TO(fromX
|
||||
+ (spikeOffset * 0.7) * dx
|
||||
- spikeDepth * dy
|
||||
+ spikeSideOffset * dy,
|
||||
fromY
|
||||
+ spikeDepth * dx
|
||||
+ (spikeOffset * 0.7) * dy
|
||||
+ spikeSideOffset * dx,
|
||||
fromX
|
||||
+ (spikeOffset + spikeWidth / 2) * dx
|
||||
- (spikeDepth * 1.1) * dy
|
||||
+ spikeSideOffset * dy,
|
||||
fromY
|
||||
+ (spikeDepth * 1.1) * dx
|
||||
+ (spikeOffset + spikeWidth / 2) * dy
|
||||
+ spikeSideOffset * dx));
|
||||
path.commands.push(CURVE_TO(fromX
|
||||
+ (spikeOffset + spikeWidth + spikeOffset * 0.3) * dx
|
||||
- spikeDepth * dy
|
||||
+ spikeSideOffset * dy,
|
||||
fromY
|
||||
+ spikeDepth * dx
|
||||
+ (spikeOffset + spikeWidth + spikeOffset * 0.3) * dy
|
||||
+ spikeSideOffset * dx,
|
||||
fromX
|
||||
+ (spikeOffset + spikeWidth) * dx
|
||||
+ spikeSideOffset * dy, fromY
|
||||
+ (spikeOffset + spikeWidth) * dy
|
||||
+ spikeSideOffset * dx));
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import flash.display.Shape;
|
||||
import ru.m.draw.DrawPath;
|
||||
|
||||
class PartMask extends Shape {
|
||||
|
||||
public function new(path:DrawPath) {
|
||||
super();
|
||||
graphics.beginFill(0xff00ff, 1);
|
||||
|
||||
@@ -5,7 +5,6 @@ import ru.m.puzzlez.proto.game.BoundType;
|
||||
import ru.m.puzzlez.proto.game.PartBound;
|
||||
|
||||
class SquarePartBuilder extends BasePartBuilder {
|
||||
|
||||
override private function createBound(path:DrawPath, fromX:Float, fromY:Float, toX:Float, toY:Float, bound:PartBound):Void {
|
||||
var dx = toX == fromX ? 0 : (toX - fromX) / Math.abs(toX - fromX);
|
||||
var dy = toY == fromY ? 0 : (toY - fromY) / Math.abs(toY - fromY);
|
||||
@@ -20,22 +19,10 @@ class SquarePartBuilder extends BasePartBuilder {
|
||||
switch bound.spike {
|
||||
case BoundType.NONE:
|
||||
case BoundType.IN | BoundType.OUT:
|
||||
path.commands.push(LINE_TO(
|
||||
fromX + spikeOffset * dx,
|
||||
fromY + spikeOffset * dy
|
||||
))
|
||||
path.commands.push(LINE_TO(
|
||||
fromX + spikeOffset * dx - spikeDepth * dy,
|
||||
fromY + spikeDepth * dx + spikeOffset * dy
|
||||
));
|
||||
path.commands.push(LINE_TO(
|
||||
fromX + (spikeOffset + spikeWidth) * dx - spikeDepth * dy,
|
||||
fromY + spikeDepth * dx + (spikeOffset + spikeWidth) * dy
|
||||
));
|
||||
path.commands.push(LINE_TO(
|
||||
fromX + (spikeOffset + spikeWidth) * dx,
|
||||
fromY + (spikeOffset + spikeWidth) * dy
|
||||
));
|
||||
path.commands.push(LINE_TO(fromX + spikeOffset * dx,
|
||||
fromY + spikeOffset * dy)) path.commands.push(LINE_TO(fromX + spikeOffset * dx - spikeDepth * dy, fromY + spikeDepth * dx + spikeOffset * dy));
|
||||
path.commands.push(LINE_TO(fromX + (spikeOffset + spikeWidth) * dx - spikeDepth * dy, fromY + spikeDepth * dx + (spikeOffset + spikeWidth) * dy));
|
||||
path.commands.push(LINE_TO(fromX + (spikeOffset + spikeWidth) * dx, fromY + (spikeOffset + spikeWidth) * dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ class AssetImageSource implements ImageSource {
|
||||
return _data;
|
||||
}
|
||||
|
||||
public function new() {
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
private function resolveData():Array<ImageId> {
|
||||
return [for (name in Assets.list(AssetType.IMAGE).filter((name:String) -> name.substr(0, 15) == "resources/image")) new ImageId().setSource(id).setId(name)];
|
||||
return [
|
||||
for (name in Assets.list(AssetType.IMAGE).filter((name:String) -> name.substr(0, 15) == "resources/image"))
|
||||
new ImageId().setSource(id).setId(name)
|
||||
];
|
||||
}
|
||||
|
||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||
|
||||
@@ -12,8 +12,7 @@ class FileImageSource implements ImageSource {
|
||||
|
||||
@:provide private var storage:FileStorage;
|
||||
|
||||
public function new() {
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||
return storage.getIndexPage(page).then((response:DataPage<String>) -> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.puzzlez.source;
|
||||
|
||||
import promhx.Promise;
|
||||
import ru.m.api.PixabayApi;
|
||||
import ru.m.data.DataSource;
|
||||
import ru.m.pixabay.PixabayApi;
|
||||
import ru.m.puzzlez.core.ImageSource;
|
||||
import ru.m.puzzlez.core.ImageValue;
|
||||
import ru.m.puzzlez.proto.game.ImageId;
|
||||
@@ -11,6 +11,7 @@ class PixabayImageSource implements ImageSource {
|
||||
public var id(default, never):String = "pixabay";
|
||||
|
||||
private var api:PixabayApi;
|
||||
|
||||
private static var imageUrlsCache:Map<String, String> = new Map();
|
||||
|
||||
public function new() {
|
||||
@@ -19,8 +20,7 @@ class PixabayImageSource implements ImageSource {
|
||||
}
|
||||
|
||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||
return this.api.getPage(page.index + 1, page.count, page.filter.get("category"))
|
||||
.then((response:PixabayResponse) -> {
|
||||
return this.api.getPage(page.index + 1, page.count, page.filter.get("category")).then((response:PixabayResponse) -> {
|
||||
var data:Array<ImageId> = [];
|
||||
for (hit in response.hits) {
|
||||
imageUrlsCache.set('${hit.id}', hit.largeImageURL);
|
||||
|
||||
@@ -7,13 +7,10 @@ import ru.m.puzzlez.core.ImageSource;
|
||||
import ru.m.puzzlez.core.ImageValue;
|
||||
import ru.m.puzzlez.proto.game.ImageId;
|
||||
|
||||
|
||||
typedef Resolver = (id:String, thumb: Bool) -> Promise<String>;
|
||||
|
||||
typedef Resolver = (id:String, thumb:Bool) -> Promise<String>;
|
||||
|
||||
class ImageResolver {
|
||||
|
||||
private var cache: Map<String, String>;
|
||||
private var cache:Map<String, String>;
|
||||
private var resolver:Resolver;
|
||||
|
||||
public function new(resolver:Resolver) {
|
||||
@@ -29,8 +26,9 @@ class ImageResolver {
|
||||
return key;
|
||||
}
|
||||
|
||||
public function setValue(id:String, url:String):Void {
|
||||
cache.set(id, url);
|
||||
public function setValue(id:String, url:String, thumb:Bool = false):Void {
|
||||
var key = buildKey(id, thumb);
|
||||
cache.set(key, url);
|
||||
}
|
||||
|
||||
public function resolve(id:String, thumb:Bool = false) {
|
||||
@@ -50,21 +48,22 @@ class UnsplashImageSource implements ImageSource {
|
||||
public var id(default, never):String = "unsplash";
|
||||
|
||||
private var api:UnsplashApi;
|
||||
|
||||
private static var resolver:ImageResolver;
|
||||
|
||||
public function new() {
|
||||
var key:String = CompilationOption.get("UNSPLASH_KEY");
|
||||
api = new UnsplashApi(key);
|
||||
resolver = new ImageResolver((imageId, thumb) -> {
|
||||
return api.get(imageId).then(data -> thumb ? data.urls.thumb : data.urls.regular);
|
||||
return api.get(imageId).then(data -> thumb ? data.urls.small : data.urls.regular);
|
||||
});
|
||||
}
|
||||
|
||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||
return this.api.getPage(page.index + 1, page.count, page.filter.get("category"))
|
||||
.then((response:UnsplashResponse) -> {
|
||||
return this.api.getPage(page.index + 1, page.count, page.filter.get("category")).then((response:UnsplashResponse) -> {
|
||||
var data:Array<ImageId> = [];
|
||||
for (image in response.results) {
|
||||
resolver.setValue(image.id, image.urls.small, true);
|
||||
resolver.setValue(image.id, image.urls.regular);
|
||||
data.push(new ImageId().setSource(id).setId(image.id));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import haxe.io.Bytes;
|
||||
import ru.m.storage.SharedObjectDataStorage;
|
||||
|
||||
@:provide class FileStorage extends SharedObjectDataStorage<Bytes, String> {
|
||||
|
||||
public function new() {
|
||||
super("file", new DefaultHelper());
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ import ru.m.puzzlez.proto.game.ImageId;
|
||||
import ru.m.storage.SharedObjectDataStorage;
|
||||
|
||||
class GameStorageHelper implements DataHelper<GameState, ImageId> {
|
||||
public function new() {
|
||||
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
public function idKey(id:ImageId):String {
|
||||
return '${id.source}:${id.id}';
|
||||
@@ -33,15 +31,11 @@ class GameStorageHelper implements DataHelper<GameState, ImageId> {
|
||||
}
|
||||
|
||||
public function dataMeta(data:GameState):DataMeta {
|
||||
return [
|
||||
"status" => data.status,
|
||||
"date" => Date.now(),
|
||||
];
|
||||
return ["status" => data.status, "date" => Date.now(),];
|
||||
}
|
||||
}
|
||||
|
||||
@:provide class GameStorage extends SharedObjectDataStorage<GameState, ImageId> {
|
||||
|
||||
public function new() {
|
||||
super("game", new GameStorageHelper());
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
||||
override public function onShow(state:GameState):Void {
|
||||
onHide();
|
||||
if (state.online) {
|
||||
//game = new NetworkGame(state);
|
||||
// game = new NetworkGame(state);
|
||||
} else {
|
||||
game = new Game(state);
|
||||
}
|
||||
@@ -92,8 +92,7 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
||||
}
|
||||
|
||||
private function back():Void {
|
||||
(game.state.status == GameStatus.COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?"))
|
||||
.then(result -> {
|
||||
(game.state.status == GameStatus.COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?")).then(result -> {
|
||||
if (result) {
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import ru.m.puzzlez.view.common.PresetView;
|
||||
@:view("sizes") var sizesView:DataView<IntPoint, ToggleButtonView>;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
//@:provide var network:Network;
|
||||
|
||||
// @:provide var network:Network;
|
||||
private var imageId:ImageId;
|
||||
|
||||
public function new() {
|
||||
@@ -54,7 +54,7 @@ import ru.m.puzzlez.view.common.PresetView;
|
||||
|
||||
private function start(online:Bool = false):Void {
|
||||
if (online) {
|
||||
//network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state));
|
||||
// network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state));
|
||||
} else {
|
||||
switcher.change(GameFrame.ID, imageView.state);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.group.VGroupView;
|
||||
|
||||
@:template class PuzzlezAppView extends VGroupView {
|
||||
|
||||
@:view("switcher") var switcherView:FrameSwitcher;
|
||||
@:view("fullscreen") var fullscreenButton:ButtonView;
|
||||
@:view("user") var userLabel:LabelView;
|
||||
@@ -26,7 +25,7 @@ import hw.view.group.VGroupView;
|
||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, (event:KeyboardEvent) -> {
|
||||
switch event.keyCode {
|
||||
case Keyboard.ESCAPE:
|
||||
//switcher.change(StartFrame.ID);
|
||||
// switcher.change(StartFrame.ID);
|
||||
case Keyboard.F:
|
||||
app.fullScreen = !app.fullScreen;
|
||||
case _:
|
||||
|
||||
@@ -4,13 +4,13 @@ import hw.view.data.DataView;
|
||||
import hw.view.form.ButtonView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.pixabay.PixabayApi;
|
||||
import ru.m.api.PixabayApi;
|
||||
import ru.m.puzzlez.FileUtil;
|
||||
import ru.m.puzzlez.proto.game.GameStatus;
|
||||
import ru.m.puzzlez.storage.FileStorage;
|
||||
import ru.m.puzzlez.storage.GameStorage;
|
||||
import ru.m.puzzlez.view.ImageListFrame;
|
||||
import ru.m.puzzlez.view.GameListFrame;
|
||||
import ru.m.puzzlez.view.ImageListFrame;
|
||||
import ru.m.update.Updater;
|
||||
|
||||
@:template class StartFrame extends FrameView<Dynamic> {
|
||||
@@ -22,7 +22,9 @@ import ru.m.update.Updater;
|
||||
@:view var updateButton:ButtonView;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
@:provide static var appUpdater:Updater;
|
||||
|
||||
@:provide var fileStorage:FileStorage;
|
||||
@:provide var gameStorage:GameStorage;
|
||||
|
||||
@@ -48,9 +50,7 @@ import ru.m.update.Updater;
|
||||
}
|
||||
|
||||
public function upload():Void {
|
||||
FileUtil.browse()
|
||||
.pipe((data:FileContent) -> fileStorage.save(data.content))
|
||||
.then(_ -> showSource(fileSource));
|
||||
FileUtil.browse().pipe((data:FileContent) -> fileStorage.save(data.content)).then(_ -> showSource(fileSource));
|
||||
}
|
||||
|
||||
public function showSource(config:ImageListConfig):Void {
|
||||
@@ -72,10 +72,10 @@ import ru.m.update.Updater;
|
||||
}
|
||||
|
||||
private function refresh():Void {
|
||||
gameStorage.getIndexPage({index:0, count:0, filter:startedGames.filter}).then(response -> {
|
||||
gameStorage.getIndexPage({index: 0, count: 0, filter: startedGames.filter}).then(response -> {
|
||||
startedButton.text = response.total > 0 ? 'Started (${response.total})' : 'Started';
|
||||
});
|
||||
gameStorage.getIndexPage({index:0, count:0, filter:completedGames.filter}).then(response -> {
|
||||
gameStorage.getIndexPage({index: 0, count: 0, filter: completedGames.filter}).then(response -> {
|
||||
completedButton.text = response.total > 0 ? 'Completed (${response.total})' : 'Completed';
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import ru.m.puzzlez.proto.game.GameState;
|
||||
@:view var image:ImageIdView;
|
||||
@:view var label:LabelView;
|
||||
|
||||
public function new(?state:GameState, ?style: StyleId) {
|
||||
public function new(?state:GameState, ?style:StyleId) {
|
||||
super();
|
||||
this.style = style;
|
||||
if (state != null) {
|
||||
|
||||
@@ -8,27 +8,24 @@ import ru.m.puzzlez.proto.game.ImageId;
|
||||
import ru.m.view.LoadingWrapper;
|
||||
|
||||
@:template class ImageIdView extends GroupView {
|
||||
|
||||
public var thumb:Bool = false;
|
||||
|
||||
public var imageId(default, set):ImageId;
|
||||
|
||||
private function set_imageId(value:ImageId):ImageId {
|
||||
imageId = value;
|
||||
var imageData = ImageData
|
||||
.fromImageId(imageId);
|
||||
var imageData = ImageData.fromImageId(imageId);
|
||||
if (thumb) {
|
||||
imageData = imageData.withThumb();
|
||||
}
|
||||
loading.promise = imageData
|
||||
.resolve()
|
||||
.then(data -> this.imageView.image = data);
|
||||
loading.promise = imageData.resolve().then(data -> this.imageView.image = data);
|
||||
return imageId;
|
||||
}
|
||||
|
||||
@:view("image") var imageView:ImageView;
|
||||
private var loading:LoadingWrapper;
|
||||
|
||||
public function new(?imageId:ImageId, ?style: StyleId, ?thumb: Bool = false) {
|
||||
public function new(?imageId:ImageId, ?style:StyleId, ?thumb:Bool = false) {
|
||||
super();
|
||||
this.style = style;
|
||||
this.thumb = thumb;
|
||||
|
||||
@@ -15,25 +15,9 @@ import ru.m.puzzlez.proto.game.ImageId;
|
||||
import ru.m.puzzlez.render.Background;
|
||||
|
||||
@:singleton @:template class BackgroundPopup extends PopupView<Background> {
|
||||
|
||||
private static var colorsList:Array<Color> = [
|
||||
'#FFFFFF',
|
||||
'#001f3f',
|
||||
'#0074D9',
|
||||
'#7FDBFF',
|
||||
'#39CCCC',
|
||||
'#3D9970',
|
||||
'#2ECC40',
|
||||
'#01FF70',
|
||||
'#FFDC00',
|
||||
'#FF851B',
|
||||
'#FF4136',
|
||||
'#85144b',
|
||||
'#F012BE',
|
||||
'#B10DC9',
|
||||
'#111111',
|
||||
'#AAAAAA',
|
||||
'#DDDDDD',
|
||||
'#FFFFFF', '#001f3f', '#0074D9', '#7FDBFF', '#39CCCC', '#3D9970', '#2ECC40', '#01FF70', '#FFDC00', '#FF851B', '#FF4136', '#85144b', '#F012BE', '#B10DC9',
|
||||
'#111111', '#AAAAAA', '#DDDDDD',
|
||||
];
|
||||
|
||||
@:view("selected") var selectedView:SpriteView;
|
||||
|
||||
@@ -7,7 +7,6 @@ import promhx.Promise;
|
||||
import ru.m.puzzlez.view.common.PresetView;
|
||||
|
||||
@:singleton @:template class PreviewPopup extends PopupView<Dynamic> {
|
||||
|
||||
@:view("preview") var previewView:PresetView;
|
||||
|
||||
public function new() {
|
||||
|
||||
@@ -10,7 +10,6 @@ using StringTools;
|
||||
using hw.color.ColorUtil;
|
||||
|
||||
@:style class ButtonSVGSkin implements ISkin<ButtonView> {
|
||||
|
||||
@:style(null) public var svg:String;
|
||||
@:style(0) public var color:Null<Color>;
|
||||
@:style(false) public var solid:Null<Bool>;
|
||||
|
||||
@@ -30,9 +30,7 @@ interface DataHelper<D, I> {
|
||||
}
|
||||
|
||||
class DefaultHelper implements DataHelper<Bytes, String> {
|
||||
public function new() {
|
||||
|
||||
}
|
||||
public function new() {}
|
||||
|
||||
public function idKey(id:String):String {
|
||||
return id;
|
||||
|
||||
@@ -30,7 +30,6 @@ typedef PackagesBundle = {
|
||||
}
|
||||
|
||||
class Updater {
|
||||
|
||||
private static inline var TAG = "Update";
|
||||
|
||||
public var type(get, null):PackageType;
|
||||
@@ -61,11 +60,8 @@ class Updater {
|
||||
}
|
||||
|
||||
public function check():Promise<Null<PackageInfo>> {
|
||||
return bundle.then((bundle:PackagesBundle) -> Lambda.find(bundle.packages, item -> (
|
||||
item.platform == Device.platform &&
|
||||
item.type == type &&
|
||||
version < Version.fromString(item.version)
|
||||
)));
|
||||
return bundle.then((bundle:PackagesBundle) -> Lambda.find(bundle.packages,
|
||||
item -> (item.platform == Device.platform && item.type == type && version < Version.fromString(item.version))));
|
||||
}
|
||||
|
||||
public function download():Promise<Bool> {
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package ru.m.update;
|
||||
|
||||
abstract Version(Array<Int>) {
|
||||
|
||||
public function new(mayor:Int, minor:Int, patch:Int, snapshot:Bool = false) {
|
||||
this = [
|
||||
mayor,
|
||||
minor,
|
||||
patch,
|
||||
snapshot ? -1 : 0,
|
||||
];
|
||||
this = [mayor, minor, patch, snapshot ? -1 : 0,];
|
||||
}
|
||||
|
||||
@:arrayAccess public inline function get(key:Int) return this[key];
|
||||
@:arrayAccess public inline function get(key:Int)
|
||||
return this[key];
|
||||
|
||||
public function compare(other:Version):Int {
|
||||
if (other == null) {
|
||||
@@ -26,21 +21,19 @@ abstract Version(Array<Int>) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@:op(A > B) static function gt(a:Version, b:Version):Bool return a.compare(b) > 0;
|
||||
@:op(A > B) static function gt(a:Version, b:Version):Bool
|
||||
return a.compare(b) > 0;
|
||||
|
||||
@:op(A == B) static function eq(a:Version, b:Version):Bool return a.compare(b) == 0;
|
||||
@:op(A == B) static function eq(a:Version, b:Version):Bool
|
||||
return a.compare(b) == 0;
|
||||
|
||||
@:op(A < B) static function lt(a:Version, b:Version):Bool return a.compare(b) < 0;
|
||||
@:op(A < B) static function lt(a:Version, b:Version):Bool
|
||||
return a.compare(b) < 0;
|
||||
|
||||
@:from public static function fromString(value:String):Version {
|
||||
var r = ~/(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?/;
|
||||
return if (r.match(value)) {
|
||||
new Version(
|
||||
Std.parseInt(r.matched(1)),
|
||||
Std.parseInt(r.matched(2)),
|
||||
Std.parseInt(r.matched(3)),
|
||||
r.matched(4) != null
|
||||
);
|
||||
new Version(Std.parseInt(r.matched(1)), Std.parseInt(r.matched(2)), Std.parseInt(r.matched(3)), r.matched(4) != null);
|
||||
} else {
|
||||
new Version(0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import ru.m.data.DataSource;
|
||||
import ru.m.view.LoadingWrapper;
|
||||
|
||||
@:template class DataList<T, V:View<Dynamic>> extends VGroupView {
|
||||
|
||||
public var source:DataSource<T>;
|
||||
public var page:Page;
|
||||
|
||||
@:view public var list(default, null):DataView<T, V>;
|
||||
|
||||
@:view private var paginator:PaginatorView;
|
||||
private var loading:LoadingWrapper;
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ class LoadingWrapper {
|
||||
|
||||
private function set_promise(value:Promise<Dynamic>):Promise<Dynamic> {
|
||||
state = LOADING;
|
||||
value
|
||||
.then(_ -> state = NONE)
|
||||
.catchError(error -> state = ERROR(error));
|
||||
value.then(_ -> state = NONE).catchError(error -> state = ERROR(error));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ class PaginatorButtonView extends ToggleButtonView {
|
||||
}
|
||||
|
||||
class PaginatorView extends DataView<PaginatorAction, PaginatorButtonView> {
|
||||
|
||||
public var page(default, set):DataPage<Dynamic>;
|
||||
public var onPageSelect(default, null):Signal<Int>;
|
||||
|
||||
|
||||
@@ -9,12 +9,8 @@ import ru.m.puzzlez.proto.event.GameEvent;
|
||||
import ru.m.puzzlez.proto.game.GameState;
|
||||
|
||||
class EventUtil {
|
||||
|
||||
public static function start(state:GameState, resume: Bool):GameEvent {
|
||||
return new GameEvent().setStart(new GameStart()
|
||||
.setState(state)
|
||||
.setResume(resume)
|
||||
);
|
||||
public static function start(state:GameState, resume:Bool):GameEvent {
|
||||
return new GameEvent().setStart(new GameStart().setState(state).setResume(resume));
|
||||
}
|
||||
|
||||
public static function complete():GameEvent {
|
||||
@@ -26,11 +22,6 @@ class EventUtil {
|
||||
}
|
||||
|
||||
public static function change(part:Part):GameEvent {
|
||||
return new GameEvent().setChange(new GameChange()
|
||||
.setPartId(part.id)
|
||||
.setLocation(part.location)
|
||||
.setPosition(part.position)
|
||||
.setPlayerId(part.playerId)
|
||||
);
|
||||
return new GameEvent().setChange(new GameChange().setPartId(part.id).setLocation(part.location).setPosition(part.position).setPlayerId(part.playerId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ class Game implements IGame {
|
||||
for (part in partsById) {
|
||||
switch part.location {
|
||||
case PartLocation.IMAGE:
|
||||
case _: return false;
|
||||
case _:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -91,8 +92,8 @@ class Game implements IGame {
|
||||
}
|
||||
case Action.PUT:
|
||||
part.playerId = null;
|
||||
var target = new PointExt(state.preset.imageRect.x, state.preset.imageRect.y)
|
||||
.add(new PointExt(part.point.x * part.rect.width, part.point.y * part.rect.height));
|
||||
var target = new PointExt(state.preset.imageRect.x,
|
||||
state.preset.imageRect.y).add(new PointExt(part.point.x * part.rect.width, part.point.y * part.rect.height));
|
||||
var d = distance(target, event.action.position);
|
||||
if (d < 70) {
|
||||
part.location = PartLocation.IMAGE;
|
||||
@@ -110,9 +111,7 @@ class Game implements IGame {
|
||||
}
|
||||
}
|
||||
|
||||
public function stop():Void {
|
||||
|
||||
}
|
||||
public function stop():Void {}
|
||||
|
||||
public function dispose():Void {
|
||||
events.dispose();
|
||||
|
||||
@@ -15,7 +15,6 @@ import ru.m.puzzlez.proto.game.PartBounds;
|
||||
import ru.m.puzzlez.proto.game.PartLocation;
|
||||
|
||||
class BoundsMap {
|
||||
|
||||
private var grid:IntPoint;
|
||||
private var bounds:Array<PartBound>;
|
||||
|
||||
@@ -65,32 +64,25 @@ class BoundsMap {
|
||||
}
|
||||
|
||||
class GameUtil {
|
||||
|
||||
private static inline var MAX_SIZE = 20;
|
||||
|
||||
private static function normilizeSize(size:Int, maxValue:Int = MAX_SIZE):Int {
|
||||
return Math.isNaN(size) ? maxValue : size < 1 ? 1 : size > maxValue ? maxValue : size;
|
||||
}
|
||||
|
||||
public static function buildPreset(image: ImageId, width:Int = 8, height:Int = MAX_SIZE):GamePreset {
|
||||
public static function buildPreset(image:ImageId, width:Int = 8, height:Int = MAX_SIZE):GamePreset {
|
||||
width = normilizeSize(width);
|
||||
height = normilizeSize(height);
|
||||
var offsetX = 500;
|
||||
var offsetY = 200;
|
||||
var imageSize = 1024;
|
||||
var s = width / height;
|
||||
var imageRect = new Rectangle()
|
||||
.setX(offsetX)
|
||||
.setY(offsetY)
|
||||
.setWidth(imageSize)
|
||||
.setHeight(imageSize / s);
|
||||
var tableRect = new Rectangle()
|
||||
.setX(0)
|
||||
var imageRect = new Rectangle().setX(offsetX).setY(offsetY).setWidth(imageSize).setHeight(imageSize / s);
|
||||
var tableRect = new Rectangle().setX(0)
|
||||
.setY(0)
|
||||
.setWidth(imageRect.width + offsetX * 2)
|
||||
.setHeight(imageRect.height + offsetY * 2);
|
||||
return new GamePreset()
|
||||
.setImage(image)
|
||||
return new GamePreset().setImage(image)
|
||||
.setGrid(new IntPoint().setX(width).setY(height))
|
||||
.setTableRect(tableRect)
|
||||
.setImageRect(imageRect);
|
||||
@@ -104,8 +96,7 @@ class GameUtil {
|
||||
var boundsMap = new BoundsMap(preset.grid);
|
||||
for (y in 0...preset.grid.y) {
|
||||
for (x in 0...preset.grid.x) {
|
||||
var bounds:PartBounds = new PartBounds()
|
||||
.setLeft(boundsMap.getBound(x, y, LEFT))
|
||||
var bounds:PartBounds = new PartBounds().setLeft(boundsMap.getBound(x, y, LEFT))
|
||||
.setRight(boundsMap.getBound(x, y, RIGHT))
|
||||
.setTop(boundsMap.getBound(x, y, TOP))
|
||||
.setBottom(boundsMap.getBound(x, y, BOTTOM));
|
||||
@@ -123,31 +114,26 @@ class GameUtil {
|
||||
}
|
||||
var id = (x << 16) + y;
|
||||
var position = new Point().setX(position.x + x * partWidth).setY(position.y + y * partHeight);
|
||||
parts.push(new Part()
|
||||
.setId(id)
|
||||
parts.push(new Part().setId(id)
|
||||
.setPoint(new IntPoint().setX(x).setY(y))
|
||||
.setLocation(PartLocation.TABLE)
|
||||
.setPosition(position)
|
||||
.setBounds(bounds)
|
||||
.setRect(new Rectangle().setX(0).setY(0).setWidth(partWidth).setHeight(partHeight))
|
||||
);
|
||||
.setRect(new Rectangle().setX(0).setY(0).setWidth(partWidth).setHeight(partHeight)));
|
||||
}
|
||||
}
|
||||
return new GameState()
|
||||
.setId(IdUtil.generate())
|
||||
.setStatus(GameStatus.READY)
|
||||
.setPreset(preset)
|
||||
.setParts(parts);
|
||||
return new GameState().setId(IdUtil.generate()).setStatus(GameStatus.READY).setPreset(preset).setParts(parts);
|
||||
}
|
||||
|
||||
public static function calcProgress(state:GameState):{complete:Int, total:Int} {
|
||||
var complete = 0;
|
||||
for (part in state.parts) {
|
||||
switch part.location {
|
||||
case PartLocation.IMAGE: complete++;
|
||||
case PartLocation.IMAGE:
|
||||
complete++;
|
||||
case _:
|
||||
}
|
||||
}
|
||||
return {complete:complete, total:state.parts.length};
|
||||
return {complete: complete, total: state.parts.length};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,36 +6,25 @@ import flash.geom.Point as FlashPoint;
|
||||
#end
|
||||
|
||||
abstract PointExt(Point) from Point to Point {
|
||||
|
||||
public function new(x: Float = 0, y: Float = 0) {
|
||||
this = new Point()
|
||||
.setX(x)
|
||||
.setY(y);
|
||||
public function new(x:Float = 0, y:Float = 0) {
|
||||
this = new Point().setX(x).setY(y);
|
||||
}
|
||||
|
||||
public function clone():PointExt {
|
||||
return new Point()
|
||||
.setX(this.x)
|
||||
.setY(this.y);
|
||||
return new Point().setX(this.x).setY(this.y);
|
||||
}
|
||||
|
||||
public function add(point:Point):PointExt {
|
||||
return new Point()
|
||||
.setX(this.x + point.x)
|
||||
.setY(this.y + point.y);
|
||||
return new Point().setX(this.x + point.x).setY(this.y + point.y);
|
||||
}
|
||||
|
||||
public function subtract(point:Point):PointExt {
|
||||
return new Point()
|
||||
.setX(this.x - point.x)
|
||||
.setY(this.y - point.y);
|
||||
return new Point().setX(this.x - point.x).setY(this.y - point.y);
|
||||
}
|
||||
|
||||
#if app
|
||||
@:from public static function fromFlashPoint(point:FlashPoint):PointExt {
|
||||
return new Point()
|
||||
.setX(point.x)
|
||||
.setY(point.y);
|
||||
return new Point().setX(point.x).setY(point.y);
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
@@ -11,11 +11,7 @@ abstract RectangleExt(Rectangle) from Rectangle to Rectangle {
|
||||
public var size(get, never):Point;
|
||||
|
||||
public function new(x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0) {
|
||||
this = new Rectangle()
|
||||
.setX(x)
|
||||
.setY(y)
|
||||
.setWidth(width)
|
||||
.setHeight(height);
|
||||
this = new Rectangle().setX(x).setY(y).setWidth(width).setHeight(height);
|
||||
}
|
||||
|
||||
private function get_left():Float {
|
||||
@@ -35,16 +31,10 @@ abstract RectangleExt(Rectangle) from Rectangle to Rectangle {
|
||||
}
|
||||
|
||||
private function get_size():Point {
|
||||
return new Point()
|
||||
.setX(this.width)
|
||||
.setY(this.height);
|
||||
return new Point().setX(this.width).setY(this.height);
|
||||
}
|
||||
|
||||
public function clone():Rectangle {
|
||||
return new Rectangle()
|
||||
.setX(this.x)
|
||||
.setY(this.y)
|
||||
.setWidth(this.width)
|
||||
.setHeight(this.height);
|
||||
return new Rectangle().setX(this.x).setY(this.y).setWidth(this.width).setHeight(this.height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,12 +66,10 @@ class GameSession extends ProtoSession<Response, Request> {
|
||||
private function list(list:GameListRequest):Void {
|
||||
var games = Lambda.array(gamesById);
|
||||
var pageGames = games.slice(list.page * list.count, list.count);
|
||||
send(new Response().setList(new GameListResponse()
|
||||
.setPage(list.page)
|
||||
send(new Response().setList(new GameListResponse().setPage(list.page)
|
||||
.setCount(list.count)
|
||||
.setTotal(games.length)
|
||||
.setGames(pageGames.map(game -> game.state))
|
||||
));
|
||||
.setGames(pageGames.map(game -> game.state))));
|
||||
}
|
||||
|
||||
private function create(create:GameCreateRequest):Void {
|
||||
|
||||
@@ -13,7 +13,6 @@ typedef ClientMessage<M> = {
|
||||
}
|
||||
|
||||
class PuzzlezServer extends ThreadServer<GameSession, Message> {
|
||||
|
||||
private static inline var TAG = 'Server';
|
||||
|
||||
override public function clientConnected(socket:Socket):GameSession {
|
||||
@@ -27,8 +26,8 @@ class PuzzlezServer extends ThreadServer<GameSession, Message> {
|
||||
session.disconnect();
|
||||
}
|
||||
|
||||
override public function readClientMessage(session:GameSession, buf:Bytes, pos:Int, len:Int): ClientMessage<Message> {
|
||||
//L.d(TAG, 'Client message: ${buf}');
|
||||
override public function readClientMessage(session:GameSession, buf:Bytes, pos:Int, len:Int):ClientMessage<Message> {
|
||||
// L.d(TAG, 'Client message: ${buf}');
|
||||
return {msg: buf.sub(pos, len), bytes: len};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
const gulp = require('gulp');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const path = require('path');
|
||||
const through = require('through2');
|
||||
const gulp = require("gulp");
|
||||
const fs = require("fs");
|
||||
const fse = require("fs-extra");
|
||||
const path = require("path");
|
||||
const through = require("through2");
|
||||
|
||||
class Package {
|
||||
|
||||
constructor(platform, type, version, versionInt) {
|
||||
this.platform = platform;
|
||||
this.type = type;
|
||||
@@ -14,16 +13,16 @@ class Package {
|
||||
}
|
||||
|
||||
get key() {
|
||||
return [this.platform, this.type].join(':');
|
||||
return [this.platform, this.type].join(":");
|
||||
}
|
||||
|
||||
static getPlatform(filename) {
|
||||
for (const [platform, r] of [
|
||||
['android', /^.*?\.apk$/],
|
||||
['linux', /^.*?\.deb$/],
|
||||
['linux', /^.*?linux\.tar\.gz$/],
|
||||
['windows', /^.*?win\.zip$/],
|
||||
['windows', /^.*?\.exe$/],
|
||||
["android", /^.*?\.apk$/],
|
||||
["linux", /^.*?\.deb$/],
|
||||
["linux", /^.*?linux\.tar\.gz$/],
|
||||
["windows", /^.*?win\.zip$/],
|
||||
["windows", /^.*?\.exe$/],
|
||||
]) {
|
||||
if (r.test(filename)) {
|
||||
return platform;
|
||||
@@ -34,11 +33,11 @@ class Package {
|
||||
|
||||
static getType(filename) {
|
||||
for (const [type, r] of [
|
||||
['apk', /^.*?\.apk$/],
|
||||
['deb', /^.*?\.deb$/],
|
||||
['archive', /^.*?\.tar\.gz$/],
|
||||
['archive', /^.*?\.zip$/],
|
||||
['exe', /^.*?\.exe$/],
|
||||
["apk", /^.*?\.apk$/],
|
||||
["deb", /^.*?\.deb$/],
|
||||
["archive", /^.*?\.tar\.gz$/],
|
||||
["archive", /^.*?\.zip$/],
|
||||
["exe", /^.*?\.exe$/],
|
||||
]) {
|
||||
if (r.test(filename)) {
|
||||
return type;
|
||||
@@ -50,7 +49,10 @@ class Package {
|
||||
static getVersion(filename) {
|
||||
const m = /(\d+)\.(\d+)\.(\d+)/.exec(filename);
|
||||
if (m) {
|
||||
return [m[0], parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3])];
|
||||
return [
|
||||
m[0],
|
||||
parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3]),
|
||||
];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -66,28 +68,37 @@ class Package {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (name, version, publishDir, publishUrl) => function publish(cb) {
|
||||
module.exports = (name, version, publishDir, publishUrl) =>
|
||||
function publish(cb) {
|
||||
const packages = {};
|
||||
fse.ensureDirSync(publishDir);
|
||||
return gulp.series([
|
||||
function copy() {
|
||||
return gulp.src('target/app/@(android|archive|debian|installer)/*')
|
||||
.pipe(through.obj(function (file, enc, cb) {
|
||||
return gulp
|
||||
.src("target/app/@(android|archive|debian|installer)/*")
|
||||
.pipe(
|
||||
through.obj(function (file, enc, cb) {
|
||||
const pack = Package.parseFilename(file.path);
|
||||
if (pack) {
|
||||
this.push(file);
|
||||
}
|
||||
cb(null);
|
||||
}))
|
||||
.pipe(gulp.dest(publishDir))
|
||||
})
|
||||
)
|
||||
.pipe(gulp.dest(publishDir));
|
||||
},
|
||||
function generate() {
|
||||
return gulp.src(`${publishDir}/*/*`)
|
||||
.pipe(through.obj(function (file, enc, cb) {
|
||||
const basepath = file.path.replace(file.base + path.sep, '');
|
||||
return gulp
|
||||
.src(`${publishDir}/*/*`)
|
||||
.pipe(
|
||||
through.obj(function (file, enc, cb) {
|
||||
const basepath = file.path.replace(file.base + path.sep, "");
|
||||
const pack = Package.parseFilename(file.path);
|
||||
if (pack) {
|
||||
if (!packages[pack.key] || packages[pack.key].versionInt < pack.versionInt) {
|
||||
if (
|
||||
!packages[pack.key] ||
|
||||
packages[pack.key].versionInt < pack.versionInt
|
||||
) {
|
||||
packages[pack.key] = {
|
||||
platform: pack.platform,
|
||||
type: pack.type,
|
||||
@@ -96,19 +107,28 @@ module.exports = (name, version, publishDir, publishUrl) => function publish(cb)
|
||||
path: basepath,
|
||||
filename: basepath.split(path.sep).pop(),
|
||||
url: `${publishUrl}/${basepath.replace(path.sep, "/")}`,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
cb(null);
|
||||
})).on('end', function () {
|
||||
fs.writeFileSync(path.join(publishDir, 'packages.json'), JSON.stringify({
|
||||
})
|
||||
)
|
||||
.on("end", function () {
|
||||
fs.writeFileSync(
|
||||
path.join(publishDir, "packages.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
name: name,
|
||||
version: version,
|
||||
packages: Object.values(packages),
|
||||
}, null, 4));
|
||||
})
|
||||
}
|
||||
},
|
||||
null,
|
||||
4
|
||||
)
|
||||
);
|
||||
});
|
||||
},
|
||||
])(cb);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.Package = Package;
|
||||
|
||||
Reference in New Issue
Block a user