[update] save state after action

This commit is contained in:
2020-02-04 21:58:23 +03:00
parent 8f934ba365
commit 73cbf0a48e

View File

@@ -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)):
storage.save(game.state);
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);
}
}