[update] update to haxe4
This commit is contained in:
@@ -7,6 +7,10 @@ const dateformat = require('dateformat');
|
|||||||
const argv = require('yargs').argv;
|
const argv = require('yargs').argv;
|
||||||
const publish = require('./tasks/gulp-publish');
|
const publish = require('./tasks/gulp-publish');
|
||||||
|
|
||||||
|
if (packageInfo.haxe) {
|
||||||
|
Haxe.VERSION = packageInfo.haxe;
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.SdkDir) {
|
if (Config.SdkDir) {
|
||||||
Sdk.dir = Config.SdkDir;
|
Sdk.dir = Config.SdkDir;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,6 @@
|
|||||||
"hxcpp": "4.0.52",
|
"hxcpp": "4.0.52",
|
||||||
"svg": "1.1.3"
|
"svg": "1.1.3"
|
||||||
},
|
},
|
||||||
|
"haxe": "4.0.5",
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,12 +43,10 @@ class DrawPath {
|
|||||||
|
|
||||||
public function move(mx:Float, my:Float):DrawPath {
|
public function move(mx:Float, my:Float):DrawPath {
|
||||||
var result = new DrawPath();
|
var result = new DrawPath();
|
||||||
result.commands = commands.map(function(command):DrawCommand {
|
result.commands = commands.map(command -> switch command {
|
||||||
return switch command {
|
case MOVE_TO(x, y): MOVE_TO(x + mx, y + my);
|
||||||
case MOVE_TO(x, y): MOVE_TO(x + mx, y + my);
|
case LINE_TO(x, y): LINE_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);
|
||||||
case CURVE_TO(cx, cy, ax, ay): CURVE_TO(cx + mx, cy + my, ax + mx, ay + my);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,16 +17,16 @@ class FileUtil {
|
|||||||
public static function browse():Promise<FileContent> {
|
public static function browse():Promise<FileContent> {
|
||||||
var d = new Deferred<FileContent>();
|
var d = new Deferred<FileContent>();
|
||||||
var file = new ModernFileReference();
|
var file = new ModernFileReference();
|
||||||
file.addEventListener(Event.SELECT, function(event:Event) {
|
file.addEventListener(Event.SELECT, (event:Event) -> {
|
||||||
cast(event.target, ModernFileReference).load();
|
cast(event.target, ModernFileReference).load();
|
||||||
});
|
});
|
||||||
file.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent) {
|
file.addEventListener(IOErrorEvent.IO_ERROR, (event:IOErrorEvent) -> {
|
||||||
d.throwError(event);
|
d.throwError(event);
|
||||||
});
|
});
|
||||||
file.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent) {
|
file.addEventListener(ProgressEvent.PROGRESS, (event:ProgressEvent) -> {
|
||||||
//trace('progress', '${event}');
|
//trace('progress', '${event}');
|
||||||
});
|
});
|
||||||
file.addEventListener(Event.COMPLETE, function(event:Event) {
|
file.addEventListener(Event.COMPLETE, (event:Event) -> {
|
||||||
var f:ModernFileReference = cast event.target;
|
var f:ModernFileReference = cast event.target;
|
||||||
d.resolve({
|
d.resolve({
|
||||||
name: f.name,
|
name: f.name,
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ class ImageUtil {
|
|||||||
public static function bytesToImage(bytes:Bytes):Promise<BitmapData> {
|
public static function bytesToImage(bytes:Bytes):Promise<BitmapData> {
|
||||||
var def = new Deferred();
|
var def = new Deferred();
|
||||||
var loader = new Loader();
|
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);
|
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);
|
def.throwError(event);
|
||||||
});
|
});
|
||||||
loader.loadBytes(bytes);
|
loader.loadBytes(bytes);
|
||||||
|
|||||||
@@ -2,11 +2,18 @@ package ru.m.puzzlez;
|
|||||||
|
|
||||||
import haxework.App;
|
import haxework.App;
|
||||||
import haxework.log.TraceLogger;
|
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;
|
import ru.m.puzzlez.view.PuzzlezAppView;
|
||||||
|
|
||||||
class PuzzlezApp extends App {
|
class PuzzlezApp extends App {
|
||||||
|
|
||||||
public static function main() {
|
public static function main() {
|
||||||
|
// ToDo: fix @:provide macro
|
||||||
|
Provider.instance.setFactory(ImageStorage, ImageStorage);
|
||||||
|
Provider.instance.setFactory(GameStorage, GameStorage);
|
||||||
|
|
||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png"));
|
var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png"));
|
||||||
var view = new PuzzlezAppView();
|
var view = new PuzzlezAppView();
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ class ImagePartBuilder {
|
|||||||
var partImage = RenderUtil.cropImagePart(image, part);
|
var partImage = RenderUtil.cropImagePart(image, part);
|
||||||
stream.update({part: part, image: partImage});
|
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<Part>):Stream<Result> {
|
public function build(parts:Array<Part>):Stream<Result> {
|
||||||
var stream = new PublicStream<Result>();
|
var stream = new PublicStream<Result>();
|
||||||
Timer.delay(function() buildPart(0, 5, parts, stream), 0);
|
Timer.delay(() -> buildPart(0, 5, parts, stream), 0);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class AssetSource implements IImageSource<Dynamic> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function resolveData():Array<ImageId> {
|
private function resolveData():Array<ImageId> {
|
||||||
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<Array<ImageId>> {
|
public function getList(?type:Dynamic):Promise<Array<ImageId>> {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ typedef PixabayResponse = {
|
|||||||
var hits:Array<PixabayImage>;
|
var hits:Array<PixabayImage>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:enum abstract PixabayCategory(String) from String to String {
|
enum abstract PixabayCategory(String) from String to String {
|
||||||
var FASHION = "fashion";
|
var FASHION = "fashion";
|
||||||
var NATURE = "nature";
|
var NATURE = "nature";
|
||||||
var BACKGROUNDS = "backgrounds";
|
var BACKGROUNDS = "backgrounds";
|
||||||
@@ -40,7 +40,7 @@ typedef PixabayResponse = {
|
|||||||
var MUSIC = "music";
|
var MUSIC = "music";
|
||||||
}
|
}
|
||||||
|
|
||||||
@:enum abstract PixabayImageType(String) from String to String {
|
enum abstract PixabayImageType(String) from String to String {
|
||||||
var ALL = "all";
|
var ALL = "all";
|
||||||
var PHOTO = "photo";
|
var PHOTO = "photo";
|
||||||
var ILLUSTRATION = "illustration";
|
var ILLUSTRATION = "illustration";
|
||||||
@@ -64,7 +64,7 @@ class PixabaySource implements IImageSource<PixabayCategory> {
|
|||||||
public function getList(?type:PixabayCategory):Promise<Array<ImageId>> {
|
public function getList(?type:PixabayCategory):Promise<Array<ImageId>> {
|
||||||
return new JsonLoader<PixabayResponse>()
|
return new JsonLoader<PixabayResponse>()
|
||||||
.GET('${baseUrl}?key=${key}&category=${type}&image_type=${PixabayImageType.PHOTO}')
|
.GET('${baseUrl}?key=${key}&category=${type}&image_type=${PixabayImageType.PHOTO}')
|
||||||
.then(function(response:PixabayResponse) {
|
.then((response:PixabayResponse) -> {
|
||||||
var result = [];
|
var result = [];
|
||||||
for (item in response.hits) {
|
for (item in response.hits) {
|
||||||
var imageId = new ImageId(id, Std.string(item.id));
|
var imageId = new ImageId(id, Std.string(item.id));
|
||||||
@@ -79,16 +79,13 @@ class PixabaySource implements IImageSource<PixabayCategory> {
|
|||||||
if (!cache.exists(id)) {
|
if (!cache.exists(id)) {
|
||||||
cache.set(id, new JsonLoader<PixabayResponse>()
|
cache.set(id, new JsonLoader<PixabayResponse>()
|
||||||
.GET('${baseUrl}?key=${key}&id=${id.id}')
|
.GET('${baseUrl}?key=${key}&id=${id.id}')
|
||||||
.then(function(response:PixabayResponse) {
|
.then((response:PixabayResponse) -> response.hits[0]));
|
||||||
return response.hits[0];
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
return cache.get(id);
|
return cache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadImage(id:ImageId, preview:Bool = false):Promise<BitmapData> {
|
public function loadImage(id:ImageId, preview:Bool = false):Promise<BitmapData> {
|
||||||
return getImage(id).pipe(function(data:PixabayImage) {
|
return getImage(id)
|
||||||
return new ImageLoader().GET(preview ? data.previewURL : data.largeImageURL);
|
.pipe((data:PixabayImage) -> return new ImageLoader().GET(preview ? data.previewURL : data.largeImageURL));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import ru.m.puzzlez.source.PixabaySource;
|
|||||||
public static function unserialize(data:ByteArray):Promise<BitmapData> {
|
public static function unserialize(data:ByteArray):Promise<BitmapData> {
|
||||||
var def = new Deferred();
|
var def = new Deferred();
|
||||||
var loader = new Loader();
|
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);
|
def.resolve(cast(cast(event.target, LoaderInfo).content, Bitmap).bitmapData);
|
||||||
});
|
});
|
||||||
loader.loadBytes(data);
|
loader.loadBytes(data);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
private function onAction(imageId:ImageId, action:Action):Void {
|
private function onAction(imageId:ImageId, action:Action):Void {
|
||||||
switch action {
|
switch action {
|
||||||
case CLEAN:
|
case CLEAN:
|
||||||
ConfirmView.confirm("Delete state?").then(function(result) {
|
ConfirmView.confirm("Delete state?").then(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
storage.delete(imageId);
|
storage.delete(imageId);
|
||||||
images.data = storage.listIds();
|
images.data = storage.listIds();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
source = data;
|
source = data;
|
||||||
select.visible = source.source.id == FileSource.ID;
|
select.visible = source.source.id == FileSource.ID;
|
||||||
images.data = [];
|
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 {
|
private function selectFile():Void {
|
||||||
FileUtil.browse().then(function(data:FileContent) {
|
FileUtil.browse().then((data:FileContent) -> {
|
||||||
var fileSource:FileSource = cast source.source;
|
var fileSource:FileSource = cast source.source;
|
||||||
var imageId = fileSource.append(data.content);
|
var imageId = fileSource.append(data.content);
|
||||||
images.data.push(imageId);
|
images.data.push(imageId);
|
||||||
@@ -56,7 +56,7 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
case REMOVE:
|
case REMOVE:
|
||||||
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
||||||
if (fileSource != null) {
|
if (fileSource != null) {
|
||||||
ConfirmView.confirm("Delete image?").then(function(result) {
|
ConfirmView.confirm("Delete image?").then(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
fileSource.remove(imageId);
|
fileSource.remove(imageId);
|
||||||
refresh();
|
refresh();
|
||||||
@@ -64,7 +64,7 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
case CLEAN:
|
case CLEAN:
|
||||||
ConfirmView.confirm("Delete state?").then(function(result) {
|
ConfirmView.confirm("Delete state?").then(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
gameStorage.delete(imageId);
|
gameStorage.delete(imageId);
|
||||||
refresh();
|
refresh();
|
||||||
@@ -74,7 +74,7 @@ import ru.m.puzzlez.view.PuzzleImageView;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function refresh():Void {
|
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 {
|
private function start(imageId:ImageId):Void {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class LoadingWrapper {
|
|||||||
private function set_promise(value:Promise<Dynamic>):Promise<Dynamic> {
|
private function set_promise(value:Promise<Dynamic>):Promise<Dynamic> {
|
||||||
state = LOADING;
|
state = LOADING;
|
||||||
value
|
value
|
||||||
.then(function(_) state = NONE)
|
.then(_ -> state = NONE)
|
||||||
.catchError(function(error) state = ERROR(error));
|
.catchError(error -> state = ERROR(error));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class PresetView extends GroupView {
|
|||||||
preset = value;
|
preset = value;
|
||||||
this.image = null;
|
this.image = null;
|
||||||
table.graphics.clear();
|
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);
|
this.image = RenderUtil.cropImage(image, preset.imageRect);
|
||||||
toRedraw();
|
toRedraw();
|
||||||
toUpdate();
|
toUpdate();
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ enum Action {
|
|||||||
private function set_imageId(value:ImageId):ImageId {
|
private function set_imageId(value:ImageId):ImageId {
|
||||||
if (imageId != value) {
|
if (imageId != value) {
|
||||||
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;
|
return imageId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ import haxework.view.group.VGroupView;
|
|||||||
public function launch():Void {
|
public function launch():Void {
|
||||||
content.stage.stageFocusRect = false;
|
content.stage.stageFocusRect = false;
|
||||||
switcher.change(StartFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event:KeyboardEvent) {
|
stage.addEventListener(KeyboardEvent.KEY_DOWN, (event:KeyboardEvent) -> {
|
||||||
switch event.keyCode {
|
switch event.keyCode {
|
||||||
case Keyboard.ESCAPE:
|
case Keyboard.ESCAPE:
|
||||||
switcher.change(StartFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
|
case _:
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import ru.m.puzzlez.storage.ImageStorage;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function clean():Void {
|
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) {
|
if (result) {
|
||||||
gameStorage.clear();
|
gameStorage.clear();
|
||||||
var fileSource:FileSource = cast storage.sources.get(FileSource.ID);
|
var fileSource:FileSource = cast storage.sources.get(FileSource.ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user