48 lines
799 B
Dart
48 lines
799 B
Dart
import 'dart:html' as html;
|
|
|
|
import 'package:rules_of_living/src/Engine.dart';
|
|
|
|
class EngineService {
|
|
Engine _engine;
|
|
|
|
Engine get engine => _engine ?? getEngine(Engine());
|
|
|
|
Engine getEngine(Engine engine) {
|
|
_engine = engine;
|
|
return _engine;
|
|
}
|
|
|
|
void set canvas(html.CanvasElement canvas) => engine.canvas = canvas;
|
|
html.CanvasElement get canvas => engine.canvas;
|
|
|
|
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();
|
|
}
|
|
|
|
bool get isRunning => engine.running;
|
|
}
|