diff --git a/gulpfile.js b/gulpfile.js index 84dfa5d..9be7f23 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,10 @@ const dateformat = require('dateformat'); const argv = require('yargs').argv; const publish = require('./tasks/gulp-publish'); +if (packageInfo.haxe) { + Haxe.VERSION = packageInfo.haxe; +} + if (Config.SdkDir) { Sdk.dir = Config.SdkDir; } diff --git a/package.json b/package.json index 3057052..41bdd8f 100644 --- a/package.json +++ b/package.json @@ -18,5 +18,6 @@ "hxcpp": "4.0.52", "svg": "1.1.3" }, + "haxe": "4.0.5", "dependencies": {} } diff --git a/src/haxe/ru/m/draw/DrawPath.hx b/src/haxe/ru/m/draw/DrawPath.hx index 66c4e62..51bb28f 100644 --- a/src/haxe/ru/m/draw/DrawPath.hx +++ b/src/haxe/ru/m/draw/DrawPath.hx @@ -43,12 +43,10 @@ class DrawPath { public function move(mx:Float, my:Float):DrawPath { var result = new DrawPath(); - result.commands = commands.map(function(command):DrawCommand { - return switch command { - case MOVE_TO(x, y): MOVE_TO(x + mx, y + my); - case LINE_TO(x, y): LINE_TO(x + mx, y + my); - case CURVE_TO(cx, cy, ax, ay): CURVE_TO(cx + mx, cy + my, ax + mx, ay + my); - } + result.commands = commands.map(command -> switch command { + case MOVE_TO(x, y): MOVE_TO(x + mx, y + my); + case LINE_TO(x, y): LINE_TO(x + mx, y + my); + case CURVE_TO(cx, cy, ax, ay): CURVE_TO(cx + mx, cy + my, ax + mx, ay + my); }); return result; } diff --git a/src/haxe/ru/m/puzzlez/FileUtil.hx b/src/haxe/ru/m/puzzlez/FileUtil.hx index e9707e7..d76a187 100644 --- a/src/haxe/ru/m/puzzlez/FileUtil.hx +++ b/src/haxe/ru/m/puzzlez/FileUtil.hx @@ -17,16 +17,16 @@ class FileUtil { public static function browse():Promise { var d = new Deferred(); var file = new ModernFileReference(); - file.addEventListener(Event.SELECT, function(event:Event) { + file.addEventListener(Event.SELECT, (event:Event) -> { cast(event.target, ModernFileReference).load(); }); - file.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) { + file.addEventListener(IOErrorEvent.IO_ERROR, (event:IOErrorEvent) -> { d.throwError(event); }); - file.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent) { + file.addEventListener(ProgressEvent.PROGRESS, (event:ProgressEvent) -> { //trace('progress', '${event}'); }); - file.addEventListener(Event.COMPLETE, function(event:Event) { + file.addEventListener(Event.COMPLETE, (event:Event) -> { var f:ModernFileReference = cast event.target; d.resolve({ name: f.name, diff --git a/src/haxe/ru/m/puzzlez/ImageUtil.hx b/src/haxe/ru/m/puzzlez/ImageUtil.hx index af70dc4..60f558f 100644 --- a/src/haxe/ru/m/puzzlez/ImageUtil.hx +++ b/src/haxe/ru/m/puzzlez/ImageUtil.hx @@ -15,10 +15,10 @@ class ImageUtil { public static function bytesToImage(bytes:Bytes):Promise { var def = new Deferred(); var loader = new Loader(); - loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event) { + loader.contentLoaderInfo.addEventListener(Event.COMPLETE, (event:Event) -> { def.resolve(cast(cast(event.target, LoaderInfo).content, Bitmap).bitmapData); }); - loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) { + loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, (event:IOErrorEvent) -> { def.throwError(event); }); loader.loadBytes(bytes); diff --git a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx index d61751a..9d55140 100644 --- a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx +++ b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx @@ -2,11 +2,18 @@ package ru.m.puzzlez; import haxework.App; import haxework.log.TraceLogger; +import haxework.provider.Provider; +import ru.m.puzzlez.storage.GameStorage; +import ru.m.puzzlez.storage.ImageStorage; import ru.m.puzzlez.view.PuzzlezAppView; class PuzzlezApp extends App { public static function main() { + // ToDo: fix @:provide macro + Provider.instance.setFactory(ImageStorage, ImageStorage); + Provider.instance.setFactory(GameStorage, GameStorage); + L.push(new TraceLogger()); var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png")); var view = new PuzzlezAppView(); diff --git a/src/haxe/ru/m/puzzlez/render/ImagePartBuilder.hx b/src/haxe/ru/m/puzzlez/render/ImagePartBuilder.hx index cb69b51..fd26390 100644 --- a/src/haxe/ru/m/puzzlez/render/ImagePartBuilder.hx +++ b/src/haxe/ru/m/puzzlez/render/ImagePartBuilder.hx @@ -28,12 +28,12 @@ class ImagePartBuilder { var partImage = RenderUtil.cropImagePart(image, part); stream.update({part: part, image: partImage}); } - Timer.delay(function() buildPart(index + count, count, parts, stream), 0); + Timer.delay(() -> buildPart(index + count, count, parts, stream), 0); } public function build(parts:Array):Stream { var stream = new PublicStream(); - Timer.delay(function() buildPart(0, 5, parts, stream), 0); + Timer.delay(() -> buildPart(0, 5, parts, stream), 0); return stream; } } diff --git a/src/haxe/ru/m/puzzlez/source/AssetSource.hx b/src/haxe/ru/m/puzzlez/source/AssetSource.hx index 35bd4d2..004f07c 100644 --- a/src/haxe/ru/m/puzzlez/source/AssetSource.hx +++ b/src/haxe/ru/m/puzzlez/source/AssetSource.hx @@ -17,7 +17,7 @@ class AssetSource implements IImageSource { } private function resolveData():Array { - return [for (name in Assets.list(AssetType.IMAGE).filter(function(name:String) return name.substr(0, 15) == "resources/image")) new ImageId(id, name)]; + return [for (name in Assets.list(AssetType.IMAGE).filter((name:String) -> name.substr(0, 15) == "resources/image")) new ImageId(id, name)]; } public function getList(?type:Dynamic):Promise> { diff --git a/src/haxe/ru/m/puzzlez/source/PixabaySource.hx b/src/haxe/ru/m/puzzlez/source/PixabaySource.hx index 99849f9..806a29c 100644 --- a/src/haxe/ru/m/puzzlez/source/PixabaySource.hx +++ b/src/haxe/ru/m/puzzlez/source/PixabaySource.hx @@ -17,7 +17,7 @@ typedef PixabayResponse = { var hits:Array; } -@:enum abstract PixabayCategory(String) from String to String { +enum abstract PixabayCategory(String) from String to String { var FASHION = "fashion"; var NATURE = "nature"; var BACKGROUNDS = "backgrounds"; @@ -40,7 +40,7 @@ typedef PixabayResponse = { var MUSIC = "music"; } -@:enum abstract PixabayImageType(String) from String to String { +enum abstract PixabayImageType(String) from String to String { var ALL = "all"; var PHOTO = "photo"; var ILLUSTRATION = "illustration"; @@ -64,7 +64,7 @@ class PixabaySource implements IImageSource { public function getList(?type:PixabayCategory):Promise> { return new JsonLoader() .GET('${baseUrl}?key=${key}&category=${type}&image_type=${PixabayImageType.PHOTO}') - .then(function(response:PixabayResponse) { + .then((response:PixabayResponse) -> { var result = []; for (item in response.hits) { var imageId = new ImageId(id, Std.string(item.id)); @@ -79,16 +79,13 @@ class PixabaySource implements IImageSource { if (!cache.exists(id)) { cache.set(id, new JsonLoader() .GET('${baseUrl}?key=${key}&id=${id.id}') - .then(function(response:PixabayResponse) { - return response.hits[0]; - })); + .then((response:PixabayResponse) -> response.hits[0])); } return cache.get(id); } public function loadImage(id:ImageId, preview:Bool = false):Promise { - return getImage(id).pipe(function(data:PixabayImage) { - return new ImageLoader().GET(preview ? data.previewURL : data.largeImageURL); - }); + return getImage(id) + .pipe((data:PixabayImage) -> return new ImageLoader().GET(preview ? data.previewURL : data.largeImageURL)); } } diff --git a/src/haxe/ru/m/puzzlez/storage/ImageStorage.hx b/src/haxe/ru/m/puzzlez/storage/ImageStorage.hx index db9a598..a686eec 100644 --- a/src/haxe/ru/m/puzzlez/storage/ImageStorage.hx +++ b/src/haxe/ru/m/puzzlez/storage/ImageStorage.hx @@ -56,7 +56,7 @@ import ru.m.puzzlez.source.PixabaySource; public static function unserialize(data:ByteArray):Promise { var def = new Deferred(); var loader = new Loader(); - loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event) { + loader.contentLoaderInfo.addEventListener(Event.COMPLETE, (event:Event) -> { def.resolve(cast(cast(event.target, LoaderInfo).content, Bitmap).bitmapData); }); loader.loadBytes(data); diff --git a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx b/src/haxe/ru/m/puzzlez/view/GameListFrame.hx index 91ebce7..c3f2f01 100644 --- a/src/haxe/ru/m/puzzlez/view/GameListFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/GameListFrame.hx @@ -32,7 +32,7 @@ import ru.m.puzzlez.view.PuzzleImageView; private function onAction(imageId:ImageId, action:Action):Void { switch action { case CLEAN: - ConfirmView.confirm("Delete state?").then(function(result) { + ConfirmView.confirm("Delete state?").then(result -> { if (result) { storage.delete(imageId); images.data = storage.listIds(); diff --git a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx index b474d12..ccc87de 100644 --- a/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/ImageListFrame.hx @@ -34,7 +34,7 @@ import ru.m.puzzlez.view.PuzzleImageView; source = data; select.visible = source.source.id == FileSource.ID; images.data = []; - loading.promise = data.source.getList(data.type).then(function(result) images.data = result); + loading.promise = data.source.getList(data.type).then(result -> images.data = result); } } @@ -43,7 +43,7 @@ import ru.m.puzzlez.view.PuzzleImageView; } private function selectFile():Void { - FileUtil.browse().then(function(data:FileContent) { + FileUtil.browse().then((data:FileContent) -> { var fileSource:FileSource = cast source.source; var imageId = fileSource.append(data.content); images.data.push(imageId); @@ -56,7 +56,7 @@ import ru.m.puzzlez.view.PuzzleImageView; case REMOVE: var fileSource:FileSource = Std.instance(source.source, FileSource); if (fileSource != null) { - ConfirmView.confirm("Delete image?").then(function(result) { + ConfirmView.confirm("Delete image?").then(result -> { if (result) { fileSource.remove(imageId); refresh(); @@ -64,7 +64,7 @@ import ru.m.puzzlez.view.PuzzleImageView; }); } case CLEAN: - ConfirmView.confirm("Delete state?").then(function(result) { + ConfirmView.confirm("Delete state?").then(result -> { if (result) { gameStorage.delete(imageId); refresh(); @@ -74,7 +74,7 @@ import ru.m.puzzlez.view.PuzzleImageView; } private function refresh():Void { - loading.promise = source.source.getList().then(function(result) images.data = result); + loading.promise = source.source.getList().then(result -> images.data = result); } private function start(imageId:ImageId):Void { diff --git a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx index 50562f8..4cbe48c 100644 --- a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx +++ b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx @@ -22,8 +22,8 @@ class LoadingWrapper { private function set_promise(value:Promise):Promise { state = LOADING; value - .then(function(_) state = NONE) - .catchError(function(error) state = ERROR(error)); + .then(_ -> state = NONE) + .catchError(error -> state = ERROR(error)); return value; } diff --git a/src/haxe/ru/m/puzzlez/view/PresetView.hx b/src/haxe/ru/m/puzzlez/view/PresetView.hx index d49f42e..47ec55f 100644 --- a/src/haxe/ru/m/puzzlez/view/PresetView.hx +++ b/src/haxe/ru/m/puzzlez/view/PresetView.hx @@ -31,7 +31,7 @@ class PresetView extends GroupView { preset = value; this.image = null; table.graphics.clear(); - loading.promise = imageStorage.resolve(preset.imageId).then(function(image) { + loading.promise = imageStorage.resolve(preset.imageId).then(image -> { this.image = RenderUtil.cropImage(image, preset.imageRect); toRedraw(); toUpdate(); diff --git a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx index 7169a69..9e17221 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx +++ b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.hx @@ -23,7 +23,7 @@ enum Action { private function set_imageId(value:ImageId):ImageId { if (imageId != value) { imageId = value; - loading.promise = imageStorage.resolve(imageId, true).then(function(data) imageView.image = data); + loading.promise = imageStorage.resolve(imageId, true).then(data -> imageView.image = data); } return imageId; } diff --git a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx index 0af34e7..7f8a118 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx +++ b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx @@ -23,10 +23,11 @@ import haxework.view.group.VGroupView; public function launch():Void { content.stage.stageFocusRect = false; switcher.change(StartFrame.ID); - stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event:KeyboardEvent) { + stage.addEventListener(KeyboardEvent.KEY_DOWN, (event:KeyboardEvent) -> { switch event.keyCode { case Keyboard.ESCAPE: switcher.change(StartFrame.ID); + case _: } }); } diff --git a/src/haxe/ru/m/puzzlez/view/StartFrame.hx b/src/haxe/ru/m/puzzlez/view/StartFrame.hx index 1776771..a37dc75 100644 --- a/src/haxe/ru/m/puzzlez/view/StartFrame.hx +++ b/src/haxe/ru/m/puzzlez/view/StartFrame.hx @@ -41,7 +41,7 @@ import ru.m.puzzlez.storage.ImageStorage; } private function clean():Void { - ConfirmView.confirm("Really clean all saved data?").then(function(result) { + ConfirmView.confirm("Really clean all saved data?").then(result -> { if (result) { gameStorage.clear(); var fileSource:FileSource = cast storage.sources.get(FileSource.ID);