(engine: VisualNovelEngine, prefix = 'SaveLabel', id: number | null = null, name: string | null = null)
| 34 | // ============================================================================ |
| 35 | |
| 36 | export async function saveTo (engine: VisualNovelEngine, prefix = 'SaveLabel', id: number | null = null, name: string | null = null): Promise<unknown> { |
| 37 | // Check if the player is actually playing |
| 38 | if (!engine.global ('playing')) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | const now = DateTime.now(); |
| 43 | const date = now.toISO(); |
| 44 | const timestamp = now.toMillis(); |
| 45 | const gameData = gameObject(engine); |
| 46 | |
| 47 | if (name === null || name.trim () === '') { |
| 48 | name = date; |
| 49 | } |
| 50 | |
| 51 | let image = ''; |
| 52 | |
| 53 | const backgroundState = engine.state ('background'); |
| 54 | const sceneState = engine.state ('scene'); |
| 55 | |
| 56 | if (backgroundState) { |
| 57 | image = backgroundState.split (' ')[2]; |
| 58 | } else if (sceneState) { |
| 59 | image = sceneState.split (' ')[2]; |
| 60 | } |
| 61 | |
| 62 | const slotKey = `${engine.setting (prefix)}_${id || timestamp}`; |
| 63 | |
| 64 | let screenshot: string | undefined; |
| 65 | |
| 66 | if (engine.setting ('Screenshots')) { |
| 67 | try { |
| 68 | // Prefer the screenshot captured when the save screen was opened. |
| 69 | // Auto-saves fire during gameplay, so they fall back to capturing the still-visible game screen. |
| 70 | let blob: Blob | null = null; |
| 71 | |
| 72 | if (engine._pendingScreenshot) { |
| 73 | blob = await engine._pendingScreenshot; |
| 74 | engine._pendingScreenshot = null; |
| 75 | } else { |
| 76 | blob = await captureGameScreenshot (engine); |
| 77 | } |
| 78 | |
| 79 | if (blob) { |
| 80 | screenshot = await engine.onSaveScreenshot (slotKey, blob); |
| 81 | } |
| 82 | } catch (e) { |
| 83 | engine.debug.warn ('Screenshot capture failed:', e); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const saveData: Record<string, unknown> = { |
| 88 | name, |
| 89 | date, |
| 90 | image, |
| 91 | game: gameData |
| 92 | }; |
| 93 |
nothing calls this directly
no test coverage detected