diff --git a/cli/apple/screenshots.ts b/cli/apple/screenshots.ts index 8f4fd48f..e2286127 100644 --- a/cli/apple/screenshots.ts +++ b/cli/apple/screenshots.ts @@ -1,8 +1,10 @@ // Store screenshots of every locale on the editable App Store version (idempotent: a set whose files already match // by MD5 and order is left alone, otherwise it is emptied and re-uploaded). // storebound apple screenshots [--src store/renders] [--only en-US,tr] [--jobs 4] -// Source per language: //ios69/NN.png (6.9", 1320 x 2868 -> APP_IPHONE_67) and -// ios65/NN.png (6.5", 1284 x 2778 -> APP_IPHONE_65). Up to 10 per set. Apple processes uploads asynchronously; failed +// Source per language: //ios69/NN.png (6.9", 1320 x 2868 -> APP_IPHONE_67), +// ios65/NN.png (6.5", 1284 x 2778 -> APP_IPHONE_65) and, only with apple.ipad, ipad13/NN.png (13" iPad, 2064 x 2752 -> +// APP_IPAD_PRO_3GEN_129: the API has no "13 inch" value, the 13" display set keeps the 3rd gen 12.9" name). Up to 10 +// per set. Apple processes uploads asynchronously; failed // ones are reported at the end. Long: run in the background with a log file. import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; @@ -12,7 +14,17 @@ import { done, log, warn } from '../lib/log'; import { numberedImages } from '../play/images'; import { ascClient, md5, type J } from './asc'; +/** Render size key -> ASC screenshotDisplayType (iPhone sets). */ export const DISPLAY: Record = { ios69: 'APP_IPHONE_67', ios65: 'APP_IPHONE_65' }; +/** 13" iPad set, uploaded only when apple.ipad is true. */ +export const IPAD_DISPLAY: Record = { ipad13: 'APP_IPAD_PRO_3GEN_129' }; + +/** Display sets this project uploads: the iPhone sets, plus the 13" iPad set with apple.ipad. */ +export const displaySets = (apple: { ipad?: boolean } | undefined): Record => ({ ...DISPLAY, ...(apple?.ipad ? IPAD_DISPLAY : {}) }); + +/** Display types `validate` requires on every locale: apple.screenshotTypes, else 6.9" iPhone (+ 13" iPad with ipad). */ +export const requiredDisplayTypes = (apple: { ipad?: boolean; screenshotTypes?: string[] } | undefined): string[] => + apple?.screenshotTypes ?? ['APP_IPHONE_67', ...(apple?.ipad ? ['APP_IPAD_PRO_3GEN_129'] : [])]; export async function run(ctx: Ctx): Promise { const { config, root, resolve } = ctx.loaded; @@ -48,7 +60,7 @@ export async function run(ctx: Ctx): Promise { if (!lang) { warn('apple', `${locale}: no language with apple: "${locale}", skipped`); continue; } tasks.push(async () => { const sets = await c.all(`/v1/appStoreVersionLocalizations/${loc.id}/appScreenshotSets`); - for (const [dir, type] of Object.entries(DISPLAY)) { + for (const [dir, type] of Object.entries(displaySets(config.apple))) { const d = join(src, lang.id, dir); const files = numberedImages(d).filter(f => f.endsWith('.png')).slice(0, 10); if (!existsSync(d) || !files.length) { warn('apple', `${locale}: nothing in ${d}, skipped`); continue; } diff --git a/cli/lib/config.ts b/cli/lib/config.ts index 591012f3..95837531 100644 --- a/cli/lib/config.ts +++ b/cli/lib/config.ts @@ -87,9 +87,11 @@ export interface ShotsConfig { fonts?: { title?: string; body?: string }; scenes: ShotScene[]; feature?: { frame: string; palette?: string | Palette }; - /** Phone screen size of the raw frames in CSS px (default 440 x 902, iPhone 6.9" minus the 54 px status bar). */ - phone?: { w: number; h: number; dpr?: number }; - tablet?: { w: number; h: number; dpr?: number }; + /** Phone screen size of the raw frames in CSS px (default 440 x 902 @3x, iPhone 6.9" minus the 54 px status bar). + * `bar` = status bar height the template draws above the frame (and that capture crops off). */ + phone?: { w: number; h: number; dpr?: number; bar?: number }; + /** Tablet frames: default 1032 x 1352 @2x (13" iPad minus its 24 px bar) with apple.ipad, else 800 x 1240 @2x. */ + tablet?: { w: number; h: number; dpr?: number; bar?: number }; /** Optional capture of raw frames (web build, iOS Simulator, Android emulator / device, or your own folder). */ capture?: ShotsCapture; /** A/B variants: other scene orders / copy, rendered into ///... (`shots render --variant b`). */ @@ -135,6 +137,9 @@ export interface ShotsCapture { args?: string[]; /** Status bar override 9:41, full battery and signal. Default true. */ statusBar?: boolean; + /** After storebound boots a simulator: launch the app once and wait this long before the first shot (a cold + * first launch is much slower than the next ones). Default 8000 ms; 0 turns it off. */ + warmupMs?: number; }; android?: { /** adb serial (adb devices); default: the only device. */ @@ -152,8 +157,10 @@ export interface ShotsCapture { }; /** folder: where your frames are (default shots.frames): ///.png */ folder?: string; - /** Rows cut from the top of a simulator / emulator screenshot (its status bar; the template draws one). Default: about 5.6 % of the height. */ - cropTop?: number; + /** Rows cut from the top of a simulator / emulator screenshot (its status bar; the template draws one). A number for + * every device, or per device class. Default: the frame's bar share of the height (phone 54 / 956 = 162 px on a 6.9" + * iPhone, 13" iPad 24 / 1376 = 48 px). */ + cropTop?: number | { phone?: number; tablet?: number }; shots: Record; } diff --git a/cli/shots/capture.ts b/cli/shots/capture.ts index 766bd8d4..dd89e384 100644 --- a/cli/shots/capture.ts +++ b/cli/shots/capture.ts @@ -7,8 +7,9 @@ // { path, waitFor?: JS expression that turns true, eval?: [JS], delayMs?, device? }; URL = baseUrl + path + // query, "{lang}" replaced. // ios-sim xcrun simctl: boots the simulator (ios.device / ios.devices.tablet), optional install of ios.app, status -// bar 9:41 / full battery / full bars, then per shot: launch ios.bundleId with -AppleLanguages (xx) -// -AppleLocale + ios.args + shot.args, open shot.url (deep link) if given, wait, `simctl io screenshot`. +// bar 9:41 / full battery / full bars, one warm-up launch after a cold boot (ios.warmupMs), then per shot: +// launch ios.bundleId with -AppleLanguages (xx) -AppleLocale + ios.args + shot.args, open shot.url +// (deep link) if given, wait, `simctl io screenshot`. // android-emu adb: demo mode status bar, per-app language (Android 13+, `cmd locale set-app-locales`), then per shot // force-stop + `am start` with shot.url (VIEW intent) or the launch activity + shot.extras, wait, // `exec-out screencap -p`. Works on an emulator or a USB device. Nothing is wiped or rebooted. @@ -16,22 +17,23 @@ // right aspect ratio and resolution. // A simulator storebound booted itself is shut down at the end (--keep-booted keeps it); one that was already running is // left running with its status bar restored. --dry prints the simctl / adb commands without running them. -// Simulator / emulator screenshots are full screen: cropTop rows (the status bar) are cut so the frame fits the template. +// Simulator / emulator screenshots are full screen: cropTop rows (the status bar) are cut so the frame fits the template +// (default per device class from the frame dims: phone 162 px of a 6.9" iPhone, tablet 48 px of a 13" iPad with apple.ipad). // The game needs switches for this: language, scene, fixed seed, no ads / tutorial, freeze. See the store-screenshots skill. import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { homedir } from 'node:os'; import { join } from 'node:path'; import { spawnSync } from 'node:child_process'; -import type { ShipConfig } from '../lib/config'; +import type { ShipConfig, ShotsCapture } from '../lib/config'; import type { Ctx } from '../lib/ctx'; import { need } from '../lib/ctx'; import { done, log, step, warn } from '../lib/log'; import { launch } from './browser'; import { checkFrameFolder } from './check'; import { adbAppLocaleArgs, adbDemoExitArgs, adbDemoModeArgs, adbForceStopArgs, adbInstallArgs, adbScreencapArgs, adbStartArgs, adbStateArgs, adbTarget, - cropArgs, defaultCropTop, fill, pickSimulator, shotsFor, simBootArgs, simBootStatusArgs, simInstallArgs, simLaunchArgs, simOpenUrlArgs, + cropArgs, cropTopFor, fill, pickSimulator, shotsFor, simBootArgs, simBootStatusArgs, simInstallArgs, simLaunchArgs, simOpenUrlArgs, simScreenshotArgs, simShutdownArgs, simStatusBarArgs, simStatusBarClearArgs, simTarget, SOURCES, type Source, TOOL_HINTS, validateCapture } from './devices'; -import { DEFAULT_PHONE, DEFAULT_TABLET } from './lib'; +import { type FrameDims, frameDims } from './lib'; import { imageInfo } from './spec'; type Device = 'phone' | 'tablet'; @@ -65,11 +67,15 @@ function localeOf(config: ShipConfig, lang: string, source: Source): string { } /** Crop the status bar off a full-screen capture and store it as a 24-bit RGB frame. */ -function storeFrame(tmp: string, out: string, cropTop: number | undefined): void { - const h = imageInfo(readFileSync(tmp)).h; +function storeFrame(tmp: string, out: string, cropTop: ShotsCapture['cropTop'], device: Device, dims: FrameDims): void { + const { w, h } = imageInfo(readFileSync(tmp)); if (!h) throw new Error('screenshot is not a PNG'); - sh('ffmpeg', cropArgs(tmp, out, cropTop ?? defaultCropTop(h))); + const top = cropTopFor(cropTop, device, h, dims); + sh('ffmpeg', cropArgs(tmp, out, top)); rmSync(tmp, { force: true }); + const want = dims.w / dims.h, got = w / (h - top); + if (Math.abs(got / want - 1) > 0.03) + warn('shots', `${out}: ${w}x${h - top} after cropping ${top} rows has aspect ${got.toFixed(3)}, ${device} frames want ${want.toFixed(3)} (set shots.${device} to this device's screen in pt, or shots.capture.cropTop)`); } export async function run(ctx: Ctx): Promise { @@ -87,6 +93,7 @@ export async function run(ctx: Ctx): Promise { const devices: Device[] = a.get('device') ? [a.get('device') as Device] : ['phone', 'tablet']; if (devices.some(d => d !== 'phone' && d !== 'tablet')) throw new Error('--device: phone | tablet'); const framesDir = resolve(shots.frames); + const dims = frameDims(config); const tmpDir = join(root, '.storebound', 'tmp'); const target = (lang: string, device: Device, name: string) => { const d = join(framesDir, lang, device); if (!dry) mkdirSync(d, { recursive: true }); return join(d, `${name}.png`); }; const total = langs.length * devices.reduce((t, d) => t + shotsFor(cap, d, only).length, 0); @@ -113,7 +120,6 @@ export async function run(ctx: Ctx): Promise { for (const lang of langs) for (const device of devices) for (const [name, s] of shotsFor(cap, device, only)) progress(`${lang}/${device}/${name}.png <- ${cap.baseUrl}${(s.path ?? '/').replaceAll('{lang}', lang)}`); return done('shots', `capture planned (dry run): ${total} frames from web`); } - const dims = { phone: { ...DEFAULT_PHONE, ...shots.phone }, tablet: { ...DEFAULT_TABLET, ...shots.tablet } }; const browser = await launch(root, { headless: true, args: ['--mute-audio', '--ignore-gpu-blocklist', '--enable-webgl', '--enable-gpu'] }); try { for (const lang of langs) for (const device of devices) for (const [name, s] of shotsFor(cap, device, only)) { @@ -159,6 +165,12 @@ export async function run(ctx: Ctx): Promise { try { if (ios.app) { log('shots', `installing ${ios.app}`); exec('xcrun', simInstallArgs(sim.udid, resolve(ios.app)), { timeout: 300_000 }); } if (ios.statusBar !== false) exec('xcrun', simStatusBarArgs(sim.udid)); + const warmup = ios.warmupMs ?? 8000; + if (bootedByUs && warmup > 0) { + log('shots', `warming up ${ios.bundleId} (first launch after boot, ${warmup} ms; shots.capture.ios.warmupMs)`); + exec('xcrun', simLaunchArgs(sim.udid, ios.bundleId, { lang: langs[0]!, locale: localeOf(config, langs[0]!, 'ios-sim'), shot: '', baseArgs: ios.args })); + if (!dry) await Bun.sleep(warmup); + } for (const lang of langs) for (const [name, s] of todo) { try { const locale = localeOf(config, lang, 'ios-sim'); @@ -169,7 +181,7 @@ export async function run(ctx: Ctx): Promise { await Bun.sleep(s.delayMs ?? 2500); const tmp = join(tmpDir, `sim-${name}.png`); sh('xcrun', simScreenshotArgs(sim.udid, tmp)); - storeFrame(tmp, out, cap.cropTop); + storeFrame(tmp, out, cap.cropTop, device, dims[device]); n++; progress(`${lang}/${device}/${name}.png (${sim.name})`); } catch (e) { failed++; i++; warn('shots', `${lang}/${device}/${name}: ${(e as Error).message.slice(0, 300)}`); } @@ -210,7 +222,7 @@ export async function run(ctx: Ctx): Promise { await Bun.sleep(s.delayMs ?? 2500); const tmp = join(tmpDir, `adb-${name}.png`); writeFileSync(tmp, sh(adb, adbScreencapArgs(serial)).out); - storeFrame(tmp, out, cap.cropTop); + storeFrame(tmp, out, cap.cropTop, device, dims[device]); n++; progress(`${lang}/${device}/${name}.png${serial ? ` (${serial})` : ''}`); } catch (e) { failed++; i++; warn('shots', `${lang}/${device}/${name}: ${(e as Error).message.slice(0, 300)}`); } diff --git a/cli/shots/devices.ts b/cli/shots/devices.ts index c0247fb7..21eda88b 100644 --- a/cli/shots/devices.ts +++ b/cli/shots/devices.ts @@ -27,6 +27,7 @@ export function validateCapture(c: ShotsCapture | undefined): string[] { if (!c.ios?.bundleId) e.push('shots.capture.ios.bundleId: bundle id of the app on the simulator (source ios-sim)'); if (!c.ios?.device && !c.ios?.devices?.phone) e.push('shots.capture.ios.device: simulator name or UDID, e.g. "iPhone 17 Pro Max"'); } + if (c.ios?.warmupMs !== undefined && !(Number.isInteger(c.ios.warmupMs) && c.ios.warmupMs >= 0)) e.push('shots.capture.ios.warmupMs: milliseconds (integer >= 0)'); if (src === 'android-emu' && !c.android?.package) e.push('shots.capture.android.package: application id (source android-emu)'); if (src !== 'folder' && (!c.shots || !Object.keys(c.shots).length)) e.push('shots.capture.shots: at least one shot'); for (const [name, s] of Object.entries(c.shots ?? {})) { @@ -39,7 +40,13 @@ export function validateCapture(c: ShotsCapture | undefined): string[] { if (!['string', 'number', 'boolean'].includes(typeof v)) e.push(`shots.capture.shots.${name}.extras.${k}: string | number | boolean`); } } - if (c.cropTop !== undefined && !(Number.isInteger(c.cropTop) && c.cropTop >= 0)) e.push('shots.capture.cropTop: pixels (integer >= 0)'); + const px = (v: unknown) => Number.isInteger(v) && (v as number) >= 0; + if (typeof c.cropTop === 'object' && c.cropTop !== null) { + for (const [k, v] of Object.entries(c.cropTop)) { + if (k !== 'phone' && k !== 'tablet') e.push(`shots.capture.cropTop.${k}: phone | tablet`); + else if (!px(v)) e.push(`shots.capture.cropTop.${k}: pixels (integer >= 0)`); + } + } else if (c.cropTop !== undefined && !px(c.cropTop)) e.push('shots.capture.cropTop: pixels (integer >= 0), or { phone, tablet }'); return e; } @@ -164,6 +171,13 @@ export const adbRecordArgs = (remote: string, seconds: number, serial?: string): * Default: the same share of the height the default phone frame uses (54 of 956 px on a 6.9" iPhone). */ export const defaultCropTop = (h: number, bar = 54, screen = 956): number => Math.round(h * bar / screen); +/** Rows to crop for a capture `h` px tall on a device class: shots.capture.cropTop (number or per device), else the + * bar share of that device's frame (bar / (frame height + bar)). */ +export function cropTopFor(cropTop: ShotsCapture['cropTop'], device: 'phone' | 'tablet', h: number, dims: { h: number; bar: number }): number { + const set = typeof cropTop === 'number' ? cropTop : cropTop?.[device]; + return set ?? defaultCropTop(h, dims.bar, dims.h + dims.bar); +} + /** ffmpeg argv: crop `top` rows, write 24-bit RGB PNG. */ export const cropArgs = (inp: string, out: string, top: number): string[] => ['-v', 'error', '-y', '-i', inp, ...(top > 0 ? ['-vf', `crop=iw:ih-${top}:0:${top}`] : []), '-pix_fmt', 'rgb24', out]; diff --git a/cli/shots/lib.ts b/cli/shots/lib.ts index 13208993..7db918db 100644 --- a/cli/shots/lib.ts +++ b/cli/shots/lib.ts @@ -74,8 +74,21 @@ export function validateCopy(copy: CopyFile, shots: ShotsConfig, langs: string[] return e; } -export const DEFAULT_PHONE = { w: 440, h: 902, dpr: 3, bar: 54 }; -export const DEFAULT_TABLET = { w: 800, h: 1240, dpr: 2, bar: 40 }; +export interface FrameDims { w: number; h: number; dpr: number; bar: number } + +/** Raw frame size in CSS px below the status bar (bar = status bar height in CSS px, drawn by the template). + * Phone: 6.9" iPhone (440 x 956 pt, 54 pt bar). Tablet: a generic Android tablet (Play 7" / 10"). */ +export const DEFAULT_PHONE: FrameDims = { w: 440, h: 902, dpr: 3, bar: 54 }; +export const DEFAULT_TABLET: FrameDims = { w: 800, h: 1240, dpr: 2, bar: 40 }; +/** 13" iPad (iPad Pro M4 / M5, iPad Air 13" M2+): 1032 x 1376 pt @2x = 2064 x 2752 px, 24 pt status bar. The tablet + * default when apple.ipad is set, so a simulator screenshot of a 13" iPad fits the frame after cropping the bar. */ +export const DEFAULT_IPAD: FrameDims = { w: 1032, h: 1352, dpr: 2, bar: 24 }; + +/** Phone / tablet frame dims for a project: defaults (tablet follows the 13" iPad when apple.ipad) + shots.phone / tablet. */ +export function frameDims(config: Pick): Record<'phone' | 'tablet', FrameDims> { + const tablet = config.apple?.ipad ? DEFAULT_IPAD : DEFAULT_TABLET; + return { phone: { ...DEFAULT_PHONE, ...config.shots?.phone }, tablet: { ...tablet, ...config.shots?.tablet } }; +} /** Size keys this project renders by default: Apple sizes only with an apple section (iPad only with apple.ipad), * Play sizes only with a play section (both when neither is configured). */ diff --git a/cli/shots/render.ts b/cli/shots/render.ts index cdd4c3d3..f1631c08 100644 --- a/cli/shots/render.ts +++ b/cli/shots/render.ts @@ -12,7 +12,7 @@ import type { Ctx } from '../lib/ctx'; import { need } from '../lib/ctx'; import { done, log, warn } from '../lib/log'; import { launch } from './browser'; -import { type CopyFile, DEFAULT_PHONE, DEFAULT_TABLET, SIZES, copyText, defaultSizes, mergeCopy, palette, renderDir, scriptFont, validateCopy, variantScenes } from './lib'; +import { type CopyFile, SIZES, copyText, defaultSizes, frameDims, mergeCopy, palette, renderDir, scriptFont, validateCopy, variantScenes } from './lib'; import { type RenderReport, mergeReport, readReport } from './report'; const TYPES: Record = { html: 'text/html; charset=utf-8', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', @@ -39,7 +39,7 @@ export async function run(ctx: Ctx): Promise { const framesDir = resolve(shots.frames), outDir = resolve(shots.out); const fontsDir = join(root, '.storebound', 'fonts'); if (!existsSync(join(fontsDir, 'fonts.css'))) warn('shots', 'no .storebound/fonts/fonts.css: run `storebound shots fonts` first (falling back to system fonts)'); - const phone = { ...DEFAULT_PHONE, ...shots.phone }, tablet = { ...DEFAULT_TABLET, ...shots.tablet }; + const { phone, tablet } = frameDims(config); const rtl = new Map(config.languages.map(l => [l.id, !!l.rtl] as const)); const fonts = { title: shots.fonts?.title ?? 'Lilita One', body: shots.fonts?.body ?? 'Montserrat' }; const tpl = import.meta.dir; diff --git a/templates/storebound.config.ts b/templates/storebound.config.ts index a54cc586..0b3ddec3 100644 --- a/templates/storebound.config.ts +++ b/templates/storebound.config.ts @@ -39,7 +39,8 @@ const config: ShipConfig = { // Export compliance (export-compliance skill). false ONLY if the game uses no encryption beyond the OS (HTTPS through // the system). Left unset on purpose: decide it, then uncomment. Same answer as ITSAppUsesNonExemptEncryption. // usesNonExemptEncryption: false, - // screenshotTypes: ['APP_IPHONE_67'], // what `storebound validate` requires per locale; iPad apps add APP_IPAD_PRO_3GEN_129 + // ipad: true, // the app runs on iPad: 13" iPad screenshots (2064 x 2752, ipad13) are rendered, checked and uploaded + // screenshotTypes: ['APP_IPHONE_67'], // what `storebound validate` requires per locale (default; + APP_IPAD_PRO_3GEN_129 with ipad) info: { categories: { primary: 'GAMES', primarySubOne: 'GAMES_CASUAL', primarySubTwo: 'GAMES_PUZZLE', secondary: 'ENTERTAINMENT' }, ageRating: { advertising: true }, // everything else NONE / false @@ -106,6 +107,7 @@ const config: ShipConfig = { logo: 'store/shots/logo.png', // optional: hero scene + feature graphic fonts: { title: 'Lilita One', body: 'Montserrat' }, // phone: { w: 440, h: 902, dpr: 3 }, // raw frame size in CSS px (screen below a 54 px status bar) + // tablet: { w: 1032, h: 1352, dpr: 2 }, // default with apple.ipad (13" iPad below its 24 px bar), else 800 x 1240 scenes: [ { id: 'hero', palette: 'fire', hero: true, over: 34, frames: [{ src: 'hero.png', rotate: -4 }], badges: [{ y: 0.42, side: 'l', icon: 'flag', iconBg: 'red', rot: -4 }, { y: 0.66, side: 'r', icon: 'offline', iconBg: 'red', rot: 3 }] },