Fix Snapshot Load and Save Functions

Were just pointers to the map before. Fix to be actual clones of the map.
This commit is contained in:
Unknown 2018-10-19 20:49:59 +02:00
parent 37bff59f83
commit 2ea974bbd5
2 changed files with 12 additions and 6 deletions

View file

@ -154,6 +154,10 @@ class Simulation {
_dirty = true; _dirty = true;
} }
void saveSnapshot() => _snapshot = map; void saveSnapshot() => _snapshot = Grid.from(map);
Grid<bool> loadSnapshot() => map = _snapshot; Grid<bool> loadSnapshot() {
map = Grid.from(_snapshot);
_dirty = true;
return map;
}
} }

View file

@ -37,12 +37,14 @@ void main() {
}, skip: "can not find a way to set dirty to true first yet"); }, skip: "can not find a way to set dirty to true first yet");
}); });
group("save&load", () { group("save&load", () {
test("saves the current map, can be loaded by loadSnapshot", () { test(
var snapshot = sut.map; "saves a copy of the map which does not change when the actual map changes",
() {
sut.saveSnapshot(); sut.saveSnapshot();
sut.map = MockGrid(); sut.mergeStateChanges({1: true, 2: true});
var snapshot = Grid.from(sut.map);
expect(sut.loadSnapshot(), equals(snapshot)); expect(sut.loadSnapshot(), isNot(equals(snapshot)));
}); });
}); });
} }