import 'dotenv/config';

console.debug = function(){
    if (process.env.debug){
      console.log.apply(console, arguments);
    }
}

import App from './app/App.js';

const modules = [
  {name: 'Config', path:'app/Config.js'},
  {name: 'Db', path:'app/Db.js'},

  {name: 'GameObjectsManager', path:'app/bl/GameObjectsManager.js'},
  {name: 'ScenariosManager', path:'app/bl/ScenariosManager.js'},
  {name: 'GamesManager', path:'app/bl/GamesManager.js'},

  {name: 'WebServer', path:'app/WebServer.js'},

  {name: 'AssetController', path: 'controllers/AssetController.js'},
  {name: 'GameObjectsController', path:'controllers/api/GameObjectsController.js'},
  {name: 'ScenariosController', path:'controllers/api/ScenariosController.js'},
  {name: 'GamesController', path:'controllers/api/GamesController.js'},
]

process.on('uncaughtException', err => {
  console.error(err, 'Uncaught Exception thrown');
}).on('unhandledRejection', (reason, p) => {
  console.error(reason, 'Unhandled Rejection at Promise', p);
});

const app = new App();

await app.importModules(modules);

await app.init();

console.log(`Starting...`);
app.start();