This commit is contained in:
Marty Oehme 2018-08-23 12:38:34 +02:00
parent 223f831196
commit 6ba0ca55cb
6 changed files with 43 additions and 15 deletions

View file

@ -8,7 +8,15 @@ import 'package:rules_of_living/service/engine_service.dart';
@Component( @Component(
selector: 'my-app', selector: 'my-app',
templateUrl: "app_component.html", templateUrl: "app_component.html",
directives: [coreDirectives, MaterialButtonComponent, MaterialIconComponent, MaterialSliderComponent, HeaderComponent, SimulationComponent, ControlsComponent], directives: [
coreDirectives,
MaterialButtonComponent,
MaterialIconComponent,
MaterialSliderComponent,
HeaderComponent,
SimulationComponent,
ControlsComponent
],
providers: [materialProviders, ClassProvider(EngineService)], providers: [materialProviders, ClassProvider(EngineService)],
styleUrls: const ['package:angular_components/app_layout/layout.scss.css'], styleUrls: const ['package:angular_components/app_layout/layout.scss.css'],
) )

View file

@ -6,7 +6,13 @@ import 'package:rules_of_living/src/Engine.dart';
@Component( @Component(
selector: 'sim-controls', selector: 'sim-controls',
templateUrl: "controls_component.html", templateUrl: "controls_component.html",
directives: [coreDirectives, MaterialButtonComponent, MaterialIconComponent, MaterialSliderComponent, MaterialTooltipDirective], directives: [
coreDirectives,
MaterialButtonComponent,
MaterialIconComponent,
MaterialSliderComponent,
MaterialTooltipDirective
],
providers: [], providers: [],
styleUrls: const ["controls_component.css"], styleUrls: const ["controls_component.css"],
) )

View file

@ -4,10 +4,13 @@ import 'package:angular_components/angular_components.dart';
@Component( @Component(
selector: 'app_header', selector: 'app_header',
templateUrl: "header_component.html", templateUrl: "header_component.html",
directives: [coreDirectives, MaterialButtonComponent, MaterialIconComponent, MaterialSliderComponent], directives: [
coreDirectives,
MaterialButtonComponent,
MaterialIconComponent,
MaterialSliderComponent
],
providers: [], providers: [],
styleUrls: const ['package:angular_components/app_layout/layout.scss.css'], styleUrls: const ['package:angular_components/app_layout/layout.scss.css'],
) )
class HeaderComponent { class HeaderComponent {}
}

View file

@ -20,7 +20,7 @@ class SimulationComponent implements OnInit {
html.CanvasElement canvas = html.CanvasElement()..id = "simulation"; html.CanvasElement canvas = html.CanvasElement()..id = "simulation";
html.querySelector("#simulation")..append(canvas); html.querySelector("#simulation")..append(canvas);
canvas.width = 500; canvas.width = 500;
canvas.height= 500; canvas.height = 500;
canvas.context2D.setFillColorRgb(200, 0, 0); canvas.context2D.setFillColorRgb(200, 0, 0);
canvas.context2D.fillRect(0, 0, canvas.width, canvas.height); canvas.context2D.fillRect(0, 0, canvas.width, canvas.height);
@ -28,7 +28,7 @@ class SimulationComponent implements OnInit {
canvas.context2D.fillText(''' canvas.context2D.fillText('''
If you see this\n If you see this\n
the app is broken :( the app is broken :(
''', canvas.width/2-50, canvas.height/2); ''', canvas.width / 2 - 50, canvas.height / 2);
engineService.create(canvas); engineService.create(canvas);
html.window.animationFrame.then(animFrame); html.window.animationFrame.then(animFrame);

View file

@ -74,7 +74,12 @@ class Engine {
} }
void addPattern( void addPattern(
{CellPattern pattern, int x, int y, int amount, int dispersal, int seed}) { {CellPattern pattern,
int x,
int y,
int amount,
int dispersal,
int seed}) {
_grid.addPattern( _grid.addPattern(
pattern: pattern, pattern: pattern,
x: x, x: x,

View file

@ -44,7 +44,12 @@ class Grid {
} }
void addPattern( void addPattern(
{CellPattern pattern, int x, int y, int amount, int dispersal, int seed}) { {CellPattern pattern,
int x,
int y,
int amount,
int dispersal,
int seed}) {
_startingSeed = seed ?? DateTime.now().millisecondsSinceEpoch; _startingSeed = seed ?? DateTime.now().millisecondsSinceEpoch;
math.Random rng = new math.Random(_startingSeed); math.Random rng = new math.Random(_startingSeed);
_x = x; _x = x;
@ -154,7 +159,7 @@ class Grid {
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
Cell c = map[y][x]; Cell c = map[y][x];
if(c.state != c.nextState) stateChanges = true; if (c.state != c.nextState) stateChanges = true;
c.advanceState(); c.advanceState();
if (!_dirty && map[y][x].dirty) _dirty = true; if (!_dirty && map[y][x].dirty) _dirty = true;
@ -212,5 +217,6 @@ class Grid {
_renderEdges = on; _renderEdges = on;
_dirty = true; _dirty = true;
} }
bool get renderEdges => _renderEdges; bool get renderEdges => _renderEdges;
} }