hadean-old/src/index.ts

36 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-06-16 15:26:42 -04:00
import { render } from './ui/UI.js';
2021-06-18 02:02:50 -04:00
import { ensureDirSync } from 'fs-extra';
import { lstatSync } from 'fs';
import { parse, resolve } from 'path';
import walkSync from 'walk-sync';
import { fileURLToPath } from 'url';
2021-06-22 19:25:41 -04:00
import { Game } from '@game';
2021-06-14 22:03:55 -04:00
2021-06-18 02:02:50 -04:00
const saveFile = process.argv[2] || 'data/world01.json';
2021-06-15 20:05:07 -04:00
2021-06-18 02:02:50 -04:00
ensureDirSync(parse(saveFile).dir);
2021-06-22 19:25:41 -04:00
// TODO extract extension loading into separate file
console.log('df-idle: Loading extensions');
const extensionsPath = resolve(parse(fileURLToPath(import.meta.url)).dir, '../content');
const extensions = walkSync(extensionsPath)
2021-06-22 19:25:41 -04:00
.map(path => resolve(extensionsPath, path))
.filter(path => lstatSync(path).isFile())
.filter(path => parse(path).ext === '.js');
// .map(path => import(path));
console.log('found', extensions.length, 'extensions');
for(const path of extensions) {
console.log('=== [', path, '] ===');
await import(path);
console.log();
}
// 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);