awacke1 commited on
Commit
beb5dfd
·
verified ·
1 Parent(s): 974e438

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +993 -19
index.html CHANGED
@@ -1,19 +1,993 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Choose Your Own Procedural Adventure</title>
7
+ <style>
8
+ body {
9
+ font-family: 'Courier New', monospace;
10
+ background-color: #222;
11
+ color: #eee;
12
+ margin: 0;
13
+ padding: 0;
14
+ overflow: hidden;
15
+ display: flex;
16
+ flex-direction: column;
17
+ height: 100vh;
18
+ }
19
+
20
+ #game-container {
21
+ display: flex;
22
+ flex-grow: 1;
23
+ overflow: hidden;
24
+ }
25
+
26
+ #scene-container {
27
+ flex-grow: 3;
28
+ position: relative;
29
+ border-right: 2px solid #555;
30
+ min-width: 200px;
31
+ background-color: #1a1a1a;
32
+ height: 100%;
33
+ box-sizing: border-box;
34
+ }
35
+
36
+ #ui-container {
37
+ flex-grow: 2;
38
+ padding: 20px;
39
+ overflow-y: auto;
40
+ background-color: #333;
41
+ min-width: 280px;
42
+ height: 100%;
43
+ box-sizing: border-box;
44
+ display: flex;
45
+ flex-direction: column;
46
+ }
47
+
48
+ #scene-container canvas { display: block; }
49
+
50
+ #story-title {
51
+ color: #ffcc66;
52
+ margin-top: 0;
53
+ margin-bottom: 15px;
54
+ border-bottom: 1px solid #555;
55
+ padding-bottom: 10px;
56
+ font-size: 1.4em;
57
+ }
58
+
59
+ #story-content {
60
+ margin-bottom: 20px;
61
+ line-height: 1.6;
62
+ flex-grow: 1;
63
+ }
64
+ #story-content p { margin-bottom: 1em; }
65
+ #story-content p:last-child { margin-bottom: 0; }
66
+
67
+ #stats-inventory-container {
68
+ margin-bottom: 20px;
69
+ padding-bottom: 15px;
70
+ border-bottom: 1px solid #555;
71
+ font-size: 0.9em;
72
+ }
73
+ #stats-display, #inventory-display {
74
+ margin-bottom: 10px;
75
+ line-height: 1.8;
76
+ }
77
+ #stats-display span, #inventory-display span {
78
+ display: inline-block;
79
+ background-color: #444;
80
+ padding: 3px 8px;
81
+ border-radius: 15px;
82
+ margin-right: 8px;
83
+ margin-bottom: 5px;
84
+ border: 1px solid #666;
85
+ white-space: nowrap;
86
+ }
87
+ #stats-display strong, #inventory-display strong { color: #aaa; margin-right: 5px; }
88
+ #inventory-display em { color: #888; font-style: normal; }
89
+
90
+ #inventory-display .item-quest { background-color: #666030; border-color: #999048;}
91
+ #inventory-display .item-weapon { background-color: #663030; border-color: #994848;}
92
+ #inventory-display .item-armor { background-color: #306630; border-color: #489948;}
93
+ #inventory-display .item-spell { background-color: #303066; border-color: #484899;}
94
+ #inventory-display .item-unknown { background-color: #555; border-color: #777;}
95
+
96
+ #choices-container {
97
+ margin-top: auto;
98
+ padding-top: 15px;
99
+ border-top: 1px solid #555;
100
+ }
101
+ #choices-container h3 { margin-top: 0; margin-bottom: 10px; color: #aaa; }
102
+ #choices { display: flex; flex-direction: column; gap: 10px; }
103
+
104
+ .choice-button {
105
+ display: block; width: 100%; padding: 10px 12px; margin-bottom: 0;
106
+ background-color: #555; color: #eee; border: 1px solid #777;
107
+ border-radius: 5px; cursor: pointer; text-align: left;
108
+ font-family: 'Courier New', monospace; font-size: 1em;
109
+ transition: background-color 0.2s, border-color 0.2s;
110
+ box-sizing: border-box;
111
+ }
112
+ .choice-button:hover:not(:disabled) { background-color: #d4a017; color: #222; border-color: #b8860b; }
113
+ .choice-button:disabled { background-color: #444; color: #888; cursor: not-allowed; border-color: #666; opacity: 0.7; }
114
+
115
+ .roll-success { color: #7f7; border-left: 3px solid #4a4; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
116
+ .roll-failure { color: #f77; border-left: 3px solid #a44; padding-left: 8px; margin-bottom: 1em; font-size: 0.9em; }
117
+ </style>
118
+ </head>
119
+ <body>
120
+ <div id="game-container">
121
+ <div id="scene-container"></div>
122
+ <div id="ui-container">
123
+ <h2 id="story-title">Loading Adventure...</h2>
124
+ <div id="story-content">
125
+ <p>Please wait while the adventure loads.</p>
126
+ </div>
127
+ <div id="stats-inventory-container">
128
+ <div id="stats-display"></div>
129
+ <div id="inventory-display"></div>
130
+ </div>
131
+ <div id="choices-container">
132
+ <h3>What will you do?</h3>
133
+ <div id="choices"></div>
134
+ </div>
135
+ </div>
136
+ </div>
137
+
138
+ <script type="importmap">
139
+ {
140
+ "imports": {
141
+ "three": "https://unpkg.com/[email protected]/build/three.module.js",
142
+ "three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
143
+ }
144
+ }
145
+ </script>
146
+
147
+ <script type="module">
148
+ import * as THREE from 'three';
149
+
150
+ const sceneContainer = document.getElementById('scene-container');
151
+ const storyTitleElement = document.getElementById('story-title');
152
+ const storyContentElement = document.getElementById('story-content');
153
+ const choicesElement = document.getElementById('choices');
154
+ const statsElement = document.getElementById('stats-display');
155
+ const inventoryElement = document.getElementById('inventory-display');
156
+
157
+ let scene, camera, renderer;
158
+ let currentAssemblyGroup = null;
159
+
160
+ // Materials
161
+ const stoneMaterial = new THREE.MeshStandardMaterial({ color: 0x888888, roughness: 0.8, metalness: 0.1 });
162
+ const woodMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513, roughness: 0.7, metalness: 0 });
163
+ const darkWoodMaterial = new THREE.MeshStandardMaterial({ color: 0x5C3D20, roughness: 0.7, metalness: 0 });
164
+ const leafMaterial = new THREE.MeshStandardMaterial({ color: 0x2E8B57, roughness: 0.6, metalness: 0 });
165
+ const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x556B2F, roughness: 0.9, metalness: 0 });
166
+ const metalMaterial = new THREE.MeshStandardMaterial({ color: 0xaaaaaa, metalness: 0.8, roughness: 0.3 });
167
+ const templeMaterial = new THREE.MeshStandardMaterial({ color: 0xA99B78, roughness: 0.7, metalness: 0.1 });
168
+ const errorMaterial = new THREE.MeshStandardMaterial({ color: 0xffa500, roughness: 0.5 });
169
+ const gameOverMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000, roughness: 0.5 });
170
+ const dirtMaterial = new THREE.MeshStandardMaterial({ color: 0x8B5E3C, roughness: 0.9 });
171
+ const grassMaterial = new THREE.MeshStandardMaterial({ color: 0x3CB371, roughness: 0.8 });
172
+ const oceanMaterial = new THREE.MeshStandardMaterial({ color: 0x1E90FF, roughness: 0.5, metalness: 0.2 });
173
+ const sandMaterial = new THREE.MeshStandardMaterial({ color: 0xF4A460, roughness: 0.9 });
174
+ const wetStoneMaterial = new THREE.MeshStandardMaterial({ color: 0x2F4F4F, roughness: 0.7 });
175
+ const glowMaterial = new THREE.MeshStandardMaterial({ color: 0x00FFAA, emissive: 0x00FFAA, emissiveIntensity: 0.5 });
176
+
177
+ function initThreeJS() {
178
+ if (!sceneContainer) { console.error("Scene container not found!"); return; }
179
+ scene = new THREE.Scene();
180
+ scene.background = new THREE.Color(0x222222);
181
+ const width = sceneContainer.clientWidth;
182
+ const height = sceneContainer.clientHeight;
183
+ camera = new THREE.PerspectiveCamera(75, (width / height) || 1, 0.1, 1000);
184
+ camera.position.set(0, 2.5, 7);
185
+ camera.lookAt(0, 0.5, 0);
186
+ renderer = new THREE.WebGLRenderer({ antialias: true });
187
+ renderer.setSize(width || 400, height || 300);
188
+ renderer.shadowMap.enabled = true;
189
+ renderer.shadowMap.type = THREE.PCFSoftShadowMap;
190
+ sceneContainer.appendChild(renderer.domElement);
191
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
192
+ scene.add(ambientLight);
193
+ window.addEventListener('resize', onWindowResize, false);
194
+ setTimeout(onWindowResize, 100);
195
+ animate();
196
+ }
197
+
198
+ function onWindowResize() {
199
+ if (!renderer || !camera || !sceneContainer) return;
200
+ const width = sceneContainer.clientWidth;
201
+ const height = sceneContainer.clientHeight;
202
+ if (width > 0 && height > 0) {
203
+ camera.aspect = width / height;
204
+ camera.updateProjectionMatrix();
205
+ renderer.setSize(width, height);
206
+ }
207
+ }
208
+
209
+ function animate() {
210
+ requestAnimationFrame(animate);
211
+ const time = performance.now() * 0.001;
212
+ scene.traverse(obj => {
213
+ if (obj.userData.update) obj.userData.update(time);
214
+ });
215
+ if (renderer && scene && camera) {
216
+ renderer.render(scene, camera);
217
+ }
218
+ }
219
+
220
+ function createMesh(geometry, material, position = { x: 0, y: 0, z: 0 }, rotation = { x: 0, y: 0, z: 0 }, scale = { x: 1, y: 1, z: 1 }) {
221
+ const mesh = new THREE.Mesh(geometry, material);
222
+ mesh.position.set(position.x, position.y, position.z);
223
+ mesh.rotation.set(rotation.x, rotation.y, rotation.z);
224
+ mesh.scale.set(scale.x, scale.y, scale.z);
225
+ mesh.castShadow = true; mesh.receiveShadow = true;
226
+ return mesh;
227
+ }
228
+
229
+ function createGroundPlane(material = groundMaterial, size = 20) {
230
+ const groundGeo = new THREE.PlaneGeometry(size, size);
231
+ const ground = new THREE.Mesh(groundGeo, material);
232
+ ground.rotation.x = -Math.PI / 2; ground.position.y = -0.05;
233
+ ground.receiveShadow = true; ground.castShadow = false;
234
+ return ground;
235
+ }
236
+
237
+ // Procedural Generation Functions
238
+ function createDefaultAssembly() {
239
+ const group = new THREE.Group();
240
+ const sphereGeo = new THREE.SphereGeometry(0.5, 16, 16);
241
+ group.add(createMesh(sphereGeo, stoneMaterial, { x: 0, y: 0.5, z: 0 }));
242
+ group.add(createGroundPlane());
243
+ return group;
244
+ }
245
+
246
+ function createCityGatesAssembly() {
247
+ const group = new THREE.Group();
248
+ const gh=4, gw=1.5, gd=0.8, ah=1, aw=3;
249
+ const tlGeo = new THREE.BoxGeometry(gw, gh, gd);
250
+ group.add(createMesh(tlGeo, stoneMaterial, { x:-(aw/2+gw/2), y:gh/2, z:0 }));
251
+ const trGeo = new THREE.BoxGeometry(gw, gh, gd);
252
+ group.add(createMesh(trGeo, stoneMaterial, { x:(aw/2+gw/2), y:gh/2, z:0 }));
253
+ const aGeo = new THREE.BoxGeometry(aw, ah, gd);
254
+ group.add(createMesh(aGeo, stoneMaterial, { x:0, y:gh-ah/2, z:0 }));
255
+ const cs=0.4;
256
+ const cg = new THREE.BoxGeometry(cs, cs, gd*1.1);
257
+ for(let i=-1; i<=1; i+=2){
258
+ group.add(createMesh(cg.clone(), stoneMaterial, { x:-(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
259
+ group.add(createMesh(cg.clone(), stoneMaterial, { x:(aw/2+gw/2)+i*cs*0.7, y:gh+cs/2, z:0 }));
260
+ }
261
+ group.add(createMesh(cg.clone(), stoneMaterial, { x:0, y:gh+ah-cs/2, z:0 }));
262
+ group.add(createGroundPlane(stoneMaterial));
263
+ return group;
264
+ }
265
+
266
+ function createWeaponsmithAssembly() {
267
+ const group = new THREE.Group();
268
+ const bw=3, bh=2.5, bd=3.5;
269
+ const bGeo = new THREE.BoxGeometry(bw, bh, bd);
270
+ group.add(createMesh(bGeo, darkWoodMaterial, { x:0, y:bh/2, z:0 }));
271
+ const ch=3.5;
272
+ const cGeo = new THREE.CylinderGeometry(0.3, 0.4, ch, 8);
273
+ group.add(createMesh(cGeo, stoneMaterial, { x:bw*0.3, y:ch/2, z:-bd*0.3 }));
274
+ group.add(createGroundPlane());
275
+ return group;
276
+ }
277
+
278
+ function createTempleAssembly() {
279
+ const group = new THREE.Group();
280
+ const bs=5, bsh=0.5, ch=3, cr=0.25, rh=0.5;
281
+ const bGeo = new THREE.BoxGeometry(bs, bsh, bs);
282
+ group.add(createMesh(bGeo, templeMaterial, { x:0, y:bsh/2, z:0 }));
283
+ const cGeo = new THREE.CylinderGeometry(cr, cr, ch, 12);
284
+ const cPos = [{x:-bs/3, z:-bs/3}, {x:bs/3, z:-bs/3}, {x:-bs/3, z:bs/3}, {x:bs/3, z:bs/3}];
285
+ cPos.forEach(p=>group.add(createMesh(cGeo.clone(), templeMaterial, { x:p.x, y:bsh+ch/2, z:p.z })));
286
+ const rGeo = new THREE.BoxGeometry(bs*0.9, rh, bs*0.9);
287
+ group.add(createMesh(rGeo, templeMaterial, { x:0, y:bsh+ch+rh/2, z:0 }));
288
+ group.add(createGroundPlane());
289
+ return group;
290
+ }
291
+
292
+ function createResistanceMeetingAssembly() {
293
+ const group = new THREE.Group();
294
+ const tw=2, th=0.8, td=1, tt=0.1;
295
+ const ttg = new THREE.BoxGeometry(tw, tt, td);
296
+ group.add(createMesh(ttg, woodMaterial, { x:0, y:th-tt/2, z:0 }));
297
+ const lh=th-tt, ls=0.1;
298
+ const lg=new THREE.BoxGeometry(ls, lh, ls);
299
+ const lofW=tw/2-ls*1.5;
300
+ const lofD=td/2-ls*1.5;
301
+ group.add(createMesh(lg, woodMaterial, { x:-lofW, y:lh/2, z:-lofD }));
302
+ group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:-lofD }));
303
+ group.add(createMesh(lg.clone(), woodMaterial, { x:-lofW, y:lh/2, z:lofD }));
304
+ group.add(createMesh(lg.clone(), woodMaterial, { x:lofW, y:lh/2, z:lofD }));
305
+ const ss=0.4;
306
+ const sg=new THREE.BoxGeometry(ss, ss*0.8, ss);
307
+ group.add(createMesh(sg, darkWoodMaterial, { x:-tw*0.6, y:ss*0.4, z:0 }));
308
+ group.add(createMesh(sg.clone(), darkWoodMaterial, { x:tw*0.6, y:ss*0.4, z:0 }));
309
+ group.add(createGroundPlane(stoneMaterial));
310
+ return group;
311
+ }
312
+
313
+ function createForestAssembly(tc=10, a=10) {
314
+ const group = new THREE.Group();
315
+ const cT=(x,z)=>{
316
+ const tg=new THREE.Group();
317
+ const th=Math.random()*1.5+2;
318
+ const tr=Math.random()*0.1+0.1;
319
+ const tGeo = new THREE.CylinderGeometry(tr*0.7, tr, th, 8);
320
+ tg.add(createMesh(tGeo, woodMaterial, {x:0, y:th/2, z:0}));
321
+ const fr=th*0.4+0.2;
322
+ const fGeo=new THREE.SphereGeometry(fr, 8, 6);
323
+ tg.add(createMesh(fGeo, leafMaterial, {x:0, y:th*0.9, z:0}));
324
+ tg.position.set(x,0,z);
325
+ return tg;
326
+ };
327
+ for(let i=0; i<tc; i++){
328
+ const x=(Math.random()-0.5)*a;
329
+ const z=(Math.random()-0.5)*a;
330
+ if(Math.sqrt(x*x+z*z)>1.0) group.add(cT(x,z));
331
+ }
332
+ group.add(createGroundPlane(groundMaterial, a*1.1));
333
+ return group;
334
+ }
335
+
336
+ function createRoadAmbushAssembly() {
337
+ const group = new THREE.Group();
338
+ const a=12;
339
+ const fg = createForestAssembly(8, a);
340
+ group.add(fg);
341
+ const rw=3, rl=a*1.2;
342
+ const rGeo=new THREE.PlaneGeometry(rw, rl);
343
+ const rMat=new THREE.MeshStandardMaterial({color:0x966F33, roughness:0.9});
344
+ const r=createMesh(rGeo, rMat, {x:0, y:0.01, z:0}, {x:-Math.PI/2});
345
+ r.receiveShadow=true;
346
+ group.add(r);
347
+ const rkGeo=new THREE.SphereGeometry(0.5, 5, 4);
348
+ const rkMat=new THREE.MeshStandardMaterial({color:0x666666, roughness:0.8});
349
+ group.add(createMesh(rkGeo, rkMat, {x:rw*0.7, y:0.25, z:1}, {y:Math.random()*Math.PI}));
350
+ group.add(createMesh(rkGeo.clone().scale(0.8,0.8,0.8), rkMat, {x:-rw*0.8, y:0.2, z:-2}, {y:Math.random()*Math.PI}));
351
+ return group;
352
+ }
353
+
354
+ function createForestEdgeAssembly() {
355
+ const group = new THREE.Group();
356
+ const a=15;
357
+ const fg = createForestAssembly(15, a);
358
+ const ttr=[];
359
+ fg.children.forEach(c => {
360
+ if(c.type === 'Group' && c.position.x > 0) ttr.push(c);
361
+ });
362
+ ttr.forEach(t => fg.remove(t));
363
+ group.add(fg);
364
+ return group;
365
+ }
366
+
367
+ function createPrisonerCellAssembly() {
368
+ const group = new THREE.Group();
369
+ const cs=3, wh=2.5, wt=0.2, br=0.05, bsp=0.25;
370
+ const cfMat=stoneMaterial.clone();
371
+ cfMat.color.setHex(0x555555);
372
+ group.add(createGroundPlane(cfMat, cs));
373
+ const wbGeo=new THREE.BoxGeometry(cs, wh, wt);
374
+ group.add(createMesh(wbGeo, stoneMaterial, {x:0, y:wh/2, z:-cs/2}));
375
+ const wsGeo=new THREE.BoxGeometry(wt, wh, cs);
376
+ group.add(createMesh(wsGeo, stoneMaterial, {x:-cs/2, y:wh/2, z:0}));
377
+ group.add(createMesh(wsGeo.clone(), stoneMaterial, {x:cs/2, y:wh/2, z:0}));
378
+ const bGeo=new THREE.CylinderGeometry(br, br, wh, 8);
379
+ const nb=Math.floor(cs/bsp);
380
+ for(let i=0; i<nb; i++){
381
+ const xp=-cs/2+(i+0.5)*bsp;
382
+ group.add(createMesh(bGeo.clone(), metalMaterial, {x:xp, y:wh/2, z:cs/2}));
383
+ }
384
+ return group;
385
+ }
386
+
387
+ function createGameOverAssembly() {
388
+ const group = new THREE.Group();
389
+ const boxGeo = new THREE.BoxGeometry(2, 2, 2);
390
+ group.add(createMesh(boxGeo, gameOverMaterial, { x: 0, y: 1, z: 0 }));
391
+ group.add(createGroundPlane(stoneMaterial.clone().set({color: 0x333333})));
392
+ return group;
393
+ }
394
+
395
+ function createErrorAssembly() {
396
+ const group = new THREE.Group();
397
+ const coneGeo = new THREE.ConeGeometry(0.8, 1.5, 8);
398
+ group.add(createMesh(coneGeo, errorMaterial, { x: 0, y: 0.75, z: 0 }));
399
+ group.add(createGroundPlane());
400
+ return group;
401
+ }
402
+
403
+ function createCrossroadsAssembly() {
404
+ const group = new THREE.Group();
405
+ group.add(createGroundPlane(dirtMaterial, 30));
406
+ const poleGeo = new THREE.CylinderGeometry(0.1, 0.1, 3, 8);
407
+ group.add(createMesh(poleGeo, woodMaterial, { y: 1.5 }));
408
+ const signGeo = new THREE.BoxGeometry(1.5, 0.3, 0.05);
409
+ group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: 0.2 }, { y: Math.PI / 4 }));
410
+ group.add(createMesh(signGeo, woodMaterial, { y: 2.5, z: -0.2 }, { y: -Math.PI / 4 }));
411
+ const grassGeo = new THREE.ConeGeometry(0.2, 0.5, 6);
412
+ for (let i = 0; i < 20; i++) {
413
+ const x = (Math.random() - 0.5) * 15;
414
+ const z = (Math.random() - 0.5) * 15;
415
+ if (Math.abs(x) > 2 || Math.abs(z) > 2) {
416
+ group.add(createMesh(grassGeo, grassMaterial, { x, y: 0.25, z }, { y: Math.random() * Math.PI }));
417
+ }
418
+ }
419
+ const rockGeo = new THREE.SphereGeometry(0.3, 6, 6);
420
+ for (let i = 0; i < 10; i++) {
421
+ group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.15, z: (Math.random() - 0.5) * 10 }, { y: Math.random() * Math.PI }));
422
+ }
423
+ return group;
424
+ }
425
+
426
+ function createRollingHillsAssembly() {
427
+ const group = new THREE.Group();
428
+ const hillGeo = new THREE.PlaneGeometry(50, 50, 10, 10);
429
+ const hillMat = grassMaterial.clone();
430
+ const hill = new THREE.Mesh(hillGeo, hillMat);
431
+ hill.rotation.x = -Math.PI / 2;
432
+ hill.receiveShadow = true;
433
+ for (let i = 0; i < hillGeo.attributes.position.count; i++) {
434
+ const x = hillGeo.attributes.position.getX(i);
435
+ const z = hillGeo.attributes.position.getZ(i);
436
+ hillGeo.attributes.position.setY(i, Math.sin(x * 0.2 + z * 0.2) * 2);
437
+ }
438
+ hillGeo.computeVertexNormals();
439
+ group.add(hill);
440
+ const shepherdGeo = new THREE.CylinderGeometry(0.1, 0.1, 1, 8);
441
+ group.add(createMesh(shepherdGeo, darkWoodMaterial, { x: 10, y: 2, z: -15 }));
442
+ const grassGeo = new THREE.ConeGeometry(0.3, 0.7, 6);
443
+ for (let i = 0; i < 50; i++) {
444
+ group.add(createMesh(grassGeo, grassMaterial, { x: (Math.random() - 0.5) * 40, y: 0.35, z: (Math.random() - 0.5) * 40 }, { y: Math.random() * Math.PI }));
445
+ }
446
+ return group;
447
+ }
448
+
449
+ function createCoastalCliffsAssembly() {
450
+ const group = new THREE.Group();
451
+ const cliffGeo = new THREE.BoxGeometry(10, 5, 10);
452
+ group.add(createMesh(cliffGeo, stoneMaterial, { y: 2.5 }));
453
+ const pathGeo = new THREE.PlaneGeometry(1, 10);
454
+ const path = createMesh(pathGeo, dirtMaterial, { x: -2, y: 2, z: 0 }, { x: -Math.PI / 2, z: -Math.PI / 4 });
455
+ group.add(path);
456
+ const oceanGeo = new THREE.PlaneGeometry(100, 100);
457
+ const ocean = createMesh(oceanGeo, oceanMaterial, { y: -2 }, { x: -Math.PI / 2 });
458
+ ocean.receiveShadow = false;
459
+ ocean.userData.update = (time) => {
460
+ ocean.position.y = -2 + Math.sin(time * 0.5) * 0.1;
461
+ };
462
+ group.add(ocean);
463
+ return group;
464
+ }
465
+
466
+ function createForestEntranceAssembly() {
467
+ const group = createForestAssembly(20, 12);
468
+ const rootGeo = new THREE.TorusGeometry(0.5, 0.1, 8, 16);
469
+ for (let i = 0; i < 10; i++) {
470
+ group.add(createMesh(rootGeo, woodMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }, { x: Math.PI / 2 }));
471
+ }
472
+ return group;
473
+ }
474
+
475
+ function createOvergrownPathAssembly() {
476
+ const group = new THREE.Group();
477
+ group.add(createGroundPlane(dirtMaterial, 15));
478
+ const forest = createForestAssembly(15, 10);
479
+ group.add(forest);
480
+ const fungiGeo = new THREE.SphereGeometry(0.1, 8, 8);
481
+ for (let i = 0; i < 30; i++) {
482
+ group.add(createMesh(fungiGeo, glowMaterial, { x: (Math.random() - 0.5) * 8, y: 0.1, z: (Math.random() - 0.5) * 8 }));
483
+ }
484
+ const vineGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
485
+ for (let i = 0; i < 10; i++) {
486
+ group.add(createMesh(vineGeo, leafMaterial, { x: (Math.random() - 0.5) * 6, y: 2, z: (Math.random() - 0.5) * 6 }, { z: Math.random() * Math.PI }));
487
+ }
488
+ return group;
489
+ }
490
+
491
+ function createClearingStatueAssembly() {
492
+ const group = new THREE.Group();
493
+ group.add(createGroundPlane(grassMaterial, 10));
494
+ const statueGeo = new THREE.BoxGeometry(0.8, 2, 0.8);
495
+ group.add(createMesh(statueGeo, stoneMaterial, { y: 1 }));
496
+ const mossGeo = new THREE.SphereGeometry(0.2, 8, 8);
497
+ for (let i = 0; i < 10; i++) {
498
+ group.add(createMesh(mossGeo, grassMaterial, { x: (Math.random() - 0.5) * 0.8, y: 0.5 + Math.random(), z: (Math.random() - 0.5) * 0.8 }));
499
+ }
500
+ const leafGeo = new THREE.PlaneGeometry(0.1, 0.1);
501
+ for (let i = 0; i < 20; i++) {
502
+ group.add(createMesh(leafGeo, leafMaterial, { x: (Math.random() - 0.5) * 5, y: 0.05, z: (Math.random() - 0.5) * 5 }, { y: Math.random() * Math.PI }));
503
+ }
504
+ return group;
505
+ }
506
+
507
+ function createGoblinAmbushAssembly() {
508
+ const group = createOvergrownPathAssembly();
509
+ const bodyGeo = new THREE.CylinderGeometry(0.3, 0.3, 1, 8);
510
+ const headGeo = new THREE.SphereGeometry(0.2, 8, 8);
511
+ const goblinMat = new THREE.MeshStandardMaterial({ color: 0x556B2F });
512
+ for (let i = -1; i <= 1; i += 2) {
513
+ const goblin = new THREE.Group();
514
+ goblin.add(createMesh(bodyGeo, goblinMat, { y: 0.5 }));
515
+ goblin.add(createMesh(headGeo, goblinMat, { y: 1.2 }));
516
+ const spearGeo = new THREE.CylinderGeometry(0.05, 0.05, 2, 8);
517
+ goblin.add(createMesh(spearGeo, woodMaterial, { x: 0.3, y: 1, z: 0 }, { z: Math.PI / 4 }));
518
+ goblin.position.set(i * 2, 0, 2);
519
+ group.add(goblin);
520
+ }
521
+ return group;
522
+ }
523
+
524
+ function createHiddenCoveAssembly() {
525
+ const group = new THREE.Group();
526
+ group.add(createGroundPlane(sandMaterial, 15));
527
+ const caveGeo = new THREE.BoxGeometry(3, 2, 3);
528
+ group.add(createMesh(caveGeo, stoneMaterial, { z: -5, y: 1 }));
529
+ const rockGeo = new THREE.SphereGeometry(0.5, 6, 6);
530
+ for (let i = 0; i < 15; i++) {
531
+ group.add(createMesh(rockGeo, stoneMaterial, { x: (Math.random() - 0.5) * 10, y: 0.25, z: (Math.random() - 0.5) * 10 }));
532
+ }
533
+ const seaweedGeo = new THREE.ConeGeometry(0.2, 1, 6);
534
+ for (let i = 0; i < 10; i++) {
535
+ group.add(createMesh(seaweedGeo, leafMaterial, { x: (Math.random() - 0.5) * 8, y: 0.5, z: (Math.random() - 0.5) * 8 }));
536
+ }
537
+ return group;
538
+ }
539
+
540
+ function createDarkCaveAssembly() {
541
+ const group = new THREE.Group();
542
+ group.add(createGroundPlane(wetStoneMaterial, 10));
543
+ const wallGeo = new THREE.CylinderGeometry(3, 3, 5, 12, 1, true);
544
+ const wall = createMesh(wallGeo, stoneMaterial, { y: 2.5 }, { x: Math.PI / 2 });
545
+ wall.scale.set(1, 1, -1);
546
+ group.add(wall);
547
+ const dripGeo = new THREE.SphereGeometry(0.05, 8, 8);
548
+ for (let i = 0; i < 5; i++) {
549
+ const drip = createMesh(dripGeo, oceanMaterial, { x: (Math.random() - 0.5) * 2, y: 4, z: (Math.random() - 0.5) * 2 });
550
+ drip.userData.update = (time) => {
551
+ drip.position.y -= 0.1;
552
+ if (drip.position.y < 0) drip.position.y = 4;
553
+ };
554
+ group.add(drip);
555
+ }
556
+ return group;
557
+ }
558
+
559
+ // Game Data
560
+ const itemsData = {
561
+ "Flaming Sword":{type:"weapon", description:"A fiery blade"},
562
+ "Whispering Bow":{type:"weapon", description:"A silent bow"},
563
+ "Guardian Shield":{type:"armor", description:"A protective shield"},
564
+ "Healing Light Spell":{type:"spell", description:"Mends minor wounds"},
565
+ "Shield of Faith Spell":{type:"spell", description:"Temporary shield"},
566
+ "Binding Runes Scroll":{type:"spell", description:"Binds an enemy"},
567
+ "Secret Tunnel Map":{type:"quest", description:"Shows a hidden path"},
568
+ "Poison Daggers":{type:"weapon", description:"Daggers with poison"},
569
+ "Master Key":{type:"quest", description:"Unlocks many doors"},
570
+ "Crude Dagger":{type:"weapon", description:"A roughly made dagger."},
571
+ "Scout's Pouch":{type:"quest", description:"Contains odds and ends."}
572
+ };
573
+
574
+ const gameData = {
575
+ "1": { title: "The Crossroads", content: `<p>Dust swirls... Which path calls to you?</p>`, options: [ { text: "Enter the Shadowwood Forest (North)", next: 5 }, { text: "Head towards the Rolling Hills (East)", next: 2 }, { text: "Investigate the Coastal Cliffs (West)", next: 3 } ], illustration: "crossroads-signpost-sunny" },
576
+ "2": { title: "Rolling Hills", content: `<p>Verdant hills stretch before you... It feels peaceful...</p>`, options: [ { text: "Follow the narrow path", next: 4 }, { text: "Try to hail the distant shepherd (Charisma Check?)", next: 99 } ], illustration: "rolling-green-hills-shepherd-distance" },
577
+ "3": { title: "Coastal Cliffs Edge", content: `<p>You stand atop windswept cliffs... A precarious-looking path descends...</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 }, { text: "Scan the cliff face for easier routes (Wisdom Check)", check: { stat: 'wisdom', dc: 11, onFailure: 32 }, next: 33 } ], illustration: "windy-sea-cliffs-crashing-waves-path-down" },
578
+ "4": { title: "Hill Path Overlook", content: `<p>The path crests a hill... you see a small, overgrown shrine...</p>`, options: [ { text: "Investigate the overgrown shrine", next: 40 }, { text: "Continue towards the badlands", next: 41 } ], illustration: "hilltop-view-overgrown-shrine-wildflowers" },
579
+ "5": { title: "Shadowwood Entrance", content: `<p>Sunlight struggles to pierce the dense canopy... How do you proceed?</p>`, options: [ { text: "Follow the main, albeit overgrown, path", next: 6 }, { text: "Try to navigate through the lighter undergrowth", next: 7 }, { text: "Look for animal trails or signs of passage (Wisdom Check)", check: { stat: 'wisdom', dc: 10, onFailure: 6 }, next: 8 } ], illustration: "dark-forest-entrance-gnarled-roots-filtered-light" },
580
+ "6": { title: "Overgrown Forest Path", content: `<p>The path is barely visible... You hear a twig snap nearby!</p>`, options: [ { text: "Ready your weapon and investigate", next: 10 }, { text: "Attempt to hide quietly (Dexterity Check)", check: { stat: 'dexterity', dc: 11, onFailure: 10 }, next: 11 }, { text: "Call out cautiously", next: 10 } ], illustration: "overgrown-forest-path-glowing-fungi-vines" },
581
+ "7": { title: "Tangled Undergrowth", content: `<p>Pushing through ferns... You stumble upon a small clearing containing a moss-covered, weathered stone statue...</p>`, options: [ { text: "Examine the statue closely (Intelligence Check)", check: { stat: 'intelligence', dc: 13, onFailure: 71 }, next: 70 }, { text: "Ignore the statue and press on", next: 72 }, { text: "Leave a small offering (if possible)", next: 73 } ], illustration: "forest-clearing-mossy-statue-weathered-stone" },
582
+ "8": { title: "Hidden Game Trail", content: `<p>Your sharp eyes spot a faint trail... It leads towards a ravine spanned by a rickety rope bridge.</p><p>(+20 XP)</p>`, options: [ { text: "Risk crossing the rope bridge (Dexterity Check)", check: { stat: 'dexterity', dc: 10, onFailure: 81 }, next: 80 }, { text: "Search for another way across the ravine", next: 82 } ], illustration: "narrow-game-trail-forest-rope-bridge-ravine", reward: { xp: 20 } },
583
+ "10": { title: "Goblin Ambush!", content: `<p>Two scraggly goblins leap out, brandishing crude spears!</p>`, options: [ { text: "Fight the goblins!", next: 12 }, { text: "Attempt to dodge past them (Dexterity Check)", check: { stat: 'dexterity', dc: 13, onFailure: 10 }, next: 13 } ], illustration: "two-goblins-ambush-forest-path-spears" },
584
+ "11": { title: "Hidden Evasion", content: `<p>You melt into the shadows as the goblins blunder past.</p><p>(+30 XP)</p>`, options: [ { text: "Continue cautiously", next: 14 } ], illustration: "forest-shadows-hiding-goblins-walking-past", reward: { xp: 30 } },
585
+ "12": { title: "Ambush Victory!", content: `<p>You defeat the goblins! Found a Crude Dagger.</p><p>(+50 XP)</p>`, options: [ { text: "Press onward", next: 14 } ], illustration: "defeated-goblins-forest-path-loot", reward: { xp: 50, addItem: "Crude Dagger" } },
586
+ "13": { title: "Daring Escape", content: `<p>With surprising agility, you tumble past the goblins!</p><p>(+25 XP)</p>`, options: [ { text: "Keep running!", next: 14 } ], illustration: "blurred-motion-running-past-goblins-forest", reward: { xp: 25 } },
587
+ "14": { title: "Forest Stream Crossing", content: `<p>The path leads to a clear, shallow stream...</p>`, options: [ { text: "Wade across the stream", next: 16 }, { text: "Look for a drier crossing point (fallen log?)", next: 15 } ], illustration: "forest-stream-crossing-dappled-sunlight-stones" },
588
+ "15": { title: "Log Bridge", content: `<p>Further upstream, a large, mossy log spans the stream.</p>`, options: [ { text: "Cross carefully on the log (Dexterity Check)", check: { stat: 'dexterity', dc: 9, onFailure: 151 }, next: 16 }, { text: "Go back and wade instead", next: 14 } ], illustration: "mossy-log-bridge-over-forest-stream" },
589
+ "151": { title: "Splash!", content: `<p>You slip on the mossy log and tumble into the cold stream! You're soaked but unharmed.</p>`, options: [ { text: "Shake yourself off and continue", next: 16 } ], illustration: "character-splashing-into-stream-from-log" },
590
+ "16": { title: "Edge of the Woods", content: `<p>You emerge from the Shadowwood... Before you lie rocky foothills...</p>`, options: [ { text: "Begin the ascent into the foothills", next: 17 }, { text: "Scan the fortress from afar (Wisdom Check)", check: { stat: 'wisdom', dc: 14, onFailure: 17 }, next: 18 } ], illustration: "forest-edge-view-rocky-foothills-distant-mountain-fortress" },
591
+ "17": { title: "Rocky Foothills Path", content: `<p>The climb is arduous... The fortress looms larger now.</p>`, options: [ { text: "Continue the direct ascent", next: 19 }, { text: "Look for signs of a hidden trail (Wisdom Check)", check: { stat: 'wisdom', dc: 15, onFailure: 19 }, next: 20 } ], illustration: "climbing-rocky-foothills-path-fortress-closer" },
592
+ "18": { title: "Distant Observation", content: `<p>You notice what might be a less-guarded approach along the western ridge...</p><p>(+30 XP)</p>`, options: [ { text: "Take the main path into the foothills", next: 17 }, { text: "Attempt the western ridge approach", next: 21 } ], illustration: "zoomed-view-mountain-fortress-western-ridge", reward: { xp: 30 } },
593
+ "19": { title: "Blocked Pass", content: `<p>The main path is blocked by a recent rockslide!</p>`, options: [ { text: "Try to climb over (Strength Check)", check: { stat: 'strength', dc: 14, onFailure: 191 }, next: 190 }, { text: "Search for another way around", next: 192 } ], illustration: "rockslide-blocking-mountain-path-boulders" },
594
+ "20": { title: "Goat Trail", content: `<p>You discover a narrow trail barely wide enough for a mountain goat...</p><p>(+40 XP)</p>`, options: [ { text: "Follow the precarious goat trail", next: 22 } ], illustration: "narrow-goat-trail-mountainside-fortress-view", reward: { xp: 40 } },
595
+ "30": { title: "Hidden Cove", content: `<p>Your careful descent brings you to a secluded cove. A dark cave entrance is visible...</p><p>(+25 XP)</p>`, options: [ { text: "Explore the dark cave", next: 35 } ], illustration: "hidden-cove-beach-dark-cave-entrance", reward: { xp: 25 } },
596
+ "31": { title: "Tumbled Down", content: `<p>You lose your footing... landing hard on the sandy cove floor. You lose 5 HP. A dark cave entrance beckons.</p>`, options: [ { text: "Gingerly explore the dark cave", next: 35 } ], illustration: "character-fallen-at-bottom-of-cliff-path-cove", hpLoss: 5 },
597
+ "32": { title: "No Easier Path", content: `<p>You scan the cliffs intently but find no obviously easier routes.</p>`, options: [ { text: "Attempt the precarious descent (Dexterity Check)", check: { stat: 'dexterity', dc: 12, onFailure: 31 }, next: 30 } ], illustration: "scanning-sea-cliffs-no-other-paths-visible" },
598
+ "33": { title: "Smuggler's Steps?", content: `<p>Your keen eyes spot a series of barely visible handholds and steps carved into the rock...</p><p>(+15 XP)</p>`, options: [ { text: "Use the hidden steps (Easier Dex Check)", check: { stat: 'dexterity', dc: 8, onFailure: 31 }, next: 30 } ], illustration: "close-up-handholds-carved-in-cliff-face", reward: { xp: 15 } },
599
+ "35": { title: "Dark Cave", content: `<p>The cave smells of salt and decay. Water drips somewhere within.</p>`, options: [{ text: "Press deeper into the darkness", next: 99 } ], illustration: "dark-cave-entrance-dripping-water" },
600
+ "40": { title: "Overgrown Shrine", content: `<p>Wildflowers grow thick around a small stone shrine. It feels ancient and neglected.</p>`, options: [{ text: "Examine the carvings (Intelligence Check)", check:{stat:'intelligence', dc:11, onFailure: 401}, next: 400 } ], illustration: "overgrown-stone-shrine-wildflowers-close" },
601
+ "41": { title: "Rocky Badlands", content: `<p>The green hills give way to cracked earth and jagged rock formations under a harsh sun.</p>`, options: [{ text: "Scout ahead", next: 99 } ], illustration: "rocky-badlands-cracked-earth-harsh-sun" },
602
+ "70": { title: "Statue's Secret", content:"<p>Running your fingers over the mossy stone... found a Scout's Pouch!</p><p>(+40 XP)</p>", options: [{text:"Take the pouch and press on", next: 72}], illustration:"forest-clearing-mossy-statue-hidden-compartment", reward:{addItem: "Scout's Pouch", xp: 40}}, // Added reward object
603
+ "71": { title: "Just an Old Statue", content:"<p>Despite a careful examination, the statue appears to be just that – an old, weathered stone figure.</p>", options: [{text:"Ignore the statue and press on", next: 72}], illustration:"forest-clearing-mossy-statue-weathered-stone"},
604
+ "72": { title: "Back to the Thicket", content:"<p>Leaving the clearing, you push back into the undergrowth, eventually relocating the main path.</p>", options: [{text:"Continue along the main path", next: 6}], illustration:"pushing-through-forest-undergrowth"},
605
+ "73": { title: "A Small Offering", content:"<p>You place a small offering at the statue's base. You feel a subtle sense of approval.</p>", options: [{text:"Try to find the main path again", next: 72}], illustration:"forest-clearing-mossy-statue-offering"},
606
+ "80": { title: "Across the Ravine", content:"<p>You make your way carefully across the swaying rope bridge.</p><p>(+25 XP)</p>", options: [{text:"Continue following the game trail", next: 14}], illustration:"character-crossing-rope-bridge-safely", reward:{xp:25}},
607
+ "81": { title: "Bridge Collapse!", content:"<p>A rope snaps! The bridge lurches, sending you plunging into the ravine! You lose 10 HP.</p>", options: [{text:"Climb out and find another way", next: 82}], illustration:"rope-bridge-snapping-character-falling", hpLoss: 10},
608
+ "82": { title: "Ravine Detour", content:"<p>You find a place where a fallen log provides a safer way across.</p>", options: [{text:"Cross the log bridge and continue", next: 14}], illustration:"fallen-log-crossing-ravine"},
609
+ "190": { title: "Over the Rocks", content:"<p>With considerable effort, you manage to climb over the rockslide.</p><p>(+35 XP)</p>", options: [{text:"Continue up the path", next: 22}], illustration:"character-climbing-over-boulders", reward: {xp:35} },
610
+ "191": { title: "Climb Fails", content:"<p>The boulders are too unstable or sheer. You cannot climb them safely.</p>", options: [{text:"Search for another way around", next: 192}], illustration:"character-slipping-on-rockslide-boulders"},
611
+ "192": { title: "Detour Found", content:"<p>After some searching, you find a rough path leading around the rockslide, eventually rejoining the main trail.</p>", options: [{text:"Continue up the path", next: 22}], illustration:"rough-detour-path-around-rockslide"},
612
+ "21": { title: "Western Ridge", content:"<p>The ridge path is narrow and exposed, with strong winds threatening to push you off.</p>", options: [{text:"Proceed carefully (Dexterity Check)", check:{stat:'dexterity', dc: 14, onFailure: 211}, next: 22 } ], illustration:"narrow-windy-mountain-ridge-path" },
613
+ "22": { title: "Fortress Approach", content:"<p>You've navigated the treacherous paths and now stand near the outer walls of the dark fortress. Guards patrol the battlements.</p>", options: [{text:"Look for an unguarded entrance", next: 99}], illustration:"approaching-dark-fortress-walls-guards"}, // Simplified options for base code
614
+ "211": {title:"Lost Balance", content:"<p>A strong gust of wind catches you off guard, sending you tumbling down a steep slope! You lose 10 HP.</p>", options:[{text:"Climb back up and find another way", next: 17}], illustration:"character-falling-off-windy-ridge", hpLoss: 10},
615
+ "400": { title: "Shrine Insights", content:"<p>The carvings depict cycles of growth. You feel a sense of calm. (+1 HP)</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close", reward: {hpGain: 1}},
616
+ "401": { title: "Mysterious Carvings", content:"<p>The carvings are too worn to decipher.</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close"},
617
+ "402": { title: "Moment of Peace", content:"<p>You spend a quiet moment in reflection. The tranquility settles your nerves.</p>", options: [{text:"Continue towards the badlands", next: 41}], illustration: "overgrown-stone-shrine-wildflowers-close"},
618
+ "99": { title: "Game Over / To Be Continued...", content: "<p>Your adventure ends here (for now).</p>", options: [{ text: "Restart", next: 1 }], illustration: "game-over-generic", gameOver: true }
619
+ };
620
+
621
+ // Game State
622
+ let gameState = {
623
+ currentPageId: 1,
624
+ character: {
625
+ name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer",
626
+ level: 1, xp: 0, xpToNextLevel: 100,
627
+ stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 },
628
+ inventory: []
629
+ }
630
+ };
631
+
632
+ // Game Logic Functions
633
+ function startGame() {
634
+ // This function RESETS the game state fully
635
+ const defaultChar = {
636
+ name: "Hero", race: "Human", alignment: "Neutral Good", class: "Adventurer",
637
+ level: 1, xp: 0, xpToNextLevel: 100,
638
+ stats: { strength: 8, intelligence: 10, wisdom: 10, dexterity: 10, constitution: 10, charisma: 8, hp: 12, maxHp: 12 },
639
+ inventory: []
640
+ };
641
+ // Use deep copy for nested objects
642
+ gameState = { currentPageId: 1, character: JSON.parse(JSON.stringify(defaultChar)) };
643
+ console.log("Starting new game state:", gameState);
644
+ renderPage(gameState.currentPageId);
645
+ }
646
+
647
+ function handleChoiceClick(choiceData) {
648
+ console.log("Choice clicked:", choiceData);
649
+
650
+ // --- Handle Restart ---
651
+ // If the 'next' property is explicitly 1 (used by the restart button on page 99)
652
+ if (choiceData.nextPage === 1 && gameState.currentPageId === 99) {
653
+ console.log("Restarting game...");
654
+ startGame(); // Call the function that fully resets the game
655
+ return; // Stop processing this click further
656
+ }
657
+
658
+ // --- Standard Choice Processing ---
659
+ const optionNextPageId = parseInt(choiceData.nextPage);
660
+ const itemToAdd = choiceData.addItem;
661
+ let nextPageId = optionNextPageId;
662
+ let rollResultMessage = "";
663
+ const check = choiceData.check;
664
+
665
+ // --- Basic Validation ---
666
+ // Check if nextPage is NaN AND there's no skill check (meaning invalid choice data)
667
+ if (isNaN(nextPageId) && !check) {
668
+ console.error("Invalid choice data:", choiceData);
669
+ // Optionally go to an error page or just log and return
670
+ // Going to page 99 for safety
671
+ renderPageInternal(99, gameData[99], `<p style="color:red;">Error: Invalid choice data!</p>`);
672
+ return;
673
+ }
674
+
675
+ // --- Skill Check Logic ---
676
+ if (check) {
677
+ const statValue = gameState.character.stats[check.stat] || 10;
678
+ const modifier = Math.floor((statValue - 10) / 2);
679
+ const roll = Math.floor(Math.random() * 20) + 1;
680
+ const totalResult = roll + modifier;
681
+ const dc = check.dc;
682
+ console.log(`Check: ${check.stat} (DC ${dc}) | Roll: ${roll} + Mod: ${modifier} = ${totalResult}`);
683
+ if (totalResult >= dc) {
684
+ nextPageId = optionNextPageId; // Success path
685
+ rollResultMessage = `<p class="roll-success"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Success! (${totalResult} vs DC ${dc})</em></p>`;
686
+ } else {
687
+ nextPageId = parseInt(check.onFailure); // Failure path
688
+ rollResultMessage = `<p class="roll-failure"><em>${check.stat.charAt(0).toUpperCase() + check.stat.slice(1)} Check Failed! (${totalResult} vs DC ${dc})</em></p>`;
689
+ if (isNaN(nextPageId)) { // Handle invalid failure ID
690
+ console.error("Invalid onFailure ID:", check.onFailure);
691
+ nextPageId = 99;
692
+ rollResultMessage += `<p style="color:red;">Error: Invalid failure path ID!</p>`;
693
+ }
694
+ }
695
+ }
696
+
697
+ // --- Add Item from Choice Property (less common now) ---
698
+ if (itemToAdd && !gameState.character.inventory.includes(itemToAdd)) {
699
+ // Check if the item exists in itemsData before adding
700
+ if (itemsData[itemToAdd]) {
701
+ gameState.character.inventory.push(itemToAdd);
702
+ console.log("Added item via choice property:", itemToAdd);
703
+ } else {
704
+ console.warn(`Attempted to add unknown item from choice property: ${itemToAdd}`);
705
+ rollResultMessage += `<p style="color:orange;">Warning: Tried to add unknown item '${itemToAdd}'.</p>`;
706
+ }
707
+ }
708
+
709
+ // --- Get Target Page Data ---
710
+ const targetPageData = gameData[nextPageId];
711
+
712
+ if (!targetPageData) {
713
+ console.error(`Data for page ${nextPageId} not found!`);
714
+ renderPageInternal(99, gameData[99], `<p style="color:red;">Error: Page data for ${nextPageId} missing!</p>`);
715
+ return;
716
+ }
717
+
718
+ // --- Apply Page Consequences/Rewards ---
719
+ let hpLostThisTurn = 0;
720
+ if (targetPageData.hpLoss) {
721
+ hpLostThisTurn = targetPageData.hpLoss;
722
+ gameState.character.stats.hp -= hpLostThisTurn;
723
+ console.log(`Lost ${hpLostThisTurn} HP.`);
724
+ }
725
+ if (targetPageData.reward && targetPageData.reward.hpGain) { // Check for hpGain
726
+ const hpGained = targetPageData.reward.hpGain;
727
+ gameState.character.stats.hp += hpGained;
728
+ console.log(`Gained ${hpGained} HP.`);
729
+ // Clamping to maxHP happens later
730
+ }
731
+
732
+ // Check for death AFTER applying HP changes for the current turn
733
+ if (gameState.character.stats.hp <= 0) {
734
+ gameState.character.stats.hp = 0; // Don't go below 0
735
+ console.log("Player died!");
736
+ nextPageId = 99; // Force game over page
737
+ rollResultMessage += `<p style="color:red;"><em>You have succumbed to your injuries!${hpLostThisTurn > 0 ? ` (-${hpLostThisTurn} HP)` : ''}</em></p>`;
738
+ renderPageInternal(nextPageId, gameData[nextPageId], rollResultMessage); // Render immediately
739
+ return; // Stop further processing
740
+ }
741
+
742
+ // Apply other rewards if player is still alive
743
+ if (targetPageData.reward) {
744
+ if (targetPageData.reward.xp) {
745
+ gameState.character.xp += targetPageData.reward.xp;
746
+ console.log(`Gained ${targetPageData.reward.xp} XP! Total: ${gameState.character.xp}`);
747
+ // TODO: Implement level up check here
748
+ }
749
+ if (targetPageData.reward.statIncrease) {
750
+ const stat = targetPageData.reward.statIncrease.stat;
751
+ const amount = targetPageData.reward.statIncrease.amount;
752
+ if (gameState.character.stats.hasOwnProperty(stat)) {
753
+ gameState.character.stats[stat] += amount;
754
+ console.log(`Stat ${stat} increased by ${amount}.`);
755
+ if (stat === 'constitution') recalculateMaxHp(); // Recalculate if Con changed
756
+ }
757
+ }
758
+ if (targetPageData.reward.addItem && !gameState.character.inventory.includes(targetPageData.reward.addItem)) {
759
+ const itemName = targetPageData.reward.addItem;
760
+ if (itemsData[itemName]) { // Check item exists
761
+ gameState.character.inventory.push(itemName);
762
+ console.log(`Found item via reward: ${itemName}`);
763
+ rollResultMessage += `<p><em>Item acquired: ${itemName}</em></p>`;
764
+ } else {
765
+ console.warn(`Attempted to add unknown item from reward: ${itemName}`);
766
+ rollResultMessage += `<p style="color:orange;">Warning: Tried to add unknown reward item '${itemName}'.</p>`;
767
+ }
768
+ }
769
+ }
770
+
771
+ // --- Update Game State & Render ---
772
+ gameState.currentPageId = nextPageId; // Set the new current page ID
773
+ recalculateMaxHp(); // Recalculate max HP based on current stats/level
774
+ gameState.character.stats.hp = Math.min(gameState.character.stats.hp, gameState.character.stats.maxHp); // Clamp HP
775
+
776
+ console.log("Transitioning to page:", nextPageId);
777
+ renderPageInternal(nextPageId, gameData[nextPageId], rollResultMessage); // Render the next page
778
+ }
779
+
780
+ function recalculateMaxHp() {
781
+ const baseHp = 10; // Assuming level 1
782
+ const conModifier = Math.floor((gameState.character.stats.constitution - 10) / 2);
783
+ gameState.character.stats.maxHp = Math.max(1, baseHp + (conModifier * gameState.character.level));
784
+ console.log(`Max HP recalculated: ${gameState.character.stats.maxHp}`);
785
+ }
786
+
787
+ function renderPageInternal(pageId, pageData, message = "") {
788
+ if (!pageData) {
789
+ console.error(`Render Error: No data for page ${pageId}! Falling back to page 99.`);
790
+ pageData = gameData[99]; // Fallback to game over page
791
+ message += `<p style="color:red;">Render Error: Data for page ${pageId} not found!</p>`;
792
+ pageId = 99; // Ensure we use 99 if data was missing
793
+ }
794
+
795
+ console.log(`Rendering page ${pageId}`);
796
+ storyTitleElement.textContent = pageData.title || "Untitled Page";
797
+ storyContentElement.innerHTML = message + (pageData.content || "<p>...</p>");
798
+ updateStatsDisplay();
799
+ updateInventoryDisplay();
800
+ choicesElement.innerHTML = '';
801
+
802
+ if (pageData.options && pageData.options.length > 0) {
803
+ pageData.options.forEach(option => {
804
+ const button = document.createElement('button');
805
+ button.classList.add('choice-button');
806
+ button.textContent = option.text;
807
+ let requirementMet = true;
808
+ let requirementText = []; // Store unmet requirements text
809
+
810
+ // Check requirements (e.g., item needed)
811
+ if (option.requireItem && !gameState.character.inventory.includes(option.requireItem)) {
812
+ requirementMet = false;
813
+ requirementText.push(`Requires: ${option.requireItem}`);
814
+ }
815
+ // TODO: Add other requirement checks (stats, flags) here
816
+
817
+ button.disabled = !requirementMet;
818
+ if (!requirementMet) {
819
+ button.title = requirementText.join(', '); // Show requirements on hover
820
+ } else {
821
+ // Pass page ID directly in choiceData for handleChoiceClick
822
+ const choiceData = { nextPage: option.next, addItem: option.addItem, check: option.check };
823
+ button.onclick = () => handleChoiceClick(choiceData);
824
+ }
825
+ choicesElement.appendChild(button);
826
+ });
827
+ } else { // No options defined - End of branch or Game Over
828
+ const button = document.createElement('button');
829
+ button.classList.add('choice-button');
830
+ button.textContent = pageData.gameOver ? "Restart Adventure" : "The End (Restart?)";
831
+ // Restart button always goes to page 1, triggering the startGame logic
832
+ button.onclick = () => handleChoiceClick({ nextPage: 1 }); // Use nextPage: 1 for restart
833
+ choicesElement.appendChild(button);
834
+ if (!pageData.gameOver) {
835
+ choicesElement.insertAdjacentHTML('afterbegin', '<p><i>The path ends here.</i></p>');
836
+ }
837
+ }
838
+ updateScene(pageData.illustration || 'default');
839
+ }
840
+
841
+ function renderPage(pageId) {
842
+ renderPageInternal(pageId, gameData[pageId]);
843
+ }
844
+
845
+ function updateStatsDisplay() {
846
+ const char=gameState.character;
847
+ statsElement.innerHTML = `<strong>Stats:</strong> <span>Lvl: ${char.level}</span> <span>XP: ${char.xp}/${char.xpToNextLevel}</span> <span>HP: ${char.stats.hp}/${char.stats.maxHp}</span> <span>Str: ${char.stats.strength}</span> <span>Int: ${char.stats.intelligence}</span> <span>Wis: ${char.stats.wisdom}</span> <span>Dex: ${char.stats.dexterity}</span> <span>Con: ${char.stats.constitution}</span> <span>Cha: ${char.stats.charisma}</span>`;
848
+ }
849
+
850
+ function updateInventoryDisplay() {
851
+ let h='<strong>Inventory:</strong> ';
852
+ if(gameState.character.inventory.length === 0){
853
+ h+='<em>Empty</em>';
854
+ } else {
855
+ gameState.character.inventory.forEach(i=>{
856
+ const d=itemsData[i]||{type:'unknown',description:'???'};
857
+ const c=`item-${d.type||'unknown'}`;
858
+ h+=`<span class="${c}" title="${d.description}">${i}</span>`;
859
+ });
860
+ }
861
+ inventoryElement.innerHTML = h;
862
+ }
863
+
864
+ function updateScene(illustrationKey) {
865
+ if (!scene) return; // Guard clause
866
+ if (currentAssemblyGroup) {
867
+ scene.remove(currentAssemblyGroup);
868
+ // Basic disposal
869
+ currentAssemblyGroup.traverse(child => {
870
+ if (child.isMesh) {
871
+ child.geometry.dispose();
872
+ // Avoid disposing shared materials
873
+ }
874
+ });
875
+ currentAssemblyGroup = null;
876
+ }
877
+ scene.fog = null;
878
+ scene.background = new THREE.Color(0x222222);
879
+ camera.position.set(0, 2.5, 7);
880
+ camera.lookAt(0, 0.5, 0);
881
+
882
+ let assemblyFunction;
883
+ switch (illustrationKey) {
884
+ case 'city-gates': assemblyFunction = createCityGatesAssembly; break;
885
+ case 'weaponsmith': assemblyFunction = createWeaponsmithAssembly; break;
886
+ case 'temple': assemblyFunction = createTempleAssembly; break;
887
+ case 'resistance-meeting': assemblyFunction = createResistanceMeetingAssembly; break;
888
+ case 'shadowwood-forest': assemblyFunction = createForestAssembly; break;
889
+ case 'road-ambush': assemblyFunction = createRoadAmbushAssembly; break;
890
+ case 'forest-edge': assemblyFunction = createForestEdgeAssembly; break;
891
+ case 'prisoner-cell': assemblyFunction = createPrisonerCellAssembly; break;
892
+ case 'game-over': case 'game-over-generic': assemblyFunction = createGameOverAssembly; break;
893
+ case 'error': assemblyFunction = createErrorAssembly; break;
894
+ case 'crossroads-signpost-sunny': scene.fog = new THREE.Fog(0x87CEEB, 10, 30); scene.background = new THREE.Color(0x87CEEB); camera.position.set(0, 3, 10); camera.lookAt(0, 1, 0); assemblyFunction = createCrossroadsAssembly; break;
895
+ case 'rolling-green-hills-shepherd-distance': scene.fog = new THREE.Fog(0xA8E4A0, 15, 50); camera.position.set(0, 5, 15); camera.lookAt(0, 2, -5); assemblyFunction = createRollingHillsAssembly; break;
896
+ case 'windy-sea-cliffs-crashing-waves-path-down': scene.fog = new THREE.Fog(0x6699CC, 10, 40); scene.background = new THREE.Color(0x6699CC); camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5); assemblyFunction = createCoastalCliffsAssembly; break;
897
+ case 'dark-forest-entrance-gnarled-roots-filtered-light': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(0, 2, 8); camera.lookAt(0, 1, 0); assemblyFunction = createForestEntranceAssembly; break;
898
+ case 'overgrown-forest-path-glowing-fungi-vines': scene.fog = new THREE.Fog(0x1A2F2A, 3, 15); camera.position.set(0, 1.5, 6); camera.lookAt(0, 0.5, 0); assemblyFunction = createOvergrownPathAssembly; break;
899
+ case 'forest-clearing-mossy-statue-weathered-stone': case 'forest-clearing-mossy-statue-hidden-compartment': case 'forest-clearing-mossy-statue-offering': scene.fog = new THREE.Fog(0x2E4F3A, 5, 25); camera.position.set(0, 2, 5); camera.lookAt(0, 1, 0); assemblyFunction = createClearingStatueAssembly; break;
900
+ case 'two-goblins-ambush-forest-path-spears': case 'forest-shadows-hiding-goblins-walking-past': case 'defeated-goblins-forest-path-loot': case 'blurred-motion-running-past-goblins-forest': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(0, 2, 7); camera.lookAt(0, 1, 0); assemblyFunction = createGoblinAmbushAssembly; break;
901
+ case 'hidden-cove-beach-dark-cave-entrance': case 'character-fallen-at-bottom-of-cliff-path-cove': scene.fog = new THREE.Fog(0x336699, 5, 30); scene.background = new THREE.Color(0x336699); camera.position.set(0, 2, 8); camera.lookAt(0, 1, -2); assemblyFunction = createHiddenCoveAssembly; break;
902
+ case 'dark-cave-entrance-dripping-water': scene.fog = new THREE.Fog(0x1A1A1A, 2, 10); scene.background = new THREE.Color(0x1A1A1A); camera.position.set(0, 1.5, 4); camera.lookAt(0, 1, 0); assemblyFunction = createDarkCaveAssembly; break;
903
+ case 'hilltop-view-overgrown-shrine-wildflowers': scene.fog = new THREE.Fog(0xA8E4A0, 15, 50); camera.position.set(0, 5, 15); camera.lookAt(0, 2, -5); assemblyFunction = createRollingHillsAssembly; break; // Added missing case from data
904
+ case 'character-splashing-into-stream-from-log': scene.fog = new THREE.Fog(0x668866, 8, 25); camera.position.set(0, 2, 6); camera.lookAt(0, 0.5, 0); assemblyFunction = createForestAssembly; break; // Added missing case
905
+ case 'forest-stream-crossing-dappled-sunlight-stones': scene.fog = new THREE.Fog(0x668866, 8, 25); camera.position.set(0, 2, 6); camera.lookAt(0, 0.5, 0); assemblyFunction = createForestAssembly; break;// Added missing case
906
+ case 'mossy-log-bridge-over-forest-stream': scene.fog = new THREE.Fog(0x668866, 8, 25); camera.position.set(1, 2, 5); camera.lookAt(-1, 0.5, 0); assemblyFunction = createForestAssembly; break;// Added missing case
907
+ case 'forest-edge-view-rocky-foothills-distant-mountain-fortress': scene.fog = new THREE.Fog(0xAAAAAA, 10, 40); camera.position.set(0, 3, 10); camera.lookAt(0, 1, -5); assemblyFunction = createForestEdgeAssembly; break;// Added missing case
908
+ case 'climbing-rocky-foothills-path-fortress-closer': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
909
+ case 'zoomed-view-mountain-fortress-western-ridge': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(5, 6, 12); camera.lookAt(-2, 3, -5); assemblyFunction = createDefaultAssembly; break;// Added missing case
910
+ case 'rockslide-blocking-mountain-path-boulders': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
911
+ case 'narrow-goat-trail-mountainside-fortress-view': scene.fog = new THREE.Fog(0x778899, 5, 30); camera.position.set(1, 3, 6); camera.lookAt(0, 2, -2); assemblyFunction = createDefaultAssembly; break;// Added missing case
912
+ case 'character-climbing-over-boulders': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
913
+ case 'character-slipping-on-rockslide-boulders': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
914
+ case 'rough-detour-path-around-rockslide': scene.fog = new THREE.Fog(0x778899, 8, 35); camera.position.set(0, 4, 9); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
915
+ case 'narrow-windy-mountain-ridge-path': scene.fog = new THREE.Fog(0x8899AA, 6, 25); camera.position.set(2, 5, 7); camera.lookAt(0, 3, -3); assemblyFunction = createDefaultAssembly; break;// Added missing case
916
+ case 'approaching-dark-fortress-walls-guards': scene.fog = new THREE.Fog(0x444455, 5, 20); camera.position.set(0, 3, 8); camera.lookAt(0, 2, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
917
+ case 'character-falling-off-windy-ridge': scene.fog = new THREE.Fog(0x8899AA, 6, 25); camera.position.set(2, 5, 7); camera.lookAt(0, 3, -3); assemblyFunction = createDefaultAssembly; break;// Added missing case
918
+ case 'scanning-sea-cliffs-no-other-paths-visible': scene.fog = new THREE.Fog(0x6699CC, 10, 40); scene.background = new THREE.Color(0x6699CC); camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5); assemblyFunction = createCoastalCliffsAssembly; break;// Added missing case
919
+ case 'close-up-handholds-carved-in-cliff-face': scene.fog = new THREE.Fog(0x6699CC, 10, 40); scene.background = new THREE.Color(0x6699CC); camera.position.set(5, 5, 10); camera.lookAt(-2, 0, -5); assemblyFunction = createCoastalCliffsAssembly; break;// Added missing case
920
+ case 'overgrown-stone-shrine-wildflowers-close': scene.fog = new THREE.Fog(0xA8E4A0, 15, 50); camera.position.set(1, 2, 4); camera.lookAt(0, 0.5, 0); assemblyFunction = createRollingHillsAssembly; break;// Added missing case
921
+ case 'rocky-badlands-cracked-earth-harsh-sun': scene.fog = new THREE.Fog(0xD2B48C, 15, 40); scene.background = new THREE.Color(0xCD853F); camera.position.set(0, 3, 12); camera.lookAt(0, 1, 0); assemblyFunction = createDefaultAssembly; break;// Added missing case
922
+ case 'pushing-through-forest-undergrowth': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(0, 1.5, 5); camera.lookAt(0, 1, 0); assemblyFunction = createForestAssembly; break;// Added missing case
923
+ case 'narrow-game-trail-forest-rope-bridge-ravine': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2); assemblyFunction = createForestAssembly; break;// Added missing case
924
+ case 'character-crossing-rope-bridge-safely': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2); assemblyFunction = createForestAssembly; break;// Added missing case
925
+ case 'rope-bridge-snapping-character-falling': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2); assemblyFunction = createForestAssembly; break;// Added missing case
926
+ case 'fallen-log-crossing-ravine': scene.fog = new THREE.Fog(0x2E2E2E, 5, 20); camera.position.set(2, 3, 6); camera.lookAt(0, -1, -2); assemblyFunction = createForestAssembly; break;// Added missing case
927
+
928
+ default:
929
+ console.warn(`Unknown illustration key: "${illustrationKey}". Using default.`);
930
+ assemblyFunction = createDefaultAssembly; break;
931
+ }
932
+ try {
933
+ currentAssemblyGroup = assemblyFunction();
934
+ if (currentAssemblyGroup && currentAssemblyGroup.isGroup) { // Check it's a group
935
+ scene.add(currentAssemblyGroup);
936
+ adjustLighting(illustrationKey);
937
+ } else {
938
+ throw new Error("Assembly function failed to return a valid THREE.Group");
939
+ }
940
+ } catch (error) {
941
+ console.error(`Error creating assembly for ${illustrationKey}:`, error);
942
+ if (currentAssemblyGroup) { scene.remove(currentAssemblyGroup); } // Try cleanup
943
+ currentAssemblyGroup = createErrorAssembly();
944
+ scene.add(currentAssemblyGroup);
945
+ adjustLighting('error');
946
+ }
947
+ }
948
+
949
+ function adjustLighting(illustrationKey) { // Unchanged
950
+ if (!scene) return;
951
+ scene.children.forEach(child => { if (child.isLight && child !== scene.children.find(c => c.isAmbientLight)) { scene.remove(child); } });
952
+ const ambient = scene.children.find(c => c.isAmbientLight);
953
+ if (!ambient) { console.warn("Ambient light missing!"); return; } // Added guard
954
+ let directionalLight;
955
+ switch (illustrationKey) {
956
+ case 'crossroads-signpost-sunny': ambient.intensity = 0.8; directionalLight = new THREE.DirectionalLight(0xFFF8E1, 1.5); directionalLight.position.set(10, 15, 10); break;
957
+ case 'dark-forest-entrance-gnarled-roots-filtered-light': case 'overgrown-forest-path-glowing-fungi-vines': ambient.intensity = 0.3; directionalLight = new THREE.DirectionalLight(0xA8E4A0, 0.6); directionalLight.position.set(5, 10, 5); break;
958
+ case 'dark-cave-entrance-dripping-water': ambient.intensity = 0.1; directionalLight = new THREE.DirectionalLight(0x666666, 0.2); directionalLight.position.set(2, 5, 2); break;
959
+ default: ambient.intensity = 0.5; directionalLight = new THREE.DirectionalLight(0xffffff, 1.2); directionalLight.position.set(8, 15, 10);
960
+ }
961
+ if (!directionalLight) { // Ensure light is created
962
+ console.warn("Directional light not set for key:", illustrationKey, ". Using default.");
963
+ ambient.intensity = 0.5; directionalLight = new THREE.DirectionalLight(0xffffff, 1.2); directionalLight.position.set(8, 15, 10);
964
+ }
965
+ directionalLight.castShadow = true;
966
+ directionalLight.shadow.mapSize.set(1024, 1024);
967
+ directionalLight.shadow.camera.near = 0.5; directionalLight.shadow.camera.far = 50;
968
+ directionalLight.shadow.camera.left = -15; directionalLight.shadow.camera.right = 15;
969
+ directionalLight.shadow.camera.top = 15; directionalLight.shadow.camera.bottom = -15;
970
+ scene.add(directionalLight);
971
+ }
972
+
973
+ // Initialization
974
+ document.addEventListener('DOMContentLoaded', () => {
975
+ console.log("DOM Ready.");
976
+ try {
977
+ initThreeJS(); // Initialize Three.js first
978
+ if (!scene || !camera || !renderer) { // Check if init failed
979
+ throw new Error("Three.js initialization failed.");
980
+ }
981
+ startGame(); // Start game logic
982
+ console.log("Game started.");
983
+ } catch (error) {
984
+ console.error("Initialization failed:", error);
985
+ storyTitleElement.textContent = "Error During Initialization";
986
+ storyContentElement.innerHTML = `<p>Could not start the adventure. Please check the developer console (F12) for more details.</p><pre>${error.stack || error}</pre>`;
987
+ choicesElement.innerHTML = ''; // Clear choices on error
988
+ if(sceneContainer) sceneContainer.innerHTML = ''; // Clear scene on error
989
+ }
990
+ });
991
+ </script>
992
+ </body>
993
+ </html>