2018-08-22 18:16:31 +00:00
|
|
|
import 'dart:html' as html;
|
|
|
|
|
|
|
|
import 'package:rules_of_living/src/Engine.dart';
|
|
|
|
|
|
|
|
class EngineService {
|
|
|
|
Engine _engine;
|
|
|
|
|
2018-08-25 12:51:28 +00:00
|
|
|
Engine get engine => _engine ?? createEngine(null);
|
2018-08-25 07:33:15 +00:00
|
|
|
|
2018-08-25 12:51:28 +00:00
|
|
|
Engine createEngine(html.CanvasElement canvas) {
|
2018-08-25 07:33:15 +00:00
|
|
|
_engine = Engine(canvas);
|
|
|
|
return _engine;
|
|
|
|
}
|
|
|
|
|
2018-08-25 13:00:46 +00:00
|
|
|
void set canvas(html.CanvasElement canvas) => engine.canvas = canvas;
|
|
|
|
html.CanvasElement get canvas => engine.canvas;
|
2018-08-25 12:51:28 +00:00
|
|
|
|
2018-08-25 07:33:15 +00:00
|
|
|
void run() {
|
|
|
|
engine.running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop() {
|
|
|
|
engine.running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleRunning() {
|
|
|
|
engine.running = !engine.running;
|
|
|
|
}
|
|
|
|
|
|
|
|
void step() {
|
|
|
|
engine.step();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
engine.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void addRandomPattern() {
|
|
|
|
engine.running = false;
|
|
|
|
engine.addPattern();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
engine.clear();
|
|
|
|
}
|
2018-08-22 18:16:31 +00:00
|
|
|
|
2018-08-25 12:10:19 +00:00
|
|
|
bool get isRunning => engine.running;
|
|
|
|
|
2018-08-22 18:16:31 +00:00
|
|
|
}
|