2022-07-18 16:07:36 +00:00
storage = require ( "Storage" ) ;
Bangle . setLCDPower ( 1 ) ;
g . clear ( ) ;
// constants
const settingsfile = "memorytrainer.settings.json" ;
2022-07-18 19:03:46 +00:00
const moduleList = [ ] ;
storage . list ( /\.memorytrainer\.js$/ ) . forEach ( module => moduleList . push ( eval ( storage . read ( module ) ) ) ) ;
2022-07-18 16:07:36 +00:00
// utilities
function wait ( s ) {
c _time = getTime ( ) ;
while ( getTime ( ) - c _time <= s ) { }
}
function getSettings ( ) {
2022-07-18 18:13:08 +00:00
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 ) ;
}
}
2022-07-18 18:13:08 +00:00
function homescreen ( ) {
g . clear ( ) ;
2022-07-18 19:03:46 +00:00
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" ) ;
2022-07-18 18:13:08 +00:00
}
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 ) ;
2022-07-18 18:13:08 +00:00
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 ) ;
2022-07-18 18:13:08 +00:00
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 ) ;
}