Move Render Methods into SimulationService

This commit is contained in:
Unknown 2018-10-18 14:41:57 +02:00
parent 58971016da
commit bbfb2f735b
4 changed files with 14 additions and 13 deletions

View file

@ -49,6 +49,6 @@ class ConfigurationComponent {
ConfigurationComponent(this.engine, this.sim);
void onEdgesClicked() {
engine.toggleGrid();
sim.toggleGrid();
}
}

View file

@ -2,6 +2,7 @@ import 'dart:html' as html;
import 'package:angular/angular.dart';
import 'package:rules_of_living/service/engine_service.dart';
import 'package:rules_of_living/service/simulation_service.dart';
@Component(
selector: 'gol-simulation',
@ -11,8 +12,9 @@ import 'package:rules_of_living/service/engine_service.dart';
)
class SimulationComponent implements OnInit {
final EngineService engine;
final SimulationService sim;
SimulationComponent(this.engine);
SimulationComponent(this.engine, this.sim);
@override
void ngOnInit() {
@ -29,6 +31,6 @@ class SimulationComponent implements OnInit {
the canvas did not load correctly :(
''', canvas.width / 2 - 50, canvas.height / 2);
engine.canvas = canvas;
sim.canvas = canvas;
}
}

View file

@ -1,5 +1,3 @@
import 'dart:html' as html;
import 'package:rules_of_living/src/Engine.dart';
class EngineService {
@ -43,14 +41,6 @@ class EngineService {
int get simSpeed => engine.stepsPerSecond;
void set simSpeed(int val) => engine.stepsPerSecond = val;
//TODO split into RenderService when rendering is decoupled from engine.
html.CanvasElement get canvas => engine.canvas;
void set canvas(html.CanvasElement canvas) => engine.canvas = canvas;
void toggleGrid() {
engine.toggleEdgeRendering();
}
void reset() {
engine.reset();
}

View file

@ -1,3 +1,4 @@
import 'dart:html' as html;
import 'dart:math';
import 'package:rules_of_living/service/engine_service.dart';
@ -24,4 +25,12 @@ class SimulationService {
}
Point<int> get gridSize => _engine.engine.gridSize;
//TODO split into RenderService when rendering is decoupled from engine.
html.CanvasElement get canvas => _engine.engine.canvas;
void set canvas(html.CanvasElement canvas) => _engine.engine.canvas = canvas;
void toggleGrid() {
_engine.engine.toggleEdgeRendering();
}
}