Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ <h2>⭐ Quest book</h2>
<div id="rb-status" class="rb-status idle"></div>
<p class="note" id="rb-editor-note"></p>
<div id="rb-blockly"></div>
<div class="rb-row">
<div class="rb-row" id="rb-controls">
<button id="rb-run" class="go" type="button">▶ Run</button>
<button id="rb-stop" type="button">⏹ Stop</button>
</div>
Expand All @@ -319,10 +319,19 @@ <h3>Starter programs <span class="note">(load into the editor and run)</span></h
<button id="rb-close" class="primary done">Done</button>
</div>

<div id="rotate" class="overlay hidden" role="dialog" aria-labelledby="rotate-title">
<div class="panel center rotate-panel">
<div class="rotate-phone" aria-hidden="true">📱</div>
<h2 id="rotate-title">Turn your phone sideways</h2>
<p class="note">MiniCrafter needs the wide view. The game starts again as soon as you turn it.</p>
<button id="rotate-back" type="button">Back to the menu</button>
</div>
</div>

<div id="gate" class="overlay hidden">
<div class="panel center">
<h2>⚔️ Adventure mode is for older players</h2>
<p class="note">It has hunger, tougher falls and losing your things when you faint (monsters are coming soon). Grown-ups, please answer:</p>
<p class="note">It has night creatures that fight back, hunger, tougher falls and losing your things when you faint. Grown-ups, please answer:</p>
<p class="gate-q" id="gate-q"></p>
<input id="gate-a" type="number" inputmode="numeric" placeholder="Answer">
<p class="note" id="gate-err"></p>
Expand Down
24 changes: 23 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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');
Expand All @@ -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)]; });
Expand Down
38 changes: 38 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
2 changes: 1 addition & 1 deletion sw.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
9 changes: 9 additions & 0 deletions tests/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading