Prompt specification
Build or customize the Three.js 3D scene "Trade a Tool for a Time Slot" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Trade a Tool for a Time Slot
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/trade-a-tool-for-a-time-slot-x3554
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows negotiated agreements between game players. Create a tabletop cooperative puzzle where players exchange access to a tool and workspace. Verify both commitments and show the consequence of an incompatible schedule. Voxel style.
Working Three.js Starter (trade-a-tool-for-a-time-slot-x3554):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Borrowed Time — Cooperative Access Pact</title>
<style>
:root {
--ink: #172033;
--ink-2: #202c43;
--paper: #f5f0df;
--paper-2: #e8e1cc;
--amber: #f5b942;
--amber-dark: #9c681d;
--teal: #50c8bd;
--teal-dark: #247c78;
--green: #79cf68;
--red: #ef6464;
--blue: #73a8ff;
--shadow: 4px 4px 0 var(--ink);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--ink);
color: var(--ink);
font-family: "Courier New", Courier, monospace;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
button:focus-visible {
outline: 4px solid var(--blue);
outline-offset: 2px;
}
#app {
min-height: 100vh;
display: grid;
grid-template-rows: 72px 1fr;
}
.topbar {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 12px 18px;
color: var(--paper);
background: var(--ink);
border-bottom: 4px solid #0c1220;
box-shadow: 0 4px 0 #0c1220;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
padding: 5px;
background: var(--paper);
border: 3px solid #0b111d;
box-shadow: 3px 3px 0 var(--amber-dark);
transform: rotate(-3deg);
}
.brand-mark i {
display: block;
background: var(--ink);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
background: var(--amber);
}
.brand strong {
display: block;
font-size: 16px;
letter-spacing: 1px;
white-space: nowrap;
}
.brand small {
display: block;
margin-top: 3px;
color: #9eabc1;
font-size: 10px;
letter-spacing: 2px;
}
.top-actions {
display: flex;
align-items: center;
gap: 12px;
}
.system-status {
display: flex;
align-items: center;
gap: 8px;
color: #c9d3e3;
font-size: 11px;
letter-spacing: 1px;
}
.status-dot {
width: 10px;
height: 10px;
background: var(--green);
box-shadow: 0 0 12px rgba(121, 207, 104, 0.7);
}
.status-dot.danger {
background: var(--red);
box-shadow: 0 0 12px rgba(239, 100, 100, 0.8);
}
.status-dot.busy {
background: var(--amber);
box-shadow: 0 0 12px rgba(245, 185, 66, 0.8);
}
.reset-button {
padding: 9px 12px;
color: var(--paper);
background: transparent;
border: 2px solid #526078;
cursor: pointer;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
.reset-button:hover {
color: var(--ink);
background: var(--paper);
border-color: var(--paper);
}
main {
min-height: 0;
display: grid;
grid-template-columns: minmax(370px, 430px) 1fr;
}
.agreement-panel {
position: relative;
z-index: 5;
min-height: 0;
overflow-y: auto;
padding: 24px 22px 28px;
background:
linear-gradient(90deg, rgba(23, 32, 51, 0.035) 1px, transparent 1px),
linear-gradient(rgba(23, 32, 51, 0.035) 1px, transparent 1px),
var(--paper);
background-size: 18px 18px;
border-right: 4px solid var(--ink);
box-shadow: 7px 0 0 rgba(23, 32, 51, 0.18);
}
.eyebrow {
display: inline-block;
margin-bottom: 10px;
padding: 5px 8px;
color: var(--paper);
background: var(--ink);
font-size: 10px;
font-weight: bold;
letter-spacing: 2px;
}
h1 {
margin: 0;
font-size: clamp(28px, 3vw, 38px);
line-height: 0.95;
letter-spacing: -2px;
text-transform: uppercase;
}
.intro {
margin: 14px 0 20px;
color: #536078;
font-size: 12px;
line-height: 1.6;
}
.objective {
display: grid;
grid-template-columns: 34px 1fr;
gap: 11px;
margin-bottom: 20px;
padding: 12px;
background: #fff9e8;
border: 3px solid var(--ink);
box-shadow: var(--shadow);
}
.objective-icon {
display: grid;
place-items: center;
width: 32px;
height: 32px;
color: var(--ink);
background: var(--amber);
border: 2px solid var(--ink);
font-size: 17px;
font-weight: bold;
}
.objective strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
text-transform: uppercase;
}
.objective span {
display: block;
color: #59647a;
font-size: 11px;
line-height: 1.4;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 20px 0 9px;
font-size: 11px;
font-weight: bold;
letter-spacing: 2px;
text-transform: uppercase;
}
.section-title small {
color: #7b8497;
font-size: 9px;
letter-spacing: 1px;
}
.pact-card {
position: relative;
margin-bottom: 13px;
padding: 14px;
background: #fffdf4;
border: 3px solid var(--ink);
box-shadow: var(--shadow);
}
.pact-card::before {
content: "";
position: absolute;
top: -3px;
bottom: -3px;
left: -3px;
width: 8px;
background: var(--player-color);
border-right: 2px solid var(--ink);
}
.pact-card.amber {
--player-color: var(--amber);
}
.pact-card.teal {
--player-color: var(--teal);
}
.pact-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.player-id {
display: flex;
align-items: center;
gap: 9px;
}
.avatar {
position: relative;
width: 34px;
height: 34px;
background: var(--player-color);
border: 3px solid var(--ink);
box-shadow: 2px 2px 0 var(--ink);
}
.avatar::before,
.avatar::after {
content: "";
position: absolute;
top: 11px;
width: 5px;
height: 5px;
background: var(--ink);
}
.avatar::before {
left: 7px;
}
.avatar::after {
right: 7px;
}
.player-id strong {
display: block;
font-size: 13px;
text-transform: uppercase;
}
.player-id small {
display: block;
margin-top: 2px;
color: #7a8294;
font-size: 9px;
text-transform: uppercase;
}
.signed {
padding: 5px 7px;
color: #26613e;
background: #dff3d9;
border: 2px solid #43835b;
font-size: 9px;
font-weight: bold;
text-transform: uppercase;
}
.resource-line {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
padding: 9px 10px;
color: #3d485e;
background: #f0ecdf;
border: 2px dashed #a7a797;
font-size: 11px;
line-height: 1.35;
}
.resource-line b {
color: var(--ink);
}
.resource-icon {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 29px;
height: 29px;
color: var(--ink);
background: var(--player-color);
border: 2px solid var(--ink);
font-size: 15px;
}
.slot-label {
margin-bottom: 7px;
color: #667085;
font-size: 9px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
}
.slots {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.slot {
padding: 8px 4px;
color: #59647a;
background: #ece7d9;
border: 2px solid #b5b09f;
cursor: pointer;
font-size: 11px;
font-weight: bold;
}
.slot:hover {
color: var(--ink);
border-color: var(--ink);
}
.slot.selected {
color: var(--paper);
background: var(--ink);
border-color: var(--ink);
box-shadow: inset 0 -4px 0 var(--player-color);
}
.exchange {
display: grid;
grid-template-columns: 1fr 34px 1fr;
align-items: center;
gap: 7px;
margin: -3px 0 14px;
color: #778094;
font-size: 9px;
font-weight: bold;
text-align: center;
letter-spacing: 1px;
}
.exchange-line {
height: 2px;
background: #a9aaa0;
position: relative;
}
.exchange-line::after {
content: "";
position: absolute;
right: -1px;
top: -3px;
border-left: 6px solid #a9aaa0;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
.exchange strong {
display: grid;
place-items: center;
width: 30px;
height: 30px;
color: var(--paper);
background: var(--ink);
border: 3px solid var(--ink);
border-radius: 50%;
font-size: 14px;
}
.constraint {
margin: 0 0 16px;
padding: 11px 12px;
color: #744b16;
background: #ffedbf;
border: 2px solid #c9953c;
font-size: 10px;
line-height: 1.5;
}
.constraint b {
color: var(--ink);
}
.timeline {
padding: 12px;
background: #fffdf4;
border: 3px solid var(--ink);
box-shadow: var(--shadow);
}
.timeline-grid {
display: grid;
grid-template-columns: 66px repeat(3, 1fr);
gap: 5px;
align-items: center;
font-size: 9px;
text-align: center;
}
.timeline-grid .label {
color: #697286;
text-align: left;
font-weight: bold;
}
.timeline-grid .head {
padding-bottom: 5px;
color: #697286;
border-bottom: 2px solid #d3ccba;
}
.timeline-bar {
grid-row: 2;
padding: 8px 3px;
color: var(--ink);
border: 2px solid var(--ink);
font-size: 8px;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
}
#timelinePress {
background: var(--amber);
}
#timelineDeck {
background: var(--teal);
}
.bus-row {
grid-column: 1 / -1;
grid-row: 3;
display: flex;
justify-content: space-between;
margin-top: 5px;
padding-top: 7px;
color: #71798b;
border-top: 2px dashed #c8c1af;
font-size: 9px;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 18px;
}
.action-button {
position: relative;
min-height: 46px;
padding: 11px 8px;
border: 3px solid var(--ink);
box-shadow: var(--shadow);
cursor: pointer;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
.action-button.primary {
color: var(--paper);
background: var(--ink);
}
.action-button.primary:hover {
background: #2c3952;
}
.action-button.secondary {
color: var(--ink);
background: var(--paper-2);
}
.action-button.secondary:hover {
background: #fff8df;
}
.action-button:disabled {
cursor: wait;
opacity: 0.65;
}
.verdict {
margin-top: 21px;
padding: 14px;
background: #fffdf4;
border: 3px solid var(--ink);
box-shadow: var(--shadow);
}
.verdict-heading {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
}
.verdict-icon {
display: grid;
place-items: center;
width: 28px;
height: 28px;
color: var(--paper);
background: #7b8497;
border: 2px solid var(--ink);
font-size: 14px;
}
.verdict.success .verdict-icon {
background: var(--green);
}
.verdict.danger .verdict-icon {
background: var(--red);
}
.verdict.busy .verdict-icon {
background: var(--amber);
}
.verdict p {
margin: 0 0 12px;
color: #59647a;
font-size: 10px;
line-height: 1.55;
}
.ledger {
display: grid;
gap: 7px;
}
.ledger-item {
display: grid;
grid-template-columns: 19px 1fr;
gap: 8px;
align-items: start;
color: #4e596e;
font-size: 10px;
line-height: 1.35;
}
.ledger-item b {
display: grid;
place-items: center;
width: 18px;
height: 18px;
color: var(--paper);
background: #7b8497;
font-size: 10px;
}
.ledger-item.pass b {
background: var(--green);
color: #16351d;
}
.ledger-item.fail b {
background: var(--red);
color: #431515;
}
.penalty {
display: none;
margin-top: 11px;
padding: 9px;
color: #7b2626;
background: #ffe1dc;
border: 2px solid #d7665d;
font-size: 10px;
font-weight: bold;
}
.penalty.visible {
display: block;
}
.keyboard-hint {
margin: 17px 0 0;
color: #89909d;
font-size: 9px;
line-height: 1.5;
text-align: center;
}
kbd {
padding: 2px 4px;
color: #4f596b;
background: #ded8c8;
border: 1px solid #aaa594;
box-shadow: 1px 1px 0 #aaa594;
font: inherit;
font-weight: bold;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #101827;
}
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas.dragging {
cursor: grabbing;
}
.scene-header {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
padding: 10px 12px;
color: var(--paper);
background: rgba(15, 23, 38, 0.86);
border: 2px solid #46536a;
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
pointer-events: none;
}
.scene-header span {
display: block;
color: var(--amber);
font-size: 9px;
font-weight: bold;
letter-spacing: 2px;
}
.scene-header strong {
display: block;
margin-top: 4px;
font-size: 13px;
letter-spacing: 1px;
}
.capacity-badge {
position: absolute;
z-index: 3;
top: 18px;
right: 18px;
padding: 10px 12px;
color: #d7deeb;
background: rgba(15, 23, 38, 0.86);
border: 2px solid #46536a;
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
text-align: right;
pointer-events: none;
}
.capacity-badge span {
display: block;
color: #91a0b8;
font-size: 8px;
letter-spacing: 1px;
}
.capacity-badge b {
display: block;
margin-top: 4px;
color: var(--amber);
font-size: 11px;
}
#viewportBanner {
position: absolute;
z-index: 4;
left: 50%;
top: 50%;
min-width: min(440px, 85%);
padding: 17px 20px;
color: var(--paper);
background: rgba(15, 23, 38, 0.94);
border: 4px solid #68758b;
box-shadow: 7px 7px 0 rgba(0, 0, 0, 0.42);
transform: translate(-50%, -50%);
text-align: center;
pointer-events: none;
transition: opacity 180ms ease, border-color 180ms ease;
}
#viewportBanner.hidden {
opacity: 0;
}
#viewportBanner.danger {
border-color: var(--red);
}
#viewportBanner.success {
border-color: var(--green);
}
#viewportBanner.busy {
border-color: var(--amber);
}
.banner-kicker {
display: block;
margin-bottom: 7px;
color: #9ba8be;
font-size: 9px;
letter-spacing: 2px;
text-transform: uppercase;
}
#viewportBanner strong {
display: block;
font-size: clamp(17px, 2.2vw, 25px);
letter-spacing: 1px;
text-transform: uppercase;
}
#viewportBanner p {
margin: 9px 0 0;
color: #c1cad8;
font-size: 10px;
line-height: 1.5;
}
.camera-hint {
position: absolute;
z-index: 3;
right: 16px;
bottom: 14px;
padding: 7px 9px;
color: #a9b4c7;
background: rgba(15, 23, 38, 0.76);
border: 1px solid #3b465c;
font-size: 9px;
letter-spacing: 1px;
pointer-events: none;
}
.world-label {
position: absolute;
z-index: 2;
min-width: 106px;
padding: 6px 8px;
color: var(--paper);
background: rgba(15, 23, 38, 0.9);
border: 2px solid #657188;
box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
font-size: 9px;
font-weight: bold;
line-height: 1.15;
letter-spacing: 1px;
text-align: center;
pointer-events: none;
transform: translate(-50%, -50%);
}
.world-label small {
display: block;
margin-top: 4px;
color: #aab4c5;
font-size: 7px;
letter-spacing: 1px;
}
.world-label.amber {
border-color: var(--amber);
}
.world-label.teal {
border-color: var(--teal);
}
.world-label.green {
border-color: var(--green);
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
min-height: 100vh;
grid-template-rows: 64px auto;
}
.topbar {
position: sticky;
top: 0;
}
.system-status {
display: none;
}
main {
display: flex;
flex-direction: column;
}
#viewport {
order: -1;
height: 58vh;
min-height: 420px;
border-bottom: 4px solid var(--ink);
}
.agreement-panel {
overflow: visible;
border-right: 0;
}
.scene-header,
.capacity-badge {
top: 12px;
}
.scene-header {
left: 12px;
}
.capacity-badge {
right: 12px;
}
}
@media (max-width: 520px) {
.brand small,
.reset-button {
display: none;
}
.topbar {
padding: 10px 12px;
}
#viewport {
min-height: 360px;
height: 52vh;
}
.agreement-panel {
padding: 20px 14px 26px;
}
.actions {
grid-template-columns: 1fr;
}
.capacity-badge {
display: none;
}
.scene-header strong {
font-size: 10px;
}
#viewportBanner {
min-width: 90%;
padding: 13px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div>
<strong>CO-OP PROTOCOL</strong>
<small>ACCESS NEGOTIATION / TABLE 01</small>
</div>
</div>
<div class="top-actions">
<div class="system-status">
<span id="statusDot" class="status-dot"></span>
<span id="systemStatus">POWER BUS READY</span>
</div>
<button id="resetButton" class="reset-button" type="button">Reset table</button>
</div>
</header>
<main>
<aside class="agreement-panel">
<span class="eyebrow">PACT 07 / TWO-PLAYER PUZZLE</span>
<h1>Borrowed<br />Time.</h1>
<p class="intro">
Ada and Bo can finish their modules only if each lends the other
access to the right resource at the right time.
</p>
<div class="objective">
<div class="objective-icon">◆</div>
<div>
<strong>Shared objective: complete the core</strong>
<span>
Ada's module needs Bo's assembly deck. Bo's module needs Ada's
compactor press. Both must reach the goal cradle.
</span>
</div>
</div>
<div class="section-title">
<span>Commitment ledger</span>
<small>BOTH SIGNATURES VALID</small>
</div>
<section class="pact-card amber" aria-label="Ada commitment">
<div class="pact-top">
<div class="player-id">
<div class="avatar" aria-hidden="true"></div>
<div>
<strong>Ada → Bo</strong>
<small>Tool owner / borrower</small>
</div>
</div>
<span class="signed">✓ Signed</span>
</div>
<div class="resource-line">
<span class="resource-icon">P</span>
<span><b>Ada lends the Compactor Press to Bo.</b><br />Bo's cobalt module uses it.</span>
</div>
<div class="slot-label">Bo receives the press at</div>
<div class="slots" data-player="ada">
<button class="slot" type="button" data-slot="0">09:00</button>
<button class="slot selected" type="button" data-slot="1">10:00</button>
<button class="slot" type="button" data-slot="2">11:00</button>
</div>
</section>
<div class="exchange" aria-hidden="true">
<span class="exchange-line"></span>
<strong>↔</strong>
<span class="exchange-line"></span>
</div>
<section class="pact-card teal" aria-label="Bo commitment">
<div class="pact-top">
<div class="player-id">
<div class="avatar" aria-hidden="true"></div>
<div>
<strong>Bo → Ada</strong>
<small>Workspace owner / borrower</small>
</div>
</div>
<span class="signed">✓ Signed</span>
</div>
<div class="resource-line">
<span class="resource-icon">D</span>
<span><b>Bo lends the Assembly Deck to Ada.</b><br />Ada's amber module uses it.</span>
</div>
<div class="slot-label">Ada receives the deck at</div>
<div class="slots" data-player="bo">
<button class="slot" type="button" data-slot="0">09:00</button>
<button class="slot selected" type="button" data-slot="1">10:00</button>
<button class="slot" type="button" data-slot="2">11:00</button>
</div>
</section>
<div class="constraint">
<b>HARDWARE RULE:</b> the bench has one shared power bus. Only one station
may run in a round, even when both commitments are genuine.
</div>
<div class="section-title">
<span>Round plan</span>
<small>ONE STATION PER ROUND</small>
</div>
<div class="timeline">
<div class="timeline-grid">
<div class="label">PRESS</div>
<div class="head">09:00</div>
<div class="head">10:00</div>
<div class="head">11:00</div>
<div id="timelinePress" class="timeline-bar">BO</div>
<div class="label">DECK</div>
<div id="timelineDeck" class="timeline-bar">ADA</div>
<div class="bus-row">
<span>Shared bus capacity</span>
<b>1 / 1</b>
</div>
</div>
</div>
<div class="actions">
<button id="verifyButton" class="action-button primary" type="button">
Verify both commitments
</button>
<button id="conflictButton" class="action-button secondary" type="button">
Force incompatible round
</button>
</div>
<section id="verdict" class="verdict" aria-live="polite">
<div class="verdict-heading">
<span id="verdictIcon" class="verdict-icon">?</span>
<span id="verdictTitle">Pact ready</span>
</div>
<p id="verdictText">
Choose a round for each signed promise. Different rounds satisfy
the one-station power limit.
</p>
<div class="ledger">
<div id="ledgerAda" class="ledger-item">
<b>1</b><span>Ada's tool grant is signed and valid.</span>
</div>
<div id="ledgerBo" class="ledger-item">
<b>2</b><span>Bo's workspace grant is signed and valid.</span>
</div>
<div id="ledgerSchedule" class="ledger-item">
<b>3</b><span>Schedule compatibility has not been tested.</span>
</div>
</div>
<div id="penalty" class="penalty"></div>
</section>
<p class="keyboard-hint">
<kbd>Enter</kbd> verify <kbd>F</kbd> force conflict
<kbd>R</kbd> reset <kbd>Drag</kbd> orbit <kbd>Scroll</kbd> zoom
</p>
</aside>
<section id="viewport" aria-label="Interactive voxel tabletop">
<div class="scene-header">
<span>TABLE 01</span>
<strong>THE BORROWING BENCH</strong>
</div>
<div class="capacity-badge">
<span>SHARED BUS</span>
<b>CAPACITY: 1 STATION</b>
</div>
<div id="viewportBanner" class="hidden">
<span id="bannerKicker" class="banner-kicker">Verification pending</span>
<strong id="bannerTitle">Ready to execute</strong>
<p id="bannerText">Verify the signed commitments to test the schedule.</p>
</div>
<div id="labelPress" class="world-label amber">
COMPACTOR PRESS
<small>OWNER · ADA</small>
</div>
<div id="labelDeck" class="world-label teal">
ASSEMBLY DECK
<small>OWNER · BO</small>
</div>
<div id="labelPower" class="world-label">
SHARED POWER BUS
<small>ONE STATION ONLY</small>
</div>
<div id="labelGoal" class="world-label green">
CORE CRADLE
<small>SHARED OBJECTIVE</small>
</div>
<div class="camera-hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const state = {
adaSlot: 1,
boSlot: 1,
phase: "editing",
attempts: 0,
runId: 0,
animationStart: 0
};
const slotNames = ["09:00", "10:00", "11:00"];
const ui = {
verify: document.getElementById("verifyButton"),
conflict: document.getElementById("conflictButton"),
reset: document.getElementById("resetButton"),
verdict: document.getElementById("verdict"),
verdictIcon: document.getElementById("verdictIcon"),
verdictTitle: document.getElementById("verdictTitle"),
verdictText: document.getElementById("verdictText"),
ledgerAda: document.getElementById("ledgerAda"),
ledgerBo: document.getElementById("ledgerBo"),
ledgerSchedule: document.getElementById("ledgerSchedule"),
penalty: document.getElementById("penalty"),
banner: document.getElementById("viewportBanner"),
bannerKicker: document.getElementById("bannerKicker"),
bannerTitle: document.getElementById("bannerTitle"),
bannerText: document.getElementById("bannerText"),
statusDot: document.getElementById("statusDot"),
systemStatus: document.getElementById("systemStatus"),
timelinePress: document.getElementById("timelinePress"),
timelineDeck: document.getElementById("timelineDeck")
};
// ---------- THREE.JS SCENE ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101827);
scene.fog = new THREE.Fog(0x101827, 17, 31);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc9ddff, 0x293126, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc2, 3.0);
sun.position.set(6, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x6fa9ff, 1.2);
rimLight.position.set(-9, 7, -8);
scene.add(rimLight);
const tableGroup = new THREE.Group();
scene.add(tableGroup);
const materials = {
table: new THREE.MeshStandardMaterial({ color: 0x26344a, roughness: 0.86 }),
tableEdge: new THREE.MeshStandardMaterial({ color: 0x0d1422, roughness: 0.92 }),
dark: new THREE.MeshStandardMaterial({ color: 0x182235, roughness: 0.82 }),
black: new THREE.MeshStandardMaterial({ color: 0x0c121d, roughness: 0.9 }),
cream: new THREE.MeshStandardMaterial({ color: 0xe7dfc6, roughness: 0.8 }),
amber: new THREE.MeshStandardMaterial({ color: 0xf5b942, roughness: 0.68 }),
amberDark: new THREE.MeshStandardMaterial({ color: 0x8a5c20, roughness: 0.8 }),
teal: new THREE.MeshStandardMaterial({ color: 0x50c8bd, roughness: 0.68 }),
tealDark: new THREE.MeshStandardMaterial({ color: 0x24716e, roughness: 0.8 }),
steel: new THREE.MeshStandardMaterial({ color: 0x9eabb7, roughness: 0.62, metalness: 0.35 }),
white: new THREE.MeshStandardMaterial({ color: 0xf6f1df, roughness: 0.72 }),
green: new THREE.MeshStandardMaterial({
color: 0x79cf68,
roughness: 0.45,
emissive: 0x1c661d,
emissiveIntensity: 0.45
}),
red: new THREE.MeshStandardMaterial({
color: 0xef6464,
roughness: 0.5,
emissive: 0x681616,
emissiveIntensity: 0.6
}),
blue: new THREE.MeshStandardMaterial({
color: 0x6398dc,
roughness: 0.55,
emissive: 0x15375f,
emissiveIntensity: 0.35
})
};
function box(width, height, depth, material, x = 0, y = 0, z = 0, parent = scene, edges = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (edges) {
const line = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({ color: 0x0b111b })
);
mesh.add(line);
}
return mesh;
}
// Table and voxel tiled board.
box(18.2, 1.0, 10.8, materials.table, 0, -0.62, 0, tableGroup, true);
box(18.6, 0.22, 11.2, materials.tableEdge, 0, -1.2, 0, tableGroup, true);
const tileGeometry = new THREE.BoxGeometry(0.94, 0.12, 0.94);
const tileColors = [0x33445a, 0x3b4c61, 0x2e3e52, 0x405168];
const tileMaterials = tileColors.map(color =>
new THREE.MeshStandardMaterial({ color, roughness: 0.9 })
);
const columns = 18;
const rows = 10;
const dummy = new THREE.Object3D();
for (let x = 0; x < columns; x++) {
for (let z = 0; z < rows; z++) {
const colorIndex = (x + z * 3) % tileMaterials.length;
const tile = new THREE.Mesh(tileGeometry, tileMaterials[colorIndex]);
tile.position.set(
(x - (columns - 1) / 2) * 0.98,
0.02,
(z - (rows - 1) / 2) * 0.98
);
tile.receiveShadow = true;
tableGroup.add(tile);
}
}
// Table legs.
for (const x of [-7.4, 7.4]) {
for (const z of [-4.3, 4.3]) {
box(1.0, 2.2, 1.0, materials.black, x, -2.25, z, tableGroup, true);
}
}
// Shared power bus tower.
const powerGroup = new THREE.Group();
powerGroup.position.set(0, 0, -3.25);
scene.add(powerGroup);
box(2.4, 0.35, 2.0, materials.dark, 0, 0.3, 0, powerGroup, true);
box(1.65, 0.45, 1.45, materials.steel, 0, 0.7, 0, powerGroup, true);
box(1.0, 1.6, 0.85, materials.dark, 0, 1.55, 0, powerGroup, true);
box(1.45, 0.28, 1.2, materials.cream, 0, 2.48, 0, powerGroup, true);
const powerCrystalMaterial = new THREE.MeshStandardMaterial({
color: 0x73c9ff,
roughness: 0.25,
metalness: 0.15,
emissive: 0x175c8d,
emissiveIntensity: 1.0
});
box(0.72, 0.88, 0.72, powerCrystalMaterial, 0, 1.52, 0, powerGroup, true);
box(0.38, 0.38, 0.38, powerCrystalMaterial, 0, 2.17, 0, powerGroup, true);
const powerCore = powerGroup;
// Floor conduits from the bus.
const conduitMaterial = new THREE.MeshStandardMaterial({
color: 0xd7aa3b,
roughness: 0.8
});
box(4.2, 0.08, 0.22, conduitMaterial, -2.1, 0.13, -2.25, scene);
box(4.2, 0.08, 0.22, conduitMaterial, 2.1, 0.13, -2.25, scene);
box(0.22, 0.08, 3.3, conduitMaterial, -4.15, 0.13, -1.0, scene);
box(0.22, 0.08, 3.3, conduitMaterial, 4.15, 0.13, -1.0, scene);
// Compactor press owned by Ada.
const pressGroup = new THREE.Group();
pressGroup.position.set(-4.2, 0, -0.25);
scene.add(pressGroup);
box(3.2, 0.45, 2.65, materials.dark, 0, 0.33, 0, pressGroup, true);
box(2.9, 0.22, 2.35, materials.amberDark, 0, 0.66, 0, pressGroup, true);
for (const x of [-1.18, 1.18]) {
box(0.36, 2.5, 0.42, materials.steel, x, 1.95, -0.68, pressGroup, true);
box(0.36, 2.5, 0.42, materials.steel, x, 1.95, 0.68, pressGroup, true);
}
box(2.9, 0.55, 2.15, materials.amber, 0, 3.18, 0, pressGroup, true);
box(1.7, 0.5, 1.2, materials.steel, 0, 2.45, 0, pressGroup, true);
box(1.45, 0.28, 1.0, materials.dark, 0, 1.55, 0, pressGroup, true);
box(0.72, 0.62, 0.72, materials.cream, 0, 1.02, 0, pressGroup, true);
const pressLightMaterial = new THREE.MeshBasicMaterial({ color: 0xf5b942 });
box(0.34, 0.25, 0.12, pressLightMaterial, 0.95, 3.18, 1.11, pressGroup);
// Assembly deck owned by Bo.
const deckGroup = new THREE.Group();
deckGroup.position.set(0, 0, -0.25);
scene.add(deckGroup);
box(3.4, 0.4, 2.7, materials.dark, 0, 0.3, 0, deckGroup, true);
box(3.05, 0.25, 2.35, materials.teal, 0, 0.63, 0, deckGroup, true);
for (const x of [-1.1, 1.1]) {
for (const z of [-0.85, 0.85]) {
box(0.28, 0.45, 0.28, materials.tealDark, x, 0.45, z, deckGroup);
}
}
box(2.7, 0.22, 0.35, materials.tealDark, 0, 1.0, -1.04, deckGroup, true);
box(0.24, 0.8, 0.24, materials.steel, -0.8, 1.35, -1.04, deckGroup);
box(0.24, 0.8, 0.24, materials.steel, 0, 1.35, -1.04, deckGroup);
box(0.24, 0.8, 0.24, materials.steel, 0.8, 1.35, -1.04, deckGroup);
const deckLightMaterial = new THREE.MeshBasicMaterial({ color: 0x50c8bd });
box(0.34, 0.25, 0.12, deckLightMaterial, -1.12, 0.69, 1.39, deckGroup);
// Goal cradle.
const goalGroup = new THREE.Group();
goalGroup.position.set(4.65, 0, -0.15);
scene.add(goalGroup);
box(3.1, 0.35, 2.6, materials.dark, 0, 0.28, 0, goalGroup, true);
box(2.6, 0.12, 2.1, materials.green, 0, 0.51, 0, goalGroup, true);
for (const x of [-1.12, 1.12]) {
for (const z of [-0.85, 0.85]) {
box(0.26, 0.72, 0.26, materials.cream, x, 0.78, z, goalGroup, true);
}
}
box(2.48, 0.24, 0.24, materials.cream, 0, 1.13, -0.85, goalGroup, true);
box(2.48, 0.24, 0.24, materials.cream, 0, 1.13, 0.85, goalGroup, true);
// Final shared core, initially hidden.
const finalCore = new THREE.Group();
finalCore.position.set(4.65, 1.04, -0.15);
finalCore.visible = false;
scene.add(finalCore);
box(0.72, 0.78, 0.72, materials.green, 0, 0, 0, finalCore, true);
box(0.46, 0.46, 0.46, materials.green, 0, 0.65, 0, finalCore, true);
box(0.34, 0.34, 0.34, materials.green, 0.47, 0.28, 0, finalCore, true);
box(0.34, 0.34, 0.34, materials.green, -0.47, 0.28, 0, finalCore, true);
function makeRobot(x, z, colorMaterial, darkMaterial) {
const group = new THREE.Group();
group.position.set(x, 0.1, z);
scene.add(group);
box(0.85, 0.26, 0.78, darkMaterial, -0.25, 0.18, 0, group, true);
box(0.85, 0.26, 0.78, darkMaterial, 0.25, 0.18, 0, group, true);
box(0.9, 0.86, 0.58, colorMaterial, 0, 0.76, 0, group, true);
box(0.78, 0.68, 0.65, colorMaterial, 0, 1.48, 0, group, true);
box(0.56, 0.2, 0.08, materials.black, 0, 1.52, -0.35, group);
box(0.11, 0.11, 0.07, materials.white, -0.17, 1.52, -0.41, group);
box(0.11, 0.11, 0.07, materials.white, 0.17, 1.52, -0.41, group);
box(0.12, 0.62, 0.12, darkMaterial, -0.56, 0.82, 0, group);
box(0.12, 0.62, 0.12, darkMaterial, 0.56, 0.82, 0, group);
return group;
}
const adaRobot = makeRobot(-4.2, 2.65, materials.amber, materials.amberDark);
const boRobot = makeRobot(4.25, 2.65, materials.teal, materials.tealDark);
function makeModule(material, accentMaterial) {
const group = new THREE.Group();
box(0.72, 0.62, 0.72, material, 0, 0.34, 0, group, true);
box(0.25, 0.17, 0.25, accentMaterial, -0.18, 0.72, -0.18, group);
box(0.25, 0.17, 0.25, accentMaterial, 0.18, 0.72, 0.18, group);
return group;
}
const amberModule = makeModule(materials.amber, materials.amberDark);
const blueModule = makeModule(materials.blue, materials.steel);
scene.add(amberModule, blueModule);
const moduleStarts = {
amber: new THREE.Vector3(-2.45, 0.12, 1.5),
blue: new THREE.Vector3(2.5, 0.12, 1.5)
};
const moduleStations = {
amber: new THREE.Vector3(0, 0.76, -0.25),
blue: new THREE.Vector3(-4.2, 0.76, -0.25)
};
const moduleGoals = {
amber: new THREE.Vector3(4.15, 0.58, -0.52),
blue: new THREE.Vector3(5.13, 0.58, 0.18)
};
amberModule.position.copy(moduleStarts.amber);
blueModule.position.copy(moduleStarts.blue);
// Voxel spark particles for the incompatible schedule.
const sparks = [];
for (let i = 0; i < 18; i++) {
const spark = box(
0.12 + Math.random() * 0.1,
0.12 + Math.random() * 0.1,
0.12 + Math.random() * 0.1,
i % 2 ? materials.amber : materials.red,
0,
1.8,
-3.25,
scene
);
spark.visible = false;
sparks.push({
mesh: spark,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 4.5,
1.5 + Math.random() * 3.2,
(Math.random() - 0.5) * 4.0
)
});
}
// ---------- CAMERA CONTROLS (IMPLEMENTED DIRECTLY) ----------
const cameraTarget = new THREE.Vector3(0, 0.75, -0.15);
let cameraTheta = 0.58;
let cameraPhi = 0.92;
let cameraRadius = 16.2;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - deltaY * 0.005, 0.48, 1.25);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("pointerleave", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(cameraRadius + event.deltaY * 0.012, 10.5, 23);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
cameraTheta = 0.58;
cameraPhi = 0.92;
cameraRadius = 16.2;
updateCamera();
});
// ---------- PROJECTED LABELS ----------
const labels = [
{
element: document.getElementById("labelPress"),
position: new THREE.Vector3(-4.2, 3.85, -0.25)
},
{
element: document.getElementById("labelDeck"),
position: new THREE.Vector3(0, 2.05, -0.25)
},
{
element: document.getElementById("labelPower"),
position: new THREE.Vector3(0, 3.05, -3.25)
},
{
element: document.getElementById("labelGoal"),
position: new THREE.Vector3(4.65, 2.0, -0.15)
}
];
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// ---------- GAME / VERIFICATION LOGIC ----------
function setLedgerItem(element, type, text) {
element.className = `ledger-item ${type}`;
const badge = element.querySelector("b");
badge.textContent = type === "pass" ? "✓" : type === "fail" ? "×" : "•";
element.querySelector("span").textContent = text;
}
function updateSlotUI() {
document.querySelectorAll(".slots").forEach(container => {
const player = container.dataset.player;
const selectedSlot = player === "ada" ? state.adaSlot : state.boSlot;
container.querySelectorAll(".slot").forEach(button => {
const selected = Number(button.dataset.slot) === selectedSlot;
button.classList.toggle("selected", selected);
button.setAttribute("aria-pressed", String(selected));
});
});
ui.timelinePress.style.gridColumn = String(state.adaSlot + 2);
ui.timelineDeck.style.gridColumn = String(state.boSlot + 2);
}
function setStatus(kind, text) {
ui.statusDot.className = `status-dot ${kind}`;
ui.systemStatus.textContent = text;
}
function showBanner(kind, kicker, title, text) {
ui.banner.className = kind;
ui.bannerKicker.textContent = kicker;
ui.bannerTitle.textContent = title;
ui.bannerText.textContent = text;
}
function hideBanner() {
ui.banner.className = "hidden";
}
function setVerdict(kind, icon, title, text) {
ui.verdict.className = `verdict ${kind}`;
ui.verdictIcon.textContent = icon;
ui.verdictTitle.textContent = title;
ui.verdictText.textContent = text;
}
function resetTable() {
state.runId++;
state.phase = "editing";
state.adaSlot = 1;
state.boSlot = 1;
amberModule.position.copy(moduleStarts.amber);
blueModule.position.copy(moduleStarts.blue);
amberModule.rotation.set(0, 0, 0);
blueModule.rotation.set(0, 0, 0);
amberModule.scale.setScalar(1);
blueModule.scale.setScalar(1);
finalCore.visible = false;
finalCore.scale.setScalar(0.01);
for (const spark of sparks) spark.mesh.visible = false;
pressLightMaterial.color.setHex(0xf5b942);
deckLightMaterial.color.setHex(0x50c8bd);
powerCrystalMaterial.color.setHex(0x73c9ff);
powerCrystalMaterial.emissive.setHex(0x175c8d);
powerCrystalMaterial.emissiveIntensity = 1.0;
ui.penalty.classList.remove("visible");
setLedgerItem(ui.ledgerAda, "", "Ada's tool grant is signed and valid.");
setLedgerItem(ui.ledgerBo, "", "Bo's workspace grant is signed and valid.");
setLedgerItem(ui.ledgerSchedule, "", "Schedule compatibility has not been tested.");
setVerdict(
"neutral",
"?",
"Pact ready",
"Choose a round for each signed promise. Different rounds satisfy the one-station power limit."
);
setStatus("", "POWER BUS READY");
hideBanner();
updateSlotUI();
}
function verifyPact() {
const runId = ++state.runId;
state.phase = "checking";
state.attempts++;
ui.verify.disabled = true;
ui.conflict.disabled = true;
setStatus("busy", "VERIFYING COMMITMENTS");
setVerdict(
"busy",
"…",
"Checking both signatures",
"The verifier is checking resource ownership, borrower access, and the shared-bus schedule."
);
setLedgerItem(ui.ledgerAda, "", "Checking Ada's tool grant…");
setLedgerItem(ui.ledgerBo, "", "Checking Bo's workspace grant…");
setLedgerItem(ui.ledgerSchedule, "", "Checking shared-bus capacity…");
showBanner(
"busy",
"Verifier running",
"Checking commitments",
"Both signatures are valid. Testing whether the promised rounds can coexist."
);
window.setTimeout(() => {
if (runId !== state.runId) return;
setLedgerItem(
ui.ledgerAda,
"pass",
`Ada's grant is valid: Bo receives the press at ${slotNames[state.adaSlot]}.`
);
setLedgerItem(
ui.ledgerBo,
"pass",
`Bo's grant is valid: Ada receives the deck at ${slotNames[state.boSlot]}.`
);
if (state.adaSlot === state.boSlot) {
state.phase = "conflict";
setLedgerItem(
ui.ledgerSchedule,
"fail",
`Both grants request the single power bus at ${slotNames[state.adaSlot]}.`
);
setVerdict(
"danger",
"×",
"Commitments incompatible",
"Both promises are genuine, but the shared bus cannot power the press and deck at the same time."
);
ui.penalty.textContent = "CONSEQUENCE: bus overload, both tasks abort, +1 round lost.";
ui.penalty.classList.add("visible");
setStatus("danger", "POWER BUS OVERLOAD");
showBanner(
"danger",
"Execution rejected",
"Shared bus overloaded",
`Both modules enter at ${slotNames[state.adaSlot]}. The bus trips, sparks fly, and both jobs return to their trays.`
);
} else {
state.phase = "success";
setLedgerItem(
ui.ledgerSchedule,
"pass",
`The stations run in separate rounds (${slotNames[state.adaSlot]} and ${slotNames[state.boSlot]}).`
);
setVerdict(
"success",
"✓",
"Compatible pact verified",
"Both commitments are valid and the schedule respects the shared power limit. The cooperative core can be completed."
);
ui.penalty.textContent = "RESULT: no penalty. Both modules complete and the shared core activates.";
ui.penalty.classList.remove("visible");
setStatus("", "CO-OP LINK STABLE");
showBanner(
"success",
"Pact verified",
"Cooperative execution",
"Each player receives the promised resource in a separate round. Both modules are moving toward the core cradle."
);
}
state.animationStart = performance.now();
ui.verify.disabled = false;
ui.conflict.disabled = false;
}, 650);
}
document.querySelectorAll(".slots").forEach(container => {
container.addEventListener("click", event => {
const button = event.target.closest(".slot");
if (!button) return;
const slot = Number(button.dataset.slot);
if (container.dataset.player === "ada") state.adaSlot = slot;
else state.boSlot = slot;
state.runId++;
state.phase = "editing";
amberModule.position.copy(moduleStarts.amber);
blueModule.position.copy(moduleStarts.blue);
finalCore.visible = false;
finalCore.scale.setScalar(0.01);
pressLightMaterial.color.setHex(0xf5b942);
deckLightMaterial.color.setHex(0x50c8bd);
powerCrystalMaterial.color.setHex(0x73c9ff);
powerCrystalMaterial.emissive.setHex(0x175c8d);
ui.penalty.classList.remove("visible");
setLedgerItem(ui.ledgerAda, "", "Ada's tool grant is signed and valid.");
setLedgerItem(ui.ledgerBo, "", "Bo's workspace grant is signed and valid.");
setLedgerItem(ui.ledgerSchedule, "", "Schedule compatibility has not been tested.");
setVerdict(
"neutral",
"?",
"Pact ready",
"The schedule changed. Verify both commitments to test the new round plan."
);
setStatus("", "POWER BUS READY");
hideBanner();
updateSlotUI();
});
});
ui.verify.addEventListener("click", verifyPact);
ui.conflict.addEventListener("click", () => {
state.adaSlot = 1;
state.boSlot = 1;
updateSlotUI();
verifyPact();
});
ui.reset.addEventListener("click", resetTable);
window.addEventListener("keydown", event => {
if (event.key === "Enter") {
event.preventDefault();
verifyPact();
} else if (event.key.toLowerCase() === "f") {
ui.conflict.click();
} else if (event.key.toLowerCase() === "r") {
resetTable();
}
});
// ---------- TABLE ANIMATION ----------
const easeInOut = value =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
function updateAnimation(now) {
if (state.phase === "conflict") {
const elapsed = (now - state.animationStart) / 1000;
const amberTravel = THREE.MathUtils.clamp(elapsed / 0.58, 0, 1);
const blueTravel = THREE.MathUtils.clamp(elapsed / 0.58, 0, 1);
const amberOut = easeInOut(amberTravel);
const blueOut = easeInOut(blueTravel);
const returnAmount = elapsed < 0.65
? 0
: easeInOut(THREE.MathUtils.clamp((elapsed - 0.65) / 0.75, 0, 1));
amberModule.position.lerpVectors(
moduleStarts.amber,
moduleStations.amber,
amberOut * (1 - returnAmount)
);
blueModule.position.lerpVectors(
moduleStarts.blue,
moduleStations.blue,
blueOut * (1 - returnAmount)
);
const shake = elapsed > 0.43 && elapsed < 0.82;
amberModule.rotation.z = shake ? Math.sin(elapsed * 58) * 0.15 : 0;
blueModule.rotation.z = shake ? Math.sin(elapsed * 63 + 1) * 0.15 : 0;
pressLightMaterial.color.setHex(0xef6464);
deckLightMaterial.color.setHex(0xef6464);
powerCrystalMaterial.color.setHex(0xef6464);
powerCrystalMaterial.emissive.setHex(0xa11919);
powerCrystalMaterial.emissiveIntensity = 1.7;
for (const spark of sparks) {
if (elapsed > 0.42 && elapsed < 1.05) {
spark.mesh.visible = true;
const t = elapsed - 0.42;
spark.mesh.position.set(
spark.velocity.x * t,
1.8 + spark.velocity.y * t - 4.8 * t * t,
-3.25 + spark.velocity.z * t
);
spark.mesh.rotation.x = t * 8;
spark.mesh.rotation.y = t * 11;
} else {
spark.mesh.visible = false;
}
}
if (elapsed > 1.5) {
amberModule.position.copy(moduleStarts.amber);
blueModule.position.copy(moduleStarts.blue);
amberModule.rotation.z = 0;
blueModule.rotation.z = 0;
pressLightMaterial.color.setHex(0xef6464);
deckLightMaterial.color.setHex(0xef6464);
}
}
if (state.phase === "success") {
const elapsed = (now - state.animationStart) / 1000;
const tasks = [
{
key: "amber",
offset: state.boSlot < state.adaSlot ? 0 : 1.15,
module: amberModule,
station: moduleStations.amber,
goal: moduleGoals.amber
},
{
key: "blue",
offset: state.boSlot < state.adaSlot ? 1.15 : 0,
module: blueModule,
station: moduleStations.blue,
goal: moduleGoals.blue
}
];
for (const task of tasks) {
const t = elapsed - task.offset;
if (t < 0.9) {
const p = easeInOut(THREE.MathUtils.clamp(t / 0.9, 0, 1));
task.module.position.lerpVectors(moduleStarts[task.key], task.station, p);
} else if (t < 1.65) {
task.module.position.copy(task.station);
} else if (t < 2.75) {
const p = easeInOut(THREE.MathUtils.clamp((t - 1.65) / 1.1, 0, 1));
task.module.position.lerpVectors(task.station, task.goal, p);
} else {
task.module.position.copy(task.goal);
}
}
const earlyTask = state.boSlot < state.adaSlot ? "amber" : "blue";
if (elapsed < 1.45) {
pressLightMaterial.color.setHex(earlyTask === "blue" ? 0x79cf68 : 0xf5b942);
deckLightMaterial.color.setHex(earlyTask === "amber" ? 0x79cf68 : 0x50c8bd);
} else {
pressLightMaterial.color.setHex(0x79cf68);
deckLightMaterial.color.setHex(0x79cf68);
}
powerCrystalMaterial.color.setHex(0x79cf68);
powerCrystalMaterial.emissive.setHex(0x267d23);
powerCrystalMaterial.emissiveIntensity = 1.35;
if (elapsed > 3.25) {
finalCore.visible = true;
const scale = easeInOut(
THREE.MathUtils.clamp((elapsed - 3.25) / 0.65, 0, 1)
);
finalCore.scale.setScalar(Math.max(0.01, scale));
finalCore.rotation.y = (elapsed - 3.25) * 0.6;
}
}
}
// ---------- RESIZE AND RENDER LOOP ----------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(viewport);
resize();
updateCamera();
updateSlotUI();
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
adaRobot.position.y = 0.1 + Math.sin(time * 2.1) * 0.025;
boRobot.position.y = 0.1 + Math.sin(time * 2.1 + 1.5) * 0.025;
if (state.phase !== "conflict" && state.phase !== "success") {
powerCrystalMaterial.emissiveIntensity = 1.0 + Math.sin(time * 3) * 0.18;
} else if (state.phase === "success") {
powerCrystalMaterial.emissiveIntensity = 1.35 + Math.sin(time * 5) * 0.18;
}
updateAnimation(now);
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```