cortico-world-genesis 2.6.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/webui.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/webui/client.ts
1
+ // src/webui/i18n.ts
2
2
  var ZH = {
3
3
  title: "\u521B\u4E16\u8BB0",
4
4
  desc: "\u4E00\u9897\u661F\uFF0C\u53EA\u6210\u5F62\u4E00\u6B21\u3002\u9009\u597D\u79CD\u5B50\u4E0E\u51E0\u4E2A\u65CB\u94AE\uFF0C\u5199\u8FDB\u5B58\u6863\u540E\u5C31\u9501\u5B9A\u3002",
@@ -406,6 +406,340 @@ var EN = {
406
406
  function text(language) {
407
407
  return language.startsWith("zh") ? ZH : EN;
408
408
  }
409
+
410
+ // src/webui/tokens.ts
411
+ var TOKENS = `
412
+ :root {
413
+ --gx-bg: #080b0a;
414
+ --gx-panel: #0d1210;
415
+ --gx-line: #1d2a24;
416
+ --gx-line-soft: #14201b;
417
+ --gx-ink: #cfe7dc;
418
+ --gx-ink-dim: #7d9a8c;
419
+ --gx-ink-faint: #4d6158;
420
+ --gx-accent: #5ef2a0;
421
+ --gx-accent-dim: #2f8f63;
422
+ --gx-warn: #ffb454;
423
+ --gx-bad: #ff6b6b;
424
+ --gx-glow: 0 0 0 1px rgba(94, 242, 160, 0.18), 0 0 14px rgba(94, 242, 160, 0.06);
425
+ --gx-sp-1: 4px;
426
+ --gx-sp-2: 8px;
427
+ --gx-sp-3: 12px;
428
+ --gx-sp-4: 16px;
429
+ --gx-radius: 6px;
430
+ --gx-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
431
+ --gx-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
432
+ }
433
+
434
+ .gx {
435
+ background: var(--gx-bg);
436
+ color: var(--gx-ink);
437
+ font-family: var(--gx-sans);
438
+ font-size: 13px;
439
+ line-height: 1.55;
440
+ border-radius: var(--gx-radius);
441
+ padding: var(--gx-sp-4);
442
+ }
443
+
444
+ .gx-topbar {
445
+ display: flex;
446
+ flex-wrap: wrap;
447
+ align-items: center;
448
+ gap: var(--gx-sp-2) var(--gx-sp-3);
449
+ padding: var(--gx-sp-2) var(--gx-sp-3);
450
+ margin-bottom: var(--gx-sp-3);
451
+ background: var(--gx-panel);
452
+ border: 1px solid var(--gx-line);
453
+ border-radius: var(--gx-radius);
454
+ box-shadow: var(--gx-glow);
455
+ }
456
+
457
+ .gx-topbar .gx-num { font-family: var(--gx-mono); font-variant-numeric: tabular-nums; }
458
+ .gx-topbar .gx-dim { color: var(--gx-ink-dim); }
459
+ .gx-topbar .gx-spacer { flex: 1 1 auto; }
460
+
461
+ .gx-body { display: grid; gap: var(--gx-sp-3); }
462
+
463
+ .gx-card {
464
+ background: var(--gx-panel);
465
+ border: 1px solid var(--gx-line-soft);
466
+ border-radius: var(--gx-radius);
467
+ padding: var(--gx-sp-3);
468
+ }
469
+
470
+ .gx-card-head {
471
+ display: flex;
472
+ align-items: center;
473
+ gap: var(--gx-sp-2);
474
+ margin-bottom: var(--gx-sp-2);
475
+ font-weight: 600;
476
+ letter-spacing: 0.02em;
477
+ }
478
+
479
+ .gx-card-head::before {
480
+ content: "";
481
+ width: 6px;
482
+ height: 6px;
483
+ border-radius: 50%;
484
+ background: var(--gx-accent);
485
+ box-shadow: 0 0 8px var(--gx-accent);
486
+ }
487
+
488
+ .gx-grid-2 { display: grid; gap: var(--gx-sp-2); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
489
+ .gx-grid-3 { display: grid; gap: var(--gx-sp-2); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
490
+
491
+ .gx-row { display: flex; align-items: baseline; gap: var(--gx-sp-2); }
492
+ .gx-row + .gx-row { margin-top: var(--gx-sp-1); }
493
+ .gx-row .gx-k { color: var(--gx-ink-dim); }
494
+ .gx-row .gx-v { font-family: var(--gx-mono); font-variant-numeric: tabular-nums; }
495
+ .gx-row .gx-gap { flex: 1 1 auto; }
496
+
497
+ .gx-num { font-family: var(--gx-mono); font-variant-numeric: tabular-nums; }
498
+ .gx-ok { color: var(--gx-accent); }
499
+ .gx-warn { color: var(--gx-warn); }
500
+ .gx-bad { color: var(--gx-bad); }
501
+ .gx-dim { color: var(--gx-ink-dim); }
502
+ .gx-faint { color: var(--gx-ink-faint); }
503
+
504
+ .gx-bar {
505
+ height: 6px;
506
+ background: var(--gx-line-soft);
507
+ border-radius: 3px;
508
+ overflow: hidden;
509
+ }
510
+ .gx-bar > i { display: block; height: 100%; background: var(--gx-accent-dim); }
511
+ .gx-bar.is-warn > i { background: var(--gx-warn); }
512
+ .gx-bar.is-bad > i { background: var(--gx-bad); }
513
+
514
+ .gx-list { display: grid; gap: var(--gx-sp-1); }
515
+ .gx-list .gx-item {
516
+ display: flex;
517
+ gap: var(--gx-sp-2);
518
+ padding: var(--gx-sp-1) var(--gx-sp-2);
519
+ border-radius: var(--gx-sp-1);
520
+ border: 1px solid transparent;
521
+ }
522
+ .gx-list .gx-item:hover { border-color: var(--gx-line); background: rgba(94, 242, 160, 0.03); }
523
+
524
+ .gx-empty { color: var(--gx-ink-faint); font-style: italic; }
525
+
526
+ /* \u7A84\u5C4F\uFF1A\u5361\u7247\u53E0\u6210\u4E00\u5217\uFF0C\u9876\u680F\u5141\u8BB8\u6362\u884C\uFF0C\u6570\u5B57\u4E0D\u6324\u5728\u4E00\u8D77\u3002 */
527
+ @media (max-width: 760px) {
528
+ .gx-body { grid-template-columns: 1fr; }
529
+ .gx-topbar { flex-wrap: wrap; gap: var(--gx-sp-1); }
530
+ .gx-row { flex-wrap: wrap; }
531
+ .gx-bar { width: 48px; }
532
+ .gx-view { min-width: 0; }
533
+ }
534
+ `;
535
+ var installed = false;
536
+ function ensureStyles(owner) {
537
+ if (installed || owner.querySelector("style[data-gx-tokens]")) return;
538
+ const style = owner.createElement("style");
539
+ style.setAttribute("data-gx-tokens", "1");
540
+ style.textContent = TOKENS;
541
+ owner.head.append(style);
542
+ installed = true;
543
+ }
544
+
545
+ // src/webui/shell.ts
546
+ function num(value, digits = 0) {
547
+ return value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
548
+ }
549
+ function bar(ratio, tone) {
550
+ const wrap = document.createElement("span");
551
+ wrap.className = tone ? `gx-bar is-${tone}` : "gx-bar";
552
+ wrap.style.width = "72px";
553
+ wrap.style.display = "inline-block";
554
+ wrap.style.verticalAlign = "middle";
555
+ const fill = document.createElement("i");
556
+ fill.style.width = `${Math.max(0, Math.min(1, ratio)) * 100}%`;
557
+ wrap.append(fill);
558
+ return wrap;
559
+ }
560
+ function createShell(ctx, opts) {
561
+ ensureStyles(ctx.root.ownerDocument);
562
+ const sheet = ctx.ui.sheet({ title: opts.title, desc: opts.desc });
563
+ const root = ctx.ui.h("div", "gx");
564
+ const topbar = ctx.ui.h("div", "gx-topbar");
565
+ const body = ctx.ui.h("div", "gx-body");
566
+ root.append(topbar, body);
567
+ sheet.body.append(root);
568
+ ctx.root.append(sheet.el);
569
+ const clock = ctx.ui.h("span", "gx-num");
570
+ const where = ctx.ui.h("span", "gx-dim");
571
+ const energy = ctx.ui.h("span", "gx-num");
572
+ const energyBar = ctx.ui.h("span");
573
+ const tungsten = ctx.ui.h("span", "gx-num");
574
+ const credits = ctx.ui.h("span", "gx-num");
575
+ const ship = ctx.ui.h("span", "gx-num");
576
+ const charter = ctx.ui.h("span", "gx-num");
577
+ topbar.append(clock, where, ctx.ui.h("span", "gx-spacer"), energy, energyBar, tungsten, credits, ship, charter);
578
+ return {
579
+ root,
580
+ body,
581
+ update(state) {
582
+ if (!state || state.locked) {
583
+ clock.textContent = "\u672A\u521B\u4E16";
584
+ where.textContent = "";
585
+ energy.textContent = "";
586
+ tungsten.textContent = "";
587
+ credits.textContent = "";
588
+ ship.textContent = "";
589
+ charter.textContent = "";
590
+ energyBar.replaceChildren();
591
+ return;
592
+ }
593
+ clock.textContent = state.game?.time ?? "\u2014";
594
+ where.textContent = state.game?.where ?? "";
595
+ const power = state.power;
596
+ if (power) {
597
+ const ratio = power.capacityKj > 0 ? power.energyKj / power.capacityKj : 0;
598
+ energy.textContent = `\u26A1 ${num(power.energyKj)} / ${num(power.capacityKj)} kJ`;
599
+ energy.className = ratio < 0.1 ? "gx-num gx-bad" : ratio < 0.25 ? "gx-num gx-warn" : "gx-num";
600
+ energyBar.replaceChildren(bar(ratio, ratio < 0.1 ? "bad" : ratio < 0.25 ? "warn" : void 0));
601
+ tungsten.textContent = `\u94A8 ${num(power.tungsten)}`;
602
+ credits.textContent = `\u{1F4B3} ${num(power.credits)}`;
603
+ credits.className = "gx-num gx-dim";
604
+ const sleepers = power.ship?.sleepers ?? 0;
605
+ if (sleepers > 0) {
606
+ const hours = power.ship?.hoursLeft;
607
+ ship.textContent = hours === null || hours === void 0 ? `\u8231\u5185 ${sleepers} \u4EBA` : `\u8231\u5185 ${sleepers} \u4EBA \xB7 \u7EA6 ${num(hours)} \u65F6`;
608
+ ship.className = hours !== null && hours !== void 0 && hours < 72 ? "gx-num gx-warn" : "gx-num gx-dim";
609
+ } else {
610
+ ship.textContent = "";
611
+ }
612
+ } else {
613
+ energy.textContent = "";
614
+ energyBar.replaceChildren();
615
+ tungsten.textContent = "";
616
+ credits.textContent = "";
617
+ ship.textContent = "";
618
+ }
619
+ const c = state.power?.charter;
620
+ if (c?.charter === "tourism") {
621
+ charter.textContent = `\u65C5\u6E38 \xB7 \u77E5\u540D\u5EA6 ${num(c.reputation ?? 0, 0)}`;
622
+ charter.className = "gx-num gx-ok";
623
+ } else if (c?.charter === "tech") {
624
+ charter.textContent = `\u79D1\u6280 \xB7 \u7B97\u529B ${num(c.compute ?? 0, 1)}`;
625
+ charter.className = "gx-num gx-ok";
626
+ } else {
627
+ charter.textContent = "";
628
+ }
629
+ }
630
+ };
631
+ }
632
+
633
+ // src/webui/panels/overview.ts
634
+ function num2(value, digits = 0) {
635
+ return value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
636
+ }
637
+ function card(ctx, title) {
638
+ const el = ctx.ui.h("div", "gx-card");
639
+ const body = ctx.ui.h("div");
640
+ el.append(ctx.ui.h("div", "gx-card-head", title), body);
641
+ return { el, body };
642
+ }
643
+ function row(ctx, key, value, tone) {
644
+ const line = ctx.ui.h("div", "gx-row");
645
+ line.append(ctx.ui.h("span", "gx-k", key), ctx.ui.h("span", "gx-gap"), ctx.ui.h("span", tone ? `gx-v ${tone}` : "gx-v", value));
646
+ return line;
647
+ }
648
+ function nextSteps(state) {
649
+ const out = [];
650
+ const power = state.power;
651
+ const ship = power?.ship;
652
+ const people = state.habitats.reduce((sum, h) => sum + h.awake, 0);
653
+ const pending = state.protocol ? state.protocol.total - state.protocol.done : 0;
654
+ if (ship && ship.sleepers > 0 && ship.hoursLeft !== null && ship.hoursLeft < 72) {
655
+ out.push({ label: `\u7740\u9646\u8231\u7684\u6C27\u6C14\u53EA\u591F\u7EA6 ${num2(ship.hoursLeft)} \u6BCD\u661F\u65F6\uFF1A\u5148\u53BB\u79CD\u3001\u53BB\u4EA7\u6C27`, tone: "bad", tab: "\u519C\u573A" });
656
+ }
657
+ if (power && power.capacityKj > 0 && power.energyKj < power.capacityKj * 0.1) {
658
+ out.push({ label: "\u7535\u5FEB\u89C1\u5E95\uFF1A\u624B\u6447\u4E00\u4E0B\uFF0C\u6216\u8005\u53BB\u300C\u5DE5\u4E1A\u300D\u5EFA\u592A\u9633\u80FD\u5E06", tone: "bad", tab: "\u5DE5\u4E1A" });
659
+ }
660
+ if (people === 0 && ship && ship.sleepers > 0) {
661
+ out.push({ label: "\u8FD8\u6CA1\u53EB\u9192\u4EFB\u4F55\u4EBA\uFF1A\u534F\u8BAE\u6E05\u5355\u5728\u300C\u534F\u8BAE\u300D\u9875", tone: "warn", tab: "\u534F\u8BAE" });
662
+ }
663
+ if (state.buildQueueFull) {
664
+ out.push({ label: "\u65BD\u5DE5\u961F\u5217\u6EE1\u4E86\uFF1A\u53BB\u300C\u5347\u7EA7\u300D\u4FEE\u5B50\u4EE3\u7406", tone: "warn", tab: "\u5347\u7EA7" });
665
+ }
666
+ if (pending > 0) {
667
+ out.push({ label: `\u534F\u8BAE\u8FD8\u5DEE ${pending} \u9879\uFF08\u5171 ${state.protocol?.total ?? 0}\uFF09`, tone: "warn", tab: "\u534F\u8BAE" });
668
+ }
669
+ if (out.length === 0) out.push({ label: "\u6CA1\u6709\u5361\u4F4F\u7684\u4E8B\uFF1A\u53EF\u4EE5\u53BB\u300C\u5730\u8868\u300D\u770B\u770B\u5730\u56FE\uFF0C\u6216\u8005\u63A8\u4E00\u63A8\u8FDB\u5EA6", tone: "ok", tab: "\u5730\u8868" });
670
+ return out.slice(0, 4);
671
+ }
672
+ var panel = {
673
+ async mount(ctx) {
674
+ const t = text(ctx.language);
675
+ const shell = createShell(ctx, { title: t.title, desc: t.desc ?? "" });
676
+ let state = null;
677
+ const lockedNote = ctx.ui.h("div", "gx-empty");
678
+ const status = card(ctx, "\u72B6\u51B5");
679
+ const vital = card(ctx, "\u8981\u7D27\u7684\u6570");
680
+ const todo = card(ctx, "\u4E0B\u4E00\u6B65");
681
+ shell.body.append(lockedNote, status.el, vital.el, todo.el);
682
+ const render = () => {
683
+ shell.update(state);
684
+ if (!state || state.locked) {
685
+ lockedNote.textContent = "\u8FD8\u6CA1\u6709\u521B\u4E16 \u2014\u2014 \u53BB\u300C\u5730\u8868\u300D\u9875\u7B7E\uFF0C\u7528\u79CD\u5B50\u4E0E\u6052\u661F\u8D28\u91CF\u5F00\u4E00\u9897\u661F\u3002";
686
+ status.body.replaceChildren();
687
+ vital.body.replaceChildren();
688
+ todo.body.replaceChildren();
689
+ return;
690
+ }
691
+ lockedNote.textContent = "";
692
+ status.body.replaceChildren(
693
+ row(ctx, "\u65F6\u95F4", state.game?.time ?? "\u2014"),
694
+ row(ctx, "\u4F4D\u7F6E", state.game?.where ?? "\u2014"),
695
+ row(ctx, "\u72B6\u6001", state.game?.transit ?? "\u6CA1\u6709\u5728\u79FB\u52A8", state.game?.transit ? "gx-warn" : "gx-ok"),
696
+ row(ctx, "\u5386\u6CD5", state.game?.calendar ?? "\u2014", "gx-dim")
697
+ );
698
+ const power = state.power;
699
+ const ship = power?.ship;
700
+ const people = state.habitats.reduce((sum, h) => sum + h.awake, 0);
701
+ const capacity = state.habitats.length * 20;
702
+ const food = ship ? `${num2(ship.food, 1)} kg` : "\u2014";
703
+ const water = ship ? `${num2(ship.water, 0)} L` : "\u2014";
704
+ const oxygen = ship ? `${num2(ship.oxygen, 1)} kg` : "\u2014";
705
+ const hours = ship?.hoursLeft;
706
+ const grid = ctx.ui.h("div", "gx-grid-3");
707
+ const cells = [
708
+ ["\u5E38\u4F4F\u4EBA\u53E3", `${num2(people)} / ${num2(capacity)}`, people === 0 ? "gx-warn" : "gx-ok"],
709
+ ["\u7740\u9646\u8231 \xB7 \u7CAE", food],
710
+ ["\u7740\u9646\u8231 \xB7 \u6C34", water],
711
+ ["\u7740\u9646\u8231 \xB7 \u6C27", oxygen],
712
+ ["\u8FD8\u80FD\u6491", hours === null || hours === void 0 ? "\u2014" : `${num2(hours)} \u6BCD\u661F\u65F6`, hours !== null && hours !== void 0 && hours < 72 ? "gx-bad" : void 0],
713
+ ["\u7535", power ? `${num2(power.energyKj)} kJ` : "\u2014"],
714
+ ["\u4FE1\u7528\u70B9", power ? num2(power.credits) : "\u2014"],
715
+ ["\u94A8", power ? `${num2(power.tungsten)} \u4EFD` : "\u2014"]
716
+ ];
717
+ for (const [k, v, tone] of cells) {
718
+ const cell = ctx.ui.h("div");
719
+ cell.append(row(ctx, k, v, tone));
720
+ grid.append(cell);
721
+ }
722
+ vital.body.replaceChildren(grid);
723
+ const steps = nextSteps(state);
724
+ const list = ctx.ui.h("div", "gx-list");
725
+ for (const step of steps) {
726
+ const item = ctx.ui.h("div", "gx-item");
727
+ const light = step.tone === "bad" ? "gx-bad" : step.tone === "warn" ? "gx-warn" : "gx-ok";
728
+ item.append(ctx.ui.h("span", light, "\u25CF"), ctx.ui.h("span", "gx-num", step.label), ctx.ui.h("span", "gx-gap"), ctx.ui.h("span", "gx-faint", step.tab));
729
+ list.append(item);
730
+ }
731
+ todo.body.replaceChildren(list);
732
+ };
733
+ const load = async () => {
734
+ state = await ctx.invoke("state", []);
735
+ render();
736
+ };
737
+ await load();
738
+ }
739
+ };
740
+ var overview_default = panel;
741
+
742
+ // src/webui/ui-kit.ts
409
743
  var BIOME_LABELS = [
410
744
  "\u6D77\u6D0B",
411
745
  "\u51B0\u76D6",
@@ -485,17 +819,28 @@ function clamp(value, min, max) {
485
819
  return Math.min(max, Math.max(min, value));
486
820
  }
487
821
  function field(ui, label, input, hint) {
488
- const row = ui.h("div");
489
- row.style.display = "grid";
490
- row.style.gap = "4px";
822
+ const row2 = ui.h("div");
823
+ row2.style.display = "grid";
824
+ row2.style.gap = "4px";
491
825
  const help = ui.h("span", "muted", hint);
492
826
  help.style.fontSize = "12px";
493
- row.append(ui.h("label", "muted", label), input, help);
494
- return row;
827
+ row2.append(ui.h("label", "muted", label), input, help);
828
+ return row2;
829
+ }
830
+ function errorText(error) {
831
+ return error instanceof Error ? error.message : String(error);
832
+ }
833
+ function normalizeSeedInput(raw) {
834
+ const text2 = raw.trim();
835
+ if (!text2) return 20261111;
836
+ return /^\d{1,15}$/.test(text2) ? Number(text2) : text2;
495
837
  }
838
+
839
+ // src/webui/map.ts
496
840
  var WIDTH = 720;
497
841
  var HEIGHT = 360;
498
- function drawMap(canvas, map) {
842
+ var PX_PER_DEG = HEIGHT / 180;
843
+ function drawMap(canvas, map, territories = []) {
499
844
  const context = canvas.getContext("2d");
500
845
  if (!context) return;
501
846
  context.clearRect(0, 0, WIDTH, HEIGHT);
@@ -542,8 +887,715 @@ function drawMap(canvas, map) {
542
887
  context.fillRect(x0, y0, Math.max(1, x1 - x0), Math.max(1, y1 - y0));
543
888
  context.globalAlpha = 1;
544
889
  }
890
+ for (const territory of territories) {
891
+ const cx = xPx(territory.lonDeg, WIDTH);
892
+ const cy = yPx(territory.latDeg, HEIGHT);
893
+ const radius = Math.max(2, territory.radiusKm / 111 * PX_PER_DEG);
894
+ context.beginPath();
895
+ context.arc(cx, cy, radius, 0, Math.PI * 2);
896
+ context.strokeStyle = "#ffb454";
897
+ context.globalAlpha = 0.7;
898
+ context.lineWidth = 1;
899
+ context.stroke();
900
+ context.globalAlpha = 1;
901
+ }
545
902
  }
546
- var panel = {
903
+
904
+ // src/webui/panels/surface.ts
905
+ var panel2 = {
906
+ async mount(ctx) {
907
+ const t = text(ctx.language);
908
+ const shell = createShell(ctx, { title: t.mapTitle, desc: "\u5730\u56FE\u3001\u770B\u9644\u8FD1\u3001\u8D70\u4E00\u6BB5\u3001\u7B49\u4E00\u4F1A\u3002\u8DE8\u661F\u822A\u884C\u5728\u300C\u5DE5\u4E1A\u300D\u9875\u7B7E\u3002" });
909
+ let state = null;
910
+ let bodyKey = "";
911
+ let map = null;
912
+ const empty = ctx.ui.h("div", "gx-empty");
913
+ const cardMap = ctx.ui.h("div", "gx-card");
914
+ const cardLook = ctx.ui.h("div", "gx-card");
915
+ const cardAct = ctx.ui.h("div", "gx-card");
916
+ const canvas = ctx.ui.h("canvas");
917
+ canvas.style.width = "100%";
918
+ canvas.style.imageRendering = "pixelated";
919
+ canvas.style.borderRadius = "6px";
920
+ canvas.style.display = "block";
921
+ const legend = ctx.ui.h("div", "gx-legend");
922
+ const lookPre = ctx.ui.h("pre", "gx-pre");
923
+ lookPre.style.display = "none";
924
+ const picker = ctx.ui.h("div", "gx-chips");
925
+ const msg = ctx.ui.h("div", "gx-msg");
926
+ msg.hidden = true;
927
+ const mapWrap = ctx.ui.h("div", "gx-mapwrap");
928
+ mapWrap.append(canvas);
929
+ cardMap.append(ctx.ui.h("div", "gx-card-head", t.mapTitle), picker, legend, mapWrap);
930
+ cardLook.append(ctx.ui.h("div", "gx-card-head", t.lookHere), lookPre);
931
+ cardAct.append(ctx.ui.h("div", "gx-card-head", "\u52A8\u4F5C"), msg);
932
+ shell.body.append(empty, cardMap, cardLook, cardAct);
933
+ const showMsg = (value, bad = false) => {
934
+ msg.textContent = value;
935
+ msg.className = bad ? "gx-msg gx-bad" : "gx-msg gx-ok";
936
+ msg.hidden = false;
937
+ };
938
+ const run = async (method, args = [], consumeState = false) => {
939
+ try {
940
+ const result = await ctx.invoke(method, args);
941
+ if (consumeState && result && typeof result === "object" && "power" in result) {
942
+ state = result;
943
+ render();
944
+ const inner = result.text;
945
+ if (inner) showMsg(inner);
946
+ return;
947
+ }
948
+ const payload = result;
949
+ showMsg(payload?.text ?? String(result));
950
+ } catch (e) {
951
+ showMsg(errorText(e), true);
952
+ }
953
+ };
954
+ const refreshMap = async () => {
955
+ if (!state || state.locked) {
956
+ map = null;
957
+ return;
958
+ }
959
+ try {
960
+ map = await ctx.invoke("map", [bodyKey]);
961
+ } catch (e) {
962
+ map = null;
963
+ showMsg(errorText(e), true);
964
+ }
965
+ draw();
966
+ };
967
+ const draw = () => {
968
+ if (!map) {
969
+ canvas.width = 0;
970
+ canvas.height = 0;
971
+ legend.replaceChildren();
972
+ return;
973
+ }
974
+ drawMap(canvas, map, state?.territories ?? []);
975
+ const seen = /* @__PURE__ */ new Set();
976
+ legend.replaceChildren();
977
+ for (const row2 of map.biome) {
978
+ for (const id of row2) {
979
+ if (seen.has(id)) continue;
980
+ seen.add(id);
981
+ const chip = ctx.ui.h("span", "gx-chip");
982
+ const dot = ctx.ui.h("span", "gx-dot");
983
+ dot.style.background = mapColor(id);
984
+ chip.append(dot, ctx.ui.h("span", "gx-faint", String(id)));
985
+ legend.append(chip);
986
+ }
987
+ }
988
+ };
989
+ const mapColor = (id) => {
990
+ const palette = ["#1d4ed8", "#e5edf7", "#c2a35a", "#b7a06a", "#8bbf6b", "#5f9e4f", "#2f7a3f", "#1f6b3a", "#0f5a33", "#345e6e", "#6c7a83", "#9a9aa0", "#9fd0e8", "#5ba6c9", "#4a7fb5", "#7a5fb5", "#c14b6b"];
991
+ return palette[id] ?? "#555";
992
+ };
993
+ const rebuildPicker = () => {
994
+ picker.replaceChildren();
995
+ if (!state) return;
996
+ for (const body of state.bodies) {
997
+ if (body.kind === "moon") continue;
998
+ const active = body.key === bodyKey;
999
+ const chip = ctx.ui.button(`${body.label}`, {
1000
+ size: "sm",
1001
+ variant: active ? "primary" : void 0,
1002
+ onClick: () => {
1003
+ bodyKey = body.key;
1004
+ rebuildPicker();
1005
+ void refreshMap();
1006
+ }
1007
+ });
1008
+ picker.append(chip);
1009
+ }
1010
+ };
1011
+ const render = () => {
1012
+ shell.update(state);
1013
+ if (!state || state.locked) {
1014
+ empty.textContent = "\u8FD8\u6CA1\u6709\u521B\u4E16 \u2014\u2014 \u5148\u53BB\u300C\u521B\u4E16\u300D\u9875\u7B7E\u843D\u5730\u3002";
1015
+ cardMap.hidden = true;
1016
+ cardLook.hidden = true;
1017
+ cardAct.hidden = true;
1018
+ return;
1019
+ }
1020
+ empty.textContent = "";
1021
+ cardMap.hidden = false;
1022
+ cardLook.hidden = false;
1023
+ cardAct.hidden = false;
1024
+ if (!bodyKey || !state.bodies.some((b) => b.key === bodyKey)) bodyKey = state.bodies.find((b) => b.kind !== "moon")?.key ?? "";
1025
+ rebuildPicker();
1026
+ };
1027
+ const latInput = ctx.ui.input({ value: "0" });
1028
+ const lonInput = ctx.ui.input({ value: "0" });
1029
+ const goButton = ctx.ui.button("\u8D70\u8FC7\u53BB", {
1030
+ size: "sm",
1031
+ variant: "primary",
1032
+ onClick: () => {
1033
+ void run("move", [{ latDeg: Number(latInput.value), lonDeg: Number(lonInput.value) }], true);
1034
+ }
1035
+ });
1036
+ const hereButton = ctx.ui.button("\u586B\u811A\u4E0B\u7684\u7ECF\u7EAC", {
1037
+ size: "sm",
1038
+ onClick: () => {
1039
+ if (!state?.location) return;
1040
+ latInput.value = state.location.latDeg.toFixed(1);
1041
+ lonInput.value = state.location.lonDeg.toFixed(1);
1042
+ }
1043
+ });
1044
+ const lookButton = ctx.ui.button(t.lookHere, { size: "sm", onClick: () => void run("look", []) });
1045
+ const waitButton = ctx.ui.button("\u7B49 1 \u65F6", { size: "sm", onClick: () => void run("wait", [{ until: "hours", hours: 1 }], true) });
1046
+ const noonButton = ctx.ui.button("\u7B49\u5230\u4E2D\u5348", { size: "sm", onClick: () => void run("wait", [{ until: "noon" }], true) });
1047
+ const terrainButton = ctx.ui.button("\u6D4B\u5730\u5F62", { size: "sm", onClick: () => void run("terrain", [{ latDeg: Number(latInput.value), lonDeg: Number(lonInput.value) }]) });
1048
+ const surveyButton = ctx.ui.button("\u6D4B\u7ED8\u4E00\u5708", { size: "sm", onClick: () => void run("survey", [], true) });
1049
+ const stargazeButton = ctx.ui.button("\u89C2\u661F", { size: "sm", onClick: () => void run("stargaze", []) });
1050
+ const travel = ctx.ui.h("div", "gx-row");
1051
+ travel.append(ctx.ui.h("span", "gx-k", "\u53BB\u54EA"), latInput, lonInput, goButton, hereButton);
1052
+ const quick = ctx.ui.h("div", "gx-row");
1053
+ quick.append(lookButton, waitButton, noonButton, terrainButton, surveyButton, stargazeButton);
1054
+ cardAct.append(travel, quick);
1055
+ const load = async () => {
1056
+ state = await ctx.invoke("state", []);
1057
+ render();
1058
+ await refreshMap();
1059
+ void run("look", []);
1060
+ };
1061
+ await load();
1062
+ }
1063
+ };
1064
+ var surface_default = panel2;
1065
+
1066
+ // src/webui/panels/farm.ts
1067
+ function num3(value, digits = 0) {
1068
+ return value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
1069
+ }
1070
+ var panel3 = {
1071
+ async mount(ctx) {
1072
+ const t = text(ctx.language);
1073
+ const shell = createShell(ctx, { title: "\u519C\u573A", desc: "\u7AD9\u70B9\u3001\u4F5C\u7269\u3001\u79CD\u5B50\u3001\u6E29\u5BA4\u3002\u5EFA\u7AD9\u5148\u8D70\u5230\u6709\u5730\u7684\u5730\u65B9\u3002" });
1074
+ let state = null;
1075
+ let siteKey = "";
1076
+ const empty = ctx.ui.h("div", "gx-empty");
1077
+ const msg = ctx.ui.h("div", "gx-msg");
1078
+ msg.hidden = true;
1079
+ const sitesCard = ctx.ui.h("div", "gx-card");
1080
+ const cropsCard = ctx.ui.h("div", "gx-card");
1081
+ const seedsCard = ctx.ui.h("div", "gx-card");
1082
+ const houseCard = ctx.ui.h("div", "gx-card");
1083
+ shell.body.append(empty, msg, sitesCard, cropsCard, seedsCard, houseCard);
1084
+ const showMsg = (value, bad = false) => {
1085
+ msg.textContent = value;
1086
+ msg.className = bad ? "gx-msg gx-bad" : "gx-msg gx-ok";
1087
+ msg.hidden = false;
1088
+ };
1089
+ const act = async (method, args = []) => {
1090
+ try {
1091
+ const result = await ctx.invoke(method, args);
1092
+ if (result && typeof result === "object" && "power" in result) {
1093
+ state = result;
1094
+ const inner = result.text;
1095
+ if (inner) showMsg(inner);
1096
+ render();
1097
+ return;
1098
+ }
1099
+ const payload = result;
1100
+ showMsg(payload?.text ?? String(result));
1101
+ state = await ctx.invoke("state", []);
1102
+ render();
1103
+ } catch (e) {
1104
+ showMsg(errorText(e), true);
1105
+ }
1106
+ };
1107
+ const flora = () => state?.flora ?? null;
1108
+ const head = (title, ...extra) => {
1109
+ const bar2 = ctx.ui.h("div", "gx-row");
1110
+ bar2.append(ctx.ui.h("span", "gx-card-head", title), ctx.ui.h("span", "gx-gap"), ...extra);
1111
+ return bar2;
1112
+ };
1113
+ const renderSites = () => {
1114
+ const f = flora();
1115
+ sitesCard.replaceChildren();
1116
+ if (!f) return;
1117
+ const buildSite = ctx.ui.button("\u5728\u8FD9\u513F\u5EFA\u7AD9", { size: "sm", variant: "primary", onClick: () => void act("site", []) });
1118
+ sitesCard.append(head("\u7AD9\u70B9", buildSite));
1119
+ if (f.sites.length === 0) {
1120
+ sitesCard.append(ctx.ui.h("div", "gx-empty", "\u8FD8\u6CA1\u6709\u7AD9\u70B9\uFF1A\u8D70\u5230\u4E00\u5757\u9646\u5730\u4E0A\uFF0C\u70B9\u300C\u5728\u8FD9\u513F\u5EFA\u7AD9\u300D\u3002"));
1121
+ return;
1122
+ }
1123
+ for (const site of f.sites) {
1124
+ const rowEl = ctx.ui.h("div", "gx-item");
1125
+ const active = site.key === siteKey;
1126
+ const pick = ctx.ui.button(site.key, {
1127
+ size: "sm",
1128
+ variant: active ? "primary" : void 0,
1129
+ onClick: () => {
1130
+ siteKey = site.key;
1131
+ render();
1132
+ }
1133
+ });
1134
+ const wet = site.wetness === null || site.wetness === void 0 ? "\u2014" : `${Math.round(site.wetness * 100)}%`;
1135
+ const fert = site.fertility === null || site.fertility === void 0 ? "\u2014" : `${Math.round(site.fertility * 100)}%`;
1136
+ rowEl.append(
1137
+ pick,
1138
+ ctx.ui.h("span", "gx-dim", `${site.kind === "water" ? "\u6C34\u8FB9\u6E7F\u5730" : "\u65F1\u5730"} \xB7 \u6E7F ${wet} \xB7 \u80A5 ${fert} \xB7 ${site.plants} \u682A/\u7FA4${site.ripe > 0 ? ` \xB7 ${site.ripe} \u719F` : ""}`)
1139
+ );
1140
+ sitesCard.append(rowEl);
1141
+ }
1142
+ };
1143
+ const renderCrops = () => {
1144
+ const f = flora();
1145
+ cropsCard.replaceChildren();
1146
+ if (!f) return;
1147
+ cropsCard.append(head("\u4F5C\u7269"));
1148
+ const crops = f.crops ?? [];
1149
+ if (crops.length === 0) {
1150
+ cropsCard.append(ctx.ui.h("div", "gx-empty", "\u8FD8\u6CA1\u6709\u4F5C\u7269\uFF1A\u5728\u79CD\u5B50\u533A\u9009\u4E00\u888B\uFF0C\u79CD\u5230\u7AD9\u70B9\u6216\u79CD\u690D\u76C6\u91CC\u3002"));
1151
+ return;
1152
+ }
1153
+ for (const crop of crops.slice(0, 40)) {
1154
+ const rowEl = ctx.ui.h("div", "gx-item");
1155
+ const label = `${crop.name} ${crop.id} \xB7 ${crop.site}`;
1156
+ rowEl.append(ctx.ui.h("span", crop.dead ? "gx-bad" : "gx-num", label), ctx.ui.h("span", "gx-dim", `${crop.stage} ${Math.round(crop.progress * 100)}%`));
1157
+ const buttons = [];
1158
+ if (crop.ripe) buttons.push(ctx.ui.button("\u6536", { size: "sm", onClick: () => void act("harvest", [crop.site, crop.id]) }));
1159
+ buttons.push(ctx.ui.button("\u8BE6\u60C5", { size: "sm", onClick: () => void act("inspect", [crop.id, crop.site]) }));
1160
+ if (!crop.dead) {
1161
+ buttons.push(ctx.ui.button("\u7559\u79CD", { size: "sm", onClick: () => void act("breed", [crop.id, crop.site, "self"]) }));
1162
+ buttons.push(ctx.ui.button("\u79FB\u683D", { size: "sm", onClick: () => void act("transplant", [crop.id, crop.site]) }));
1163
+ }
1164
+ if (crop.dead || crop.health < 20) {
1165
+ buttons.push(ctx.ui.button("\u62D4\u6389", { size: "sm", onClick: () => void act("remove", [crop.id, crop.site]) }));
1166
+ }
1167
+ rowEl.append(...buttons);
1168
+ cropsCard.append(rowEl);
1169
+ }
1170
+ };
1171
+ const renderSeeds = () => {
1172
+ const f = flora();
1173
+ seedsCard.replaceChildren();
1174
+ if (!f) return;
1175
+ const planterSelect = ctx.ui.select({
1176
+ options: [
1177
+ { value: "", label: "\u79CD\u5230\uFF1A\u9009\u4E2D\u7684\u7AD9\u70B9" },
1178
+ ...(f.planters ?? []).map((p) => ({ value: p.key, label: `${p.key}\uFF08${p.plants}/3\uFF09` }))
1179
+ ]
1180
+ });
1181
+ seedsCard.append(head("\u79CD\u5B50", planterSelect));
1182
+ if (f.bags.length === 0) {
1183
+ seedsCard.append(ctx.ui.h("div", "gx-empty", "\u6CA1\u6709\u79CD\u5B50\uFF1A\u5546\u5E97\u4E70\u3001\u7559\u79CD\u3001\u6216\u8005\u79FB\u683D\u56DE\u6765\u3002"));
1184
+ }
1185
+ for (const bag of f.bags) {
1186
+ const rowEl = ctx.ui.h("div", "gx-item");
1187
+ rowEl.append(ctx.ui.h("span", "gx-num", `${bag.premium ? "\u9AD8\u7EA7" : "\u968F\u673A"} \xB7 ${bag.name} \xD7${bag.count}`));
1188
+ rowEl.append(
1189
+ ctx.ui.button("\u79CD\u4E0B", {
1190
+ size: "sm",
1191
+ onClick: () => {
1192
+ const target = planterSelect.value !== "" ? planterSelect.value : siteKey;
1193
+ if (!target) {
1194
+ showMsg("\u5148\u9009\u4E00\u4E2A\u7AD9\u70B9\uFF08\u6216\u8005\u4E00\u53EA\u79CD\u690D\u76C6\uFF09\u3002", true);
1195
+ return;
1196
+ }
1197
+ void act("plant", [bag.id, target]);
1198
+ }
1199
+ })
1200
+ );
1201
+ seedsCard.append(rowEl);
1202
+ }
1203
+ const inv = (f.inventory ?? []).filter((item) => item.amount > 0);
1204
+ if (inv.length > 0) {
1205
+ seedsCard.append(ctx.ui.h("div", "gx-faint", `\u80CC\u5305\uFF1A${inv.map((item) => `${item.name} ${num3(item.amount, item.amount < 10 ? 1 : 0)}`).join(" \xB7 ")}`));
1206
+ }
1207
+ const fert = (f.inventory ?? []).find((item) => item.id === "fertilizer");
1208
+ if (fert && fert.amount > 0) {
1209
+ seedsCard.append(
1210
+ ctx.ui.button("\u7ED9\u9009\u4E2D\u7AD9\u70B9\u6492 1 kg \u590D\u5408\u80A5", {
1211
+ size: "sm",
1212
+ onClick: () => void act("fertilize", [1, siteKey])
1213
+ })
1214
+ );
1215
+ }
1216
+ };
1217
+ const renderHouse = () => {
1218
+ const f = flora();
1219
+ houseCard.replaceChildren();
1220
+ if (!f) return;
1221
+ houseCard.append(head("\u6E29\u5BA4\u4E0E\u79CD\u690D\u76C6"));
1222
+ const list = ctx.ui.h("div", "gx-list");
1223
+ const greenhouses = state?.greenhouses ?? [];
1224
+ if (greenhouses.length === 0) list.append(ctx.ui.h("div", "gx-empty", "\u8FD8\u6CA1\u6709\u6E29\u5BA4\uFF1A\u6E29\u5BA4\u6309\u7AD9\u70B9\u751F\u6548\uFF0C\u6574\u7AD9\u4F5C\u7269\u90FD\u7B97\u3002"));
1225
+ for (const gh of greenhouses) {
1226
+ const rowEl = ctx.ui.h("div", "gx-item");
1227
+ const inside = gh.interiorC === null ? "\u65AD\u7535" : `${gh.interiorC}\u2103`;
1228
+ rowEl.append(ctx.ui.h("span", "gx-num", `${gh.siteKey} \xB7 \u81EA\u52A8 \xB7 \u5BA4\u5185 ${inside}\uFF08\u5BA4\u5916 ${gh.ambientC ?? "\u2014"}\u2103\uFF09`));
1229
+ const slider = ctx.ui.h("input");
1230
+ slider.type = "range";
1231
+ slider.value = gh.targetC === null ? "0" : String(gh.targetC);
1232
+ slider.min = "-60";
1233
+ slider.max = "80";
1234
+ slider.step = "1";
1235
+ slider.onchange = () => {
1236
+ const value = Number(slider.value);
1237
+ void act("install", [{ id: "greenhouse", site: gh.siteKey, tempC: value === 0 ? "auto" : value }]);
1238
+ };
1239
+ rowEl.append(slider);
1240
+ list.append(rowEl);
1241
+ }
1242
+ for (const planter of f.planters ?? []) {
1243
+ const rowEl = ctx.ui.h("div", "gx-item");
1244
+ rowEl.append(ctx.ui.h("span", "gx-num", `${planter.key} \xB7 ${planter.plants}/3${planter.ripe > 0 ? ` \xB7 ${planter.ripe} \u719F` : ""}`));
1245
+ rowEl.append(ctx.ui.h("span", "gx-dim", planter.powered ? `\u901A\u7535 \xB7 \u5BA4\u5916 ${planter.ambientC ?? "\u2014"}\u2103` : "\u65AD\u7535\uFF08\u8DDF\u5BA4\u5916\uFF09"));
1246
+ list.append(rowEl);
1247
+ }
1248
+ houseCard.append(list);
1249
+ const build = ctx.ui.h("div", "gx-row");
1250
+ for (const [kind, label] of [
1251
+ ["greenhouse", "\u5EFA\u6E29\u5BA4\u6838\u5FC3"],
1252
+ ["planter", "\u5EFA\u79CD\u690D\u76C6"],
1253
+ ["fence", "\u5EFA\u56F4\u680F"],
1254
+ ["scarecrow", "\u5EFA\u7A3B\u8349\u4EBA"],
1255
+ ["feed_trough", "\u5EFA\u5582\u98DF\u69FD"]
1256
+ ]) {
1257
+ build.append(ctx.ui.button(label, { size: "sm", onClick: () => void act("install", [{ id: kind, site: siteKey }]) }));
1258
+ }
1259
+ houseCard.append(build);
1260
+ };
1261
+ const render = () => {
1262
+ shell.update(state);
1263
+ if (!state || state.locked) {
1264
+ empty.textContent = "\u8FD8\u6CA1\u6709\u521B\u4E16 \u2014\u2014 \u5148\u53BB\u300C\u521B\u4E16\u300D\u9875\u7B7E\u843D\u5730\u3002";
1265
+ for (const card2 of [sitesCard, cropsCard, seedsCard, houseCard]) card2.hidden = true;
1266
+ return;
1267
+ }
1268
+ empty.textContent = "";
1269
+ for (const card2 of [sitesCard, cropsCard, seedsCard, houseCard]) card2.hidden = false;
1270
+ if (!siteKey || !(state.flora?.sites ?? []).some((site) => site.key === siteKey)) {
1271
+ siteKey = state.flora?.sites[0]?.key ?? "";
1272
+ }
1273
+ renderSites();
1274
+ renderCrops();
1275
+ renderSeeds();
1276
+ renderHouse();
1277
+ };
1278
+ state = await ctx.invoke("state", []);
1279
+ render();
1280
+ }
1281
+ };
1282
+ var farm_default = panel3;
1283
+
1284
+ // src/webui/panels/industry.ts
1285
+ function num4(value, digits = 0) {
1286
+ return value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
1287
+ }
1288
+ var KINDS = [
1289
+ ["greenhouse", "\u6E29\u5BA4\u6838\u5FC3"],
1290
+ ["planter", "\u79CD\u690D\u76C6"],
1291
+ ["warehouse", "\u4ED3\u5E93"],
1292
+ ["cold_store", "\u51B7\u5E93"],
1293
+ ["inert_room", "\u60F0\u6027\u6C14\u4F53\u5BA4"],
1294
+ ["habitat", "\u5C45\u6240"],
1295
+ ["duty", "\u503C\u73ED\u7EC8\u7AEF"],
1296
+ ["storage_terminal", "\u4ED3\u50A8\u7EC8\u7AEF"],
1297
+ ["terminal", "\u4EA4\u6613\u7EC8\u7AEF"],
1298
+ ["arm", "\u673A\u68B0\u81C2"],
1299
+ ["drone_cluster", "\u65E0\u4EBA\u673A\u96C6\u7FA4"],
1300
+ ["miner", "\u91C7\u77FF\u673A"],
1301
+ ["rectifier", "\u6574\u6D41\u7535\u5854"],
1302
+ ["feed_trough", "\u5582\u98DF\u69FD"],
1303
+ ["fence", "\u56F4\u680F"],
1304
+ ["scarecrow", "\u7A3B\u8349\u4EBA"],
1305
+ ["rocket", "\u706B\u7BAD"],
1306
+ ["carrier", "\u7A7A\u5929\u6BCD\u8230"],
1307
+ ["tourism_dock", "\u89C2\u5149\u5854\u53F0\uFF08\u65C5\u6E38\uFF09"],
1308
+ ["visitor_lodge", "\u8BBF\u5BA2\u9A7F\u7AD9\uFF08\u65C5\u6E38\uFF09"],
1309
+ ["tour_line", "\u89C2\u5149\u7EBF\u8DEF\u7AD9\uFF08\u65C5\u6E38\uFF09"],
1310
+ ["souvenir", "\u7EAA\u5FF5\u54C1\u5E97\uFF08\u65C5\u6E38\uFF09"],
1311
+ ["recruit_office", "\u62DB\u52DF\u7AD9\uFF08\u79D1\u6280\uFF09"],
1312
+ ["staff_housing", "\u5458\u5DE5\u516C\u5BD3\uFF08\u79D1\u6280\uFF09"],
1313
+ ["fab", "\u6676\u5706\u5382\uFF08\u79D1\u6280\uFF09"],
1314
+ ["compute_array", "\u8BA1\u7B97\u9635\u5217\uFF08\u79D1\u6280\uFF09"],
1315
+ ["heavy_water", "\u91CD\u6C34\u63D0\u53D6\u5668\uFF08\u79D1\u6280\uFF09"],
1316
+ ["enrichment", "\u5BCC\u96C6\u5854\uFF08\u79D1\u6280\uFF09"]
1317
+ ];
1318
+ var WONDERS = [
1319
+ ["sky_ring", "\u5929\u7A79\u73AF"],
1320
+ ["under_ice_eye", "\u51B0\u4E0B\u4E4B\u773C"],
1321
+ ["silicon_valley", "\u7845\u8C37"],
1322
+ ["orbital_mirror", "\u8F68\u9053\u955C\u9635"],
1323
+ ["s2_engine", "\u62DF\u9020S2\u673A\u5173"]
1324
+ ];
1325
+ var panel4 = {
1326
+ async mount(ctx) {
1327
+ const t = text(ctx.language);
1328
+ const shell = createShell(ctx, { title: "\u5DE5\u4E1A", desc: "\u7535\u3001\u5EFA\u7B51\u3001\u5EFA\u9020\u3001\u822A\u884C\u3002\u624B\u6447\u51FA\u6765\u7684\u7535\u5148\u5B58\u8FDB\u7535\u6C60\u3002" });
1329
+ let state = null;
1330
+ const empty = ctx.ui.h("div", "gx-empty");
1331
+ const msg = ctx.ui.h("div", "gx-msg");
1332
+ msg.hidden = true;
1333
+ const powerCard = ctx.ui.h("div", "gx-card");
1334
+ const buildCard = ctx.ui.h("div", "gx-card");
1335
+ const listCard = ctx.ui.h("div", "gx-card");
1336
+ const travelCard = ctx.ui.h("div", "gx-card");
1337
+ const wonderCard = ctx.ui.h("div", "gx-card");
1338
+ shell.body.append(empty, msg, powerCard, buildCard, listCard, travelCard, wonderCard);
1339
+ const showMsg = (value, bad = false) => {
1340
+ msg.textContent = value;
1341
+ msg.className = bad ? "gx-msg gx-bad" : "gx-msg gx-ok";
1342
+ msg.hidden = false;
1343
+ };
1344
+ const act = async (method, args = []) => {
1345
+ try {
1346
+ const result = await ctx.invoke(method, args);
1347
+ if (result && typeof result === "object" && "power" in result) {
1348
+ state = result;
1349
+ const inner = result.text;
1350
+ if (inner) showMsg(inner);
1351
+ } else {
1352
+ const payload = result;
1353
+ showMsg(payload?.text ?? String(result));
1354
+ state = await ctx.invoke("state", []);
1355
+ }
1356
+ } catch (e) {
1357
+ showMsg(errorText(e), true);
1358
+ }
1359
+ render();
1360
+ };
1361
+ const head = (title, ...extra) => {
1362
+ const bar2 = ctx.ui.h("div", "gx-row");
1363
+ bar2.append(ctx.ui.h("span", "gx-card-head", title), ctx.ui.h("span", "gx-gap"), ...extra);
1364
+ return bar2;
1365
+ };
1366
+ const renderPower = () => {
1367
+ powerCard.replaceChildren();
1368
+ const power = state?.power;
1369
+ if (!power) return;
1370
+ const ratio = power.capacityKj > 0 ? power.energyKj / power.capacityKj : 0;
1371
+ const press = ctx.ui.button("\u624B\u6447\u4E00\u6B21", { size: "sm", variant: "primary", onClick: () => void act("press", []) });
1372
+ const sail = ctx.ui.button("\u5EFA\u592A\u9633\u80FD\u5E06", { size: "sm", onClick: () => void act("install", [{ id: "sail" }]) });
1373
+ const monitor = ctx.ui.button("\u88C5\u73AF\u5883\u76D1\u6D4B\u5668", { size: "sm", onClick: () => void act("monitor", []) });
1374
+ powerCard.append(head("\u80FD\u91CF\u4E0E\u8BBE\u5907", press, sail, monitor));
1375
+ powerCard.append(
1376
+ ctx.ui.h("div", "gx-row", `\u26A1 ${num4(power.energyKj)} / ${num4(power.capacityKj)} kJ\uFF08${Math.round(ratio * 100)}%\uFF09`),
1377
+ ctx.ui.h("div", "gx-row", `\u94A8 ${num4(power.tungsten)} kg \xB7 \u592A\u9633\u80FD\u5E06 ${power.sails} \u53F0`)
1378
+ );
1379
+ if (power.grid) {
1380
+ powerCard.append(
1381
+ ctx.ui.h("div", "gx-row", `\u7535\u7F51 ${num4(power.grid.storedKj)} / ${num4(power.grid.capacityKj)} kJ \xB7 ${power.grid.hasTower ? power.grid.reachable ? "\u5728\u7535\u5854\u65C1\uFF08\u53EF\u642C\u7535\uFF09" : "\u7535\u5854\u5728\u522B\u5904" : "\u6CA1\u6709\u7535\u5854"}`)
1382
+ );
1383
+ }
1384
+ };
1385
+ const renderBuild = () => {
1386
+ const select = ctx.ui.select({ options: KINDS.map(([value, label]) => ({ value, label })) });
1387
+ const button = ctx.ui.button("\u5EFA\u5728\u811A\u4E0B", {
1388
+ size: "sm",
1389
+ variant: "primary",
1390
+ onClick: () => void act("install", [{ id: select.value }])
1391
+ });
1392
+ buildCard.replaceChildren(head("\u5EFA\u9020", select, button));
1393
+ if (state?.builds.length) {
1394
+ buildCard.append(
1395
+ ctx.ui.h("div", "gx-faint", `\u65BD\u5DE5\u4E2D\uFF1A${state.builds.map((b) => `${b.label}\uFF08\u8FD8\u5269 ${num4(b.leftHomeHours, 1)} \u65F6\uFF09`).join(" \xB7 ")}`)
1396
+ );
1397
+ } else {
1398
+ buildCard.append(ctx.ui.h("div", "gx-faint", `\u65BD\u5DE5\u961F\u5217 ${state?.builds.length ?? 0} / ${state?.buildSlots ?? 1}`));
1399
+ }
1400
+ };
1401
+ const renderList = () => {
1402
+ listCard.replaceChildren(head("\u5DF2\u5EFA\u5EFA\u7B51"));
1403
+ const list = ctx.ui.h("div", "gx-list");
1404
+ for (const item of state?.structures ?? []) {
1405
+ const rowEl = ctx.ui.h("div", "gx-item");
1406
+ rowEl.append(ctx.ui.h("span", "gx-num", `${item.label} \xB7 ${item.siteKey}`));
1407
+ if (item.capKg > 0) rowEl.append(ctx.ui.h("span", "gx-dim", `${num4(item.usedKg, 1)} / ${num4(item.capKg)} kg`));
1408
+ if (item.interiorC !== void 0) rowEl.append(ctx.ui.h("span", "gx-dim", `\u5BA4\u5185 ${item.interiorC}\u2103`));
1409
+ if (item.armText) rowEl.append(ctx.ui.h("span", "gx-dim", item.armText));
1410
+ if (item.dutyText) rowEl.append(ctx.ui.h("span", "gx-dim", item.dutyText));
1411
+ rowEl.append(
1412
+ ctx.ui.button("\u8D70\u8FC7\u53BB", { size: "sm", onClick: () => void act("move", [{ latDeg: item.latDeg, lonDeg: item.lonDeg }]) })
1413
+ );
1414
+ list.append(rowEl);
1415
+ }
1416
+ if ((state?.structures ?? []).length === 0) list.append(ctx.ui.h("div", "gx-empty", "\u8FD8\u6CA1\u6709\u5EFA\u7B51\u3002"));
1417
+ listCard.append(list);
1418
+ };
1419
+ const renderTravel = () => {
1420
+ travelCard.replaceChildren(head("\u8DE8\u661F\u822A\u884C"));
1421
+ const list = ctx.ui.h("div", "gx-chips");
1422
+ for (const body of state?.bodies ?? []) {
1423
+ if (body.kind === "moon") continue;
1424
+ list.append(
1425
+ ctx.ui.button(body.label, {
1426
+ size: "sm",
1427
+ onClick: () => void act("move", [{ kind: "interstellar", target: body.key }])
1428
+ })
1429
+ );
1430
+ }
1431
+ travelCard.append(list, ctx.ui.h("div", "gx-faint", "\u8981\u5148\u628A\u3010\u673A\u52A8\u6838\u5FC3\u3011\u4FEE\u597D\u3001\u5E76\u4E14\u770B\u5F97\u89C1\uFF08\u89C2\u661F\uFF09\u6216\u8005\u624B\u91CC\u6709\u661F\u56FE\u3002"));
1432
+ };
1433
+ const renderWonders = () => {
1434
+ wonderCard.replaceChildren(head("\u5947\u89C2"));
1435
+ const charter = state?.power?.charter;
1436
+ if (!charter || charter.charter === null) {
1437
+ wonderCard.append(ctx.ui.h("div", "gx-faint", "\u8FD8\u6CA1\u4E70\u6267\u7167\uFF1A\u53BB\u300C\u5546\u5E97\u300D\u4E70\u4E00\u5F20\u661F\u9645\u5E7F\u64AD\u3002"));
1438
+ return;
1439
+ }
1440
+ if (charter.wonder) {
1441
+ wonderCard.append(ctx.ui.h("div", "gx-row", `${charter.wonder.label} \xB7 ${Math.round(charter.wonder.progress * 100)}%\uFF08\u65AD\u7535\u4F1A\u70C2\u5C3E\uFF09`));
1442
+ } else {
1443
+ const chips = ctx.ui.h("div", "gx-chips");
1444
+ for (const [id, label] of WONDERS) {
1445
+ chips.append(ctx.ui.button(`\u9020${label}`, { size: "sm", onClick: () => void act("wonder", [{ id }]) }));
1446
+ }
1447
+ wonderCard.append(chips);
1448
+ }
1449
+ if (charter.wonders.length > 0) wonderCard.append(ctx.ui.h("div", "gx-faint", `\u5DF2\u843D\u6210\uFF1A${charter.wonders.join(" \xB7 ")}`));
1450
+ };
1451
+ const render = () => {
1452
+ shell.update(state);
1453
+ if (!state || state.locked) {
1454
+ empty.textContent = "\u8FD8\u6CA1\u6709\u521B\u4E16 \u2014\u2014 \u5148\u53BB\u300C\u521B\u4E16\u300D\u9875\u7B7E\u843D\u5730\u3002";
1455
+ for (const card2 of [powerCard, buildCard, listCard, travelCard, wonderCard]) card2.hidden = true;
1456
+ return;
1457
+ }
1458
+ empty.textContent = "";
1459
+ for (const card2 of [powerCard, buildCard, listCard, travelCard, wonderCard]) card2.hidden = false;
1460
+ renderPower();
1461
+ renderBuild();
1462
+ renderList();
1463
+ renderTravel();
1464
+ renderWonders();
1465
+ };
1466
+ state = await ctx.invoke("state", []);
1467
+ render();
1468
+ }
1469
+ };
1470
+ var industry_default = panel4;
1471
+
1472
+ // src/webui/panels/life.ts
1473
+ function num5(value, digits = 0) {
1474
+ return value.toLocaleString("en-US", { minimumFractionDigits: digits, maximumFractionDigits: digits });
1475
+ }
1476
+ var panel5 = {
1477
+ async mount(ctx) {
1478
+ const t = text(ctx.language);
1479
+ const shell = createShell(ctx, { title: "\u751F\u547D\u4E0E\u4EBA\u4E8B", desc: "\u4EBA\u53E3\u3001\u5C45\u6240\u3001\u4EBA\u624B\u91CC\u5728\u5E72\u4EC0\u4E48\u3002\u53EB\u9192\u4E4B\u540E\u4ED6\u4EEC\u8981\u5403\u8981\u559D\u3002" });
1480
+ let state = null;
1481
+ const empty = ctx.ui.h("div", "gx-empty");
1482
+ const msg = ctx.ui.h("div", "gx-msg");
1483
+ msg.hidden = true;
1484
+ const peopleCard = ctx.ui.h("div", "gx-card");
1485
+ const houseCard = ctx.ui.h("div", "gx-card");
1486
+ const protocolCard = ctx.ui.h("div", "gx-card");
1487
+ shell.body.append(empty, msg, peopleCard, houseCard, protocolCard);
1488
+ const showMsg = (value, bad = false) => {
1489
+ msg.textContent = value;
1490
+ msg.className = bad ? "gx-msg gx-bad" : "gx-msg gx-ok";
1491
+ msg.hidden = false;
1492
+ };
1493
+ const act = async (method, args = []) => {
1494
+ try {
1495
+ const result = await ctx.invoke(method, args);
1496
+ if (result && typeof result === "object" && "power" in result) {
1497
+ state = result;
1498
+ const inner = result.text;
1499
+ if (inner) showMsg(inner);
1500
+ } else {
1501
+ const payload = result;
1502
+ showMsg(payload?.text ?? String(result));
1503
+ state = await ctx.invoke("state", []);
1504
+ }
1505
+ } catch (e) {
1506
+ showMsg(errorText(e), true);
1507
+ }
1508
+ render();
1509
+ };
1510
+ const head = (title, ...extra) => {
1511
+ const bar2 = ctx.ui.h("div", "gx-row");
1512
+ bar2.append(ctx.ui.h("span", "gx-card-head", title), ctx.ui.h("span", "gx-gap"), ...extra);
1513
+ return bar2;
1514
+ };
1515
+ const renderPeople = () => {
1516
+ peopleCard.replaceChildren();
1517
+ if (!state) return;
1518
+ const awake = state.habitats.reduce((sum, h) => sum + h.awake, 0);
1519
+ const capacity = state.habitats.length * 20;
1520
+ const sleepers = state.power?.ship?.sleepers ?? 0;
1521
+ const labor = Math.floor(awake / 5);
1522
+ const wake = ctx.ui.button("\u53EB\u9192\u4E00\u6279", {
1523
+ size: "sm",
1524
+ variant: "primary",
1525
+ onClick: () => void act("wake", [])
1526
+ });
1527
+ peopleCard.append(head("\u4EBA\u53E3", wake));
1528
+ peopleCard.append(
1529
+ ctx.ui.h("div", "gx-row", `\u5E38\u4F4F ${num5(awake)} / ${num5(capacity)} \xB7 \u4F11\u7720\u8231 ${num5(sleepers)} \u4EBA \xB7 \u4EBA\u624B ${num5(labor)} \u4EFD\uFF08\u6BCF 5 \u4EBA\u4E00\u4EFD\uFF09`)
1530
+ );
1531
+ const ship = state.power?.ship;
1532
+ if (ship && ship.sleepers > 0) {
1533
+ const hours = ship.hoursLeft === null ? "\u2014" : `${num5(ship.hoursLeft)} \u6BCD\u661F\u65F6`;
1534
+ peopleCard.append(ctx.ui.h("div", "gx-faint", `\u8231\u91CC\uFF1A\u7CAE ${num5(ship.food, 1)} kg \xB7 \u6C34 ${num5(ship.water)} L \xB7 \u6C27 ${num5(ship.oxygen, 1)} kg \xB7 \u8FD8\u80FD\u6491 ${hours}`));
1535
+ peopleCard.append(ctx.ui.h("div", "gx-faint", "\u8231\u7A7A\u4E86\u4E0D\u4F1A\u81EA\u52A8\u53BB\u4ED3\u5E93\u62FF\u8D27\uFF1A\u8865\u8231\u7528\u4ED3\u5E93\u7684 deposit\uFF0Cbuilding \u586B\u300Cpod\u300D\u3002"));
1536
+ }
1537
+ if (awake > 0) {
1538
+ peopleCard.append(ctx.ui.h("div", "gx-faint", "\u4EBA\u624B\u8981\u300C\u503C\u73ED\u7EC8\u7AEF\u300D\u624D\u4F1A\u5E72\u6D3B\uFF1A\u5EFA\u7EC8\u7AEF\u3001\u7ED1\u5C45\u6240\u4E0E\u4ED3\u5E93\uFF0C\u7136\u540E\u6BCF\u5929\u81EA\u52A8\u6536\u79CD\u65BD\u80A5\u3002"));
1539
+ }
1540
+ };
1541
+ const renderHouses = () => {
1542
+ houseCard.replaceChildren(head("\u5C45\u6240"));
1543
+ const list = ctx.ui.h("div", "gx-list");
1544
+ if ((state?.habitats ?? []).length === 0) list.append(ctx.ui.h("div", "gx-empty", "\u8FD8\u6CA1\u6709\u5C45\u6240\uFF1A\u5148\u5EFA\u4E00\u5EA7\uFF08\u4EBA\u53EA\u63A5\u53D7 5\u201332\u2103 \u7684\u5BA4\u5185\uFF09\u3002"));
1545
+ for (const habitat of state?.habitats ?? []) {
1546
+ const rowEl = ctx.ui.h("div", "gx-item");
1547
+ rowEl.append(ctx.ui.h("span", "gx-num", `${habitat.nickname} \xB7 ${habitat.awake}/${habitat.awake + habitat.dormant} \u4EBA`));
1548
+ rowEl.append(
1549
+ ctx.ui.h("span", "gx-dim", `\u7CAE ${num5(habitat.food, 1)} \xB7 \u6C34 ${num5(habitat.water)} \xB7 \u6C27 ${num5(habitat.oxygen, 1)} \xB7 \u8FD8\u80FD\u6491 ${num5(habitat.hoursLeft)} \u65F6`)
1550
+ );
1551
+ const structure = (state?.structures ?? []).find((item) => item.siteKey && item.kind === "habitat" && item.interiorC !== void 0);
1552
+ if (structure?.interiorC !== void 0) {
1553
+ const tone = structure.comfort === "ok" ? "gx-ok" : "gx-warn";
1554
+ rowEl.append(ctx.ui.h("span", tone, `\u5BA4\u5185 ${structure.interiorC}\u2103`));
1555
+ }
1556
+ list.append(rowEl);
1557
+ }
1558
+ houseCard.append(list);
1559
+ };
1560
+ const renderProtocol = () => {
1561
+ protocolCard.replaceChildren(head("\u534F\u8BAE\u8FDB\u5EA6"));
1562
+ const protocol = state?.protocol;
1563
+ if (!protocol) {
1564
+ protocolCard.append(ctx.ui.h("div", "gx-faint", "\u534F\u8BAE\u6E05\u5355\u5728\u300C\u534F\u8BAE\u300D\u9875\u7B7E\u3002"));
1565
+ return;
1566
+ }
1567
+ protocolCard.append(ctx.ui.h("div", "gx-row", `${protocol.done} / ${protocol.total} \u6761 \xB7 ${protocol.awakened ? "\u5DF2\u7ECF\u53EB\u9192" : protocol.complete ? "\u53EF\u4EE5\u53EB\u9192\u4E86" : "\u8FD8\u5DEE\u51E0\u6761"}`));
1568
+ const undone = protocol.tasks.filter((task) => !task.done).slice(0, 4);
1569
+ const list = ctx.ui.h("div", "gx-list");
1570
+ for (const task of undone) {
1571
+ const rowEl = ctx.ui.h("div", "gx-item");
1572
+ rowEl.append(ctx.ui.h("span", "gx-warn", "\u25CF"), ctx.ui.h("span", "gx-num", task.title), ctx.ui.h("span", "gx-faint", task.progress));
1573
+ list.append(rowEl);
1574
+ }
1575
+ if (undone.length === 0) list.append(ctx.ui.h("div", "gx-ok", "\u6E05\u5355\u5DF2\u7ECF\u5168\u7EFF\u3002"));
1576
+ protocolCard.append(list);
1577
+ };
1578
+ const render = () => {
1579
+ shell.update(state);
1580
+ if (!state || state.locked) {
1581
+ empty.textContent = "\u8FD8\u6CA1\u6709\u521B\u4E16 \u2014\u2014 \u5148\u53BB\u300C\u521B\u4E16\u300D\u9875\u7B7E\u843D\u5730\u3002";
1582
+ for (const card2 of [peopleCard, houseCard, protocolCard]) card2.hidden = true;
1583
+ return;
1584
+ }
1585
+ empty.textContent = "";
1586
+ for (const card2 of [peopleCard, houseCard, protocolCard]) card2.hidden = false;
1587
+ renderPeople();
1588
+ renderHouses();
1589
+ renderProtocol();
1590
+ };
1591
+ state = await ctx.invoke("state", []);
1592
+ render();
1593
+ }
1594
+ };
1595
+ var life_default = panel5;
1596
+
1597
+ // src/webui/panels/system.ts
1598
+ var panel6 = {
547
1599
  async mount(ctx) {
548
1600
  const t = text(ctx.language);
549
1601
  const sheet = ctx.ui.sheet({ title: t.title, desc: t.desc });
@@ -851,6 +1903,9 @@ var panel = {
851
1903
  { value: "cold_store", label: "\u51B7\u5E93" },
852
1904
  { value: "inert_room", label: "\u60F0\u6027\u6C14\u4F53\u5BA4" },
853
1905
  { value: "planter", label: "\u79CD\u690D\u76C6" },
1906
+ { value: "feed_trough", label: "\u5582\u98DF\u69FD\uFF08\u52A8\u7269\u4F18\u5148\u5403\u8FD9\u91CC\uFF09" },
1907
+ { value: "fence", label: "\u56F4\u680F\uFF08\u62A4\u4F4F 1.5 km \u4F5C\u7269\uFF09" },
1908
+ { value: "scarecrow", label: "\u7A3B\u8349\u4EBA\uFF08\u4FBF\u5B9C\u7684\u62A4\u5730\uFF09" },
854
1909
  { value: "carrier", label: "\u7A7A\u5929\u6BCD\u8230" },
855
1910
  { value: "wind", label: "\u98CE\u529B\u53D1\u7535\u7AD9" },
856
1911
  { value: "fire", label: "\u706B\u529B\u53D1\u7535\u7AD9" },
@@ -1137,11 +2192,11 @@ ${t.wondersDone(charter.wonders.length)}`;
1137
2192
  floraSites.append(ctx.ui.h("div", "muted", t.floraNone));
1138
2193
  }
1139
2194
  for (const site of flora.sites) {
1140
- const row = ctx.ui.h("div");
1141
- row.style.display = "flex";
1142
- row.style.gap = "8px";
1143
- row.style.alignItems = "center";
1144
- row.append(
2195
+ const row2 = ctx.ui.h("div");
2196
+ row2.style.display = "flex";
2197
+ row2.style.gap = "8px";
2198
+ row2.style.alignItems = "center";
2199
+ row2.append(
1145
2200
  ctx.ui.h(
1146
2201
  "span",
1147
2202
  "mono",
@@ -1149,49 +2204,49 @@ ${t.wondersDone(charter.wonders.length)}`;
1149
2204
  )
1150
2205
  );
1151
2206
  if (site.ripe > 0) {
1152
- row.append(
2207
+ row2.append(
1153
2208
  ctx.ui.button(`${t.floraHarvest} ${site.ripe}`, { size: "sm", variant: "primary", onClick: () => void floraDo("harvest", [site.key]) })
1154
2209
  );
1155
2210
  }
1156
- floraSites.append(row);
2211
+ floraSites.append(row2);
1157
2212
  }
1158
2213
  for (const planter of flora.planters ?? []) {
1159
- const row = ctx.ui.h("div");
1160
- row.style.display = "flex";
1161
- row.style.gap = "8px";
1162
- row.style.alignItems = "center";
2214
+ const row2 = ctx.ui.h("div");
2215
+ row2.style.display = "flex";
2216
+ row2.style.gap = "8px";
2217
+ row2.style.alignItems = "center";
1163
2218
  const stateLine = planter.powered ? t.planterOk : t.planterOff;
1164
- row.append(ctx.ui.h("span", "mono", `${planter.key} \xB7 ${t.planterName} \xB7 ${planter.plants}/3 \xB7 ${stateLine}`));
2219
+ row2.append(ctx.ui.h("span", "mono", `${planter.key} \xB7 ${t.planterName} \xB7 ${planter.plants}/3 \xB7 ${stateLine}`));
1165
2220
  if (planter.ripe > 0) {
1166
- row.append(
2221
+ row2.append(
1167
2222
  ctx.ui.button(`${t.floraHarvest} ${planter.ripe}`, { size: "sm", variant: "primary", onClick: () => void floraDo("harvest", [planter.key]) })
1168
2223
  );
1169
2224
  }
1170
2225
  const bag = flora.bags[0];
1171
2226
  if (bag) {
1172
- row.append(
2227
+ row2.append(
1173
2228
  ctx.ui.button(`${t.floraPlant} ${bag.name}`, { size: "sm", onClick: () => void floraDo("plant", [bag.id, planter.key]) })
1174
2229
  );
1175
2230
  }
1176
- floraSites.append(row);
2231
+ floraSites.append(row2);
1177
2232
  }
1178
2233
  for (const crop of flora.crops ?? []) {
1179
- const row = ctx.ui.h("div");
1180
- row.style.display = "flex";
1181
- row.style.gap = "8px";
1182
- row.style.alignItems = "center";
1183
- row.append(
2234
+ const row2 = ctx.ui.h("div");
2235
+ row2.style.display = "flex";
2236
+ row2.style.gap = "8px";
2237
+ row2.style.alignItems = "center";
2238
+ row2.append(
1184
2239
  ctx.ui.h("span", "mono", `${crop.site} \xB7 ${crop.name} \xB7 ${Math.round(crop.progress * 100)}%${crop.ripe ? " \xB7 \u7ED3\u5B9E" : ""}${crop.dead ? " \xB7 \u67AF\u6B7B" : ""}`)
1185
2240
  );
1186
2241
  if (crop.dead) {
1187
- row.append(
2242
+ row2.append(
1188
2243
  ctx.ui.button(t.floraRemove, {
1189
2244
  size: "sm",
1190
2245
  onClick: () => void floraDo("remove", [crop.id, crop.site])
1191
2246
  })
1192
2247
  );
1193
2248
  } else {
1194
- row.append(
2249
+ row2.append(
1195
2250
  ctx.ui.button(t.floraInspect, {
1196
2251
  size: "sm",
1197
2252
  onClick: () => void inspectCrop(crop.id, crop.site)
@@ -1206,7 +2261,7 @@ ${t.wondersDone(charter.wonders.length)}`;
1206
2261
  })
1207
2262
  );
1208
2263
  }
1209
- floraSites.append(row);
2264
+ floraSites.append(row2);
1210
2265
  }
1211
2266
  floraInv.replaceChildren();
1212
2267
  floraInv.textContent = flora.inventory.length === 0 ? `${t.floraInventory}\uFF1A${t.floraEmpty}` : `${t.floraInventory}\uFF1A` + flora.inventory.map((item) => `${item.name} ${item.amount}`).join("\u3001");
@@ -1226,21 +2281,21 @@ ${t.wondersDone(charter.wonders.length)}`;
1226
2281
  }
1227
2282
  floraBags.replaceChildren();
1228
2283
  for (const bag of flora.bags) {
1229
- const row = ctx.ui.h("div");
1230
- row.style.display = "flex";
1231
- row.style.gap = "8px";
1232
- row.style.alignItems = "center";
1233
- row.append(
2284
+ const row2 = ctx.ui.h("div");
2285
+ row2.style.display = "flex";
2286
+ row2.style.gap = "8px";
2287
+ row2.style.alignItems = "center";
2288
+ row2.append(
1234
2289
  ctx.ui.h("span", "mono", `${bag.id} \xB7 ${bag.name} \xD7${bag.count}${bag.premium ? " \xB7 \u9AD8\u7EA7" : ""}`),
1235
2290
  ctx.ui.button(t.floraPlant, { size: "sm", onClick: () => void floraDo("plant", [bag.id]) })
1236
2291
  );
1237
- floraBags.append(row);
2292
+ floraBags.append(row2);
1238
2293
  }
1239
2294
  for (const gh of state?.greenhouses ?? []) {
1240
- const row = ctx.ui.h("div");
1241
- row.style.display = "flex";
1242
- row.style.gap = "8px";
1243
- row.style.alignItems = "center";
2295
+ const row2 = ctx.ui.h("div");
2296
+ row2.style.display = "flex";
2297
+ row2.style.gap = "8px";
2298
+ row2.style.alignItems = "center";
1244
2299
  const label = ctx.ui.h("span", "mono", `\u6E29\u5BA4 ${gh.siteKey}`);
1245
2300
  const indoors = gh.interiorC === null ? gh.powered ? "\u8D85\u51FA\u6E29\u5BA4\u80FD\u529B" : "\u65AD\u7535\uFF0C\u4E0D\u5DE5\u4F5C" : `\u5BA4\u5185 ${gh.interiorC}\u2103`;
1246
2301
  const value = ctx.ui.h("span", "mono", `${gh.targetC === null ? "\u81EA\u52A8" : `\u8BBE\u5B9A ${gh.targetC}\u2103`} \xB7 ${indoors}\uFF08\u5BA4\u5916 ${gh.ambientC ?? "\u2014"}\u2103\uFF09${gh.realismCores > 0 ? ` \xB7 \u62DF\u771F \xD7${gh.realismCores}` : ""}`);
@@ -1263,8 +2318,8 @@ ${t.wondersDone(charter.wonders.length)}`;
1263
2318
  size: "sm",
1264
2319
  onClick: () => void lifeDo("install", [{ id: "realism", site: gh.siteKey }])
1265
2320
  });
1266
- row.append(label, slider, value, auto, realism);
1267
- floraBags.append(row);
2321
+ row2.append(label, slider, value, auto, realism);
2322
+ floraBags.append(row2);
1268
2323
  }
1269
2324
  };
1270
2325
  async function lifeDo(method, args) {
@@ -1325,11 +2380,11 @@ ${t.wondersDone(charter.wonders.length)}`;
1325
2380
  storeList.textContent = view.list;
1326
2381
  storeRows.replaceChildren();
1327
2382
  for (const c of view.containers) {
1328
- const row = ctx.ui.h("div");
1329
- row.style.display = "flex";
1330
- row.style.gap = "6px";
1331
- row.style.flexWrap = "wrap";
1332
- row.style.alignItems = "center";
2383
+ const row2 = ctx.ui.h("div");
2384
+ row2.style.display = "flex";
2385
+ row2.style.gap = "6px";
2386
+ row2.style.flexWrap = "wrap";
2387
+ row2.style.alignItems = "center";
1333
2388
  const first = c.contents[0]?.resource ?? "biomass";
1334
2389
  const bufferNote = c.kind === "terminal" ? ctx.ui.h(
1335
2390
  "span",
@@ -1344,7 +2399,7 @@ ${t.wondersDone(charter.wonders.length)}`;
1344
2399
  depositBtn.disabled = true;
1345
2400
  depositBtn.title = t.terminalFull;
1346
2401
  }
1347
- row.append(
2402
+ row2.append(
1348
2403
  ctx.ui.h("span", "mono", `${c.id} \xB7 ${c.where} \xB7 ${c.usedKg}/${c.capKg} kg`),
1349
2404
  ...bufferNote ? [bufferNote] : [],
1350
2405
  ...c.routesText ? [ctx.ui.h("span", "muted", c.routesText.split("\n").join(" \xB7 "))] : [],
@@ -1353,7 +2408,7 @@ ${t.wondersDone(charter.wonders.length)}`;
1353
2408
  ctx.ui.button(t.storeDemolish, { size: "sm", onClick: () => void storeDo("demolish", c.id, "", 0) }),
1354
2409
  ...c.kind === "terminal" ? [ctx.ui.button(t.terminalTake, { size: "sm", onClick: () => void storeDo("take", c.id, "", 0) })] : []
1355
2410
  );
1356
- storeRows.append(row);
2411
+ storeRows.append(row2);
1357
2412
  }
1358
2413
  } catch (error) {
1359
2414
  fail(error);
@@ -1608,6 +2663,8 @@ ${t.wondersDone(charter.wonders.length)}`;
1608
2663
  }
1609
2664
  }
1610
2665
  };
2666
+
2667
+ // src/webui/panels/upgrade.ts
1611
2668
  var upgradePanel = {
1612
2669
  async mount(ctx) {
1613
2670
  const t = text(ctx.language);
@@ -1627,58 +2684,58 @@ var upgradePanel = {
1627
2684
  const render = (state) => {
1628
2685
  energy.textContent = state.locked ? t.upLocked : `${t.upEnergy}\uFF1A${state.energyKj.toLocaleString("en-US")} kJ`;
1629
2686
  cards.textContent = "";
1630
- for (const card of state.cards) {
2687
+ for (const card2 of state.cards) {
1631
2688
  const box = ctx.ui.h("div", "cardbox");
1632
2689
  box.style.border = "1px solid var(--line, #333)";
1633
2690
  box.style.borderRadius = "8px";
1634
2691
  box.style.padding = "10px";
1635
2692
  box.style.marginTop = "10px";
1636
- const status = card.status === "ready" ? t.upReady : card.status === "repairing" ? t.upRepairing : card.status === "maxed" ? t.upMaxed : t.upBroken;
1637
- const heading = card.level !== void 0 ? `${card.label} \xB7 lv${card.level}${card.maxLevel ? ` / lv${card.maxLevel}` : ""}` : card.label;
2693
+ const status = card2.status === "ready" ? t.upReady : card2.status === "repairing" ? t.upRepairing : card2.status === "maxed" ? t.upMaxed : t.upBroken;
2694
+ const heading = card2.level !== void 0 ? `${card2.label} \xB7 lv${card2.level}${card2.maxLevel ? ` / lv${card2.maxLevel}` : ""}` : card2.label;
1638
2695
  const title = ctx.ui.h("h3", "", `${heading} \xB7 ${status}`);
1639
2696
  title.style.margin = "0 0 6px";
1640
- const flavor = ctx.ui.h("p", "muted", card.flavor);
2697
+ const flavor = ctx.ui.h("p", "muted", card2.flavor);
1641
2698
  flavor.style.margin = "0 0 8px";
1642
2699
  box.append(title, flavor);
1643
- if (card.window) {
1644
- const now = ctx.ui.h("p", "", `${t.upWindow}\uFF1A${card.window}${card.limitFactor ? `\uFF08${t.upLimit} \xD7${card.limitFactor}\uFF09` : ""}`);
2700
+ if (card2.window) {
2701
+ const now = ctx.ui.h("p", "", `${t.upWindow}\uFF1A${card2.window}${card2.limitFactor ? `\uFF08${t.upLimit} \xD7${card2.limitFactor}\uFF09` : ""}`);
1645
2702
  now.style.margin = "0 0 6px";
1646
2703
  box.append(now);
1647
2704
  }
1648
- if (card.status === "repairing") {
1649
- const left = ctx.ui.h("p", "", `${t.upRepairing} \xB7 \u8FD8\u5269 ${card.leftHomeHours.toFixed(1)} \u6BCD\u661F\u65F6`);
2705
+ if (card2.status === "repairing") {
2706
+ const left = ctx.ui.h("p", "", `${t.upRepairing} \xB7 \u8FD8\u5269 ${card2.leftHomeHours.toFixed(1)} \u6BCD\u661F\u65F6`);
1650
2707
  box.append(left);
1651
2708
  cards.append(box);
1652
2709
  continue;
1653
2710
  }
1654
- if (card.status === "maxed") {
1655
- if (card.benefits) box.append(ctx.ui.h("p", "muted", card.benefits));
2711
+ if (card2.status === "maxed") {
2712
+ if (card2.benefits) box.append(ctx.ui.h("p", "muted", card2.benefits));
1656
2713
  cards.append(box);
1657
2714
  continue;
1658
2715
  }
1659
2716
  const need = ctx.ui.h(
1660
2717
  "p",
1661
2718
  "",
1662
- `${t.upNeed} ${card.costKj.toLocaleString("en-US")} kJ + ` + card.materials.map((m) => `${m.name} ${m.needKg} kg\uFF08${m.haveKg} kg\uFF09`).join("\u3001") + ` \xB7 ${card.buildHours} \u6BCD\u661F\u65F6`
2719
+ `${t.upNeed} ${card2.costKj.toLocaleString("en-US")} kJ + ` + card2.materials.map((m) => `${m.name} ${m.needKg} kg\uFF08${m.haveKg} kg\uFF09`).join("\u3001") + ` \xB7 ${card2.buildHours} \u6BCD\u661F\u65F6`
1663
2720
  );
1664
2721
  need.style.margin = "0 0 8px";
1665
2722
  box.append(need);
1666
- if (card.benefits) {
1667
- const benefit = ctx.ui.h("p", "muted", `${t.upBenefit}\uFF1A${card.benefits}`);
2723
+ if (card2.benefits) {
2724
+ const benefit = ctx.ui.h("p", "muted", `${t.upBenefit}\uFF1A${card2.benefits}`);
1668
2725
  benefit.style.margin = "0 0 6px";
1669
2726
  box.append(benefit);
1670
2727
  }
1671
- const button = ctx.ui.button(card.status === "broken" ? t.upRepair : t.upUpgrade, {
2728
+ const button = ctx.ui.button(card2.status === "broken" ? t.upRepair : t.upUpgrade, {
1672
2729
  variant: "primary",
1673
2730
  size: "sm",
1674
2731
  onClick: () => {
1675
- void repair(card.id, button);
2732
+ void repair(card2.id, button);
1676
2733
  }
1677
2734
  });
1678
- if (!card.canRepair) {
2735
+ if (!card2.canRepair) {
1679
2736
  button.disabled = true;
1680
- if (card.blockers.length > 0) {
1681
- box.append(ctx.ui.h("p", "muted", card.blockers.join("\uFF1B")));
2737
+ if (card2.blockers.length > 0) {
2738
+ box.append(ctx.ui.h("p", "muted", card2.blockers.join("\uFF1B")));
1682
2739
  }
1683
2740
  }
1684
2741
  box.append(button);
@@ -1709,6 +2766,8 @@ var upgradePanel = {
1709
2766
  }, 5e3);
1710
2767
  }
1711
2768
  };
2769
+
2770
+ // src/webui/panels/protocol.ts
1712
2771
  var protocolPanel = {
1713
2772
  async mount(ctx) {
1714
2773
  const t = text(ctx.language);
@@ -1765,24 +2824,24 @@ var protocolPanel = {
1765
2824
  void recreate(recreateButton);
1766
2825
  });
1767
2826
  ctx.root.append(sheet.el);
1768
- const render = (panel2) => {
2827
+ const render = (panel7) => {
1769
2828
  wakeButton.hidden = false;
1770
- progress.textContent = `${t.protoDone} ${panel2.done} / ${panel2.total}`;
2829
+ progress.textContent = `${t.protoDone} ${panel7.done} / ${panel7.total}`;
1771
2830
  body.textContent = "";
1772
- for (const chapter of panel2.chapters) {
2831
+ for (const chapter of panel7.chapters) {
1773
2832
  const heading = ctx.ui.h("h3", "", `${chapter.title} \xB7 ${chapter.done}/${chapter.total}`);
1774
2833
  heading.style.margin = "10px 0 4px";
1775
2834
  body.append(heading);
1776
2835
  for (const task of chapter.tasks) {
1777
- const row = ctx.ui.h("div", "", `${task.done ? "\u2713" : "\u25CB"} ${task.title}${task.done ? "" : ` \xB7 ${task.progress}`}`);
1778
- row.style.padding = "2px 0";
1779
- row.style.color = task.done ? "var(--muted, #8a8a8a)" : "";
1780
- body.append(row);
2836
+ const row2 = ctx.ui.h("div", "", `${task.done ? "\u2713" : "\u25CB"} ${task.title}${task.done ? "" : ` \xB7 ${task.progress}`}`);
2837
+ row2.style.padding = "2px 0";
2838
+ row2.style.color = task.done ? "var(--muted, #8a8a8a)" : "";
2839
+ body.append(row2);
1781
2840
  }
1782
2841
  }
1783
2842
  habitatBox.textContent = "";
1784
- if (panel2.population) {
1785
- const p = panel2.population;
2843
+ if (panel7.population) {
2844
+ const p = panel7.population;
1786
2845
  habitatBox.append(
1787
2846
  ctx.ui.h("h3", "", t.protoPopulation),
1788
2847
  ctx.ui.h(
@@ -1792,8 +2851,8 @@ var protocolPanel = {
1792
2851
  )
1793
2852
  );
1794
2853
  }
1795
- if (panel2.habitat) {
1796
- const h = panel2.habitat;
2854
+ if (panel7.habitat) {
2855
+ const h = panel7.habitat;
1797
2856
  habitatBox.append(
1798
2857
  ctx.ui.h("h3", "", `${t.protoHabitat}`),
1799
2858
  ctx.ui.h(
@@ -1804,21 +2863,21 @@ var protocolPanel = {
1804
2863
  );
1805
2864
  }
1806
2865
  recreateBox.hidden = false;
1807
- if (recreateSeedInput.value === "") recreateSeedInput.value = panel2.recreate.seed;
1808
- if (recreateMassInput.value === "") recreateMassInput.value = String(panel2.recreate.starMass);
2866
+ if (recreateSeedInput.value === "") recreateSeedInput.value = panel7.recreate.seed;
2867
+ if (recreateMassInput.value === "") recreateMassInput.value = String(panel7.recreate.starMass);
1809
2868
  paintMass();
1810
- recreateButton.disabled = !panel2.recreate.ready;
2869
+ recreateButton.disabled = !panel7.recreate.ready;
1811
2870
  recreateList.textContent = "";
1812
- if (!panel2.recreate.ready) {
2871
+ if (!panel7.recreate.ready) {
1813
2872
  recreateList.append(ctx.ui.h("li", "muted", t.recreateBlocked));
1814
- for (const blocker of panel2.recreate.blockers) recreateList.append(ctx.ui.h("li", "", blocker));
2873
+ for (const blocker of panel7.recreate.blockers) recreateList.append(ctx.ui.h("li", "", blocker));
1815
2874
  }
1816
- if (panel2.awakened) {
2875
+ if (panel7.awakened) {
1817
2876
  wakeButton.disabled = true;
1818
2877
  wakeButton.textContent = t.protoAwakened;
1819
2878
  } else {
1820
- wakeButton.disabled = !panel2.ready || !panel2.habitat;
1821
- wakeButton.textContent = panel2.ready ? t.protoWake : `${t.protoWake}\uFF08${t.protoDone} ${panel2.done}/${panel2.total}\uFF09`;
2879
+ wakeButton.disabled = !panel7.ready || !panel7.habitat;
2880
+ wakeButton.textContent = panel7.ready ? t.protoWake : `${t.protoWake}\uFF08${t.protoDone} ${panel7.done}/${panel7.total}\uFF09`;
1822
2881
  }
1823
2882
  };
1824
2883
  const load = async () => {
@@ -1840,8 +2899,8 @@ var protocolPanel = {
1840
2899
  const wake = async (button) => {
1841
2900
  button.disabled = true;
1842
2901
  try {
1843
- const panel2 = await ctx.invoke("wake", []);
1844
- render(panel2);
2902
+ const panel7 = await ctx.invoke("wake", []);
2903
+ render(panel7);
1845
2904
  ctx.ui.toast(t.protoAwakened, "ok");
1846
2905
  void ctx.refresh();
1847
2906
  } catch (error) {
@@ -1871,92 +2930,117 @@ var protocolPanel = {
1871
2930
  }, 5e3);
1872
2931
  }
1873
2932
  };
1874
- var guidePanel = {
2933
+
2934
+ // src/webui/panels/shop.ts
2935
+ var shopPanel = {
1875
2936
  mount(ctx) {
1876
2937
  const t = text(ctx.language);
1877
- const sheet = ctx.ui.sheet({ title: t.guideTitle, desc: t.guideDesc });
1878
- const searchRow = ctx.ui.rowbar();
1879
- const searchInput = ctx.ui.input({ placeholder: t.guideSearchHint });
1880
- searchInput.type = "text";
1881
- const searchButton = ctx.ui.button(t.guideSearch, { size: "sm" });
1882
- const toolsButton = ctx.ui.button(t.guideTools, { size: "sm" });
1883
- searchRow.append(searchInput, searchButton, toolsButton);
1884
- const chips = ctx.ui.h("div", "rows");
1885
- const article = ctx.ui.h("div", "cols");
1886
- const hint = ctx.ui.h("p", "muted", t.guideEmpty);
1887
- chips.append(ctx.ui.h("span", "muted", t.guidePick));
1888
- article.append(hint);
1889
- sheet.body.append(searchRow, chips, article);
2938
+ const sheet = ctx.ui.sheet({ title: t.shopTitle, desc: t.shopDesc });
2939
+ const head = ctx.ui.rowbar();
2940
+ const statusLine = ctx.ui.msgline();
2941
+ const wallet = ctx.ui.h("span", "mono", "");
2942
+ const refreshButton = ctx.ui.button("\u5237\u65B0", { size: "sm" });
2943
+ head.append(refreshButton, statusLine, wallet);
2944
+ const sellBox = ctx.ui.h("div");
2945
+ const buyBox = ctx.ui.h("div");
2946
+ const orderBox = ctx.ui.h("div");
2947
+ sheet.body.append(head, sellBox, buyBox, orderBox);
1890
2948
  ctx.root.append(sheet.el);
1891
- let current = null;
1892
- let topics = [];
1893
- const paintChips = () => {
1894
- for (const chip of Array.from(chips.querySelectorAll("button"))) chip.remove();
1895
- for (const topic of topics) {
1896
- const button = ctx.ui.button(topic.title, { size: "sm", variant: topic.id === current ? "primary" : void 0 });
1897
- button.addEventListener("click", () => {
1898
- void open(topic.id);
1899
- });
1900
- chips.append(button);
1901
- }
1902
- };
1903
- const open = async (id) => {
1904
- current = id;
1905
- paintChips();
2949
+ const fmt = (value) => value.toLocaleString("en-US");
2950
+ async function act(method, args) {
1906
2951
  try {
1907
- const payload = await ctx.invoke("read", [id]);
1908
- article.replaceChildren(renderMarkdown(document, payload.text));
2952
+ const result = await ctx.invoke(method, args);
2953
+ if (result?.text) ctx.ui.toast(result.text, "ok");
2954
+ if (result?.state) render(result.state);
2955
+ else await load();
2956
+ void ctx.refresh();
1909
2957
  } catch (error) {
1910
- article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
2958
+ ctx.ui.toast(error instanceof Error ? error.message : String(error), "bad");
1911
2959
  }
1912
- };
1913
- const search = async () => {
1914
- const query = searchInput.value.trim();
1915
- if (!query) return;
1916
- const busy = ctx.ui.disable(searchButton);
1917
- try {
1918
- const payload = await ctx.invoke("search", [query]);
1919
- const card = renderMarkdown(document, payload.text);
1920
- card.classList.add("mono");
1921
- article.replaceChildren(card);
1922
- } catch (error) {
1923
- article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
1924
- } finally {
1925
- busy.dispose();
2960
+ }
2961
+ function buyArgs(row2) {
2962
+ if (row2.id === "random_seed" || row2.id === "premium_seed") {
2963
+ return { kind: row2.id, ...row2.species ? { species: row2.species } : {} };
1926
2964
  }
1927
- };
1928
- searchButton.addEventListener("click", () => void search());
1929
- toolsButton.addEventListener("click", () => {
1930
- void (async () => {
1931
- try {
1932
- const payload = await ctx.invoke("tools", []);
1933
- const card = renderMarkdown(document, payload.text);
1934
- card.classList.add("mono");
1935
- article.replaceChildren(card);
1936
- } catch (error) {
1937
- article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
1938
- }
1939
- })();
1940
- });
1941
- searchInput.addEventListener("keydown", (event) => {
1942
- if (event.key === "Enter") void search();
1943
- });
1944
- const load = async () => {
2965
+ if (row2.id === "fertilizer") return { kind: "fertilizer", kg: 5 };
2966
+ if (row2.id === "cylinder") return { kind: "cylinder", count: 10 };
2967
+ return { kind: row2.id };
2968
+ }
2969
+ function render(panel7) {
2970
+ const open = panel7.open;
2971
+ statusLine.textContent = open ? t.shopOpenNow : t.shopClosedNow;
2972
+ wallet.textContent = [
2973
+ t.shopCredits + " " + fmt(panel7.credits),
2974
+ t.shopEnergy + " " + fmt(panel7.energyKj) + " kJ",
2975
+ t.shopTungsten + " " + fmt(panel7.tungsten) + " kg",
2976
+ t.shopWindowLabel + " " + panel7.window,
2977
+ open ? panel7.closedNote ?? "" : t.shopNextOpen(panel7.nextOpenHours)
2978
+ ].filter(Boolean).join(" \xB7 ");
2979
+ sellBox.replaceChildren(ctx.ui.h("h4", "", t.shopSellHeader));
2980
+ for (const row2 of panel7.sellables) {
2981
+ const line = ctx.ui.h("div");
2982
+ line.style.display = "flex";
2983
+ line.style.gap = "8px";
2984
+ line.style.alignItems = "center";
2985
+ line.append(
2986
+ ctx.ui.h("span", "mono", row2.name + " \xB7 " + row2.priceLabel + " \xB7 " + row2.limitLabel),
2987
+ ctx.ui.h("span", "muted", t.shopHeld(fmt(row2.held ?? 0)))
2988
+ );
2989
+ const sell = ctx.ui.button(t.shopSell(row2.name, "1"), {
2990
+ size: "sm",
2991
+ onClick: () => void act("sell", [{ id: row2.id, amount: 1 }])
2992
+ });
2993
+ sell.disabled = !open || (row2.held ?? 0) <= 0;
2994
+ line.append(sell);
2995
+ sellBox.append(line);
2996
+ }
2997
+ buyBox.replaceChildren(ctx.ui.h("h4", "", t.shopBuyHeader));
2998
+ for (const row2 of panel7.buyables) {
2999
+ const line = ctx.ui.h("div");
3000
+ line.style.display = "flex";
3001
+ line.style.gap = "8px";
3002
+ line.style.alignItems = "center";
3003
+ line.append(ctx.ui.h("span", "mono", row2.name + " \xB7 " + row2.priceLabel + " \xB7 " + row2.limitLabel));
3004
+ if (row2.note) line.append(ctx.ui.h("span", "muted", row2.note));
3005
+ const buy = ctx.ui.button(t.shopBuy(row2.name), {
3006
+ size: "sm",
3007
+ onClick: () => void act("buy", [buyArgs(row2)])
3008
+ });
3009
+ buy.disabled = !open;
3010
+ line.append(buy);
3011
+ buyBox.append(line);
3012
+ }
3013
+ orderBox.replaceChildren(ctx.ui.h("h4", "", t.shopOrdersHeader));
3014
+ if (panel7.orders.length === 0) {
3015
+ orderBox.append(ctx.ui.h("p", "muted", t.shopNoOrders));
3016
+ }
3017
+ for (const order of panel7.orders) {
3018
+ const line = ctx.ui.h("div");
3019
+ line.style.display = "flex";
3020
+ line.style.gap = "8px";
3021
+ line.style.alignItems = "center";
3022
+ line.append(ctx.ui.h("span", "mono", order.label));
3023
+ if (order.note) line.append(ctx.ui.h("span", "muted", order.note));
3024
+ const deliver = ctx.ui.button(t.shopDeliver, { size: "sm", onClick: () => void act("order", [{ id: order.id }]) });
3025
+ deliver.disabled = !open;
3026
+ line.append(deliver);
3027
+ orderBox.append(line);
3028
+ }
3029
+ }
3030
+ async function load() {
1945
3031
  try {
1946
- const payload = await ctx.invoke("topics");
1947
- topics = payload.topics ?? [];
1948
- paintChips();
1949
- if (topics.length === 0) return;
1950
- if (!current || !topics.some((topic) => topic.id === current)) {
1951
- await open(topics[0].id);
1952
- }
3032
+ const panel7 = await ctx.invoke("state", []);
3033
+ render(panel7);
1953
3034
  } catch (error) {
1954
- hint.textContent = errorText(error);
3035
+ statusLine.textContent = error instanceof Error ? error.message : String(error);
1955
3036
  }
1956
- };
3037
+ }
3038
+ refreshButton.addEventListener("click", () => void load());
1957
3039
  void load();
1958
3040
  }
1959
3041
  };
3042
+
3043
+ // src/webui/markdown.ts
1960
3044
  function renderMarkdown(owner, text2) {
1961
3045
  const root = owner.createElement("div");
1962
3046
  root.className = "rows";
@@ -2026,122 +3110,99 @@ function inlineNodes(owner, text2) {
2026
3110
  if (last < text2.length) nodes.push(owner.createTextNode(text2.slice(last)));
2027
3111
  return nodes;
2028
3112
  }
2029
- var shopPanel = {
3113
+
3114
+ // src/webui/panels/guide.ts
3115
+ var guidePanel = {
2030
3116
  mount(ctx) {
2031
3117
  const t = text(ctx.language);
2032
- const sheet = ctx.ui.sheet({ title: t.shopTitle, desc: t.shopDesc });
2033
- const head = ctx.ui.rowbar();
2034
- const statusLine = ctx.ui.msgline();
2035
- const wallet = ctx.ui.h("span", "mono", "");
2036
- const refreshButton = ctx.ui.button("\u5237\u65B0", { size: "sm" });
2037
- head.append(refreshButton, statusLine, wallet);
2038
- const sellBox = ctx.ui.h("div");
2039
- const buyBox = ctx.ui.h("div");
2040
- const orderBox = ctx.ui.h("div");
2041
- sheet.body.append(head, sellBox, buyBox, orderBox);
3118
+ const sheet = ctx.ui.sheet({ title: t.guideTitle, desc: t.guideDesc });
3119
+ const searchRow = ctx.ui.rowbar();
3120
+ const searchInput = ctx.ui.input({ placeholder: t.guideSearchHint });
3121
+ searchInput.type = "text";
3122
+ const searchButton = ctx.ui.button(t.guideSearch, { size: "sm" });
3123
+ const toolsButton = ctx.ui.button(t.guideTools, { size: "sm" });
3124
+ searchRow.append(searchInput, searchButton, toolsButton);
3125
+ const chips = ctx.ui.h("div", "rows");
3126
+ const article = ctx.ui.h("div", "cols");
3127
+ const hint = ctx.ui.h("p", "muted", t.guideEmpty);
3128
+ chips.append(ctx.ui.h("span", "muted", t.guidePick));
3129
+ article.append(hint);
3130
+ sheet.body.append(searchRow, chips, article);
2042
3131
  ctx.root.append(sheet.el);
2043
- const fmt = (value) => value.toLocaleString("en-US");
2044
- async function act(method, args) {
2045
- try {
2046
- const result = await ctx.invoke(method, args);
2047
- if (result?.text) ctx.ui.toast(result.text, "ok");
2048
- if (result?.state) render(result.state);
2049
- else await load();
2050
- void ctx.refresh();
2051
- } catch (error) {
2052
- ctx.ui.toast(error instanceof Error ? error.message : String(error), "bad");
2053
- }
2054
- }
2055
- function buyArgs(row) {
2056
- if (row.id === "random_seed" || row.id === "premium_seed") {
2057
- return { kind: row.id, ...row.species ? { species: row.species } : {} };
2058
- }
2059
- if (row.id === "fertilizer") return { kind: "fertilizer", kg: 5 };
2060
- if (row.id === "cylinder") return { kind: "cylinder", count: 10 };
2061
- return { kind: row.id };
2062
- }
2063
- function render(panel2) {
2064
- const open = panel2.open;
2065
- statusLine.textContent = open ? t.shopOpenNow : t.shopClosedNow;
2066
- wallet.textContent = [
2067
- t.shopCredits + " " + fmt(panel2.credits),
2068
- t.shopEnergy + " " + fmt(panel2.energyKj) + " kJ",
2069
- t.shopTungsten + " " + fmt(panel2.tungsten) + " kg",
2070
- t.shopWindowLabel + " " + panel2.window,
2071
- open ? panel2.closedNote ?? "" : t.shopNextOpen(panel2.nextOpenHours)
2072
- ].filter(Boolean).join(" \xB7 ");
2073
- sellBox.replaceChildren(ctx.ui.h("h4", "", t.shopSellHeader));
2074
- for (const row of panel2.sellables) {
2075
- const line = ctx.ui.h("div");
2076
- line.style.display = "flex";
2077
- line.style.gap = "8px";
2078
- line.style.alignItems = "center";
2079
- line.append(
2080
- ctx.ui.h("span", "mono", row.name + " \xB7 " + row.priceLabel + " \xB7 " + row.limitLabel),
2081
- ctx.ui.h("span", "muted", t.shopHeld(fmt(row.held ?? 0)))
2082
- );
2083
- const sell = ctx.ui.button(t.shopSell(row.name, "1"), {
2084
- size: "sm",
2085
- onClick: () => void act("sell", [{ id: row.id, amount: 1 }])
2086
- });
2087
- sell.disabled = !open || (row.held ?? 0) <= 0;
2088
- line.append(sell);
2089
- sellBox.append(line);
2090
- }
2091
- buyBox.replaceChildren(ctx.ui.h("h4", "", t.shopBuyHeader));
2092
- for (const row of panel2.buyables) {
2093
- const line = ctx.ui.h("div");
2094
- line.style.display = "flex";
2095
- line.style.gap = "8px";
2096
- line.style.alignItems = "center";
2097
- line.append(ctx.ui.h("span", "mono", row.name + " \xB7 " + row.priceLabel + " \xB7 " + row.limitLabel));
2098
- if (row.note) line.append(ctx.ui.h("span", "muted", row.note));
2099
- const buy = ctx.ui.button(t.shopBuy(row.name), {
2100
- size: "sm",
2101
- onClick: () => void act("buy", [buyArgs(row)])
3132
+ let current = null;
3133
+ let topics = [];
3134
+ const paintChips = () => {
3135
+ for (const chip of Array.from(chips.querySelectorAll("button"))) chip.remove();
3136
+ for (const topic of topics) {
3137
+ const button = ctx.ui.button(topic.title, { size: "sm", variant: topic.id === current ? "primary" : void 0 });
3138
+ button.addEventListener("click", () => {
3139
+ void open(topic.id);
2102
3140
  });
2103
- buy.disabled = !open;
2104
- line.append(buy);
2105
- buyBox.append(line);
3141
+ chips.append(button);
2106
3142
  }
2107
- orderBox.replaceChildren(ctx.ui.h("h4", "", t.shopOrdersHeader));
2108
- if (panel2.orders.length === 0) {
2109
- orderBox.append(ctx.ui.h("p", "muted", t.shopNoOrders));
3143
+ };
3144
+ const open = async (id) => {
3145
+ current = id;
3146
+ paintChips();
3147
+ try {
3148
+ const payload = await ctx.invoke("read", [id]);
3149
+ article.replaceChildren(renderMarkdown(document, payload.text));
3150
+ } catch (error) {
3151
+ article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
2110
3152
  }
2111
- for (const order of panel2.orders) {
2112
- const line = ctx.ui.h("div");
2113
- line.style.display = "flex";
2114
- line.style.gap = "8px";
2115
- line.style.alignItems = "center";
2116
- line.append(ctx.ui.h("span", "mono", order.label));
2117
- if (order.note) line.append(ctx.ui.h("span", "muted", order.note));
2118
- const deliver = ctx.ui.button(t.shopDeliver, { size: "sm", onClick: () => void act("order", [{ id: order.id }]) });
2119
- deliver.disabled = !open;
2120
- line.append(deliver);
2121
- orderBox.append(line);
3153
+ };
3154
+ const search = async () => {
3155
+ const query = searchInput.value.trim();
3156
+ if (!query) return;
3157
+ const busy = ctx.ui.disable(searchButton);
3158
+ try {
3159
+ const payload = await ctx.invoke("search", [query]);
3160
+ const card2 = renderMarkdown(document, payload.text);
3161
+ card2.classList.add("mono");
3162
+ article.replaceChildren(card2);
3163
+ } catch (error) {
3164
+ article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
3165
+ } finally {
3166
+ busy.dispose();
2122
3167
  }
2123
- }
2124
- async function load() {
3168
+ };
3169
+ searchButton.addEventListener("click", () => void search());
3170
+ toolsButton.addEventListener("click", () => {
3171
+ void (async () => {
3172
+ try {
3173
+ const payload = await ctx.invoke("tools", []);
3174
+ const card2 = renderMarkdown(document, payload.text);
3175
+ card2.classList.add("mono");
3176
+ article.replaceChildren(card2);
3177
+ } catch (error) {
3178
+ article.replaceChildren(ctx.ui.h("p", "muted", errorText(error)));
3179
+ }
3180
+ })();
3181
+ });
3182
+ searchInput.addEventListener("keydown", (event) => {
3183
+ if (event.key === "Enter") void search();
3184
+ });
3185
+ const load = async () => {
2125
3186
  try {
2126
- const panel2 = await ctx.invoke("state", []);
2127
- render(panel2);
3187
+ const payload = await ctx.invoke("topics");
3188
+ topics = payload.topics ?? [];
3189
+ paintChips();
3190
+ if (topics.length === 0) return;
3191
+ if (!current || !topics.some((topic) => topic.id === current)) {
3192
+ await open(topics[0].id);
3193
+ }
2128
3194
  } catch (error) {
2129
- statusLine.textContent = error instanceof Error ? error.message : String(error);
3195
+ hint.textContent = errorText(error);
2130
3196
  }
2131
- }
2132
- refreshButton.addEventListener("click", () => void load());
3197
+ };
2133
3198
  void load();
2134
3199
  }
2135
3200
  };
2136
- var bundle = { panels: { system: panel, upgrade: upgradePanel, protocol: protocolPanel, shop: shopPanel, guide: guidePanel } };
2137
- function errorText(error) {
2138
- return error instanceof Error ? error.message : String(error);
2139
- }
2140
- function normalizeSeedInput(raw) {
2141
- const text2 = raw.trim();
2142
- if (!text2) return 20261111;
2143
- return /^\d{1,15}$/.test(text2) ? Number(text2) : text2;
2144
- }
3201
+
3202
+ // src/webui/client.ts
3203
+ var bundle = {
3204
+ panels: { overview: overview_default, surface: surface_default, farm: farm_default, industry: industry_default, life: life_default, system: panel6, upgrade: upgradePanel, protocol: protocolPanel, shop: shopPanel, guide: guidePanel }
3205
+ };
2145
3206
  var client_default = bundle;
2146
3207
  export {
2147
3208
  client_default as default