Improve potion names, origin labels, and tight-fit clothing.
Unstable draughts no longer reveal their effect in the name; stack origins omit counts for a single source and use per-line lowercase labels when mixed. Cloth shirts and sweaters clip to the body silhouette when equipped via a tight-fit equip shader.
@@ -13,6 +13,7 @@ import {
13
13
} from "./canvasSprite.js";
14
14
import { applyNearestToAllTextures, setNearestFilter } from "./sprites.js";
15
15
import { SeasonId, seasonIdAt } from "/shared/world/season.js";
16
import { SPELL_PROJECTILE_FRAME_MS } from "/shared/spells/constants.js";
16
17
17
18
const LAYER_GROUND = 0;
18
19
const LAYER_EDGE = 900000;
@@ -177,6 +178,72 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
177
178
"}"
178
179
].join("\n");
179
180
181
/** Magenta-tint equip overlay that clips alpha to the worn body silhouette. */
182
const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [
183
"precision mediump float;",
184
"varying vec2 v_texCoord;",
185
"uniform sampler2D u_texture;",
186
"uniform sampler2D u_secondary;",
187
"uniform float u_darkness;",
188
"uniform float u_strength;",
189
"uniform float u_wade;",
190
"uniform float u_spriteHeight;",
191
"uniform float u_useTint;",
192
"uniform vec3 u_tintColor;",
193
"void main() {",
194
" vec4 color = texture2D(u_texture, v_texCoord);",
195
" if (color.a <= 0.0) { discard; }",
196
" float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
197
" if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
198
" vec3 rgb = color.rgb;",
199
" if (u_useTint > 0.5) {",
200
" if (abs(color.r - color.b) * 255.0 <= 2.01 && color.g < color.r) {",
201
" float L = color.r;",
202
" float gBlend = color.r > 0.0 ? clamp(color.g / color.r, 0.0, 1.0) : 0.0;",
203
" float tintLuma = dot(u_tintColor, vec3(0.2126, 0.7152, 0.0722));",
204
" rgb = mix(u_tintColor, vec3(tintLuma), gBlend) * L;",
205
" }",
206
" }",
207
" if (u_wade > 0.5 && fromBottom < 5.0) {",
208
" rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
209
" }",
210
" rgb = mix(rgb, vec3(0.0), u_darkness);",
211
" rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
212
" vec4 bodyPx = texture2D(u_secondary, v_texCoord);",
213
" float alpha = min(bodyPx.a, color.a);",
214
" if (alpha <= 0.0) { discard; }",
215
" gl_FragColor = vec4(rgb, alpha);",
216
"}"
217
].join("\n");
218
219
/** Body-clipped equip overlay without dye recolour. */
220
const TIGHT_FIT_LIT_SPRITE_FRAG = [
221
"precision mediump float;",
222
"varying vec2 v_texCoord;",
223
"uniform sampler2D u_texture;",
224
"uniform sampler2D u_secondary;",
225
"uniform float u_darkness;",
226
"uniform float u_strength;",
227
"uniform float u_wade;",
228
"uniform float u_spriteHeight;",
229
"void main() {",
230
" vec4 color = texture2D(u_texture, v_texCoord);",
231
" if (color.a <= 0.0) { discard; }",
232
" float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
233
" if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
234
" vec3 rgb = color.rgb;",
235
" if (u_wade > 0.5 && fromBottom < 5.0) {",
236
" rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
237
" }",
238
" rgb = mix(rgb, vec3(0.0), u_darkness);",
239
" rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
240
" vec4 bodyPx = texture2D(u_secondary, v_texCoord);",
241
" float alpha = min(bodyPx.a, color.a);",
242
" if (alpha <= 0.0) { discard; }",
243
" gl_FragColor = vec4(rgb, alpha);",
244
"}"
245
].join("\n");
246
180
247
const ATLAS_LIGHTING_FRAG = [
181
248
"precision mediump float;",
182
249
"varying vec2 v_texCoord;",
@@ -203,6 +270,8 @@ let atlasLightingShader = null;
203
270
let waterGroundShader = null;
204
271
let tintLitSpriteShader = null;
205
272
let dualTintLitSpriteShader = null;
273
let tightFitTintLitSpriteShader = null;
274
let tightFitLitSpriteShader = null;
206
275
207
276
function getSpriteLightingShader ()
208
277
{
@@ -239,6 +308,20 @@ function getDualTintLitSpriteShader ()
239
308
return dualTintLitSpriteShader;
240
309
}
241
310
311
function getTightFitTintLitSpriteShader ()
312
{
313
if (!tightFitTintLitSpriteShader)
314
{ tightFitTintLitSpriteShader = Shader.fragment(TIGHT_FIT_TINT_LIT_SPRITE_FRAG); }
315
return tightFitTintLitSpriteShader;
316
}
317
318
function getTightFitLitSpriteShader ()
319
{
320
if (!tightFitLitSpriteShader)
321
{ tightFitLitSpriteShader = Shader.fragment(TIGHT_FIT_LIT_SPRITE_FRAG); }
322
return tightFitLitSpriteShader;
323
}
324
242
325
export class WorldView
243
326
{
244
327
constructor (game, scene, catalog = { grounds: {}, blocks: {} })
@@ -267,6 +350,7 @@ export class WorldView
267
350
this.nightPreview = null;
268
351
this.followPlayer = true;
269
352
this.dynamicLights = [];
353
this.spellLights = new Map();
270
354
this.swipes = [];
271
355
this.damageFloats = [];
272
356
this.damageNumbersEl = document.getElementById("damage-numbers");
@@ -945,6 +1029,99 @@ export class WorldView
945
1029
});
946
1030
}
947
1031
1032
/** Bloom-layer spell projectiles — unlit, animated, 2s travel. */
1033
spawnSpellProjectileFx (payload)
1034
{
1035
const baseSprite = payload.sprite ?? "fx:projectile:spell-light";
1036
const image = this.#spellProjectileImage(baseSprite, 0);
1037
if (!image)
1038
{ return; }
1039
const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());
1040
const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
1041
const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
1042
const angle = Math.atan2(toPivot.y - fromPivot.y, toPivot.x - fromPivot.x) * (180 / Math.PI);
1043
const object = new GameObject(0, 0, image, SORT_FX);
1044
object.renderer.layer = RENDER_LAYER_BLOOM;
1045
this.#markUnlit(object);
1046
if (object.transform)
1047
{ object.transform.rotation = angle; }
1048
this.scene.addObject(object);
1049
this.#placePivoted(object, fromPivot.x, fromPivot.y, sortY, SORT_FX);
1050
const started = performance.now();
1051
const durationMs = payload.durationMs ?? 2000;
1052
this.swipes.push({
1053
object,
1054
until: started + durationMs,
1055
started,
1056
durationMs,
1057
lerp: true,
1058
spellProjectile: true,
1059
baseSprite,
1060
fromTileX: payload.fromTileX,
1061
fromTileY: payload.fromTileY,
1062
tileX: payload.tileX,
1063
tileY: payload.tileY
1064
});
1065
}
1066
1067
spawnSpellFizzleFx (payload)
1068
{
1069
this.spawnSpellCastFlash({
1070
tileX: payload.tileX,
1071
tileY: payload.tileY,
1072
radiusTiles: 0.5,
1073
durationMs: 220,
1074
tier: 1
1075
});
1076
}
1077
1078
spawnSpellCastFlash (payload)
1079
{
1080
const pivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
1081
this.addDynamicLight({
1082
worldX: pivot.x,
1083
worldY: pivot.y,
1084
radiusTiles: payload.radiusTiles ?? 1,
1085
intensity: 0.55 + (payload.tier ?? 1) * 0.12,
1086
durationMs: payload.durationMs ?? 500
1087
});
1088
}
1089
1090
setSpellLight (payload)
1091
{
1092
const key = `${payload.tileX},${payload.tileY}`;
1093
this.spellLights.set(key, {
1094
tileX: payload.tileX,
1095
tileY: payload.tileY,
1096
until: performance.now() + Math.max(0, payload.remainingMs ?? 0),
1097
range: payload.rangeTiles ?? 6,
1098
intensity: payload.intensity ?? 0.88
1099
});
1100
}
1101
1102
removeSpellLight (payload)
1103
{
1104
this.spellLights.delete(`${payload.tileX},${payload.tileY}`);
1105
}
1106
1107
#spellProjectileImage (baseSprite, frameIndex)
1108
{
1109
const frame = Math.max(0, Math.min(2, frameIndex | 0));
1110
const stem = baseSprite.split(":").pop() ?? "spell-light";
1111
const names = [
1112
`${baseSprite}-${frame}`,
1113
`fx:projectile:${stem}-${frame}`,
1114
baseSprite,
1115
`fx:projectile:${stem}`
1116
];
1117
for (const name of names)
1118
{
1119
if (this.game.images[name])
1120
{ return this.game.images[name]; }
1121
}
1122
return null;
1123
}
1124
948
1125
addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 1, durationMs = 250 })
949
1126
{
950
1127
this.dynamicLights.push({
@@ -1354,6 +1531,7 @@ export class WorldView
1354
1531
{ overlay.destroy(); }
1355
1532
entity.overlays = [];
1356
1533
entity.overlayTints = [];
1534
entity.overlayTightFit = [];
1357
1535
entity.bloomOverlays = [];
1358
1536
for (const layer of layers.slice(1))
1359
1537
{
@@ -1363,6 +1541,8 @@ export class WorldView
1363
1541
const object = new GameObject(0, 0, image, SORT_ENTITY);
1364
1542
this.scene.addObject(object);
1365
1543
entity.overlays.push(object);
1544
const layerDef = layer.itemId != null ? itemDefinition(layer.itemId) : null;
1545
entity.overlayTightFit.push(!!layerDef?.tightFit);
1366
1546
entity.overlayTints.push(
1367
1547
layer.tint
1368
1548
? normalizeRgb(layer.tint)
@@ -1409,7 +1589,21 @@ export class WorldView
1409
1589
const overlay = entity.overlays[index];
1410
1590
const overlaySortY = pivotY + 0.5 * (index + 1);
1411
1591
overlay.transform.rotation = walkTilt;
1412
this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);
1592
if (entity.overlayTightFit?.[index])
1593
{
1594
this.#syncTightFitLitSprite(
1595
overlay,
1596
entity,
1597
tileShade,
1598
flashStrength,
1599
wade,
1600
entity.overlayTints?.[index] ?? null
1601
);
1602
}
1603
else
1604
{
1605
this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);
1606
}
1413
1607
this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
1414
1608
}
1415
1609
for (const overlay of entity.bloomOverlays ?? [])
@@ -1468,6 +1662,51 @@ export class WorldView
1468
1662
object.renderer.secondaryMap = null;
1469
1663
}
1470
1664
1665
#bodySecondaryMap (entity)
1666
{
1667
return entity?.object?.renderer?.sprite?.g_image ?? null;
1668
}
1669
1670
#syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null)
1671
{
1672
if (!overlay?.renderer || entity?.object?.renderer == null)
1673
{ return; }
1674
const bodyMap = this.#bodySecondaryMap(entity);
1675
if (!bodyMap)
1676
{
1677
this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor);
1678
return;
1679
}
1680
overlay._lit = true;
1681
const dark = Math.min(1, Math.max(0, darkness ?? 0));
1682
const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
1683
const height = overlay.renderer.sprite?.height ?? SPRITE_SIZE_PX;
1684
const tint = tintColor ? normalizeRgb(tintColor) : null;
1685
overlay.renderer.secondaryMap = bodyMap;
1686
if (tint)
1687
{
1688
overlay.renderer.shader = getTightFitTintLitSpriteShader();
1689
overlay.renderer.shaderUniforms = {
1690
u_darkness: dark,
1691
u_strength: flash,
1692
u_wade: wade ? 1 : 0,
1693
u_spriteHeight: height,
1694
u_useTint: 1,
1695
u_tintColor: [tint.r, tint.g, tint.b]
1696
};
1697
}
1698
else
1699
{
1700
overlay.renderer.shader = getTightFitLitSpriteShader();
1701
overlay.renderer.shaderUniforms = {
1702
u_darkness: dark,
1703
u_strength: flash,
1704
u_wade: wade ? 1 : 0,
1705
u_spriteHeight: height
1706
};
1707
}
1708
}
1709
1471
1710
#syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
1472
1711
{
1473
1712
if (!object?.renderer || object._lit === false || !dualTint)
@@ -2119,6 +2358,22 @@ export class WorldView
2119
2358
this.dynamicLights = this.dynamicLights.filter((light) => light.until > now);
2120
2359
2121
2360
const activeLights = [...this.dynamicLights];
2361
for (const light of this.spellLights.values())
2362
{
2363
if (light.until <= now)
2364
{ continue; }
2365
activeLights.push({
2366
tileX: light.tileX,
2367
tileY: light.tileY,
2368
range: light.range,
2369
intensity: light.intensity
2370
});
2371
}
2372
for (const key of [...this.spellLights.keys()])
2373
{
2374
if (this.spellLights.get(key).until <= now)
2375
{ this.spellLights.delete(key); }
2376
}
2122
2377
const tileSize = this.tileSize();
2123
2378
const blindLight = this.#blindVisionLight();
2124
2379
if (blindLight)
@@ -2412,17 +2667,27 @@ export class WorldView
2412
2667
toPivot.x - fromPivot.x
2413
2668
) * (180 / Math.PI);
2414
2669
}
2670
if (swipe.spellProjectile && swipe.baseSprite)
2671
{
2672
const frame = Math.floor((now - swipe.started) / SPELL_PROJECTILE_FRAME_MS) % 3;
2673
const image = this.#spellProjectileImage(swipe.baseSprite, frame);
2674
if (image && swipe.object?.renderer)
2675
{ swipe.object.renderer.sprite = image; }
2676
}
2415
2677
this.#placePivoted(swipe.object, x, y, sortY, SORT_FX);
2416
this.#applyPhysicalCombatFxDarkness(
2417
swipe.object,
2418
swipe.fromTileX,
2419
swipe.fromTileY,
2420
swipe.tileX,
2421
swipe.tileY,
2422
swipe.dualTint ?? null
2423
);
2678
if (!swipe.spellProjectile)
2679
{
2680
this.#applyPhysicalCombatFxDarkness(
2681
swipe.object,
2682
swipe.fromTileX,
2683
swipe.fromTileY,
2684
swipe.tileX,
2685
swipe.tileY,
2686
swipe.dualTint ?? null
2687
);
2688
}
2424
2689
}
2425
else if (swipe.fromTileX != null)
2690
else if (swipe.fromTileX != null && !swipe.spellProjectile)
2426
2691
{
2427
2692
this.#applyPhysicalCombatFxDarkness(
2428
2693
swipe.object,
@@ -13,6 +13,7 @@ import {13
} from "./canvasSprite.js";13
} from "./canvasSprite.js";14
import { applyNearestToAllTextures, setNearestFilter } from "./sprites.js";14
import { applyNearestToAllTextures, setNearestFilter } from "./sprites.js";15
import { SeasonId, seasonIdAt } from "/shared/world/season.js";15
import { SeasonId, seasonIdAt } from "/shared/world/season.js";16
import { SPELL_PROJECTILE_FRAME_MS } from "/shared/spells/constants.js";16
17
17
const LAYER_GROUND = 0;18
const LAYER_GROUND = 0;18
const LAYER_EDGE = 900000;19
const LAYER_EDGE = 900000;@@ -177,6 +178,72 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [177
"}"178
"}"178
].join("\n");179
].join("\n");179
180
181
/** Magenta-tint equip overlay that clips alpha to the worn body silhouette. */182
const TIGHT_FIT_TINT_LIT_SPRITE_FRAG = [183
"precision mediump float;",184
"varying vec2 v_texCoord;",185
"uniform sampler2D u_texture;",186
"uniform sampler2D u_secondary;",187
"uniform float u_darkness;",188
"uniform float u_strength;",189
"uniform float u_wade;",190
"uniform float u_spriteHeight;",191
"uniform float u_useTint;",192
"uniform vec3 u_tintColor;",193
"void main() {",194
" vec4 color = texture2D(u_texture, v_texCoord);",195
" if (color.a <= 0.0) { discard; }",196
" float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",197
" if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",198
" vec3 rgb = color.rgb;",199
" if (u_useTint > 0.5) {",200
" if (abs(color.r - color.b) * 255.0 <= 2.01 && color.g < color.r) {",201
" float L = color.r;",202
" float gBlend = color.r > 0.0 ? clamp(color.g / color.r, 0.0, 1.0) : 0.0;",203
" float tintLuma = dot(u_tintColor, vec3(0.2126, 0.7152, 0.0722));",204
" rgb = mix(u_tintColor, vec3(tintLuma), gBlend) * L;",205
" }",206
" }",207
" if (u_wade > 0.5 && fromBottom < 5.0) {",208
" rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",209
" }",210
" rgb = mix(rgb, vec3(0.0), u_darkness);",211
" rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",212
" vec4 bodyPx = texture2D(u_secondary, v_texCoord);",213
" float alpha = min(bodyPx.a, color.a);",214
" if (alpha <= 0.0) { discard; }",215
" gl_FragColor = vec4(rgb, alpha);",216
"}"217
].join("\n");218
219
/** Body-clipped equip overlay without dye recolour. */220
const TIGHT_FIT_LIT_SPRITE_FRAG = [221
"precision mediump float;",222
"varying vec2 v_texCoord;",223
"uniform sampler2D u_texture;",224
"uniform sampler2D u_secondary;",225
"uniform float u_darkness;",226
"uniform float u_strength;",227
"uniform float u_wade;",228
"uniform float u_spriteHeight;",229
"void main() {",230
" vec4 color = texture2D(u_texture, v_texCoord);",231
" if (color.a <= 0.0) { discard; }",232
" float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",233
" if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",234
" vec3 rgb = color.rgb;",235
" if (u_wade > 0.5 && fromBottom < 5.0) {",236
" rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",237
" }",238
" rgb = mix(rgb, vec3(0.0), u_darkness);",239
" rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",240
" vec4 bodyPx = texture2D(u_secondary, v_texCoord);",241
" float alpha = min(bodyPx.a, color.a);",242
" if (alpha <= 0.0) { discard; }",243
" gl_FragColor = vec4(rgb, alpha);",244
"}"245
].join("\n");246
180
const ATLAS_LIGHTING_FRAG = [247
const ATLAS_LIGHTING_FRAG = [181
"precision mediump float;",248
"precision mediump float;",182
"varying vec2 v_texCoord;",249
"varying vec2 v_texCoord;",@@ -203,6 +270,8 @@ let atlasLightingShader = null;203
let waterGroundShader = null;270
let waterGroundShader = null;204
let tintLitSpriteShader = null;271
let tintLitSpriteShader = null;205
let dualTintLitSpriteShader = null;272
let dualTintLitSpriteShader = null;273
let tightFitTintLitSpriteShader = null;274
let tightFitLitSpriteShader = null;206
275
207
function getSpriteLightingShader ()276
function getSpriteLightingShader ()208
{277
{@@ -239,6 +308,20 @@ function getDualTintLitSpriteShader ()239
return dualTintLitSpriteShader;308
return dualTintLitSpriteShader;240
}309
}241
310
311
function getTightFitTintLitSpriteShader ()312
{313
if (!tightFitTintLitSpriteShader)314
{ tightFitTintLitSpriteShader = Shader.fragment(TIGHT_FIT_TINT_LIT_SPRITE_FRAG); }315
return tightFitTintLitSpriteShader;316
}317
318
function getTightFitLitSpriteShader ()319
{320
if (!tightFitLitSpriteShader)321
{ tightFitLitSpriteShader = Shader.fragment(TIGHT_FIT_LIT_SPRITE_FRAG); }322
return tightFitLitSpriteShader;323
}324
242
export class WorldView325
export class WorldView243
{326
{244
constructor (game, scene, catalog = { grounds: {}, blocks: {} })327
constructor (game, scene, catalog = { grounds: {}, blocks: {} })@@ -267,6 +350,7 @@ export class WorldView267
this.nightPreview = null;350
this.nightPreview = null;268
this.followPlayer = true;351
this.followPlayer = true;269
this.dynamicLights = [];352
this.dynamicLights = [];353
this.spellLights = new Map();270
this.swipes = [];354
this.swipes = [];271
this.damageFloats = [];355
this.damageFloats = [];272
this.damageNumbersEl = document.getElementById("damage-numbers");356
this.damageNumbersEl = document.getElementById("damage-numbers");@@ -945,6 +1029,99 @@ export class WorldView945
});1029
});946
}1030
}947
1031
1032
/** Bloom-layer spell projectiles — unlit, animated, 2s travel. */1033
spawnSpellProjectileFx (payload)1034
{1035
const baseSprite = payload.sprite ?? "fx:projectile:spell-light";1036
const image = this.#spellProjectileImage(baseSprite, 0);1037
if (!image)1038
{ return; }1039
const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());1040
const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());1041
const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;1042
const angle = Math.atan2(toPivot.y - fromPivot.y, toPivot.x - fromPivot.x) * (180 / Math.PI);1043
const object = new GameObject(0, 0, image, SORT_FX);1044
object.renderer.layer = RENDER_LAYER_BLOOM;1045
this.#markUnlit(object);1046
if (object.transform)1047
{ object.transform.rotation = angle; }1048
this.scene.addObject(object);1049
this.#placePivoted(object, fromPivot.x, fromPivot.y, sortY, SORT_FX);1050
const started = performance.now();1051
const durationMs = payload.durationMs ?? 2000;1052
this.swipes.push({1053
object,1054
until: started + durationMs,1055
started,1056
durationMs,1057
lerp: true,1058
spellProjectile: true,1059
baseSprite,1060
fromTileX: payload.fromTileX,1061
fromTileY: payload.fromTileY,1062
tileX: payload.tileX,1063
tileY: payload.tileY1064
});1065
}1066
1067
spawnSpellFizzleFx (payload)1068
{1069
this.spawnSpellCastFlash({1070
tileX: payload.tileX,1071
tileY: payload.tileY,1072
radiusTiles: 0.5,1073
durationMs: 220,1074
tier: 11075
});1076
}1077
1078
spawnSpellCastFlash (payload)1079
{1080
const pivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());1081
this.addDynamicLight({1082
worldX: pivot.x,1083
worldY: pivot.y,1084
radiusTiles: payload.radiusTiles ?? 1,1085
intensity: 0.55 + (payload.tier ?? 1) * 0.12,1086
durationMs: payload.durationMs ?? 5001087
});1088
}1089
1090
setSpellLight (payload)1091
{1092
const key = `${payload.tileX},${payload.tileY}`;1093
this.spellLights.set(key, {1094
tileX: payload.tileX,1095
tileY: payload.tileY,1096
until: performance.now() + Math.max(0, payload.remainingMs ?? 0),1097
range: payload.rangeTiles ?? 6,1098
intensity: payload.intensity ?? 0.881099
});1100
}1101
1102
removeSpellLight (payload)1103
{1104
this.spellLights.delete(`${payload.tileX},${payload.tileY}`);1105
}1106
1107
#spellProjectileImage (baseSprite, frameIndex)1108
{1109
const frame = Math.max(0, Math.min(2, frameIndex | 0));1110
const stem = baseSprite.split(":").pop() ?? "spell-light";1111
const names = [1112
`${baseSprite}-${frame}`,1113
`fx:projectile:${stem}-${frame}`,1114
baseSprite,1115
`fx:projectile:${stem}`1116
];1117
for (const name of names)1118
{1119
if (this.game.images[name])1120
{ return this.game.images[name]; }1121
}1122
return null;1123
}1124
948
addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 1, durationMs = 250 })1125
addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 1, durationMs = 250 })949
{1126
{950
this.dynamicLights.push({1127
this.dynamicLights.push({@@ -1354,6 +1531,7 @@ export class WorldView1354
{ overlay.destroy(); }1531
{ overlay.destroy(); }1355
entity.overlays = [];1532
entity.overlays = [];1356
entity.overlayTints = [];1533
entity.overlayTints = [];1534
entity.overlayTightFit = [];1357
entity.bloomOverlays = [];1535
entity.bloomOverlays = [];1358
for (const layer of layers.slice(1))1536
for (const layer of layers.slice(1))1359
{1537
{@@ -1363,6 +1541,8 @@ export class WorldView1363
const object = new GameObject(0, 0, image, SORT_ENTITY);1541
const object = new GameObject(0, 0, image, SORT_ENTITY);1364
this.scene.addObject(object);1542
this.scene.addObject(object);1365
entity.overlays.push(object);1543
entity.overlays.push(object);1544
const layerDef = layer.itemId != null ? itemDefinition(layer.itemId) : null;1545
entity.overlayTightFit.push(!!layerDef?.tightFit);1366
entity.overlayTints.push(1546
entity.overlayTints.push(1367
layer.tint1547
layer.tint1368
? normalizeRgb(layer.tint)1548
? normalizeRgb(layer.tint)@@ -1409,7 +1589,21 @@ export class WorldView1409
const overlay = entity.overlays[index];1589
const overlay = entity.overlays[index];1410
const overlaySortY = pivotY + 0.5 * (index + 1);1590
const overlaySortY = pivotY + 0.5 * (index + 1);1411
overlay.transform.rotation = walkTilt;1591
overlay.transform.rotation = walkTilt;1412
this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);1592
if (entity.overlayTightFit?.[index])1593
{1594
this.#syncTightFitLitSprite(1595
overlay,1596
entity,1597
tileShade,1598
flashStrength,1599
wade,1600
entity.overlayTints?.[index] ?? null1601
);1602
}1603
else1604
{1605
this.#syncLitSprite(overlay, tileShade, flashStrength, wade, entity.overlayTints?.[index] ?? null);1606
}1413
this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);1607
this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);1414
}1608
}1415
for (const overlay of entity.bloomOverlays ?? [])1609
for (const overlay of entity.bloomOverlays ?? [])@@ -1468,6 +1662,51 @@ export class WorldView1468
object.renderer.secondaryMap = null;1662
object.renderer.secondaryMap = null;1469
}1663
}1470
1664
1665
#bodySecondaryMap (entity)1666
{1667
return entity?.object?.renderer?.sprite?.g_image ?? null;1668
}1669
1670
#syncTightFitLitSprite (overlay, entity, darkness, flashStrength = 0, wade = false, tintColor = null)1671
{1672
if (!overlay?.renderer || entity?.object?.renderer == null)1673
{ return; }1674
const bodyMap = this.#bodySecondaryMap(entity);1675
if (!bodyMap)1676
{1677
this.#syncLitSprite(overlay, darkness, flashStrength, wade, tintColor);1678
return;1679
}1680
overlay._lit = true;1681
const dark = Math.min(1, Math.max(0, darkness ?? 0));1682
const flash = Math.min(1, Math.max(0, flashStrength ?? 0));1683
const height = overlay.renderer.sprite?.height ?? SPRITE_SIZE_PX;1684
const tint = tintColor ? normalizeRgb(tintColor) : null;1685
overlay.renderer.secondaryMap = bodyMap;1686
if (tint)1687
{1688
overlay.renderer.shader = getTightFitTintLitSpriteShader();1689
overlay.renderer.shaderUniforms = {1690
u_darkness: dark,1691
u_strength: flash,1692
u_wade: wade ? 1 : 0,1693
u_spriteHeight: height,1694
u_useTint: 1,1695
u_tintColor: [tint.r, tint.g, tint.b]1696
};1697
}1698
else1699
{1700
overlay.renderer.shader = getTightFitLitSpriteShader();1701
overlay.renderer.shaderUniforms = {1702
u_darkness: dark,1703
u_strength: flash,1704
u_wade: wade ? 1 : 0,1705
u_spriteHeight: height1706
};1707
}1708
}1709
1471
#syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)1710
#syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)1472
{1711
{1473
if (!object?.renderer || object._lit === false || !dualTint)1712
if (!object?.renderer || object._lit === false || !dualTint)@@ -2119,6 +2358,22 @@ export class WorldView2119
this.dynamicLights = this.dynamicLights.filter((light) => light.until > now);2358
this.dynamicLights = this.dynamicLights.filter((light) => light.until > now);2120
2359
2121
const activeLights = [...this.dynamicLights];2360
const activeLights = [...this.dynamicLights];2361
for (const light of this.spellLights.values())2362
{2363
if (light.until <= now)2364
{ continue; }2365
activeLights.push({2366
tileX: light.tileX,2367
tileY: light.tileY,2368
range: light.range,2369
intensity: light.intensity2370
});2371
}2372
for (const key of [...this.spellLights.keys()])2373
{2374
if (this.spellLights.get(key).until <= now)2375
{ this.spellLights.delete(key); }2376
}2122
const tileSize = this.tileSize();2377
const tileSize = this.tileSize();2123
const blindLight = this.#blindVisionLight();2378
const blindLight = this.#blindVisionLight();2124
if (blindLight)2379
if (blindLight)@@ -2412,17 +2667,27 @@ export class WorldView2412
toPivot.x - fromPivot.x2667
toPivot.x - fromPivot.x2413
) * (180 / Math.PI);2668
) * (180 / Math.PI);2414
}2669
}2670
if (swipe.spellProjectile && swipe.baseSprite)2671
{2672
const frame = Math.floor((now - swipe.started) / SPELL_PROJECTILE_FRAME_MS) % 3;2673
const image = this.#spellProjectileImage(swipe.baseSprite, frame);2674
if (image && swipe.object?.renderer)2675
{ swipe.object.renderer.sprite = image; }2676
}2415
this.#placePivoted(swipe.object, x, y, sortY, SORT_FX);2677
this.#placePivoted(swipe.object, x, y, sortY, SORT_FX);2416
this.#applyPhysicalCombatFxDarkness(2678
if (!swipe.spellProjectile)2417
swipe.object,2679
{2418
swipe.fromTileX,2680
this.#applyPhysicalCombatFxDarkness(2419
swipe.fromTileY,2681
swipe.object,2420
swipe.tileX,2682
swipe.fromTileX,2421
swipe.tileY,2683
swipe.fromTileY,2422
swipe.dualTint ?? null2684
swipe.tileX,2423
);2685
swipe.tileY,2686
swipe.dualTint ?? null2687
);2688
}2424
}2689
}2425
else if (swipe.fromTileX != null)2690
else if (swipe.fromTileX != null && !swipe.spellProjectile)2426
{2691
{2427
this.#applyPhysicalCombatFxDarkness(2692
this.#applyPhysicalCombatFxDarkness(2428
swipe.object,2693
swipe.object,@@ -28,7 +28,7 @@ test("gathered origins use Mined by / Felled by labels", () =>
28
28
itemId: ItemId.copperOre,
29
29
quantity: 2,
30
30
origins: [{ origin: mined, quantity: 2 }]
31
}), "2 Mined by Ada Miner");
31
}), "Mined by Ada Miner");
32
32
assert.equal(originLabel(gatherOrigin(GatherOriginVerb.felled, "Bob")), "Felled by Bob");
33
33
});
34
34
@@ -61,7 +61,7 @@ test("mixed-origin stacks merge and show a breakdown label", () =>
61
61
}, def);
62
62
assert.equal(second.ok, true);
63
63
assert.equal(second.slots[0].quantity, 8);
64
assert.equal(formatOriginBreakdown(second.slots[0]), "5 Made by Ada, 3 Made by Bob");
64
assert.equal(formatOriginBreakdown(second.slots[0]), "5 made by Ada\n3 made by Bob");
65
65
});
66
66
67
67
test("splitting a stack distributes origins FIFO", () =>
@@ -28,7 +28,7 @@ test("gathered origins use Mined by / Felled by labels", () =>28
itemId: ItemId.copperOre,28
itemId: ItemId.copperOre,29
quantity: 2,29
quantity: 2,30
origins: [{ origin: mined, quantity: 2 }]30
origins: [{ origin: mined, quantity: 2 }]31
}), "2 Mined by Ada Miner");31
}), "Mined by Ada Miner");32
assert.equal(originLabel(gatherOrigin(GatherOriginVerb.felled, "Bob")), "Felled by Bob");32
assert.equal(originLabel(gatherOrigin(GatherOriginVerb.felled, "Bob")), "Felled by Bob");33
});33
});34
34
@@ -61,7 +61,7 @@ test("mixed-origin stacks merge and show a breakdown label", () =>61
}, def);61
}, def);62
assert.equal(second.ok, true);62
assert.equal(second.ok, true);63
assert.equal(second.slots[0].quantity, 8);63
assert.equal(second.slots[0].quantity, 8);64
assert.equal(formatOriginBreakdown(second.slots[0]), "5 Made by Ada, 3 Made by Bob");64
assert.equal(formatOriginBreakdown(second.slots[0]), "5 made by Ada\n3 made by Bob");65
});65
});66
66
67
test("splitting a stack distributes origins FIFO", () =>67
test("splitting a stack distributes origins FIFO", () =>