(file)
| 5465 | if ('cylinderRadius' in snap) settings.cylinderRadius = snap.cylinderRadius; |
| 5466 | if ('cylinderPanelMinimized' in snap) { |
| 5467 | settings.cylinderPanelMinimized = !!snap.cylinderPanelMinimized; |
| 5468 | cylinderPanel.classList.toggle('minimized', settings.cylinderPanelMinimized); |
| 5469 | } |
| 5470 | updateCylinderUIVisibility(); |
| 5471 | } |
| 5472 | |
| 5473 | /** |
| 5474 | * Find a preset by name and activate it. By default, suppresses preset defaults |
| 5475 | * (resetTextureSmoothing + defaultScale override) so a just-restored snapshot |
| 5476 | * isn't clobbered. Pass applyDefaults=true for fresh user-initiated picks. |
| 5477 | */ |
| 5478 | function _selectPresetByName(name, applyDefaults = false) { |
| 5479 | if (!name) return false; |
| 5480 | const idx = IMAGE_PRESETS.findIndex(p => p.name === name); |
| 5481 | if (idx < 0) return false; |
| 5482 | const swatch = _presetSwatches[idx]; |
| 5483 | if (!swatch) return false; |
| 5484 | selectPreset(idx, swatch, applyDefaults); |
| 5485 | return true; |
| 5486 | } |
| 5487 | |
| 5488 | // ── localStorage auto-save ─────────────────────────────────────────────────── |
| 5489 | |
| 5490 | let _autoSaveTimer = null; |
| 5491 | let _autoSavePaused = false; |
| 5492 | function _autoSaveSettings() { |
| 5493 | if (_autoSavePaused) return; |
| 5494 | clearTimeout(_autoSaveTimer); |
| 5495 | _autoSaveTimer = setTimeout(() => { |
| 5496 | try { |
| 5497 | const payload = { version: PROJECT_VERSION, ...getSettingsSnapshot() }; |
| 5498 | sessionStorage.setItem(PROJECT_STORAGE_KEY, JSON.stringify(payload)); |
| 5499 | } catch { /* quota exceeded or disabled — ignore */ } |
| 5500 | }, 300); |
| 5501 | } |
| 5502 | |
| 5503 | function _restoreSessionSettings() { |
| 5504 | let raw; |
| 5505 | try { raw = sessionStorage.getItem(PROJECT_STORAGE_KEY); } |
| 5506 | catch { return; } |
| 5507 | if (!raw) return; |
| 5508 | let data; |
| 5509 | try { data = JSON.parse(raw); } catch { return; } |
| 5510 | if (!data || typeof data !== 'object') return; |
| 5511 | applySettingsSnapshot(data); |
| 5512 | // Preset activation is handled by the thumbnail-load auto-select path — |
| 5513 | // it reads activeMapName from sessionStorage and suppresses defaults so |
| 5514 | // the user's saved scaleU / textureSmoothing survive. |
| 5515 | } |
| 5516 | |
| 5517 | // Delegate auto-save to input/change bubbling in the settings panel — |
| 5518 | // covers every slider, number input, select, and checkbox in one shot. |
| 5519 | const _settingsPanel = document.getElementById('settings-panel'); |
| 5520 | if (_settingsPanel) { |
| 5521 | _settingsPanel.addEventListener('input', _autoSaveSettings); |
| 5522 | _settingsPanel.addEventListener('change', _autoSaveSettings); |
| 5523 | } |
| 5524 | // The lock-scale button doesn't emit input/change — catch it separately. |
no test coverage detected