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
|
|
@ -17,6 +17,7 @@ All notable changes to this project are documented here. The project follows
|
|||
- Maps with more than a thousand lines on screen draw about twice as fast: they leave out the link labels and the dots on lit fiber, which nobody could read in such a tangle. Zoom in and they come back; the selected link keeps its label.
|
||||
- The map of a huge network spends less time working out fiber capacities on every frame, and skips links above or below the screen.
|
||||
- Big networks with thousands of fiber customers no longer stall: each game day and each action is about two to three times faster, and new alien-wave offers no longer freeze the game for a moment.
|
||||
- The game now tells you when it cannot save: a network too big for the browser's storage, or a browser that blocks it, used to stop saving without a word (#176). Export a save from the warning to keep a backup.
|
||||
|
||||
## [1.34.1] — 2026-10-27
|
||||
|
||||
|
|
|
|||
|
|
@ -2716,7 +2716,9 @@
|
|||
"save.that_file_is_too_big_to":"<b>Ese archivo es demasiado grande para ser una partida.</b>",
|
||||
"save.that_network_went_bankrupt_it_cannot":"Esa red quebró. No se puede recuperar, solo llorar.",
|
||||
"save.that_save_has_a_pop_in":"Esa partida tiene un POP en una ciudad que esta versión no conoce ({city}).",
|
||||
"save.this_browser_is_not_letting_the":"<b>Tu partida no se está guardando.</b> Este navegador no deja que el juego guarde nada (ventana privada o datos de sitios desactivados). Exporta una partida para no perder tu red.",
|
||||
"save.this_replaces_name_export_it_first":"Esto reemplaza a {name}. Expórtala primero si quieres conservarla.",
|
||||
"save.your_network_is_too_big_to":"<b>Tu partida no se está guardando.</b> Tu red se ha vuelto demasiado grande para el almacenamiento de este navegador. Exporta una partida ahora y guarda el archivo: es tu copia de seguridad.",
|
||||
"scenario_progress.goal_goal_time_d_days_start":"<b>Objetivo:</b> {goal} · <b>Tiempo:</b> {d} días · empiezas en {city}",
|
||||
"scenario_progress.goal_was_not_reached_in_d":"{goal} no se logró en {d} días. Sigue jugando esta red en modo libre, o inténtalo de nuevo.",
|
||||
"scenario_progress.just_in_time":"Justo a tiempo.",
|
||||
|
|
|
|||
|
|
@ -2716,7 +2716,9 @@
|
|||
"save.that_file_is_too_big_to":"<b>Ce fichier est trop gros pour être une sauvegarde.</b>",
|
||||
"save.that_network_went_bankrupt_it_cannot":"Ce réseau a fait faillite. Impossible de le ressusciter, on ne peut que le pleurer.",
|
||||
"save.that_save_has_a_pop_in":"Cette sauvegarde a un POP dans une ville que cette version ne connaît pas ({city}).",
|
||||
"save.this_browser_is_not_letting_the":"<b>Votre partie n'est pas sauvegardée.</b> Ce navigateur n'autorise pas le jeu à stocker quoi que ce soit (fenêtre privée ou données de sites désactivées). Exportez une sauvegarde pour garder votre réseau.",
|
||||
"save.this_replaces_name_export_it_first":"Cela remplace {name}. Exporte-le d’abord si tu veux le garder.",
|
||||
"save.your_network_is_too_big_to":"<b>Votre partie n'est pas sauvegardée.</b> Votre réseau est devenu trop gros pour le stockage de ce navigateur. Exportez une sauvegarde maintenant et gardez le fichier : c'est votre copie de secours.",
|
||||
"scenario_progress.goal_goal_time_d_days_start":"<b>Objectif :</b> {goal} · <b>Durée :</b> {d} jours · départ à {city}",
|
||||
"scenario_progress.goal_was_not_reached_in_d":"Objectif non atteint en {d} jours : {goal}. Continue avec ce réseau en partie libre, ou réessaie.",
|
||||
"scenario_progress.just_in_time":"Juste à temps.",
|
||||
|
|
|
|||
|
|
@ -2716,7 +2716,9 @@
|
|||
"save.that_file_is_too_big_to":"<b>Quel file è troppo grande per essere un salvataggio.</b>",
|
||||
"save.that_network_went_bankrupt_it_cannot":"Quella rete è finita in bancarotta. Non si può resuscitare, solo piangere.",
|
||||
"save.that_save_has_a_pop_in":"Quel salvataggio ha un POP in una città che questa versione non conosce ({city}).",
|
||||
"save.this_browser_is_not_letting_the":"<b>La partita non viene salvata.</b> Questo browser non permette al gioco di salvare nulla (finestra privata o dati dei siti disattivati). Esporta un salvataggio per non perdere la tua rete.",
|
||||
"save.this_replaces_name_export_it_first":"Sostituisce {name}. Esportala prima, se vuoi tenerla.",
|
||||
"save.your_network_is_too_big_to":"<b>La partita non viene salvata.</b> La tua rete è diventata troppo grande per lo spazio di questo browser. Esporta un salvataggio adesso e tieni il file: è il tuo backup.",
|
||||
"scenario_progress.goal_goal_time_d_days_start":"<b>Obiettivo:</b> {goal} · <b>Tempo:</b> {d} giorni · si parte da {city}",
|
||||
"scenario_progress.goal_was_not_reached_in_d":"Obiettivo non raggiunto in {d} giorni: {goal}. Continua a giocare questa rete in modalità libera, o riprova.",
|
||||
"scenario_progress.just_in_time":"Appena in tempo.",
|
||||
|
|
|
|||
|
|
@ -2716,7 +2716,9 @@
|
|||
"save.that_file_is_too_big_to":"<b>Esse arquivo é grande demais para ser um save.</b>",
|
||||
"save.that_network_went_bankrupt_it_cannot":"Essa rede foi à falência. Não dá para trazer de volta, só chorar.",
|
||||
"save.that_save_has_a_pop_in":"Esse save tem um POP numa cidade que esta versão não conhece ({city}).",
|
||||
"save.this_browser_is_not_letting_the":"<b>Seu jogo não está sendo salvo.</b> Este navegador não deixa o jogo guardar nada (janela anônima ou dados de sites desativados). Exporte um save para não perder sua rede.",
|
||||
"save.this_replaces_name_export_it_first":"Isso substitui {name}. Exporte antes se quiser guardar.",
|
||||
"save.your_network_is_too_big_to":"<b>Seu jogo não está sendo salvo.</b> Sua rede ficou grande demais para o armazenamento deste navegador. Exporte um save agora e guarde o arquivo: é o seu backup.",
|
||||
"scenario_progress.goal_goal_time_d_days_start":"<b>Objetivo:</b> {goal} · <b>Tempo:</b> {d} dias · começa em {city}",
|
||||
"scenario_progress.goal_was_not_reached_in_d":"Objetivo não alcançado em {d} dias: {goal}. Continue jogando esta rede no modo livre, ou tente de novo.",
|
||||
"scenario_progress.just_in_time":"Bem na hora.",
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
35
tests/save-size.test.js
Normal file
35
tests/save-size.test.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// Make the browser's storage refuse the save: 'QuotaExceededError' (too big) or 'SecurityError' (not allowed).
|
||||
const refuse = name => `window.__err=${JSON.stringify(name)};{const P=Object.getPrototypeOf(localStorage),set=P.setItem;
|
||||
P.setItem=function(k,v){if(k==='sot-save-v1'&&__err){const e=new Error('no');e.name=__err;throw e;}return set.call(this,k,v);};}`;
|
||||
|
||||
test('#176 a save that does not fit tells the player once, with Export, and the menu says so', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev("ACT.start({});UI.saveFail=null;" + refuse('QuotaExceededError'));
|
||||
ev('save()');
|
||||
const toasts = () => [...dom.window.document.querySelectorAll('.toast')].filter(t => /not being saved/.test(t.textContent));
|
||||
assert.equal(toasts().length, 1, 'one warning');
|
||||
assert.match(toasts()[0].textContent, /too big for this browser/);
|
||||
assert.ok(toasts()[0].querySelector('[data-act=exportSave]'), 'with an Export button');
|
||||
ev('UI.saveFail.at-=1e6;save();save(true)');
|
||||
assert.equal(toasts().length, 1, 'not again for every retry');
|
||||
ev('ACT.menu()');
|
||||
const card = ev("document.getElementById('modalCard').innerHTML");
|
||||
assert.match(card, /not being saved/);
|
||||
assert.doesNotMatch(card, /saves itself every few seconds/, 'the menu no longer claims it saves');
|
||||
// Once a save works again, the menu goes back to normal.
|
||||
ev("__err=null;save(true);ACT.menu()");
|
||||
assert.equal(ev('saveFailing()'), false);
|
||||
assert.match(ev("document.getElementById('modalCard').innerHTML"), /saves itself every few seconds/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#176 storage that is blocked altogether gets its own advice', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev("ACT.start({});UI.saveFail=null;" + refuse('SecurityError') + ';save()');
|
||||
assert.match(dom.window.document.body.textContent, /private window/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue