Move Canvas setting to configuration service

Fix #39
This commit is contained in:
Marty Oehme 2018-08-27 20:55:55 +02:00
parent a92b864dfa
commit b6919cff6b
3 changed files with 12 additions and 13 deletions

View file

@ -1,7 +1,7 @@
import 'dart:html' as html; import 'dart:html' as html;
import 'package:angular/angular.dart'; import 'package:angular/angular.dart';
import 'package:rules_of_living/service/control_service.dart'; import 'package:rules_of_living/service/configuration_service.dart';
@Component( @Component(
selector: 'gol-simulation', selector: 'gol-simulation',
@ -10,9 +10,9 @@ import 'package:rules_of_living/service/control_service.dart';
providers: [], providers: [],
) )
class SimulationComponent implements OnInit { class SimulationComponent implements OnInit {
final ControlService ctrl; final ConfigurationService config;
SimulationComponent(this.ctrl); SimulationComponent(this.config);
@override @override
void ngOnInit() { void ngOnInit() {
@ -29,6 +29,6 @@ class SimulationComponent implements OnInit {
the canvas did not load correctly :( the canvas did not load correctly :(
''', canvas.width / 2 - 50, canvas.height / 2); ''', canvas.width / 2 - 50, canvas.height / 2);
ctrl.canvas = canvas; config.canvas = canvas;
} }
} }

View file

@ -1,3 +1,4 @@
import 'dart:html' as html;
import 'dart:math'; import 'dart:math';
import 'package:rules_of_living/service/engine_service.dart'; import 'package:rules_of_living/service/engine_service.dart';
@ -9,6 +10,11 @@ class ConfigurationService {
int _simSpeed; int _simSpeed;
ConfigurationService(this._es) {
showGrid = false;
simSpeed = 5;
}
/// Simulation Speed /// Simulation Speed
/// ///
/// Sets the number of updates the simulation takes per second. Can range from /// Sets the number of updates the simulation takes per second. Can range from
@ -20,10 +26,8 @@ class ConfigurationService {
_es.engine.stepsPerSecond = simSpeed; _es.engine.stepsPerSecond = simSpeed;
} }
ConfigurationService(this._es) { void set canvas(html.CanvasElement canvas) => _es.engine.canvas = canvas;
showGrid = false; html.CanvasElement get canvas => _es.engine.canvas;
simSpeed = 5;
}
void toggleGrid() { void toggleGrid() {
showGrid = !showGrid; showGrid = !showGrid;

View file

@ -1,5 +1,3 @@
import 'dart:html' as html;
import 'package:rules_of_living/service/engine_service.dart'; import 'package:rules_of_living/service/engine_service.dart';
class ControlService { class ControlService {
@ -7,9 +5,6 @@ class ControlService {
ControlService(this._es); ControlService(this._es);
void set canvas(html.CanvasElement canvas) => _es.engine.canvas = canvas;
html.CanvasElement get canvas => _es.engine.canvas;
void run() { void run() {
_es.engine.running = true; _es.engine.running = true;
} }