From c5b62e6c9f0369235791756dcb94f4c540f57dc2 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 7 Jul 2018 21:43:24 +0200 Subject: [PATCH] Fix Reset & Step not working on first click Rendering dirty flags were not updated accordingly, so the updates happened but were not pushed to be rendered. Added and moved additional dirty flag setters. --- lib/app_component.dart | 1 + lib/src/App.dart | 7 ++++--- lib/src/Grid.dart | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/app_component.dart b/lib/app_component.dart index e559ab7..afce95f 100644 --- a/lib/app_component.dart +++ b/lib/app_component.dart @@ -44,6 +44,7 @@ class AppComponent implements OnInit { } void onResetClicked() { + engine.running = false; engine.reset(); } diff --git a/lib/src/App.dart b/lib/src/App.dart index cfbc032..8ab933a 100644 --- a/lib/src/App.dart +++ b/lib/src/App.dart @@ -24,12 +24,13 @@ class App { App(this.canvas) { _elapsed.start(); - grid.startingPattern(); + grid.addPattern(amount: 15, dispersal: 5); } void reset() { - grid = new Grid(100, 100); - running = false; +// grid = new Grid(100, 100); +// running = false; + grid.reset(); } void process(num now) { diff --git a/lib/src/Grid.dart b/lib/src/Grid.dart index c35bd16..5730461 100644 --- a/lib/src/Grid.dart +++ b/lib/src/Grid.dart @@ -89,6 +89,10 @@ class Grid { if (y < map.length && x < map[y].length) map[y][x].state = state; } + bool getCellState(int x, int y) { + if (y < map.length && x < map[y].length) return map[y][x].state; + } + List> _buildGrid(int w, int h) { print("grid being created"); List> grid = new List(h); @@ -133,13 +137,13 @@ class Grid { for (int x = 0; x < w; x++) { // DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE map[y][x].update(getSurroundingNeighbors(x, y, 1)); - if (!_dirty && map[y][x].dirty) _dirty = true; } } for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { // DEFAULTS TO CONWAY GAME OF LIFE RANGE OF ONE map[y][x].advanceState(); + if (!_dirty && map[y][x].dirty) _dirty = true; } } }