game.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. // UI 主控:渲染单屏 + 处理动作返回的事件(反馈 / 叙事 / 成就)。逻辑全部在 core / game。署名:FmodeCode
  2. import * as S from '../game/state.js';
  3. import * as F from '../core/formulas.js';
  4. import * as B from '../core/balance.js';
  5. import { PLANETS } from '../data/planets.js';
  6. import { LIFE, lifeById } from '../data/lives.js';
  7. import { CHAPTER_TEXT, LIFE_CRY, ERA_TEXT, TUTORIAL_LINES, PROLOGUE } from '../data/story.js';
  8. import { ACHIEVEMENTS, achById, achCount } from '../game/achievements.js';
  9. import { $, $$, fmt, fmtTime, icon, esc } from '../util.js';
  10. import { buildSystemSvg, planetSvg, planetPos, fxAt, sparksAt, rippleAt, confetti, globalFlash } from './art.js';
  11. export class Game {
  12. constructor(state) {
  13. this.s = state;
  14. this.now = Date.now() / 1000;
  15. this.sheetName = null;
  16. this.modalQueue = [];
  17. this.modalOpen = false;
  18. this.lastSave = Date.now();
  19. this.bind();
  20. }
  21. start() {
  22. $('#app').hidden = false;
  23. document.body.classList.toggle('in-prologue', !this.s.story.prologue);
  24. this.buildSystem();
  25. if (!this.s.story.prologue) this.showPrologue();
  26. else this.afterPrologue(false);
  27. document.body.classList.toggle('in-prologue', !this.s.story.prologue);
  28. this.renderAll();
  29. this.loop();
  30. setInterval(() => this.tickOnce(), 1000);
  31. document.addEventListener('visibilitychange', () => { if (!document.hidden) this.onReturn(); });
  32. window.addEventListener('beforeunload', () => this.persist());
  33. setInterval(() => this.persist(), 5000);
  34. }
  35. // ── 主循环:数字与进度条按帧平滑 ─────────────────────
  36. loop() {
  37. const paint = () => {
  38. this.now = Date.now() / 1000;
  39. this.paintStats();
  40. this.frame = requestAnimationFrame(paint);
  41. };
  42. paint();
  43. }
  44. tickOnce() {
  45. const out = S.tick(this.s, this.now, 1);
  46. this.handle(out.world, 'tick');
  47. this.handle(out.ui, 'tick', true);
  48. this.refreshDynamic();
  49. }
  50. onReturn() {
  51. const gap = this.now ? (Date.now() / 1000 - this.now) : 0;
  52. const off = S.applyOffline(this.s, gap, Date.now() / 1000);
  53. if (off) {
  54. const sec = fmtTime(off.sec);
  55. this.toast(`<b>根系在你离开时仍在生长</b><small>${sec} · 本源 +${fmt(off.res)}${off.grow > 0 ? ` · 星球改造 +${off.grow.toFixed(1)}%` : ''}</small>`, 'green', 5000);
  56. this.handle(off.events, 'offline');
  57. }
  58. this.now = Date.now() / 1000;
  59. this.renderAll();
  60. }
  61. persist() { S.save.write(localStorage, this.s); this.lastSave = Date.now(); }
  62. // ── 事件绑定 ───────────────────────────────────────
  63. bind() {
  64. $('#tree').addEventListener('pointerdown', (e) => this.onTap(e));
  65. $('#goal').addEventListener('click', () => this.onGoalClick());
  66. $$('.tabbar button').forEach((b) => b.addEventListener('click', () => this.openSheet(b.dataset.nav)));
  67. $('#btn-menu').addEventListener('click', () => this.openSheet('menu'));
  68. $('#root-chip').addEventListener('click', () => this.openSheet('root'));
  69. $('#crystal-chip').addEventListener('click', () => this.openSheet('era'));
  70. $('#sheet-x').addEventListener('click', () => this.closeSheet());
  71. $('#sheet-mask').addEventListener('click', (e) => { if (e.target.id === 'sheet-mask') this.closeSheet(); });
  72. $('#btn-explore').addEventListener('click', () => this.doExplore());
  73. document.addEventListener('keydown', (e) => {
  74. if (e.key === 'Escape') { this.closeSheet(); if (this.modalOpen) this.advanceModal(); }
  75. if (e.code === 'Space' && !this.modalOpen && $('#app').hidden === false && !this.sheetName) { e.preventDefault(); this.onTap({ clientX: innerWidth / 2, clientY: innerHeight * 0.8 }); }
  76. });
  77. // 星图:事件委托
  78. $('#system').addEventListener('click', (e) => {
  79. const g = e.target.closest('[data-planet]');
  80. if (!g) return;
  81. const i = +g.dataset.planet;
  82. if (F.isPlanetUnlocked(this.s, i)) this.switchPlanet(i);
  83. else this.explainLocked(i);
  84. });
  85. }
  86. // ── 开场故事 ──────────────────────────────────────
  87. showPrologue() {
  88. this.proIdx = 0;
  89. const el = $('#prologue');
  90. el.hidden = false;
  91. $('#pro-next').onclick = () => this.proNext();
  92. $('#pro-skip').onclick = () => this.proFinish();
  93. this.proRender();
  94. }
  95. proRender() {
  96. const p = PROLOGUE[this.proIdx];
  97. $('#pro-bg').style.backgroundImage = `url(assets/${p.art}.webp)`;
  98. $('#pro-kicker').textContent = p.kicker;
  99. $('#pro-text').textContent = p.text;
  100. $('#pro-lines').innerHTML = p.lines.map((l) => `<p>${esc(l)}</p>`).join('');
  101. $('#pro-dots').innerHTML = PROLOGUE.map((_, k) => `<i class="${k === this.proIdx ? 'on' : ''}"></i>`).join('');
  102. $('#pro-next').textContent = this.proIdx < PROLOGUE.length - 1 ? '继续' : '让根须苏醒';
  103. const body = $('#pro-body') || $('.pro-body');
  104. body.style.animation = 'none'; void body.offsetWidth; body.style.animation = '';
  105. }
  106. proNext() {
  107. if (this.proIdx < PROLOGUE.length - 1) { this.proIdx++; this.proRender(); }
  108. else this.proFinish();
  109. }
  110. proFinish() {
  111. this.s.story.prologue = 1;
  112. $('#prologue').hidden = true;
  113. document.body.classList.remove('in-prologue');
  114. globalFlash();
  115. this.afterPrologue(true);
  116. }
  117. // ── 引导:每一步只讲一句话,完成即推进 ─────────────────
  118. afterPrologue(fresh) {
  119. const step = this.s.tutorial.step;
  120. if (fresh && step <= 1) {
  121. this.introCard = true;
  122. this.pushModal({
  123. kicker: '第一章 · 地球', title: CHAPTER_TEXT.earth.intro.title, text: CHAPTER_TEXT.earth.intro.text,
  124. sigil: 'earth', choices: [{ text: '让根须扎进土壤', primary: true }],
  125. });
  126. } else if (TUTORIAL_LINES[step]) {
  127. this.toast(`<b>世界树</b><small>${esc(TUTORIAL_LINES[step].text)}</small>`, 'green', 6000);
  128. }
  129. }
  130. tutorialHint() {
  131. const step = this.s.tutorial.step;
  132. const line = TUTORIAL_LINES[step];
  133. if (!line || this.hintShown === step) return;
  134. this.hintShown = step;
  135. this.toast(`<b>${line.speaker}</b><small>${esc(line.text)}</small>`, 'green', 5500);
  136. }
  137. // ── 点击世界树 ─────────────────────────────────────
  138. onTap(e) {
  139. const out = S.tap(this.s, this.now);
  140. const btn = $('#tree').getBoundingClientRect();
  141. const x = (e && e.clientX) || btn.left + btn.width / 2;
  142. const y = (e && e.clientY) || btn.top + btn.height / 2;
  143. const gain = out.find((o) => o.type === 'tap')?.gain || 0;
  144. fxAt(x, y - 10, '+' + fmt(gain));
  145. sparksAt(x, y, 6);
  146. rippleAt(x, y);
  147. const crown = $('.tree-crown');
  148. crown.style.transform = 'scale(1.12)';
  149. setTimeout(() => { crown.style.transform = ''; }, 120);
  150. this.handle(out);
  151. this.paintStats();
  152. this.renderGoal();
  153. this.tutorialHint();
  154. }
  155. onGoalClick() {
  156. const g = F.currentGoal(this.s);
  157. if (g.key === 'tut5' || g.key === 'tut6') this.s.tutorial.starOpened = true;
  158. if (g.action === 'next') { this.onNextPlanet(g.planet); return; }
  159. if (g.action === 'era') { this.openSheet('era'); return; }
  160. if (g.action === 'life') this.openSheet('lives');
  161. else if (g.action === 'explore') this.doExplore();
  162. else if (g.action === 'planet') this.openSheet('planet');
  163. else if (g.action === 'root') this.openSheet('root');
  164. else if (g.action === 'star') this.openSheet('star');
  165. else this.pulse('#tree');
  166. this.renderAll();
  167. }
  168. pulse(sel) { const e = $(sel); if (!e) return; e.classList.remove('hint'); void e.offsetWidth; e.classList.add('hint'); }
  169. // ── 提示 toast ──────────────────────────────────────
  170. toast(html, cls = '', ms = 3000, bad = false) {
  171. const box = $('#toasts');
  172. const t = document.createElement('div');
  173. t.className = 'toast ' + (cls || '');
  174. t.innerHTML = html;
  175. box.appendChild(t);
  176. while (box.children.length > 3) box.firstChild.remove();
  177. setTimeout(() => { t.classList.add('out'); setTimeout(() => t.remove(), 320); }, ms);
  178. }
  179. // ── 核心动作 ───────────────────────────────────────
  180. switchPlanet(i) {
  181. if (i === this.s.curPlanet) { this.openSheet('planet'); return; }
  182. const out = S.enterPlanet(this.s, i);
  183. this.handle(out);
  184. this.buildSystem();
  185. this.renderAll();
  186. this.toast(`<b>${PLANETS[i].name}</b><small>${esc(PLANETS[i].hint)}</small>`, '', 3800);
  187. }
  188. explainLocked(i) {
  189. const P = PLANETS[i];
  190. const prev = PLANETS[i - 1];
  191. const prevDone = this.s.planets[i - 1].rem <= 0;
  192. const lvOk = this.s.rootLv >= P.unlockLv;
  193. this.openSheet('lock', { i, msg: prevDone && !lvOk ? `需要世界树扎根 ${P.unlockLv} 级(当前 ${this.s.rootLv} 级)` : `先让${prev.name}复苏,并让世界树扎根到 ${P.unlockLv} 级` });
  194. }
  195. buyLife(id) {
  196. const out = S.buyLife(this.s, id);
  197. if (!out.length) return;
  198. const btn = $(`.life-btn[data-life="${id}"]`);
  199. if (btn) { btn.classList.remove('flash'); void btn.offsetWidth; btn.classList.add('flash'); }
  200. this.handle(out);
  201. this.renderLives();
  202. this.renderGoal();
  203. this.paintStats();
  204. }
  205. buyRootAll() {
  206. const n = 8;
  207. const out = S.buyRoot(this.s, n);
  208. if (out.length) this.toast(`<b>根系生长</b><small>扎根 ${this.s.rootLv} 级 · 本源 ×${B.rootProdMul(this.s.rootLv).toFixed(1)}</small>`, 'green', 2500);
  209. this.handle(out);
  210. this.renderAll();
  211. }
  212. doExplore() {
  213. const i = this.s.curPlanet;
  214. const out = S.explore(this.s);
  215. if (!out.length) {
  216. const p = this.s.planets[i];
  217. if (p.explore >= B.STAR.exploreMax) this.toast('<b>这颗星球已被完全勘探</b><small>改造只需 3% 的等级即可完成</small>', '', 3000);
  218. else this.toast(`<b>勘探需要 ${fmt(S.exploreCostNow(this.s, i))} 本源</b><small>根须继续生长后再来</small>`, '', 2600);
  219. return;
  220. }
  221. confettiSmall();
  222. this.handle(out);
  223. this.renderAll();
  224. }
  225. // ── 事件处理(所有动作统一出口)────────────────────────
  226. handle(events, source = 'ui', deferModal = false) {
  227. for (const ev of events || []) {
  228. switch (ev.type) {
  229. case 'tap': break;
  230. case 'ach': this.toast(`<span class="ic">${icon(ev.ach.icon)}</span><span><b>成就解锁 · ${esc(ev.ach.name)}</b><small>${esc(ev.ach.desc)}</small></span>`, 'ach', 4200); this.renderNavDots(); break;
  231. case 'life':
  232. if (ev.first && ev.planet === this.s.curPlanet) {
  233. // 生命苏醒卡:同一时刻苏醒的多种生命合并成一张卡;引导期间只弹“引导”的那一株(避免打断教学)
  234. const stepNow = this.s.tutorial.step;
  235. const tutLife = !(stepNow === 1 || stepNow === 2) && stepNow < 99; // 只有走到“种下第一株生命”那一步之后才需要弹出
  236. if (!tutLife || ev.id === 'moss') {
  237. this.lifeModalQueue = (this.lifeModalQueue || []).concat([ev]);
  238. if (!this.lifeModalTimer) this.lifeModalTimer = setTimeout(() => this.flushLifeModals(), 1500);
  239. }
  240. }
  241. break;
  242. case 'planet-done': this.onPlanetDone(ev.planet); break;
  243. case 'heat-good': this.toast(`<b>环境转机</b><small>${esc(CHAPTER_TEXT[PLANETS[ev.planet].id].heatGood)}</small>`, 'green', 3200); break;
  244. case 'heat-bad': this.toast(`<b>环境恶化</b><small>${esc(CHAPTER_TEXT[PLANETS[ev.planet].id].heatBad)}</small>`, '', 2600, true); break;
  245. case 'event-open': this.pushModalEv(ev.ev, ev.crisis ? '危机' : '星海事件'); break;
  246. case 'event-done': this.toast(`<b>${esc(ev.choice.effect)}</b>`, 'green', 2600); break;
  247. case 'res': fxAt(innerWidth / 2, innerHeight * 0.55, '+' + fmt(ev.amount)); break;
  248. case 'progress': this.toast(`<b>${ev.pct > 0 ? '改造推进' : '改造回退'} ${Math.abs(ev.pct)}%</b>`, ev.pct > 0 ? 'green' : '', 2000); break;
  249. case 'life-gain': this.toast(`<b>${esc(ev.life.name)} ×${ev.n}</b><small>生命在根系中苏醒</small>`, 'green', 2400); break;
  250. case 'tut': this.tutorialHint(); this.pulseGoal(); break;
  251. case 'era': this.onEra(ev); break;
  252. case 'curio': this.toast(`<b>星辰洗礼 · ${esc(B.STEM_ELEMENTS.find((e) => e.id === ev.el)?.name)}</b><small>第 ${ev.stems} 颗基因之种</small>`, 'ach', 3200); break;
  253. case 'heal': this.toast('<b>屏障修补完成</b><small>根系撑过了这一阵风暴</small>', 'green', 2200); break;
  254. case 'explore': this.toast(`<b>勘探第 ${ev.level} 层</b><small>所需生命等级 ×${B.STAR.exploreBoost.toFixed(2)}</small>`, 'green', 2400); break;
  255. case 'enter': break;
  256. default: break;
  257. }
  258. }
  259. }
  260. /** 生命苏醒:集中弹一次(多个生命在同一时刻苏醒时只弹一个“名录”) */
  261. flushLifeModals() {
  262. const q = this.lifeModalQueue || []; this.lifeModalQueue = []; this.lifeModalTimer = null;
  263. if (!q.length) return;
  264. if (q.length === 1) {
  265. const ev = q[0];
  266. this.pushModal({ kicker: `${PLANETS[ev.planet].name} · 生命苏醒`, title: lifeById(ev.id).name, text: LIFE_CRY[ev.id] || lifeById(ev.id).lore, sigil: lifeById(ev.id).icon, choices: [{ text: '让它继续生长', primary: true }] });
  267. return;
  268. }
  269. const title = q.map((ev) => lifeById(ev.id).name).join('、');
  270. const text = q.map((ev) => `「${lifeById(ev.id).name}」——${LIFE_CRY[ev.id] || lifeById(ev.id).lore}`).join('\n\n');
  271. this.pushModal({ kicker: `${PLANETS[q[0].planet].name} · 生命苏醒`, title, text, sigil: lifeById(q[q.length - 1].id).icon, choices: [{ text: '让它们一起生长', primary: true }] });
  272. }
  273. pulseGoal() { const g = $('#goal'); g.classList.remove('flash'); void g.offsetWidth; g.classList.add('flash'); }
  274. onPlanetDone(i) {
  275. const P = PLANETS[i];
  276. const ch = CHAPTER_TEXT[P.id];
  277. confetti(); globalFlash();
  278. const next = PLANETS[i + 1];
  279. this.pushModal({
  280. kicker: `第 ${P.chapterNo} 章 · 星球复苏`, title: ch.clear.title, text: ch.clear.text, sigil: P.sun ? 'sun' : 'check',
  281. choices: [{ text: next ? `前往${next.name}` : '回到太阳系', primary: true, next: next ? i + 1 : null, reopen: !!next }],
  282. });
  283. this.buildSystem();
  284. }
  285. onEra(ev) {
  286. confetti(); globalFlash();
  287. if (this.sheetName === 'era') this.closeSheet();
  288. this.pushModal({
  289. kicker: `第 ${ev.eras} 纪元`, title: ERA_TEXT.title, text: ERA_TEXT.text + `\n\n获得时间结晶 ×${ev.reward}(共 ${ev.crystals})。`,
  290. sigil: 'hourglass', choices: [{ text: '让新的纪元开始', primary: true }], era: true,
  291. });
  292. this.buildSystem();
  293. }
  294. onSwitchAfterDone(i) {
  295. const out = S.enterPlanet(this.s, i);
  296. this.handle(out);
  297. this.buildSystem();
  298. if (this.s.planets[i].rem > 0 && !this.s.story['intro' + i]) {
  299. this.s.story['intro' + i] = 1;
  300. this.pushModal({ kicker: `第 ${PLANETS[i].chapterNo} 章`, title: CHAPTER_TEXT[PLANETS[i].id].intro.title, text: CHAPTER_TEXT[PLANETS[i].id].intro.text, sigil: PLANETS[i].icon || 'planet', choices: [{ text: '开始改造', primary: true }] });
  301. }
  302. this.renderAll();
  303. }
  304. // ── 弹窗队列 ──────────────────────────────────────
  305. pushModal(spec) { this.modalQueue.push(spec); if (!this.modalOpen) this.nextModal(); }
  306. pushModalEv(ev, kind) {
  307. this.modalQueue.push({
  308. kicker: kind, title: ev.title, text: ev.text, sigil: 'wind', ev,
  309. choices: ev.choices.map((c, k) => ({ text: c.text, effect: c.effect, pick: k })),
  310. });
  311. if (!this.modalOpen) this.nextModal();
  312. }
  313. nextModal() {
  314. const m = this.modalQueue.shift();
  315. if (!m) { this.modalOpen = false; $('#modal-mask').hidden = true; this.renderAll(); return; }
  316. this.modalOpen = true; this.curModal = m;
  317. $('#modal-mask').hidden = false;
  318. const sig = m.lifeId ? (lifeById(m.lifeId)?.icon || 'sprout') : (m.sigil || 'star');
  319. $('#modal-art').innerHTML = `<div class="sigil">${icon(sig)}</div>`;
  320. $('#modal-kicker').textContent = m.kicker || '';
  321. $('#modal-title').textContent = m.lifeId ? lifeById(m.lifeId).name : (m.title || '');
  322. let text = m.text || '';
  323. if (m.lifeId) {
  324. const l = lifeById(m.lifeId);
  325. text = LIFE_CRY[m.lifeId] || l.lore;
  326. }
  327. $('#modal-text').innerHTML = esc(text);
  328. $('#modal-choices').innerHTML = m.choices.map((c, k) =>
  329. `<button class="choice ${c.primary ? 'primary' : ''}" data-k="${k}"><b>${esc(c.text)}</b>${c.effect ? `<small>${esc(c.effect)}</small>` : ''}</button>`).join('');
  330. $$('#modal-choices .choice').forEach((b) => b.addEventListener('click', () => this.chooseModal(+b.dataset.k)));
  331. const first = $('#modal-choices .choice'); if (first) setTimeout(() => first.focus({ preventScroll: true }), 30);
  332. }
  333. chooseModal(k) {
  334. const m = this.curModal;
  335. const c = m.choices[k];
  336. // 只有真实事件卡才把选择写回存档;叙事卡(章节 / 苏醒 / 纪元)只是“继续”按钮
  337. if (m.ev) {
  338. const out = S.resolveEvent(this.s, k, this.now);
  339. this.handle(out);
  340. }
  341. this.modalOpen = false; $('#modal-mask').hidden = true;
  342. if (c && c.next !== undefined && c.next !== null) setTimeout(() => this.onNextPlanet(c.next), 80);
  343. if (m.era) setTimeout(() => this.renderAll(), 80);
  344. setTimeout(() => this.nextModal(), 60);
  345. this.renderAll();
  346. }
  347. /** 星球已复苏时:直接进入下一颗(由“前往”按钮触发) */
  348. onNextPlanet(i) {
  349. if (F.isPlanetUnlocked(this.s, i)) this.onSwitchAfterDone(i);
  350. else { this.explainLocked(i); this.renderAll(); }
  351. }
  352. advanceModal() { if (this.curModal && this.curModal.choices.length === 1) this.chooseModal(0); }
  353. // ── 渲染 ──────────────────────────────────────────
  354. buildSystem() {
  355. this.systemSig = this.s.planets.map((p) => F.planetStatus(this.s, this.s.planets.indexOf(p))).join(',') + '|' + this.s.rootLv + '|' + this.s.curPlanet + '|' + this.s.planets.map((p) => p.rem <= 0 ? 1 : 0).join('');
  356. const st = PLANETS.map((P, i) => ({ i, idx: i, state: F.planetStatus(this.s, i), pct: 100 - this.s.planets[i].rem }));
  357. $('#system').innerHTML = buildSystemSvg(st);
  358. }
  359. paintStats() {
  360. const s = this.s;
  361. const inc = F.incomeOf(s, this.now);
  362. $('#res-val').textContent = fmt(s.res);
  363. $('#res-rate').textContent = '+' + fmt(inc) + '/秒';
  364. $('#root-lv').textContent = s.rootLv;
  365. $('#crystal-val').textContent = s.crystals;
  366. const eb = $('#era-badge');
  367. if (s.eras > 0) { eb.hidden = false; eb.textContent = `纪元 ${s.eras + 1}`; } else eb.hidden = true;
  368. const bar = $('#pc-bar'), pct = $('#pc-pct');
  369. if (bar) {
  370. const i = s.curPlanet, p = s.planets[i];
  371. const v = 100 - p.rem;
  372. bar.style.width = v.toFixed(2) + '%';
  373. pct.textContent = v.toFixed(1) + '%';
  374. }
  375. }
  376. renderGoal() {
  377. const g = F.currentGoal(this.s, this.now);
  378. this.curGoal = g;
  379. $('#goal-text').textContent = g.text;
  380. $('#goal-sub').textContent = g.sub || '';
  381. const tree = $('#tree');
  382. tree.classList.toggle('hint', ['tut1', 'tut2', 'tut3', 'tut4'].includes(g.key));
  383. if (g.life) this.hlLife = g.life;
  384. }
  385. renderPlanetCard() {
  386. const s = this.s, i = s.curPlanet, P = PLANETS[i];
  387. const cleared = s.planets[i].rem <= 0;
  388. $('#progress-card').classList.toggle('cleared', cleared);
  389. const h = s.heat[i];
  390. $('#pc-name').textContent = P.name;
  391. const env = $('#pc-env');
  392. const cs = F.challengeStatus(s, i);
  393. if (h && h.kind === 'bad' && h.until > this.now) { env.textContent = `${P.wave.short}来袭`; env.className = 'pc-env bad'; }
  394. else if (h && h.kind === 'good' && h.until > this.now) { env.textContent = '环境转机'; env.className = 'pc-env good'; }
  395. else if (!cs.sat) { env.textContent = `${cs.threat.short}压制中`; env.className = 'pc-env'; }
  396. else { env.textContent = '生长中'; env.className = 'pc-env'; }
  397. const rate = F.growRateOf(s, i, this.now);
  398. $('#pc-note').textContent = cleared ? '星球复苏 · 绿意永续' : rate > 0 ? `+${rate.toFixed(2)}%/秒 · ${cs.sat ? '挑战已攻克' : '挑战压制中'}` : '根系正在寻找第一颗种子';
  399. const ex = S.exploreCostNow(s, i);
  400. const bt = $('#btn-explore');
  401. const exLeft = (s.planets[i].explore || 0) < B.STAR.exploreMax;
  402. bt.textContent = exLeft ? `勘探 ${fmt(ex)}` : '已勘探';
  403. bt.disabled = !exLeft || s.res < ex || s.planets[i].rem <= 0;
  404. }
  405. renderLives() {
  406. const s = this.s, i = s.curPlanet;
  407. const av = F.availableLives(s, i);
  408. const nextL = F.nextLife(s, i);
  409. const list = LIFE.filter((l) => l.planet === i);
  410. $('#lives').innerHTML = list.map((l) => {
  411. const cur = s.lives[i][l.id];
  412. const unlocked = av.some((x) => x.id === l.id);
  413. const cost = S.lifeCostNow(s, l.id);
  414. const can = unlocked && s.res >= cost;
  415. if (!unlocked) {
  416. const pct = (100 - s.planets[i].rem);
  417. return `<button class="life-btn locked" data-life="${l.id}" aria-label="${l.name}未解锁">${icon(l.icon)}<span class="nm">${l.name}</span><span class="lv">${pct < l.stage * 100 ? `${Math.round(l.stage * 100)}%` : '扎根'}</span></button>`;
  418. }
  419. return `<button class="life-btn ${can ? 'buyable' : ''}" data-life="${l.id}" aria-label="${l.name} ${cur || 0}级">${icon(l.icon)}<span class="nm">${l.name}</span><span class="lv">Lv ${cur || 0} · ${fmt(cost)}</span></button>`;
  420. }).join('');
  421. if (nextL && this.modalOpen === false) $$('.life-btn').forEach((b) => { if (b.dataset.life === nextL.id && !av.some((x) => x.id === nextL.id)) b.classList.add('next'); });
  422. $$('.life-btn').forEach((b) => b.addEventListener('click', () => this.onLifeBtn(b.dataset.life)));
  423. }
  424. onLifeBtn(id) {
  425. if (S.lifeAvailable(this.s, id)) this.buyLife(id);
  426. else {
  427. const l = lifeById(id);
  428. const pct = (100 - this.s.planets[this.s.curPlanet].rem);
  429. if (l.unlockRoot && this.s.rootLv < l.unlockRoot) this.toast(`<b>${l.name}</b><small>根系扎根到 ${l.unlockRoot} 级后才会苏醒</small>`, '', 2600);
  430. else this.toast(`<b>${l.name}</b><small>星球改造到 ${Math.round(l.stage * 100)}% 后苏醒</small>`, '', 2600);
  431. }
  432. }
  433. renderNavDots() {
  434. const btn = $('.tabbar [data-nav="ach"]');
  435. btn.querySelector('.dot')?.remove();
  436. if (achCount(this.s) > (this.s.seen.ach || 0)) { const d = document.createElement('i'); d.className = 'dot'; btn.appendChild(d); }
  437. }
  438. refreshDynamic() {
  439. this.renderGoal(); this.renderPlanetCard(); this.renderLives(); this.paintStats();
  440. // 星图只在状态变化时重绘(避免每帧重建 SVG 导致点击目标抖动)
  441. const sig = this.s.planets.map((p) => F.planetStatus(this.s, this.s.planets.indexOf(p))).join(',') + '|' + this.s.rootLv + '|' + this.s.curPlanet + '|' + this.s.planets.map((p) => p.rem <= 0 ? 1 : 0).join('');
  442. if (sig !== this.systemSig) { this.systemSig = sig; this.buildSystem(); }
  443. }
  444. renderAll() {
  445. this.buildSystem();
  446. this.renderGoal(); this.renderPlanetCard(); this.renderLives(); this.paintStats(); this.renderNavDots();
  447. // 抽屉正文只在“打开抽屉”时由 openSheet 渲染;其余渲染不重建(避免按钮句柄丢失与输入被打断)
  448. this.tutorialHint();
  449. }
  450. // ── 抽屉 ──────────────────────────────────────────
  451. openSheet(name, arg) {
  452. if (name === 'star') this.s.tutorial.starOpened = true;
  453. this.sheetName = name; this.sheetArg = arg;
  454. $('#sheet-mask').hidden = false;
  455. setTimeout(() => $('#sheet').focus({ preventScroll: true }), 30);
  456. if (name === 'ach') this.s.seen.ach = achCount(this.s);
  457. this.renderNavDots();
  458. $$('.tabbar button').forEach((b) => b.classList.toggle('on', b.dataset.nav === name));
  459. this.renderSheetBody();
  460. this.renderGoal();
  461. this.afterSheetRender(name);
  462. }
  463. closeSheet() {
  464. if ($('#sheet-mask').hidden) return;
  465. $('#sheet-mask').hidden = true; this.sheetName = null;
  466. $$('.tabbar button').forEach((b) => b.classList.remove('on'));
  467. }
  468. renderSheetBody() {
  469. const name = this.sheetName;
  470. const titles = { lives: '生命', star: '太阳系星图', era: '纪元 · 时间结晶', ach: '成就', root: '世界树根系', menu: '菜单', planet: PLANETS[this.s.curPlanet].name, lock: '尚未抵达' };
  471. $('#sheet-title').textContent = titles[name] || '';
  472. const body = $('#sheet-body');
  473. const foot = $('#sheet-foot');
  474. foot.innerHTML = '';
  475. if (name === 'lives') body.innerHTML = this.sheetLives();
  476. else if (name === 'star') body.innerHTML = this.sheetStar();
  477. else if (name === 'era') body.innerHTML = this.sheetEra();
  478. else if (name === 'ach') body.innerHTML = this.sheetAch();
  479. else if (name === 'root') body.innerHTML = this.sheetRoot();
  480. else if (name === 'menu') body.innerHTML = this.sheetMenu();
  481. else if (name === 'planet') body.innerHTML = this.sheetPlanet();
  482. else if (name === 'lock') body.innerHTML = `<div class="lock-note">${icon('lock')}<div>${esc(this.sheetArg?.msg || '')}</div></div><div class="sec-title">星球档案</div>${this.planetDossier(this.sheetArg?.i ?? 0)}`;
  483. if (name === 'lives') {
  484. const i = this.s.curPlanet;
  485. const cur = F.availableLives(this.s, i).find((l) => this.s.res >= S.lifeCostNow(this.s, l.id));
  486. if (cur) {
  487. foot.innerHTML = `<button class="btn primary" id="buy-best" style="width:100%">种下 / 升级「${esc(cur.name)}」· ${fmt(S.lifeCostNow(this.s, cur.id))}</button>`;
  488. $('#buy-best').onclick = () => this.buyLife(cur.id);
  489. }
  490. }
  491. if (name === 'root') {
  492. foot.innerHTML = `<button class="btn primary" id="root-buy" style="width:100%">升级根系 · ${fmt(S.rootCostNow(this.s))}</button>`;
  493. $('#root-buy').onclick = () => this.buyRootAll();
  494. }
  495. if (name === 'era') {
  496. if (S.canCurio(this.s)) {
  497. const opts = S.curioOptions(this.s);
  498. foot.innerHTML = `<div class="sec-title" style="margin-top:0">星辰洗礼(${B.CURIO.cost} 结晶 · 三选一)</div><div class="curio-opts">${opts.map((o) => `<button class="curio" data-el="${o.id}">${icon(o.icon)}<b>${o.name}</b><small>${o.desc}</small><span class="own">已有 ${(this.s.stems[o.id] || 0)}</span></button>`).join('')}</div>`;
  499. $$('#sheet-foot .curio').forEach((b) => b.onclick = () => { const out = S.doCurio(this.s, b.dataset.el); this.handle(out); this.renderAll(); this.paintStats(); });
  500. }
  501. return;
  502. }
  503. if (name === 'planet') {
  504. const i = this.s.curPlanet;
  505. const cs = F.challengeStatus(this.s, i);
  506. if (!cs.sat && cs.unlockedAll) { /* 挑战详情在正文里 */ }
  507. const h = this.s.heat[i];
  508. const canHeal = h.kind === 'bad' && !h.healed && h.until - this.now >= B.STAR.heatBadDur - B.STAR.healWindow && h.until > this.now;
  509. foot.innerHTML = `${canHeal ? `<button class="btn primary" id="heal-btn" style="width:100%">修补根系屏障 · ${fmt(S.healCostNow(this.s, this.now))}</button>` : ''}`;
  510. if (canHeal) $('#heal-btn').onclick = () => { const out = S.heal(this.s, this.now); this.handle(out); this.renderAll(); };
  511. }
  512. }
  513. sheetLives() {
  514. const s = this.s, i = s.curPlanet;
  515. const P = PLANETS[i];
  516. const av = F.availableLives(s, i);
  517. const nextL = F.nextLife(s, i);
  518. const ls = LIFE.filter((l) => l.planet === i);
  519. const rows = ls.map((l) => {
  520. const cur = s.lives[i][l.id];
  521. const unlocked = av.some((x) => x.id === l.id);
  522. const cost = S.lifeCostNow(s, l.id);
  523. if (!unlocked) {
  524. const need = l.unlockRoot && s.rootLv < l.unlockRoot ? `世界树扎根 ${l.unlockRoot} 级` : `星球改造 ${Math.round(l.stage * 100)}%`;
  525. return `<div class="card life-card locked">${iconBox(l.icon, true)}<div><h4>${l.name}</h4><p>${esc(l.lore)}</p><p style="color:#8fa2c4;margin-top:4px">🔒 ${need} 后苏醒</p></div><div></div></div>`;
  526. }
  527. return `<div class="card life-card">${iconBox(l.icon)}<div><h4>${l.name} <span class="muted small">Lv ${cur || 0}</span></h4><p>${esc(l.lore)}</p><p style="margin-top:4px;color:#9cffc0">${kindText(l)}${cur ? ` · 已叠 ${stackText(l, cur)}` : ''}</p></div><button class="buy" data-buy="${l.id}" ${s.res < cost ? 'disabled' : ''}>${cur ? '升级' : '种下'}<span class="c">${fmt(cost)} 本源</span></button></div>`;
  528. }).join('');
  529. $$('.life-card').forEach(() => {});
  530. setTimeout(() => $$('#sheet-body [data-buy]').forEach((b) => b.onclick = () => this.buyLife(b.dataset.buy)), 0);
  531. const root = `<div class="card life-card">${iconBox('root')}<div><h4>世界树根系 <span class="muted small">Lv ${s.rootLv}</span></h4><p>根系越深,本源生长越快。${PLANETS[Math.min(8, i + 1)].name}需要扎根 ${PLANETS[Math.min(8, i + 1)].unlockLv} 级。</p><p style="margin-top:4px;color:#9cffc0">本源产出 ×${B.rootProdMul(s.rootLv).toFixed(2)}</p></div><button class="buy" data-root="1" ${s.res < S.rootCostNow(s) ? 'disabled' : ''}>扎根<span class="c">${fmt(S.rootCostNow(s))} 本源</span></button></div>`;
  532. setTimeout(() => { const b = $('#sheet-body [data-root]'); if (b) b.onclick = () => this.buyRootAll(); }, 0);
  533. const nextHint = nextL && !av.some((x) => x.id === nextL.id) ? `<div class="card"><b class="small">下一株生命 · ${nextL.name}</b><p class="small muted" style="margin:4px 0 0">${nextL.unlockRoot && s.rootLv < nextL.unlockRoot ? `根系扎根到 ${nextL.unlockRoot} 级` : `星球改造到 ${Math.round(nextL.stage * 100)}%`} 后,它会从根须里苏醒。</p></div>` : '';
  534. return `<div class="sec-title">${P.name} · 生命</div>${root}${rows}${nextHint}`;
  535. }
  536. sheetStar() {
  537. const s = this.s;
  538. const rows = PLANETS.map((P, i) => {
  539. const st = F.planetStatus(s, i);
  540. const pct = 100 - s.planets[i].rem;
  541. const sub = st === 'cleared' ? '已复苏 ✓' : st === 'locked' ? `需要:${PLANETS[i - 1].name}复苏 · 扎根 ${P.unlockLv} 级` : `${Math.round(pct)}% · ${i === s.curPlanet ? '当前' : '可前往'}`;
  542. const go = st === 'cleared' ? '已复苏' : st === 'locked' ? '未解锁' : i === s.curPlanet ? '改造中' : '前往';
  543. return `<div class="pcard ${st} ${i === s.curPlanet ? 'cur' : ''}" data-go="${i}"><div class="orb" style="background: radial-gradient(circle at 34% 30%, ${P.color2}, ${P.color} 60%, #1a2234)"></div><div><h4>${P.name} <span class="muted small">第 ${P.chapterNo} 章</span></h4><p>${sub}</p></div><span class="go ${st === 'locked' ? 'lock' : ''}">${go} ›</span></div>`;
  544. }).join('');
  545. setTimeout(() => $$('#sheet-body [data-go]').forEach((c) => c.onclick = () => { const i = +c.dataset.go; if (F.isPlanetUnlocked(s, i)) { if (i !== s.curPlanet && s.planets[i].rem > 0) { this.closeSheet(); this.switchPlanet(i); } else this.openSheet('planet'); } else this.explainLocked(i); }), 0);
  546. const done = F.clearedCount(s);
  547. return `<div class="card"><div class="row"><div class="grow"><b>太阳系复苏进度</b><p class="small muted" style="margin:4px 0 0">${done} / ${PLANETS.length} 颗星球重新长出生命</p></div><b style="font-size:26px;color:var(--green2)">${Math.round(done / PLANETS.length * 100)}%</b></div></div><div class="sec-title">逐星推进</div><div class="planet-list">${rows}</div>`;
  548. }
  549. sheetEra() {
  550. const s = this.s;
  551. const can = S.canEra(s);
  552. const cleared = F.clearedCount(s);
  553. const reward = S.eraPreview(s);
  554. const stems = B.STEM_ELEMENTS.map((e) => `<div class="kv"><span class="k" style="display:flex;gap:6px;align-items:center">${icon(e.icon)} ${e.name}</span><span class="v">×${s.stems[e.id] || 0}</span></div>`).join('');
  555. const lock = can ? '' : `<div class="lock-note">${icon('lock')}<div><b>新纪元尚未开启</b><br>必须先让<b>地球复苏</b>${s.planets[0].rem <= 0 ? `,并让世界树扎根到 ${B.ERA.minRootLv} 级(当前 ${s.rootLv} 级)` : '——这是第一个纪元的终章仪式'}。<br>纪元会重置所有星球的改造与生命,但时间结晶与基因之种永久保留。</div></div>`;
  556. const btn = can ? `<div class="sec-title">星辰洗礼</div>${S.canCurio(s) ? '<p class="small muted">选择一颗基因之种,它会永久改变下一个纪元。</p>' : `<p class="small muted">攒够 ${B.CURIO.cost} 颗时间结晶,可以完成一次三选一的星辰洗礼。(当前 ${s.crystals})</p>`}` : '';
  557. return `<div class="era-hero"><div class="lbl">当前纪元</div><div class="big">${s.eras + 1}</div><div class="small muted">纪元乘区 ×${F.eraFactor(s).toFixed(2)} · 时间结晶 ${s.crystals}</div></div>
  558. ${lock}
  559. <div class="card"><div class="kv"><span class="k">已完成星球</span><span class="v">${cleared} / ${PLANETS.length}</span></div>
  560. <div class="kv"><span class="k">进入新纪元可得</span><span class="v" style="color:var(--gold)">时间结晶 ×${reward}</span></div>
  561. <div class="kv"><span class="k">永久加成(每次纪元)</span><span class="v">产出与生长 ×1.25</span></div>
  562. <div class="kv"><span class="k">时间结晶效果</span><span class="v">产出 +15%/颗 · 基因之种 −4%/颗</span></div></div>
  563. ${can ? `<button class="btn primary" id="era-go" style="width:100%;margin:6px 0 10px">进入新纪元 · ${s.eras + 2}</button>` : ''}
  564. <div class="sec-title">基因之种(跨纪元永久)</div><div class="card">${stems}</div>${btn}`;
  565. }
  566. sheetAch() {
  567. const s = this.s;
  568. const grid = ACHIEVEMENTS.map((a) => `<div class="ach ${s.ach[a.id] ? 'on' : ''}"><div class="ic">${icon(a.icon)}</div><b>${a.name}</b><small>${a.desc}</small></div>`).join('');
  569. return `<div class="card"><div class="row"><div class="grow"><b>成就</b><p class="small muted" style="margin:4px 0 0">已点亮 ${achCount(s)} / ${ACHIEVEMENTS.length}</p></div><b style="font-size:26px;color:var(--gold)">${Math.round(achCount(s) / ACHIEVEMENTS.length * 100)}%</b></div></div><div class="ach-grid">${grid}</div>`;
  570. }
  571. sheetRoot() {
  572. const s = this.s;
  573. const P = PLANETS[s.curPlanet];
  574. const nextP = PLANETS[Math.min(PLANETS.length - 1, s.curPlanet + 1)];
  575. const rows = [
  576. ['根系等级', `Lv ${s.rootLv}`],
  577. ['本源产出乘区', `×${B.rootProdMul(s.rootLv).toFixed(2)}(每级 +${(B.ROOT.prodPer * 100).toFixed(0)}%)`],
  578. ['点击本源', fmt(F.tapOf(s, this.now))],
  579. ['自动产出', fmt(F.incomeOf(s, this.now)) + '/秒'],
  580. ['星辰共鸣', '×' + fmt(F.resonanceMul(s)) + '(此前复苏星球的生命)'],
  581. ['纪元乘区', `×${F.eraFactor(s).toFixed(2)}`],
  582. ['下一颗星', `${nextP.name} · 需要扎根 ${nextP.unlockLv} 级`],
  583. ].map(([k, v]) => `<div class="kv"><span class="k">${k}</span><span class="v">${v}</span></div>`).join('');
  584. return `<div class="card">${rows}</div><p class="small muted">根系是全太阳系的根:等级越高,所有星球的生长都越快。</p>`;
  585. }
  586. sheetPlanet() {
  587. const s = this.s, i = s.curPlanet, P = PLANETS[i];
  588. const ch = CHAPTER_TEXT[P.id];
  589. const cs = F.challengeStatus(s, i);
  590. const th = cs.threat;
  591. const h = s.heat[i];
  592. const pct = 100 - s.planets[i].rem;
  593. return `${this.planetDossier(i)}
  594. <div class="sec-title">环境挑战 · ${th.name}</div>
  595. <div class="card"><p class="lore">${esc(th.desc)}</p>
  596. <div class="kv"><span class="k">攻克条件</span><span class="v" style="color:${cs.sat ? 'var(--green2)' : 'var(--red)'}">${th.needText} ${cs.sat ? '✓' : '✗'}</span></div>
  597. <div class="kv"><span class="k">当前压制</span><span class="v">${cs.sat ? '已攻克' : `改造速度 −${Math.round(B.STAR.attackDef * B.STAR.suppress * 100)}%`}</span></div>
  598. ${P.wave ? `<div class="kv"><span class="k">环境波动</span><span class="v">${h.kind === 'bad' && h.until > this.now ? `${P.wave.name}来袭` : h.kind === 'good' && h.until > this.now ? '转机' : '平稳'}</span></div>` : ''}</div>
  599. <div class="sec-title">本章</div><div class="card"><p class="lore">${esc(ch.intro.text)}</p></div>`;
  600. }
  601. planetDossier(i) {
  602. const P = PLANETS[i];
  603. const pct = 100 - this.s.planets[i].rem;
  604. return `<div class="card"><div class="row"><div style="width:56px;height:56px;position:relative">${`<svg viewBox="-60 -60 120 120" style="width:56px;height:56px">${planetSvg(i, 34)}</svg>`}</div><div class="grow"><b>${P.name} <span class="muted small">${P.en}</span></b><p class="small muted" style="margin:4px 0 0">${esc(P.intro)}</p></div></div>
  605. <div class="bar" style="margin-top:10px"><i style="width:${pct.toFixed(1)}%"></i><span>${pct.toFixed(1)}%</span></div></div>`;
  606. }
  607. sheetMenu() {
  608. return `<div class="card"><b>存档</b><p class="small muted" style="margin:6px 0 10px">游戏每 5 秒自动保存在本机。导出后可在其他设备导入。</p>
  609. <div class="row" style="gap:8px"><button class="btn ghost grow" id="m-export">导出存档</button><label class="btn ghost grow" style="display:inline-flex;align-items:center;justify-content:center;text-align:center">导入<input type="file" id="m-import" accept="application/json,.json" hidden></label></div>
  610. <button class="btn ghost" id="m-reset" style="width:100%;margin-top:8px;color:var(--red);border-color:rgba(255,122,107,.3)">重新开始(清除存档)</button></div>
  611. <div class="card"><b>关于</b><p class="small muted" style="margin:6px 0 0;line-height:1.8">《世界树 · 太阳系》<br>作者:FmodeCode<br>操作:点击世界树获得本源 · 空格键也可以<br>快捷键:Esc 关闭弹层</p></div>
  612. <p class="small muted" style="text-align:center;margin-top:12px">版本 v3 · 太阳系篇</p>`;
  613. }
  614. afterSheetRender(m) {
  615. if (m === 'era') {
  616. const go = document.getElementById('era-go');
  617. if (go) go.onclick = () => { const out = S.doEra(this.s); this.handle(out); this.renderAll(); };
  618. return;
  619. }
  620. if (m !== 'menu') return;
  621. $('#m-export').onclick = () => {
  622. const blob = new Blob([S.save.serialize(this.s)], { type: 'application/json' });
  623. const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'worldtree-solaris-save.json'; a.click();
  624. setTimeout(() => URL.revokeObjectURL(a.href), 1000);
  625. this.toast('<b>存档已导出</b>', 'green');
  626. };
  627. $('#m-import').onchange = async (e) => {
  628. const f = e.target.files[0]; if (!f) return;
  629. const text = await f.text();
  630. const r = S.save.parse(text);
  631. if (!r.ok) { this.toast(`<b>导入失败</b><small>${r.error}</small>`, '', 3000); return; }
  632. S.save.write(localStorage, r.data); location.reload();
  633. };
  634. $('#m-reset').onclick = () => {
  635. if (!confirm('确定清除存档,从第一根须重新开始吗?')) return;
  636. S.save.clear(localStorage); location.reload();
  637. };
  638. }
  639. }
  640. function iconBox(name, locked) { return `<div class="ic">${icon(name)}</div>`; }
  641. function kindText(l) {
  642. if (l.kind === 'prod') return `本源产出 +${Math.round(l.per * 100)}%/级`;
  643. if (l.kind === 'attack') return `星球稳定 +${Math.round(l.per * 100)}%/级(产出与改造更快)`;
  644. return `产出 +${Math.round(l.per * 100)}% · 稳定 +${Math.round(l.per * 100)}%/级`;
  645. }
  646. function stackText(l, n) {
  647. if (l.kind === 'prod') return `本源 ×${(1 + l.per * n).toFixed(2)}`;
  648. if (l.kind === 'attack') return `稳定 +${(l.per * n * 100).toFixed(0)}%`;
  649. return `本源 ×${(1 + l.per * n).toFixed(2)} · 稳定 +${(l.per * n * 100).toFixed(0)}%`;
  650. }
  651. function confettiSmall() {
  652. const layer = document.getElementById('fx');
  653. for (let k = 0; k < 18; k++) {
  654. const e = document.createElement('div'); e.className = 'spark';
  655. e.style.left = (innerWidth / 2 + (Math.random() - 0.5) * 80) + 'px'; e.style.top = innerHeight * 0.6 + 'px';
  656. e.style.setProperty('--dx', (Math.random() - 0.5) * 120 + 'px'); e.style.setProperty('--dy', (-60 - Math.random() * 80) + 'px');
  657. layer.appendChild(e); setTimeout(() => e.remove(), 700);
  658. }
  659. }
  660. /** 导出给自动化测试使用:渲染类的小工具 */
  661. export const __test = { planetPos };