Merge branch '14-refactor-reliance-on-inner-variables' into 'master'

Resolve "Refactor reliance on inner variables"

Closes #14

See merge request marty.oehme/cellular-automata!4
This commit is contained in:
Marty 2018-07-09 15:35:19 +00:00
commit 436061a629
3 changed files with 37 additions and 14 deletions

View file

@ -39,22 +39,20 @@ class AppComponent implements OnInit {
}
void onStepClicked() {
engine.running = false;
engine.update();
engine.step();
}
void onResetClicked() {
engine.running = false;
engine.reset();
}
void onRandomClicked() {
engine.running = false;
engine.grid.addPattern();
engine.addPattern();
}
void onEdgesClicked() {
engine.grid.switchEdgeRendering();
engine.toggleEdgeRendering();
}
void onClearClicked() {

View file

@ -19,20 +19,21 @@ class Engine {
num _drawLag = 0.0;
final html.CanvasElement canvas;
Grid grid = new Grid(100, 100);
bool running = false;
Grid _grid = new Grid(100, 100);
bool _running = false;
Engine(this.canvas) {
_elapsed.start();
grid.addPattern(amount: 15, dispersal: 5);
_grid.addPattern(amount: 15, dispersal: 5);
}
void reset() {
grid.reset();
_grid.reset();
running = false;
}
void clear() {
grid = new Grid(100, 100);
_grid = new Grid(100, 100);
running = false;
}
@ -59,11 +60,34 @@ class Engine {
void update() {
// print("updating");
if(!grid.update()) running = false;
if (!_grid.update()) running = false;
}
void step() {
running = false;
_grid.update();
}
void render([num interp]) {
// print("rendering");
grid.render(canvas, interp);
_grid.render(canvas, interp);
}
void addPattern(
{CellPattern pattern, int x, int y, int amount, int dispersal, int seed}) {
_grid.addPattern(
pattern: pattern,
x: x,
y: y,
amount: amount,
dispersal: dispersal,
seed: seed);
}
void toggleEdgeRendering() {
_grid.renderEdges = !_grid.renderEdges;
}
void set running(bool on) => _running = on;
bool get running => _running;
}

View file

@ -208,8 +208,9 @@ class Grid {
_dirty = false;
}
void switchEdgeRendering([bool on]) {
_renderEdges = on ?? !_renderEdges;
void set renderEdges(bool on) {
_renderEdges = on;
_dirty = true;
}
bool get renderEdges => _renderEdges;
}