Split ConfigurationService to use SimulationService
Methods concerning engine make use of EngineService, those concerning grid and patterns make use of SimulationService.
This commit is contained in:
parent
6b4786fdd0
commit
7729da3a40
3 changed files with 26 additions and 15 deletions
|
@ -2,15 +2,17 @@ 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';
|
||||||
|
import 'package:rules_of_living/service/simulation_service.dart';
|
||||||
|
|
||||||
class ConfigurationService {
|
class ConfigurationService {
|
||||||
final EngineService _es;
|
final EngineService _engine;
|
||||||
|
final SimulationService _sim;
|
||||||
|
|
||||||
bool showGrid;
|
bool showGrid;
|
||||||
|
|
||||||
int _simSpeed;
|
int _simSpeed;
|
||||||
|
|
||||||
ConfigurationService(this._es) {
|
ConfigurationService(this._engine, this._sim) {
|
||||||
showGrid = false;
|
showGrid = false;
|
||||||
simSpeed = 5;
|
simSpeed = 5;
|
||||||
}
|
}
|
||||||
|
@ -23,21 +25,20 @@ class ConfigurationService {
|
||||||
int get simSpeed => _simSpeed;
|
int get simSpeed => _simSpeed;
|
||||||
void set simSpeed(int val) {
|
void set simSpeed(int val) {
|
||||||
_simSpeed = val;
|
_simSpeed = val;
|
||||||
_es.engine.stepsPerSecond = simSpeed;
|
//TODO make method in EngineService to respect Demeter
|
||||||
|
_engine.engine.stepsPerSecond = simSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set canvas(html.CanvasElement canvas) => _es.engine.canvas = canvas;
|
void set canvas(html.CanvasElement canvas) => _engine.engine.canvas = canvas;
|
||||||
html.CanvasElement get canvas => _es.engine.canvas;
|
html.CanvasElement get canvas => _engine.engine.canvas;
|
||||||
|
|
||||||
void toggleGrid() {
|
void toggleGrid() {
|
||||||
showGrid = !showGrid;
|
showGrid = !showGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGridSize({int x, int y}) {
|
void setGridSize({int x, int y}) {
|
||||||
x = x ?? _es.engine.gridSize.x;
|
_sim.gridSize = Point(x ?? gridSize.x, y ?? gridSize.y);
|
||||||
y = y ?? _es.engine.gridSize.y;
|
|
||||||
_es.engine.gridSize = Point(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Point<int> get gridSize => _es.engine.gridSize;
|
Point<int> get gridSize => _sim.gridSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,27 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:rules_of_living/service/engine_service.dart';
|
import 'package:rules_of_living/service/engine_service.dart';
|
||||||
|
|
||||||
class SimulationService {
|
class SimulationService {
|
||||||
final EngineService engine;
|
final EngineService _engine;
|
||||||
|
|
||||||
SimulationService(this.engine);
|
SimulationService(this._engine);
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
engine.reset();
|
_engine.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRandomPattern() {
|
void addRandomPattern() {
|
||||||
engine.addRandomPattern();
|
_engine.addRandomPattern();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
engine.clear();
|
_engine.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set gridSize(Point size) {
|
||||||
|
_engine.engine.gridSize = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Point<int> get gridSize => _engine.engine.gridSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.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';
|
||||||
import 'package:rules_of_living/src/Engine.dart';
|
import 'package:rules_of_living/src/Engine.dart';
|
||||||
@TestOn('browser')
|
@TestOn('browser')
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
@ -12,12 +13,13 @@ class MockEngine extends Mock implements Engine {}
|
||||||
void main() {
|
void main() {
|
||||||
ConfigurationService sut;
|
ConfigurationService sut;
|
||||||
EngineService engineService;
|
EngineService engineService;
|
||||||
|
SimulationService simService;
|
||||||
MockEngine me;
|
MockEngine me;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
me = MockEngine();
|
me = MockEngine();
|
||||||
engineService = EngineService();
|
engineService = EngineService();
|
||||||
engineService.engine = me;
|
engineService.engine = me;
|
||||||
sut = ConfigurationService(engineService);
|
sut = ConfigurationService(engineService, simService);
|
||||||
});
|
});
|
||||||
|
|
||||||
group("simulation speed", () {
|
group("simulation speed", () {
|
||||||
|
|
Loading…
Reference in a new issue