cellular-automata/lib/service/configuration_service.dart

45 lines
1.1 KiB
Dart
Raw Normal View History

import 'dart:html' as html;
2018-08-27 17:55:30 +00:00
import 'dart:math';
import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/service/simulation_service.dart';
class ConfigurationService {
final EngineService _engine;
final SimulationService _sim;
bool showGrid;
int _simSpeed;
2018-08-25 14:41:11 +00:00
ConfigurationService(this._engine, this._sim) {
showGrid = false;
simSpeed = 5;
}
2018-08-25 14:41:11 +00:00
/// Simulation Speed
///
/// Sets the number of updates the simulation takes per second. Can range from
/// 1 to arbitrarily high numbers (though setting it too high can potentially
/// make the app brittle).
int get simSpeed => _simSpeed;
void set simSpeed(int val) {
_simSpeed = val;
//TODO make method in EngineService to respect Demeter
_engine.engine.stepsPerSecond = simSpeed;
}
void set canvas(html.CanvasElement canvas) => _engine.engine.canvas = canvas;
html.CanvasElement get canvas => _engine.engine.canvas;
void toggleGrid() {
showGrid = !showGrid;
}
2018-08-27 17:55:30 +00:00
void setGridSize({int x, int y}) {
_sim.gridSize = Point<int>(x ?? gridSize.x, y ?? gridSize.y);
2018-08-27 17:55:30 +00:00
}
Point<int> get gridSize => _sim.gridSize;
2018-08-27 17:55:30 +00:00
}