Polish friends, Dark daylight, craft UI, and cauldron soft claims.
Blink Friends on incoming requests, hide claimed dye/potion mats from the bag picker, reserve craft status/progress space, dim daylight inside Dark pools, and translate the dye bottle warning to British English.
@@ -269,7 +269,7 @@
269
269
</div>
270
270
<ul id="craft-inputs" class="craft-inputs"></ul>
271
271
<p id="craft-status" class="hint"></p>
272
<div id="craft-progress" class="craft-progress" hidden>
272
<div id="craft-progress" class="craft-progress">
273
273
<div id="craft-progress-fill" class="craft-progress-fill"></div>
274
274
</div>
275
275
<div id="craft-actions" class="craft-actions">
@@ -269,7 +269,7 @@269
</div>269
</div>270
<ul id="craft-inputs" class="craft-inputs"></ul>270
<ul id="craft-inputs" class="craft-inputs"></ul>271
<p id="craft-status" class="hint"></p>271
<p id="craft-status" class="hint"></p>272
<div id="craft-progress" class="craft-progress" hidden>272
<div id="craft-progress" class="craft-progress">273
<div id="craft-progress-fill" class="craft-progress-fill"></div>273
<div id="craft-progress-fill" class="craft-progress-fill"></div>274
</div>274
</div>275
<div id="craft-actions" class="craft-actions">275
<div id="craft-actions" class="craft-actions">@@ -56,6 +56,7 @@ export function initAlchemy ({
56
56
let pickItemId = null;
57
57
let pickInstance = null;
58
58
let pendingDyeConfirm = null;
59
let onSoftClaimsChanged = null;
59
60
60
61
function emptyAlchemySlots ()
61
62
{
@@ -67,6 +68,62 @@ export function initAlchemy ({
67
68
return Array.from({ length: DYE_CAULDRON_SLOT_COUNT }, () => null);
68
69
}
69
70
71
function sameClaimInstance (a, b)
72
{
73
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
74
}
75
76
/** Soft claims: local UI slots + server brew pending (still in bag). */
77
function listSoftClaims ({ excludeMode = null, excludeSlotIndex = null } = {})
78
{
79
const claims = [];
80
const push = (slot) =>
81
{
82
if (!slot?.itemId || !(slot.quantity > 0))
83
{ return; }
84
claims.push({
85
itemId: slot.itemId | 0,
86
quantity: slot.quantity | 0,
87
instance: slot.instance ? structuredClone(slot.instance) : null
88
});
89
};
90
for (let i = 0; i < localSlots.length; i++)
91
{
92
if (excludeMode === "alchemy" && excludeSlotIndex === i)
93
{ continue; }
94
push(localSlots[i]);
95
}
96
for (let i = 0; i < localDyeSlots.length; i++)
97
{
98
if (excludeMode === "dye" && excludeSlotIndex === i)
99
{ continue; }
100
push(localDyeSlots[i]);
101
}
102
for (const row of state?.brew ?? [])
103
{ push(row); }
104
return claims;
105
}
106
107
function claimedQuantityFor (itemId, instance, opts = {})
108
{
109
const id = itemId | 0;
110
let total = 0;
111
for (const claim of listSoftClaims(opts))
112
{
113
if ((claim.itemId | 0) !== id)
114
{ continue; }
115
if (id === ItemId.flower && !sameClaimInstance(claim.instance, instance))
116
{ continue; }
117
total += claim.quantity | 0;
118
}
119
return total;
120
}
121
122
function notifySoftClaimsChanged ()
123
{
124
onSoftClaimsChanged?.();
125
}
126
70
127
function flowerPayload ()
71
128
{
72
129
return localDyeSlots
@@ -246,6 +303,7 @@ export function initAlchemy ({
246
303
});
247
304
localSlots[i] = null;
248
305
render();
306
notifySoftClaimsChanged();
249
307
});
250
308
insertsEl.append(insertBtn);
251
309
}
@@ -327,6 +385,18 @@ export function initAlchemy ({
327
385
}
328
386
for (const entry of counts.values())
329
387
{
388
entry.quantity = Math.max(
389
0,
390
(entry.quantity | 0) - claimedQuantityFor(entry.itemId, entry.instance, {
391
excludeMode: mode,
392
excludeSlotIndex: slotIndex
393
})
394
);
395
}
396
for (const entry of counts.values())
397
{
398
if (!(entry.quantity > 0))
399
{ continue; }
330
400
const stack = {
331
401
itemId: entry.itemId,
332
402
quantity: entry.quantity,
@@ -376,7 +446,31 @@ export function initAlchemy ({
376
446
if (pickSlotIndex == null || pickItemId == null)
377
447
{ return; }
378
448
const rawQty = Math.max(1, pickQty.value | 0);
379
const quantity = pickMode === "dye" ? Math.min(rawQty, FLOWER_MAX_STACK) : rawQty;
449
const available = claimedQuantityFor
450
? Math.max(0, (() =>
451
{
452
let bagQty = 0;
453
for (const slot of getInventorySlots?.() ?? [])
454
{
455
if (!slot || (slot.itemId | 0) !== (pickItemId | 0))
456
{ continue; }
457
if (pickItemId === ItemId.flower && !sameClaimInstance(slot.instance, pickInstance))
458
{ continue; }
459
bagQty += slot.quantity | 0;
460
}
461
return bagQty - claimedQuantityFor(pickItemId, pickInstance, {
462
excludeMode: pickMode,
463
excludeSlotIndex: pickSlotIndex
464
});
465
})())
466
: rawQty;
467
const quantity = Math.min(
468
rawQty,
469
available,
470
pickMode === "dye" ? FLOWER_MAX_STACK : available
471
);
472
if (quantity <= 0)
473
{ return; }
380
474
const entry = {
381
475
itemId: pickItemId,
382
476
quantity,
@@ -388,6 +482,7 @@ export function initAlchemy ({
388
482
{ localSlots[pickSlotIndex] = entry; }
389
483
closePick();
390
484
render();
485
notifySoftClaimsChanged();
391
486
}
392
487
393
488
function openDyeConfirm (confirm)
@@ -395,7 +490,7 @@ export function initAlchemy ({
395
490
pendingDyeConfirm = confirm;
396
491
const wanted = confirm.wanted | 0;
397
492
const bottles = confirm.bottles | 0;
398
confirmText.textContent = `Je staat op het punt ${wanted} units aan dye te maken, maar je hebt maar genoeg lege flesjes om ${bottles} op te slaan. De rest gaat verloren. Weet je het zeker?`;
493
confirmText.textContent = `You are about to make ${wanted} units of dye, but you only have enough empty bottles for ${bottles}. The rest will be lost. Are you sure?`;
399
494
confirmBackdrop.hidden = false;
400
495
confirmPanel.hidden = false;
401
496
}
@@ -435,6 +530,7 @@ export function initAlchemy ({
435
530
closePick();
436
531
closeDyeConfirm();
437
532
socket.send({ type: MessageType.cauldronClose });
533
notifySoftClaimsChanged();
438
534
}
439
535
440
536
return {
@@ -449,6 +545,11 @@ export function initAlchemy ({
449
545
return open;
450
546
},
451
547
close,
548
listSoftClaims,
549
setOnSoftClaimsChanged (fn)
550
{
551
onSoftClaimsChanged = typeof fn === "function" ? fn : null;
552
},
452
553
reset ()
453
554
{
454
555
open = false;
@@ -461,6 +562,7 @@ export function initAlchemy ({
461
562
{ panel.hidden = true; }
462
563
closePick();
463
564
closeDyeConfirm();
565
notifySoftClaimsChanged();
464
566
},
465
567
handleSnapshot (message)
466
568
{
@@ -475,6 +577,7 @@ export function initAlchemy ({
475
577
localSlots = emptyAlchemySlots();
476
578
localDyeSlots = emptyDyeSlots();
477
579
closeDyeConfirm();
580
notifySoftClaimsChanged();
478
581
return;
479
582
}
480
583
if (!open)
@@ -484,6 +587,7 @@ export function initAlchemy ({
484
587
state = message.state;
485
588
render();
486
589
}
590
notifySoftClaimsChanged();
487
591
if (message.dyeConfirm)
488
592
{ openDyeConfirm(message.dyeConfirm); }
489
593
if (message.alchemyResult)
@@ -56,6 +56,7 @@ export function initAlchemy ({56
let pickItemId = null;56
let pickItemId = null;57
let pickInstance = null;57
let pickInstance = null;58
let pendingDyeConfirm = null;58
let pendingDyeConfirm = null;59
let onSoftClaimsChanged = null;59
60
60
function emptyAlchemySlots ()61
function emptyAlchemySlots ()61
{62
{@@ -67,6 +68,62 @@ export function initAlchemy ({67
return Array.from({ length: DYE_CAULDRON_SLOT_COUNT }, () => null);68
return Array.from({ length: DYE_CAULDRON_SLOT_COUNT }, () => null);68
}69
}69
70
71
function sameClaimInstance (a, b)72
{73
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);74
}75
76
/** Soft claims: local UI slots + server brew pending (still in bag). */77
function listSoftClaims ({ excludeMode = null, excludeSlotIndex = null } = {})78
{79
const claims = [];80
const push = (slot) =>81
{82
if (!slot?.itemId || !(slot.quantity > 0))83
{ return; }84
claims.push({85
itemId: slot.itemId | 0,86
quantity: slot.quantity | 0,87
instance: slot.instance ? structuredClone(slot.instance) : null88
});89
};90
for (let i = 0; i < localSlots.length; i++)91
{92
if (excludeMode === "alchemy" && excludeSlotIndex === i)93
{ continue; }94
push(localSlots[i]);95
}96
for (let i = 0; i < localDyeSlots.length; i++)97
{98
if (excludeMode === "dye" && excludeSlotIndex === i)99
{ continue; }100
push(localDyeSlots[i]);101
}102
for (const row of state?.brew ?? [])103
{ push(row); }104
return claims;105
}106
107
function claimedQuantityFor (itemId, instance, opts = {})108
{109
const id = itemId | 0;110
let total = 0;111
for (const claim of listSoftClaims(opts))112
{113
if ((claim.itemId | 0) !== id)114
{ continue; }115
if (id === ItemId.flower && !sameClaimInstance(claim.instance, instance))116
{ continue; }117
total += claim.quantity | 0;118
}119
return total;120
}121
122
function notifySoftClaimsChanged ()123
{124
onSoftClaimsChanged?.();125
}126
70
function flowerPayload ()127
function flowerPayload ()71
{128
{72
return localDyeSlots129
return localDyeSlots@@ -246,6 +303,7 @@ export function initAlchemy ({246
});303
});247
localSlots[i] = null;304
localSlots[i] = null;248
render();305
render();306
notifySoftClaimsChanged();249
});307
});250
insertsEl.append(insertBtn);308
insertsEl.append(insertBtn);251
}309
}@@ -327,6 +385,18 @@ export function initAlchemy ({327
}385
}328
for (const entry of counts.values())386
for (const entry of counts.values())329
{387
{388
entry.quantity = Math.max(389
0,390
(entry.quantity | 0) - claimedQuantityFor(entry.itemId, entry.instance, {391
excludeMode: mode,392
excludeSlotIndex: slotIndex393
})394
);395
}396
for (const entry of counts.values())397
{398
if (!(entry.quantity > 0))399
{ continue; }330
const stack = {400
const stack = {331
itemId: entry.itemId,401
itemId: entry.itemId,332
quantity: entry.quantity,402
quantity: entry.quantity,@@ -376,7 +446,31 @@ export function initAlchemy ({376
if (pickSlotIndex == null || pickItemId == null)446
if (pickSlotIndex == null || pickItemId == null)377
{ return; }447
{ return; }378
const rawQty = Math.max(1, pickQty.value | 0);448
const rawQty = Math.max(1, pickQty.value | 0);379
const quantity = pickMode === "dye" ? Math.min(rawQty, FLOWER_MAX_STACK) : rawQty;449
const available = claimedQuantityFor450
? Math.max(0, (() =>451
{452
let bagQty = 0;453
for (const slot of getInventorySlots?.() ?? [])454
{455
if (!slot || (slot.itemId | 0) !== (pickItemId | 0))456
{ continue; }457
if (pickItemId === ItemId.flower && !sameClaimInstance(slot.instance, pickInstance))458
{ continue; }459
bagQty += slot.quantity | 0;460
}461
return bagQty - claimedQuantityFor(pickItemId, pickInstance, {462
excludeMode: pickMode,463
excludeSlotIndex: pickSlotIndex464
});465
})())466
: rawQty;467
const quantity = Math.min(468
rawQty,469
available,470
pickMode === "dye" ? FLOWER_MAX_STACK : available471
);472
if (quantity <= 0)473
{ return; }380
const entry = {474
const entry = {381
itemId: pickItemId,475
itemId: pickItemId,382
quantity,476
quantity,@@ -388,6 +482,7 @@ export function initAlchemy ({388
{ localSlots[pickSlotIndex] = entry; }482
{ localSlots[pickSlotIndex] = entry; }389
closePick();483
closePick();390
render();484
render();485
notifySoftClaimsChanged();391
}486
}392
487
393
function openDyeConfirm (confirm)488
function openDyeConfirm (confirm)@@ -395,7 +490,7 @@ export function initAlchemy ({395
pendingDyeConfirm = confirm;490
pendingDyeConfirm = confirm;396
const wanted = confirm.wanted | 0;491
const wanted = confirm.wanted | 0;397
const bottles = confirm.bottles | 0;492
const bottles = confirm.bottles | 0;398
confirmText.textContent = `Je staat op het punt ${wanted} units aan dye te maken, maar je hebt maar genoeg lege flesjes om ${bottles} op te slaan. De rest gaat verloren. Weet je het zeker?`;493
confirmText.textContent = `You are about to make ${wanted} units of dye, but you only have enough empty bottles for ${bottles}. The rest will be lost. Are you sure?`;399
confirmBackdrop.hidden = false;494
confirmBackdrop.hidden = false;400
confirmPanel.hidden = false;495
confirmPanel.hidden = false;401
}496
}@@ -435,6 +530,7 @@ export function initAlchemy ({435
closePick();530
closePick();436
closeDyeConfirm();531
closeDyeConfirm();437
socket.send({ type: MessageType.cauldronClose });532
socket.send({ type: MessageType.cauldronClose });533
notifySoftClaimsChanged();438
}534
}439
535
440
return {536
return {@@ -449,6 +545,11 @@ export function initAlchemy ({449
return open;545
return open;450
},546
},451
close,547
close,548
listSoftClaims,549
setOnSoftClaimsChanged (fn)550
{551
onSoftClaimsChanged = typeof fn === "function" ? fn : null;552
},452
reset ()553
reset ()453
{554
{454
open = false;555
open = false;@@ -461,6 +562,7 @@ export function initAlchemy ({461
{ panel.hidden = true; }562
{ panel.hidden = true; }462
closePick();563
closePick();463
closeDyeConfirm();564
closeDyeConfirm();565
notifySoftClaimsChanged();464
},566
},465
handleSnapshot (message)567
handleSnapshot (message)466
{568
{@@ -475,6 +577,7 @@ export function initAlchemy ({475
localSlots = emptyAlchemySlots();577
localSlots = emptyAlchemySlots();476
localDyeSlots = emptyDyeSlots();578
localDyeSlots = emptyDyeSlots();477
closeDyeConfirm();579
closeDyeConfirm();580
notifySoftClaimsChanged();478
return;581
return;479
}582
}480
if (!open)583
if (!open)@@ -484,6 +587,7 @@ export function initAlchemy ({484
state = message.state;587
state = message.state;485
render();588
render();486
}589
}590
notifySoftClaimsChanged();487
if (message.dyeConfirm)591
if (message.dyeConfirm)488
{ openDyeConfirm(message.dyeConfirm); }592
{ openDyeConfirm(message.dyeConfirm); }489
if (message.alchemyResult)593
if (message.alchemyResult)@@ -610,7 +610,7 @@ export function initCrafting ({
610
610
{ craftBatchButton.disabled = true; }
611
611
if (craftBatchAllButton)
612
612
{ craftBatchAllButton.disabled = true; }
613
progressWrap.hidden = false;
613
progressWrap.classList.add("is-active");
614
614
progressFill.style.width = "0%";
615
615
statusEl.textContent = options.batchAll
616
616
? "Crafting all…"
@@ -666,7 +666,7 @@ export function initCrafting ({
666
666
craftAnimFrame = null;
667
667
}
668
668
crafting = false;
669
progressWrap.hidden = true;
669
progressWrap.classList.remove("is-active");
670
670
progressFill.style.width = "0%";
671
671
}
672
672
@@ -748,7 +748,7 @@ export function initCrafting ({
748
748
{ craftBatchButton.disabled = true; }
749
749
if (craftBatchAllButton)
750
750
{ craftBatchAllButton.disabled = true; }
751
progressWrap.hidden = false;
751
progressWrap.classList.add("is-active");
752
752
progressFill.style.width = "0%";
753
753
statusEl.textContent = "Crafting…";
754
754
craftStartedAt = performance.now();
@@ -610,7 +610,7 @@ export function initCrafting ({610
{ craftBatchButton.disabled = true; }610
{ craftBatchButton.disabled = true; }611
if (craftBatchAllButton)611
if (craftBatchAllButton)612
{ craftBatchAllButton.disabled = true; }612
{ craftBatchAllButton.disabled = true; }613
progressWrap.hidden = false;613
progressWrap.classList.add("is-active");614
progressFill.style.width = "0%";614
progressFill.style.width = "0%";615
statusEl.textContent = options.batchAll615
statusEl.textContent = options.batchAll616
? "Crafting all…"616
? "Crafting all…"@@ -666,7 +666,7 @@ export function initCrafting ({666
craftAnimFrame = null;666
craftAnimFrame = null;667
}667
}668
crafting = false;668
crafting = false;669
progressWrap.hidden = true;669
progressWrap.classList.remove("is-active");670
progressFill.style.width = "0%";670
progressFill.style.width = "0%";671
}671
}672
672
@@ -748,7 +748,7 @@ export function initCrafting ({748
{ craftBatchButton.disabled = true; }748
{ craftBatchButton.disabled = true; }749
if (craftBatchAllButton)749
if (craftBatchAllButton)750
{ craftBatchAllButton.disabled = true; }750
{ craftBatchAllButton.disabled = true; }751
progressWrap.hidden = false;751
progressWrap.classList.add("is-active");752
progressFill.style.width = "0%";752
progressFill.style.width = "0%";753
statusEl.textContent = "Crafting…";753
statusEl.textContent = "Crafting…";754
craftStartedAt = performance.now();754
craftStartedAt = performance.now();@@ -31,7 +31,9 @@ export function initInventory ({
31
31
resolveSpriteUrl,
32
32
getFriends,
33
33
getLocalName,
34
tipArrows = null
34
tipArrows = null,
35
getSoftClaims = null,
36
knowsSpell = null
35
37
})
36
38
{
37
39
const bagPanel = document.getElementById("bag-panel");
@@ -145,17 +147,60 @@ export function initInventory ({
145
147
refreshLetterSignature();
146
148
});
147
149
150
function sameClaimInstance (a, b)
151
{
152
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
153
}
154
155
/** Bag view with cauldron soft-claims subtracted (presentation only). */
156
function displayInventorySlots ()
157
{
158
const source = bag.inventory ?? [];
159
const claims = getSoftClaims?.() ?? [];
160
if (!claims.length)
161
{ return source; }
162
const slots = source.map((slot) => (slot
163
? {
164
...slot,
165
instance: slot.instance ? structuredClone(slot.instance) : null,
166
quantity: slot.quantity | 0
167
}
168
: null));
169
for (const claim of claims)
170
{
171
let need = claim.quantity | 0;
172
if (need <= 0)
173
{ continue; }
174
for (let i = 0; i < slots.length && need > 0; i++)
175
{
176
const slot = slots[i];
177
if (!slot || (slot.itemId | 0) !== (claim.itemId | 0))
178
{ continue; }
179
if ((claim.itemId | 0) === ItemId.flower
180
&& !sameClaimInstance(slot.instance, claim.instance))
181
{ continue; }
182
const take = Math.min(need, slot.quantity | 0);
183
slot.quantity -= take;
184
need -= take;
185
if (!(slot.quantity > 0))
186
{ slots[i] = null; }
187
}
188
}
189
return slots;
190
}
191
148
192
function render ()
149
193
{
150
194
bagGrid.innerHTML = "";
151
(bag.inventory ?? []).forEach((slot, index) =>
195
displayInventorySlots().forEach((slot, index) =>
152
196
{
197
const realSlot = bag.inventory?.[index] ?? null;
153
198
const button = document.createElement("button");
154
199
button.type = "button";
155
200
button.className = `item-slot${selected === index ? " selected" : ""}`;
156
201
button.dataset.slotIndex = String(index);
157
button.title = tooltip(slot);
158
button.draggable = !!slot;
202
button.title = tooltip(slot ?? realSlot);
203
button.draggable = !!realSlot;
159
204
if (slot)
160
205
{
161
206
const img = document.createElement("img");
@@ -171,9 +216,14 @@ export function initInventory ({
171
216
button.append(count);
172
217
}
173
218
}
219
else if (realSlot)
220
{
221
button.classList.add("soft-claimed");
222
button.title = `${itemDisplayName(realSlot)} (in use at the cauldron)`;
223
}
174
224
button.addEventListener("dragstart", (event) =>
175
225
{
176
if (!slot)
226
if (!realSlot || !slot)
177
227
{
178
228
event.preventDefault();
179
229
return;
@@ -323,7 +373,7 @@ export function initInventory ({
323
373
}
324
374
}
325
375
const learnSpellId = spellIdFromSpellbookStack(slot, def);
326
if (learnSpellId)
376
if (learnSpellId && !knowsSpell?.(learnSpellId))
327
377
{
328
378
const spellName = spellDefinition(learnSpellId)?.displayName ?? "spell";
329
379
items.push({
@@ -961,6 +1011,10 @@ export function initInventory ({
961
1011
closeTransfer();
962
1012
closeWriteCheque();
963
1013
},
1014
refreshBagDisplay ()
1015
{
1016
render();
1017
},
964
1018
isBlocking ()
965
1019
{
966
1020
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden
@@ -31,7 +31,9 @@ export function initInventory ({31
resolveSpriteUrl,31
resolveSpriteUrl,32
getFriends,32
getFriends,33
getLocalName,33
getLocalName,34
tipArrows = null34
tipArrows = null,35
getSoftClaims = null,36
knowsSpell = null35
})37
})36
{38
{37
const bagPanel = document.getElementById("bag-panel");39
const bagPanel = document.getElementById("bag-panel");@@ -145,17 +147,60 @@ export function initInventory ({145
refreshLetterSignature();147
refreshLetterSignature();146
});148
});147
149
150
function sameClaimInstance (a, b)151
{152
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);153
}154
155
/** Bag view with cauldron soft-claims subtracted (presentation only). */156
function displayInventorySlots ()157
{158
const source = bag.inventory ?? [];159
const claims = getSoftClaims?.() ?? [];160
if (!claims.length)161
{ return source; }162
const slots = source.map((slot) => (slot163
? {164
...slot,165
instance: slot.instance ? structuredClone(slot.instance) : null,166
quantity: slot.quantity | 0167
}168
: null));169
for (const claim of claims)170
{171
let need = claim.quantity | 0;172
if (need <= 0)173
{ continue; }174
for (let i = 0; i < slots.length && need > 0; i++)175
{176
const slot = slots[i];177
if (!slot || (slot.itemId | 0) !== (claim.itemId | 0))178
{ continue; }179
if ((claim.itemId | 0) === ItemId.flower180
&& !sameClaimInstance(slot.instance, claim.instance))181
{ continue; }182
const take = Math.min(need, slot.quantity | 0);183
slot.quantity -= take;184
need -= take;185
if (!(slot.quantity > 0))186
{ slots[i] = null; }187
}188
}189
return slots;190
}191
148
function render ()192
function render ()149
{193
{150
bagGrid.innerHTML = "";194
bagGrid.innerHTML = "";151
(bag.inventory ?? []).forEach((slot, index) =>195
displayInventorySlots().forEach((slot, index) =>152
{196
{197
const realSlot = bag.inventory?.[index] ?? null;153
const button = document.createElement("button");198
const button = document.createElement("button");154
button.type = "button";199
button.type = "button";155
button.className = `item-slot${selected === index ? " selected" : ""}`;200
button.className = `item-slot${selected === index ? " selected" : ""}`;156
button.dataset.slotIndex = String(index);201
button.dataset.slotIndex = String(index);157
button.title = tooltip(slot);202
button.title = tooltip(slot ?? realSlot);158
button.draggable = !!slot;203
button.draggable = !!realSlot;159
if (slot)204
if (slot)160
{205
{161
const img = document.createElement("img");206
const img = document.createElement("img");@@ -171,9 +216,14 @@ export function initInventory ({171
button.append(count);216
button.append(count);172
}217
}173
}218
}219
else if (realSlot)220
{221
button.classList.add("soft-claimed");222
button.title = `${itemDisplayName(realSlot)} (in use at the cauldron)`;223
}174
button.addEventListener("dragstart", (event) =>224
button.addEventListener("dragstart", (event) =>175
{225
{176
if (!slot)226
if (!realSlot || !slot)177
{227
{178
event.preventDefault();228
event.preventDefault();179
return;229
return;@@ -323,7 +373,7 @@ export function initInventory ({323
}373
}324
}374
}325
const learnSpellId = spellIdFromSpellbookStack(slot, def);375
const learnSpellId = spellIdFromSpellbookStack(slot, def);326
if (learnSpellId)376
if (learnSpellId && !knowsSpell?.(learnSpellId))327
{377
{328
const spellName = spellDefinition(learnSpellId)?.displayName ?? "spell";378
const spellName = spellDefinition(learnSpellId)?.displayName ?? "spell";329
items.push({379
items.push({@@ -961,6 +1011,10 @@ export function initInventory ({961
closeTransfer();1011
closeTransfer();962
closeWriteCheque();1012
closeWriteCheque();963
},1013
},1014
refreshBagDisplay ()1015
{1016
render();1017
},964
isBlocking ()1018
isBlocking ()965
{1019
{966
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden1020
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden@@ -1580,6 +1580,14 @@ async function main ()
1580
1580
{
1581
1581
const you = document.getElementById("you")?.textContent ?? "";
1582
1582
return you.split("(")[0].trim() || "Unknown";
1583
},
1584
getSoftClaims ()
1585
{
1586
return alchemy?.listSoftClaims?.() ?? [];
1587
},
1588
knowsSpell (spellId)
1589
{
1590
return !!spells?.knowsSpell?.(spellId);
1583
1591
}
1584
1592
});
1585
1593
skills = initSkills({
@@ -1620,6 +1628,7 @@ async function main ()
1620
1628
return inventory?.getInventorySlots?.() ?? [];
1621
1629
}
1622
1630
});
1631
alchemy?.setOnSoftClaimsChanged?.(() => inventory?.refreshBagDisplay?.());
1623
1632
staminaUi = initStamina();
1624
1633
healthUi = initHealth();
1625
1634
statusEffectsUi = initStatusEffects();
@@ -1580,6 +1580,14 @@ async function main ()1580
{1580
{1581
const you = document.getElementById("you")?.textContent ?? "";1581
const you = document.getElementById("you")?.textContent ?? "";1582
return you.split("(")[0].trim() || "Unknown";1582
return you.split("(")[0].trim() || "Unknown";1583
},1584
getSoftClaims ()1585
{1586
return alchemy?.listSoftClaims?.() ?? [];1587
},1588
knowsSpell (spellId)1589
{1590
return !!spells?.knowsSpell?.(spellId);1583
}1591
}1584
});1592
});1585
skills = initSkills({1593
skills = initSkills({@@ -1620,6 +1628,7 @@ async function main ()1620
return inventory?.getInventorySlots?.() ?? [];1628
return inventory?.getInventorySlots?.() ?? [];1621
}1629
}1622
});1630
});1631
alchemy?.setOnSoftClaimsChanged?.(() => inventory?.refreshBagDisplay?.());1623
staminaUi = initStamina();1632
staminaUi = initStamina();1624
healthUi = initHealth();1633
healthUi = initHealth();1625
statusEffectsUi = initStatusEffects();1634
statusEffectsUi = initStatusEffects();@@ -27,6 +27,15 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })
27
27
{
28
28
friendsPanel.hidden = !friendsPanel.hidden;
29
29
});
30
const friendsToggle = document.getElementById("friends-toggle");
31
32
function syncFriendsAlert ()
33
{
34
const hasIncoming = (social.incoming ?? []).length > 0;
35
friendsToggle?.classList.toggle("has-incoming", hasIncoming);
36
if (friendsToggle)
37
{ friendsToggle.title = hasIncoming ? "Friends — pending requests" : "Friends"; }
38
}
30
39
31
40
function hideInspect ()
32
41
{
@@ -289,6 +298,7 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })
289
298
)
290
299
{ expandedAccountId = null; }
291
300
renderLists();
301
syncFriendsAlert();
292
302
if (open)
293
303
{ renderInspect(); }
294
304
},
@@ -362,6 +372,8 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })
362
372
hideInspect();
363
373
friendsPanel.hidden = true;
364
374
nametag.hidden = true;
375
social = { friends: [], incoming: [], outgoing: [] };
376
syncFriendsAlert();
365
377
},
366
378
updateNametag (view, scene, localEntityId)
367
379
{
@@ -27,6 +27,15 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })27
{27
{28
friendsPanel.hidden = !friendsPanel.hidden;28
friendsPanel.hidden = !friendsPanel.hidden;29
});29
});30
const friendsToggle = document.getElementById("friends-toggle");31
32
function syncFriendsAlert ()33
{34
const hasIncoming = (social.incoming ?? []).length > 0;35
friendsToggle?.classList.toggle("has-incoming", hasIncoming);36
if (friendsToggle)37
{ friendsToggle.title = hasIncoming ? "Friends — pending requests" : "Friends"; }38
}30
39
31
function hideInspect ()40
function hideInspect ()32
{41
{@@ -289,6 +298,7 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })289
)298
)290
{ expandedAccountId = null; }299
{ expandedAccountId = null; }291
renderLists();300
renderLists();301
syncFriendsAlert();292
if (open)302
if (open)293
{ renderInspect(); }303
{ renderInspect(); }294
},304
},@@ -362,6 +372,8 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null })362
hideInspect();372
hideInspect();363
friendsPanel.hidden = true;373
friendsPanel.hidden = true;364
nametag.hidden = true;374
nametag.hidden = true;375
social = { friends: [], incoming: [], outgoing: [] };376
syncFriendsAlert();365
},377
},366
updateNametag (view, scene, localEntityId)378
updateNametag (view, scene, localEntityId)367
{379
{@@ -250,6 +250,10 @@ export function initSpells ({ socket, MessageType, getSkillLevel } = {})
250
250
renderList();
251
251
renderBar();
252
252
},
253
knowsSpell (spellId)
254
{
255
return spells.some((spell) => spell.spellId === spellId);
256
},
253
257
handleSpellDisarmed ()
254
258
{
255
259
disarmLocal();
@@ -250,6 +250,10 @@ export function initSpells ({ socket, MessageType, getSkillLevel } = {})250
renderList();250
renderList();251
renderBar();251
renderBar();252
},252
},253
knowsSpell (spellId)254
{255
return spells.some((spell) => spell.spellId === spellId);256
},253
handleSpellDisarmed ()257
handleSpellDisarmed ()254
{258
{255
disarmLocal();259
disarmLocal();@@ -3830,8 +3830,7 @@ export class WorldView
3830
3830
if (objects._inViewport === false)
3831
3831
{ continue; }
3832
3832
const lights = this.#dynamicLightsForTile(objects.tileX, objects.tileY, activeLights);
3833
const intensity = this.#tileLightIntensity(objects, lights, lightOcclusion);
3834
objects.shadeAlpha = ambientDark * (1 - intensity);
3833
objects.shadeAlpha = this.#tileShadeAlpha(objects, lights, lightOcclusion, ambientDark);
3835
3834
}
3836
3835
3837
3836
for (const baked of this.bakedChunks.values())
@@ -3839,13 +3838,14 @@ export class WorldView
3839
3838
if (baked._inViewport === false)
3840
3839
{ continue; }
3841
3840
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);
3842
this.#writeChunkLightmap(baked, lights, lightOcclusion);
3841
this.#writeChunkLightmap(baked, lights, lightOcclusion, ambientDark);
3842
// Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.
3843
3843
if (baked.groundObject?.renderer?.shaderUniforms)
3844
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = ambientDark; }
3844
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = 1; }
3845
3845
for (const object of baked.blockObjects ?? [])
3846
3846
{
3847
3847
if (object?.renderer?.shaderUniforms)
3848
{ object.renderer.shaderUniforms.u_ambientDark = ambientDark; }
3848
{ object.renderer.shaderUniforms.u_ambientDark = 1; }
3849
3849
}
3850
3850
}
3851
3851
@@ -3859,7 +3859,8 @@ export class WorldView
3859
3859
if (objects.ground && isWaterGround(objects.groundTypeId))
3860
3860
{
3861
3861
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);
3862
this.#syncGroundWaterFx(objects, ambientDark, timeSec, baked);
3862
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
3863
this.#syncGroundWaterFx(objects, 1, timeSec, baked);
3863
3864
}
3864
3865
else if (objects.ground)
3865
3866
{ this.#syncLitSprite(objects.ground, objects.shadeAlpha); }
@@ -3872,7 +3873,7 @@ export class WorldView
3872
3873
}
3873
3874
}
3874
3875
3875
#tileLightIntensity (objects, activeLights, lightOcclusion)
3876
#tileLightSources (objects, activeLights, lightOcclusion)
3876
3877
{
3877
3878
const baked = lightIntensity(objects.light ?? 0);
3878
3879
const dynamic = dynamicLightAtTile(
@@ -3887,27 +3888,41 @@ export class WorldView
3887
3888
this._activeSpellDarks ?? [],
3888
3889
lightOcclusion
3889
3890
);
3890
return Math.max(0, Math.max(baked, dynamic) - dark);
3891
return { lights: Math.max(baked, dynamic), dark };
3892
}
3893
3894
/** Shade 0–1: night ambient over unlit tiles, plus Dark spell dimming daylight/torches. */
3895
#tileShadeAlpha (objects, activeLights, lightOcclusion, ambientDark)
3896
{
3897
const { lights, dark } = this.#tileLightSources(objects, activeLights, lightOcclusion);
3898
return Math.min(1, Math.max(0, ambientDark) * (1 - lights) + dark);
3899
}
3900
3901
#tileLightIntensity (objects, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())
3902
{
3903
return 1 - this.#tileShadeAlpha(objects, activeLights, lightOcclusion, ambientDark);
3891
3904
}
3892
3905
3893
3906
/** Baked + dynamic light intensity (0–1) for any world tile, including across chunks. */
3894
#intensityAtTile (tileX, tileY, activeLights, lightOcclusion)
3907
#intensityAtTile (tileX, tileY, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())
3895
3908
{
3896
3909
const tileObjects = this.tiles.get(`${tileX},${tileY}`);
3897
3910
if (tileObjects)
3898
{ return this.#tileLightIntensity(tileObjects, activeLights, lightOcclusion); }
3911
{ return this.#tileLightIntensity(tileObjects, activeLights, lightOcclusion, ambientDark); }
3899
3912
const chunkX = Math.floor(tileX / CHUNK_SIZE);
3900
3913
const chunkY = Math.floor(tileY / CHUNK_SIZE);
3901
3914
const snapshot = this.chunks.get(`${chunkX},${chunkY}`);
3902
3915
if (!snapshot)
3903
{ return 0; }
3916
{ return 1 - Math.min(1, Math.max(0, ambientDark)); }
3904
3917
const localX = tileX - chunkX * CHUNK_SIZE;
3905
3918
const localY = tileY - chunkY * CHUNK_SIZE;
3906
3919
const index = localY * CHUNK_SIZE + localX;
3907
3920
const bakedLit = lightIntensity(snapshot.light[index] ?? 0);
3908
3921
const dynamic = dynamicLightAtTile(tileX, tileY, activeLights, lightOcclusion);
3909
3922
const dark = dynamicDarknessAtTile(tileX, tileY, this._activeSpellDarks ?? [], lightOcclusion);
3910
return Math.max(0, Math.max(bakedLit, dynamic) - dark);
3923
const lights = Math.max(bakedLit, dynamic);
3924
const shade = Math.min(1, Math.max(0, ambientDark) * (1 - lights) + dark);
3925
return 1 - shade;
3911
3926
}
3912
3927
3913
3928
/** True when ground or block on this tile occludes light rays (same rules as bake). */
@@ -3931,7 +3946,7 @@ export class WorldView
3931
3946
return isBlockOccludingLight(snapshot.blocks?.[index]?.typeId ?? null);
3932
3947
}
3933
3948
3934
#fillChunkLightGrids (baked, activeLights, lightOcclusion)
3949
#fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
3935
3950
{
3936
3951
const gridW = CHUNK_SIZE + 2;
3937
3952
const gridSize = gridW * gridW;
@@ -3948,7 +3963,7 @@ export class WorldView
3948
3963
const tileX = baked.chunkX * CHUNK_SIZE + lx;
3949
3964
const tileY = baked.chunkY * CHUNK_SIZE + ly;
3950
3965
const gi = (ly + 1) * gridW + (lx + 1);
3951
grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion);
3966
grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion, ambientDark);
3952
3967
occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;
3953
3968
}
3954
3969
}
@@ -4040,7 +4055,7 @@ export class WorldView
4040
4055
return Math.hypot(light.tileX - closestX, light.tileY - closestY) <= light.range;
4041
4056
}
4042
4057
4043
#chunkLightmapCacheKey (baked, activeLights)
4058
#chunkLightmapCacheKey (baked, activeLights, ambientDark = this.#ambientDarkness())
4044
4059
{
4045
4060
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4046
4061
if (!snapshot?.light)
@@ -4049,6 +4064,7 @@ export class WorldView
4049
4064
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);
4050
4065
const darks = this._activeSpellDarks ?? [];
4051
4066
const mode = this.lightingMode === "simple" ? "s" : "f";
4067
const ambientKey = Math.round(Math.max(0, ambientDark) * 1000);
4052
4068
let lightsKey = "";
4053
4069
for (const light of lights)
4054
4070
{
@@ -4063,9 +4079,7 @@ export class WorldView
4063
4079
{ continue; }
4064
4080
darksKey += `d${dark.tileX},${dark.tileY},${dark.range},${dark.intensity ?? 1};`;
4065
4081
}
4066
if (!lightsKey && !darksKey)
4067
{ return `i:${bakedHash}`; }
4068
return `a:${mode}:${bakedHash}:${lightsKey}|${darksKey}`;
4082
return `a:${mode}:${ambientKey}:${bakedHash}:${lightsKey}|${darksKey}`;
4069
4083
}
4070
4084
4071
4085
#invalidateNeighborLightmapCaches (chunkX, chunkY)
@@ -4087,12 +4101,12 @@ export class WorldView
4087
4101
* occluding tiles stay flat and contribute 0 into others so light does not bleed
4088
4102
* through a wall to the far side. Diagonals only when both cardinals are clear.
4089
4103
*/
4090
#writeChunkLightmap (baked, activeLights, lightOcclusion)
4104
#writeChunkLightmap (baked, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())
4091
4105
{
4092
4106
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4093
4107
if (!snapshot)
4094
4108
{ return; }
4095
const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights);
4109
const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights, ambientDark);
4096
4110
if (cacheKey && baked.lightmapCacheKey === cacheKey)
4097
4111
{ return; }
4098
4112
const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;
@@ -4101,7 +4115,7 @@ export class WorldView
4101
4115
{ baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }
4102
4116
const pixels = baked.lightmapPixels;
4103
4117
4104
this.#fillChunkLightGrids(baked, activeLights, lightOcclusion);
4118
this.#fillChunkLightGrids(baked, activeLights, lightOcclusion, ambientDark);
4105
4119
const simple = this.lightingMode === "simple";
4106
4120
4107
4121
for (let localY = 0; localY < CHUNK_SIZE; localY++)
@@ -3830,8 +3830,7 @@ export class WorldView3830
if (objects._inViewport === false)3830
if (objects._inViewport === false)3831
{ continue; }3831
{ continue; }3832
const lights = this.#dynamicLightsForTile(objects.tileX, objects.tileY, activeLights);3832
const lights = this.#dynamicLightsForTile(objects.tileX, objects.tileY, activeLights);3833
const intensity = this.#tileLightIntensity(objects, lights, lightOcclusion);3833
objects.shadeAlpha = this.#tileShadeAlpha(objects, lights, lightOcclusion, ambientDark);3834
objects.shadeAlpha = ambientDark * (1 - intensity);3835
}3834
}3836
3835
3837
for (const baked of this.bakedChunks.values())3836
for (const baked of this.bakedChunks.values())@@ -3839,13 +3838,14 @@ export class WorldView3839
if (baked._inViewport === false)3838
if (baked._inViewport === false)3840
{ continue; }3839
{ continue; }3841
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);3840
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);3842
this.#writeChunkLightmap(baked, lights, lightOcclusion);3841
this.#writeChunkLightmap(baked, lights, lightOcclusion, ambientDark);3842
// Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.3843
if (baked.groundObject?.renderer?.shaderUniforms)3843
if (baked.groundObject?.renderer?.shaderUniforms)3844
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = ambientDark; }3844
{ baked.groundObject.renderer.shaderUniforms.u_ambientDark = 1; }3845
for (const object of baked.blockObjects ?? [])3845
for (const object of baked.blockObjects ?? [])3846
{3846
{3847
if (object?.renderer?.shaderUniforms)3847
if (object?.renderer?.shaderUniforms)3848
{ object.renderer.shaderUniforms.u_ambientDark = ambientDark; }3848
{ object.renderer.shaderUniforms.u_ambientDark = 1; }3849
}3849
}3850
}3850
}3851
3851
@@ -3859,7 +3859,8 @@ export class WorldView3859
if (objects.ground && isWaterGround(objects.groundTypeId))3859
if (objects.ground && isWaterGround(objects.groundTypeId))3860
{3860
{3861
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);3861
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);3862
this.#syncGroundWaterFx(objects, ambientDark, timeSec, baked);3862
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.3863
this.#syncGroundWaterFx(objects, 1, timeSec, baked);3863
}3864
}3864
else if (objects.ground)3865
else if (objects.ground)3865
{ this.#syncLitSprite(objects.ground, objects.shadeAlpha); }3866
{ this.#syncLitSprite(objects.ground, objects.shadeAlpha); }@@ -3872,7 +3873,7 @@ export class WorldView3872
}3873
}3873
}3874
}3874
3875
3875
#tileLightIntensity (objects, activeLights, lightOcclusion)3876
#tileLightSources (objects, activeLights, lightOcclusion)3876
{3877
{3877
const baked = lightIntensity(objects.light ?? 0);3878
const baked = lightIntensity(objects.light ?? 0);3878
const dynamic = dynamicLightAtTile(3879
const dynamic = dynamicLightAtTile(@@ -3887,27 +3888,41 @@ export class WorldView3887
this._activeSpellDarks ?? [],3888
this._activeSpellDarks ?? [],3888
lightOcclusion3889
lightOcclusion3889
);3890
);3890
return Math.max(0, Math.max(baked, dynamic) - dark);3891
return { lights: Math.max(baked, dynamic), dark };3892
}3893
3894
/** Shade 0–1: night ambient over unlit tiles, plus Dark spell dimming daylight/torches. */3895
#tileShadeAlpha (objects, activeLights, lightOcclusion, ambientDark)3896
{3897
const { lights, dark } = this.#tileLightSources(objects, activeLights, lightOcclusion);3898
return Math.min(1, Math.max(0, ambientDark) * (1 - lights) + dark);3899
}3900
3901
#tileLightIntensity (objects, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())3902
{3903
return 1 - this.#tileShadeAlpha(objects, activeLights, lightOcclusion, ambientDark);3891
}3904
}3892
3905
3893
/** Baked + dynamic light intensity (0–1) for any world tile, including across chunks. */3906
/** Baked + dynamic light intensity (0–1) for any world tile, including across chunks. */3894
#intensityAtTile (tileX, tileY, activeLights, lightOcclusion)3907
#intensityAtTile (tileX, tileY, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())3895
{3908
{3896
const tileObjects = this.tiles.get(`${tileX},${tileY}`);3909
const tileObjects = this.tiles.get(`${tileX},${tileY}`);3897
if (tileObjects)3910
if (tileObjects)3898
{ return this.#tileLightIntensity(tileObjects, activeLights, lightOcclusion); }3911
{ return this.#tileLightIntensity(tileObjects, activeLights, lightOcclusion, ambientDark); }3899
const chunkX = Math.floor(tileX / CHUNK_SIZE);3912
const chunkX = Math.floor(tileX / CHUNK_SIZE);3900
const chunkY = Math.floor(tileY / CHUNK_SIZE);3913
const chunkY = Math.floor(tileY / CHUNK_SIZE);3901
const snapshot = this.chunks.get(`${chunkX},${chunkY}`);3914
const snapshot = this.chunks.get(`${chunkX},${chunkY}`);3902
if (!snapshot)3915
if (!snapshot)3903
{ return 0; }3916
{ return 1 - Math.min(1, Math.max(0, ambientDark)); }3904
const localX = tileX - chunkX * CHUNK_SIZE;3917
const localX = tileX - chunkX * CHUNK_SIZE;3905
const localY = tileY - chunkY * CHUNK_SIZE;3918
const localY = tileY - chunkY * CHUNK_SIZE;3906
const index = localY * CHUNK_SIZE + localX;3919
const index = localY * CHUNK_SIZE + localX;3907
const bakedLit = lightIntensity(snapshot.light[index] ?? 0);3920
const bakedLit = lightIntensity(snapshot.light[index] ?? 0);3908
const dynamic = dynamicLightAtTile(tileX, tileY, activeLights, lightOcclusion);3921
const dynamic = dynamicLightAtTile(tileX, tileY, activeLights, lightOcclusion);3909
const dark = dynamicDarknessAtTile(tileX, tileY, this._activeSpellDarks ?? [], lightOcclusion);3922
const dark = dynamicDarknessAtTile(tileX, tileY, this._activeSpellDarks ?? [], lightOcclusion);3910
return Math.max(0, Math.max(bakedLit, dynamic) - dark);3923
const lights = Math.max(bakedLit, dynamic);3924
const shade = Math.min(1, Math.max(0, ambientDark) * (1 - lights) + dark);3925
return 1 - shade;3911
}3926
}3912
3927
3913
/** True when ground or block on this tile occludes light rays (same rules as bake). */3928
/** True when ground or block on this tile occludes light rays (same rules as bake). */@@ -3931,7 +3946,7 @@ export class WorldView3931
return isBlockOccludingLight(snapshot.blocks?.[index]?.typeId ?? null);3946
return isBlockOccludingLight(snapshot.blocks?.[index]?.typeId ?? null);3932
}3947
}3933
3948
3934
#fillChunkLightGrids (baked, activeLights, lightOcclusion)3949
#fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)3935
{3950
{3936
const gridW = CHUNK_SIZE + 2;3951
const gridW = CHUNK_SIZE + 2;3937
const gridSize = gridW * gridW;3952
const gridSize = gridW * gridW;@@ -3948,7 +3963,7 @@ export class WorldView3948
const tileX = baked.chunkX * CHUNK_SIZE + lx;3963
const tileX = baked.chunkX * CHUNK_SIZE + lx;3949
const tileY = baked.chunkY * CHUNK_SIZE + ly;3964
const tileY = baked.chunkY * CHUNK_SIZE + ly;3950
const gi = (ly + 1) * gridW + (lx + 1);3965
const gi = (ly + 1) * gridW + (lx + 1);3951
grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion);3966
grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion, ambientDark);3952
occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;3967
occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;3953
}3968
}3954
}3969
}@@ -4040,7 +4055,7 @@ export class WorldView4040
return Math.hypot(light.tileX - closestX, light.tileY - closestY) <= light.range;4055
return Math.hypot(light.tileX - closestX, light.tileY - closestY) <= light.range;4041
}4056
}4042
4057
4043
#chunkLightmapCacheKey (baked, activeLights)4058
#chunkLightmapCacheKey (baked, activeLights, ambientDark = this.#ambientDarkness())4044
{4059
{4045
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);4060
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);4046
if (!snapshot?.light)4061
if (!snapshot?.light)@@ -4049,6 +4064,7 @@ export class WorldView4049
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);4064
const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);4050
const darks = this._activeSpellDarks ?? [];4065
const darks = this._activeSpellDarks ?? [];4051
const mode = this.lightingMode === "simple" ? "s" : "f";4066
const mode = this.lightingMode === "simple" ? "s" : "f";4067
const ambientKey = Math.round(Math.max(0, ambientDark) * 1000);4052
let lightsKey = "";4068
let lightsKey = "";4053
for (const light of lights)4069
for (const light of lights)4054
{4070
{@@ -4063,9 +4079,7 @@ export class WorldView4063
{ continue; }4079
{ continue; }4064
darksKey += `d${dark.tileX},${dark.tileY},${dark.range},${dark.intensity ?? 1};`;4080
darksKey += `d${dark.tileX},${dark.tileY},${dark.range},${dark.intensity ?? 1};`;4065
}4081
}4066
if (!lightsKey && !darksKey)4082
return `a:${mode}:${ambientKey}:${bakedHash}:${lightsKey}|${darksKey}`;4067
{ return `i:${bakedHash}`; }4068
return `a:${mode}:${bakedHash}:${lightsKey}|${darksKey}`;4069
}4083
}4070
4084
4071
#invalidateNeighborLightmapCaches (chunkX, chunkY)4085
#invalidateNeighborLightmapCaches (chunkX, chunkY)@@ -4087,12 +4101,12 @@ export class WorldView4087
* occluding tiles stay flat and contribute 0 into others so light does not bleed4101
* occluding tiles stay flat and contribute 0 into others so light does not bleed4088
* through a wall to the far side. Diagonals only when both cardinals are clear.4102
* through a wall to the far side. Diagonals only when both cardinals are clear.4089
*/4103
*/4090
#writeChunkLightmap (baked, activeLights, lightOcclusion)4104
#writeChunkLightmap (baked, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())4091
{4105
{4092
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);4106
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);4093
if (!snapshot)4107
if (!snapshot)4094
{ return; }4108
{ return; }4095
const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights);4109
const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights, ambientDark);4096
if (cacheKey && baked.lightmapCacheKey === cacheKey)4110
if (cacheKey && baked.lightmapCacheKey === cacheKey)4097
{ return; }4111
{ return; }4098
const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;4112
const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;@@ -4101,7 +4115,7 @@ export class WorldView4101
{ baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }4115
{ baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }4102
const pixels = baked.lightmapPixels;4116
const pixels = baked.lightmapPixels;4103
4117
4104
this.#fillChunkLightGrids(baked, activeLights, lightOcclusion);4118
this.#fillChunkLightGrids(baked, activeLights, lightOcclusion, ambientDark);4105
const simple = this.lightingMode === "simple";4119
const simple = this.lightingMode === "simple";4106
4120
4107
for (let localY = 0; localY < CHUNK_SIZE; localY++)4121
for (let localY = 0; localY < CHUNK_SIZE; localY++)@@ -25,6 +25,17 @@ body {
25
25
background: rgba(12, 14, 18, 0.82);
26
26
}
27
27
28
@keyframes friends-incoming-blink {
29
0%,
30
100% { opacity: 1; }
31
50% { opacity: 0.35; }
32
}
33
34
#friends-toggle.has-incoming {
35
animation: friends-incoming-blink 1s ease-in-out infinite;
36
color: #e8c84a;
37
}
38
28
39
#overlay {
29
40
position: fixed;
30
41
inset: 0;
@@ -1370,6 +1381,11 @@ button.friend-account-name:hover {
1370
1381
border: 1px solid #2c3340;
1371
1382
border-radius: 2px;
1372
1383
overflow: hidden;
1384
visibility: hidden;
1385
}
1386
1387
.craft-progress.is-active {
1388
visibility: visible;
1373
1389
}
1374
1390
1375
1391
.craft-progress-fill {
@@ -1379,6 +1395,11 @@ button.friend-account-name:hover {
1379
1395
transition: width 0.05s linear;
1380
1396
}
1381
1397
1398
#craft-status {
1399
min-height: 1.25em;
1400
margin: 0.35rem 0 0.15rem;
1401
}
1402
1382
1403
#craft-button {
1383
1404
width: 100%;
1384
1405
margin-top: 0.25rem;
@@ -25,6 +25,17 @@ body {25
background: rgba(12, 14, 18, 0.82);25
background: rgba(12, 14, 18, 0.82);26
}26
}27
27
28
@keyframes friends-incoming-blink {29
0%,30
100% { opacity: 1; }31
50% { opacity: 0.35; }32
}33
34
#friends-toggle.has-incoming {35
animation: friends-incoming-blink 1s ease-in-out infinite;36
color: #e8c84a;37
}38
28
#overlay {39
#overlay {29
position: fixed;40
position: fixed;30
inset: 0;41
inset: 0;@@ -1370,6 +1381,11 @@ button.friend-account-name:hover {1370
border: 1px solid #2c3340;1381
border: 1px solid #2c3340;1371
border-radius: 2px;1382
border-radius: 2px;1372
overflow: hidden;1383
overflow: hidden;1384
visibility: hidden;1385
}1386
1387
.craft-progress.is-active {1388
visibility: visible;1373
}1389
}1374
1390
1375
.craft-progress-fill {1391
.craft-progress-fill {@@ -1379,6 +1395,11 @@ button.friend-account-name:hover {1379
transition: width 0.05s linear;1395
transition: width 0.05s linear;1380
}1396
}1381
1397
1398
#craft-status {1399
min-height: 1.25em;1400
margin: 0.35rem 0 0.15rem;1401
}1402
1382
#craft-button {1403
#craft-button {1383
width: 100%;1404
width: 100%;1384
margin-top: 0.25rem;1405
margin-top: 0.25rem;@@ -42,10 +42,34 @@ test("spell dark reduces combat light like missing local light at night", () =>
42
42
nightDarkness: 0.72
43
43
});
44
44
assert.equal(nightLit, 1);
45
assert.equal(nightDarkSpell, 1 - 0.72);
45
assert.equal(nightDarkSpell, 0);
46
46
assert.ok(toHitDarknessPenalty(nightDarkSpell) > toHitDarknessPenalty(nightLit));
47
47
});
48
48
49
test("spell dark also dims daylight so day and night pools match near a torch", () =>
50
{
51
const dayDark = tileCombatLight01({
52
bakedLight01: 1,
53
spellDark01: 0.6,
54
worldHour: 12,
55
nightDarkness: 0.72
56
});
57
const nightTorchDark = tileCombatLight01({
58
bakedLight01: 1,
59
spellDark01: 0.6,
60
worldHour: 0,
61
nightDarkness: 0.72
62
});
63
assert.equal(dayDark, 0.4);
64
assert.equal(nightTorchDark, 0.4);
65
const dayOpen = tileCombatLight01({
66
spellDark01: 0.6,
67
worldHour: 12,
68
nightDarkness: 0.72
69
});
70
assert.equal(dayOpen, 0.4);
71
});
72
49
73
test("spell light restores combat light against spell dark at night", () =>
50
74
{
51
75
const withLight = tileCombatLight01({
@@ -42,10 +42,34 @@ test("spell dark reduces combat light like missing local light at night", () =>42
nightDarkness: 0.7242
nightDarkness: 0.7243
});43
});44
assert.equal(nightLit, 1);44
assert.equal(nightLit, 1);45
assert.equal(nightDarkSpell, 1 - 0.72);45
assert.equal(nightDarkSpell, 0);46
assert.ok(toHitDarknessPenalty(nightDarkSpell) > toHitDarknessPenalty(nightLit));46
assert.ok(toHitDarknessPenalty(nightDarkSpell) > toHitDarknessPenalty(nightLit));47
});47
});48
48
49
test("spell dark also dims daylight so day and night pools match near a torch", () =>50
{51
const dayDark = tileCombatLight01({52
bakedLight01: 1,53
spellDark01: 0.6,54
worldHour: 12,55
nightDarkness: 0.7256
});57
const nightTorchDark = tileCombatLight01({58
bakedLight01: 1,59
spellDark01: 0.6,60
worldHour: 0,61
nightDarkness: 0.7262
});63
assert.equal(dayDark, 0.4);64
assert.equal(nightTorchDark, 0.4);65
const dayOpen = tileCombatLight01({66
spellDark01: 0.6,67
worldHour: 12,68
nightDarkness: 0.7269
});70
assert.equal(dayOpen, 0.4);71
});72
49
test("spell light restores combat light against spell dark at night", () =>73
test("spell light restores combat light against spell dark at night", () =>50
{74
{51
const withLight = tileCombatLight01({75
const withLight = tileCombatLight01({