cellular-automata/lib/service/engine_service.dart
Unknown 17697070ee Move ControlService tasks into EngineService
All ControlService was used for was a redirection to the engine service. This will be further split up in the future into more logical units of responsibility.
2018-10-18 11:58:38 +02:00

46 lines
783 B
Dart

import 'package:rules_of_living/src/Engine.dart';
class EngineService {
Engine _uncachedEngineAccess;
Engine get engine => _uncachedEngineAccess ?? _setCachedAndReturn(Engine());
void set engine(Engine newEngine) {
_uncachedEngineAccess = newEngine;
}
Engine _setCachedAndReturn(Engine newEngine) {
engine = newEngine;
return newEngine;
}
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;
}