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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ It needs a modern browser with WebGL. Everything, including three.js and Blockly
<details>
<summary><b>🧩 How it's built</b> (for developers)</summary>

- **Offline:** `sw.js` precaches every file (stale-while-revalidate) and `manifest.webmanifest` makes it installable. Bump `VERSION` in `sw.js` when files change. The service worker is skipped on localhost so development always sees fresh files (add `?sw=1` to test it).
- **Offline:** `sw.js` precaches every file (stale-while-revalidate) and `manifest.webmanifest` makes it installable. Bump `VERSION` in `sw.js` when files change. To tell returning players about a new feature, also add an entry with the same number at the top of `NEWS` in `src/news.js`: they see a short "What's new" card once (brand-new players don't). The service worker is skipped on localhost so development always sees fresh files (add `?sw=1` to test it).
- **Rendering:** [three.js](https://threejs.org/) 0.160 (vendored) loaded through an import map. Chunks are 16×16×96 with hidden-face culling and per-vertex ambient occlusion, so each chunk layer is a single draw call.
- **Lighting:** sky light and block light (0–15) are flood-filled while meshing, over the chunk plus a 15-block margin, and smoothed per vertex. A small shader hook mixes them with the time of day, so torchlight stays warm at night.
- **Everything procedural:** a seeded Perlin-noise world, a pixel-art texture atlas painted in code, and Web Audio sound effects synthesized on the fly.
Expand Down
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ <h2>👤 Your account</h2>
</div>
</div>

<div id="news" class="overlay hidden">
<div class="panel news-panel">
<h2>✨ What's new: <span id="news-title"></span></h2>
<ul id="news-list" class="news-list"></ul>
<p class="note"><a href="features.html">See all features</a></p>
<button id="news-done" class="wide-btn" type="button">Got it!</button>
</div>
</div>

<div id="report" class="overlay hidden">
<div class="panel report-panel">
<h2>🐞 Report a problem</h2>
Expand Down
19 changes: 18 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Account, accountMessage } from './account.js';
import { Course, fmtTime } from './course.js';
import { PhotoMode, FRAMES, FILTERS, STICKERS } from './photo.js';
import { Insights, REPORTS } from './insights.js';
import { unseenNews, markNewsSeen } from './news.js';

const insights = new Insights(); // anonymous counts + error reports, online edition only

Expand Down Expand Up @@ -1270,7 +1271,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'], ['pet', 'pet-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel'], ['photo', 'ph-close'], ['report', 'report-done']]) {
for (const [overlay, done] of [['inventory', 'inv-done'], ['craft', 'craft-done'], ['pet', 'pet-done'], ['worlds', 'w-done'], ['trade', 'tr-done'], ['questbook', 'qb-done'], ['together', 'tg-close'], ['account', 'acc-done'], ['gate', 'gate-cancel'], ['photo', 'ph-close'], ['report', 'report-done'], ['news', 'news-done']]) {
const ov = $(overlay);
const x = document.createElement('button');
x.type = 'button'; x.className = 'x-close'; x.textContent = '✕'; x.setAttribute('aria-label', 'Close');
Expand All @@ -1293,6 +1294,22 @@ window.caches?.keys().then((keys) => {
if (v) $('game-version').textContent = `Version ${v}`;
}).catch(() => {});

// ---------- What's new (once after an update, returning players only) ----------
{
const news = unseenNews();
if (news.length) {
$('news-title').textContent = news[0].title;
$('news-list').replaceChildren(...news.flatMap((n) => n.items).map(([icon, text]) => {
const li = document.createElement('li');
const span = document.createElement('span'); span.textContent = icon;
li.append(span, document.createTextNode(text));
return li;
}));
$('news').classList.remove('hidden');
}
$('news-done').addEventListener('click', () => { $('news').classList.add('hidden'); markNewsSeen(); });
}

// ---------- Report a problem (online edition) ----------
{
const box = $('report-choices');
Expand Down
45 changes: 45 additions & 0 deletions src/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// "What's new": a short card shown once after an update, so returning players hear about
// new things (players never read changelogs). Brand-new players don't see it: everything
// is new to them.
//
// To announce a release: bump VERSION in sw.js, then add an entry at the TOP of NEWS with
// the same number. Small bug-fix releases can skip the news (the card only shows entries
// newer than the last one this player saw).
export const NEWS = [
{
v: 31,
title: 'Pets got upgrades!',
items: [
['🛡️', 'Pet armor: craft a Cozy Pet Coat, Iron or Starlight armor and give it to your dog or cat. It keeps them safe.'],
['🎒', 'Pet Backpack: give one to your pet and it carries 9 things for you. Tap your pet to look inside.'],
['🛏️', 'Pet Beds and Doghouses: pets nap there and get their hearts back.'],
['🔧', 'Fixes: Bit works on iPhone again, and new versions now arrive straight away.'],
],
},
];

const SEEN = 'minicrafter:news-seen';

/** The news this player hasn't seen yet (newest first), or [] for a new player or none. */
export function unseenNews(store = localStorage) {
const latest = NEWS[0]?.v || 0;
let seen = null;
try { seen = Number(store.getItem(SEEN)) || null; } catch { return []; }
if (seen === null) {
// First time with news: a returning player already has something saved; a new player doesn't.
let returning = false;
try {
for (let i = 0; i < store.length; i++) {
const k = store.key(i);
if (k && k.startsWith('minicrafter:') && k !== SEEN && k !== 'minicrafter:settings:v1') { returning = true; break; }
}
} catch { /* ignore */ }
if (!returning) { markNewsSeen(store); return []; }
seen = 0;
}
return NEWS.filter((n) => n.v > seen).slice(0, 2);
}

export function markNewsSeen(store = localStorage) {
try { store.setItem(SEEN, String(NEWS[0]?.v || 0)); } catch { /* private mode: fine */ }
}
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ body.touch #quest-tracker { right: calc(max(10px, env(safe-area-inset-right)) +
.report-choices { display: grid; gap: 6px; margin: 10px 0; }
.report-choices .wide-btn { margin-top: 0; text-align: left; }

/* What's new card (once after an update) */
.news-panel { width: min(440px, 100%); }
.news-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.news-list li { display: grid; grid-template-columns: 2em 1fr; gap: 6px; align-items: start; line-height: 1.35; }
.news-list li span { font-size: 1.3rem; text-align: center; }
.news-panel a { color: #9be06a; }

/* Pet panel (armor + backpack) */
.pet-panel { width: min(520px, 100%); }
.pet-panel h3 { margin: 14px 0 6px; font-size: 1rem; }
Expand Down
3 changes: 2 additions & 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-v30';
const VERSION = 'minicrafter-v31';
const CORE = [
'./', './index.html', './style.css', './privacy.html', './terms.html', './legal.css', './features.html', './features.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 All @@ -15,6 +15,7 @@ const CORE = [
'./src/course.js',
'./src/photo.js',
'./src/insights.js',
'./src/news.js',
'./src/craftui.js',
'./src/petui.js',
'./src/critters.js',
Expand Down
14 changes: 14 additions & 0 deletions tests/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ try {
ok(core.worlds >= 1, 'a saved world exists');
ok(core.hotbar === 9, 'hotbar has 9 slots');

// What's new: hidden for a brand-new player; shown once to a returning player after an update.
const news = await page.evaluate(async () => {
const { unseenNews, markNewsSeen, NEWS } = await import('./src/news.js');
const data = { 'minicrafter:worlds': '[]' }; // a returning player: something already saved
const returning = { get length() { return Object.keys(data).length; }, key: (i) => Object.keys(data)[i], getItem: (k) => data[k] ?? null, setItem: (k, v) => { data[k] = v; } };
const shown = unseenNews(returning).length;
markNewsSeen(returning);
const sw = await fetch('./sw.js').then((r) => r.text());
return { newHidden: document.getElementById('news').classList.contains('hidden'), shown, after: unseenNews(returning).length,
sameVersion: sw.includes(`minicrafter-v${NEWS[0].v}'`) || Number(/minicrafter-v(\d+)/.exec(sw)[1]) > NEWS[0].v };
});
ok(news.newHidden && news.shown === 1 && news.after === 0, "what's new: hidden for new players, shown once to returning players", JSON.stringify(news));
ok(news.sameVersion, "what's new: the newest news is not ahead of sw.js VERSION");

const features = await page.evaluate(async () => {
const m = window.minicrafter;
const { QUESTS } = await import('./src/quests.js');
Expand Down
Loading