134 lines
3.7 KiB
JavaScript
Executable File
134 lines
3.7 KiB
JavaScript
Executable File
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();
|
|
var boolean = false;
|
|
var number = 50;
|
|
|
|
// Main menu
|
|
var mainmenu = {
|
|
"" : { title : "What to do?" },
|
|
"Learn Pi, 3.141592" : () => { E.showMenu(pimenu); },
|
|
"----": () => {},
|
|
"Exit": () => { Bangle.showLauncher(); }, // remove the menu
|
|
};
|
|
|
|
// Pi-Menu
|
|
var pimenu = {
|
|
"" : "3.1415926535", "< Back": () => { E.showMenu(mainmenu); },
|
|
"------": undefined,
|
|
"001-020": () => { E.showPrompt("1415926535", { "title": "001-020", "buttons": {"< Back": true} }).then(function(v) { showMenu(pimenu); }); },
|
|
"021-040": () => { },
|
|
"041-060": () => { },
|
|
"061-080": () => { },
|
|
"081-100": () => { },
|
|
"101-120": () => { },
|
|
"121-140": () => { },
|
|
"141-160": () => { },
|
|
"161-180": () => { },
|
|
"181-200": () => { },
|
|
"201-220": () => { },
|
|
"221-240": () => { },
|
|
"241-260": () => { },
|
|
"261-280": () => { },
|
|
"281-300": () => { },
|
|
"301-320": () => { },
|
|
"321-340": () => { },
|
|
"341-360": () => { },
|
|
"361-380": () => { },
|
|
"381-400": () => { }
|
|
};
|
|
|
|
// Actually display the menu
|
|
E.showMenu(mainmenu);
|
|
}
|
|
|
|
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();
|
|
var currentModule = 0;
|
|
var moduleInterval; // interval for the modules to be called
|
|
|
|
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);
|
|
}
|