Skip to content

Commit 4c35c4a

Browse files
authored
chore: Update dependencies and to Pub Workspaces (#102)
# Description * Migrates to pub workspaces * Migrates to package:web (from dart:html) * Makes examples slightly more efficient * Cleans up the new lint warnings ## Checklist <!-- Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. --> - [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc). - [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs. - [x] I have updated/added tests for ALL new/updated/fixed functionality. - [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`. - [x] I have updated/added relevant examples in `examples`. ## Breaking Change <!-- Does your PR require Flame users to manually update their apps to accommodate your change? If the PR is a breaking change this should be indicated with suffix "!" (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details. --> - [ ] Yes, this is a breaking change. - [x] No, this is *not* a breaking change. ## Related Issues <!-- Provide a list of issues related to this PR from the [issue database]. Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !--> <!-- Links --> [issue database]: https://github.com/flame-engine/flame/issues [Contributor Guide]: https://github.com/flame-engine/flame/blob/main/CONTRIBUTING.md [Flame Style Guide]: https://github.com/flame-engine/flame/blob/main/STYLEGUIDE.md [Conventional Commit]: https://conventionalcommits.org
1 parent 584a07e commit 4c35c4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+468
-409
lines changed

melos.yaml

Lines changed: 0 additions & 84 deletions
This file was deleted.

packages/benchmark/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
name: forge2d_benchmark
22
description: Simple benchmark for Forge2D
3+
resolution: workspace
34

45
version: 1.0.0+1
56

67
publish_to: 'none'
78

89
environment:
9-
sdk: ">=3.0.0 <4.0.0"
10+
sdk: ">=3.8.0 <4.0.0"
1011

1112
dependencies:
1213
build_runner: ^2.4.5
1314
build_web_compilers: ^4.0.3
1415
forge2d: ^0.14.0
16+
web: ^1.1.1
1517

1618
dev_dependencies:
17-
flame_lint: ^1.1.1
19+
flame_lint: ^1.4.1

packages/benchmark/web/bench2d_web.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import 'dart:html';
1+
import 'dart:js_interop';
22

33
import 'package:forge2d/forge2d_browser.dart';
4+
import 'package:web/web.dart';
45

56
import 'bench2d.dart';
67

@@ -16,7 +17,7 @@ class Bench2dWeb extends Bench2d {
1617
static const int canvasHeight = 600;
1718
static const double _viewportScale = 10.0;
1819

19-
late CanvasElement canvas;
20+
late HTMLCanvasElement canvas;
2021
late CanvasRenderingContext2D ctx;
2122
late ViewportTransform viewport;
2223
late DebugDraw debugDraw;
@@ -25,7 +26,7 @@ class Bench2dWeb extends Bench2d {
2526
/// before calling runAnimation.
2627
void initializeAnimation() {
2728
// Setup the canvas.
28-
canvas = CanvasElement()
29+
canvas = HTMLCanvasElement()
2930
..width = canvasWidth
3031
..height = canvasHeight;
3132

@@ -51,10 +52,10 @@ class Bench2dWeb extends Bench2d {
5152

5253
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
5354
world.drawDebugData();
54-
window.animationFrame.then(render);
55+
window.requestAnimationFrame(render.toJS);
5556
}
5657

5758
void runAnimation() {
58-
window.animationFrame.then(render);
59+
window.requestAnimationFrame(render.toJS);
5960
}
6061
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: forge2d_examples
22
description: Samples showcasing Forge2D
3-
43
version: 1.0.0+1
4+
resolution: workspace
55

66
publish_to: 'none'
77

88
environment:
9-
sdk: ">=3.0.0 <4.0.0"
9+
sdk: ">=3.8.0 <4.0.0"
1010

1111
dependencies:
1212
forge2d: ^0.14.0
13+
web: ^1.1.1
1314

1415
dev_dependencies:
15-
build_runner: ^2.4.5
16-
build_web_compilers: ^4.0.4
17-
flame_lint: ^1.1.1
16+
build_runner: ^2.6.0
17+
build_web_compilers: ^4.2.0
18+
flame_lint: ^1.4.1

packages/forge2d/example/web/demo.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'dart:async';
2-
import 'dart:html' hide Body;
2+
import 'dart:js_interop';
33

44
import 'package:forge2d/forge2d_browser.dart';
5+
import 'package:web/web.dart';
56

67
/// An abstract class for any Demo of the Forge2D library.
78
abstract class Demo {
@@ -31,7 +32,7 @@ abstract class Demo {
3132
final double _viewportScale;
3233

3334
/// The drawing canvas.
34-
late final CanvasElement canvas;
35+
late final HTMLCanvasElement canvas;
3536

3637
/// The canvas rendering context.
3738
late final CanvasRenderingContext2D ctx;
@@ -55,10 +56,10 @@ abstract class Demo {
5556
late final Element worldStepTime;
5657

5758
Demo(String name, [Vector2? gravity, this._viewportScale = viewportScale])
58-
: world = World(gravity ?? Vector2(0.0, _gravity)),
59-
_stopwatch = Stopwatch()..start() {
59+
: world = World(gravity ?? Vector2(0.0, _gravity)),
60+
_stopwatch = Stopwatch()..start() {
6061
world.setAllowSleep(true);
61-
querySelector('#title')?.innerHtml = name;
62+
document.querySelector('#title')?.innerHTML = name.toJS;
6263
}
6364

6465
/// Advances the world forward by timestep seconds.
@@ -72,17 +73,17 @@ abstract class Demo {
7273
world.drawDebugData();
7374
frameCount++;
7475

75-
window.requestAnimationFrame(step);
76+
window.requestAnimationFrame(step.toJS);
7677
}
7778

7879
/// Creates the canvas and readies the demo for animation. Must be called
7980
/// before calling runAnimation.
8081
void initializeAnimation() {
8182
// Setup the canvas.
82-
canvas = (Element.tag('canvas') as CanvasElement)
83+
canvas = HTMLCanvasElement()
8384
..width = canvasWidth
8485
..height = canvasHeight;
85-
document.body?.nodes.add(canvas);
86+
document.body?.appendChild(canvas);
8687
ctx = canvas.context2D;
8788

8889
// Create the viewport transform with the center at extents.
@@ -96,24 +97,24 @@ abstract class Demo {
9697
// Have the world draw itself for debugging purposes.
9798
world.debugDraw = debugDraw;
9899

99-
fpsCounter = querySelector('#fps-counter')!;
100-
worldStepTime = querySelector('#world-step-time')!;
100+
fpsCounter = document.querySelector('#fps-counter')!;
101+
worldStepTime = document.querySelector('#world-step-time')!;
101102
Timer.periodic(const Duration(seconds: 1), (Timer t) {
102-
fpsCounter.innerHtml = frameCount.toString();
103+
fpsCounter.innerHTML = frameCount.toJS;
103104
frameCount = 0;
104105
});
105106
Timer.periodic(const Duration(milliseconds: 200), (Timer t) {
106107
if (elapsedUs == null) {
107108
return;
108109
}
109-
worldStepTime.innerHtml = '${elapsedUs! / 1000} ms';
110+
worldStepTime.innerHTML = '${elapsedUs! / 1000} ms'.toJS;
110111
});
111112
}
112113

113114
void initialize();
114115

115116
/// Starts running the demo as an animation using an animation scheduler.
116117
void runAnimation() {
117-
window.requestAnimationFrame(step);
118+
window.requestAnimationFrame(step.toJS);
118119
}
119120
}

packages/forge2d/example/web/domino_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ class DominoTest extends Demo {
4242

4343
for (var i = 0; i < 4; ++i) {
4444
for (var j = 0; j < numPerRow; j++) {
45-
bodyDef.position =
46-
Vector2(-14.75 + j * (29.5 / (numPerRow - 1)), 7.3 + 5 * i);
45+
bodyDef.position = Vector2(
46+
-14.75 + j * (29.5 / (numPerRow - 1)),
47+
7.3 + 5 * i,
48+
);
4749
if (i == 2 && j == 0) {
4850
bodyDef.angle = -.1;
4951
bodyDef.position.x += .1;

packages/forge2d/example/web/domino_tower.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class DominoTower extends Demo {
9797
dominoHeight * .5 + (dominoHeight + 2 * dominoWidth) * .99 * j;
9898

9999
for (var i = 0; i < baseCount - j; ++i) {
100-
currX = i * 1.5 * dominoHeight -
100+
currX =
101+
i * 1.5 * dominoHeight -
101102
(1.5 * dominoHeight * (baseCount - j) / 2);
102103
dominoDensity *= 2.5;
103104
if (i == 0) {

packages/forge2d/example/web/racer.dart

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import 'dart:html' hide Body;
1+
import 'dart:js_interop';
22
import 'dart:math';
33

44
import 'package:forge2d/forge2d_browser.dart';
5+
import 'package:web/web.dart';
56

67
import 'demo.dart';
78
import 'racer/car.dart';
@@ -26,8 +27,8 @@ class Racer extends Demo implements ContactListener {
2627
_controlState = 0;
2728

2829
// Bind to keyboard events.
29-
document.onKeyDown.listen(_handleKeyDown);
30-
document.onKeyUp.listen(_handleKeyUp);
30+
document.onkeydown = _handleKeyDown.toJS;
31+
document.onkeyup = _handleKeyUp.toJS;
3132

3233
// Add ourselves as a collision listener.
3334
world.setContactListener(this);
@@ -120,33 +121,25 @@ class Racer extends Demo implements ContactListener {
120121
switch (event.keyCode) {
121122
case 37:
122123
_controlState |= ControlState.left;
123-
break;
124124
case 38:
125125
_controlState |= ControlState.up;
126-
break;
127126
case 39:
128127
_controlState |= ControlState.right;
129-
break;
130128
case 40:
131129
_controlState |= ControlState.down;
132-
break;
133130
}
134131
}
135132

136133
void _handleKeyUp(KeyboardEvent event) {
137134
switch (event.keyCode) {
138135
case 37:
139136
_controlState &= ~ControlState.left;
140-
break;
141137
case 38:
142138
_controlState &= ~ControlState.up;
143-
break;
144139
case 39:
145140
_controlState &= ~ControlState.right;
146-
break;
147141
case 40:
148142
_controlState &= ~ControlState.down;
149-
break;
150143
}
151144
}
152145

@@ -179,8 +172,8 @@ void main() {
179172
final racer = Racer();
180173
racer.initialize();
181174
racer.initializeAnimation();
182-
final paragraph = ParagraphElement()
175+
final paragraph = HTMLParagraphElement()
183176
..innerText = 'Use the arrow keys to drive the car';
184-
document.body?.nodes.add(paragraph);
177+
document.body?.append(paragraph);
185178
racer.runAnimation();
186179
}

packages/forge2d/example/web/racer/car.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ class Car {
122122
switch (controlState & (ControlState.left | ControlState.right)) {
123123
case ControlState.left:
124124
desiredAngle = _lockAngle;
125-
break;
126125
case ControlState.right:
127126
desiredAngle = -_lockAngle;
128-
break;
129127
}
130128
final turnPerTimeStep = _turnSpeedPerSec * 1000 / time;
131129
final angleNow = _frontLeftJoint.jointAngle();
132-
final angleToTurn =
133-
(desiredAngle - angleNow).clamp(-turnPerTimeStep, turnPerTimeStep);
130+
final angleToTurn = (desiredAngle - angleNow).clamp(
131+
-turnPerTimeStep,
132+
turnPerTimeStep,
133+
);
134134
final angle = angleNow + angleToTurn;
135135
_frontLeftJoint.setLimits(angle, angle);
136136
_frontRightJoint.setLimits(angle, angle);

packages/forge2d/example/web/racer/tire.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ class Tire {
7171
switch (controlState & (ControlState.up | ControlState.down)) {
7272
case ControlState.up:
7373
desiredSpeed = _maxForwardSpeed;
74-
break;
7574
case ControlState.down:
7675
desiredSpeed = _maxBackwardSpeed;
77-
break;
7876
default:
7977
return;
8078
}
@@ -98,10 +96,8 @@ class Tire {
9896
switch (controlState & (ControlState.left | ControlState.right)) {
9997
case ControlState.left:
10098
desiredTorque = 15.0;
101-
break;
10299
case ControlState.right:
103100
desiredTorque = -15.0;
104-
break;
105101
}
106102
body.applyTorque(desiredTorque);
107103
}

0 commit comments

Comments
 (0)