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:
parent
37bff59f83
commit
2ea974bbd5
2 changed files with 12 additions and 6 deletions
|
@ -154,6 +154,10 @@ class Simulation {
|
|||
_dirty = true;
|
||||
}
|
||||
|
||||
void saveSnapshot() => _snapshot = map;
|
||||
Grid<bool> loadSnapshot() => map = _snapshot;
|
||||
void saveSnapshot() => _snapshot = Grid.from(map);
|
||||
Grid<bool> loadSnapshot() {
|
||||
map = Grid.from(_snapshot);
|
||||
_dirty = true;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,12 +37,14 @@ void main() {
|
|||
}, skip: "can not find a way to set dirty to true first yet");
|
||||
});
|
||||
group("save&load", () {
|
||||
test("saves the current map, can be loaded by loadSnapshot", () {
|
||||
var snapshot = sut.map;
|
||||
test(
|
||||
"saves a copy of the map which does not change when the actual map changes",
|
||||
() {
|
||||
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)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue