From bbfb2f735b26b3112f0773072b14bc5fb72e1138 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 18 Oct 2018 14:41:57 +0200 Subject: [PATCH] Move Render Methods into SimulationService --- lib/components/configuration_component.dart | 2 +- lib/components/simulation_component.dart | 6 ++++-- lib/service/engine_service.dart | 10 ---------- lib/service/simulation_service.dart | 9 +++++++++ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/components/configuration_component.dart b/lib/components/configuration_component.dart index c72106c..abbd2e5 100644 --- a/lib/components/configuration_component.dart +++ b/lib/components/configuration_component.dart @@ -49,6 +49,6 @@ class ConfigurationComponent { ConfigurationComponent(this.engine, this.sim); void onEdgesClicked() { - engine.toggleGrid(); + sim.toggleGrid(); } } diff --git a/lib/components/simulation_component.dart b/lib/components/simulation_component.dart index 91812fb..1fcef71 100644 --- a/lib/components/simulation_component.dart +++ b/lib/components/simulation_component.dart @@ -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; } } diff --git a/lib/service/engine_service.dart b/lib/service/engine_service.dart index 6d40681..a76fedb 100644 --- a/lib/service/engine_service.dart +++ b/lib/service/engine_service.dart @@ -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(); } diff --git a/lib/service/simulation_service.dart b/lib/service/simulation_service.dart index 0c967ef..b5a9021 100644 --- a/lib/service/simulation_service.dart +++ b/lib/service/simulation_service.dart @@ -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 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(); + } }