BlueGit

timfa questward

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.

timfa Tim Falken · pushed by timfa

Authored 2026-08-27 · 2 months ago

Hash
70f66bccf0b210d682cdef56008c457c0e48146e
Parent
48803caf
6 files changed +301 −22
client/src/render/worldView.js +275 −10
@@ -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";
14import { applyNearestToAllTextures, setNearestFilter } from "./sprites.js";
14import { applyNearestToAllTextures, setNearestFilter } from "./sprites.js";
15import { SeasonId, seasonIdAt } from "/shared/world/season.js";
15import { SeasonId, seasonIdAt } from "/shared/world/season.js";
16import { SPELL_PROJECTILE_FRAME_MS } from "/shared/spells/constants.js";
16
17
17const LAYER_GROUND = 0;
18const LAYER_GROUND = 0;
18const LAYER_EDGE = 900000;
19const 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. */
182const 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. */
220const 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
180const ATLAS_LIGHTING_FRAG = [
247const 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;
203let waterGroundShader = null;
270let waterGroundShader = null;
204let tintLitSpriteShader = null;
271let tintLitSpriteShader = null;
205let dualTintLitSpriteShader = null;
272let dualTintLitSpriteShader = null;
273let tightFitTintLitSpriteShader = null;
274let tightFitLitSpriteShader = null;
206
275
207function getSpriteLightingShader ()
276function getSpriteLightingShader ()
208{
277{
@@ -239,6 +308,20 @@ function getDualTintLitSpriteShader ()
239 return dualTintLitSpriteShader;
308 return dualTintLitSpriteShader;
240}
309}
241
310
311function getTightFitTintLitSpriteShader ()
312{
313 if (!tightFitTintLitSpriteShader)
314 { tightFitTintLitSpriteShader = Shader.fragment(TIGHT_FIT_TINT_LIT_SPRITE_FRAG); }
315 return tightFitTintLitSpriteShader;
316}
317
318function getTightFitLitSpriteShader ()
319{
320 if (!tightFitLitSpriteShader)
321 { tightFitLitSpriteShader = Shader.fragment(TIGHT_FIT_LIT_SPRITE_FRAG); }
322 return tightFitLitSpriteShader;
323}
324
242export class WorldView
325export class WorldView
243{
326{
244 constructor (game, scene, catalog = { grounds: {}, blocks: {} })
327 constructor (game, scene, catalog = { grounds: {}, blocks: {} })
@@ -267,6 +350,7 @@ export class WorldView
267 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 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 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 WorldView
1354 { 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 WorldView
1363 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.tint
1547 layer.tint
1368 ? normalizeRgb(layer.tint)
1548 ? normalizeRgb(layer.tint)
@@ -1409,7 +1589,21 @@ export class WorldView
1409 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] ?? null
1601 );
1602 }
1603 else
1604 {
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 WorldView
1468 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 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 #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 WorldView
2119 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.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 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 WorldView
2412 toPivot.x - fromPivot.x
2667 toPivot.x - fromPivot.x
2413 ) * (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 ?? null
2684 swipe.tileX,
2423 );
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 this.#applyPhysicalCombatFxDarkness(
2692 this.#applyPhysicalCombatFxDarkness(
2428 swipe.object,
2693 swipe.object,
server/tests/origins.test.js +2 −2
@@ -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
67test("splitting a stack distributes origins FIFO", () =>
67test("splitting a stack distributes origins FIFO", () =>
shared/definitions/alchemy.js +4 −4
@@ -128,7 +128,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
128 128 export const UNSTABLE_POTION_EFFECTS = Object.freeze([
129 129 Object.freeze({
130 130 effectKey: "stamina-drain",
131 displayName: "Unstable draught (leeching)",
131 displayName: "Unstable draught",
132 132 color: { r: 0.55, g: 0.2, b: 0.35 },
133 133 fillLevel: 3,
134 134 effect: Object.freeze({
@@ -139,7 +139,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
139 139 }),
140 140 Object.freeze({
141 141 effectKey: "glow",
142 displayName: "Unstable draught (glowing)",
142 displayName: "Unstable draught",
143 143 color: { r: 0.95, g: 0.9, b: 0.45 },
144 144 fillLevel: 3,
145 145 effect: Object.freeze({
@@ -150,7 +150,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
150 150 }),
151 151 Object.freeze({
152 152 effectKey: "shrink",
153 displayName: "Unstable draught (diminishing)",
153 displayName: "Unstable draught",
154 154 color: { r: 0.7, g: 0.55, b: 0.85 },
155 155 fillLevel: 2,
156 156 effect: Object.freeze({
@@ -161,7 +161,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
161 161 }),
162 162 Object.freeze({
163 163 effectKey: "blind",
164 displayName: "Unstable draught (murky)",
164 displayName: "Unstable draught",
165 165 color: { r: 0.12, g: 0.12, b: 0.16 },
166 166 fillLevel: 3,
167 167 effect: Object.freeze({
@@ -128,7 +128,7 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
128export const UNSTABLE_POTION_EFFECTS = Object.freeze([
128export const UNSTABLE_POTION_EFFECTS = Object.freeze([
129 Object.freeze({
129 Object.freeze({
130 effectKey: "stamina-drain",
130 effectKey: "stamina-drain",
131 displayName: "Unstable draught (leeching)",
131 displayName: "Unstable draught",
132 color: { r: 0.55, g: 0.2, b: 0.35 },
132 color: { r: 0.55, g: 0.2, b: 0.35 },
133 fillLevel: 3,
133 fillLevel: 3,
134 effect: Object.freeze({
134 effect: Object.freeze({
@@ -139,7 +139,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
139 }),
139 }),
140 Object.freeze({
140 Object.freeze({
141 effectKey: "glow",
141 effectKey: "glow",
142 displayName: "Unstable draught (glowing)",
142 displayName: "Unstable draught",
143 color: { r: 0.95, g: 0.9, b: 0.45 },
143 color: { r: 0.95, g: 0.9, b: 0.45 },
144 fillLevel: 3,
144 fillLevel: 3,
145 effect: Object.freeze({
145 effect: Object.freeze({
@@ -150,7 +150,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
150 }),
150 }),
151 Object.freeze({
151 Object.freeze({
152 effectKey: "shrink",
152 effectKey: "shrink",
153 displayName: "Unstable draught (diminishing)",
153 displayName: "Unstable draught",
154 color: { r: 0.7, g: 0.55, b: 0.85 },
154 color: { r: 0.7, g: 0.55, b: 0.85 },
155 fillLevel: 2,
155 fillLevel: 2,
156 effect: Object.freeze({
156 effect: Object.freeze({
@@ -161,7 +161,7 @@ export const UNSTABLE_POTION_EFFECTS = Object.freeze([
161 }),
161 }),
162 Object.freeze({
162 Object.freeze({
163 effectKey: "blind",
163 effectKey: "blind",
164 displayName: "Unstable draught (murky)",
164 displayName: "Unstable draught",
165 color: { r: 0.12, g: 0.12, b: 0.16 },
165 color: { r: 0.12, g: 0.12, b: 0.16 },
166 fillLevel: 3,
166 fillLevel: 3,
167 effect: Object.freeze({
167 effect: Object.freeze({
shared/definitions/clothItems.js +1 −0
@@ -171,6 +171,7 @@ function sweaterDef (itemId, tier, key)
171 171 tier,
172 172 tintFromTier: true,
173 173 dyeable: true,
174 tightFit: true,
174 175 clothing: Object.freeze({ warm: true, style: true }),
175 176 equipment: Object.freeze({
176 177 slot: "chest",
@@ -171,6 +171,7 @@ function sweaterDef (itemId, tier, key)
171 tier,
171 tier,
172 tintFromTier: true,
172 tintFromTier: true,
173 dyeable: true,
173 dyeable: true,
174 tightFit: true,
174 clothing: Object.freeze({ warm: true, style: true }),
175 clothing: Object.freeze({ warm: true, style: true }),
175 equipment: Object.freeze({
176 equipment: Object.freeze({
176 slot: "chest",
177 slot: "chest",
shared/definitions/items.js +1 −0
@@ -170,6 +170,7 @@ export const ITEM_DEFINITIONS = Object.freeze({
170 170 iconKey: "clothing",
171 171 defaultState: "shirt",
172 172 dyeable: true,
173 tightFit: true,
173 174 clothing: Object.freeze({ warm: false, style: true }),
174 175 equipment: Object.freeze({
175 176 slot: EQUIPMENT_SLOT.chest,
@@ -170,6 +170,7 @@ export const ITEM_DEFINITIONS = Object.freeze({
170 iconKey: "clothing",
170 iconKey: "clothing",
171 defaultState: "shirt",
171 defaultState: "shirt",
172 dyeable: true,
172 dyeable: true,
173 tightFit: true,
173 clothing: Object.freeze({ warm: false, style: true }),
174 clothing: Object.freeze({ warm: false, style: true }),
174 equipment: Object.freeze({
175 equipment: Object.freeze({
175 slot: EQUIPMENT_SLOT.chest,
176 slot: EQUIPMENT_SLOT.chest,
shared/items/origin.js +18 −6
@@ -51,24 +51,28 @@ export function originKey (origin)
51 51 return JSON.stringify(origin);
52 52 }
53 53
54 export function originLabel (origin)
54 export function originLabel (origin, { lowercaseVerb = false } = {})
55 55 {
56 56 if (!origin)
57 57 { return "unknown origin"; }
58 58 if (origin.kind === ItemOriginKind.crafted)
59 59 {
60 const verb = origin.verb?.trim() || CraftOriginVerb.made;
60 let verb = origin.verb?.trim() || CraftOriginVerb.made;
61 if (lowercaseVerb && verb.length)
62 { verb = verb.charAt(0).toLowerCase() + verb.slice(1); }
61 63 const name = origin.displayName?.trim() || "someone";
62 64 return `${verb} by ${name}`;
63 65 }
64 66 if (origin.kind === ItemOriginKind.shop)
65 67 {
66 68 const name = origin.displayName?.trim() || "a shop";
67 return `Bought from ${name}`;
69 return lowercaseVerb ? `bought from ${name}` : `Bought from ${name}`;
68 70 }
69 71 if (origin.kind === ItemOriginKind.gathered)
70 72 {
71 const verb = origin.verb?.trim() || "Gathered";
73 let verb = origin.verb?.trim() || "Gathered";
74 if (lowercaseVerb && verb.length)
75 { verb = verb.charAt(0).toLowerCase() + verb.slice(1); }
72 76 const name = origin.displayName?.trim() || "someone";
73 77 return `${verb} by ${name}`;
74 78 }
@@ -77,6 +81,12 @@ export function originLabel (origin)
77 81 return "unknown origin";
78 82 }
79 83
84 function originLabelWithQuantity (entry)
85 {
86 const label = originLabel(entry.origin, { lowercaseVerb: true });
87 return `${entry.quantity} ${label}`;
88 }
89
80 90 /** Build a crafted-item origin (`Forged by Ada`, …). */
81 91 export function craftOrigin (verb, displayName)
82 92 {
@@ -185,7 +195,9 @@ export function formatOriginBreakdown (stack)
185 195 const origins = normalizeOrigins(stack);
186 196 if (!origins.length)
187 197 { return ""; }
198 if (origins.length === 1)
199 { return originLabel(origins[0].origin); }
188 200 return origins
189 .map((entry) => `${entry.quantity} ${originLabel(entry.origin)}`)
190 .join(", ");
201 .map((entry) => originLabelWithQuantity(entry))
202 .join("\n");
191 203 }
@@ -51,24 +51,28 @@ export function originKey (origin)
51 return JSON.stringify(origin);
51 return JSON.stringify(origin);
52}
52}
53
53
54export function originLabel (origin)
54export function originLabel (origin, { lowercaseVerb = false } = {})
55{
55{
56 if (!origin)
56 if (!origin)
57 { return "unknown origin"; }
57 { return "unknown origin"; }
58 if (origin.kind === ItemOriginKind.crafted)
58 if (origin.kind === ItemOriginKind.crafted)
59 {
59 {
60 const verb = origin.verb?.trim() || CraftOriginVerb.made;
60 let verb = origin.verb?.trim() || CraftOriginVerb.made;
61 if (lowercaseVerb && verb.length)
62 { verb = verb.charAt(0).toLowerCase() + verb.slice(1); }
61 const name = origin.displayName?.trim() || "someone";
63 const name = origin.displayName?.trim() || "someone";
62 return `${verb} by ${name}`;
64 return `${verb} by ${name}`;
63 }
65 }
64 if (origin.kind === ItemOriginKind.shop)
66 if (origin.kind === ItemOriginKind.shop)
65 {
67 {
66 const name = origin.displayName?.trim() || "a shop";
68 const name = origin.displayName?.trim() || "a shop";
67 return `Bought from ${name}`;
69 return lowercaseVerb ? `bought from ${name}` : `Bought from ${name}`;
68 }
70 }
69 if (origin.kind === ItemOriginKind.gathered)
71 if (origin.kind === ItemOriginKind.gathered)
70 {
72 {
71 const verb = origin.verb?.trim() || "Gathered";
73 let verb = origin.verb?.trim() || "Gathered";
74 if (lowercaseVerb && verb.length)
75 { verb = verb.charAt(0).toLowerCase() + verb.slice(1); }
72 const name = origin.displayName?.trim() || "someone";
76 const name = origin.displayName?.trim() || "someone";
73 return `${verb} by ${name}`;
77 return `${verb} by ${name}`;
74 }
78 }
@@ -77,6 +81,12 @@ export function originLabel (origin)
77 return "unknown origin";
81 return "unknown origin";
78}
82}
79
83
84function originLabelWithQuantity (entry)
85{
86 const label = originLabel(entry.origin, { lowercaseVerb: true });
87 return `${entry.quantity} ${label}`;
88}
89
80/** Build a crafted-item origin (`Forged by Ada`, …). */
90/** Build a crafted-item origin (`Forged by Ada`, …). */
81export function craftOrigin (verb, displayName)
91export function craftOrigin (verb, displayName)
82{
92{
@@ -185,7 +195,9 @@ export function formatOriginBreakdown (stack)
185 const origins = normalizeOrigins(stack);
195 const origins = normalizeOrigins(stack);
186 if (!origins.length)
196 if (!origins.length)
187 { return ""; }
197 { return ""; }
198 if (origins.length === 1)
199 { return originLabel(origins[0].origin); }
188 return origins
200 return origins
189 .map((entry) => `${entry.quantity} ${originLabel(entry.origin)}`)
201 .map((entry) => originLabelWithQuantity(entry))
190 .join(", ");
202 .join("\n");
191}
203}