woofjs-engine 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +16 -106
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/dist/canvas.js +4 -31
- package/dist/collision.js +8 -5
- package/dist/game.js +4 -84
- package/dist/index-1jykaz1m.js +142 -0
- package/dist/index-9mz0qg9d.js +39 -0
- package/dist/index-b9a70qgn.js +34 -0
- package/dist/index-dp75gf4w.js +57 -0
- package/dist/index-f63yb8zf.js +85 -0
- package/dist/index-gypg8d50.js +31 -0
- package/dist/index-w4yvg8ax.js +2568 -0
- package/dist/index.js +134 -239
- package/dist/input.js +4 -33
- package/dist/play.js +304 -0
- package/dist/sound.js +4 -56
- package/dist/store.js +4 -30
- package/dist/types/canvas.d.ts +20 -2
- package/dist/types/collision.d.ts +62 -0
- package/dist/types/game.d.ts +21 -1
- package/dist/types/global.d.ts +4 -0
- package/dist/types/helpers.d.ts +92 -0
- package/dist/types/index.d.ts +23 -12
- package/dist/types/input.d.ts +4 -0
- package/dist/types/play.d.ts +167 -0
- package/dist/types/sound.d.ts +10 -3
- package/dist/types/sprites/custom.d.ts +9 -0
- package/dist/types/sprites/easing.d.ts +9 -0
- package/dist/types/sprites/geometry.d.ts +22 -0
- package/dist/types/sprites/options.d.ts +98 -0
- package/dist/types/sprites/render.d.ts +2 -0
- package/dist/types/sprites/sprite.d.ts +283 -0
- package/dist/types/store.d.ts +4 -0
- package/dist/types/ui.d.ts +65 -0
- package/dist/types/woof.d.ts +395 -0
- package/dist/types/world/audio.d.ts +118 -0
- package/dist/types/world/globals.d.ts +3 -0
- package/dist/types/world/keys.d.ts +2 -0
- package/dist/types/world/options.d.ts +44 -0
- package/dist/types/world/render.d.ts +13 -0
- package/dist/types/world/scheduler.d.ts +65 -0
- package/dist/ui.js +235 -0
- package/dist/woof.global.js +3620 -0
- package/docs/api.json +5439 -0
- package/docs/woof-parity.md +231 -0
- package/package.json +25 -8
- package/docs/architecture.md +0 -37
- package/docs/planning.md +0 -33
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# WoofJS upstream parity
|
|
2
|
+
|
|
3
|
+
Targets are runtime property paths rooted at `api`, `play`, `project`, `sprite`, or `sound`. Internal SAT and browser implementation details are excluded.
|
|
4
|
+
|
|
5
|
+
The fixture in `test/fixtures/woof-public-members.json` inventories the upstream
|
|
6
|
+
Woof constructor and prototype, project-facing names, sprite and sound members,
|
|
7
|
+
and the exposed prototype extensions and scheduling records. Underscore-prefixed
|
|
8
|
+
fields, backing storage (including `fullScreen1`, `privateX`, and canvas/audio
|
|
9
|
+
implementation objects), and the bundled SAT library are implementation details,
|
|
10
|
+
not separate game-facing API entries. Some exposed implementation methods and
|
|
11
|
+
records are retained in the inventory where they could be called directly.
|
|
12
|
+
|
|
13
|
+
| Upstream | Runtime target | Status | Reason |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| `detectCollision` | `api.detectCollision` | same | Accepts SAT.js shapes and engine colliders. |
|
|
16
|
+
| `Woof` | `api.woof` | renamed | — |
|
|
17
|
+
| `Bundle` | `play.Bundle` | same | — |
|
|
18
|
+
| `Circle` | `play.Circle` | same | — |
|
|
19
|
+
| `DOWN` | `api.DOWN` | same | — |
|
|
20
|
+
| `Image` | `play.Image` | same | — |
|
|
21
|
+
| `LEFT` | `api.LEFT` | same | — |
|
|
22
|
+
| `Line` | `play.Line` | same | — |
|
|
23
|
+
| `Oval` | `play.Oval` | same | — |
|
|
24
|
+
| `Polygon` | `play.Polygon` | same | — |
|
|
25
|
+
| `RIGHT` | `api.RIGHT` | same | — |
|
|
26
|
+
| `Rectangle` | `play.Rectangle` | same | — |
|
|
27
|
+
| `Repeat` | `api.Repeat` | same | — |
|
|
28
|
+
| `RepeatUntil` | `api.RepeatUntil` | same | — |
|
|
29
|
+
| `Sound` | `play.Sound` | same | — |
|
|
30
|
+
| `Sprite` | `play.Sprite` | same | — |
|
|
31
|
+
| `Text` | `play.Text` | same | — |
|
|
32
|
+
| `TextPrimative` | `play.TextPrimative` | same | — |
|
|
33
|
+
| `UP` | `api.UP` | same | — |
|
|
34
|
+
| `abs` | `api.abs` | same | — |
|
|
35
|
+
| `acos` | `api.acos` | same | — |
|
|
36
|
+
| `asin` | `api.asin` | same | — |
|
|
37
|
+
| `atan` | `api.atan` | same | — |
|
|
38
|
+
| `ceiling` | `api.ceiling` | same | — |
|
|
39
|
+
| `cos` | `api.cos` | same | — |
|
|
40
|
+
| `customSprite` | `project.customSprite` | same | Also available through the beginner API. |
|
|
41
|
+
| `dayOfMonth` | `api.dayOfMonth` | same | — |
|
|
42
|
+
| `dayOfWeek` | `api.dayOfWeek` | same | — |
|
|
43
|
+
| `extend` | `api.extend` | same | — |
|
|
44
|
+
| `floor` | `api.floor` | same | — |
|
|
45
|
+
| `hour` | `api.hour` | same | — |
|
|
46
|
+
| `hourMilitary` | `api.hourMilitary` | same | — |
|
|
47
|
+
| `importCodeURL` | `api.importCodeURL` | same | — |
|
|
48
|
+
| `keyCodeToString` | `api.keyCodeToString` | same | — |
|
|
49
|
+
| `ln` | `api.ln` | same | — |
|
|
50
|
+
| `log` | `api.log` | same | — |
|
|
51
|
+
| `minute` | `api.minute` | same | — |
|
|
52
|
+
| `mobile` | `api.mobile` | same | — |
|
|
53
|
+
| `month` | `api.month` | same | — |
|
|
54
|
+
| `months` | `api.months` | same | — |
|
|
55
|
+
| `pow` | `api.pow` | same | — |
|
|
56
|
+
| `random` | `api.random` | same | Whole numbers are sampled uniformly and inclusively; upstream rounds and supports fractional bounds. Use `randomFloat` for fractions. |
|
|
57
|
+
| `randomColor` | `api.randomColor` | same | — |
|
|
58
|
+
| `range` | `api.range` | same | — |
|
|
59
|
+
| `rgb` | `api.rgb` | same | — |
|
|
60
|
+
| `second` | `api.second` | same | — |
|
|
61
|
+
| `sin` | `api.sin` | same | — |
|
|
62
|
+
| `sqrt` | `api.sqrt` | same | — |
|
|
63
|
+
| `tan` | `api.tan` | same | — |
|
|
64
|
+
| `unitsToMiliseconds` | `api.unitsToMiliseconds` | same | — |
|
|
65
|
+
| `year` | `api.year` | same | — |
|
|
66
|
+
| `project.after` | `project.after` | same | — |
|
|
67
|
+
| `project.backdrop` | `project.backdrop` | same | — |
|
|
68
|
+
| `project.bounds` | `project.bounds` | same | — |
|
|
69
|
+
| `project.cameraX` | `project.cameraX` | same | — |
|
|
70
|
+
| `project.cameraY` | `project.cameraY` | same | — |
|
|
71
|
+
| `project.clearPen` | `project.clearPen` | same | — |
|
|
72
|
+
| `project.collider` | `project.collider` | same | — |
|
|
73
|
+
| `project.defrost` | `project.defrost` | same | — |
|
|
74
|
+
| `project.every` | `project.every` | same | — |
|
|
75
|
+
| `project.forever` | `project.forever` | same | — |
|
|
76
|
+
| `project.freeze` | `project.freeze` | same | — |
|
|
77
|
+
| `project.fullScreen` | `project.fullScreen` | same | — |
|
|
78
|
+
| `project.global` | `project.global` | same | — |
|
|
79
|
+
| `project.height` | `project.height` | same | — |
|
|
80
|
+
| `project.keysDown` | `project.keysDown` | same | Set with an `includes` compatibility method; array indexing and mutation methods differ. |
|
|
81
|
+
| `project.maxX` | `project.maxX` | same | — |
|
|
82
|
+
| `project.maxY` | `project.maxY` | same | — |
|
|
83
|
+
| `project.minX` | `project.minX` | same | — |
|
|
84
|
+
| `project.minY` | `project.minY` | same | — |
|
|
85
|
+
| `project.mouseDown` | `project.mouseDown` | same | — |
|
|
86
|
+
| `project.mouseX` | `project.mouseX` | same | — |
|
|
87
|
+
| `project.mouseXSpeed` | `project.mouseXSpeed` | same | — |
|
|
88
|
+
| `project.mouseY` | `project.mouseY` | same | — |
|
|
89
|
+
| `project.mouseYSpeed` | `project.mouseYSpeed` | same | — |
|
|
90
|
+
| `project.onKeyDown` | `project.onKeyDown` | same | — |
|
|
91
|
+
| `project.onKeyUp` | `project.onKeyUp` | same | — |
|
|
92
|
+
| `project.onMouseDown` | `project.onMouseDown` | same | — |
|
|
93
|
+
| `project.onMouseMove` | `project.onMouseMove` | same | — |
|
|
94
|
+
| `project.onMouseUp` | `project.onMouseUp` | same | — |
|
|
95
|
+
| `project.pMouseX` | `project.pMouseX` | same | — |
|
|
96
|
+
| `project.pMouseY` | `project.pMouseY` | same | — |
|
|
97
|
+
| `project.randomX` | `project.randomX` | same | — |
|
|
98
|
+
| `project.randomY` | `project.randomY` | same | — |
|
|
99
|
+
| `project.ready` | `project.ready` | same | — |
|
|
100
|
+
| `project.repeat` | `project.repeat` | same | — |
|
|
101
|
+
| `project.repeatUntil` | `project.repeatUntil` | same | — |
|
|
102
|
+
| `project.resetTimer` | `project.resetTimer` | same | — |
|
|
103
|
+
| `project.setBackdropColor` | `project.setBackdropColor` | same | — |
|
|
104
|
+
| `project.setBackdropRepeat` | `project.setBackdropRepeat` | same | — |
|
|
105
|
+
| `project.setBackdropSize` | `project.setBackdropSize` | same | — |
|
|
106
|
+
| `project.setBackdropStyle` | `project.setBackdropStyle` | same | — |
|
|
107
|
+
| `project.setBackdropURL` | `project.setBackdropURL` | same | — |
|
|
108
|
+
| `project.sprites` | `project.sprites` | same | — |
|
|
109
|
+
| `project.stopped` | `project.stopped` | same | — |
|
|
110
|
+
| `project.timer` | `project.timer` | same | — |
|
|
111
|
+
| `project.translateToCanvas` | `project.translateToCanvas` | same | — |
|
|
112
|
+
| `project.translateToCenter` | `project.translateToCenter` | same | — |
|
|
113
|
+
| `project.when` | `project.when` | same | — |
|
|
114
|
+
| `project.width` | `project.width` | same | — |
|
|
115
|
+
| `sprite.addComponent` | `sprite.addComponent` | same | — |
|
|
116
|
+
| `sprite.angle` | `sprite.angle` | same | — |
|
|
117
|
+
| `sprite.bounds` | `sprite.bounds` | same | — |
|
|
118
|
+
| `sprite.brightness` | `sprite.brightness` | same | — |
|
|
119
|
+
| `sprite.canvasX` | `sprite.canvasX` | same | — |
|
|
120
|
+
| `sprite.canvasY` | `sprite.canvasY` | same | — |
|
|
121
|
+
| `sprite.changePosition` | `sprite.changePosition` | same | — |
|
|
122
|
+
| `sprite.collider` | `sprite.collider` | same | — |
|
|
123
|
+
| `sprite.color` | `sprite.color` | same | — |
|
|
124
|
+
| `sprite.components` | `sprite.components` | same | — |
|
|
125
|
+
| `sound.currentTime` | `sound.currentTime` | same | — |
|
|
126
|
+
| `sprite.delete` | `sprite.delete` | same | — |
|
|
127
|
+
| `sprite.deleted` | `sprite.deleted` | same | — |
|
|
128
|
+
| `sprite.distanceTo` | `sprite.distanceTo` | same | — |
|
|
129
|
+
| `sound.duration` | `sound.duration` | same | — |
|
|
130
|
+
| `sprite.fontFamily` | `sprite.fontFamily` | same | — |
|
|
131
|
+
| `sprite.height` | `sprite.height` | same | — |
|
|
132
|
+
| `sprite.hide` | `sprite.hide` | same | — |
|
|
133
|
+
| `sound.isPlaying` | `sound.isPlaying` | same | — |
|
|
134
|
+
| `sprite.length` | `sprite.length` | same | — |
|
|
135
|
+
| `sprite.lineWidth` | `sprite.lineWidth` | same | — |
|
|
136
|
+
| `sound.loop` | `sound.loop` | same | — |
|
|
137
|
+
| `sprite.mouseDown` | `sprite.mouseDown` | same | — |
|
|
138
|
+
| `sprite.mouseOver` | `sprite.mouseOver` | same | — |
|
|
139
|
+
| `sprite.move` | `sprite.move` | same | — |
|
|
140
|
+
| `sound.neverPlayed` | `sound.neverPlayed` | same | — |
|
|
141
|
+
| `sprite.onMouseDown` | `sprite.onMouseDown` | same | — |
|
|
142
|
+
| `sprite.onMouseUp` | `sprite.onMouseUp` | same | — |
|
|
143
|
+
| `sprite.over` | `sprite.over` | same | — |
|
|
144
|
+
| `sprite.overlap` | `sprite.overlap` | same | — |
|
|
145
|
+
| `sound.pausePlaying` | `sound.pausePlaying` | same | — |
|
|
146
|
+
| `sprite.penColor` | `sprite.penColor` | same | — |
|
|
147
|
+
| `sprite.penDown` | `sprite.penDown` | same | — |
|
|
148
|
+
| `sprite.penUp` | `sprite.penUp` | same | — |
|
|
149
|
+
| `sprite.penWidth` | `sprite.penWidth` | same | — |
|
|
150
|
+
| `sprite.pointTowards` | `sprite.pointTowards` | same | — |
|
|
151
|
+
| `sprite.project` | `sprite.project` | same | — |
|
|
152
|
+
| `sprite.radians` | `sprite.radians` | same | — |
|
|
153
|
+
| `sprite.radius` | `sprite.radius` | same | — |
|
|
154
|
+
| `sprite.removeComponent` | `sprite.removeComponent` | same | — |
|
|
155
|
+
| `sprite.render` | `sprite.render` | same | — |
|
|
156
|
+
| `sprite.rotatedVector` | `sprite.rotatedVector` | same | — |
|
|
157
|
+
| `sprite.rotationStyle` | `sprite.rotationStyle` | same | — |
|
|
158
|
+
| `sprite.sendToBack` | `sprite.sendToBack` | same | — |
|
|
159
|
+
| `sprite.sendToFront` | `sprite.sendToFront` | same | — |
|
|
160
|
+
| `sprite.setImageURL` | `sprite.setImageURL` | same | — |
|
|
161
|
+
| `sprite.setPosition` | `sprite.setPosition` | same | — |
|
|
162
|
+
| `sprite.setRotationStyle` | `sprite.setRotationStyle` | same | — |
|
|
163
|
+
| `sprite.show` | `sprite.show` | same | — |
|
|
164
|
+
| `sprite.showCollider` | `sprite.showCollider` | same | — |
|
|
165
|
+
| `sprite.showing` | `sprite.showing` | same | — |
|
|
166
|
+
| `sprite.sides` | `sprite.sides` | same | — |
|
|
167
|
+
| `sprite.size` | `sprite.size` | same | — |
|
|
168
|
+
| `sound.speed` | `sound.speed` | same | — |
|
|
169
|
+
| `sound.startPlaying` | `sound.startPlaying` | same | — |
|
|
170
|
+
| `sound.stopPlaying` | `sound.stopPlaying` | same | — |
|
|
171
|
+
| `sprite.text` | `sprite.text` | same | — |
|
|
172
|
+
| `sprite.textAlign` | `sprite.textAlign` | same | — |
|
|
173
|
+
| `sprite.textEval` | `sprite.textEval` | same | — |
|
|
174
|
+
| `sprite.toJSON` | `sprite.toJSON` | same | — |
|
|
175
|
+
| `sprite.toString` | `sprite.toString` | same | — |
|
|
176
|
+
| `sprite.touching` | `sprite.touching` | same | — |
|
|
177
|
+
| `sprite.translatedVector` | `sprite.translatedVector` | same | — |
|
|
178
|
+
| `sprite.turnLeft` | `sprite.turnLeft` | same | — |
|
|
179
|
+
| `sprite.turnRight` | `sprite.turnRight` | same | — |
|
|
180
|
+
| `sprite.type` | `sprite.type` | same | — |
|
|
181
|
+
| `sprite.url` | `sprite.url` | same | — |
|
|
182
|
+
| `sound.url` | `sound.url` | same | — |
|
|
183
|
+
| `sound.volume` | `sound.volume` | same | — |
|
|
184
|
+
| `sprite.width` | `sprite.width` | same | — |
|
|
185
|
+
| `sprite.x` | `sprite.x` | same | — |
|
|
186
|
+
| `sprite.x1` | `sprite.x1` | same | — |
|
|
187
|
+
| `sprite.y` | `sprite.y` | same | — |
|
|
188
|
+
| `sprite.y1` | `sprite.y1` | same | — |
|
|
189
|
+
| `Number.prototype.between` | `api.between` | renamed | — |
|
|
190
|
+
| `Array.prototype.remove` | `api.remove` | renamed | — |
|
|
191
|
+
| `throttle` | `api.throttle` | same | — |
|
|
192
|
+
| `getData` | `api.getData` | same | — |
|
|
193
|
+
| `project.freezing` | `project.freezing` | same | Freeze completes synchronously. |
|
|
194
|
+
| `project.woofEpoch` | `project.woofEpoch` | same | Timer progression uses game time. |
|
|
195
|
+
| `project.renderInterval` | `project.renderInterval` | same | — |
|
|
196
|
+
| `sprite.trackPen` | `sprite.trackPen` | same | — |
|
|
197
|
+
| `sprite.detachListeners` | `sprite.detachListeners` | same | — |
|
|
198
|
+
| `sprite.arrangeComponents` | `sprite.arrangeComponents` | same | — |
|
|
199
|
+
| `sprite.offsetX` | `sprite.offsetX` | same | — |
|
|
200
|
+
| `sprite.offsetY` | `sprite.offsetY` | same | — |
|
|
201
|
+
| `sprite.offsetAngle` | `sprite.offsetAngle` | same | — |
|
|
202
|
+
| `sprite.image` | `sprite.image` | same | — |
|
|
203
|
+
| `sound.audio` | `sound.audio` | same | Intentional difference: the current Web Audio source replaces the HTML audio element so amplification can use the audio graph. |
|
|
204
|
+
| `sound.audioSettings` | `sound.audioSettings` | same | — |
|
|
205
|
+
| `Repeat.func` | `repeat.func` | same | — |
|
|
206
|
+
| `Repeat.curTimes` | `repeat.curTimes` | same | — |
|
|
207
|
+
| `Repeat.times` | `repeat.times` | same | — |
|
|
208
|
+
| `Repeat.done` | `repeat.done` | same | — |
|
|
209
|
+
| `Repeat.next` | `repeat.next` | same | — |
|
|
210
|
+
| `RepeatUntil.func` | `repeatUntil.func` | same | — |
|
|
211
|
+
| `RepeatUntil.curTimes` | `repeatUntil.curTimes` | same | — |
|
|
212
|
+
| `RepeatUntil.condition` | `repeatUntil.condition` | same | — |
|
|
213
|
+
| `RepeatUntil.done` | `repeatUntil.done` | same | — |
|
|
214
|
+
| `RepeatUntil.next` | `repeatUntil.next` | same | — |
|
|
215
|
+
| `Array.prototype.toString` | `api.arrayToString` | renamed | — |
|
|
216
|
+
|
|
217
|
+
## Behaviour and intentional differences
|
|
218
|
+
|
|
219
|
+
Coordinates are centred, with positive y upwards; angles are in degrees, with zero pointing right and positive turns counter-clockwise. Movement is measured in world units. Sprite collision uses an AABB prefilter and shape intersection; precise collision reads canvas pixels and throws for tainted images; upstream falls back to treating tainted images as touching. Ovals use ellipse geometry for shape collision; upstream uses a rectangular collider for ovals. Ellipse intersection uses numerical calculations for curved shapes. A sprite does not touch itself here. Sprite bounds account for rotation and scale, whereas upstream's base sprite bounds use unrotated width and height. Bundle bounds encompass their components.
|
|
220
|
+
|
|
221
|
+
`overlap(bounds)` tests the bounds supplied by the caller; upstream's implementation instead tests the project collider regardless of that argument. Lines can use `move` here, while upstream rejects it. Angles are normalized to the range from zero inclusive to 360 exclusive after turns and `pointTowards`; upstream can leave 360 or a negative result. These are deliberate corrections or additions.
|
|
222
|
+
|
|
223
|
+
`after` and `every` use game time, with numeric durations in seconds and explicit millisecond or minute units supported. `every` runs immediately, and `when` runs on each frame while true. The timer also uses game time, whereas upstream uses wall-clock time. Explicit `step` makes timing deterministic, and automatic frame deltas are clamped.
|
|
224
|
+
|
|
225
|
+
The scheduler returns cancellable handles, and repeating tasks stop immediately when cancelled, including during catch-up after a long step. Upstream uses browser timers for `after` and `every`, while its frame repetitions advance with rendering. Callback errors are reported through the project error handler so other tasks can continue.
|
|
226
|
+
|
|
227
|
+
The engine exposes `sound.audio` as the active Web Audio source rather than upstream's HTML audio element, allowing amplification through the audio graph. Project teardown removes listeners, and helper functions replace upstream prototype extensions.
|
|
228
|
+
|
|
229
|
+
Upstream rounds the visible bounds for odd canvas dimensions; this engine retains fractional half-pixel bounds. Images have no default URL here because upstream’s default references an image asset that is not distributed with this engine.
|
|
230
|
+
|
|
231
|
+
`hour()` returns 12 at midnight, while upstream returns 0. Mobile detection uses the user agent instead of upstream’s `window.orientation` check. The engine accepts a wider range of positive playback speeds than upstream’s 0.5–2 range. These are intentional differences.
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "woofjs-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A browser game engine for JavaScript and TypeScript, ported from WoofJS, with components for shadcn/ui, shadcn-svelte and Optimus UI.",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -32,12 +32,20 @@
|
|
|
32
32
|
"./collision": {
|
|
33
33
|
"types": "./dist/types/collision.d.ts",
|
|
34
34
|
"import": "./dist/collision.js"
|
|
35
|
+
},
|
|
36
|
+
"./play": {
|
|
37
|
+
"types": "./dist/types/play.d.ts",
|
|
38
|
+
"import": "./dist/play.js"
|
|
39
|
+
},
|
|
40
|
+
"./ui": {
|
|
41
|
+
"types": "./dist/types/ui.d.ts",
|
|
42
|
+
"import": "./dist/ui.js"
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
45
|
"scripts": {
|
|
38
46
|
"prebuild": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
39
|
-
"build": "bun build src/index.ts src/game.ts src/sound.ts src/store.ts src/canvas.ts src/input.ts src/collision.ts --outdir dist --target browser --format esm && tsc -p tsconfig.json",
|
|
40
|
-
"typecheck": "tsc -p tsconfig.consumer.json",
|
|
47
|
+
"build": "bun build src/index.ts src/play.ts src/game.ts src/sound.ts src/store.ts src/canvas.ts src/input.ts src/collision.ts src/ui.ts --outdir dist --root src --target browser --format esm --splitting && bun build src/global.ts --outfile dist/woof.global.js --target browser --format iife && tsc -p tsconfig.json",
|
|
48
|
+
"typecheck": "tsc -p tsconfig.consumer.json && node type-tests/generate-woof-style.mjs && tsc -p /tmp/woofjs-engine-style-types/tsconfig.json",
|
|
41
49
|
"test": "npm run typecheck && node --test"
|
|
42
50
|
},
|
|
43
51
|
"engines": {
|
|
@@ -48,25 +56,34 @@
|
|
|
48
56
|
"type": "git",
|
|
49
57
|
"url": "git+https://gitlab.com/ratradworke/woofjs-engine.git"
|
|
50
58
|
},
|
|
51
|
-
"homepage": "https://
|
|
59
|
+
"homepage": "https://ratradworke.gitlab.io/woofjs-engine/",
|
|
52
60
|
"bugs": {
|
|
53
61
|
"url": "https://gitlab.com/ratradworke/woofjs-engine/-/issues"
|
|
54
62
|
},
|
|
55
63
|
"keywords": [
|
|
56
64
|
"game-engine",
|
|
65
|
+
"woofjs",
|
|
57
66
|
"education",
|
|
58
67
|
"canvas",
|
|
59
|
-
"svelte"
|
|
68
|
+
"svelte",
|
|
69
|
+
"react",
|
|
70
|
+
"angular",
|
|
71
|
+
"shadcn"
|
|
60
72
|
],
|
|
61
73
|
"files": [
|
|
62
74
|
"dist/",
|
|
63
75
|
"docs/",
|
|
64
76
|
"examples/",
|
|
65
77
|
"README.md",
|
|
66
|
-
"LICENSE"
|
|
78
|
+
"LICENSE",
|
|
79
|
+
"CHANGELOG.md",
|
|
80
|
+
"THIRD_PARTY_NOTICES.md"
|
|
67
81
|
],
|
|
68
82
|
"devDependencies": {
|
|
69
83
|
"bun": "^1.4.5",
|
|
84
|
+
"sucrase": "^3.35.1",
|
|
70
85
|
"typescript": "^7.0.2"
|
|
71
|
-
}
|
|
86
|
+
},
|
|
87
|
+
"unpkg": "./dist/woof.global.js",
|
|
88
|
+
"jsdelivr": "./dist/woof.global.js"
|
|
72
89
|
}
|
package/docs/architecture.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Architecture
|
|
2
|
-
|
|
3
|
-
woofjs-engine is a small set of host-independent primitives. It does not own a scene graph, asset loader, or framework lifecycle. Its optional keyboard helper tracks physical key codes on a supplied event target, clears on blur, and must be destroyed on teardown. The rectangle overlap helper is independent of the DOM. The host application owns those concerns and supplies callbacks or browser objects when needed. The public entry point also exports `createStore` for observable shared state and `createCanvas` for independent DOM canvas surfaces. Multiple canvases can share a store without requiring a built-in scene graph.
|
|
4
|
-
|
|
5
|
-
## Game loop
|
|
6
|
-
|
|
7
|
-
`createGame({ state, update, render, requestFrame, cancelFrame })` creates a game controller. `state` is the starting state object. `update(deltaSeconds, state, frame)` advances it; `render(state, frame)` draws or presents it. The first callback argument is elapsed **seconds**. The public `step(deltaMs)` accepts **milliseconds** and converts the duration before invoking `update`.
|
|
8
|
-
|
|
9
|
-
The controller exposes:
|
|
10
|
-
|
|
11
|
-
- `step(deltaMs)` to process one frame explicitly.
|
|
12
|
-
- `start()` to begin scheduling frames through the injected scheduler.
|
|
13
|
-
- `stop()` to cancel the scheduled frame and halt the loop.
|
|
14
|
-
- `getState()` to read the live state object.
|
|
15
|
-
- `setState(nextState)` to replace the state object.
|
|
16
|
-
|
|
17
|
-
This split keeps the simulation usable without `window` or `requestAnimationFrame`. A server process, test, or fixed-step host can call `step()` directly. A browser can inject `requestAnimationFrame` and `cancelAnimationFrame`. The engine does not assume the global browser functions exist.
|
|
18
|
-
|
|
19
|
-
The simulation's update callback receives time in seconds, which makes movement independent of a particular display refresh rate when update logic scales changes by the supplied duration. `step()` makes the duration explicit for reproducible scenarios. The engine does not currently claim to provide a fixed timestep, input buffering, delta clamping, pause semantics, or rollback; applications should make those policies explicit where they matter.
|
|
20
|
-
|
|
21
|
-
The update callback also receives frame metadata as its third argument; the render callback receives state and metadata. Metadata includes `deltaMs`, `timestamp`, and `frame` (and render metadata also includes `deltaSeconds`). `createStore(initialState)` is separate from the game controller: `getState()` reads it, `setState(valueOrUpdater)` replaces it, `update(mutator)` applies a transform, and `subscribe(listener)` returns an unsubscribe function. The game loop and store are not implicitly connected; application code chooses how state flows between them.
|
|
22
|
-
|
|
23
|
-
## Audio
|
|
24
|
-
|
|
25
|
-
`createSound(buffer, audioContext, { volume = 1, maxGain = 4 })` wraps a decoded Web Audio `AudioBuffer` and an `AudioContext`. It returns a sound object with `startPlaying(options?)`. Each playback handle exposes `amplify(number | 'max')`, `stop()`, and its source node as `.source`.
|
|
26
|
-
|
|
27
|
-
Numeric amplification multiplies the initial `volume` and clamps the result between zero and `maxGain`; `'max'` selects the configured maximum. This is only a software gain bound and cannot guarantee protection from clipping, loud speakers, or hearing damage. The sound helper uses browser Web Audio rather than an engine-owned audio backend. The application remains responsible for fetching/decoding assets, managing the context, and complying with browser autoplay restrictions.
|
|
28
|
-
|
|
29
|
-
## Framework integration
|
|
30
|
-
|
|
31
|
-
Frameworks own mount/unmount and view updates. An integration should create the controller at mount time, provide scheduler functions where available, and call `stop()` during teardown. Keep mutable simulation state in the engine and use the framework's rendering mechanism to reflect it. See [the Svelte example](../examples/svelte/Game.svelte) for a minimal pattern.
|
|
32
|
-
|
|
33
|
-
`createCanvas({ document, parent, width, height, context, contextOptions })` creates a canvas element, optionally appends it to `parent`, and returns `{ element, context, resize, destroy }`. The `document` can be injected for alternate DOM environments; otherwise it reads `globalThis.document` when called. Multiple canvas instances are independent surfaces, and a shared store can coordinate the data they render.
|
|
34
|
-
|
|
35
|
-
## Module boundaries
|
|
36
|
-
|
|
37
|
-
The public entry point is `src/index.ts`; game-loop behavior lives in `src/game.ts`, sound in `src/sound.ts`, shared state in `src/store.ts`, and canvas surfaces in `src/canvas.ts`. Keeping the modules focused leaves input, asset loading, and UI choices to consumers.
|
package/docs/planning.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Planning notes
|
|
2
|
-
|
|
3
|
-
This document records design directions, not a release schedule. The project is inspired by the approachable WoofJS style ([source project](https://github.com/stevekrouse/WoofJS), [website](https://woofjs.com/)), but is an independent implementation and does not promise source or API compatibility. The guiding constraint is to keep the core small and portable while adding features only when they have clear contracts and can be exercised without tying the engine to a particular UI framework.
|
|
4
|
-
|
|
5
|
-
## Current baseline
|
|
6
|
-
|
|
7
|
-
- A host-provided state/update/render game loop.
|
|
8
|
-
- Explicit deterministic stepping via `step(deltaMs)`.
|
|
9
|
-
- Optional host-provided frame scheduling via `start()` and `stop()`.
|
|
10
|
-
- A basic observable store and independent canvas surface helper.
|
|
11
|
-
- Optional keyboard state tracking and axis-aligned rectangle collision.
|
|
12
|
-
- Web Audio playback helper with bounded amplification and explicit stop control.
|
|
13
|
-
|
|
14
|
-
## Candidate areas to explore
|
|
15
|
-
|
|
16
|
-
1. **Richer shared views:** the current store and canvas helpers are basic building blocks. Explore coordination for multiple canvases or components that share state and utilities, with clearly defined ownership and update ordering.
|
|
17
|
-
2. **UI component mappings:** explore mapping familiar UI components to game behavior without making a specific framework mandatory.
|
|
18
|
-
3. **Input adapters:** extend the optional keyboard helper with touch or gamepad support if examples show a need.
|
|
19
|
-
4. **Timing policy:** consider opt-in delta clamping or fixed-step accumulation, preserving the current explicit step behavior.
|
|
20
|
-
5. **Optional compilation:** evaluate whether compilation meaningfully helps users author games, and define a build step only if it remains optional and has a stable input/output contract.
|
|
21
|
-
6. **Lifecycle and examples:** document teardown, browser audio activation, and integration with common frameworks.
|
|
22
|
-
7. **Testability and assets:** retain deterministic stepping; consider loading/decoding helpers only after deciding whether they belong in core or adapters.
|
|
23
|
-
|
|
24
|
-
The richer shared-view coordination, component-mapping, and compilation ideas are roadmap questions. The current release provides basic store and canvas helpers but does not implement those higher-level systems.
|
|
25
|
-
|
|
26
|
-
## Decisions to preserve
|
|
27
|
-
|
|
28
|
-
- Core game logic should be callable in Node and browser environments.
|
|
29
|
-
- Browser facilities should be injected or isolated behind optional adapters rather than read at module import time.
|
|
30
|
-
- Time units and audio gain bounds should remain explicit in the public API.
|
|
31
|
-
- Avoid framework-specific abstractions in the core package.
|
|
32
|
-
|
|
33
|
-
These candidates need user and maintainer feedback before becoming commitments.
|