From 34bdd1ae816f9bca3584b885e5c9aba4fe90e173 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 7 Jul 2018 20:49:02 +0200 Subject: [PATCH] Apply dartfmt --- lib/app_component.dart | 7 +++---- lib/src/App.dart | 10 ++++------ lib/src/Cell.dart | 4 ++-- lib/src/Grid.dart | 35 +++++++++++++++++------------------ lib/src/Rule.dart | 2 +- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/app_component.dart b/lib/app_component.dart index e5ece87..435b9aa 100644 --- a/lib/app_component.dart +++ b/lib/app_component.dart @@ -4,10 +4,9 @@ import 'dart:html' as html; import 'package:rules_of_living/src/App.dart'; @Component( - selector: 'my-app', - templateUrl: "app_component.html", - directives: [coreDirectives] -) + selector: 'my-app', + templateUrl: "app_component.html", + directives: [coreDirectives]) class AppComponent implements OnInit { var name = "World"; diff --git a/lib/src/App.dart b/lib/src/App.dart index 64bfde9..cfbc032 100644 --- a/lib/src/App.dart +++ b/lib/src/App.dart @@ -18,9 +18,8 @@ class App { num _updateLag = 0.0; num _drawLag = 0.0; - final html.CanvasElement canvas; - Grid grid = new Grid(100,100); + Grid grid = new Grid(100, 100); bool running = false; App(this.canvas) { @@ -28,13 +27,13 @@ class App { grid.startingPattern(); } - void reset () { + void reset() { grid = new Grid(100, 100); running = false; } void process(num now) { - _drawLag+= _elapsed.elapsedMilliseconds; + _drawLag += _elapsed.elapsedMilliseconds; _updateLag += _elapsed.elapsedMilliseconds; _elapsed.reset(); @@ -59,9 +58,8 @@ class App { grid.update(); } - void render([num interp]) { // print("rendering"); grid.render(canvas, interp); } -} \ No newline at end of file +} diff --git a/lib/src/Cell.dart b/lib/src/Cell.dart index 5301fb6..f472280 100644 --- a/lib/src/Cell.dart +++ b/lib/src/Cell.dart @@ -20,8 +20,8 @@ class Cell { void update(int neighbors) { if (state == true) { - surviveRules.forEach( (Rule rule) { - if(rule.evaluate(neighbors) == true) this.nextState = true; + surviveRules.forEach((Rule rule) { + if (rule.evaluate(neighbors) == true) this.nextState = true; }); } else { birthRules.forEach((Rule rule) { diff --git a/lib/src/Grid.dart b/lib/src/Grid.dart index 5649c6b..c03b413 100644 --- a/lib/src/Grid.dart +++ b/lib/src/Grid.dart @@ -4,10 +4,7 @@ import 'dart:math' as math; import 'package:rules_of_living/src/Cell.dart'; import 'package:rules_of_living/src/Rule.dart'; -enum Pattern { - SpaceShip, - Blinker -} +enum Pattern { SpaceShip, Blinker } class Grid { final int w; @@ -25,24 +22,25 @@ class Grid { print("Grid creation finished"); } - void startingPattern({Pattern pattern, int x, int y, int amount, int dispersal}) { + void startingPattern( + {Pattern pattern, int x, int y, int amount, int dispersal}) { math.Random rng = new math.Random(); - int cx = x ?? rng.nextInt(w~/3) + (w~/3); - int cy = y ?? rng.nextInt(h~/3) + (h~/3); + int cx = x ?? rng.nextInt(w ~/ 3) + (w ~/ 3); + int cy = y ?? rng.nextInt(h ~/ 3) + (h ~/ 3); switch (pattern) { // Two blocks, offset // ## // ## case Pattern.Blinker: setCellState(cx, cy, true); - setCellState(cx+1, cy, true); - setCellState(cx, cy+1, true); - setCellState(cx+1, cy+1, true); + setCellState(cx + 1, cy, true); + setCellState(cx, cy + 1, true); + setCellState(cx + 1, cy + 1, true); - setCellState(cx+2, cy+2, true); - setCellState(cx+3, cy+2, true); - setCellState(cx+2, cy+3, true); - setCellState(cx+3, cy+3, true); + setCellState(cx + 2, cy + 2, true); + setCellState(cx + 3, cy + 2, true); + setCellState(cx + 2, cy + 3, true); + setCellState(cx + 3, cy + 3, true); break; // A 'gliding' Spaceship // # @@ -57,12 +55,13 @@ class Grid { break; default: for (var i = 0; i < amount ?? rng.nextInt(20); i++) { - setCellState(cx + dispersal ?? rng.nextInt(10), cy + dispersal ?? rng.nextInt(10), true); + setCellState(cx + dispersal ?? rng.nextInt(10), + cy + dispersal ?? rng.nextInt(10), true); } break; } } - + void setCellState(int x, int y, bool state) { if (y < map.length && x < map[y].length) map[y][x].state = state; } @@ -82,11 +81,11 @@ class Grid { // DEBUG RULE TESTING FOR PATTERNS Rule coagSurvive = new Rule((int n) { - if (n==1) return true; + if (n == 1) return true; return false; }); Rule coagBirth = new Rule((int n) { - if (n==1) return true; + if (n == 1) return true; return false; }); diff --git a/lib/src/Rule.dart b/lib/src/Rule.dart index 3a5eb1a..723b4d0 100644 --- a/lib/src/Rule.dart +++ b/lib/src/Rule.dart @@ -2,4 +2,4 @@ class Rule { final Function evaluate; Rule(this.evaluate); -} \ No newline at end of file +}