Persist games across reloads and announce new releases
- Autosave every five seconds while playing, plus on pagehide and when the tab is hidden. On load, a saved game resumes immediately (same speed and camera) instead of waiting behind the title screen. - The build turns this version's CHANGELOG section into release notes: baked into the page for a one-time "What's new" card for returning players, and published as /version.json. - Open games poll /version.json every 10 minutes and when the tab comes back into view; if a newer release is out, a banner offers to save and reload. - "Start a new network" moves into the help screen, behind a confirm.
This commit is contained in:
parent
b52d20e536
commit
e082d6fc60
9 changed files with 145 additions and 9 deletions
|
|
@ -12,11 +12,19 @@ test('build stamps version and date into the site', () => {
|
|||
assert.match(html, /const APP_VERSION='9\.9\.9'/);
|
||||
assert.match(html, /"softwareVersion": "9\.9\.9"/);
|
||||
assert.match(fs.readFileSync(path.join(root, '_site', 'sitemap.xml'), 'utf8'), /<lastmod>2030-01-01<\/lastmod>/);
|
||||
for (const f of ['favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'icon-192.png', 'icon-512.png', 'site.webmanifest', 'robots.txt', 'images/og-image.png', '404.html', 'CNAME']) {
|
||||
for (const f of ['favicon.svg', 'favicon.ico', 'apple-touch-icon.png', 'icon-192.png', 'icon-512.png', 'site.webmanifest', 'robots.txt', 'images/og-image.png', '404.html', 'CNAME', 'version.json']) {
|
||||
assert.ok(fs.existsSync(path.join(root, '_site', f)), `${f} is shipped`);
|
||||
}
|
||||
});
|
||||
|
||||
test('version.json carries the release notes from the changelog', () => {
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, VERSION: '1.0.0', BUILD_DATE: '2026-10-23' } });
|
||||
const v = JSON.parse(fs.readFileSync(path.join(root, '_site', 'version.json'), 'utf8'));
|
||||
assert.equal(v.version, '1.0.0');
|
||||
assert.ok(v.notes.length >= 5);
|
||||
assert.ok(v.notes.every((n) => !n.startsWith('-')));
|
||||
});
|
||||
|
||||
test('head carries the SEO and social metadata', () => {
|
||||
const html = fs.readFileSync(path.join(root, 'site', 'index.html'), 'utf8');
|
||||
for (const needle of ['<link rel="canonical" href="https://seriesoftub.es/">', 'property="og:image"', 'name="twitter:card"', 'application/ld+json', 'rel="manifest"', 'name="description"']) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ const fs = require('node:fs');
|
|||
const path = require('node:path');
|
||||
const { JSDOM, VirtualConsole } = require('jsdom');
|
||||
|
||||
function load() {
|
||||
const html = fs.readFileSync(path.join(__dirname, '..', 'site', 'index.html'), 'utf8');
|
||||
function load(opts = {}) {
|
||||
const file = opts.file || path.join(__dirname, '..', 'site', 'index.html');
|
||||
const html = fs.readFileSync(file, 'utf8');
|
||||
const errors = [];
|
||||
const vc = new VirtualConsole();
|
||||
vc.on('jsdomError', (e) => {
|
||||
|
|
@ -19,6 +20,7 @@ function load() {
|
|||
virtualConsole: vc,
|
||||
beforeParse(window) {
|
||||
window.__TUBES_TEST__ = true;
|
||||
for (const [k, v] of Object.entries(opts.storage || {})) window.localStorage.setItem(k, v);
|
||||
window.Path2D = class { moveTo() {} quadraticCurveTo() {} closePath() {} };
|
||||
},
|
||||
});
|
||||
|
|
|
|||
51
tests/persist.test.js
Normal file
51
tests/persist.test.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const { load } = require('./harness');
|
||||
|
||||
const root = path.join(__dirname, '..');
|
||||
|
||||
function playedGame() {
|
||||
const a = load();
|
||||
a.ev("ACT.start({});ACT.launchBB({city:'fra'});for(let i=0;i<25;i++)dayTick();UI.speed=2;save()");
|
||||
return { a, saved: a.ev("localStorage.getItem('sot-save-v1')"), day: a.ev('S.day') };
|
||||
}
|
||||
|
||||
test('a reload drops you straight back into your saved network', () => {
|
||||
const { saved, day } = playedGame();
|
||||
const b = load({ storage: { 'sot-save-v1': saved } });
|
||||
assert.equal(b.ev('UI.started'), true);
|
||||
assert.equal(b.ev('S.day'), day);
|
||||
assert.equal(b.ev('UI.speed'), 2, 'game speed is remembered');
|
||||
assert.equal(b.ev("document.getElementById('modal').hidden"), true, 'no title screen in the way');
|
||||
assert.deepEqual(b.errors, []);
|
||||
});
|
||||
|
||||
test('leaving the page saves the game', () => {
|
||||
const a = load();
|
||||
a.ev("ACT.start({});for(let i=0;i<7;i++)dayTick();localStorage.removeItem('sot-save-v1')");
|
||||
a.ev("dispatchEvent(new Event('pagehide'))");
|
||||
assert.equal(JSON.parse(a.ev("localStorage.getItem('sot-save-v1')")).day, a.ev('S.day'));
|
||||
});
|
||||
|
||||
test('returning players see what is new after an update, once', () => {
|
||||
const { saved } = playedGame();
|
||||
execFileSync('bash', ['scripts/build.sh'], { cwd: root, env: { ...process.env, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
const file = path.join(root, '_site', 'index.html');
|
||||
const b = load({ file, storage: { 'sot-save-v1': saved, 'sot-seen-version': '1.0.0' } });
|
||||
const text = b.ev("document.getElementById('modalCard').textContent");
|
||||
assert.match(text, /New in Series of Tubes 1\.1\.0/);
|
||||
assert.match(text, /Spätzle-IX/);
|
||||
assert.equal(b.ev("localStorage.getItem('sot-seen-version')"), '1.1.0');
|
||||
const c = load({ file, storage: { 'sot-save-v1': saved, 'sot-seen-version': '1.1.0' } });
|
||||
assert.equal(c.ev("document.getElementById('modal').hidden"), true, 'not shown again');
|
||||
});
|
||||
|
||||
test('version comparison for the update banner', () => {
|
||||
const { ev } = load();
|
||||
assert.equal(ev("newerVer('1.2.0','1.1.0')"), true);
|
||||
assert.equal(ev("newerVer('1.10.0','1.9.3')"), true);
|
||||
assert.equal(ev("newerVer('1.1.0','1.1.0')"), false);
|
||||
assert.equal(ev("newerVer('1.0.9','1.1.0')"), false);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue