Skip to content

Commit

Permalink
refactor: Use main outside of classes for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Aug 6, 2024
1 parent 9eff207 commit c30b2ea
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 66 deletions.
13 changes: 4 additions & 9 deletions packages/forge2d/example/web/ball_cage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -91,5 +83,8 @@ class BallCage extends Demo {
}

void main() {
BallCage.main();
final cage = BallCage();
cage.initialize();
cage.initializeAnimation();
cage.runAnimation();
}
13 changes: 4 additions & 9 deletions packages/forge2d/example/web/blob_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,5 +71,8 @@ class BlobTest extends Demo {
}

void main() {
BlobTest.main();
final blob = BlobTest();
blob.initialize();
blob.initializeAnimation();
blob.runAnimation();
}
13 changes: 4 additions & 9 deletions packages/forge2d/example/web/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -69,5 +61,8 @@ class BoxTest extends Demo {
}

void main() {
BoxTest.main();
final boxTest = BoxTest();
boxTest.initialize();
boxTest.initializeAnimation();
boxTest.runAnimation();
}
13 changes: 4 additions & 9 deletions packages/forge2d/example/web/domino_tower.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -142,5 +134,8 @@ class DominoTower extends Demo {
}

void main() {
DominoTower.main();
final tower = DominoTower();
tower.initialize();
tower.initializeAnimation();
tower.runAnimation();
}
15 changes: 5 additions & 10 deletions packages/forge2d/example/web/friction_joint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
13 changes: 4 additions & 9 deletions packages/forge2d/example/web/particles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -103,5 +95,8 @@ class Particles extends Demo {
}

void main() {
Particles.main();
Particles()
..initialize()
..initializeAnimation()
..runAnimation();
}
18 changes: 7 additions & 11 deletions packages/forge2d/example/web/racer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

0 comments on commit c30b2ea

Please sign in to comment.