diff --git a/index.html b/index.html index 0be232a..4257595 100644 --- a/index.html +++ b/index.html @@ -297,7 +297,7 @@
MiniCrafter needs the wide view. The game starts again as soon as you turn it.
+ +It has hunger, tougher falls and losing your things when you faint (monsters are coming soon). Grown-ups, please answer:
+It has night creatures that fight back, hunger, tougher falls and losing your things when you faint. Grown-ups, please answer:
diff --git a/src/main.js b/src/main.js index 1aebd91..5f043f1 100644 --- a/src/main.js +++ b/src/main.js @@ -835,11 +835,25 @@ function startPlaying() { function enterPlay() { // Adventure worlds sit behind the grown-up gate (once per browser session). if (isAdventure() && !gateUnlocked()) { showGate(() => enterPlay(), () => showMenu()); return; } + if (touchMode && upright.matches) { askSideways(); return; } if (touchMode) startPlaying(); else { state = 'locking'; lock(); } } $('btn-play').addEventListener('click', enterPlay); + +// Phones held upright: the game view doesn't fit, so pause and ask for the phone to be +// turned sideways, then carry on by itself. (The menus still work upright.) +const upright = matchMedia('(orientation: portrait) and (max-width: 600px)'); +let resumeWhenSideways = false; +function askSideways() { resumeWhenSideways = true; $('rotate').classList.remove('hidden'); } +function cancelSideways() { resumeWhenSideways = false; $('rotate').classList.add('hidden'); } +upright.addEventListener('change', () => { + if (!touchMode) return; + if (upright.matches && state === 'playing') { showMenu(); askSideways(); } + else if (!upright.matches && resumeWhenSideways) { cancelSideways(); enterPlay(); } +}); +$('rotate-back').addEventListener('click', cancelSideways); $('inv-done').addEventListener('click', () => closeOverlay(true)); $('craft-done').addEventListener('click', () => closeOverlay(true)); $('qb-done').addEventListener('click', () => closeOverlay(true)); @@ -1039,7 +1053,7 @@ $('acc-delete').addEventListener('click', async () => { // Every pop-up panel gets a ✕ that is always on screen, and tapping the dimmed area // outside a panel closes it too. (Phones have no Escape key, and on a small screen the // Done button can be scrolled out of sight under a long list.) -for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done']]) { +for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel']]) { const ov = $(overlay); const x = document.createElement('button'); x.type = 'button'; x.className = 'x-close'; x.textContent = '✕'; x.setAttribute('aria-label', 'Close'); @@ -1048,6 +1062,14 @@ for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done' ov.addEventListener('click', (e) => { if (e.target === ov) $(done).click(); }); } +// Bit's side panel is not a pop-up (taps inside it must not close it), so it only gets the ✕. +{ + const x = document.createElement('button'); + x.type = 'button'; x.className = 'x-close'; x.textContent = '✕'; x.setAttribute('aria-label', 'Close'); + x.addEventListener('click', () => $('rb-close').click()); + $('robot-panel').appendChild(x); +} + // ---------- today's building idea ---------- $('idea-text').textContent = ideaOfTheDay(); $('btn-idea').addEventListener('click', () => { $('idea-text').textContent = IDEAS[Math.floor(Math.random() * IDEAS.length)]; }); diff --git a/style.css b/style.css index 4cc7ad4..310637a 100644 --- a/style.css +++ b/style.css @@ -377,3 +377,41 @@ body.touch #emoji-bar small { display: none; } button.danger { background: #7a2323; border-color: #c54848; } .tg-login { margin-top: 12px; padding: 12px; border-radius: 8px; background: rgba(59, 130, 246, .12); border: 1px solid rgba(59, 130, 246, .5); } .tg-login p { margin: 0 0 10px; } + +/* ---------- Phones (design audit fixes) ---------- */ +/* "Turn your phone sideways" card, shown when a phone is held upright at Play. */ +#rotate { z-index: 40; } +.rotate-panel { width: min(320px, 100%); } +.rotate-phone { font-size: 64px; line-height: 1.2; margin-bottom: 8px; animation: rotate-hint 2.4s ease-in-out infinite; } +@keyframes rotate-hint { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } } +@media (prefers-reduced-motion: reduce) { .rotate-phone { animation: none; transform: rotate(-90deg); } } +#rotate-back { margin-top: 8px; } + +/* Bit's panel: the ✕ stays at the screen's top right while the panel scrolls. */ +#robot-panel > .x-close { position: fixed; } +#robot-panel .rb-head { padding-right: 48px; } + +/* Touch tablets: at most two quests in the tracker, so it covers less of the world. */ +body.touch #quest-tracker .q-card ~ .q-card ~ .q-card { display: none; } + +/* Phones held sideways: keep the main button in reach and use one scroll per panel. */ +@media (max-height: 520px) { + /* Done stays pinned to the bottom of the panel instead of starting below the fold. */ + .panel > button.done { position: sticky; bottom: -1px; z-index: 2; margin-top: 10px; box-shadow: 0 -10px 14px 6px rgba(20, 24, 34, .95); } + .panel { padding: 16px 18px 12px; } + .panel > h2 { padding-right: 44px; } + /* Quest book: the whole panel scrolls (no list scrolling inside a scrolling panel). */ + #qb-list { max-height: none; overflow: visible; } + /* Block picker: tabs in one sideways-scrolling row, no subtitle, more room for blocks. */ + #inventory .panel > .note { display: none; } + #inv-tabs { flex: none; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; } + #inv-tabs button { flex: none; } + #inv-grid { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; margin-top: 8px; } + /* Bit: compact header, editor sized to the screen, Run / Stop pinned to the bottom. */ + #robot-panel { padding: 10px 14px; } + #robot-panel .rb-head .note, #rb-editor-note { display: none; } + #robot-panel .rb-face { font-size: 1.6rem; } + #rb-status { margin-top: 6px; padding: 6px 10px; } + #rb-blockly { height: calc(100vh - 150px); min-height: 180px; } + #rb-controls { position: sticky; bottom: -10px; z-index: 2; margin-top: 0; padding: 8px 0 10px; background: rgba(20, 24, 34, .98); } +} diff --git a/sw.js b/sw.js index 99877d8..c4e7a00 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ // Service worker: caches the whole game so it works offline once loaded. // Bump VERSION whenever files change so players get the update. -const VERSION = 'minicrafter-v20'; +const VERSION = 'minicrafter-v21'; const CORE = [ './', './index.html', './style.css', './manifest.webmanifest', './site-config.json', './icons/icon-192.png', './icons/icon-512.png', './icons/icon-maskable-512.png', './icons/apple-touch-icon.png', './icons/favicon-32.png', diff --git a/tests/smoke.mjs b/tests/smoke.mjs index ac4bff8..4d9c5e4 100644 --- a/tests/smoke.mjs +++ b/tests/smoke.mjs @@ -256,6 +256,15 @@ try { return document.getElementById('touch').classList.contains('active'); }); ok(touch, 'touch controls appear in touch mode'); + // Phones: turning the phone upright pauses and asks for sideways; turning it back carries on. + const shown = (id) => t.page.evaluate((i) => !document.getElementById(i).classList.contains('hidden'), id); + await t.page.setViewportSize({ width: 390, height: 844 }); + await t.page.waitForTimeout(300); + const askedUpright = (await shown('rotate')) && !(await shown('hud')); + await t.page.setViewportSize({ width: 844, height: 390 }); + await t.page.waitForTimeout(300); + const resumed = !(await shown('rotate')) && (await shown('hud')); + ok(askedUpright && resumed, 'phones: upright pauses and asks to turn sideways, sideways carries on'); ok(t.errors.length === 0, 'no console errors (touch)', t.errors.slice(0, 3).join(' | ')); await t.page.close();