@scenoco-three/unity 0.7.0 → 0.8.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/dist/export.js +29 -2
- package/package.json +3 -3
package/dist/export.js
CHANGED
|
@@ -81,6 +81,9 @@ export async function snapshotProject(root, options = {}) {
|
|
|
81
81
|
plugins: [page(root, gameModules(root))],
|
|
82
82
|
// Not pre-bundled: the snapshot and the scenes must share one copy of core's JSX runtime.
|
|
83
83
|
optimizeDeps: { exclude: ['@scenoco-three/core'] },
|
|
84
|
+
// Its own optimizer cache: a dev server or the observer on the same project re-bundling the
|
|
85
|
+
// shared one mid-load answers this page's imports with 504 "Outdated Optimize Dep".
|
|
86
|
+
cacheDir: join(root, 'node_modules', '.vite-scenoco-unity'),
|
|
84
87
|
server: { port: 0, hmr: false },
|
|
85
88
|
});
|
|
86
89
|
await server.listen();
|
|
@@ -90,8 +93,16 @@ export async function snapshotProject(root, options = {}) {
|
|
|
90
93
|
const errors = [];
|
|
91
94
|
tab.on('pageerror', (e) => errors.push(e.message));
|
|
92
95
|
tab.on('console', (m) => m.type() === 'error' && errors.push(m.text()));
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
// A cold cache can still be re-bundled while the page loads, when Vite finds a dependency its scan
|
|
97
|
+
// missed. Vite's HMR client reloads the page then; with HMR off, this does.
|
|
98
|
+
const url = new URL(PAGE, server.resolvedUrls.local[0]).href;
|
|
99
|
+
for (let attempt = 1;; attempt++) {
|
|
100
|
+
errors.length = 0;
|
|
101
|
+
await tab.goto(url);
|
|
102
|
+
if ((await pageLoaded(tab)) === 'settled' || attempt === 3)
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
await tab.waitForFunction(() => '__scenocoSnapshot' in window, null, { timeout: 1_000 }).catch(async () => {
|
|
95
106
|
// The server's own reason, which the browser reports only as a status code.
|
|
96
107
|
const reason = await tab.evaluate((url) => fetch(url).then((r) => (r.ok ? '' : r.text())), `/@id/${ENTRY}`).catch(() => '');
|
|
97
108
|
const missing = /snapshot/.test(reason) ? ' — the project\'s @scenoco-three/core is older than this exporter: update it.' : '';
|
|
@@ -109,6 +120,22 @@ export async function snapshotProject(root, options = {}) {
|
|
|
109
120
|
await server.close();
|
|
110
121
|
}
|
|
111
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Wait for the export page: 'outdated' as soon as Vite answers one of its imports 504 — its optimizer
|
|
125
|
+
* re-bundled underneath, and only a reload picks that up — and 'settled' once it loaded or gave up.
|
|
126
|
+
*/
|
|
127
|
+
function pageLoaded(tab) {
|
|
128
|
+
return new Promise((done) => {
|
|
129
|
+
const onResponse = (response) => response.status() === 504 && finish('outdated');
|
|
130
|
+
const finish = (result) => {
|
|
131
|
+
tab.off('response', onResponse);
|
|
132
|
+
done(result);
|
|
133
|
+
};
|
|
134
|
+
tab.on('response', onResponse);
|
|
135
|
+
// A page that never loads is reported by the caller, with the server's reason.
|
|
136
|
+
tab.waitForFunction(() => '__scenocoSnapshot' in window, null, { timeout: 30_000 }).then(() => finish('settled'), () => finish('settled'));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
112
139
|
/** Convert a snapshot and write it into the Unity project: data for the importer, the importer, C# stubs, textures. */
|
|
113
140
|
export function writeUnity(snap, project, root) {
|
|
114
141
|
project = resolve(project);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenoco-three/unity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Export a SceNoCo game's prefabs, scenes, meshes and materials into a Unity project: nested prefabs, shared materials, behaviours as MonoBehaviours with their fields wired.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"directory": "packages/unity"
|
|
28
28
|
},
|
|
29
29
|
"bin": {
|
|
30
|
-
"scenoco-unity": "
|
|
30
|
+
"scenoco-unity": "dist/cli.js"
|
|
31
31
|
},
|
|
32
32
|
"main": "./dist/export.js",
|
|
33
33
|
"types": "./dist/export.d.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"playwright-core": "^1.62.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@scenoco-three/core": "0.
|
|
56
|
+
"@scenoco-three/core": "0.8.0",
|
|
57
57
|
"vite": ">=6"
|
|
58
58
|
}
|
|
59
59
|
}
|