[refactoring] #2
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
package ru.m.puzzlez;
|
package ru.m.puzzlez;
|
||||||
|
|
||||||
import ru.m.puzzlez.image.PixabayImageSource;
|
|
||||||
import ru.m.puzzlez.render.part.IPartBuilder;
|
|
||||||
import ru.m.puzzlez.image.AssetImageSource;
|
|
||||||
import ru.m.puzzlez.image.ImageSourceBundle;
|
|
||||||
import ru.m.puzzlez.settings.Settings;
|
|
||||||
import ru.m.puzzlez.view.PuzzlezAppView;
|
|
||||||
import hw.app.App;
|
import hw.app.App;
|
||||||
import hw.app.Const;
|
import hw.app.Const;
|
||||||
import hw.log.TraceLogger;
|
import hw.log.TraceLogger;
|
||||||
|
import ru.m.puzzlez.image.ImageSourceBundle;
|
||||||
|
import ru.m.puzzlez.render.part.IPartBuilder;
|
||||||
|
import ru.m.puzzlez.settings.Settings;
|
||||||
|
import ru.m.puzzlez.source.AssetImageSource;
|
||||||
|
import ru.m.puzzlez.source.PixabayImageSource;
|
||||||
|
import ru.m.puzzlez.view.PuzzlezAppView;
|
||||||
import ru.m.update.Updater;
|
import ru.m.update.Updater;
|
||||||
|
|
||||||
class PuzzlezApp {
|
class PuzzlezApp {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package ru.m.puzzlez.image;
|
|
||||||
|
|
||||||
import openfl.utils.Assets;
|
|
||||||
import promhx.Promise;
|
|
||||||
import ru.m.data.DataSource;
|
|
||||||
import ru.m.puzzlez.image.ImageSource;
|
|
||||||
import ru.m.puzzlez.proto.game.ImageId;
|
|
||||||
|
|
||||||
class AssetImageSource implements ImageSource {
|
|
||||||
public var id(default, never):String = "asset";
|
|
||||||
|
|
||||||
public function new() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
|
||||||
return Promise.promise({
|
|
||||||
page: page,
|
|
||||||
data: [],
|
|
||||||
total: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(id:String):Promise<ImageValue> {
|
|
||||||
return Promise.promise(ImageValue.BITMAP(Assets.getBitmapData(id)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
41
src/app/haxe/ru/m/puzzlez/source/AssetImageSource.hx
Normal file
41
src/app/haxe/ru/m/puzzlez/source/AssetImageSource.hx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package ru.m.puzzlez.source;
|
||||||
|
|
||||||
|
import openfl.utils.AssetType;
|
||||||
|
import openfl.utils.Assets;
|
||||||
|
import promhx.Promise;
|
||||||
|
import ru.m.data.DataSource;
|
||||||
|
import ru.m.puzzlez.image.ImageSource;
|
||||||
|
import ru.m.puzzlez.proto.game.ImageId;
|
||||||
|
|
||||||
|
class AssetImageSource implements ImageSource {
|
||||||
|
public var id(default, never):String = "asset";
|
||||||
|
|
||||||
|
private var _data:Array<ImageId>;
|
||||||
|
private var data(get, null):Array<ImageId>;
|
||||||
|
|
||||||
|
private function get_data():Array<ImageId> {
|
||||||
|
if (_data == null) {
|
||||||
|
_data = resolveData();
|
||||||
|
}
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||||
|
return Promise.promise({
|
||||||
|
page: page,
|
||||||
|
data: data.slice(page.index * page.count, page.count),
|
||||||
|
total: data.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(id:String):Promise<ImageValue> {
|
||||||
|
return Promise.promise(ImageValue.BITMAP(Assets.getBitmapData(id)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.m.puzzlez.image;
|
package ru.m.puzzlez.source;
|
||||||
|
|
||||||
import promhx.Promise;
|
import promhx.Promise;
|
||||||
import ru.m.data.DataSource;
|
import ru.m.data.DataSource;
|
||||||
@@ -17,7 +17,7 @@ class PixabayImageSource implements ImageSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
public function getPage(page:Page):Promise<DataPage<ImageId>> {
|
||||||
return this.api.getPage(page.index + 1, page.count).then((response:PixabayResponse) -> {
|
return this.api.getPage(page.index + 1, page.count, page.params.get("category")).then((response:PixabayResponse) -> {
|
||||||
var data:Array<ImageId> = [];
|
var data:Array<ImageId> = [];
|
||||||
for (hit in response.hits) {
|
for (hit in response.hits) {
|
||||||
imageUrlsCache.set(hit.id, hit.largeImageURL);
|
imageUrlsCache.set(hit.id, hit.largeImageURL);
|
||||||
@@ -3,7 +3,7 @@ package ru.m.puzzlez.view;
|
|||||||
import hw.view.form.LabelView;
|
import hw.view.form.LabelView;
|
||||||
import hw.view.frame.FrameSwitcher;
|
import hw.view.frame.FrameSwitcher;
|
||||||
import hw.view.frame.FrameView;
|
import hw.view.frame.FrameView;
|
||||||
import ru.m.puzzlez.image.GameUtil;
|
import ru.m.data.DataSource.PageParams;
|
||||||
import ru.m.puzzlez.image.ImageSourceBundle;
|
import ru.m.puzzlez.image.ImageSourceBundle;
|
||||||
import ru.m.puzzlez.proto.game.ImageId;
|
import ru.m.puzzlez.proto.game.ImageId;
|
||||||
import ru.m.puzzlez.view.common.ImageDataList;
|
import ru.m.puzzlez.view.common.ImageDataList;
|
||||||
@@ -11,6 +11,7 @@ import ru.m.puzzlez.view.common.ImageDataList;
|
|||||||
typedef ImageSourceConfig = {
|
typedef ImageSourceConfig = {
|
||||||
var title:String;
|
var title:String;
|
||||||
var sourceId:String;
|
var sourceId:String;
|
||||||
|
@:optional var params:PageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:template class ImageSourceFrame extends FrameView<ImageSourceConfig> {
|
@:template class ImageSourceFrame extends FrameView<ImageSourceConfig> {
|
||||||
@@ -29,15 +30,16 @@ typedef ImageSourceConfig = {
|
|||||||
images.reset();
|
images.reset();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
header.text = data.title;
|
header.text = data.title;
|
||||||
// images.page.filter = data.filter;
|
images.page.params = data.params;
|
||||||
images.source = sourceBundle.get(data.sourceId);
|
images.source = sourceBundle.get(data.sourceId);
|
||||||
images.refresh();
|
images.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function start(imageId:ImageId):Void {
|
private function start(imageId:ImageId):Void {
|
||||||
var state = GameUtil.buildState(GameUtil.buildPreset(imageId, 2, 2));
|
//var state = GameUtil.buildState(GameUtil.buildPreset(imageId, 2, 2));
|
||||||
switcher.change(GameFrame.ID, state);
|
//switcher.change(GameFrame.ID, state);
|
||||||
|
switcher.change(PresetFrame.ID, imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function back():Void {
|
private function back():Void {
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ import hw.view.form.ToggleButtonView;
|
|||||||
import hw.view.frame.FrameSwitcher;
|
import hw.view.frame.FrameSwitcher;
|
||||||
import hw.view.frame.FrameView;
|
import hw.view.frame.FrameView;
|
||||||
import ru.m.puzzlez.image.GameUtil;
|
import ru.m.puzzlez.image.GameUtil;
|
||||||
import ru.m.puzzlez.net.Network;
|
|
||||||
import ru.m.puzzlez.proto.game.ImageId;
|
import ru.m.puzzlez.proto.game.ImageId;
|
||||||
import ru.m.puzzlez.settings.ImageStorage;
|
|
||||||
import ru.m.puzzlez.view.common.PresetView;
|
import ru.m.puzzlez.view.common.PresetView;
|
||||||
|
|
||||||
@:template class PresetFrame extends FrameView<ImageId> {
|
@:template class PresetFrame extends FrameView<ImageId> {
|
||||||
@@ -17,9 +15,8 @@ import ru.m.puzzlez.view.common.PresetView;
|
|||||||
@:view("image") var imageView:PresetView;
|
@:view("image") var imageView:PresetView;
|
||||||
@:view("sizes") var sizesView:DataView<IntPoint, ToggleButtonView>;
|
@:view("sizes") var sizesView:DataView<IntPoint, ToggleButtonView>;
|
||||||
|
|
||||||
@:provide var imageStorage:ImageStorage;
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var network:Network;
|
//@:provide var network:Network;
|
||||||
|
|
||||||
private var imageId:ImageId;
|
private var imageId:ImageId;
|
||||||
|
|
||||||
@@ -57,13 +54,13 @@ import ru.m.puzzlez.view.common.PresetView;
|
|||||||
|
|
||||||
private function start(online:Bool = false):Void {
|
private function start(online:Bool = false):Void {
|
||||||
if (online) {
|
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 {
|
} else {
|
||||||
switcher.change(GameFrame.ID, imageView.state);
|
switcher.change(GameFrame.ID, imageView.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function back():Void {
|
private function back():Void {
|
||||||
switcher.change(ImageListFrame.ID);
|
switcher.change(ImageSourceFrame.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ views:
|
|||||||
factory:
|
factory:
|
||||||
_start_: {$class: ru.m.puzzlez.view.StartFrame}
|
_start_: {$class: ru.m.puzzlez.view.StartFrame}
|
||||||
_source_: {$class: ru.m.puzzlez.view.ImageSourceFrame}
|
_source_: {$class: ru.m.puzzlez.view.ImageSourceFrame}
|
||||||
#_preset_: {$class: ru.m.puzzlez.view.PresetFrame}
|
_preset_: {$class: ru.m.puzzlez.view.PresetFrame}
|
||||||
_game_: {$class: ru.m.puzzlez.view.GameFrame}
|
_game_: {$class: ru.m.puzzlez.view.GameFrame}
|
||||||
- $type: hw.view.group.HGroupView
|
- $type: hw.view.group.HGroupView
|
||||||
geometry.position: absolute
|
geometry.position: absolute
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view;
|
||||||
|
|
||||||
|
import hw.view.data.DataView;
|
||||||
import hw.view.form.ButtonView;
|
import hw.view.form.ButtonView;
|
||||||
import hw.view.frame.FrameSwitcher;
|
import hw.view.frame.FrameSwitcher;
|
||||||
import hw.view.frame.FrameView;
|
import hw.view.frame.FrameView;
|
||||||
|
import ru.m.pixabay.PixabayApi;
|
||||||
import ru.m.puzzlez.view.ImageSourceFrame;
|
import ru.m.puzzlez.view.ImageSourceFrame;
|
||||||
import ru.m.update.Updater;
|
import ru.m.update.Updater;
|
||||||
|
|
||||||
@:template class StartFrame extends FrameView<Dynamic> {
|
@:template class StartFrame extends FrameView<Dynamic> {
|
||||||
public static var ID = "start";
|
public static var ID = "start";
|
||||||
|
|
||||||
|
@:view var sources:DataView<ImageSourceConfig, ButtonView>;
|
||||||
@:view var updateButton:ButtonView;
|
@:view var updateButton:ButtonView;
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@@ -16,9 +19,22 @@ import ru.m.update.Updater;
|
|||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(ID);
|
super(ID);
|
||||||
|
var data:Array<ImageSourceConfig> = [];
|
||||||
|
data.push({title: "Assets", sourceId: "asset"});
|
||||||
|
// data.push({title: "Files", sourceId: "file"});
|
||||||
|
for (type in AbstractEnumTools.getValues(PixabayCategory)) {
|
||||||
|
data.push({title: type, sourceId: "pixabay", params: ["category" => type]});
|
||||||
|
}
|
||||||
|
sources.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function openSource(source:ImageSourceConfig):Void {
|
private function sourceViewFactory(index:Int, source:ImageSourceConfig):ButtonView {
|
||||||
|
var result = new ButtonView();
|
||||||
|
result.text = source.title;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showSource(source:ImageSourceConfig):Void {
|
||||||
switcher.change(ImageSourceFrame.ID, source);
|
switcher.change(ImageSourceFrame.ID, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,18 @@ views:
|
|||||||
- $type: hw.view.form.LabelView
|
- $type: hw.view.form.LabelView
|
||||||
text: $r:text:app.name
|
text: $r:text:app.name
|
||||||
font.size: 50
|
font.size: 50
|
||||||
- $type: hw.view.form.ButtonView
|
- id: sources
|
||||||
text: Pixabay
|
$type: hw.view.data.DataView
|
||||||
geometry.hAlign: center
|
layout:
|
||||||
+onPress: "~openSource({title: 'Pixabay', sourceId: 'pixabay'})"
|
$type: hw.view.layout.TailLayout
|
||||||
|
rowSize: 5
|
||||||
|
margin: 10
|
||||||
|
vAlign: middle
|
||||||
|
geometry.stretch: true
|
||||||
|
factory: ~sourceViewFactory
|
||||||
|
+onDataSelect: ~showSource
|
||||||
|
geometry.margin: 5
|
||||||
|
overflow.y: scroll
|
||||||
- $type: hw.view.form.LabelView
|
- $type: hw.view.form.LabelView
|
||||||
text: $r:text:app.version
|
text: $r:text:app.version
|
||||||
geometry.position: absolute
|
geometry.position: absolute
|
||||||
|
|||||||
Reference in New Issue
Block a user