2021-06-18 02:02:50 -04:00
|
|
|
import { ensureDirSync } from 'fs-extra';
|
2021-07-23 00:12:02 -04:00
|
|
|
import { parse } from 'path';
|
2021-06-22 19:25:41 -04:00
|
|
|
import { Game } from '@game';
|
2021-07-23 00:12:02 -04:00
|
|
|
import {
|
|
|
|
|
isStarted,
|
|
|
|
|
stop,
|
|
|
|
|
update,
|
|
|
|
|
GameView,
|
|
|
|
|
setView,
|
|
|
|
|
start
|
|
|
|
|
} from '@ui';
|
2021-07-19 01:53:30 -04:00
|
|
|
import ansi from 'sisteransi';
|
2021-06-26 03:11:18 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
// HACK static extension loading
|
|
|
|
|
import './../content/content.js';
|
|
|
|
|
import { loadExtensions } from './Util.js';
|
|
|
|
|
import { APPLICATION_NAME } from './Constants.js';
|
2021-06-18 02:02:50 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
// console.clear();
|
2021-06-22 19:25:41 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
function gracefulShutdown() {
|
|
|
|
|
if (isStarted()) {
|
|
|
|
|
stop();
|
2021-07-20 16:37:38 -04:00
|
|
|
}
|
2021-07-23 00:12:02 -04:00
|
|
|
console.log('shutting down gracefully...');
|
|
|
|
|
if (Game.current) {
|
|
|
|
|
console.log('saving world...');
|
|
|
|
|
Game.current.sync();
|
|
|
|
|
}
|
|
|
|
|
console.log('exitting');
|
|
|
|
|
process.stdout.write(ansi.cursor.show);
|
2021-06-19 18:23:44 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
process.exit(0);
|
|
|
|
|
}
|
2021-07-20 16:37:38 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
process.on('exit', gracefulShutdown);
|
2021-07-20 16:37:38 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
const saveFile = process.argv[2] || 'data/world01.json';
|
2021-07-20 16:37:38 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
ensureDirSync(parse(saveFile).dir);
|
2021-07-20 16:37:38 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
// loadExtensions();
|
2021-07-20 16:37:38 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
for (let seconds = 0; seconds > 0; seconds--) {
|
|
|
|
|
process.stdout.write('Starting ' + APPLICATION_NAME + ' in ' + seconds + '\r');
|
|
|
|
|
await new Promise(res => setTimeout(res, 1000));
|
|
|
|
|
}
|
|
|
|
|
process.stdout.write('Starting ' + APPLICATION_NAME + ' in ' + 0 + '\n');
|
|
|
|
|
// console.clear();
|
2021-07-16 20:49:29 -04:00
|
|
|
|
2021-07-23 00:12:02 -04:00
|
|
|
// TODO move render logic into game, so that the ui doesnt exist until the game does...
|
|
|
|
|
// maybe, i mean, an argument could be made for not that, because the game
|
|
|
|
|
// isnt necessarily the entire thing, its just one instance of a save file.
|
|
|
|
|
// But probably the initial menu screens will be their own thing entirely.
|
|
|
|
|
const game = Game.create(saveFile);
|
|
|
|
|
start();
|
|
|
|
|
const gameView = new GameView(game);
|
|
|
|
|
setView(gameView);
|