BlueGit

timfa questward

Restore the local player instead of destroying them after the death fade.

PLAYER_RESPAWNED never sends the local client a new entity-spawn, so finishing
the red dissolve by deleting the sprite left respawn with nothing to show.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-09-03 · 2 months ago

Hash
ac70cc2b0d28dc01e57972b4961b57cc7e941d2a
Parent
5b4a486e
2 files changed +86 −12
client/src/play/main.js +7 −4
@@ -2243,10 +2243,13 @@ async function main ()
2243 2243 death?.hide();
2244 2244 // Drop deferred killing-blow health=0 that may still be queued on a projectile.
2245 2245 view?.cancelDeferredCombatHits?.(message.entityId);
2246 view?.finishDeathDissolve?.(message.entityId);
2247 view?.updateEntityHealth(message.entityId, message.health, message.maxHealth);
2248 if (message.skullValue != null)
2249 { view?.updateEntitySkull(message.entityId, message.skullValue); }
2246 view?.reviveAfterDeath?.(message.entityId, {
2247 tileX: message.tileX,
2248 tileY: message.tileY,
2249 health: message.health,
2250 maxHealth: message.maxHealth,
2251 skullValue: message.skullValue
2252 });
2250 2253 if (message.entityId === view?.localEntityId)
2251 2254 {
2252 2255 healthUi?.apply({
@@ -2243,10 +2243,13 @@ async function main ()
2243 death?.hide();
2243 death?.hide();
2244 // Drop deferred killing-blow health=0 that may still be queued on a projectile.
2244 // Drop deferred killing-blow health=0 that may still be queued on a projectile.
2245 view?.cancelDeferredCombatHits?.(message.entityId);
2245 view?.cancelDeferredCombatHits?.(message.entityId);
2246 view?.finishDeathDissolve?.(message.entityId);
2246 view?.reviveAfterDeath?.(message.entityId, {
2247 view?.updateEntityHealth(message.entityId, message.health, message.maxHealth);
2247 tileX: message.tileX,
2248 if (message.skullValue != null)
2248 tileY: message.tileY,
2249 { view?.updateEntitySkull(message.entityId, message.skullValue); }
2249 health: message.health,
2250 maxHealth: message.maxHealth,
2251 skullValue: message.skullValue
2252 });
2250 if (message.entityId === view?.localEntityId)
2253 if (message.entityId === view?.localEntityId)
2251 {
2254 {
2252 healthUi?.apply({
2255 healthUi?.apply({
client/src/render/worldView.js +79 −8
@@ -767,6 +767,9 @@ export class WorldView
767 767 // (that looked like a nameless humanoid "target"). Wait for entity-spawn.
768 768 if (!existing)
769 769 { return; }
770 // Fading corpses stay put; respawn restores via reviveAfterDeath / spawn.
771 if (existing.dying)
772 { return; }
770 773 const size = this.tileSize();
771 774 existing.fromX = existing.visualX;
772 775 existing.fromY = existing.visualY;
@@ -845,12 +848,29 @@ export class WorldView
845 848 this.#beginDeathDissolve(existing);
846 849 }
847 850
848 /** Abort an in-progress fade (respawn / session wipe). */
849 finishDeathDissolve (entityId)
851 /**
852 * Abort an in-progress (or finished) death fade and snap the sprite back.
853 * Local players are never entity-despawned, so respawn must restore — not
854 * destroy — the visual. Remotes get a fresh entity-spawn instead.
855 */
856 reviveAfterDeath (entityId, { tileX, tileY, health, maxHealth, skullValue } = {})
850 857 {
851 if (!this.entities.get(entityId)?.dying)
852 { return; }
853 this.#finishEntityFade(entityId);
858 const entity = this.entities.get(entityId);
859 if (!entity)
860 { return false; }
861 this.#abortEntityFade(entity);
862 if (tileX != null && tileY != null)
863 { this.#snapEntityToTile(entity, tileX, tileY); }
864 if (health != null)
865 { entity.health = health; }
866 if (maxHealth != null)
867 { entity.maxHealth = maxHealth; }
868 if (skullValue != null)
869 { entity.skullValue = Math.max(0, skullValue | 0); }
870 this.#syncHpBar(entity);
871 this.#syncSkullMarker(entity);
872 this.#placeEntity(entity, performance.now());
873 return true;
854 874 }
855 875
856 876 #destroyEntityVisuals (existing)
@@ -913,6 +933,52 @@ export class WorldView
913 933 entity.damageFlashColor = FLASH_COLOR_DAMAGE;
914 934 }
915 935
936 #abortEntityFade (entity)
937 {
938 entity.dying = false;
939 entity.deathDissolve = false;
940 entity.untargetable = false;
941 entity.deathFadeStarted = null;
942 entity.deathFadeMs = null;
943 entity.damageFlashUntil = 0;
944 entity.damageFlashColor = null;
945 if (entity.object?.renderer)
946 { entity.object.renderer.alpha = 1; }
947 for (const overlay of entity.overlays ?? [])
948 {
949 if (overlay.renderer)
950 { overlay.renderer.alpha = 1; }
951 }
952 for (const overlay of entity.bloomOverlays ?? [])
953 {
954 if (overlay.renderer)
955 { overlay.renderer.alpha = 1; }
956 }
957 }
958
959 #snapEntityToTile (entity, tileX, tileY)
960 {
961 const size = this.tileSize();
962 const pivot = tilePivot(tileX, tileY, size);
963 entity.tileX = tileX;
964 entity.tileY = tileY;
965 entity.visualX = pivot.x;
966 entity.visualY = pivot.y;
967 entity.targetX = pivot.x;
968 entity.targetY = pivot.y;
969 entity.fromX = pivot.x;
970 entity.fromY = pivot.y;
971 entity.lerpStarted = null;
972 entity.previousTileX = null;
973 entity.previousTileY = null;
974 entity.shadeFromTileX = null;
975 entity.shadeFromTileY = null;
976 entity.shoveOffsetX = 0;
977 entity.shoveOffsetY = 0;
978 if (entity.entityId === this.localEntityId)
979 { this.#notePlayerTile(tileX, tileY); }
980 }
981
916 982 #finishEntityFade (entityId)
917 983 {
918 984 this.cancelDeferredCombatHits(entityId);
@@ -2474,8 +2540,13 @@ export class WorldView
2474 2540 let entity = this.entities.get(payload.entityId);
2475 2541 if (entity?.dying)
2476 2542 {
2477 this.#finishEntityFade(payload.entityId);
2478 entity = null;
2543 if (entity.entityId === this.localEntityId)
2544 { this.#abortEntityFade(entity); }
2545 else
2546 {
2547 this.#finishEntityFade(payload.entityId);
2548 entity = null;
2549 }
2479 2550 }
2480 2551 if (!entity)
2481 2552 {
@@ -2726,7 +2797,7 @@ export class WorldView
2726 2797 {
2727 2798 const fadeMs = Math.max(1, entity.deathFadeMs ?? DEATH_FADE_MS);
2728 2799 const fadeT = (now - (entity.deathFadeStarted ?? now)) / fadeMs;
2729 if (fadeT >= 1)
2800 if (fadeT >= 1 && entity.entityId !== this.localEntityId)
2730 2801 {
2731 2802 this.#finishEntityFade(entity.entityId);
2732 2803 return;
@@ -767,6 +767,9 @@ export class WorldView
767 // (that looked like a nameless humanoid "target"). Wait for entity-spawn.
767 // (that looked like a nameless humanoid "target"). Wait for entity-spawn.
768 if (!existing)
768 if (!existing)
769 { return; }
769 { return; }
770 // Fading corpses stay put; respawn restores via reviveAfterDeath / spawn.
771 if (existing.dying)
772 { return; }
770 const size = this.tileSize();
773 const size = this.tileSize();
771 existing.fromX = existing.visualX;
774 existing.fromX = existing.visualX;
772 existing.fromY = existing.visualY;
775 existing.fromY = existing.visualY;
@@ -845,12 +848,29 @@ export class WorldView
845 this.#beginDeathDissolve(existing);
848 this.#beginDeathDissolve(existing);
846 }
849 }
847
850
848 /** Abort an in-progress fade (respawn / session wipe). */
851 /**
849 finishDeathDissolve (entityId)
852 * Abort an in-progress (or finished) death fade and snap the sprite back.
853 * Local players are never entity-despawned, so respawn must restore — not
854 * destroy — the visual. Remotes get a fresh entity-spawn instead.
855 */
856 reviveAfterDeath (entityId, { tileX, tileY, health, maxHealth, skullValue } = {})
850 {
857 {
851 if (!this.entities.get(entityId)?.dying)
858 const entity = this.entities.get(entityId);
852 { return; }
859 if (!entity)
853 this.#finishEntityFade(entityId);
860 { return false; }
861 this.#abortEntityFade(entity);
862 if (tileX != null && tileY != null)
863 { this.#snapEntityToTile(entity, tileX, tileY); }
864 if (health != null)
865 { entity.health = health; }
866 if (maxHealth != null)
867 { entity.maxHealth = maxHealth; }
868 if (skullValue != null)
869 { entity.skullValue = Math.max(0, skullValue | 0); }
870 this.#syncHpBar(entity);
871 this.#syncSkullMarker(entity);
872 this.#placeEntity(entity, performance.now());
873 return true;
854 }
874 }
855
875
856 #destroyEntityVisuals (existing)
876 #destroyEntityVisuals (existing)
@@ -913,6 +933,52 @@ export class WorldView
913 entity.damageFlashColor = FLASH_COLOR_DAMAGE;
933 entity.damageFlashColor = FLASH_COLOR_DAMAGE;
914 }
934 }
915
935
936 #abortEntityFade (entity)
937 {
938 entity.dying = false;
939 entity.deathDissolve = false;
940 entity.untargetable = false;
941 entity.deathFadeStarted = null;
942 entity.deathFadeMs = null;
943 entity.damageFlashUntil = 0;
944 entity.damageFlashColor = null;
945 if (entity.object?.renderer)
946 { entity.object.renderer.alpha = 1; }
947 for (const overlay of entity.overlays ?? [])
948 {
949 if (overlay.renderer)
950 { overlay.renderer.alpha = 1; }
951 }
952 for (const overlay of entity.bloomOverlays ?? [])
953 {
954 if (overlay.renderer)
955 { overlay.renderer.alpha = 1; }
956 }
957 }
958
959 #snapEntityToTile (entity, tileX, tileY)
960 {
961 const size = this.tileSize();
962 const pivot = tilePivot(tileX, tileY, size);
963 entity.tileX = tileX;
964 entity.tileY = tileY;
965 entity.visualX = pivot.x;
966 entity.visualY = pivot.y;
967 entity.targetX = pivot.x;
968 entity.targetY = pivot.y;
969 entity.fromX = pivot.x;
970 entity.fromY = pivot.y;
971 entity.lerpStarted = null;
972 entity.previousTileX = null;
973 entity.previousTileY = null;
974 entity.shadeFromTileX = null;
975 entity.shadeFromTileY = null;
976 entity.shoveOffsetX = 0;
977 entity.shoveOffsetY = 0;
978 if (entity.entityId === this.localEntityId)
979 { this.#notePlayerTile(tileX, tileY); }
980 }
981
916 #finishEntityFade (entityId)
982 #finishEntityFade (entityId)
917 {
983 {
918 this.cancelDeferredCombatHits(entityId);
984 this.cancelDeferredCombatHits(entityId);
@@ -2474,8 +2540,13 @@ export class WorldView
2474 let entity = this.entities.get(payload.entityId);
2540 let entity = this.entities.get(payload.entityId);
2475 if (entity?.dying)
2541 if (entity?.dying)
2476 {
2542 {
2477 this.#finishEntityFade(payload.entityId);
2543 if (entity.entityId === this.localEntityId)
2478 entity = null;
2544 { this.#abortEntityFade(entity); }
2545 else
2546 {
2547 this.#finishEntityFade(payload.entityId);
2548 entity = null;
2549 }
2479 }
2550 }
2480 if (!entity)
2551 if (!entity)
2481 {
2552 {
@@ -2726,7 +2797,7 @@ export class WorldView
2726 {
2797 {
2727 const fadeMs = Math.max(1, entity.deathFadeMs ?? DEATH_FADE_MS);
2798 const fadeMs = Math.max(1, entity.deathFadeMs ?? DEATH_FADE_MS);
2728 const fadeT = (now - (entity.deathFadeStarted ?? now)) / fadeMs;
2799 const fadeT = (now - (entity.deathFadeStarted ?? now)) / fadeMs;
2729 if (fadeT >= 1)
2800 if (fadeT >= 1 && entity.entityId !== this.localEntityId)
2730 {
2801 {
2731 this.#finishEntityFade(entity.entityId);
2802 this.#finishEntityFade(entity.entityId);
2732 return;
2803 return;