[update] save state after action
This commit is contained in:
@@ -6,7 +6,6 @@ import ru.m.puzzlez.core.Game;
|
||||
import ru.m.puzzlez.core.GameEvent;
|
||||
import ru.m.puzzlez.core.GameState;
|
||||
import ru.m.puzzlez.core.IGame;
|
||||
import ru.m.puzzlez.core.PartLocation;
|
||||
import ru.m.puzzlez.render.IRender;
|
||||
import ru.m.puzzlez.source.GameStorage;
|
||||
|
||||
@@ -18,6 +17,8 @@ import ru.m.puzzlez.source.GameStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var storage:GameStorage;
|
||||
|
||||
private var toSave:Bool;
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
}
|
||||
@@ -42,13 +43,18 @@ import ru.m.puzzlez.source.GameStorage;
|
||||
|
||||
private function onGameEvent(event:GameEvent):Void {
|
||||
switch event {
|
||||
case CHANGE(PART_UPDATE(_, IMAGE)):
|
||||
case ACTION(PART_PUT(_, _)):
|
||||
toSave = true;
|
||||
case CHANGE(PART_UPDATE(_, _)):
|
||||
if (toSave) {
|
||||
storage.save(game.state);
|
||||
toSave = false;
|
||||
}
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
private function back():Void {
|
||||
switcher.change(ImageListFrame.ID);
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user