File size: 471 Bytes
1c00bf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Game } from './game.js';
import { UI } from './ui.js';

const game = new Game();
const ui = new UI(game);

window.__empire = { game, ui };

ui.init();

// Auto-save when the tab is closed or backgrounded.
window.addEventListener('beforeunload', () => {
  if (game.state && !game.state.isOver) game.save();
});
document.addEventListener('visibilitychange', () => {
  if (document.visibilityState === 'hidden' && game.state && !game.state.isOver) game.save();
});