[update] :-)
This commit is contained in:
@@ -4,7 +4,7 @@ import flash.geom.Rectangle;
|
|||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
|
|
||||||
typedef GamePreset = {
|
typedef GamePreset = {
|
||||||
var image:ImageId;
|
var imageId:ImageId;
|
||||||
var grid:Grid;
|
var grid:Grid;
|
||||||
var tableRect:Rectangle;
|
var tableRect:Rectangle;
|
||||||
var imageRect:Rectangle;
|
var imageRect:Rectangle;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class GameUtil {
|
|||||||
return Math.isNaN(size) ? maxValue : size < 1 ? 1 : size > maxValue ? maxValue : size;
|
return Math.isNaN(size) ? maxValue : size < 1 ? 1 : size > maxValue ? maxValue : size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function buildPreset(image:ImageId, width:Int = 8, height:Int = 8):GamePreset {
|
public static function buildPreset(imageId:ImageId, width:Int = 8, height:Int = 8):GamePreset {
|
||||||
width = normilizeSize(width);
|
width = normilizeSize(width);
|
||||||
height = normilizeSize(height);
|
height = normilizeSize(height);
|
||||||
var offsetX = 500;
|
var offsetX = 500;
|
||||||
@@ -79,7 +79,7 @@ class GameUtil {
|
|||||||
var imageRect = new Rectangle(offsetX, offsetY, imageSize, imageSize / s);
|
var imageRect = new Rectangle(offsetX, offsetY, imageSize, imageSize / s);
|
||||||
var tableRect = new Rectangle(0, 0, imageRect.width + offsetX * 2, imageRect.height + offsetY * 2);
|
var tableRect = new Rectangle(0, 0, imageRect.width + offsetX * 2, imageRect.height + offsetY * 2);
|
||||||
return {
|
return {
|
||||||
image:image,
|
imageId: imageId,
|
||||||
grid: {width: width, height: height},
|
grid: {width: width, height: height},
|
||||||
tableRect: tableRect,
|
tableRect: tableRect,
|
||||||
imageRect: imageRect,
|
imageRect: imageRect,
|
||||||
@@ -130,4 +130,15 @@ class GameUtil {
|
|||||||
parts: parts,
|
parts: 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 _:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {complete:complete, total:state.parts.length};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class Render extends SpriteView implements IRender {
|
|||||||
imageView.graphics.lineStyle();
|
imageView.graphics.lineStyle();
|
||||||
progress.text = "Loading image";
|
progress.text = "Loading image";
|
||||||
content.addChild(progress.content);
|
content.addChild(progress.content);
|
||||||
imageStorage.resolve(state.preset.image).then(onImageResolved);
|
imageStorage.resolve(state.preset.imageId).then(onImageResolved);
|
||||||
toUpdate();
|
toUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,18 @@ import ru.m.puzzlez.core.Id.ImageId;
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function save(state:GameState):Void {
|
public function save(state:GameState):Void {
|
||||||
write(state.preset.image, state);
|
write(state.preset.imageId, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(imageId:ImageId):Null<GameState> {
|
public function load(imageId:ImageId):Null<GameState> {
|
||||||
return read(imageId);
|
return read(imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function list():Array<ImageId> {
|
public function listIds():Array<ImageId> {
|
||||||
return [for (key in Reflect.fields(so.data)) ImageId.fromString(key)];
|
return [for (key in Reflect.fields(so.data)) ImageId.fromString(key)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function list():Array<GameState> {
|
||||||
|
return [for (id in listIds()) load(id)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,7 @@ import ru.m.puzzlez.source.GameStorage;
|
|||||||
private function onGameEvent(event:GameEvent):Void {
|
private function onGameEvent(event:GameEvent):Void {
|
||||||
switch event {
|
switch event {
|
||||||
case ACTION(PART_PUT(_, _)):
|
case ACTION(PART_PUT(_, _)):
|
||||||
toSave = true;
|
|
||||||
case CHANGE(PART_UPDATE(_, _)):
|
|
||||||
if (toSave) {
|
|
||||||
storage.save(game.state);
|
storage.save(game.state);
|
||||||
toSave = false;
|
|
||||||
}
|
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package ru.m.puzzlez.view;
|
|||||||
import haxework.view.data.DataView;
|
import haxework.view.data.DataView;
|
||||||
import haxework.view.frame.FrameSwitcher;
|
import haxework.view.frame.FrameSwitcher;
|
||||||
import haxework.view.frame.FrameView;
|
import haxework.view.frame.FrameView;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.GameState;
|
||||||
import ru.m.puzzlez.source.GameStorage;
|
import ru.m.puzzlez.source.GameStorage;
|
||||||
|
import ru.m.puzzlez.view.PuzzleImageView;
|
||||||
|
|
||||||
@:template class GameListFrame extends FrameView<Dynamic> {
|
@:template class GameListFrame extends FrameView<Dynamic> {
|
||||||
|
|
||||||
public static var ID(default, never) = "game_list";
|
public static var ID(default, never) = "game_list";
|
||||||
|
|
||||||
@:view var images:DataView<ImageId, PuzzleImageView>;
|
@:view var images:ActionDataView<GameState, PuzzleImageView, Action>;
|
||||||
|
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var storage:GameStorage;
|
@:provide var storage:GameStorage;
|
||||||
@@ -23,11 +24,18 @@ import ru.m.puzzlez.source.GameStorage;
|
|||||||
images.data = storage.list();
|
images.data = storage.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function start(image:ImageId):Void {
|
private function start(state:GameState):Void {
|
||||||
var state = storage.load(image);
|
|
||||||
switcher.change(GameFrame.ID, state);
|
switcher.change(GameFrame.ID, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function onAction(state:GameState, action:Action):Void {
|
||||||
|
switch action {
|
||||||
|
case CLOSE:
|
||||||
|
storage.delete(state.preset.imageId);
|
||||||
|
images.data = storage.list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function back():Void {
|
private function back():Void {
|
||||||
switcher.change(StartFrame.ID);
|
switcher.change(StartFrame.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
style: frame
|
style: frame
|
||||||
views:
|
views:
|
||||||
- id: images
|
- id: images
|
||||||
$type: haxework.view.data.DataView
|
$type: haxework.view.data.ActionDataView
|
||||||
layout:
|
layout:
|
||||||
$type: haxework.view.layout.TailLayout
|
$type: haxework.view.layout.TailLayout
|
||||||
margin: 5
|
margin: 5
|
||||||
vAlign: middle
|
vAlign: middle
|
||||||
geometry.stretch: true
|
geometry.stretch: true
|
||||||
factory: ~ru.m.puzzlez.view.PuzzleImageView.factory
|
factory: ~ru.m.puzzlez.view.PuzzleImageView.stateFactory
|
||||||
+onDataSelect: ~start
|
+onDataSelect: ~start
|
||||||
|
+onDataAction: ~onAction
|
||||||
geometry.margin: 5
|
geometry.margin: 5
|
||||||
overflow.y: scroll
|
overflow.y: scroll
|
||||||
- $type: haxework.view.form.ButtonView
|
- $type: haxework.view.form.ButtonView
|
||||||
|
|||||||
@@ -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.image).then(function(image) {
|
loading.promise = imageStorage.resolve(preset.imageId).then(function(image) {
|
||||||
this.image = RenderUtil.cropImage(image, preset.imageRect);
|
this.image = RenderUtil.cropImage(image, preset.imageRect);
|
||||||
toRedraw();
|
toRedraw();
|
||||||
toUpdate();
|
toUpdate();
|
||||||
|
|||||||
@@ -1,41 +1,69 @@
|
|||||||
package ru.m.puzzlez.view;
|
package ru.m.puzzlez.view;
|
||||||
|
|
||||||
|
import haxework.view.data.DataView.ActionDataView;
|
||||||
|
import haxework.view.form.LabelView;
|
||||||
import haxework.view.group.GroupView;
|
import haxework.view.group.GroupView;
|
||||||
import haxework.view.ImageView;
|
import haxework.view.ImageView;
|
||||||
import haxework.view.utils.DrawUtil;
|
import ru.m.puzzlez.core.GameState;
|
||||||
|
import ru.m.puzzlez.core.GameUtil;
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
import ru.m.puzzlez.storage.ImageStorage;
|
import ru.m.puzzlez.storage.ImageStorage;
|
||||||
|
|
||||||
class PuzzleImageView extends GroupView {
|
enum Action {
|
||||||
|
CLOSE;
|
||||||
|
}
|
||||||
|
|
||||||
public var imageId(null, set):ImageId;
|
@:template class PuzzleImageView extends GroupView {
|
||||||
|
|
||||||
|
public var imageId(default, set):ImageId;
|
||||||
|
|
||||||
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) image.image = data);
|
loading.promise = imageStorage.resolve(imageId, true).then(function(data) imageView.image = data);
|
||||||
}
|
}
|
||||||
return imageId;
|
return imageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private var image:ImageView;
|
public var text(default, set):String;
|
||||||
private var loading:LoadingWrapper;
|
|
||||||
|
private function set_text(value:String):String {
|
||||||
|
if (text != value) {
|
||||||
|
text = value;
|
||||||
|
labelView.text = text;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:view("image") var imageView:ImageView;
|
||||||
|
@:view("label") var labelView:LabelView;
|
||||||
@:provide var imageStorage:ImageStorage;
|
@:provide var imageStorage:ImageStorage;
|
||||||
|
private var loading:LoadingWrapper;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
style = "view";
|
|
||||||
image = new ImageView();
|
|
||||||
image.geometry.stretch = true;
|
|
||||||
image.stretch = false;
|
|
||||||
image.fillType = COVER;
|
|
||||||
addView(image);
|
|
||||||
loading = new LoadingWrapper(this);
|
loading = new LoadingWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function close():Void {
|
||||||
|
var dataView:ActionDataView<Dynamic, PuzzleImageView, Action> = Std.instance(parent, ActionDataView);
|
||||||
|
if (dataView != null) {
|
||||||
|
var index = dataView.dataViews.indexOf(this);
|
||||||
|
dataView.onDataAction.emit(dataView.data[index], CLOSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function factory(index:Int, imageId:ImageId):PuzzleImageView {
|
public static function factory(index:Int, imageId:ImageId):PuzzleImageView {
|
||||||
var result = new PuzzleImageView();
|
var result = new PuzzleImageView();
|
||||||
result.imageId = imageId;
|
result.imageId = imageId;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function stateFactory(index:Int, state:GameState):PuzzleImageView {
|
||||||
|
var result = new PuzzleImageView();
|
||||||
|
result.imageId = state.preset.imageId;
|
||||||
|
var progress = GameUtil.calcProgress(state);
|
||||||
|
result.text = '${progress.complete}/${progress.total}';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml
Normal file
16
src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
style: view
|
||||||
|
views:
|
||||||
|
- id: image
|
||||||
|
$type: haxework.view.ImageView
|
||||||
|
geometry.stretch: true
|
||||||
|
stretch: false
|
||||||
|
fillType: COVER
|
||||||
|
- id: label
|
||||||
|
$type: haxework.view.form.LabelView
|
||||||
|
- id: close
|
||||||
|
$type: haxework.view.form.ButtonView
|
||||||
|
propagation: false
|
||||||
|
geometry.hAlign: right
|
||||||
|
text: X
|
||||||
|
+onPress: ~close()
|
||||||
Reference in New Issue
Block a user