[add] FileSource
This commit is contained in:
@@ -4,45 +4,36 @@ import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import ru.m.puzzlez.core.ImageSource;
|
||||
import ru.m.puzzlez.storage.AssetStorage;
|
||||
import ru.m.puzzlez.storage.ISourceStorage;
|
||||
import ru.m.puzzlez.storage.PixabayStorage;
|
||||
|
||||
typedef Source<T> = {
|
||||
var storage:ISourceStorage<T>;
|
||||
@:optional var type:T;
|
||||
}
|
||||
import ru.m.puzzlez.storage.AssetSource;
|
||||
import ru.m.puzzlez.storage.FileSource;
|
||||
import ru.m.puzzlez.storage.ImageStorage;
|
||||
import ru.m.puzzlez.storage.PixabaySource;
|
||||
|
||||
@:template class StartFrame extends FrameView<Dynamic> {
|
||||
public static var ID = "start";
|
||||
|
||||
@:view var sources:DataView<Source<Dynamic>, ButtonView>;
|
||||
@:provide var assetStorage:AssetStorage;
|
||||
@:provide var pixabayStorage:PixabayStorage;
|
||||
@:view var sources:DataView<ImageListSource<Dynamic>, ButtonView>;
|
||||
@:provide var storage:ImageStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
var data:Array<Source<Dynamic>> = [];
|
||||
data.push({storage: assetStorage});
|
||||
var data:Array<ImageListSource<Dynamic>> = [];
|
||||
data.push({source: storage.sources.get(AssetSource.ID), type: "asset"});
|
||||
data.push({source: storage.sources.get(FileSource.ID), type: "file"});
|
||||
for (type in AbstractEnumTools.getValues(PixabayCategory)) {
|
||||
data.push({storage: pixabayStorage, type: type});
|
||||
data.push({source: storage.sources.get(PixabaySource.ID), type: type});
|
||||
}
|
||||
sources.data = data;
|
||||
}
|
||||
|
||||
private function sourceViewFactory(index:Int, source:Source<Dynamic>):ButtonView {
|
||||
private function sourceViewFactory(index:Int, source:ImageListSource<Dynamic>):ButtonView {
|
||||
var result = new ButtonView();
|
||||
result.text = Std.string(source.type != null ? source.type : "custom");
|
||||
return result;
|
||||
}
|
||||
|
||||
private function load(source:Source<Dynamic>):Void {
|
||||
source.storage.resolve(source.type).then(onLoaded);
|
||||
}
|
||||
|
||||
private function onLoaded(result:Array<ImageSource>):Void {
|
||||
switcher.change(ImagesFrame.ID, result);
|
||||
private function load(source:ImageListSource<Dynamic>):Void {
|
||||
switcher.change(ImagesFrame.ID, source);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user