From c30b2ea63029ed1f45f9d2e17a4bcf583d5f7efc Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 6 Aug 2024 20:50:42 +0200 Subject: [PATCH] refactor: Use main outside of classes for examples --- packages/forge2d/example/web/ball_cage.dart | 13 ++++--------- packages/forge2d/example/web/blob_test.dart | 13 ++++--------- packages/forge2d/example/web/box_test.dart | 13 ++++--------- packages/forge2d/example/web/domino_tower.dart | 13 ++++--------- .../example/web/friction_joint_test.dart | 15 +++++---------- packages/forge2d/example/web/particles.dart | 13 ++++--------- packages/forge2d/example/web/racer.dart | 18 +++++++----------- 7 files changed, 32 insertions(+), 66 deletions(-) diff --git a/packages/forge2d/example/web/ball_cage.dart b/packages/forge2d/example/web/ball_cage.dart index 1f922b0..6d8513a 100644 --- a/packages/forge2d/example/web/ball_cage.dart +++ b/packages/forge2d/example/web/ball_cage.dart @@ -16,14 +16,6 @@ class BallCage extends Demo { /// Constructs a new BallCage. BallCage() : super('Ball cage'); - /// Entrypoint. - void main() { - final cage = BallCage(); - cage.initialize(); - cage.initializeAnimation(); - cage.runAnimation(); - } - @override void initialize() { // Define the circle shape. @@ -91,5 +83,8 @@ class BallCage extends Demo { } void main() { - BallCage.main(); + final cage = BallCage(); + cage.initialize(); + cage.initializeAnimation(); + cage.runAnimation(); } diff --git a/packages/forge2d/example/web/blob_test.dart b/packages/forge2d/example/web/blob_test.dart index 1791c20..fbca10c 100644 --- a/packages/forge2d/example/web/blob_test.dart +++ b/packages/forge2d/example/web/blob_test.dart @@ -8,14 +8,6 @@ class BlobTest extends Demo { /// Constructs a new BlobTest. BlobTest() : super('Blob test'); - /// Entrypoint. - void main() { - final blob = BlobTest(); - blob.initialize(); - blob.initializeAnimation(); - blob.runAnimation(); - } - @override void initialize() { Body ground; @@ -79,5 +71,8 @@ class BlobTest extends Demo { } void main() { - BlobTest.main(); + final blob = BlobTest(); + blob.initialize(); + blob.initializeAnimation(); + blob.runAnimation(); } diff --git a/packages/forge2d/example/web/box_test.dart b/packages/forge2d/example/web/box_test.dart index a62ebc8..2f80cab 100644 --- a/packages/forge2d/example/web/box_test.dart +++ b/packages/forge2d/example/web/box_test.dart @@ -8,14 +8,6 @@ class BoxTest extends Demo { /// Constructs a new BoxTest. BoxTest() : super('Box test'); - /// Entrypoint. - void main() { - final boxTest = BoxTest(); - boxTest.initialize(); - boxTest.initializeAnimation(); - boxTest.runAnimation(); - } - @override void initialize() { _createGround(); @@ -69,5 +61,8 @@ class BoxTest extends Demo { } void main() { - BoxTest.main(); + final boxTest = BoxTest(); + boxTest.initialize(); + boxTest.initializeAnimation(); + boxTest.runAnimation(); } diff --git a/packages/forge2d/example/web/domino_tower.dart b/packages/forge2d/example/web/domino_tower.dart index 36e6eaa..1322c12 100644 --- a/packages/forge2d/example/web/domino_tower.dart +++ b/packages/forge2d/example/web/domino_tower.dart @@ -17,14 +17,6 @@ class DominoTower extends Demo { /// Construct a DominoTower. DominoTower() : super('Domino tower'); - /// Entrypoint. - void main() { - final tower = DominoTower(); - tower.initialize(); - tower.initializeAnimation(); - tower.runAnimation(); - } - void makeDomino(double x, double y, {required bool horizontal}) { final shape = PolygonShape() ..setAsBoxXY(.5 * dominoWidth, .5 * dominoHeight); @@ -142,5 +134,8 @@ class DominoTower extends Demo { } void main() { - DominoTower.main(); + final tower = DominoTower(); + tower.initialize(); + tower.initializeAnimation(); + tower.runAnimation(); } diff --git a/packages/forge2d/example/web/friction_joint_test.dart b/packages/forge2d/example/web/friction_joint_test.dart index f8a8240..2dcae2f 100644 --- a/packages/forge2d/example/web/friction_joint_test.dart +++ b/packages/forge2d/example/web/friction_joint_test.dart @@ -7,15 +7,6 @@ import 'demo.dart'; class FrictionJointTest extends Demo { FrictionJointTest() : super('FrictionJoint test'); - /// Entrypoint. - void main() { - final test = FrictionJointTest(); - test.initialize(); - test.initializeAnimation(); - test.debugDraw.appendFlags(DebugDraw.jointBit); - test.runAnimation(); - } - late Body _ground; late FixtureDef _boxFixture; @@ -100,5 +91,9 @@ class FrictionJointTest extends Demo { } void main() { - FrictionJointTest.main(); + final test = FrictionJointTest(); + test.initialize(); + test.initializeAnimation(); + test.debugDraw.appendFlags(DebugDraw.jointBit); + test.runAnimation(); } diff --git a/packages/forge2d/example/web/particles.dart b/packages/forge2d/example/web/particles.dart index ed63a9b..5e3dbf7 100644 --- a/packages/forge2d/example/web/particles.dart +++ b/packages/forge2d/example/web/particles.dart @@ -15,14 +15,6 @@ class Particles extends Demo { /// Constructs a new Particles example. Particles() : super('Particles'); - - void main() { - Particles() - ..initialize() - ..initializeAnimation() - ..runAnimation(); - } - @override void initialize() { // Define the circle shape. @@ -103,5 +95,8 @@ class Particles extends Demo { } void main() { - Particles.main(); + Particles() + ..initialize() + ..initializeAnimation() + ..runAnimation(); } diff --git a/packages/forge2d/example/web/racer.dart b/packages/forge2d/example/web/racer.dart index 0ccb0c0..0036e46 100644 --- a/packages/forge2d/example/web/racer.dart +++ b/packages/forge2d/example/web/racer.dart @@ -10,16 +10,6 @@ import 'racer/ground_area.dart'; import 'racer/tire.dart'; class Racer extends Demo implements ContactListener { - void main() { - final racer = Racer(); - racer.initialize(); - racer.initializeAnimation(); - final paragraph = ParagraphElement() - ..innerText = 'Use the arrow keys to drive the car'; - document.body?.nodes.add(paragraph); - racer.runAnimation(); - } - Racer() : super('Racer', Vector2.zero(), 2.5); late int _controlState; @@ -186,5 +176,11 @@ class Racer extends Demo implements ContactListener { } void main() { - Racer.main(); + final racer = Racer(); + racer.initialize(); + racer.initializeAnimation(); + final paragraph = ParagraphElement() + ..innerText = 'Use the arrow keys to drive the car'; + document.body?.nodes.add(paragraph); + racer.runAnimation(); }