Add Save and Load Functions to SimService

This commit is contained in:
Unknown 2018-10-19 20:50:24 +02:00
parent 2ea974bbd5
commit 22dabda987
2 changed files with 29 additions and 2 deletions

View file

@ -9,9 +9,10 @@ class SimulationService {
static final int DEFAULT_GRID_SIZE = 50;
final EngineService _engine;
final Simulation _sim = Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE);
final Simulation _sim;
SimulationService(this._engine) {
SimulationService(this._engine, [Simulation sim])
: this._sim = sim ?? Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE) {
_engine.simulation = _sim;
_sim.addRandomPattern(amount: 15, dispersal: 5);
}
@ -36,4 +37,7 @@ class SimulationService {
void toggleGrid() {
_sim.renderEdges = !_sim.renderEdges;
}
void save() => _sim.saveSnapshot();
void load() => _sim.loadSnapshot();
}