Object.assign(ACT,{
// Continue a network from the list (or the newest one).
cont:({id}={})=>{if(!slotOkId(id)){const t=slotTop(slotIdx(true));if(!t)return;id=t.id;}
if(id===UI.slot&&S&&!pzOn()){UI.started=true;closeModal();renderAll();return;}
slotOpen(id,false,()=>track('game_continue',true));},
// Back to the title with this network kept and saved.
toTitle:()=>{if(pzOn()){pzLeave();}slotLeave();gameClear();showTitle();},
slotBack:()=>{if(S&&UI.started)closeModal();else showTitle();},
// A damaged save, opened once more: if it loads, it is no longer damaged; if not, it is marked again.
slotRetry:({id})=>{const l=slotIdx(),e=l.find(x=>x.id===id);if(!e)return;e.broken=false;slotIdxPut(l);closeModal();ACT.cont({id});},
slotMenu:({id})=>{const h=slotMenuHtml(id);if(h)openModal(h);},
slotExport:({id})=>exportSlot(id),
slotDel:({id,back})=>{const e=slotIdx().find(x=>x.id===id);if(!e)return;
openModal(`
`);},
slotDelGo:({id,back})=>{if(!slotIdx().some(e=>e.id===id))return;
if(id===UI.slot){ACT.newgame();return;}
slotDrop(id);try{BC&&BC.postMessage({t:'gone',id});}catch(e){}sfx('click');
if(back==='space')openModal(slotSpaceHtml());else showTitle();},
slotSpace:()=>openModal(slotSpaceHtml()),
// The other window cannot be brought forward from here; it says hello when the player gets there.
slotSwitch:({id})=>{try{BC&&BC.postMessage({t:'focus',id});}catch(e){}const e=slotIdx().find(x=>x.id===id);showTitle();toast(tr('slots.name_is_waiting_in_your_other',{name:esc(e&&e.name||'')}),'goal');},
// Ask the other window to save and step aside, then open it here. Without an answer (it is frozen, or the browser has
// no BroadcastChannel) it is taken anyway after a moment: the other window stops writing the moment it notices.
slotTake:({id})=>{if(!slotOkId(id))return;const w=SLOT.wait={id,go:()=>{if(SLOT.wait!==w)return;SLOT.wait=null;clearTimeout(w.t);slotOpen(id,true);}};
w.t=setTimeout(w.go,BC?1500:0);try{if(BC)BC.postMessage({t:'take',id});}catch(e){w.go();}},
rename:()=>{if(!S||!UI.started||pzOn())return;openModal(`
`);},
// name: the new name as an argument (a server runs this without the sheet), else the sheet's field.
renameGo:({name}={})=>{const el=$('rnIn'),raw=typeof name==='string'?name:el?el.value:null;if(!S||raw===null||pzOn())return;const v=raw.replace(/\s+/g,' ').trim().slice(0,24);if(!v)return;S.name=v;closeModal();after();toast(tr('slots.renamed_to_name',{name:esc(v)}),'good');},
});
// No game on screen: the map stays empty behind the title.
function gameClear(){S=null;R=emptyR();UI.started=false;UI.sel=null;UI.nm=null;UI.confirm=null;$('dash').hidden=true;$('bankBox').hidden=true;renderAll();}
// Back from the title (or a puzzle) into a loaded network.
function gameResume(){UI.started=true;UI.sel=null;UI.confirm=null;$('dash').hidden=true;$('bankBox').hidden=true;setSpeed([0,0.5,1,2,4,8].includes(S.uiSpeed)?S.uiSpeed:1);
if(S.cam&&isFinite(S.cam.x))Object.assign(cam,S.cam);else{const h=CITY[S.home];if(h){cam.x=h.x;cam.y=h.y;cam.z=innerWidth<760?1.1:1.4;}}
closeModal();renderAll();toast(tr('loop.welcome_back_name_your_network_is',{name:esc(S.name),date:dateStr(S.day)}),'good');if(MP_API)mpResume();}