fix(map): drop the last network's floaters when another one starts
Floaters ("New POP!", payday money) live in FLOATS and fade on the map's
animation clock, which only runs while the game does. A new network
whose clock stands still (the agent's clock on the development page)
kept the previous network's floaters frozen over its map until a reload:
hundreds of them after a payday on a big network at 8x.
Each floater now records the network that raised it, and the map drops
any that belong to another one (new game, another slot, import, puzzle,
title screen). Same code for the 2D and WebGL maps.
This commit is contained in:
parent
dd6e4f4f8a
commit
fca11b39d2
5 changed files with 24 additions and 4 deletions
|
|
@ -6,6 +6,8 @@ All notable changes to this project are documented here. The project follows
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Starting a new network no longer leaves the last one's "New POP!" and money pop-ups frozen all over the map until a reload.
|
||||||
|
|
||||||
## [2.10.1] — 2026-11-05
|
## [2.10.1] — 2026-11-05
|
||||||
|
|
||||||
- "Meet halfway" on a renewal now offers the price halfway between what the customer pays and what they ask, and the button shows it before you press (#293).
|
- "Meet halfway" on a renewal now offers the price halfway between what the customer pays and what they ask, and the button shows it before you press (#293).
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,6 @@ const CLOUDS=Array.from({length:7},(_,i)=>({x:R1()*W,y:60+R1()*(H-120),s:.7+R1()
|
||||||
const FLOATS=[];
|
const FLOATS=[];
|
||||||
// Stamped with the map's animation clock, which stops while paused: on the real clock, every floater born after a
|
// Stamped with the map's animation clock, which stops while paused: on the real clock, every floater born after a
|
||||||
// pause lingered off-screen for as long as the pause had lasted, and paydays piled up hundreds of them.
|
// pause lingered off-screen for as long as the pause had lasted, and paydays piled up hundreds of them.
|
||||||
function floater(x,y,text,col){if(!animOn()||UI.mapHid)return;FLOATS.push({x,y,text,col,t:animT});}
|
// Each belongs to the network that raised it (s): a new game starts paused, and the last one's, frozen with the clock,
|
||||||
|
// stayed on its map until a reload.
|
||||||
|
function floater(x,y,text,col){if(!animOn()||UI.mapHid)return;FLOATS.push({x,y,text,col,t:animT,s:S});}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ function drawFrame(now){
|
||||||
// the chaos monkey (woken here after a reload, wherever it last snipped)
|
// the chaos monkey (woken here after a reload, wherever it last snipped)
|
||||||
if(UI.mk)mkDraw(ks);else if(mkOn()&&!pzOn()&&CITY[S.monkey.c])mkStart(S.monkey.c);
|
if(UI.mk)mkDraw(ks);else if(mkOn()&&!pzOn()&&CITY[S.monkey.c])mkStart(S.monkey.c);
|
||||||
// floaters
|
// floaters
|
||||||
for(let i=FLOATS.length-1;i>=0;i--){const f=FLOATS[i],a=(now-f.t)/1600;if(a>1){FLOATS.splice(i,1);continue;}
|
for(let i=FLOATS.length-1;i>=0;i--){const f=FLOATS[i],a=(now-f.t)/1600;if(a>1||f.s!==S){FLOATS.splice(i,1);continue;}
|
||||||
const font='800 17px "Baloo 2", sans-serif';if(f.w===undefined){ctx.font=font;f.w=ctx.measureText(f.text).width;}
|
const font='800 17px "Baloo 2", sans-serif';if(f.w===undefined){ctx.font=font;f.w=ctx.measureText(f.text).width;}
|
||||||
for(const k of ks){const [sx,sy]=toS(f.x,f.y,k);ctx.globalAlpha=1-a*a;textStamp(f.text,font,17,f.w,f.col,'#fff',4,sx,sy-a*40);ctx.globalAlpha=1;}}
|
for(const k of ks){const [sx,sy]=toS(f.x,f.y,k);ctx.globalAlpha=1-a*a;textStamp(f.text,font,17,f.w,f.col,'#fff',4,sx,sy-a*40);ctx.globalAlpha=1;}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,7 @@ test('the 2D map paints its pictures again for a new pixel density', () => {
|
||||||
test('money pop-ups on the 2D map fade out as before', () => {
|
test('money pop-ups on the 2D map fade out as before', () => {
|
||||||
const { ev, errors } = open();
|
const { ev, errors } = open();
|
||||||
const C = 'CITY[S.home]';
|
const C = 'CITY[S.home]';
|
||||||
ev(`cam.x=${C}.x;cam.y=${C}.y;cam.z=1;__T+=16;FLOATS.push({x:${C}.x,y:${C}.y,text:'+$1,234',col:'#16A866',t:__T});`);
|
ev(`cam.x=${C}.x;cam.y=${C}.y;cam.z=1;__T+=16;FLOATS.push({x:${C}.x,y:${C}.y,text:'+$1,234',col:'#16A866',s:S,t:__T});`);
|
||||||
// At 0, 40% and 80% of its life: drawn at opacity 1-a².
|
// At 0, 40% and 80% of its life: drawn at opacity 1-a².
|
||||||
const alphas = [];
|
const alphas = [];
|
||||||
for (const a of [0, 0.4, 0.8]) {
|
for (const a of [0, 0.4, 0.8]) {
|
||||||
|
|
@ -282,7 +282,7 @@ test('money pop-ups on the 2D map fade out as before', () => {
|
||||||
ev(`__M2D.frame(FLOATS[FLOATS.length-1].t+1700)`);
|
ev(`__M2D.frame(FLOATS[FLOATS.length-1].t+1700)`);
|
||||||
assert.equal(ev('FLOATS.length'), 0, 'gone after its life');
|
assert.equal(ev('FLOATS.length'), 0, 'gone after its life');
|
||||||
// The same text in two colours at once: two pictures, each in its own colour.
|
// The same text in two colours at once: two pictures, each in its own colour.
|
||||||
ev(`FLOATS.push({x:${C}.x,y:${C}.y,text:'+$500',col:'#16A866',t:5000},{x:${C}.x+40,y:${C}.y,text:'+$500',col:'#FF4D5E',t:5000});`);
|
ev(`FLOATS.push({x:${C}.x,y:${C}.y,text:'+$500',col:'#16A866',s:S,t:5000},{x:${C}.x+40,y:${C}.y,text:'+$500',col:'#FF4D5E',s:S,t:5000});`);
|
||||||
const r = JSON.parse(ev('JSON.stringify(__M2D.pair(5400))'));
|
const r = JSON.parse(ev('JSON.stringify(__M2D.pair(5400))'));
|
||||||
assert.deepEqual(problems(r, 'two pop-ups'), []);
|
assert.deepEqual(problems(r, 'two pop-ups'), []);
|
||||||
assert.deepEqual(errors, []);
|
assert.deepEqual(errors, []);
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,22 @@ test('payday money floaters fade after a long pause instead of piling up', () =>
|
||||||
assert.deepEqual(errors, []);
|
assert.deepEqual(errors, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a new network starts without the last one's money floating over its map", () => {
|
||||||
|
const { ev, errors } = load();
|
||||||
|
bigNet(ev);
|
||||||
|
ev("closeModal();ACT.animSet({v:'on'});setPref('pauseFurious',false);setPref('pauseIncident',false);window.__clk=5000;performance.now=()=>__clk;last=__clk;UI.speed=1");
|
||||||
|
const run = (ms) => { for (let t = 0; t < ms; t += 16) ev('__clk+=16;frame(__clk)'); };
|
||||||
|
run(2000);
|
||||||
|
ev('while(cal(S.day+1).d!==1)dayTick();acc=DAY_MS');
|
||||||
|
run(16);
|
||||||
|
assert.ok(ev('FLOATS.length') > 0, 'payday shows the money');
|
||||||
|
// A new game straight away: it waits, paused, for the player's first POP, and the clock of the floaters with it.
|
||||||
|
ev("ACT.newgame();ACT.start({});closeModal();UI.speed=0");
|
||||||
|
run(100);
|
||||||
|
assert.equal(ev('FLOATS.length'), 0, "the old network's floaters are gone");
|
||||||
|
assert.deepEqual(errors, []);
|
||||||
|
});
|
||||||
|
|
||||||
test('the map is not drawn while the dashboard covers the whole screen', () => {
|
test('the map is not drawn while the dashboard covers the whole screen', () => {
|
||||||
const { ev, errors } = load();
|
const { ev, errors } = load();
|
||||||
bigNet(ev);
|
bigNet(ev);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue