Add SimulationService to controls

Will eventually attach to the Simulation directly without first going through Engine. For now just redirects calls to EngineService to keep functions intact.
This commit is contained in:
Unknown 2018-10-18 12:05:02 +02:00
parent 72ce25a806
commit 6b4786fdd0
3 changed files with 27 additions and 4 deletions

View file

@ -6,6 +6,7 @@ import 'package:rules_of_living/components/header_component.dart';
import 'package:rules_of_living/components/simulation_component.dart'; import 'package:rules_of_living/components/simulation_component.dart';
import 'package:rules_of_living/service/configuration_service.dart'; import 'package:rules_of_living/service/configuration_service.dart';
import 'package:rules_of_living/service/engine_service.dart'; import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/service/simulation_service.dart';
@Component( @Component(
selector: 'my-app', selector: 'my-app',
@ -24,6 +25,7 @@ import 'package:rules_of_living/service/engine_service.dart';
materialProviders, materialProviders,
ClassProvider(EngineService), ClassProvider(EngineService),
ClassProvider(ConfigurationService), ClassProvider(ConfigurationService),
ClassProvider(SimulationService)
], ],
styleUrls: const [ styleUrls: const [
'package:angular_components/app_layout/layout.scss.css', 'package:angular_components/app_layout/layout.scss.css',

View file

@ -1,6 +1,7 @@
import 'package:angular/angular.dart'; import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart'; import 'package:angular_components/angular_components.dart';
import 'package:rules_of_living/service/engine_service.dart'; import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/service/simulation_service.dart';
@Component( @Component(
selector: 'sim-controls', selector: 'sim-controls',
@ -16,8 +17,9 @@ import 'package:rules_of_living/service/engine_service.dart';
) )
class ControlsComponent { class ControlsComponent {
final EngineService engine; final EngineService engine;
final SimulationService sim;
ControlsComponent(this.engine); ControlsComponent(this.engine, this.sim);
void onStartClicked() { void onStartClicked() {
engine.toggleRunning(); engine.toggleRunning();
@ -28,14 +30,14 @@ class ControlsComponent {
} }
void onResetClicked() { void onResetClicked() {
engine.reset(); sim.reset();
} }
void onRandomClicked() { void onRandomClicked() {
engine.addRandomPattern(); sim.addRandomPattern();
} }
void onClearClicked() { void onClearClicked() {
engine.clear(); sim.clear();
} }
} }

View file

@ -0,0 +1,19 @@
import 'package:rules_of_living/service/engine_service.dart';
class SimulationService {
final EngineService engine;
SimulationService(this.engine);
void reset() {
engine.reset();
}
void addRandomPattern() {
engine.addRandomPattern();
}
void clear() {
engine.clear();
}
}