Prompt specification
Build or customize the Three.js 3D scene "Inventor Village Progression Game" 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: Inventor Village Progression Game
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inventor-village-progression-game-x3583
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring technology prerequisites and unlockable skills. Build an original fictional village unlocking irrigation, storage, and transport upgrades. Label the dependency tree as a game abstraction rather than an accurate history of invention. Voxel style.
Working Three.js Starter (inventor-village-progression-game-x3583):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mossbell Hamlet — Voxel Technology Tree</title>
<style>
:root {
--panel-width: 405px;
--ink: #17312d;
--muted: #61716b;
--paper: rgba(248, 244, 224, 0.94);
--paper-solid: #f8f4e0;
--line: rgba(34, 65, 55, 0.16);
--water: #2c9eaa;
--water-soft: #d9f0ed;
--storage: #c98435;
--storage-soft: #f6e5c9;
--transport: #bd5d50;
--transport-soft: #f4d9d1;
--leaf: #4e8158;
--gold: #dfac45;
--shadow: 0 18px 50px rgba(24, 52, 45, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d9d2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.glass {
border: 1px solid rgba(255, 255, 255, 0.62);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px) saturate(1.1);
-webkit-backdrop-filter: blur(14px) saturate(1.1);
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.brand {
position: absolute;
top: 18px;
left: 18px;
width: 340px;
padding: 17px 19px 15px;
border-radius: 19px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
color: var(--leaf);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
content: "";
border-radius: 2px;
background: var(--leaf);
transform: rotate(45deg);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 30px;
font-weight: 700;
line-height: 1;
letter-spacing: -0.035em;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#resourceDock {
position: absolute;
top: 145px;
left: 18px;
display: grid;
grid-template-columns: repeat(2, minmax(112px, 1fr));
gap: 7px;
width: 340px;
padding: 8px;
border-radius: 16px;
}
.resource {
display: flex;
align-items: center;
gap: 8px;
min-height: 38px;
padding: 7px 9px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.45);
}
.resource-icon {
display: grid;
width: 25px;
height: 25px;
flex: 0 0 auto;
place-items: center;
border-radius: 7px;
color: white;
font-size: 13px;
font-weight: 900;
}
.resource.timber .resource-icon { background: #8a603d; }
.resource.stone .resource-icon { background: #798781; }
.resource.roots .resource-icon { background: #5f8b56; }
.resource.insight .resource-icon { background: #7c66a5; }
.resource-copy {
display: flex;
min-width: 0;
flex-direction: column;
line-height: 1.1;
}
.resource-copy span {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.resource-copy strong {
margin-top: 3px;
font-size: 15px;
}
#objective {
position: absolute;
bottom: 18px;
left: 18px;
width: 340px;
padding: 14px 16px;
border-radius: 16px;
}
#objective strong {
display: block;
margin-bottom: 5px;
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#objective p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#controlsHint {
position: absolute;
bottom: 19px;
left: 375px;
padding: 8px 11px;
border-radius: 10px;
color: rgba(23, 49, 45, 0.78);
background: rgba(248, 244, 224, 0.76);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#treePanel {
position: fixed;
z-index: 5;
top: 16px;
right: 16px;
bottom: 16px;
display: flex;
width: var(--panel-width);
flex-direction: column;
overflow: hidden;
border-radius: 23px;
transition: transform 220ms ease;
}
.panel-head {
padding: 20px 20px 15px;
border-bottom: 1px solid var(--line);
}
.panel-title-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.panel-title-row h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
letter-spacing: -0.025em;
}
.panel-title-row p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.reset-button {
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--muted);
background: rgba(255, 255, 255, 0.48);
cursor: pointer;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.reset-button:hover {
color: var(--ink);
background: white;
}
.disclaimer {
margin: 14px 0 0;
padding: 10px 11px;
border-left: 3px solid var(--gold);
border-radius: 4px 9px 9px 4px;
color: #5d563d;
background: rgba(223, 172, 69, 0.13);
font-size: 10px;
line-height: 1.48;
}
.disclaimer strong {
color: #453f29;
}
.progress-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 14px;
}
.progress-track {
height: 7px;
flex: 1;
overflow: hidden;
border-radius: 99px;
background: rgba(32, 68, 57, 0.1);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--water), var(--leaf), var(--storage));
transition: width 300ms ease;
}
#progressText {
min-width: 55px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
text-align: right;
}
#gatherButton {
width: 100%;
margin-top: 12px;
padding: 10px 12px;
border: 0;
border-radius: 10px;
color: white;
background: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 850;
transition: transform 120ms ease, opacity 120ms ease;
}
#gatherButton:hover:not(:disabled) {
transform: translateY(-1px);
}
#gatherButton:disabled {
cursor: default;
opacity: 0.5;
}
#treeScroll {
flex: 1;
overflow-y: auto;
padding: 15px 14px 24px;
scrollbar-width: thin;
scrollbar-color: rgba(35, 72, 61, 0.25) transparent;
}
.branch {
margin-bottom: 19px;
padding: 0 5px;
}
.branch-heading {
display: flex;
align-items: center;
gap: 9px;
margin: 0 0 10px 3px;
}
.branch-mark {
width: 11px;
height: 11px;
border-radius: 3px;
transform: rotate(45deg);
}
.branch.water .branch-mark { background: var(--water); }
.branch.storage .branch-mark { background: var(--storage); }
.branch.transport .branch-mark { background: var(--transport); }
.branch-heading h3 {
margin: 0;
font-size: 11px;
font-weight: 950;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.branch-heading span:last-child {
margin-left: auto;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.nodes {
position: relative;
}
.nodes::before {
position: absolute;
top: 15px;
bottom: 16px;
left: 8px;
width: 2px;
content: "";
border-radius: 2px;
background: rgba(34, 65, 55, 0.12);
}
.skill-node {
position: relative;
display: block;
width: 100%;
margin: 0 0 9px 23px;
padding: 11px 12px 10px;
border: 1px solid var(--line);
border-radius: 13px;
color: var(--ink);
background: rgba(255, 255, 255, 0.58);
cursor: pointer;
text-align: left;
transition: border-color 140ms ease, transform 140ms ease, background 140ms ease,
box-shadow 140ms ease;
}
.skill-node::before {
position: absolute;
top: 19px;
left: -20px;
width: 13px;
height: 13px;
content: "";
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: #a9b1aa;
box-shadow: 0 0 0 1px rgba(34, 65, 55, 0.16);
}
.skill-node:hover {
z-index: 1;
border-color: rgba(34, 65, 55, 0.38);
background: rgba(255, 255, 255, 0.9);
transform: translateX(2px);
}
.skill-node.ready {
border-color: rgba(78, 129, 88, 0.56);
background: rgba(239, 247, 228, 0.9);
box-shadow: 0 6px 18px rgba(52, 94, 63, 0.08);
}
.skill-node.ready::before {
background: var(--leaf);
}
.skill-node.unlocked {
border-color: rgba(44, 158, 170, 0.55);
background: rgba(223, 244, 240, 0.86);
}
.skill-node.unlocked::before {
background: var(--water);
box-shadow: 0 0 0 1px rgba(44, 158, 170, 0.3), 0 0 0 5px rgba(44, 158, 170, 0.09);
}
.skill-node.locked {
opacity: 0.66;
}
.node-heading {
display: flex;
align-items: center;
gap: 9px;
}
.node-icon {
display: grid;
width: 28px;
height: 28px;
flex: 0 0 auto;
place-items: center;
border-radius: 8px;
background: rgba(34, 65, 55, 0.08);
font-size: 15px;
}
.node-name {
min-width: 0;
flex: 1;
}
.node-name strong {
display: block;
font-size: 12px;
line-height: 1.25;
}
.node-name small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.node-state {
padding: 4px 6px;
border-radius: 6px;
color: var(--muted);
background: rgba(34, 65, 55, 0.07);
font-size: 8px;
font-weight: 950;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.ready .node-state {
color: #3e6845;
background: rgba(78, 129, 88, 0.13);
}
.unlocked .node-state {
color: #1f737e;
background: rgba(44, 158, 170, 0.14);
}
.node-description {
margin: 8px 0 7px;
color: #52645e;
font-size: 10px;
line-height: 1.42;
}
.prereq-line,
.cost-line {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 5px;
}
.prereq-line {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
}
.prereq-label {
font-weight: 800;
}
.prereq-chip {
padding: 3px 5px;
border-radius: 5px;
color: #53615d;
background: rgba(34, 65, 55, 0.07);
font-size: 8px;
font-weight: 800;
}
.prereq-chip.done {
color: #397047;
background: rgba(78, 129, 88, 0.12);
}
.cost {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 4px 6px;
border-radius: 6px;
color: #425d54;
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(34, 65, 55, 0.08);
font-size: 9px;
font-weight: 900;
}
.cost.short {
color: #a54538;
background: rgba(189, 93, 80, 0.1);
border-color: rgba(189, 93, 80, 0.18);
}
#inspector {
position: fixed;
z-index: 4;
right: calc(var(--panel-width) + 32px);
bottom: 18px;
width: 290px;
padding: 14px 15px;
border-radius: 16px;
opacity: 0;
pointer-events: none;
transform: translateY(10px);
transition: opacity 180ms ease, transform 180ms ease;
}
#inspector.visible {
opacity: 1;
pointer-events: auto;
transform: translateY(0);
}
#inspector h3 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
}
#inspector p {
margin: 0 0 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
#focusButton {
padding: 8px 10px;
border: 0;
border-radius: 8px;
color: white;
background: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#toastStack {
position: fixed;
z-index: 20;
top: 24px;
left: 50%;
display: flex;
width: min(390px, calc(100vw - 32px));
flex-direction: column;
gap: 8px;
pointer-events: none;
transform: translateX(-50%);
}
.toast {
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 13px;
color: white;
background: rgba(23, 49, 45, 0.94);
box-shadow: 0 12px 35px rgba(23, 49, 45, 0.24);
font-size: 11px;
font-weight: 750;
line-height: 1.4;
animation: toastIn 200ms ease both;
}
.toast.warning {
color: #493e28;
background: rgba(255, 235, 184, 0.97);
}
@keyframes toastIn {
from { opacity: 0; transform: translateY(-8px); }
to { opacity: 1; transform: translateY(0); }
}
#panelToggle {
position: fixed;
z-index: 10;
top: 16px;
right: 16px;
display: none;
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
color: white;
background: var(--ink);
box-shadow: var(--shadow);
cursor: pointer;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #b8d9d2;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-mark {
text-align: center;
}
.loading-cubes {
display: flex;
justify-content: center;
gap: 6px;
margin-bottom: 14px;
}
.loading-cubes i {
width: 13px;
height: 13px;
border-radius: 3px;
background: var(--leaf);
animation: hop 900ms ease-in-out infinite alternate;
}
.loading-cubes i:nth-child(2) { animation-delay: 150ms; background: var(--water); }
.loading-cubes i:nth-child(3) { animation-delay: 300ms; background: var(--storage); }
@keyframes hop {
to { transform: translateY(-9px) rotate(45deg); }
}
@media (max-width: 900px) {
:root {
--panel-width: min(390px, 92vw);
}
#treePanel {
transform: translateX(calc(100% + 24px));
}
#treePanel.open {
transform: translateX(0);
}
#panelToggle {
display: block;
}
#inspector {
right: 16px;
bottom: 16px;
}
}
@media (max-width: 620px) {
.brand {
top: 10px;
left: 10px;
width: calc(100vw - 86px);
padding: 13px 14px;
}
.brand h1 {
font-size: 23px;
}
.brand p {
font-size: 10px;
}
#resourceDock {
top: 112px;
left: 10px;
width: calc(100vw - 20px);
grid-template-columns: repeat(4, 1fr);
}
.resource {
min-height: 36px;
padding: 5px;
}
.resource-icon {
width: 22px;
height: 22px;
}
.resource-copy span {
display: none;
}
.resource-copy strong {
margin: 0;
font-size: 13px;
}
#objective,
#controlsHint {
display: none;
}
#inspector {
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
}
#toastStack {
top: 160px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="hud">
<section class="brand glass">
<div class="eyebrow">Fictional voxel settlement</div>
<h1>Mossbell Hamlet</h1>
<p>The Fen of Nine Lamps · A living settlement built one clever skill at a time.</p>
</section>
<section id="resourceDock" class="glass" aria-label="Settlement resources">
<div class="resource timber">
<div class="resource-icon">▰</div>
<div class="resource-copy"><span>Timber</span><strong id="res-timber">0</strong></div>
</div>
<div class="resource stone">
<div class="resource-icon">◆</div>
<div class="resource-copy"><span>Stone</span><strong id="res-stone">0</strong></div>
</div>
<div class="resource roots">
<div class="resource-icon">✦</div>
<div class="resource-copy"><span>Sunroot</span><strong id="res-roots">0</strong></div>
</div>
<div class="resource insight">
<div class="resource-icon">◈</div>
<div class="resource-copy"><span>Insight</span><strong id="res-insight">0</strong></div>
</div>
</section>
<section id="objective" class="glass">
<strong>Hamlet directive</strong>
<p>Select a skill in the lattice to unlock it. Click glowing sites in the village to inspect them.</p>
</section>
<div id="controlsHint">Drag orbit · Right-drag pan · Wheel zoom</div>
</div>
<button id="panelToggle" aria-expanded="false">Skills</button>
<aside id="treePanel" class="glass" aria-label="Technology skill tree">
<header class="panel-head">
<div class="panel-title-row">
<div>
<h2>Technology lattice</h2>
<p>Prerequisites & unlockable settlement skills</p>
</div>
<button id="resetButton" class="reset-button">Reset</button>
</div>
<p class="disclaimer">
<strong>Game abstraction.</strong> This dependency tree is a gameplay design,
<strong>not an accurate history of invention</strong>. Mossbell and its technologies are fictional.
</p>
<div class="progress-row">
<div class="progress-track"><div id="progressFill"></div></div>
<div id="progressText">0 / 10</div>
</div>
<button id="gatherButton">Gather district yield · +6 timber, +4 stone, +4 root, +2 insight</button>
</header>
<div id="treeScroll">
<section class="branch water">
<div class="branch-heading">
<i class="branch-mark"></i>
<h3>Waterworks</h3>
<span>IRRIGATION</span>
</div>
<div id="waterNodes" class="nodes"></div>
</section>
<section class="branch storage">
<div class="branch-heading">
<i class="branch-mark"></i>
<h3>Granary</h3>
<span>STORAGE</span>
</div>
<div id="storageNodes" class="nodes"></div>
</section>
<section class="branch transport">
<div class="branch-heading">
<i class="branch-mark"></i>
<h3>Roadwardens</h3>
<span>TRANSPORT</span>
</div>
<div id="transportNodes" class="nodes"></div>
</section>
</div>
</aside>
<section id="inspector" class="glass" aria-live="polite">
<h3 id="inspectorTitle"></h3>
<p id="inspectorText"></p>
<button id="focusButton">Focus site</button>
</section>
<div id="toastStack" aria-live="polite"></div>
<div id="loading">
<div class="loading-mark">
<div class="loading-cubes"><i></i><i></i><i></i></div>
<strong>Growing Mossbell…</strong>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and game definitions
// -------------------------------------------------------------------------
const RESOURCE_META = {
timber: { icon: "▰", label: "Timber" },
stone: { icon: "◆", label: "Stone" },
roots: { icon: "✦", label: "Sunroot" },
insight: { icon: "◈", label: "Insight" }
};
const skills = {
waterMap: {
branch: "water",
name: "Water Map",
tag: "Surveying",
icon: "⌖",
description: "Mark the fen's seasonal flow and identify safe channel routes.",
cost: { insight: 2 },
prereq: [],
effects: ["waterMap"],
location: new THREE.Vector3(-11.5, 0, 2),
siteTitle: "Water Map stakes",
siteText: "Survey stakes reveal where the fen's blue ribbons can safely be redirected."
},
reedChannels: {
branch: "water",
name: "Reed Channels",
tag: "Irrigation",
icon: "≋",
description: "Build shallow reed-lined channels that carry water into Mossbell's plots.",
cost: { timber: 8, stone: 4 },
prereq: ["waterMap"],
effects: ["reedChannels"],
location: new THREE.Vector3(-7.5, 0, -5),
siteTitle: "Reed irrigation",
siteText: "Blue voxel channels now feed the soil beds, making crop rows possible."
},
rainVault: {
branch: "water",
name: "Rain Vault",
tag: "Water storage",
icon: "▣",
description: "Stack blue ceramic tanks that keep rainy-day water above the muddy ground.",
cost: { timber: 5, roots: 6 },
prereq: ["waterMap"],
effects: ["rainVault"],
location: new THREE.Vector3(-10, 0, -1),
siteTitle: "Rain Vault",
siteText: "A raised tank stores fen water for dry spells and thirsty root crops."
},
sunliftPumps: {
branch: "water",
name: "Sunlift Pumps",
tag: "Fiction mechanism",
icon: "☼",
description: "Use polished sunstones to lift water through a fictional wind-and-sun mechanism.",
cost: { stone: 8, insight: 4 },
prereq: ["reedChannels", "rainVault"],
effects: ["sunliftPumps"],
location: new THREE.Vector3(-9.8, 0, -6),
siteTitle: "Sunlift mechanism",
siteText: "The glowing sunstone wheel powers a decorative water-lifting contraption."
},
dryFrames: {
branch: "storage",
name: "Dry Frames",
tag: "Foundations",
icon: "⌗",
description: "Raise simple timber frames to keep sacks away from damp floorboards.",
cost: { timber: 5 },
prereq: [],
effects: ["dryFrames"],
location: new THREE.Vector3(6.4, 0, -5.7),
siteTitle: "Dry storage frame",
siteText: "A raised timber frame creates the first protected storage platform."
},
grainBaskets: {
branch: "storage",
name: "Grain Baskets",
tag: "Food storage",
icon: "▤",
description: "Weave broad baskets for grain, roots, and the hamlet's famously blue pears.",
cost: { timber: 6, roots: 5 },
prereq: ["dryFrames", "reedChannels"],
effects: ["grainBaskets"],
location: new THREE.Vector3(7, 0, -5.4),
siteTitle: "Grain baskets",
siteText: "Woven baskets hold the first harvest, using timber and cultivated sunroot fiber."
},
raisedSilos: {
branch: "storage",
name: "Raised Silos",
tag: "Capacity",
icon: "▥",
description: "Build tall stone-and-timber silos with cool ventilation chambers.",
cost: { stone: 10, timber: 5 },
prereq: ["grainBaskets"],
effects: ["raisedSilos"],
location: new THREE.Vector3(7.8, 0, -7.2),
siteTitle: "Raised silos",
siteText: "Twin silos substantially increase Mossbell's dry food capacity."
},
packRacks: {
branch: "transport",
name: "Pack Racks",
tag: "Preparation",
icon: "▰",
description: "Standardize backpack frames so couriers can carry more consistent loads.",
cost: { timber: 6, roots: 3 },
prereq: [],
effects: ["packRacks"],
location: new THREE.Vector3(4.5, 0, 6),
siteTitle: "Courier pack racks",
siteText: "Standard pack frames prepare Mossbell's couriers for longer journeys."
},
wheeledCart: {
branch: "transport",
name: "Wheeled Cart",
tag: "Freight",
icon: "◉",
description: "Build a broad wooden cart that can haul several baskets at once.",
cost: { timber: 8, stone: 6 },
prereq: ["packRacks"],
effects: ["wheeledCart"],
location: new THREE.Vector3(5.6, 0, 7.4),
siteTitle: "Wheeled freight cart",
siteText: "A chunky voxel cart now moves supplies between the granary and north road."
},
routeGuild: {
branch: "transport",
name: "Route Guild",
tag: "Network",
icon: "✣",
description: "Establish shared road markers and a courier network between neighboring groves.",
cost: { roots: 8, insight: 3 },
prereq: ["raisedSilos", "wheeledCart"],
effects: ["routeGuild"],
location: new THREE.Vector3(9, 0, 7.7),
siteTitle: "Route Guild marker",
siteText: "Road banners announce Mossbell's new courier network to neighboring settlements."
}
};
const DEFAULT_RESOURCES = {
timber: 32,
stone: 24,
roots: 20,
insight: 12
};
const STORAGE_KEY = "mossbell-hamlet-v1";
let state = {
unlocked: [],
resources: { ...DEFAULT_RESOURCES }
};
try {
const saved = JSON.parse(localStorage.getItem(STORAGE_KEY));
if (saved && Array.isArray(saved.unlocked) && saved.resources) {
state.unlocked = saved.unlocked.filter((id) => skills[id]);
state.resources = { ...DEFAULT_RESOURCES };
for (const key of Object.keys(DEFAULT_RESOURCES)) {
const value = Number(saved.resources[key]);
if (Number.isFinite(value) && value >= 0) {
state.resources[key] = Math.floor(value);
}
}
}
} catch (error) {
console.warn("Could not load saved progress.", error);
}
function saveState() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
} catch (error) {
console.warn("Could not save progress.", error);
}
}
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d9d2);
scene.fog = new THREE.Fog(0xb8d9d2, 52, 94);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-20, 20, 13.5, -13.5, 0.1, 180);
const cameraTarget = new THREE.Vector3(-1.5, 0, 0.5);
let cameraTheta = 0.72;
let cameraPhi = 0.88;
let cameraRadius = 58;
let desiredZoom = 0.92;
const hemisphere = new THREE.HemisphereLight(0xe8fff4, 0x526b53, 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff0c8, 3.2);
sunlight.position.set(-20, 32, 18);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -28;
sunlight.shadow.camera.right = 28;
sunlight.shadow.camera.top = 28;
sunlight.shadow.camera.bottom = -28;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 80;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0x9ed9e6, 0.75);
fillLight.position.set(22, 12, -18);
scene.add(fillLight);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = JSON.stringify([color, options]);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const material = color?.isMaterial
? color
: getMaterial(color, options.material || {});
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addWireBox(parent, size, position, color) {
const material = new THREE.MeshBasicMaterial({
color,
wireframe: true,
transparent: true,
opacity: 0.42
});
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Village terrain and architecture
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
addBox(world, [32, 2, 28], [0, -1.1, 0], 0x685443, { receiveShadow: true });
addBox(world, [31.6, 0.45, 27.6], [0, -0.2, 0], 0x6f8d58, { receiveShadow: true });
let randomSeed = 73129;
function seededRandom() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const grassColors = [0x779b62, 0x7fa568, 0x6f915b, 0x86aa6b, 0x759b60];
for (let x = -14; x <= 14; x += 2) {
for (let z = -12; z <= 12; z += 2) {
if (x < -10.8) continue;
const color = grassColors[Math.floor(seededRandom() * grassColors.length)];
addBox(
world,
[1.93, 0.12, 1.93],
[x, 0.08 + seededRandom() * 0.025, z],
color,
{ castShadow: false }
);
}
}
// River and blocky banks.
const waterMaterial = getMaterial(0x4aa5a5, {
roughness: 0.28,
metalness: 0.05,
transparent: true,
opacity: 0.91
});
addBox(world, [3.6, 0.22, 27], [-14, 0.16, 0], waterMaterial, { castShadow: false });
addBox(world, [0.8, 0.42, 27], [-11.95, 0.3, 0], 0x789075, { castShadow: false });
for (let z = -11; z <= 11; z += 3) {
addBox(world, [0.7, 0.25, 0.8], [-12.1, 0.56, z], 0x95a08a);
}
// Main paths.
for (let z = -11; z <= 11; z += 1.45) {
addBox(world, [2.2, 0.12, 1.38], [1, 0.19, z], 0xc4ae78, { castShadow: false });
}
for (let x = -8; x <= 10; x += 1.45) {
addBox(world, [1.38, 0.12, 2.1], [x, 0.2, 2.5], 0xc4ae78, { castShadow: false });
}
// Farm soil beds.
const farm = new THREE.Group();
world.add(farm);
addBox(farm, [6.6, 0.28, 5.3], [-7, 0.27, -5.1], 0x72503a, { castShadow: false });
for (let row = 0; row < 4; row++) {
addBox(
farm,
[5.7, 0.18, 0.5],
[-7, 0.49, -6.85 + row * 1.12],
0x594432,
{ castShadow: false }
);
}
// Granary slab.
addBox(world, [5.7, 0.35, 4.7], [7, 0.25, -6.3], 0xa9a28b, { castShadow: false });
function makeHouse(x, z, scale = 1, wallColor = 0xd9c49a, roofColor = 0x785043) {
const house = new THREE.Group();
house.position.set(x, 0, z);
house.scale.setScalar(scale);
world.add(house);
addBox(house, [3.4, 2.4, 3.1], [0, 1.3, 0], wallColor);
addBox(house, [3.85, 0.42, 3.55], [0, 2.68, 0], roofColor);
addBox(house, [3.1, 0.42, 2.85], [0, 3.05, 0], roofColor);
addBox(house, [2.25, 0.4, 2.05], [0, 3.42, 0], roofColor);
const windowMaterial = getMaterial(0xffdc83, {
emissive: 0xffb84d,
emissiveIntensity: 0.7,
roughness: 0.35
});
addBox(house, [0.52, 0.55, 0.09], [-1.05, 1.45, 1.59], windowMaterial);
addBox(house, [0.52, 0.55, 0.09], [1.05, 1.45, 1.59], windowMaterial);
addBox(house, [0.65, 1.2, 0.1], [0, 0.72, 1.61], 0x5c4639);
addBox(house, [0.44, 1.1, 0.44], [0.9, 3.35, -0.55], 0x68504a);
addBox(house, [0.5, 0.2, 0.5], [0.9, 3.93, -0.55], 0x8b5c4d);
addBox(house, [0.32, 0.6, 0.08], [-1.05, 1.45, -1.59], windowMaterial);
addBox(house, [0.32, 0.6, 0.08], [1.05, 1.45, -1.59], windowMaterial);
return house;
}
makeHouse(-4.3, 6.4, 1.02, 0xe4cca0, 0x8d5848);
makeHouse(3.2, 6.5, 1.08, 0xc9d2ad, 0x486c63);
makeHouse(7.2, 0.5, 0.9, 0xd8b98e, 0x6b5260);
makeHouse(-1.4, 8.4, 0.88, 0xd9c8b0, 0x647557);
// Community well and central lamp.
const well = new THREE.Group();
well.position.set(1, 0, -0.9);
world.add(well);
addBox(well, [2.1, 0.45, 2.1], [0, 0.38, 0], 0x8f9183);
addBox(well, [1.2, 0.3, 1.2], [0, 0.67, 0], 0x3b6e73);
addBox(well, [0.2, 2.1, 0.2], [-0.8, 1.25, 0], 0x71513d);
addBox(well, [0.2, 2.1, 0.2], [0.8, 1.25, 0], 0x71513d);
addBox(well, [2.0, 0.25, 0.25], [0, 2.28, 0], 0x71513d);
const lampMaterial = getMaterial(0xffdc79, {
emissive: 0xffb13b,
emissiveIntensity: 1.5,
roughness: 0.25
});
const lamp = new THREE.Group();
lamp.position.set(1, 0, 1.8);
world.add(lamp);
addBox(lamp, [0.3, 3.1, 0.3], [0, 1.6, 0], 0x5e5447);
addBox(lamp, [0.72, 0.8, 0.72], [0, 3.1, 0], lampMaterial);
addBox(lamp, [0.95, 0.22, 0.95], [0, 3.58, 0], 0x4e5149);
const lampLight = new THREE.PointLight(0xffc967, 1.7, 8, 2);
lampLight.position.set(1, 3.4, 1.8);
scene.add(lampLight);
function makeTree(x, z, scale = 1, canopy = 0x547f50) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
world.add(tree);
addBox(tree, [0.45, 2.4, 0.45], [0, 1.2, 0], 0x76513b);
addBox(tree, [2.2, 1.1, 2.2], [0, 2.6, 0], canopy);
addBox(tree, [1.65, 1.0, 1.65], [0.25, 3.45, -0.15], canopy);
addBox(tree, [1.15, 0.8, 1.15], [-0.25, 4.15, 0.1], 0x648f5b);
return tree;
}
[
[-11, -9, 1.0], [-8.5, -10.5, 0.85], [-3, -10.7, 1.0],
[1, -10.5, 0.9], [5, -10.4, 1.0], [10.6, -9.2, 1.15],
[12.2, -5.2, 0.9], [12.1, -0.5, 1.05], [12.1, 4.5, 0.9],
[11.1, 10.3, 1.0], [7.5, 11, 0.85], [-4.5, 11, 0.95],
[-10.2, 8.7, 1.0], [-12.1, 5.8, 0.85], [-6.5, -10.2, 0.75]
].forEach((entry, index) => {
makeTree(
entry[0],
entry[1],
entry[2],
[0x557f50, 0x668f56, 0x476f4a, 0x78965c][index % 4]
);
});
// Farm fence.
const fenceMaterial = 0x896143;
for (let i = -3; i <= 3; i++) {
addBox(world, [0.15, 1.1, 0.15], [-10.1 + i * 1, 0.72, -8], fenceMaterial);
}
addBox(world, [6.2, 0.13, 0.13], [-7, 0.92, -8], fenceMaterial);
addBox(world, [6.2, 0.13, 0.13], [-7, 0.55, -8], fenceMaterial);
// Small residents.
function makeResident(x, z, color, scale = 1) {
const resident = new THREE.Group();
resident.position.set(x, 0, z);
resident.scale.setScalar(scale);
world.add(resident);
addBox(resident, [0.55, 0.75, 0.42], [0, 0.6, 0], color);
addBox(resident, [0.55, 0.5, 0.5], [0, 1.25, 0], 0xd8b28f);
addBox(resident, [0.16, 0.35, 0.16], [-0.18, 0.18, 0], 0x4e5149);
addBox(resident, [0.16, 0.35, 0.16], [0.18, 0.18, 0], 0x4e5149);
addBox(resident, [0.62, 0.16, 0.56], [0, 1.55, 0], 0x5b6d58);
return resident;
}
makeResident(-0.8, 2.1, 0x9a5e53, 0.8);
makeResident(2.4, 3.8, 0x4d7680, 0.72);
makeResident(-5.8, -1.9, 0x6d8050, 0.76);
// -------------------------------------------------------------------------
// Unlockable construction effects
// -------------------------------------------------------------------------
const effectGroups = {};
function createEffect(id) {
const group = new THREE.Group();
group.visible = false;
scene.add(group);
effectGroups[id] = group;
return group;
}
// Water Map survey stakes.
{
const group = createEffect("waterMap");
[-5, 0, 5].forEach((z, index) => {
addBox(group, [0.16, 1.3, 0.16], [-11.35, 0.8, z], 0x7e5b3e);
addBox(group, [0.5, 0.38, 0.08], [-11.18, 1.35, z], 0x3fa6ad);
addBox(group, [0.7, 0.1, 0.1], [-11.35, 0.95, z], 0xd8c291);
});
}
// Reed channels and crop rows.
{
const group = createEffect("reedChannels");
for (let x = -10.5; x <= -6; x += 1.45) {
addBox(group, [1.35, 0.16, 0.72], [x, 0.44, -4.65], 0x47a8ae, {
castShadow: false
});
}
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 6; col++) {
const plant = addBox(
group,
[0.24, 0.55, 0.24],
[-9.4 + col * 0.95, 0.78, -6.85 + row * 1.12],
0x79a84f
);
plant.rotation.y = (row + col) % 2 ? 0.4 : -0.35;
}
}
addBox(group, [0.2, 1.2, 1.25], [-10.75, 0.8, -4.65], 0x76533b);
addBox(group, [0.2, 1.2, 1.25], [-9.45, 0.8, -4.65], 0x76533b);
}
// Rain Vault.
{
const group = createEffect("rainVault");
addBox(group, [3.3, 0.35, 3.2], [0, 0.55, 0], 0x858a7d);
const tankMaterial = getMaterial(0x4ca9b2, {
roughness: 0.25,
metalness: 0.08,
transparent: true,
opacity: 0.85
});
addBox(group, [2.65, 2.35, 2.55], [0, 1.8, 0], tankMaterial);
addBox(group, [2.9, 0.25, 2.8], [0, 3.05, 0], 0x657d79);
addBox(group, [2.25, 0.22, 2.15], [0, 3.28, 0], 0x4d6e6d);
addBox(group, [0.35, 0.9, 0.35], [0, 3.75, 0], 0x7a6650);
}
// Sunlift Pumps.
let pumpWheel;
{
const group = createEffect("sunliftPumps");
addBox(group, [2.7, 0.35, 2.4], [0, 0.55, 0], 0x8b8f80);
addBox(group, [0.3, 2.5, 0.3], [-0.9, 1.6, 0], 0x70523d);
addBox(group, [0.3, 2.5, 0.3], [0.9, 1.6, 0], 0x70523d);
addBox(group, [2.3, 0.3, 0.3], [0, 2.75, 0], 0x70523d);
addBox(group, [0.65, 0.65, 1.6], [0, 1.3, 0], 0x5e716c);
addBox(group, [0.5, 0.5, 2.6], [0, 1.3, 1], 0x58b9ba);
const sunstoneMaterial = getMaterial(0xffcf56, {
emissive: 0xffa82d,
emissiveIntensity: 1.25,
roughness: 0.3
});
pumpWheel = new THREE.Group();
pumpWheel.position.set(0, 1.65, 1.45);
group.add(pumpWheel);
addBox(pumpWheel, [1.8, 0.18, 0.18], [0, 0, 0], 0x77573d);
addBox(pumpWheel, [0.18, 1.8, 0.18], [0, 0, 0], 0x77573d);
addBox(pumpWheel, [0.7, 0.7, 0.28], [0, 0, 0], sunstoneMaterial);
}
// Dry storage frames.
{
const group = createEffect("dryFrames");
addBox(group, [3.7, 0.3, 2.7], [0, 0.55, 0], 0x8c7050);
[-1.55, 1.55].forEach((x) => {
[-1, 1].forEach((z) => {
addBox(group, [0.2, 2.1, 0.2], [x, 1.55, z], 0x79573d);
});
});
addBox(group, [3.5, 0.22, 2.45], [0, 2.62, 0], 0x8d6947);
}
// Grain baskets.
{
const group = createEffect("grainBaskets");
const basketColors = [0xc49755, 0xb98948, 0xd0a864];
[
[-0.9, 0.9, 0],
[0.7, 0.85, 0.45],
[-0.15, 1.65, -0.35]
].forEach((position, index) => {
addBox(
group,
[1.15, 0.85, 1.05],
position,
basketColors[index],
{ material: { roughness: 0.95 } }
);
addBox(group, [1.25, 0.16, 1.15], [position[0], position[1] + 0.48, position[2]], 0x866239);
addBox(group, [0.85, 0.14, 0.8], [position[0], position[1] + 0.55, position[2]], 0xd5b969);
});
}
// Raised silos.
{
const group = createEffect("raisedSilos");
addBox(group, [4.7, 0.35, 3.7], [0, 0.55, 0], 0x8e8b79);
[-0.95, 0.95].forEach((x, index) => {
addBox(group, [1.55, 3.2, 1.55], [x, 2.25, 0], index ? 0xbca77f : 0xc6b68e);
addBox(group, [1.8, 0.25, 1.8], [x, 3.95, 0], 0x766857);
addBox(group, [1.35, 0.35, 1.35], [x, 4.2, 0], 0x8d7558);
addBox(group, [0.42, 0.5, 0.12], [x, 2.5, 0.82], 0x554a3e);
});
}
// Courier pack racks.
{
const group = createEffect("packRacks");
addBox(group, [3.1, 0.25, 1.9], [0, 0.48, 0], 0x866548);
[-1.25, 1.25].forEach((x) => {
addBox(group, [0.18, 2.25, 0.18], [x, 1.45, 0], 0x73533b);
});
addBox(group, [2.75, 0.18, 0.18], [0, 2.55, 0], 0x73533b);
[-0.75, 0, 0.75].forEach((x, index) => {
addBox(group, [0.55, 0.8, 0.55], [x, 1.15, 0], [0x78905c, 0xb77554, 0x62868a][index]);
});
}
// Wheeled cart.
let cart;
const cartWheels = [];
{
const group = createEffect("wheeledCart");
cart = group;
addBox(group, [1.7, 0.32, 2.4], [0, 1.0, 0], 0x9a7148);
addBox(group, [1.55, 0.72, 0.16], [0, 1.48, -1.12], 0x7a573b);
addBox(group, [1.55, 0.72, 0.16], [0, 1.48, 1.12], 0x7a573b);
addBox(group, [0.16, 0.72, 2.1], [-0.78, 1.48, 0], 0x7a573b);
addBox(group, [0.16, 0.72, 2.1], [0.78, 1.48, 0], 0x7a573b);
addBox(group, [1.05, 0.65, 1.05], [0, 1.48, 0], 0xb8854d);
[-0.93, 0.93].forEach((x) => {
[-0.75, 0.75].forEach((z) => {
const wheel = new THREE.Group();
wheel.position.set(x, 0.75, z);
addBox(wheel, [0.22, 0.85, 0.85], [0, 0, 0], 0x4f5148);
addBox(wheel, [0.28, 0.25, 0.85], [0, 0, 0], 0xb88d52);
addBox(wheel, [0.28, 0.85, 0.25], [0, 0, 0], 0xb88d52);
group.add(wheel);
cartWheels.push(wheel);
});
});
addBox(group, [0.18, 0.18, 2.4], [-0.45, 1.35, 1.95], 0x755239);
addBox(group, [0.18, 0.18, 2.4], [0.45, 1.35, 1.95], 0x755239);
}
// Route Guild banners.
{
const group = createEffect("routeGuild");
addBox(group, [0.28, 3.4, 0.28], [0, 1.9, 0], 0x76533b);
addBox(group, [1.8, 0.25, 0.25], [0, 3.35, 0], 0x76533b);
addBox(group, [0.85, 1.05, 0.1], [0.65, 2.65, 0], 0xba5d50);
addBox(group, [0.65, 0.65, 0.1], [0.65, 2.65, 0.08], 0xe1bd59);
for (let i = 0; i < 5; i++) {
addBox(group, [0.65, 0.12, 0.65], [-1.4 + i * 0.7, 0.35, 1.2], 0xa99b79);
}
}
// -------------------------------------------------------------------------
// Scene labels and selectable proxies
// -------------------------------------------------------------------------
function makeLabel(text, position, accent = "#2c9eaa") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(248, 244, 224, 0.94)";
context.strokeStyle = "rgba(30, 62, 53, 0.24)";
context.lineWidth = 5;
context.beginPath();
context.roundRect(8, 12, 496, 104, 22);
context.fill();
context.stroke();
context.fillStyle = accent;
context.fillRect(24, 34, 9, 60);
context.fillStyle = "#17312d";
context.font = "800 35px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 270, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(5.2, 1.3, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
makeLabel("WATER GARDENS", new THREE.Vector3(-7.5, 4.5, -5), "#2c9eaa");
makeLabel("RAISED GRANARY", new THREE.Vector3(7, 5.1, -6.6), "#c98435");
makeLabel("NORTH ROAD", new THREE.Vector3(6, 4.5, 7.7), "#bd5d50");
const selectable = [];
const selectionOutline = addWireBox(
scene,
[4, 3, 4],
[0, 1, 0],
0xffdc73
);
selectionOutline.visible = false;
selectionOutline.renderOrder = 30;
const proxyMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
function addSelectable(skillId, size, position) {
const proxy = new THREE.Mesh(cubeGeometry, proxyMaterial);
proxy.scale.set(size[0], size[1], size[2]);
proxy.position.set(position[0], position[1], position[2]);
proxy.userData.skillId = skillId;
scene.add(proxy);
selectable.push(proxy);
}
addSelectable("waterMap", [3, 2.5, 7], [-11.4, 1.2, 0]);
addSelectable("reedChannels", [6, 1.2, 4], [-7.2, 0.7, -4.8]);
addSelectable("rainVault", [3.6, 4.5, 3.6], [-10, 2.1, -1]);
addSelectable("sunliftPumps", [3.5, 3.5, 3.5], [-9.8, 1.8, -6]);
addSelectable("dryFrames", [4.5, 3, 3.5], [6.4, 1.5, -5.7]);
addSelectable("grainBaskets", [4, 2.6, 3], [7, 1.3, -5.4]);
addSelectable("raisedSilos", [4.5, 4.8, 3.6], [7.8, 2.4, -7]);
addSelectable("packRacks", [3.6, 3, 2.5], [4.5, 1.5, 6]);
addSelectable("wheeledCart", [3, 2.5, 4], [5.6, 1.2, 7.4]);
addSelectable("routeGuild", [3.5, 4, 3.5], [9, 2, 7.7]);
// -------------------------------------------------------------------------
// Ambient animated details
// -------------------------------------------------------------------------
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
addBox(group, [3.2, 0.75, 1.25], [0, 0, 0], 0xf2f0d9, { castShadow: false });
addBox(group, [1.8, 1.05, 1.45], [-0.7, 0.5, 0], 0xf7f4df, { castShadow: false });
addBox(group, [2.1, 1.25, 1.35], [0.85, 0.55, 0], 0xf7f4df, { castShadow: false });
clouds.push(group);
}
makeCloud(-18, 14, -14, 1.4);
makeCloud(9, 17, -21, 1.1);
makeCloud(20, 13, 4, 1.25);
const waterGlints = [];
for (let i = 0; i < 8; i++) {
const glint = addBox(
world,
[0.65, 0.035, 0.14],
[-14, 0.3, -11 + i * 3],
0xb9ebe0,
{ castShadow: false }
);
waterGlints.push(glint);
}
const fireflies = [];
const fireflyMaterial = getMaterial(0xffe993, {
emissive: 0xffc84a,
emissiveIntensity: 1.3
});
for (let i = 0; i < 16; i++) {
const firefly = addBox(
world,
[0.09, 0.09, 0.09],
[-10 + seededRandom() * 20, 1.5 + seededRandom() * 4, -9 + seededRandom() * 18],
fireflyMaterial,
{ castShadow: false }
);
firefly.userData.phase = seededRandom() * Math.PI * 2;
fireflies.push(firefly);
}
// Build particles.
const particles = [];
const particleGeometry = new THREE.BoxGeometry(0.15, 0.15, 0.15);
const particleMaterial = new THREE.MeshBasicMaterial({ color: 0xffdc73 });
function burstAt(position, color = 0xffdc73) {
particleMaterial.color.setHex(color);
for (let i = 0; i < 22; i++) {
const particle = new THREE.Mesh(particleGeometry, particleMaterial);
particle.position.copy(position);
particle.position.y += 1;
scene.add(particle);
particles.push({
mesh: particle,
velocity: new THREE.Vector3(
(seededRandom() - 0.5) * 3,
2.5 + seededRandom() * 2,
(seededRandom() - 0.5) * 3
),
life: 1.2
});
}
}
// -------------------------------------------------------------------------
// Custom camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let pointerMode = "rotate";
let lastX = 0;
let lastY = 0;
let lastPinchDistance = 0;
let pointerDownX = 0;
let pointerDownY = 0;
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraRadius,
cameraPhi,
cameraTheta
);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
function setZoom(value) {
camera.zoom = THREE.MathUtils.clamp(value, 0.62, 2.15);
camera.updateProjectionMatrix();
desiredZoom = camera.zoom;
}
function panCamera(deltaX, deltaY) {
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
const worldUp = new THREE.Vector3(0, 1, 0);
camera.getWorldDirection(forward);
right.crossVectors(forward, worldUp).normalize();
forward.crossVectors(right, worldUp).normalize();
const scale = 0.035 / camera.zoom;
cameraTarget.addScaledVector(right, -deltaX * scale);
cameraTarget.addScaledVector(forward, deltaY * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -16, 16);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -15, 15);
}
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
pointerMode = event.button === 2 || event.shiftKey ? "pan" : "rotate";
lastX = event.clientX;
lastY = event.clientY;
pointerDownX = event.clientX;
pointerDownY = event.clientY;
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (pointers.has(event.pointerId)) {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
}
if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
setZoom(camera.zoom * (distance / lastPinchDistance));
}
lastPinchDistance = distance;
return;
}
if (pointers.size === 1) {
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (pointerMode === "rotate") {
cameraTheta -= deltaX * 0.005;
cameraPhi = THREE.MathUtils.clamp(cameraPhi + deltaY * 0.004, 0.45, 1.35);
} else {
panCamera(deltaX, deltaY);
}
} else {
updateHover(event);
}
});
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function setRayFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
}
function updateHover(event) {
setRayFromEvent(event);
const hit = raycaster.intersectObjects(selectable, false)[0];
canvas.style.cursor = hit ? "pointer" : "grab";
}
canvas.addEventListener("pointerup", (event) => {
const wasClick =
Math.hypot(event.clientX - pointerDownX, event.clientY - pointerDownY) < 5;
if (wasClick && pointers.size === 1) {
setRayFromEvent(event);
const hit = raycaster.intersectObjects(selectable, false)[0];
if (hit) {
selectSkill(hit.object.userData.skillId, true);
}
}
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
lastX = remaining.x;
lastY = remaining.y;
pointerMode = "rotate";
}
});
canvas.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
setZoom(camera.zoom * Math.exp(-event.deltaY * 0.001));
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.left = -13.5 * aspect;
camera.right = 13.5 * aspect;
camera.top = 13.5;
camera.bottom = -13.5;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const treePanel = document.querySelector("#treePanel");
const panelToggle = document.querySelector("#panelToggle");
const gatherButton = document.querySelector("#gatherButton");
const inspector = document.querySelector("#inspector");
const inspectorTitle = document.querySelector("#inspectorTitle");
const inspectorText = document.querySelector("#inspectorText");
const focusButton = document.querySelector("#focusButton");
const toastStack = document.querySelector("#toastStack");
let selectedSkillId = null;
let gatherReadyAt = 0;
function toast(message, warning = false) {
const element = document.createElement("div");
element.className = `toast${warning ? " warning" : ""}`;
element.textContent = message;
toastStack.appendChild(element);
setTimeout(() => {
element.style.opacity = "0";
element.style.transform = "translateY(-8px)";
element.style.transition = "opacity 180ms ease, transform 180ms ease";
setTimeout(() => element.remove(), 200);
}, 3100);
}
function updateResourceUI() {
for (const key of Object.keys(RESOURCE_META)) {
document.querySelector(`#res-${key}`).textContent = state.resources[key];
}
}
function isUnlocked(id) {
return state.unlocked.includes(id);
}
function hasAllPrerequisites(skill) {
return skill.prereq.every(isUnlocked);
}
function canAfford(skill) {
return Object.entries(skill.cost).every(
([key, amount]) => state.resources[key] >= amount
);
}
function statusFor(skill) {
if (isUnlocked(skill.id)) return "unlocked";
if (!hasAllPrerequisites(skill)) return "locked";
if (!canAfford(skill)) return "locked";
return "ready";
}
function renderTree() {
const branchNodes = {
water: document.querySelector("#waterNodes"),
storage: document.querySelector("#storageNodes"),
transport: document.querySelector("#transportNodes")
};
Object.entries(skills).forEach(([id, skill]) => {
skill.id = id;
const status = statusFor(skill);
const stateText = status === "unlocked" ? "Unlocked" : status === "ready" ? "Ready" : "Locked";
const prerequisites = skill.prereq.length
? skill.prereq
.map(
(preId) =>
`<span class="prereq-chip ${isUnlocked(preId) ? "done" : ""}">${skills[preId].name}</span>`
)
.join("")
: `<span class="prereq-chip done">None</span>`;
const costs = Object.entries(skill.cost)
.map(([key, amount]) => {
const short = state.resources[key] < amount;
const difference = short ? amount - state.resources[key] : 0;
return `<span class="cost ${short ? "short" : ""}">
${RESOURCE_META[key].icon} ${amount}${difference ? ` · need ${difference}` : ""}
</span>`;
})
.join("");
const button = document.createElement("button");
button.className = `skill-node ${status}`;
button.dataset.skillId = id;
button.innerHTML = `
<div class="node-heading">
<span class="node-icon">${skill.icon}</span>
<span class="node-name">
<strong>${skill.name}</strong>
<small>${skill.tag}</small>
</span>
<span class="node-state">${stateText}</span>
</div>
<p class="node-description">${skill.description}</p>
<div class="prereq-line">
<span class="prereq-label">Requires</span>
${prerequisites}
</div>
<div class="cost-line">${costs}</div>
`;
branchNodes[skill.branch].appendChild(button);
});
const count = state.unlocked.length;
const total = Object.keys(skills).length;
document.querySelector("#progressFill").style.width = `${(count / total) * 100}%`;
document.querySelector("#progressText").textContent = `${count} / ${total}`;
updateResourceUI();
}
function applyUnlockedVisuals() {
for (const [id, skill] of Object.entries(skills)) {
skill.effects.forEach((effectId) => {
if (effectGroups[effectId]) {
effectGroups[effectId].visible = isUnlocked(id);
}
});
}
}
function unlockSkill(id) {
const skill = skills[id];
if (!skill) return;
if (isUnlocked(id)) {
selectSkill(id, false);
toast(`${skill.name} is already part of Mossbell's lattice.`);
return;
}
if (!hasAllPrerequisites(skill)) {
const missing = skill.prereq
.filter((preId) => !isUnlocked(preId))
.map((preId) => skills[preId].name)
.join(", ");
toast(`Locked: unlock ${missing} first.`, true);
return;
}
if (!canAfford(skill)) {
const missing = Object.entries(skill.cost)
.filter(([key, amount]) => state.resources[key] < amount)
.map(
([key, amount]) =>
`${amount - state.resources[key]} more ${RESOURCE_META[key].label.toLowerCase()}`
)
.join(" and ");
toast(`More supplies needed: ${missing}.`, true);
return;
}
Object.entries(skill.cost).forEach(([key, amount]) => {
state.resources[key] -= amount;
});
state.unlocked.push(id);
applyUnlockedVisuals();
saveState();
renderTree();
selectSkill(id, false);
burstAt(skill.location, id === "routeGuild" ? 0xe6b859 : 0x8ee1dc);
toast(`${skill.name} unlocked — ${skill.tag.toLowerCase()} added to Mossbell.`);
}
function selectSkill(id, focusScene = false) {
const skill = skills[id];
if (!skill) return;
selectedSkillId = id;
inspectorTitle.textContent = skill.siteTitle;
inspectorText.textContent = skill.siteText;
inspector.classList.add("visible");
selectionOutline.position.copy(skill.location);
selectionOutline.position.y = 1.3;
selectionOutline.scale.set(4.2, 3.2, 4.2);
selectionOutline.visible = true;
if (focusScene) {
focusOn(skill.location);
}
}
function focusOn(position) {
cameraTarget.copy(position);
cameraTarget.y = 0;
setZoom(Math.max(camera.zoom, 1.18));
}
document.querySelector("#treeScroll").addEventListener("click", (event) => {
const node = event.target.closest(".skill-node");
if (node) {
unlockSkill(node.dataset.skillId);
}
});
focusButton.addEventListener("click", () => {
if (selectedSkillId) {
focusOn(skills[selectedSkillId].location);
}
});
function updateGatherButton() {
const remaining = Math.max(0, Math.ceil((gatherReadyAt - Date.now()) / 1000));
if (remaining > 0) {
gatherButton.disabled = true;
gatherButton.textContent = `District yield ready in ${remaining}s`;
} else {
gatherButton.disabled = false;
gatherButton.textContent = "Gather district yield · +6 timber, +4 stone, +4 root, +2 insight";
}
}
gatherButton.addEventListener("click", () => {
if (Date.now() < gatherReadyAt) return;
state.resources.timber += 6;
state.resources.stone += 4;
state.resources.roots += 4;
state.resources.insight += 2;
gatherReadyAt = Date.now() + 12000;
saveState();
renderTree();
updateGatherButton();
burstAt(new THREE.Vector3(0, 0, 1), 0xffd66e);
toast("District yield gathered. New supplies are ready for the lattice.");
});
document.querySelector("#resetButton").addEventListener("click", () => {
if (!window.confirm("Reset Mossbell's skill tree and resources?")) return;
state = {
unlocked: [],
resources: { ...DEFAULT_RESOURCES }
};
gatherReadyAt = 0;
selectedSkillId = null;
inspector.classList.remove("visible");
selectionOutline.visible = false;
applyUnlockedVisuals();
saveState();
renderTree();
updateGatherButton();
toast("Mossbell's lattice has been reset.");
});
panelToggle.addEventListener("click", () => {
const isOpen = treePanel.classList.toggle("open");
panelToggle.setAttribute("aria-expanded", String(isOpen));
panelToggle.textContent = isOpen ? "Close" : "Skills";
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (pumpWheel) {
pumpWheel.rotation.z += delta * 0.75;
}
if (cart) {
cart.position.z = 7.3 + Math.sin(elapsed * 0.42) * 2.2;
cart.rotation.y = Math.sin(elapsed * 0.42) > 0 ? 0 : Math.PI;
cartWheels.forEach((wheel) => {
wheel.rotation.x += delta * 2.2;
});
}
clouds.forEach((cloud, index) => {
cloud.position.x += delta * (0.18 + index * 0.035);
if (cloud.position.x > 32) cloud.position.x = -32;
});
waterGlints.forEach((glint, index) => {
glint.position.x = -14 + Math.sin(elapsed * 0.8 + index * 1.4) * 0.6;
glint.material.emissive = glint.material.emissive || {};
glint.scale.x = 0.4 + Math.max(0, Math.sin(elapsed * 1.2 + index)) * 0.7;
});
fireflies.forEach((firefly) => {
firefly.position.y += Math.sin(elapsed * 1.1 + firefly.userData.phase) * delta * 0.28;
firefly.position.x += Math.cos(elapsed * 0.8 + firefly.userData.phase) * delta * 0.12;
firefly.rotation.y += delta;
});
for (let i = particles.length - 1; i >= 0; i--) {
const particle = particles[i];
particle.life -= delta;
particle.mesh.position.addScaledVector(particle.velocity, delta);
particle.velocity.y -= 4.5 * delta;
particle.mesh.rotation.x += delta * 3;
particle.mesh.rotation.y += delta * 4;
particle.mesh.scale.setScalar(Math.max(0.01, particle.life));
if (particle.life <= 0) {
scene.remove(particle.mesh);
particles.splice(i, 1);
}
}
if (selectionOutline.visible) {
selectionOutline.material.opacity = 0.28 + Math.sin(elapsed * 3) * 0.12;
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
applyUnlockedVisuals();
renderTree();
updateGatherButton();
setInterval(updateGatherButton, 500);
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```