@threenative/runtime-native 0.2.0 → 0.3.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/README.md +63 -0
- package/android/README.md +2 -2
- package/android/app/build.gradle.kts +166 -29
- package/android/app/src/main/AndroidManifest.xml +8 -1
- package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +179 -2
- package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +261 -0
- package/android/app/src/main/res/values/branding.xml +12 -0
- package/android/app/src/main/res/values/themes.xml +2 -0
- package/package.json +21 -8
- package/scripts/asset-preflight.mjs +442 -0
- package/scripts/bundle.mjs +167 -44
- package/scripts/device-preflight.mjs +456 -0
- package/scripts/install-prebuilt.mjs +80 -11
- package/scripts/package-android.mjs +400 -20
- package/scripts/package-desktop.mjs +83 -6
- package/scripts/package-ios.mjs +205 -22
- package/scripts/physical-device-evidence.mjs +644 -0
- package/scripts/production-evidence.mjs +1 -1
- package/scripts/profile-production.mjs +54 -23
- package/scripts/qualify-physical-mobile.mjs +1327 -0
- package/scripts/verify-starter-desktop.mjs +6 -3
- package/scripts/xvfb.sh +63 -0
|
@@ -16,11 +16,15 @@ import {
|
|
|
16
16
|
} from 'node:fs';
|
|
17
17
|
import { tmpdir } from 'node:os';
|
|
18
18
|
import { dirname, join, resolve } from 'node:path';
|
|
19
|
-
import { pathToFileURL } from 'node:url';
|
|
19
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
20
|
+
|
|
21
|
+
import { assertNativeAssetsDecodable, deriveDesktopWebpSupport } from './asset-preflight.mjs';
|
|
22
|
+
|
|
23
|
+
const runtimeRoot = resolve(fileURLToPath(new URL('..', import.meta.url)));
|
|
20
24
|
|
|
21
25
|
export const DEFAULT_DESKTOP_CONFIG = {
|
|
22
26
|
app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.0', build: 1 },
|
|
23
|
-
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false },
|
|
27
|
+
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
|
|
24
28
|
window: { title: 'ThreeNative', width: 1280, height: 720, resizable: true },
|
|
25
29
|
};
|
|
26
30
|
|
|
@@ -38,8 +42,8 @@ export function parseArgs(args) {
|
|
|
38
42
|
for (let index = 0; index < args.length; index += 2) {
|
|
39
43
|
const flag = args[index];
|
|
40
44
|
const value = args[index + 1];
|
|
41
|
-
if (!['--assets', '--bundle', '--config', '--output', '--runtime'].includes(flag) || !value) {
|
|
42
|
-
throw new Error('Usage: package-desktop.mjs --bundle FILE --runtime FILE --output FILE [--assets DIR] [--config FILE]');
|
|
45
|
+
if (!['--assets', '--bundle', '--config', '--output', '--runtime', '--ui'].includes(flag) || !value) {
|
|
46
|
+
throw new Error('Usage: package-desktop.mjs --bundle FILE --runtime FILE --output FILE [--assets DIR] [--ui DIR] [--config FILE]');
|
|
43
47
|
}
|
|
44
48
|
options[flag.slice(2)] = resolve(value);
|
|
45
49
|
}
|
|
@@ -69,6 +73,16 @@ export function packageDesktop(options) {
|
|
|
69
73
|
staging,
|
|
70
74
|
options.config === undefined ? undefined : readConfig(options.config),
|
|
71
75
|
);
|
|
76
|
+
// The UI bundle sits beside the executable rather than inside it. Desktop compiles to one
|
|
77
|
+
// file, but the overlay's web view reads its page from a real path — that is what gives it a
|
|
78
|
+
// real origin, the way `WebViewAssetLoader` does on Android, and it is the difference between
|
|
79
|
+
// `fetch` behaving as it does on web and not. A game with the native UI renderer ships neither
|
|
80
|
+
// the directory nor an overlay.
|
|
81
|
+
stageDesktopUi(
|
|
82
|
+
options.ui,
|
|
83
|
+
options.config === undefined ? 'native' : readConfig(options.config).ui?.renderer ?? 'native',
|
|
84
|
+
join(dirname(output), 'ui'),
|
|
85
|
+
);
|
|
72
86
|
const args = [
|
|
73
87
|
'compile',
|
|
74
88
|
stagedEntry,
|
|
@@ -91,12 +105,60 @@ export function packageDesktop(options) {
|
|
|
91
105
|
return output;
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Stage the built UI bundle beside the desktop executable.
|
|
110
|
+
*
|
|
111
|
+
* Fails closed both ways, for the same reasons the Android packager does: a `web` game with no
|
|
112
|
+
* built UI would install, launch and show nothing over a working game, and a `native` game must
|
|
113
|
+
* ship no bundle at all.
|
|
114
|
+
*/
|
|
115
|
+
export function stageDesktopUi(ui, renderer, destination) {
|
|
116
|
+
rmSync(destination, { force: true, recursive: true });
|
|
117
|
+
if (renderer !== 'web') {
|
|
118
|
+
if (ui) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`TN_UI_BUNDLE_UNEXPECTED: a UI bundle was staged for a game whose ui.renderer is '${renderer}'. ` +
|
|
121
|
+
'The native renderer ships no web view; remove the bundle or set ui.renderer to "web".',
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
if (!ui || !existsSync(ui)) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`TN_UI_BUNDLE_MISSING: ui.renderer is "web" but no built UI was found at ${ui ?? '(not provided)'}. ` +
|
|
129
|
+
'Build the UI before packaging, or set ui.renderer to "native".',
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (!statSync(ui).isDirectory()) throw new Error(`TN_UI_BUNDLE_MISSING: not a directory: ${ui}`);
|
|
133
|
+
if (!existsSync(join(ui, 'index.html'))) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`TN_UI_BUNDLE_MISSING: ${ui} has no index.html, which is the page the overlay loads.`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
mkdirSync(destination, { recursive: true });
|
|
139
|
+
cpSync(ui, destination, { recursive: true });
|
|
140
|
+
return readdirSync(destination);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function stageDesktopFiles(
|
|
144
|
+
bundle,
|
|
145
|
+
assets,
|
|
146
|
+
staging,
|
|
147
|
+
config = undefined,
|
|
148
|
+
runtimeSource = runtimeRoot,
|
|
149
|
+
) {
|
|
95
150
|
mkdirSync(staging, { recursive: true });
|
|
96
151
|
if (assets && existsSync(assets)) {
|
|
97
152
|
if (!statSync(assets).isDirectory()) {
|
|
98
153
|
throw new Error(`Desktop assets path is not a directory: ${assets}`);
|
|
99
154
|
}
|
|
155
|
+
// Desktop ran no preflight at all, so an asset the runtime cannot decode reached the same
|
|
156
|
+
// rejected `decodeAudioData` that black-screened an APK — with the packager having already
|
|
157
|
+
// read the bytes on its way past. Same gate, desktop's own derived capabilities.
|
|
158
|
+
assertNativeAssetsDecodable(assets, {
|
|
159
|
+
target: 'desktop',
|
|
160
|
+
capabilities: { webp: deriveDesktopWebpSupport(runtimeSource) },
|
|
161
|
+
});
|
|
100
162
|
for (const entry of readdirSync(assets)) {
|
|
101
163
|
if (entry === '.threenative') {
|
|
102
164
|
throw new Error('TN_NATIVE_ASSET_RESERVED_PATH: public/.threenative is reserved.');
|
|
@@ -108,7 +170,22 @@ export function stageDesktopFiles(bundle, assets, staging, config = undefined) {
|
|
|
108
170
|
mkdirSync(dirname(entry), { recursive: true });
|
|
109
171
|
copyFileSync(bundle, entry);
|
|
110
172
|
if (config !== undefined) {
|
|
111
|
-
|
|
173
|
+
const icon = config.app?.icon ?? config.app?.icons?.android?.foreground;
|
|
174
|
+
const packaged = { ...config, app: { ...(config.app ?? {}) } };
|
|
175
|
+
// Flattened deliberately. The embedded config is read by a small scanner in the C++ host, and
|
|
176
|
+
// `renderer` already exists at the top level as the WebGPU preference — a nested lookup for a
|
|
177
|
+
// second `renderer` would find the wrong one. Anything but "web" is the native renderer.
|
|
178
|
+
packaged.uiRenderer = config.ui?.renderer === 'web' ? 'web' : 'native';
|
|
179
|
+
packaged.maxFps = config.display?.maxFps ?? 60;
|
|
180
|
+
if (icon !== undefined) {
|
|
181
|
+
if (!existsSync(icon) || !statSync(icon).isFile()) {
|
|
182
|
+
throw new Error(`TN_CONFIG_BRAND_DESKTOP_MISSING: app icon does not exist: ${icon}`);
|
|
183
|
+
}
|
|
184
|
+
const stagedIcon = join(staging, '.threenative', 'app-icon.png');
|
|
185
|
+
copyFileSync(icon, stagedIcon);
|
|
186
|
+
packaged.app.icon = '.threenative/app-icon.png';
|
|
187
|
+
}
|
|
188
|
+
writeFileSync(join(staging, '.threenative', 'config.json'), `${JSON.stringify(packaged, null, 2)}\n`);
|
|
112
189
|
}
|
|
113
190
|
return entry;
|
|
114
191
|
}
|
package/scripts/package-ios.mjs
CHANGED
|
@@ -17,12 +17,14 @@ import { tmpdir } from 'node:os';
|
|
|
17
17
|
import { basename, dirname, join, posix, resolve } from 'node:path';
|
|
18
18
|
import { fileURLToPath } from 'node:url';
|
|
19
19
|
import { spawnSync } from 'node:child_process';
|
|
20
|
+
import { assertNativeAssetsDecodable, deriveIosWebpSupport } from './asset-preflight.mjs';
|
|
20
21
|
import { downloadReleaseArtifact } from './install-prebuilt.mjs';
|
|
22
|
+
import { PNG } from 'pngjs';
|
|
21
23
|
|
|
22
24
|
export const NATIVE_ORIENTATIONS = ['landscape', 'portrait', 'sensor'];
|
|
23
25
|
export const DEFAULT_IOS_CONFIG = {
|
|
24
26
|
app: { id: 'com.threenative.game', name: 'ThreeNative', version: '0.1.13', build: 1 },
|
|
25
|
-
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false },
|
|
27
|
+
display: { orientation: 'landscape', fullscreen: true, keepScreenOn: false, maxFps: 60 },
|
|
26
28
|
window: { title: 'ThreeNative', width: 1280, height: 720, resizable: true },
|
|
27
29
|
};
|
|
28
30
|
const IOS_ORIENTATIONS = {
|
|
@@ -41,6 +43,7 @@ function configValue(value, orientation) {
|
|
|
41
43
|
const app = source.app && typeof source.app === 'object' ? source.app : {};
|
|
42
44
|
const display = source.display && typeof source.display === 'object' ? source.display : {};
|
|
43
45
|
const window = source.window && typeof source.window === 'object' ? source.window : {};
|
|
46
|
+
const bootSplash = source.bootSplash && typeof source.bootSplash === 'object' ? source.bootSplash : {};
|
|
44
47
|
return {
|
|
45
48
|
app: { ...DEFAULT_IOS_CONFIG.app, ...app },
|
|
46
49
|
display: {
|
|
@@ -49,6 +52,7 @@ function configValue(value, orientation) {
|
|
|
49
52
|
orientation: orientation ?? display.orientation ?? DEFAULT_IOS_CONFIG.display.orientation,
|
|
50
53
|
},
|
|
51
54
|
window: { ...DEFAULT_IOS_CONFIG.window, ...window },
|
|
55
|
+
...(source.bootSplash === undefined ? {} : { bootSplash: { ...bootSplash } }),
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -69,21 +73,35 @@ function plistKey(source, key, value) {
|
|
|
69
73
|
const rendered = ` <key>${key}</key>\n <string>${xmlEscape(value)}</string>`;
|
|
70
74
|
const pattern = new RegExp(`\\s*<key>${key}</key>\\s*<(?:string|true|false)>[\\s\\S]*?</(?:string|true|false)>`, 'u');
|
|
71
75
|
if (pattern.test(source)) return source.replace(pattern, `\n${rendered}`);
|
|
72
|
-
return source.replace(/\s*<\/dict>/u, `\n${rendered}\n</dict>`);
|
|
76
|
+
return source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
function plistBoolean(source, key, value) {
|
|
76
80
|
const rendered = ` <key>${key}</key>\n <${value ? 'true' : 'false'}/>`;
|
|
77
81
|
const pattern = new RegExp(`\\s*<key>${key}</key>\\s*<(?:true|false)\\s*/?>`, 'u');
|
|
78
82
|
if (pattern.test(source)) return source.replace(pattern, `\n${rendered}`);
|
|
79
|
-
return source.replace(/\s*<\/dict>/u, `\n${rendered}\n</dict>`);
|
|
83
|
+
return source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
function plistInteger(source, key, value) {
|
|
83
87
|
const rendered = ` <key>${key}</key>\n <integer>${value}</integer>`;
|
|
84
88
|
const pattern = new RegExp(`\\s*<key>${key}</key>\\s*<integer>[\\s\\S]*?</integer>`, 'u');
|
|
85
89
|
if (pattern.test(source)) return source.replace(pattern, `\n${rendered}`);
|
|
86
|
-
return source.replace(/\s*<\/dict>/u, `\n${rendered}\n</dict>`);
|
|
90
|
+
return source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function plistLaunchScreen(source, config) {
|
|
94
|
+
const image = config.bootSplash?.image === undefined ? undefined : 'LaunchImage';
|
|
95
|
+
const inner = [
|
|
96
|
+
' <key>UIColorName</key>',
|
|
97
|
+
' <string>TNLaunchBackground</string>',
|
|
98
|
+
...(image === undefined ? [] : [' <key>UIImageName</key>', ` <string>${image}</string>`]),
|
|
99
|
+
].join('\n');
|
|
100
|
+
const rendered = ` <key>UILaunchScreen</key>\n <dict>\n${inner}\n </dict>`;
|
|
101
|
+
const pattern = /\s*<key>UILaunchScreen<\/key>\s*<dict>[\s\S]*?<\/dict>/u;
|
|
102
|
+
return pattern.test(source)
|
|
103
|
+
? source.replace(pattern, `\n${rendered}`)
|
|
104
|
+
: source.replace(/\s*<\/dict>\s*<\/plist>/u, `\n${rendered}\n</dict>\n</plist>`);
|
|
87
105
|
}
|
|
88
106
|
|
|
89
107
|
function orientationValue(value = 'landscape') {
|
|
@@ -111,12 +129,15 @@ export function renderIosInfoPlist(source, orientation = 'landscape') {
|
|
|
111
129
|
rendered = plistKey(rendered, 'CFBundleVersion', config.app.build);
|
|
112
130
|
rendered = plistBoolean(rendered, 'TNFullscreen', config.display.fullscreen);
|
|
113
131
|
rendered = plistBoolean(rendered, 'TNKeepScreenOn', config.display.keepScreenOn);
|
|
132
|
+
rendered = plistInteger(rendered, 'TNMaxFps', config.display.maxFps);
|
|
114
133
|
rendered = plistKey(rendered, 'TNWindowTitle', config.window.title);
|
|
115
134
|
rendered = plistInteger(rendered, 'TNWindowWidth', config.window.width);
|
|
116
135
|
rendered = plistInteger(rendered, 'TNWindowHeight', config.window.height);
|
|
117
136
|
rendered = plistBoolean(rendered, 'TNWindowResizable', config.window.resizable);
|
|
118
|
-
if (config.app.icon !== undefined
|
|
119
|
-
|
|
137
|
+
if (config.app.icon !== undefined || config.app.icons?.ios !== undefined) {
|
|
138
|
+
rendered = plistKey(rendered, 'CFBundleIconName', 'AppIcon');
|
|
139
|
+
}
|
|
140
|
+
return plistLaunchScreen(rendered, config);
|
|
120
141
|
}
|
|
121
142
|
|
|
122
143
|
function argumentAfter(args, flag) {
|
|
@@ -159,15 +180,15 @@ function findApp(directory) {
|
|
|
159
180
|
return undefined;
|
|
160
181
|
}
|
|
161
182
|
|
|
162
|
-
function
|
|
183
|
+
function compileIosAssets(catalog, output, includeAppIcon = false) {
|
|
184
|
+
const iconArguments = includeAppIcon ? ['--app-icon', 'AppIcon'] : [];
|
|
163
185
|
const result = spawnSync(
|
|
164
186
|
'xcrun',
|
|
165
187
|
[
|
|
166
188
|
'actool',
|
|
167
189
|
'--compile',
|
|
168
190
|
output,
|
|
169
|
-
|
|
170
|
-
'AppIcon',
|
|
191
|
+
...iconArguments,
|
|
171
192
|
'--platform',
|
|
172
193
|
'iphonesimulator',
|
|
173
194
|
'--minimum-deployment-target',
|
|
@@ -192,10 +213,65 @@ function compileIosIcon(catalog, output) {
|
|
|
192
213
|
}
|
|
193
214
|
}
|
|
194
215
|
|
|
195
|
-
function
|
|
216
|
+
function compileIosIcon(catalog, output) {
|
|
217
|
+
return compileIosAssets(catalog, output, true);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function assertIosIconSource(icon, label) {
|
|
221
|
+
let image;
|
|
222
|
+
try {
|
|
223
|
+
image = PNG.sync.read(readFileSync(icon));
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`TN_CONFIG_ICON_INVALID: ${label} is not a valid PNG file: ${icon} (${error instanceof Error ? error.message : String(error)})`,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (image.width !== 1024 || image.height !== 1024) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`TN_CONFIG_ICON_DIMENSIONS_INVALID: ${label} must be 1024x1024 for iOS AppIcon metadata; received ${image.width}x${image.height}: ${icon}`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function colorComponents(value) {
|
|
237
|
+
const hex = /^#([0-9a-f]{6})$/iu.exec(value ?? '')?.[1] ?? '000000';
|
|
238
|
+
return {
|
|
239
|
+
blue: hex.slice(4, 6),
|
|
240
|
+
green: hex.slice(2, 4),
|
|
241
|
+
red: hex.slice(0, 2),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function writeLaunchColor(catalog, value) {
|
|
246
|
+
const colorset = join(catalog, 'LaunchBackground.colorset');
|
|
247
|
+
mkdirSync(colorset, { recursive: true });
|
|
248
|
+
const components = colorComponents(value);
|
|
249
|
+
writeFileSync(
|
|
250
|
+
join(colorset, 'Contents.json'),
|
|
251
|
+
`${JSON.stringify(
|
|
252
|
+
{
|
|
253
|
+
colors: [
|
|
254
|
+
{
|
|
255
|
+
color: {
|
|
256
|
+
'color-space': 'srgb',
|
|
257
|
+
components: { alpha: '1.000', ...components },
|
|
258
|
+
},
|
|
259
|
+
idiom: 'universal',
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
info: { author: 'xcode', version: 1 },
|
|
263
|
+
},
|
|
264
|
+
null,
|
|
265
|
+
2,
|
|
266
|
+
)}\n`,
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function stageIosIcon(output, icon, compileIcon = compileIosIcon, options = {}) {
|
|
196
271
|
if (!existsSync(icon) || !statSync(icon).isFile()) {
|
|
197
272
|
throw new Error(`TN_CONFIG_ICON_MISSING: app.icon does not exist: ${icon}`);
|
|
198
273
|
}
|
|
274
|
+
assertIosIconSource(icon, 'app.icon');
|
|
199
275
|
const temporary = mkdtempSync(join(tmpdir(), 'threenative-ios-icon-'));
|
|
200
276
|
try {
|
|
201
277
|
const catalog = join(temporary, 'Assets.xcassets');
|
|
@@ -204,19 +280,39 @@ function stageIosIcon(output, icon, compileIcon = compileIosIcon) {
|
|
|
204
280
|
mkdirSync(appIcon, { recursive: true });
|
|
205
281
|
mkdirSync(compiled, { recursive: true });
|
|
206
282
|
copyFileSync(icon, join(appIcon, 'AppIcon-1024.png'));
|
|
283
|
+
const appearances = options.variants ?? {};
|
|
284
|
+
const images = [
|
|
285
|
+
{
|
|
286
|
+
filename: 'AppIcon-1024.png',
|
|
287
|
+
idiom: 'universal',
|
|
288
|
+
platform: 'ios',
|
|
289
|
+
scale: '1x',
|
|
290
|
+
size: '1024x1024',
|
|
291
|
+
},
|
|
292
|
+
];
|
|
293
|
+
for (const [appearance, source] of [['dark', appearances.dark], ['tinted', appearances.tinted]]) {
|
|
294
|
+
if (source === undefined) continue;
|
|
295
|
+
if (!existsSync(source) || !statSync(source).isFile()) {
|
|
296
|
+
throw new Error(`TN_CONFIG_BRAND_IOS_${appearance.toUpperCase()}_MISSING: ${source}`);
|
|
297
|
+
}
|
|
298
|
+
assertIosIconSource(source, `app.icons.ios.${appearance}`);
|
|
299
|
+
const filename = `AppIcon-1024-${appearance}.png`;
|
|
300
|
+
copyFileSync(source, join(appIcon, filename));
|
|
301
|
+
images.push({
|
|
302
|
+
appearances: [{ appearance: 'luminosity', value: appearance }],
|
|
303
|
+
filename,
|
|
304
|
+
idiom: 'universal',
|
|
305
|
+
platform: 'ios',
|
|
306
|
+
scale: '1x',
|
|
307
|
+
size: '1024x1024',
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
writeLaunchColor(catalog, options.backgroundColor ?? '#000000');
|
|
207
311
|
writeFileSync(
|
|
208
312
|
join(appIcon, 'Contents.json'),
|
|
209
313
|
`${JSON.stringify(
|
|
210
314
|
{
|
|
211
|
-
images
|
|
212
|
-
{
|
|
213
|
-
idiom: 'universal',
|
|
214
|
-
platform: 'ios',
|
|
215
|
-
size: '1024x1024',
|
|
216
|
-
scale: '1x',
|
|
217
|
-
filename: 'AppIcon-1024.png',
|
|
218
|
-
},
|
|
219
|
-
],
|
|
315
|
+
images,
|
|
220
316
|
info: { author: 'xcode', version: 1 },
|
|
221
317
|
},
|
|
222
318
|
null,
|
|
@@ -235,14 +331,71 @@ function stageIosIcon(output, icon, compileIcon = compileIosIcon) {
|
|
|
235
331
|
}
|
|
236
332
|
}
|
|
237
333
|
|
|
334
|
+
function stageIosLaunchAssets(output, backgroundColor, compileAssets = compileIosAssets) {
|
|
335
|
+
const temporary = mkdtempSync(join(tmpdir(), 'threenative-ios-launch-'));
|
|
336
|
+
try {
|
|
337
|
+
const catalog = join(temporary, 'Assets.xcassets');
|
|
338
|
+
const compiled = join(temporary, 'compiled');
|
|
339
|
+
mkdirSync(compiled, { recursive: true });
|
|
340
|
+
writeLaunchColor(catalog, backgroundColor);
|
|
341
|
+
compileAssets(catalog, compiled);
|
|
342
|
+
const assetsCar = join(compiled, 'Assets.car');
|
|
343
|
+
if (!existsSync(assetsCar) || !statSync(assetsCar).isFile() || statSync(assetsCar).size === 0) {
|
|
344
|
+
throw new Error('TN_IOS_LAUNCH_COMPILE_FAILED: actool did not produce a usable Assets.car.');
|
|
345
|
+
}
|
|
346
|
+
copyFileSync(assetsCar, join(output, 'Assets.car'));
|
|
347
|
+
} finally {
|
|
348
|
+
rmSync(temporary, { force: true, recursive: true });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Stage the built UI bundle into the app bundle, where `WKURLSchemeHandler` serves it.
|
|
354
|
+
*
|
|
355
|
+
* Same two refusals as Android and desktop, because the same two mistakes are possible: a `web`
|
|
356
|
+
* game with no built UI would launch and show nothing over a working game, and a `native` game must
|
|
357
|
+
* carry no bundle at all.
|
|
358
|
+
*
|
|
359
|
+
* **The iOS host that would read this has never run.** See `ios/ui_overlay_ios.mm`.
|
|
360
|
+
*/
|
|
361
|
+
export function stageIosUi(ui, renderer, destination) {
|
|
362
|
+
rmSync(destination, { force: true, recursive: true });
|
|
363
|
+
if (renderer !== 'web') {
|
|
364
|
+
if (ui) {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`TN_UI_BUNDLE_UNEXPECTED: a UI bundle was staged for a game whose ui.renderer is '${renderer}'. ` +
|
|
367
|
+
'The native renderer ships no web view; remove the bundle or set ui.renderer to "web".',
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
372
|
+
if (!ui || !existsSync(ui)) {
|
|
373
|
+
throw new Error(
|
|
374
|
+
`TN_UI_BUNDLE_MISSING: ui.renderer is "web" but no built UI was found at ${ui ?? '(not provided)'}. ` +
|
|
375
|
+
'Build the UI before packaging, or set ui.renderer to "native".',
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
if (!statSync(ui).isDirectory()) throw new Error(`TN_UI_BUNDLE_MISSING: not a directory: ${ui}`);
|
|
379
|
+
if (!existsSync(join(ui, 'index.html'))) {
|
|
380
|
+
throw new Error(
|
|
381
|
+
`TN_UI_BUNDLE_MISSING: ${ui} has no index.html, which is the page the overlay loads.`,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
mkdirSync(destination, { recursive: true });
|
|
385
|
+
cpSync(ui, destination, { recursive: true });
|
|
386
|
+
return listFiles(destination);
|
|
387
|
+
}
|
|
388
|
+
|
|
238
389
|
export function stageIosSimulatorApp({
|
|
239
390
|
assets,
|
|
240
391
|
bundle,
|
|
392
|
+
ui = undefined,
|
|
241
393
|
output,
|
|
242
394
|
templateApp,
|
|
243
395
|
orientation = undefined,
|
|
244
396
|
config = undefined,
|
|
245
397
|
compileIcon = compileIosIcon,
|
|
398
|
+
compileAssets = compileIosAssets,
|
|
246
399
|
}) {
|
|
247
400
|
const declared = configValue(config, orientation);
|
|
248
401
|
const declaredOrientation = orientationValue(declared.display.orientation);
|
|
@@ -264,14 +417,41 @@ export function stageIosSimulatorApp({
|
|
|
264
417
|
const game = join(output, 'game');
|
|
265
418
|
rmSync(game, { force: true, recursive: true });
|
|
266
419
|
mkdirSync(game, { recursive: true });
|
|
420
|
+
stageIosUi(ui, declared.ui?.renderer === 'web' ? 'web' : 'native', join(output, 'ui'));
|
|
267
421
|
const plist = join(output, 'Info.plist');
|
|
268
422
|
writeFileSync(plist, renderIosInfoPlist(readFileSync(plist, 'utf8'), declared));
|
|
269
|
-
|
|
423
|
+
const iosVariants = declared.app.icons?.ios ?? {};
|
|
424
|
+
const icon = declared.app.icon ?? iosVariants.dark ?? iosVariants.tinted;
|
|
425
|
+
if (icon !== undefined) {
|
|
426
|
+
stageIosIcon(output, icon, compileIcon, {
|
|
427
|
+
backgroundColor: declared.bootSplash?.backgroundColor,
|
|
428
|
+
variants: iosVariants,
|
|
429
|
+
});
|
|
430
|
+
} else if (declared.bootSplash !== undefined) {
|
|
431
|
+
stageIosLaunchAssets(
|
|
432
|
+
output,
|
|
433
|
+
declared.bootSplash.backgroundColor ?? '#000000',
|
|
434
|
+
compileAssets,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (declared.bootSplash?.image !== undefined) {
|
|
438
|
+
if (!existsSync(declared.bootSplash.image) || !statSync(declared.bootSplash.image).isFile()) {
|
|
439
|
+
throw new Error(`TN_CONFIG_BRAND_SPLASH_MISSING: ${declared.bootSplash.image}`);
|
|
440
|
+
}
|
|
441
|
+
copyFileSync(declared.bootSplash.image, join(output, 'LaunchImage.png'));
|
|
442
|
+
}
|
|
270
443
|
let assetFiles = [];
|
|
271
444
|
if (assets && existsSync(assets)) {
|
|
272
445
|
if (!statSync(assets).isDirectory()) {
|
|
273
446
|
throw new Error(`iOS assets path is not a directory: ${assets}`);
|
|
274
447
|
}
|
|
448
|
+
// iOS ran no preflight at all. Its capability set is not Android's: `CMakeLists.txt` excludes
|
|
449
|
+
// IOS from every libwebp branch, so a WebP texture that packages for Android must still be
|
|
450
|
+
// refused here, while the audio answer is the same on every native target.
|
|
451
|
+
assertNativeAssetsDecodable(assets, {
|
|
452
|
+
target: 'ios',
|
|
453
|
+
capabilities: { webp: deriveIosWebpSupport() },
|
|
454
|
+
});
|
|
275
455
|
assetFiles = listFiles(assets);
|
|
276
456
|
for (const file of assetFiles) {
|
|
277
457
|
const staged = join(game, file);
|
|
@@ -288,8 +468,10 @@ export function stageIosSimulatorApp({
|
|
|
288
468
|
appName: declared.app.name,
|
|
289
469
|
version: declared.app.version,
|
|
290
470
|
build: declared.app.build,
|
|
291
|
-
...(
|
|
292
|
-
...(
|
|
471
|
+
...(icon === undefined ? {} : { icon }),
|
|
472
|
+
...(icon === undefined ? {} : { iconArtifact: 'Assets.car' }),
|
|
473
|
+
...(declared.bootSplash?.image === undefined ? {} : { launchImage: 'LaunchImage.png' }),
|
|
474
|
+
launchBackground: declared.bootSplash?.backgroundColor ?? '#000000',
|
|
293
475
|
output,
|
|
294
476
|
outputBundleSha256: checksum(join(output, 'native-smoke.js')),
|
|
295
477
|
};
|
|
@@ -355,6 +537,7 @@ export async function packageIosSimulator(options) {
|
|
|
355
537
|
export function parseIosPackageArgs(args) {
|
|
356
538
|
return {
|
|
357
539
|
assets: args.includes('--assets') ? valueAfter(args, '--assets') : undefined,
|
|
540
|
+
ui: args.includes('--ui') ? valueAfter(args, '--ui') : undefined,
|
|
358
541
|
bundle: valueAfter(args, '--bundle'),
|
|
359
542
|
output: valueAfter(args, '--output'),
|
|
360
543
|
config: args.includes('--config') ? valueAfter(args, '--config') : undefined,
|