cellular-automata/lib/service/engine_service.dart

47 lines
783 B
Dart
Raw Normal View History

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;
}