storage = require("Storage"); Bangle.setLCDPower(1); g.clear(); // constants const settingsfile = "memorytrainer.settings.json"; const moduleList = []; storage.list(/\.memorytrainer\.js$/).forEach(module => moduleList.push(eval(storage.read(module)))); // utilities function wait(s) { c_time = getTime(); while(getTime() - c_time <= s) {} } function getSettings() { return Object.assign({"firstrun": true, "fullscreen": true}, storage.readJSON(settingsfile, true) || {}); } // UI functions function animate100x100img_big2small(img, minscale, maxscale) { for(img_scale = minscale; img_scale <= maxscale; img_scale+=0.3) { try { g.drawImage(img, (g.getWidth()-100*img_scale)/2, (g.getHeight()-100*img_scale)/2, {scale: img_scale}); } catch(e) {} // place the image in the middle of screen (100 is the image width and height) g.clear(); wait(1/60); } for(img_scale = maxscale; img_scale >= minscale; img_scale-=0.4) { try { g.drawImage(img, (g.getWidth()-100*img_scale)/2, (g.getHeight()-100*img_scale)/2, {scale: img_scale}); } catch(e) {} g.clear(); wait(1/60); } } function homescreen() { g.clear(); if(moduleList.length == 0) { E.showMessage("No module to load.\nExiting...", {"title": "ERROR", "img": atob("FBQBAfgAf+Af/4P//D+fx/n+f5/v+f//n//5//+f//n////3//5/n+P//D//wf/4B/4AH4A=")}); wait(5); Bangle.showLauncher(); } E.showMessage(":/\nModules aren't implemented yet.\nSee you soon!", "COMING SOON"); } function setupWizard() { E.showPrompt( "Do you want the app to stay full screen (default)?", { "title": "FULLSCREEN", "buttons": {"Yes!": true, "No, I love Widgets!": false} } ).then(function(v) { if(settings.fullscreen != v) { settings.fullscreen = v; storage.writeJSON(settingsfile, settings); E.showMessage("Changes will be visible after a restart of the application.", "INFO"); wait(2); } // always do start homescreen g.clear(); E.showMessage("You can now use your fully configured MemoryTrainer app.", "CONGRATULATIONS!"); wait(2); homescreen(); }); } function welcome(new_user) { var brain_trainer_text = storage.readJSON("memorytrainer.icons.json", true).brain_trainer_text; var img_brain_trainer_text = brain_trainer_text.data; if(new_user) { E.showMessage("Hello!"); wait(1); g.clear(); wait(0.2); E.showMessage("This is a\nBRAIN-TRAINER."); wait(1); g.clear(); wait(0.2); setupWizard(); return; } g.drawImage(img_brain_trainer_text, g.getWidth()/2, g.getHeight()/2, {rotate: 0.04, scale: 1.2}); wait(1); homescreen(); } // now the real code begins var settings = getSettings(); animate100x100img_big2small(storage.read("memorytrainer.png"), 0.1, 1.5); if(settings.firstrun) { welcome(true); settings.firstrun = false; storage.writeJSON(settingsfile, settings); } else { welcome(false); }