Merge #158: smoother huge networks, map and autosave (huguesdelamure)
Capacity deals now record customer names with useName() too, and the #156 CHANGELOG bullet moves to Unreleased where it belongs.
This commit is contained in:
commit
4c499de742
14 changed files with 130 additions and 23 deletions
|
|
@ -30,6 +30,38 @@ test('leaving the page saves the game', () => {
|
|||
assert.equal(JSON.parse(a.ev("localStorage.getItem('sot-save-v1')")).day, a.ev('S.day'));
|
||||
});
|
||||
|
||||
test('a save too big for the browser is not retried every few seconds, but leaving still tries', () => {
|
||||
const a = load();
|
||||
// A storage that counts tries and refuses the game save, like a full quota.
|
||||
a.ev(`window.__tries=0;window.__full=true;const P=Object.getPrototypeOf(localStorage),set=P.setItem;
|
||||
P.setItem=function(k,v){if(k==='sot-save-v1'){__tries++;if(__full){const e=new Error('full');e.name='QuotaExceededError';throw e;}}return set.call(this,k,v);};
|
||||
ACT.start({});for(let i=0;i<7;i++)dayTick();__tries=0;UI.saveFail=null;save()`);
|
||||
assert.equal(a.ev('__tries'), 1);
|
||||
a.ev('save();save();after()');
|
||||
assert.equal(a.ev('__tries'), 1, 'autosaves wait after a failure');
|
||||
a.ev("dispatchEvent(new Event('pagehide'))");
|
||||
assert.equal(a.ev('__tries'), 2, 'leaving the page still tries');
|
||||
assert.equal(a.ev('UI.saveFail.wait'), 120000, 'and each failure waits longer');
|
||||
a.ev('__full=false;UI.saveFail.at-=120001;save()');
|
||||
assert.equal(a.ev('__tries'), 3, 'tried again once the wait is over');
|
||||
assert.equal(JSON.parse(a.ev("localStorage.getItem('sot-save-v1')")).day, a.ev('S.day'));
|
||||
assert.equal(a.ev('UI.saveFail'), null);
|
||||
a.ev('save()');
|
||||
assert.equal(a.ev('__tries'), 4, 'a save that works keeps saving every time');
|
||||
a.ev('__full=true;save();S=migrate(JSON.parse(JSON.stringify(S)));save()');
|
||||
assert.equal(a.ev('__tries'), 6, 'another game (a new state) tries at once');
|
||||
});
|
||||
|
||||
test('customer names already used are remembered once each, and old saves shrink on load', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.usedNames=['A','B','A','A',7,'B'];S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.usedNames)')), ['A', 'B']);
|
||||
ev("for(let i=0;i<400;i++)dayTick()");
|
||||
const u = JSON.parse(ev('JSON.stringify(S.usedNames)'));
|
||||
assert.equal(new Set(u).size, u.length, 'no name twice');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('returning players see what is new after an update, once', () => {
|
||||
const { saved } = playedGame();
|
||||
execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, env: { ...process.env, OUT, VERSION: '1.1.0', BUILD_DATE: '2026-10-23' } });
|
||||
|
|
|
|||
|
|
@ -100,6 +100,52 @@ test('the map draws a big network at every zoom, with a city or a link selected'
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('the map keeps fiber capacities for one frame only, and skips links above or below the screen', () => {
|
||||
const { ev, errors } = load();
|
||||
bigNet(ev);
|
||||
ev("S.links.push({id:'dfT',a:'fra',b:'ams',kind:'df',own:true,km:kmBetween('fra','ams'),ready:0,ch:['zr4']});compute()");
|
||||
ev('cam.x=CITY.fra.x;cam.y=CITY.fra.y;cam.z=2;draw(0)');
|
||||
assert.equal(ev('DFC'), null, 'nothing is kept between frames');
|
||||
const cap = ev("dfCap(S.links.find(l=>l.id==='dfT'))");
|
||||
ev("S.links.find(l=>l.id==='dfT').ch.push('zr4');draw(0)");
|
||||
assert.equal(ev("dfCap(S.links.find(l=>l.id==='dfT'))"), 2 * cap, 'a new channel counts on the next frame');
|
||||
ev("ctx.fillText=()=>{throw new Error('boom')}");
|
||||
assert.throws(() => ev('draw(0)'));
|
||||
ev('delete ctx.fillText');
|
||||
assert.equal(ev('DFC'), null, 'not even after a frame that failed');
|
||||
// The whole network far above the screen: the links cost nothing, as if there were none.
|
||||
const calls = (body) => ev(`(()=>{cam.x=CITY.fra.x;cam.y=CITY.fra.y+${'2000'};cam.z=2;${body};const n=ctx.calls.n;draw(0);return ctx.calls.n-n;})()`);
|
||||
const withLinks = calls(''), links = ev('JSON.stringify(S.links)');
|
||||
assert.equal(withLinks, calls('S.links=[]'));
|
||||
ev(`S.links=JSON.parse(${JSON.stringify(links)})`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('a map with more than MAP_BUSY lines on screen leaves out link labels and fiber dots, and they come back', () => {
|
||||
const { ev, errors } = load();
|
||||
bigNet(ev);
|
||||
// Spy on the two things that go: the dotted line on lit fiber and the link labels.
|
||||
ev("window.__dots=0;window.__labels=[];ctx.setLineDash=d=>{if(d.length===2&&d[0]===1&&d[1]===6)__dots++;};ctx.fillText=t=>{if(/ DF$/.test(t))__labels.push(t);}");
|
||||
const frame = () => ev("__dots=0;__labels=[];draw(0);JSON.stringify([__dots,__labels.length])");
|
||||
const view = "cam.x=(CITY.fra.x+CITY.lon.x)/2;cam.y=(CITY.fra.y+CITY.lon.y)/2;cam.z=1.6;";
|
||||
const lines = () => ev("(()=>{const PI=pairIdx();return linesOnScreen(linkGroups().map(g=>linkGeom(g[0],PI.get(edgeKey(g[0])))),visibleKs());})()");
|
||||
ev("const ps=[['fra','ams'],['ams','lon'],['lon','par'],['par','fra'],['fra','lon'],['ams','par']];for(let i=0;i<20;i++){const [a,b]=ps[i%6];S.links.push({id:'dfB'+i,a,b,kind:'df',own:true,km:kmBetween(a,b),ready:0,ch:['zr4']});}compute()");
|
||||
ev(view);
|
||||
assert.ok(lines() < ev('MAP_BUSY'));
|
||||
const [dots, labels] = JSON.parse(frame());
|
||||
assert.ok(dots >= 20 && labels >= 20, 'a normal map shows them');
|
||||
ev("const ps2=[['fra','ams'],['ams','lon'],['lon','par'],['par','fra'],['fra','lon'],['ams','par']];for(let i=20;i<MAP_BUSY+20;i++){const [a,b]=ps2[i%6];S.links.push({id:'dfB'+i,a,b,kind:'df',own:true,km:kmBetween(a,b),ready:0,ch:['zr4']});}compute()");
|
||||
ev(view);
|
||||
assert.ok(lines() > ev('MAP_BUSY'));
|
||||
assert.equal(frame(), '[0,0]', 'a tangle of lines does not');
|
||||
ev("UI.sel={type:'link',id:'dfB3'}");
|
||||
assert.equal(frame(), '[0,1]', 'except the label of the selected link');
|
||||
ev("UI.sel=null;S.links=S.links.filter(l=>!/^dfB/.test(l.id)||+l.id.slice(3)<20);compute()");
|
||||
ev(view);
|
||||
assert.deepEqual(JSON.parse(frame()), [dots, labels], 'back as soon as fewer lines show');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('long lists in the NOC dashboard show 100 rows at a time and grow on request', () => {
|
||||
const { ev, errors } = load();
|
||||
bigNet(ev);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue