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() { void onStepClicked() {
engine.running = false; engine.step();
engine.update();
} }
void onResetClicked() { void onResetClicked() {
engine.running = false;
engine.reset(); engine.reset();
} }
void onRandomClicked() { void onRandomClicked() {
engine.running = false; engine.running = false;
engine.grid.addPattern(); engine.addPattern();
} }
void onEdgesClicked() { void onEdgesClicked() {
engine.grid.switchEdgeRendering(); engine.toggleEdgeRendering();
} }
void onClearClicked() { void onClearClicked() {

View file

@ -19,20 +19,21 @@ class Engine {
num _drawLag = 0.0; num _drawLag = 0.0;
final html.CanvasElement canvas; final html.CanvasElement canvas;
Grid grid = new Grid(100, 100); Grid _grid = new Grid(100, 100);
bool running = false; bool _running = false;
Engine(this.canvas) { Engine(this.canvas) {
_elapsed.start(); _elapsed.start();
grid.addPattern(amount: 15, dispersal: 5); _grid.addPattern(amount: 15, dispersal: 5);
} }
void reset() { void reset() {
grid.reset(); _grid.reset();
running = false;
} }
void clear() { void clear() {
grid = new Grid(100, 100); _grid = new Grid(100, 100);
running = false; running = false;
} }
@ -59,11 +60,34 @@ class Engine {
void update() { void update() {
// print("updating"); // print("updating");
if(!grid.update()) running = false; if (!_grid.update()) running = false;
}
void step() {
running = false;
_grid.update();
} }
void render([num interp]) { void render([num interp]) {
// print("rendering"); // 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; _dirty = false;
} }
void switchEdgeRendering([bool on]) { void set renderEdges(bool on) {
_renderEdges = on ?? !_renderEdges; _renderEdges = on;
_dirty = true; _dirty = true;
} }
bool get renderEdges => _renderEdges;
} }