Show auto-accept countdowns only for ready offers
Hide the countdown when an offer has unmet requirements, missing locations, expired terms or insufficient service capacity. Keep manual acceptance available with its existing behavior. Share capacity previews across the Deals, city and fiber views, reuse them between automatic checks, and invalidate them after actions or incidents. Check changing requirements immediately and always perform a fresh full validation before automatically signing a contract. Add regression tests for blocked offers, requirements becoming fulfilled or unfulfilled, capacity changes and preview reuse. All 17 automation tests pass; the full independent branch passes 314 of 315 tests, with only the pre-existing locale-dependent subsea formatting failure remaining.
This commit is contained in:
parent
abe92fe3b1
commit
dd82737af8
6 changed files with 64 additions and 14 deletions
|
|
@ -6,7 +6,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- Toggle auto-accept in Deals to check ready sales every five real seconds, including their requirements and available service capacity, with a countdown beside each Accept button.
|
||||
- Toggle auto-accept in Deals to check ready sales every five real seconds, including their requirements and available service capacity, with a countdown beside eligible Accept buttons.
|
||||
- Toggle auto-pay repairs in the NOC to pay for affordable rush repairs automatically while the game runs.
|
||||
|
||||
## [1.35.0] — 2026-10-27
|
||||
|
|
|
|||
|
|
@ -3,9 +3,15 @@ const AUTO_SALES_MS=5000;
|
|||
function autoSalesSeconds(now=performance.now()){if(!S||!S.autoSales)return null;
|
||||
const left=UI.autoGame===S&&autoActive()?AUTO_SALES_MS-(now-UI.autoSalesAt):AUTO_SALES_MS;
|
||||
return Math.max(1,Math.min(AUTO_SALES_MS/1000,Math.ceil(left/1000)));}
|
||||
function autoAcceptLabel(){return tr('common.accept')+(S.autoSales?` <small data-auto-sales title="${esc(tr('automation.next_auto_check'))}">(${autoSalesSeconds()})</small>`:'');}
|
||||
function renderAutoCountdown(now=performance.now()){const n=autoSalesSeconds(now);if(UI.autoCount===n)return;UI.autoCount=n;
|
||||
for(const el of document.querySelectorAll('[data-auto-sales]'))el.textContent=n===null?'':`(${n})`;}
|
||||
function autoCountdownReady(o){if(!S||!S.autoSales||!o||!(o.exp>S.day)||!bCities(o).every(popUp)||!reqOk(o))return false;
|
||||
const inc=S.inc.map(i=>i.id).join('|');let c=UI.autoReady;
|
||||
// Share capacity trials between views and keep them until the next check, action or incident.
|
||||
if(!c||c.s!==S||c.at!==UI.autoSalesAt||c.inc!==inc||c.event!==S.nextEvent)c=UI.autoReady={s:S,at:UI.autoSalesAt,inc,event:S.nextEvent,offers:new Map()};
|
||||
if(!c.offers.has(o))c.offers.set(o,!!autoOffer(o));return c.offers.get(o);}
|
||||
function autoAcceptLabel(o){return tr('common.accept')+(S.autoSales?` <small data-auto-sales="${esc(o.id)}" title="${esc(tr('automation.next_auto_check'))}">${autoCountdownReady(o)?`(${autoSalesSeconds()})`:''}</small>`:'');}
|
||||
function renderAutoCountdown(now=performance.now()){const n=autoSalesSeconds(now);if(UI.autoCount===n&&UI.autoCountResult===R)return;UI.autoCount=n;UI.autoCountResult=R;
|
||||
const offers=new Map((S?S.offers:[]).map(o=>[o.id,o]));
|
||||
for(const el of document.querySelectorAll('[data-auto-sales]'))el.textContent=n!==null&&autoCountdownReady(offers.get(el.dataset.autoSales))?`(${n})`:'';}
|
||||
function offerCustomer(o){return {id:o.id,city:o.city,city2:o.city2||null,reqs:o.reqs||[],latMax:o.latMax||null,route:BIZ_T[o.type].scenic?'scenic':BIZ_T[o.type].lat?'fast':'normal',name:o.name,type:o.type,bw:o.bw,rate:o.rate,mood:100,since:S.day,sites:o.sites||null,start:o.start,dur:o.dur,fee:o.fee,link:o.link,slots:o.slots||0,what:o.what,prov:o.prov,due:BIZ_T[o.type].cap?S.day+o.win:undefined};}
|
||||
function autoOffer(o){if(!o||!own(BIZ_T,o.type)||!(o.exp>S.day)||!(o.bw>0)||o.rate<0||!bCities(o).length||!bCities(o).every(popUp)||!reqOk(o))return null;
|
||||
const T=BIZ_T[o.type],b=offerCustomer(o);if(T.event&&(!(o.start>S.day)||!(o.dur>0)))return null;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function chWhy(l,o){const O=OPT[o];if(O.lvl>lvl())return tr('action_helpers.unlo
|
|||
if((l.ch||[]).length+soldSlots(l)>=chMax(l))return soldSlots(l)?tr('action_helpers.sys_is_full_max_channels_sold',{sys:DF_SYS[l.sys].n,max:chMax(l),sold:soldSlots(l)}):tr('action_helpers.sys_is_full_max_channels',{sys:DF_SYS[l.sys].n,max:chMax(l)});
|
||||
for(const c of [l.a,l.b]){const p=S.pops[c];if(p&&RG[p.rgen||0].cls<O.rg)return tr('action_helpers.needs_routers_with_pn_ports_or',{pn:RG[mainRG(O.rg)].pn,city:CITY[c].name});}return '';}
|
||||
function bbCost(c){return 15000+CITY[c].P*20;}
|
||||
function after(){if(S)purgeInc();compute();checkGoals();renderAll();if(S&&!$('dash').hidden)renderDash();save();}
|
||||
function after(){UI.autoReady=null;if(S)purgeInc();compute();checkGoals();renderAll();if(S&&!$('dash').hidden)renderDash();save();}
|
||||
const isTablet=()=>innerWidth>760&&innerWidth<=1200;
|
||||
function selectLink(id){UI.sel={type:'link',id};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;$('panel').classList.remove('full');renderPanel();renderLeft();}
|
||||
function selectCity(c){UI.sel={type:'city',id:c};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;const P=$('panel');if(P)P.classList.remove('full');if(!S.pops[c])UI.tab='cust';renderPanel();}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function renderLeft(){checkLayer();
|
|||
if(!S.offers.length)h+=`<p class="empty">${tr('hud_and_panels.no_open_offers_right_now_businesses')}</p>`;
|
||||
for(const o of S.offers.slice().sort((a,b)=>a.exp-b.exp)){const has=bHas(o);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · <b>${bTerms(o)}</b> · ${tr('ui.n_d_left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('hud_and_panels.n_special_requirement',o.reqs.length)}`:''}</div>${reqList(o)}
|
||||
<div class="btns">${has?btn(autoAcceptLabel(),'accept',{id:o.id},'green sm'):btn(tr('common.go_there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('common.decline'),'decline',{id:o.id},'ghost sm')}</div>${has?'':`<div class="why">${tr('hud_and_panels.needs_a_pop_in_cities',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div></div>`;}
|
||||
<div class="btns">${has?btn(autoAcceptLabel(o),'accept',{id:o.id},'green sm'):btn(tr('common.go_there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('common.decline'),'decline',{id:o.id},'ghost sm')}</div>${has?'':`<div class="why">${tr('hud_and_panels.needs_a_pop_in_cities',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div></div>`;}
|
||||
}else if(UI.left==='noc'){
|
||||
h+=`<div class="btns" style="margin-bottom:8px">${btn(tr('hud_and_panels.open_noc_dashboard'),'dash',{},'pink')}${btn(tr('common.connections'),'connOpen',{},'')}${btn(tr('common.traceroute'),'trace',{},'')}</div>`;
|
||||
h+=`<p class="lead">${tr('hud_and_panels.your_network_operations_center_every')}</p>`;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ function dfPanel(l){
|
|||
if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l);
|
||||
h+=`<section><h3>${tr('link_panels.selling_spare_capacity')}</h3><p class="lead">${tr('link_panels.other_carriers_rent_what_you_do')}</p>
|
||||
<div class="kv"><span>${tr('common.free_channels')}</span><b>${fc} / ${chMax(l)}</b></div>${sold.map(b=>`<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}</div></div></div>`).join('')}
|
||||
${off?`<div class="row"><div class="grow"><div class="nm">${esc(off.name)}</div><div class="meta">${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}</div></div>${btn(autoAcceptLabel(),'accept',{id:off.id},'pink sm')}</div>`:fc>=1||pairFree(l)?`<div class="btns">${btn(tr('link_panels.list_it_with_a_capacity_broker'),'advertise',{id:l.id},'sm')}</div>`:`<p class="note">${tr('link_panels.nothing_spare_to_sell_on_this')}</p>`}</section>`;}
|
||||
${off?`<div class="row"><div class="grow"><div class="nm">${esc(off.name)}</div><div class="meta">${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}</div></div>${btn(autoAcceptLabel(off),'accept',{id:off.id},'pink sm')}</div>`:fc>=1||pairFree(l)?`<div class="btns">${btn(tr('link_panels.list_it_with_a_capacity_broker'),'advertise',{id:l.id},'sm')}</div>`:`<p class="note">${tr('link_panels.nothing_spare_to_sell_on_this')}</p>`}</section>`;}
|
||||
h+=`<section><h3>${tr('common.optics')}</h3><p class="lead">${tr('link_panels.each_channel_is_a_pair_of')}</p>`;
|
||||
if(l.own&&l.sub)h+=subUpgradePanel(l);
|
||||
for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k);
|
||||
|
|
@ -93,7 +93,7 @@ function dfPanel(l){
|
|||
}
|
||||
function offersHere(c){
|
||||
const os=S.offers.filter(o=>bCities(o).includes(c));if(!os.length)return '';
|
||||
return `<section><h3>${tr('common.offers_here')}</h3>${os.map(o=>`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>${R.reach<0.99&&!BIZ_T[o.type].l2?`<div class="why">${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}</div>`:''}${o.type==='scrub'&&!hasScrub()?`<div class="why">${tr('link_panels.needs_your_own_scrubbing_center')}</div>`:''}${reqList(o)}${bHas(o)?'':`<div class="why">${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div>${bHas(o)?btn(autoAcceptLabel(),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}</div>`).join('')}</section>`;
|
||||
return `<section><h3>${tr('common.offers_here')}</h3>${os.map(o=>`<div class="row"><div class="grow"><div class="nm">${esc(o.name)}</div><div class="meta">${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}</div>${R.reach<0.99&&!BIZ_T[o.type].l2?`<div class="why">${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}</div>`:''}${o.type==='scrub'&&!hasScrub()?`<div class="why">${tr('link_panels.needs_your_own_scrubbing_center')}</div>`:''}${reqList(o)}${bHas(o)?'':`<div class="why">${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}</div>`}</div>${bHas(o)?btn(autoAcceptLabel(o),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}</div>`).join('')}</section>`;
|
||||
}
|
||||
function linkPanel(id){
|
||||
const l=S.links.find(x=>x.id===id);if(!l){UI.sel=null;return '';}
|
||||
|
|
|
|||
|
|
@ -44,14 +44,16 @@ test('Accept buttons share a real-time countdown in Deals, city offers and fiber
|
|||
assert.equal(dom.window.document.querySelectorAll('[data-auto-sales]').length, 0);
|
||||
ev("ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
|
||||
const counts = () => [...dom.window.document.querySelectorAll('[data-auto-sales]')];
|
||||
assert.ok(counts().length >= 2, 'Deals and the city panel both show it');
|
||||
assert.ok(counts().every(el => el.textContent === '(5)'));
|
||||
const readyCounts = () => counts().filter(el => el.dataset.autoSales === 'ready');
|
||||
assert.ok(readyCounts().length >= 2, 'Deals and the city panel both show it');
|
||||
assert.ok(readyCounts().every(el => el.textContent === '(5)'));
|
||||
assert.ok(counts().filter(el => el.dataset.autoSales === 'waiting').every(el => el.textContent === ''), 'unmet requirements have no countdown');
|
||||
ev('testNow=2001;renderAutoCountdown()');
|
||||
assert.ok(counts().every(el => el.textContent === '(4)'));
|
||||
assert.ok(readyCounts().every(el => el.textContent === '(4)'));
|
||||
ev('testNow=3000;UI.speed=8;renderAutoCountdown()');
|
||||
assert.ok(counts().every(el => el.textContent === '(3)'));
|
||||
assert.ok(readyCounts().every(el => el.textContent === '(3)'));
|
||||
ev('UI.speed=0.5;renderAll();renderAutoCountdown()');
|
||||
assert.ok(counts().every(el => el.textContent === '(3)'), 'game speed and re-rendering leave the real-time clock alone');
|
||||
assert.ok(readyCounts().every(el => el.textContent === '(3)'), 'game speed and re-rendering leave the real-time clock alone');
|
||||
assert.match(dom.window.document.querySelector('#leftBody [data-act="accept"]').textContent, /Accept \(3\)/);
|
||||
ev("ACT.buildPop({city:'ams'});S.links.push({id:'fiber',a:'fra',b:'ams',kind:'df',sys:'lite',ch:[],own:true,km:450,ready:0,cut:0,mo:1})");
|
||||
offer(ev, 'broker', { type: 'wwave', city2: 'ams', link: 'fiber', slots: 1, what: 'One wave' });
|
||||
|
|
@ -62,13 +64,55 @@ test('Accept buttons share a real-time countdown in Deals, city offers and fiber
|
|||
ev('testNow=6000;automationTick(testNow);renderAutoCountdown()');
|
||||
assert.equal(ev("S.biz.some(b=>b.id==='ready')"), true);
|
||||
assert.equal(ev("S.offers.some(o=>o.id==='waiting')"), true, 'the countdown does not bypass requirements');
|
||||
assert.ok(counts().every(el => el.textContent === '(5)'), 'the next check starts a fresh countdown');
|
||||
offer(ev, 'next-ready');
|
||||
ev('renderAll();renderAutoCountdown()');
|
||||
assert.ok(counts().filter(el => el.dataset.autoSales === 'next-ready').every(el => el.textContent === '(5)'), 'the next check starts a fresh countdown');
|
||||
ev("ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
|
||||
assert.equal(counts().length, 0);
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('only ready offers get a countdown, including after requirements or capacity change', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev);
|
||||
offer(ev, 'ready');
|
||||
offer(ev, 'needs-generator', { reqs: ['gen'] });
|
||||
offer(ev, 'too-big', { bw: 1000 });
|
||||
offer(ev, 'expired', { exp: 0 });
|
||||
ev("window.testNow=1000;performance.now=()=>testNow;ACT.leftTab({t:'deals'});ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
|
||||
const count = id => dom.window.document.querySelector(`#leftBody [data-auto-sales="${id}"]`).textContent;
|
||||
assert.equal(count('ready'), '(5)');
|
||||
assert.equal(count('needs-generator'), '');
|
||||
assert.equal(count('too-big'), '');
|
||||
assert.equal(count('expired'), '');
|
||||
ev('S.pops.fra.gen=true;after()');
|
||||
assert.equal(count('needs-generator'), '(5)', 'becoming eligible shows the timer');
|
||||
ev('S.pops.fra.gen=false;compute();renderAutoCountdown()');
|
||||
assert.equal(count('needs-generator'), '', 'a requirement becoming false hides it immediately');
|
||||
ev("S.offers.find(o=>o.id==='too-big').bw=2;after()");
|
||||
assert.equal(count('too-big'), '(5)', 'actions invalidate the capacity preview');
|
||||
ev('testNow=6000;automationTick(testNow);renderAutoCountdown()');
|
||||
assert.equal(ev("S.offers.some(o=>o.id==='needs-generator')"), true, 'acceptance checks requirements again');
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('readiness trials are shared between views and are not repeated for every redraw', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev);
|
||||
offer(ev, 'ready');
|
||||
ev("window.testNow=1000;performance.now=()=>testNow;ACT.leftTab({t:'deals'});UI.sel={type:'city',id:'fra'};UI.tab='cust';window.originalAutoOffer=autoOffer;window.trials=0;window.autoOffer=o=>{trials++;return originalAutoOffer(o)};ACT.autoToggle({k:'autoSales'})");
|
||||
assert.equal(ev('trials'), 1);
|
||||
ev('renderAll();compute();renderAll();renderAutoCountdown()');
|
||||
assert.equal(ev('trials'), 1, 'ordinary routing refreshes reuse the preview');
|
||||
ev('after()');
|
||||
assert.equal(ev('trials'), 2, 'a real action refreshes readiness');
|
||||
ev('window.autoOffer=originalAutoOffer');
|
||||
assert.deepEqual(errors, []);
|
||||
dom.window.close();
|
||||
});
|
||||
|
||||
test('auto-accept leaves unready and expired offers alone without failure notifications', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
setup(ev);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue