cellular-automata/lib/service/configuration_service.dart

43 lines
1 KiB
Dart

import 'dart:html' as html;
import 'dart:math';
import 'package:rules_of_living/service/engine_service.dart';
class ConfigurationService {
final EngineService _es;
bool showGrid;
int _simSpeed;
ConfigurationService(this._es) {
showGrid = false;
simSpeed = 5;
}
/// 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;
_es.engine.stepsPerSecond = simSpeed;
}
void set canvas(html.CanvasElement canvas) => _es.engine.canvas = canvas;
html.CanvasElement get canvas => _es.engine.canvas;
void toggleGrid() {
showGrid = !showGrid;
}
void setGridSize({int x, int y}) {
x = x ?? _es.engine.gridSize.x;
y = y ?? _es.engine.gridSize.y;
_es.engine.gridSize = Point(x, y);
}
Point<int> get gridSize => _es.engine.gridSize;
}