| 1234567891011121314151617181920212223242526 |
- // 入口:读档 → 迁移 → 离线结算 → 启动单屏 UI。署名:FmodeCode
- import * as S from './game/state.js';
- import { Game } from './ui/game.js';
- function boot() {
- let state = null;
- try { state = S.save.load(localStorage); } catch (e) { state = null; }
- if (!state) state = S.newState();
- let offline = null;
- try {
- const gap = (Date.now() - (state.savedAt || Date.now())) / 1000;
- if (gap > 60 && state.story && state.story.prologue) offline = S.applyOffline(state, gap);
- } catch (e) { offline = null; }
- const game = new Game(state);
- window.__wt = game; // 供自动化测试读取(只读)
- game.start();
- if (offline) {
- const g = window.__wt;
- g.toast(`<b>根系在你离开时仍在生长</b><small>${S.formatGap ? S.formatGap(offline.sec) : Math.round(offline.sec / 60) + ' 分钟'} · 本源 +${Math.round(offline.res)}</small>`, 'green', 5000);
- g.handle(offline.events, 'offline');
- g.renderAll();
- }
- }
- if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
- else boot();
|