Skip to content

Commit 8f827aa

Browse files
authored
Merge pull request #1343 from melonjs/refactor/bootstrap-module
Move boot() to system/bootstrap.ts, auto-bootstrap from Application
2 parents be0f014 + 0e52393 commit 8f827aa

29 files changed

Lines changed: 570 additions & 234 deletions

File tree

packages/examples/src/examples/helloWorld/ExampleHelloWorld.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { game, Text, video } from "melonjs";
1+
import { Application, Text } from "melonjs";
22
import { createExampleComponent } from "../utils";
33

44
export const ExampleHelloWorld = createExampleComponent(() => {
5-
// Initialize the video.
6-
video.init(1218, 562, { parent: "screen", scale: "auto" });
5+
// create a new Application instance
6+
const app = new Application(1218, 562, {
7+
parent: "screen",
8+
scale: "auto",
9+
backgroundColor: "#202020",
10+
});
711

812
// set a gray background color
9-
game.world.backgroundColor.parseCSS("#202020");
13+
app.world.backgroundColor.parseCSS("#202020");
1014

1115
// add a text object in the center of the display
12-
game.world.addChild(
16+
app.world.addChild(
1317
new Text(609, 281, {
1418
font: "Arial",
1519
size: 160,

packages/melonjs/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88
- Tiled: `detectObjectType()` now checks `settings.class` and `settings.name` against the factory registry before falling through to structural detection, enabling class-based dispatch for custom types
99

1010
### Changed
11+
- Application: `new Application(width, height, options)` now auto-calls `boot()` if the engine hasn't been initialized, making it a valid standalone entry point
12+
- Application: `boot()` moved to `system/bootstrap.ts` — decoupled from `index.js`
13+
- Application: `game` singleton decoupled from barrel `index.js` — internal modules no longer import from the barrel
14+
- Application: new `canvas` getter, `resize()`, and `destroy()` convenience methods
15+
- Application: `GAME_INIT` event now passes the Application instance as parameter
16+
- Stage: `onResetEvent(app, ...args)` now receives the Application instance as first parameter, followed by any extra arguments from `state.change()`
1117
- EventEmitter: native context parameter support — `addListener(event, fn, context)` and `addListenerOnce(event, fn, context)` now accept an optional context, eliminating `.bind()` closure overhead and enabling proper `removeListener()` by original function reference
1218
- EventEmitter: `event.on()` and `event.once()` no longer create `.bind()` closures when a context is provided
1319

1420
### Fixed
21+
- Application: `Object.assign(defaultApplicationSettings, options)` mutated the shared defaults object in both `Application.init()` and `video.init()` — creating multiple Application instances would corrupt settings. Fixed with object spread.
22+
- Application: prevent white flash on load by setting a black background on the parent element when no background is defined
1523
- WebGLRenderer: `setBlendMode()` now tracks the `premultipliedAlpha` flag — previously only the mode name was checked, causing incorrect GL blend function when mixing PMA and non-PMA textures with the same blend mode
1624
- TMX: fix crash in `getObjects(false)` when a map contains an empty object group (Container.children lazily initialized)
1725
- EventEmitter: `removeAllListeners()` now correctly clears once-listeners (previously only cleared regular listeners)
1826
- Loader: fix undefined `crossOrigin` variable in script parser, unsafe regex match in video parser, missing error parameter in video/fontface error callbacks, `fetchData` Promise constructor antipattern and silent error swallowing
1927

2028
### Chore
29+
- Converted `index.js` to `index.ts` — no internal modules import from the barrel anymore
2130
- Minimum Node.js version is now 24.0.0 (Node 18/20 EOL, Node 22 in maintenance)
2231
- CI: upgrade to Node.js 24 and pnpm/action-setup v5
2332
- TypeScript: 5.9 → 6.0 (added explicit `rootDir` to all tsconfig.build.json)

packages/melonjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
"lint": "eslint src tests",
8181
"build": "pnpm lint && tsx scripts/build.js && pnpm types",
8282
"dist": "pnpm clean && pnpm lint && pnpm vitest run && pnpm build && pnpm doc && cp ../../README.md .",
83-
"doc": "typedoc src/index.js --tsconfig tsconfig.build.json --readme DOC_README.md --hideGenerator --name 'melonJS' --navigation.includeCategories true --categorizeByGroup false",
84-
"doc:watch": "typedoc src/index.js --tsconfig tsconfig.build.json --readme DOC_README.md --hideGenerator --name 'melonJS' --navigation.includeCategories true --categorizeByGroup false --watch --skipErrorChecking --preserveWatchOutput --logLevel Error",
83+
"doc": "typedoc src/index.ts --tsconfig tsconfig.build.json --readme DOC_README.md --hideGenerator --name 'melonJS' --navigation.includeCategories true --categorizeByGroup false",
84+
"doc:watch": "typedoc src/index.ts --tsconfig tsconfig.build.json --readme DOC_README.md --hideGenerator --name 'melonJS' --navigation.includeCategories true --categorizeByGroup false --watch --skipErrorChecking --preserveWatchOutput --logLevel Error",
8585
"serve": "serve docs",
8686
"prepublishOnly": "pnpm dist",
8787
"clean": "tsx scripts/clean.ts",

packages/melonjs/scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const banner = [
1212
].join("\n");
1313

1414
const buildOptions = {
15-
entryPoints: ["src/index.js"],
15+
entryPoints: ["src/index.ts"],
1616
loader: {
1717
".png": "dataurl",
1818
".vert": "text",

0 commit comments

Comments
 (0)