This repository has been archived on 2024-05-26. You can view files and clone it, but cannot push or open issues or pull requests.
MemoryTrainer/memorytrainer.app.js

92 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-07-18 16:07:36 +00:00
storage = require("Storage");
Bangle.setLCDPower(1);
g.clear();
// constants
const settingsfile = "memorytrainer.settings.json";
// 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) || {});
2022-07-18 16:07:36 +00:00
}
// 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();
}
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();
});
}
2022-07-18 16:07:36 +00:00
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;
2022-07-18 16:07:36 +00:00
}
g.drawImage(img_brain_trainer_text, g.getWidth()/2, g.getHeight()/2, {rotate: 0.04, scale: 1.2});
wait(1);
homescreen();
2022-07-18 16:07:36 +00:00
}
// now the real code begins
var settings = getSettings();
2022-07-18 16:17:28 +00:00
animate100x100img_big2small(storage.read("memorytrainer.png"), 0.1, 1.5);
2022-07-18 16:07:36 +00:00
if(settings.firstrun) {
welcome(true);
settings.firstrun = false;
storage.writeJSON(settingsfile, settings);
} else {
welcome(false);
}