Seitenhöhen analytisch ans Spielfeld anpassen, Layout idempotent machen und Canvas nach resize sofort neu zeichnen (leeres Feld behoben); doppelten fxbar-Label entfernt
This commit is contained in:
1 parent
139b67407e
commit
b4f4d7529a
1 file changed
+65
-16
+65
-16
@@ -24,6 +24,8 @@
|
||||
/* --pw = Spielfeld-Breite (JS), --s = UI-Skalierung (JS) */
|
||||
--pw: 760px;
|
||||
--s: 1;
|
||||
--ls: 1;
|
||||
--fieldH: 100%;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
|
||||
@@ -130,13 +132,19 @@
|
||||
#side { margin-bottom: 8px; }
|
||||
#rail { margin-top: 10px; }
|
||||
body.cols #main { display: flex; align-items: flex-start; gap: 10px; }
|
||||
body.cols #side { flex: none; width: calc(148px * var(--s)); margin: 0; }
|
||||
body.cols #rail { flex: none; width: calc(238px * var(--s)); margin: 0; }
|
||||
body.cols #side { flex: none; width: calc(148px * var(--s)); margin: 0; max-height: var(--fieldH); overflow: hidden auto; }
|
||||
body.cols #rail { flex: none; width: calc(238px * var(--s)); margin: 0; max-height: var(--fieldH); overflow: hidden auto; }
|
||||
body.cols #strip { flex-direction: column; align-items: stretch; gap: calc(6px * var(--s)); margin-left: 0; }
|
||||
body.cols .pill { border-radius: 10px; justify-content: space-between; }
|
||||
body.cols #wrap { flex: 1 1 0; min-width: 0; width: auto; }
|
||||
body.cols #pu-legend { grid-template-columns: 1fr; }
|
||||
body.cols #pu-legend { grid-template-columns: 1fr; gap: calc(6px * var(--ls)); margin-top: calc(8px * var(--ls)); }
|
||||
body.cols .card { padding: calc(7px * var(--ls)) calc(9px * var(--ls)); gap: calc(8px * var(--ls)); border-radius: calc(9px * var(--ls)); }
|
||||
body.cols .card .n { font-size: calc(11.5px * var(--ls)); }
|
||||
body.cols .card .d { font-size: calc(10px * var(--ls)); line-height: 1.3; }
|
||||
body.cols .card .glyph { width: calc(18px * var(--ls)); height: calc(18px * var(--ls)); }
|
||||
body.cols #fxbar { flex-direction: column; align-items: flex-start; gap: calc(6px * var(--s)); }
|
||||
body.cols.tight .card .d { display: none; }
|
||||
body.cols.tight .card { padding: calc(5px * var(--ls)) calc(8px * var(--ls)); }
|
||||
#legend .ltitle { font-size: calc(12px * var(--s)); color: var(--muted); margin: 4px 0 6px; }
|
||||
#pu-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 8px; margin-top: 10px; }
|
||||
.card {
|
||||
@@ -377,6 +385,11 @@
|
||||
return { w: cw, h: ch };
|
||||
}
|
||||
|
||||
/* resize() leert das Canvas: sofort neu zeichnen, damit das Spielfeld nach
|
||||
Layout-Anpassungen nie blank stehen bleibt. */
|
||||
var drawReady = false;
|
||||
function redraw() { if (drawReady) draw(); }
|
||||
|
||||
/* Viewport-Breite UND -Höhe gemeinsam auflösen und UI proportional einpassen.
|
||||
Löst die Kopplung (Skala -> chrome-Höhe -> Feldbreite) iterativ, damit das
|
||||
Panel nie über den Viewport ragt. */
|
||||
@@ -424,7 +437,7 @@
|
||||
var pwf = Math.min(base.panelFull, fieldW + base.extra + base.sideW1 * s);
|
||||
rootEl.style.setProperty('--pw', pwf.toFixed(1) + 'px');
|
||||
rootEl.style.setProperty('--s', s.toFixed(3));
|
||||
return s;
|
||||
return { s: s, pw: pwf };
|
||||
}
|
||||
var lastPw = 0;
|
||||
|
||||
@@ -439,27 +452,58 @@
|
||||
var vw = document.documentElement.clientWidth || window.innerWidth || 720;
|
||||
bodyCols = vw >= 940 && vh >= 600;
|
||||
document.body.classList.toggle('cols', bodyCols);
|
||||
document.body.classList.remove('tight');
|
||||
rootEl.style.setProperty('--ls', '1');
|
||||
|
||||
var base = measureChromeBase();
|
||||
var s = fitField(base);
|
||||
var fit = fitField(base);
|
||||
var s = fit.s;
|
||||
|
||||
/* Seitenhöhen analytisch an die Feldhöhe anpassen (Legende skaliert mit --ls).
|
||||
Leicht konservativ rechnen, damit das Nachmessen nicht nachjustieren muss. */
|
||||
if (bodyCols) {
|
||||
var natural = Math.max(railEl.scrollHeight, sideEl.scrollHeight, 1);
|
||||
var wrapH0 = wrap.clientHeight || 1;
|
||||
var ls = clamp(0.97 * wrapH0 / natural, 0.6, 1);
|
||||
rootEl.style.setProperty('--ls', ls.toFixed(3));
|
||||
if (natural * Math.max(0.6, ls) > wrapH0 + 6) document.body.classList.add('tight');
|
||||
}
|
||||
|
||||
/* Nur resize(), wenn sich tatsächlich etwas geändert hat: jedes resize()
|
||||
leert das Canvas – wiederholtes Layout ohne Änderung ließ das Feld leer. */
|
||||
var sig = bodyCols + '|' + fit.pw.toFixed(1) + '|' + s.toFixed(3) + '|' +
|
||||
rootEl.style.getPropertyValue('--ls') + '|' + document.body.classList.contains('tight');
|
||||
if (sig === lastLayoutSig) {
|
||||
rootEl.style.setProperty('--fieldH', Math.max(120, wrap.clientHeight || 1) + 'px');
|
||||
return;
|
||||
}
|
||||
lastLayoutSig = sig;
|
||||
|
||||
var dim = resize();
|
||||
redraw();
|
||||
if (dimsEl) dimsEl.textContent = dim.w + ' × ' + dim.h + ' px';
|
||||
|
||||
/* Sicherheitsnetz: ragt das Panel über den Viewport (z.B. rechte Spalte höher
|
||||
als das Spielfeld), tatsächlich nachmessen und bis zu 3x nachjustieren. */
|
||||
for (var guard = 0; guard < 3; guard++) {
|
||||
var panelH = document.getElementById('panel').getBoundingClientRect().height;
|
||||
var allowed = viewportH() - base.padY;
|
||||
if (!isFinite(panelH) || panelH <= allowed + 2) break;
|
||||
/* Nachprüfung: Seitenhöhen dürfen das Spielfeld nicht überragen; die
|
||||
Feldhöhe ist harte Obergrenze (--fieldH), chrome1 wird nicht verbogen. */
|
||||
for (var guard = 0; guard < 2; guard++) {
|
||||
var wrapH = wrap.clientHeight || 1;
|
||||
var sCur = clamp(parseFloat(rootEl.style.getPropertyValue('--s')) || s, S_MIN, S_MAX);
|
||||
base.chrome1 = Math.max(40, (panelH - wrapH) / Math.max(0.5, sCur));
|
||||
s = fitField(base);
|
||||
rootEl.style.setProperty('--fieldH', Math.max(120, wrapH) + 'px');
|
||||
var over = bodyCols ? Math.max(railEl.scrollHeight, sideEl.scrollHeight) - wrapH : 0;
|
||||
if (over <= 2) break;
|
||||
if (bodyCols) {
|
||||
rootEl.style.setProperty('--ls', clamp((parseFloat(rootEl.style.getPropertyValue('--ls')) || 1) * 0.9, 0.6, 1).toFixed(3));
|
||||
document.body.classList.add('tight');
|
||||
} else {
|
||||
base.chrome1 = Math.max(40, chromeH());
|
||||
fit = fitField(base);
|
||||
s = fit.s;
|
||||
}
|
||||
dim = resize();
|
||||
redraw();
|
||||
if (dimsEl) dimsEl.textContent = dim.w + ' × ' + dim.h + ' px';
|
||||
}
|
||||
}
|
||||
var lastLayoutSig = '';
|
||||
|
||||
var layoutQueued = false;
|
||||
function requestLayout() {
|
||||
@@ -1001,8 +1045,11 @@
|
||||
/* Chips bleiben bestehen, nur Balkenbreite aktualisiert -> kein Flackern */
|
||||
var changed = false;
|
||||
if (!fxChips.lbl) {
|
||||
var lbl = document.createElement('span'); lbl.className = 'lbl'; lbl.textContent = 'Aktive Power-ups';
|
||||
fxbar.appendChild(lbl);
|
||||
var lbl = fxbar.querySelector('.lbl');
|
||||
if (!lbl) {
|
||||
lbl = document.createElement('span'); lbl.className = 'lbl'; lbl.textContent = 'Aktive Power-ups';
|
||||
fxbar.appendChild(lbl);
|
||||
}
|
||||
fxChips.lbl = { el: lbl };
|
||||
}
|
||||
var live = { lbl: true };
|
||||
@@ -1195,6 +1242,8 @@
|
||||
}
|
||||
|
||||
legend(); renderOpts(); layout(); buildLevel(); resetBall(); hud(); hudFx(true);
|
||||
drawReady = true;
|
||||
redraw();
|
||||
/* Layout finalisieren nachdem Fonts/Box-Messung stabil sind */
|
||||
if (document.fonts && document.fonts.ready) document.fonts.ready.then(requestLayout);
|
||||
setTimeout(requestLayout, 80);
|
||||
|
||||
Reference in new issue
Block a user