2018-08-27 18:55:55 +00:00
|
|
|
import 'dart:html' as html;
|
2018-08-27 17:55:30 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2018-08-23 12:12:22 +00:00
|
|
|
import 'package:rules_of_living/service/engine_service.dart';
|
|
|
|
|
|
|
|
class ConfigurationService {
|
2018-08-27 18:50:12 +00:00
|
|
|
final EngineService _es;
|
2018-08-23 12:12:22 +00:00
|
|
|
|
|
|
|
bool showGrid;
|
2018-08-25 13:26:44 +00:00
|
|
|
|
|
|
|
int _simSpeed;
|
2018-08-25 14:41:11 +00:00
|
|
|
|
2018-08-27 18:55:55 +00:00
|
|
|
ConfigurationService(this._es) {
|
|
|
|
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).
|
2018-08-25 13:26:44 +00:00
|
|
|
int get simSpeed => _simSpeed;
|
|
|
|
void set simSpeed(int val) {
|
2018-08-25 13:51:32 +00:00
|
|
|
_simSpeed = val;
|
2018-08-27 18:50:12 +00:00
|
|
|
_es.engine.stepsPerSecond = simSpeed;
|
2018-08-25 13:26:44 +00:00
|
|
|
}
|
2018-08-23 12:12:22 +00:00
|
|
|
|
2018-08-27 18:55:55 +00:00
|
|
|
void set canvas(html.CanvasElement canvas) => _es.engine.canvas = canvas;
|
|
|
|
html.CanvasElement get canvas => _es.engine.canvas;
|
2018-08-23 12:12:22 +00:00
|
|
|
|
|
|
|
void toggleGrid() {
|
|
|
|
showGrid = !showGrid;
|
|
|
|
}
|
2018-08-27 17:55:30 +00:00
|
|
|
|
|
|
|
void setGridSize({int x, int y}) {
|
2018-08-27 18:50:12 +00:00
|
|
|
x = x ?? _es.engine.gridSize.x;
|
|
|
|
y = y ?? _es.engine.gridSize.y;
|
|
|
|
_es.engine.gridSize = Point(x, y);
|
2018-08-27 17:55:30 +00:00
|
|
|
}
|
2018-08-27 21:03:35 +00:00
|
|
|
|
|
|
|
Point<int> get gridSize => _es.engine.gridSize;
|
2018-08-27 17:55:30 +00:00
|
|
|
}
|