1import { threatHeight } from './threat.js'; 2 3const TOP = 44; 4const PORTRAITS_W = 4 * 140 + 3 * 8; 5const MENU_W = 238; 6export const LIP = 6; 7 8export function uiScale(w, h) { 9 if (w < 640) return Math.min(1.4, Math.max(0.8, w / 440)); 10 return Math.min(2.5, Math.max(0.92, Math.min(w / 1000, h / 620))); 11} 12 13export function layoutFor(lw, lh, m) { 14 const out = {}; 15 const pad = 8; 16 const wide = 10 + PORTRAITS_W + 16 + MENU_W + 10 <= lw; 17 out.scrim = m.screen ? { x: 0, y: 0, w: lw, h: lh } : null; 18 const cw = Math.min(lw - 2 * pad, 500); 19 const ch = Math.min(lh - 2 * pad, m.screen === 'end' ? (cw < 460 ? 430 : 410) : cw < 460 ? 490 : 420); 20 out.card = m.screen ? { x: (lw - cw) / 2, y: (lh - ch) / 2, w: cw, h: ch } : null; 21 if (!m.hud) return out; 22 23 const tw = Math.min(lw - 2 * pad, 600); 24 out.topbar = { x: (lw - tw) / 2, y: 6, w: tw, h: 32 }; 25 const bh = wide ? 100 : 128; 26 out.bottom = { x: 0, y: lh - bh - LIP, w: lw, h: bh + LIP }; 27 if (wide) { 28 out.portraits = { x: 10, y: lh - bh - LIP, w: PORTRAITS_W, h: bh - 2 }; 29 out.menu = { x: lw - MENU_W - 10, y: lh - bh + 8, w: MENU_W, h: 84 }; 30 } else { 31 out.menu = { x: pad, y: lh - bh + 8, w: lw - 2 * pad, h: 44 }; 32 out.portraits = { x: pad, y: lh - bh + 52, w: lw - 2 * pad, h: bh - 58 }; 33 } 34 const avail = lh - bh - TOP - pad; 35 const pw = Math.min(lw - 2 * pad, 660); 36 const ph = Math.min(avail, wide ? 520 : 660); 37 const panel = { x: (lw - pw) / 2, y: TOP + (avail - ph) / 2, w: pw, h: ph }; 38 out['panel-inv'] = m.panel === 'inv' ? panel : null; 39 out['panel-journal'] = m.panel === 'journal' ? panel : null; 40 out['panel-shop'] = m.panel === 'shop' ? panel : null; 41 const fw = Math.min(lw - 2 * pad, 520); 42 const fh = Math.min(avail, 340); 43 out['panel-feedback'] = m.panel === 'feedback' ? { x: (lw - fw) / 2, y: TOP + (avail - fh) / 2, w: fw, h: fh } : null; 44 out['feedback-cta'] = m.state.feedback && !m.panel && !m.threat && !m.combat && !m.camp ? { x: out.topbar.x + tw - 136, y: TOP, w: 136, h: 30 } : null; 45 if (m.threat) { 46 const w = Math.min(lw - 2 * pad, 400); 47 const h = Math.min(avail, threatHeight(m.threat.threat)); 48 out.threat = { x: (lw - w) / 2, y: TOP + (avail - h) / 2, w, h }; 49 } 50 const logW = Math.min(wide ? 380 : lw - 2 * pad, lw * (wide ? 0.4 : 1)); 51 const lines = Math.min(m.logRowsFor(logW), wide ? 6 : 4); 52 const logH = lines * 17 + 12; 53 out.log = m.panel || m.threat || m.hush || !lines ? null : { x: pad, y: lh - bh - pad - logH, w: logW, h: logH }; 54 out['combat-banner'] = m.combat ? { x: (lw - 300) / 2, y: TOP, w: 300, h: 34 } : null; 55 out['camp-banner'] = m.camp ? { x: (lw - 300) / 2, y: TOP, w: 300, h: 58 } : null; 56 return out; 57}