Tell the player when the game cannot save (#176)
This commit is contained in:
parent
1e1864a173
commit
cbe11339a7
9 changed files with 55 additions and 3 deletions
|
|
@ -13,10 +13,10 @@ Object.assign(ACT,{
|
|||
importPick:()=>{let f=$('importIn');if(!f){f=document.createElement('input');f.type='file';f.accept='.json,application/json';f.id='importIn';f.hidden=true;document.body.appendChild(f);f.addEventListener('change',()=>{importFile(f.files[0]);f.value='';});}f.click();},
|
||||
importGo:()=>{const s0=UI.importing;if(!s0)return;UI.importing=null;const prev=S;try{S=migrate(JSON.parse(JSON.stringify(s0)));compute();checkGoals();renderAll();}catch(e){S=prev;if(S)compute();renderAll();toast(tr('game_and_settings.import_failed_that_save_is_damaged'),'bad');sfx('err');return;}UI.confirm=null;$('bankBox').hidden=true;$('dash').hidden=true;UI.started=true;UI.sel=null;UI.speed=S.uiSpeed===undefined?1:S.uiSpeed;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;}}closeModal();$('modal').hidden=true;compute();renderAll();save();toast(tr('game_and_settings.welcome_back_name_imported_and_saved',{name:esc(S.name)}),'good');sfx('coin');track('game_import');},
|
||||
menu:()=>{if(!S||!UI.started){showTitle();return;}openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">AS${S.asn} · ${esc(dateStr(S.day))} · ${tierLabel()}</div><h2 style="font-size:28px">${esc(S.name)}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>
|
||||
<p class="tagline">${tr('game_and_settings.your_game_saves_itself_every_few')}</p>${isPhone()?installRow():''}
|
||||
${saveFailing()?`<p class="why">${saveFailMsg()}</p>`:`<p class="tagline">${tr('game_and_settings.your_game_saves_itself_every_few')}</p>`}${isPhone()?installRow():''}
|
||||
<div class="menu-list">
|
||||
${btn(tr('common.back_to_the_map'),'closeModal',{},'pink big')}
|
||||
${btn(tr('game_and_settings.export_save_download_a_file'),'exportSave',{},'')}
|
||||
${btn(tr('game_and_settings.export_save_download_a_file'),'exportSave',{},saveFailing()?'pink':'')}
|
||||
${btn(tr('game_and_settings.import_a_save_from_a_file'),'importPick',{},'')}
|
||||
${btn(tr('game_and_settings.share_your_network_image_card'),'share',{},'')}
|
||||
${btn(tr('game_and_settings.scenarios_amp_weekly_challenge'),'scenarios',{},'ghost')}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,14 @@
|
|||
function save(force){if(!S||S.lost)return;S.uiSpeed=UI.speed;S.cam={x:cam.x,y:cam.y,z:cam.z};const f=UI.saveFail;
|
||||
if(!force&&f&&f.s===S&&performance.now()-f.at<f.wait){UI.lastSave=performance.now();return;}
|
||||
try{localStorage.setItem('sot-save-v1',JSON.stringify(S));UI.saveFail=null;}
|
||||
catch(e){UI.saveFail={s:S,at:performance.now(),wait:f&&f.s===S?Math.min(300000,f.wait*2):60000};}
|
||||
catch(e){const again=f&&f.s===S;UI.saveFail={s:S,at:performance.now(),wait:again?Math.min(300000,f.wait*2):60000,full:saveFull(e)};
|
||||
// Say so once per game (#176): a save that silently fails loses everything since the last one that worked.
|
||||
if(!again)toast(saveFailMsg(),'bad',[{l:tr('common.export_save'),act:'exportSave',args:{}}]);}
|
||||
UI.lastSave=performance.now();}
|
||||
// Out of room (quota) or not allowed to store at all (private window, blocked site data): different advice.
|
||||
const saveFull=e=>!!e&&(e.name==='QuotaExceededError'||e.name==='NS_ERROR_DOM_QUOTA_REACHED'||e.code===22||e.code===1014);
|
||||
const saveFailing=()=>!!(UI.saveFail&&UI.saveFail.s===S);
|
||||
const saveFailMsg=()=>UI.saveFail&&UI.saveFail.full?tr('save.your_network_is_too_big_to'):tr('save.this_browser_is_not_letting_the');
|
||||
// Save whenever the player might be leaving: tab hidden, page closing or reloading.
|
||||
addEventListener('pagehide',()=>save(true));
|
||||
document.addEventListener('visibilitychange',()=>{if(document.visibilityState==='hidden')save(true);else checkUpdate();});
|
||||
|
|
|
|||
|
|
@ -2717,7 +2717,9 @@
|
|||
"save.that_file_is_too_big_to":"<b>That file is too big to be a save.</b>",
|
||||
"save.that_network_went_bankrupt_it_cannot":"That network went bankrupt. It cannot be brought back, only mourned.",
|
||||
"save.that_save_has_a_pop_in":"That save has a POP in a city this version does not know ({city}).",
|
||||
"save.this_browser_is_not_letting_the":"<b>Your game is not being saved.</b> This browser is not letting the game store anything (a private window, or site data turned off). Export a save to keep your network.",
|
||||
"save.this_replaces_name_export_it_first":"This replaces {name}. Export it first if you want to keep it.",
|
||||
"save.your_network_is_too_big_to":"<b>Your game is not being saved.</b> Your network has grown too big for this browser's storage. Export a save now and keep the file: it is your backup.",
|
||||
"scenario_progress.goal_goal_time_d_days_start":"<b>Goal:</b> {goal} · <b>Time:</b> {d} days · start in {city}",
|
||||
"scenario_progress.goal_was_not_reached_in_d":"{goal} was not reached in {d} days. Keep playing this network as free play, or try again.",
|
||||
"scenario_progress.just_in_time":"Just in time.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue