Mercurial > hg > forks > multipaint-js
changeset 105:6429d0b757cd
Implement quick save/load ("S"/"L") via browser local storage.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Jul 2018 06:14:27 +0300 |
parents | 73a8773466ae |
children | 3abfab85e7bc |
files | events.pde |
diffstat | 1 files changed, 45 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/events.pde Fri Jul 06 05:29:26 2018 +0300 +++ b/events.pde Fri Jul 06 06:14:27 2018 +0300 @@ -803,23 +803,7 @@ redo_undo(); refresh(); } - if (g_data[int('S')] == 1) { - g_data[int('S')] = 0; - String sname = g_spare ? sfilename : filename; - if (sname) { - if (g_iconmode == 0) { - message(g_spare ? "Spare page|saved" : "Page saved"); - mpSaveNativeImage(sname); - } - - } else { - message("No filename!"); - message("*"); - g_data[int('S')] = 0; - g_data[int('s')] = 0; - } - } if (machine == SPECTRUM) { if (g_data[int('i')] == 1) { @@ -847,7 +831,52 @@ g_data[int('s')] = 0; saveas = true; } + + if (g_data[int('S')] == 1) + { + g_data[int('S')] = 0; + g_data[int('s')] = 0; + + if (mpHaveLocalStorage()) + { + var fdata = mpGetNativeImage(); + if (fdata != null) + { + var fstr = JSON.stringify(fdata); + localStorage.setItem("MPIMAGE_DATA", fstr); + message("Saved to lstorage"); + } + else + message("ERROR"); + } + else + message("Lstorage/save|not available"); + } + if (g_data[int('L')] == 1) { g_data[int('L')] = 0; + if (mpHaveLocalStorage()) + { + var fstr = localStorage.getItem("MPIMAGE_DATA"); + if (fstr != null && typeof(fstr) == "string") + { + var fdata = JSON.parse(fstr); + if (typeof(fdata) == "object" && + Array.isArray(fdata)) + { + int res = mpSetNativeImage(fdata, false); + if (res != 0) + message("Wrong machine"); + else + message("Loaded lstorage"); + } + else + message("Invalid data in lstorage"); + } + else + message("No data in lstorage"); + } + else + message("Lstorage/load|not available"); } }