BlueGit

timfa questward

Fix editor Apply now flow, combat feedback, and block lighting.

Apply now is enabled only with a pending revision, shows applying/applied feedback, and receives EDITOR_REVISION_APPLIED to refresh revision state. Physical combat drops dynamic lights; damage flash and floating numbers work. Light baker illuminates blocks in line of sight. Mob retaliation clears stale paths.

timfa Tim Falken · pushed by timfa

Authored 2026-08-24 · 2 months ago

Hash
6d593cda4f5f0d8799fdbef3594b62f0cc5631cf
Parent
d215c503
14 files changed +242 −62
client/editor.html +2 −1
@@ -41,7 +41,8 @@
41 41 <label>Range <input id="spawner-range" type="number" min="1" max="16" value="4"></label>
42 42 </div>
43 43 <button id="save" type="button">Save chunk</button>
44 <button id="apply" type="button">Apply now</button>
44 <button id="apply" type="button" disabled title="Save a chunk first to create a pending revision">Apply now</button>
45 <p id="apply-status" class="hint" aria-live="polite"></p>
45 46 <label>Night preview <input id="night" type="range" min="0" max="24" step="0.1" value="12"><span id="night-label">12.0</span></label>
46 47 <button id="open-settings" type="button">World settings</button>
47 48 <p class="hint">The red border is the chunk you are editing. Neighbours are shown for alignment and lighting, but paint only applies inside the border. Hover previews the selected tool. Mouse wheel zooms (view stays centred on the selected chunk); Shift+wheel cycles visual states. Chunk saves write a pending revision; world settings apply immediately. Place a spawner or bank with the tools above (placeholder art until real sprites exist).</p>
@@ -41,7 +41,8 @@
41 <label>Range <input id="spawner-range" type="number" min="1" max="16" value="4"></label>
41 <label>Range <input id="spawner-range" type="number" min="1" max="16" value="4"></label>
42 </div>
42 </div>
43 <button id="save" type="button">Save chunk</button>
43 <button id="save" type="button">Save chunk</button>
44 <button id="apply" type="button">Apply now</button>
44 <button id="apply" type="button" disabled title="Save a chunk first to create a pending revision">Apply now</button>
45 <p id="apply-status" class="hint" aria-live="polite"></p>
45 <label>Night preview <input id="night" type="range" min="0" max="24" step="0.1" value="12"><span id="night-label">12.0</span></label>
46 <label>Night preview <input id="night" type="range" min="0" max="24" step="0.1" value="12"><span id="night-label">12.0</span></label>
46 <button id="open-settings" type="button">World settings</button>
47 <button id="open-settings" type="button">World settings</button>
47 <p class="hint">The red border is the chunk you are editing. Neighbours are shown for alignment and lighting, but paint only applies inside the border. Hover previews the selected tool. Mouse wheel zooms (view stays centred on the selected chunk); Shift+wheel cycles visual states. Chunk saves write a pending revision; world settings apply immediately. Place a spawner or bank with the tools above (placeholder art until real sprites exist).</p>
48 <p class="hint">The red border is the chunk you are editing. Neighbours are shown for alignment and lighting, but paint only applies inside the border. Hover previews the selected tool. Mouse wheel zooms (view stays centred on the selected chunk); Shift+wheel cycles visual states. Chunk saves write a pending revision; world settings apply immediately. Place a spawner or bank with the tools above (placeholder art until real sprites exist).</p>
client/index.html +1 −0
@@ -173,6 +173,7 @@
173 173 </aside>
174 174
175 175 <div id="nametag" hidden></div>
176 <div id="damage-numbers"></div>
176 177 <div id="chat-bubbles"></div>
177 178 <div id="chat-bar" hidden>
178 179 <input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">
@@ -173,6 +173,7 @@
173 </aside>
173 </aside>
174
174
175 <div id="nametag" hidden></div>
175 <div id="nametag" hidden></div>
176 <div id="damage-numbers"></div>
176 <div id="chat-bubbles"></div>
177 <div id="chat-bubbles"></div>
177 <div id="chat-bar" hidden>
178 <div id="chat-bar" hidden>
178 <input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">
179 <input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">
client/src/editor/main.js +74 −12
@@ -18,6 +18,9 @@ let settingsModal;
18 18 let catalog = { grounds: {}, blocks: {} };
19 19 let hoverLocal = null;
20 20 let editorZoom = null;
21 let activeRevisionId = null;
22 let pendingRevisionId = null;
23 let applyInFlight = false;
21 24 const EDITOR_ZOOM_MIN = 0.25;
22 25 const EDITOR_ZOOM_MAX = 8;
23 26 const EDITOR_ZOOM_STEP = 1.12;
@@ -121,14 +124,15 @@ function paintAt (localX, localY)
121 124 let config = null;
122 125 if (tool.typeId === BlockType.spawner)
123 126 {
124 config = existing?.typeId === BlockType.spawner && existing.config
125 ? { ...existing.config }
126 : {
127 spawnerId: `${chunkX}:${chunkY}:${index}`,
128 mobTypeId: $("spawner-mob")?.value || "deer",
129 maxAlive: Number($("spawner-max")?.value || 3),
130 spawnRangeTiles: Number($("spawner-range")?.value || 4)
131 };
127 const spawnerId = existing?.typeId === BlockType.spawner && existing.config?.spawnerId
128 ? existing.config.spawnerId
129 : `${chunkX}:${chunkY}:${index}`;
130 config = {
131 spawnerId,
132 mobTypeId: $("spawner-mob")?.value || "deer",
133 maxAlive: Number($("spawner-max")?.value || 3),
134 spawnRangeTiles: Number($("spawner-range")?.value || 4)
135 };
132 136 }
133 137 draft.blocks[index] = { typeId: tool.typeId, state, config };
134 138 }
@@ -139,6 +143,28 @@ function paintAt (localX, localY)
139 143 });
140 144 }
141 145
146 function updateRevisionUI ()
147 {
148 const applyBtn = $("apply");
149 $("revision").textContent = `active ${activeRevisionId ?? "?"}` +
150 (pendingRevisionId ? ` · pending ${pendingRevisionId}` : " · no pending revision");
151 if (applyBtn)
152 {
153 applyBtn.disabled = !pendingRevisionId || applyInFlight;
154 applyBtn.title = pendingRevisionId
155 ? "Reload the live world with the pending map revision"
156 : "Save a chunk first to create a pending revision";
157 }
158 }
159
160 function setRevisionState ({ activeRevisionId: active, pendingRevisionId: pending })
161 {
162 if (active != null)
163 { activeRevisionId = active; }
164 pendingRevisionId = pending ?? null;
165 updateRevisionUI();
166 }
167
142 168 function showSelectedChunk (payload)
143 169 {
144 170 draft = {
@@ -149,8 +175,10 @@ function showSelectedChunk (payload)
149 175 };
150 176 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
151 177 $("open").checked = draft.open;
152 $("revision").textContent = `active ${payload.activeRevisionId}` +
153 (payload.pendingRevisionId ? ` · pending ${payload.pendingRevisionId}` : " · no pending revision");
178 setRevisionState({
179 activeRevisionId: payload.activeRevisionId,
180 pendingRevisionId: payload.pendingRevisionId
181 });
154 182 $("authored").textContent = payload.authored ? "authored" : "default grass (closed until saved open)";
155 183 const log = $("changelog");
156 184 log.innerHTML = "";
@@ -335,8 +363,29 @@ async function main ()
335 363 { view.applySnapshot(snapshotFromPayload(message)); }
336 364 pruneView();
337 365 }
366 else if (message.type === MessageType.editorRevisionApplied)
367 {
368 applyInFlight = false;
369 setRevisionState({
370 activeRevisionId: message.activeRevisionId,
371 pendingRevisionId: message.pendingRevisionId
372 });
373 const status = $("apply-status");
374 status.textContent = `Applied revision ${message.appliedRevisionId}. Live world reloaded.`;
375 status.className = "hint ok";
376 requestChunks(neighborhoodCoords(chunkX, chunkY));
377 }
338 378 else if (message.type === MessageType.error)
339 { $("error").textContent = message.message; }
379 {
380 $("error").textContent = message.message;
381 if (applyInFlight)
382 {
383 applyInFlight = false;
384 $("apply-status").textContent = "";
385 $("apply-status").className = "hint";
386 updateRevisionUI();
387 }
388 }
340 389 });
341 390 settingsModal = initSettingsModal({
342 391 socket,
@@ -381,6 +430,8 @@ $("open").addEventListener("change", () =>
381 430 $("save").addEventListener("click", () =>
382 431 {
383 432 $("error").textContent = "";
433 $("apply-status").textContent = "";
434 $("apply-status").className = "hint";
384 435 socket.send({
385 436 type: MessageType.editorSaveChunk,
386 437 chunkX,
@@ -389,7 +440,18 @@ $("save").addEventListener("click", () =>
389 440 });
390 441 requestNeighbors();
391 442 });
392 $("apply").addEventListener("click", () => socket.send({ type: MessageType.editorApplyRevision }));
443 $("apply").addEventListener("click", () =>
444 {
445 if (!pendingRevisionId || applyInFlight)
446 { return; }
447 $("error").textContent = "";
448 const status = $("apply-status");
449 status.textContent = "Applying…";
450 status.className = "hint";
451 applyInFlight = true;
452 updateRevisionUI();
453 socket.send({ type: MessageType.editorApplyRevision });
454 });
393 455 $("night").addEventListener("input", () =>
394 456 {
395 457 view.nightPreview = Number($("night").value);
@@ -18,6 +18,9 @@ let settingsModal;
18let catalog = { grounds: {}, blocks: {} };
18let catalog = { grounds: {}, blocks: {} };
19let hoverLocal = null;
19let hoverLocal = null;
20let editorZoom = null;
20let editorZoom = null;
21let activeRevisionId = null;
22let pendingRevisionId = null;
23let applyInFlight = false;
21const EDITOR_ZOOM_MIN = 0.25;
24const EDITOR_ZOOM_MIN = 0.25;
22const EDITOR_ZOOM_MAX = 8;
25const EDITOR_ZOOM_MAX = 8;
23const EDITOR_ZOOM_STEP = 1.12;
26const EDITOR_ZOOM_STEP = 1.12;
@@ -121,14 +124,15 @@ function paintAt (localX, localY)
121 let config = null;
124 let config = null;
122 if (tool.typeId === BlockType.spawner)
125 if (tool.typeId === BlockType.spawner)
123 {
126 {
124 config = existing?.typeId === BlockType.spawner && existing.config
127 const spawnerId = existing?.typeId === BlockType.spawner && existing.config?.spawnerId
125 ? { ...existing.config }
128 ? existing.config.spawnerId
126 : {
129 : `${chunkX}:${chunkY}:${index}`;
127 spawnerId: `${chunkX}:${chunkY}:${index}`,
130 config = {
128 mobTypeId: $("spawner-mob")?.value || "deer",
131 spawnerId,
129 maxAlive: Number($("spawner-max")?.value || 3),
132 mobTypeId: $("spawner-mob")?.value || "deer",
130 spawnRangeTiles: Number($("spawner-range")?.value || 4)
133 maxAlive: Number($("spawner-max")?.value || 3),
131 };
134 spawnRangeTiles: Number($("spawner-range")?.value || 4)
135 };
132 }
136 }
133 draft.blocks[index] = { typeId: tool.typeId, state, config };
137 draft.blocks[index] = { typeId: tool.typeId, state, config };
134 }
138 }
@@ -139,6 +143,28 @@ function paintAt (localX, localY)
139 });
143 });
140}
144}
141
145
146function updateRevisionUI ()
147{
148 const applyBtn = $("apply");
149 $("revision").textContent = `active ${activeRevisionId ?? "?"}` +
150 (pendingRevisionId ? ` · pending ${pendingRevisionId}` : " · no pending revision");
151 if (applyBtn)
152 {
153 applyBtn.disabled = !pendingRevisionId || applyInFlight;
154 applyBtn.title = pendingRevisionId
155 ? "Reload the live world with the pending map revision"
156 : "Save a chunk first to create a pending revision";
157 }
158}
159
160function setRevisionState ({ activeRevisionId: active, pendingRevisionId: pending })
161{
162 if (active != null)
163 { activeRevisionId = active; }
164 pendingRevisionId = pending ?? null;
165 updateRevisionUI();
166}
167
142function showSelectedChunk (payload)
168function showSelectedChunk (payload)
143{
169{
144 draft = {
170 draft = {
@@ -149,8 +175,10 @@ function showSelectedChunk (payload)
149 };
175 };
150 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
176 $("coords").textContent = `${payload.chunkX}, ${payload.chunkY}`;
151 $("open").checked = draft.open;
177 $("open").checked = draft.open;
152 $("revision").textContent = `active ${payload.activeRevisionId}` +
178 setRevisionState({
153 (payload.pendingRevisionId ? ` · pending ${payload.pendingRevisionId}` : " · no pending revision");
179 activeRevisionId: payload.activeRevisionId,
180 pendingRevisionId: payload.pendingRevisionId
181 });
154 $("authored").textContent = payload.authored ? "authored" : "default grass (closed until saved open)";
182 $("authored").textContent = payload.authored ? "authored" : "default grass (closed until saved open)";
155 const log = $("changelog");
183 const log = $("changelog");
156 log.innerHTML = "";
184 log.innerHTML = "";
@@ -335,8 +363,29 @@ async function main ()
335 { view.applySnapshot(snapshotFromPayload(message)); }
363 { view.applySnapshot(snapshotFromPayload(message)); }
336 pruneView();
364 pruneView();
337 }
365 }
366 else if (message.type === MessageType.editorRevisionApplied)
367 {
368 applyInFlight = false;
369 setRevisionState({
370 activeRevisionId: message.activeRevisionId,
371 pendingRevisionId: message.pendingRevisionId
372 });
373 const status = $("apply-status");
374 status.textContent = `Applied revision ${message.appliedRevisionId}. Live world reloaded.`;
375 status.className = "hint ok";
376 requestChunks(neighborhoodCoords(chunkX, chunkY));
377 }
338 else if (message.type === MessageType.error)
378 else if (message.type === MessageType.error)
339 { $("error").textContent = message.message; }
379 {
380 $("error").textContent = message.message;
381 if (applyInFlight)
382 {
383 applyInFlight = false;
384 $("apply-status").textContent = "";
385 $("apply-status").className = "hint";
386 updateRevisionUI();
387 }
388 }
340 });
389 });
341 settingsModal = initSettingsModal({
390 settingsModal = initSettingsModal({
342 socket,
391 socket,
@@ -381,6 +430,8 @@ $("open").addEventListener("change", () =>
381$("save").addEventListener("click", () =>
430$("save").addEventListener("click", () =>
382{
431{
383 $("error").textContent = "";
432 $("error").textContent = "";
433 $("apply-status").textContent = "";
434 $("apply-status").className = "hint";
384 socket.send({
435 socket.send({
385 type: MessageType.editorSaveChunk,
436 type: MessageType.editorSaveChunk,
386 chunkX,
437 chunkX,
@@ -389,7 +440,18 @@ $("save").addEventListener("click", () =>
389 });
440 });
390 requestNeighbors();
441 requestNeighbors();
391});
442});
392$("apply").addEventListener("click", () => socket.send({ type: MessageType.editorApplyRevision }));
443$("apply").addEventListener("click", () =>
444{
445 if (!pendingRevisionId || applyInFlight)
446 { return; }
447 $("error").textContent = "";
448 const status = $("apply-status");
449 status.textContent = "Applying…";
450 status.className = "hint";
451 applyInFlight = true;
452 updateRevisionUI();
453 socket.send({ type: MessageType.editorApplyRevision });
454});
393$("night").addEventListener("input", () =>
455$("night").addEventListener("input", () =>
394{
456{
395 view.nightPreview = Number($("night").value);
457 view.nightPreview = Number($("night").value);
client/src/play/main.js +1 −7
@@ -538,13 +538,7 @@ async function main ()
538 538 case MessageType.combatHit:
539 539 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
540 540 view?.flashDamage(message.targetId);
541 view?.addDynamicLight({
542 worldX: (message.tileX ?? 0) + 0.5,
543 worldY: (message.tileY ?? 0) + 0.5,
544 radiusTiles: 2,
545 intensity: 0.4,
546 durationMs: 180
547 });
541 view?.spawnDamageNumber(message.targetId, message.damage);
548 542 break;
549 543 case MessageType.error:
550 544 showError(message.message);
@@ -538,13 +538,7 @@ async function main ()
538 case MessageType.combatHit:
538 case MessageType.combatHit:
539 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
539 view?.updateEntityHealth(message.targetId, message.health, message.maxHealth);
540 view?.flashDamage(message.targetId);
540 view?.flashDamage(message.targetId);
541 view?.addDynamicLight({
541 view?.spawnDamageNumber(message.targetId, message.damage);
542 worldX: (message.tileX ?? 0) + 0.5,
543 worldY: (message.tileY ?? 0) + 0.5,
544 radiusTiles: 2,
545 intensity: 0.4,
546 durationMs: 180
547 });
548 break;
542 break;
549 case MessageType.error:
543 case MessageType.error:
550 showError(message.message);
544 showError(message.message);
client/src/render/worldView.js +88 −20
@@ -15,6 +15,7 @@ const SORT_SHADE = 2;
15 15 const SORT_ENTITY = 3;
16 16 const SORT_SPRITE_SHADE = 4;
17 17 const SORT_HP_BAR = 5;
18 const SORT_FX = 6;
18 19 const RENDER_LAYER_BLOOM = "bloom";
19 20
20 21 const HP_BAR_W = 14;
@@ -24,6 +25,7 @@ const RUN_TILT_DEG = 8;
24 25 const SHOVE_TILE_FRACTION = 0.25;
25 26 const SHOVE_MS = 280;
26 27 const DAMAGE_FLASH_MS = 180;
28 const DAMAGE_FLOAT_MS = 900;
27 29
28 30 const SPRITE_SHADE_FRAG = [
29 31 "precision mediump float;",
@@ -89,6 +91,8 @@ export class WorldView
89 91 this.followPlayer = true;
90 92 this.dynamicLights = [];
91 93 this.swipes = [];
94 this.damageFloats = [];
95 this.damageNumbersEl = document.getElementById("damage-numbers");
92 96 this.#syncBloomLayer();
93 97 }
94 98
@@ -239,6 +243,18 @@ export class WorldView
239 243 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
240 244 }
241 245
246 spawnDamageNumber (entityId, damage)
247 {
248 const amount = damage | 0;
249 if (amount <= 0)
250 { return; }
251 this.damageFloats.push({
252 entityId,
253 damage: amount,
254 started: performance.now()
255 });
256 }
257
242 258 setAppearance (payload)
243 259 {
244 260 const existing = this.entities.get(payload.entityId);
@@ -431,6 +447,7 @@ export class WorldView
431 447 }
432 448
433 449 this.#updateSwipes(now);
450 this.#updateDamageNumbers(now);
434 451 this.#centerCamera();
435 452 this.#updateShade(deltaTime);
436 453 }
@@ -478,20 +495,15 @@ export class WorldView
478 495 };
479 496 const midX = (attacker.visualX + target.visualX) / 2;
480 497 const midY = (attacker.visualY + target.visualY) / 2;
498 const sortY = Math.max(attacker.visualY, target.visualY) + 0.02;
481 499 const angle = Math.atan2(target.visualY - attacker.visualY, target.visualX - attacker.visualX) * (180 / Math.PI);
482 500 const spriteName = "fx:melee-swipe:melee-swipe";
483 const object = new GameObject(midX, midY, this.game.images[spriteName], SORT_ENTITY + 1);
501 const object = new GameObject(0, 0, this.game.images[spriteName], SORT_FX);
484 502 if (object.transform)
485 503 { object.transform.rotation = angle; }
486 504 this.scene.addObject(object);
505 this.#placePivoted(object, midX, midY, sortY, SORT_FX);
487 506 this.swipes.push({ object, until: performance.now() + 500 });
488 this.addDynamicLight({
489 worldX: (attacker.tileX + target.tileX) / 2 + 0.5,
490 worldY: (attacker.tileY + target.tileY) / 2 + 0.5,
491 radiusTiles: 2.5,
492 intensity: 0.55,
493 durationMs: 220
494 });
495 507 }
496 508
497 509 addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 0.5, durationMs = 250 })
@@ -681,6 +693,7 @@ export class WorldView
681 693 const flashStrength = (entity.damageFlashUntil ?? 0) > now
682 694 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
683 695 : 0;
696 const tileShade = this.tiles.get(`${entity.tileX},${entity.tileY}`)?.shadeAlpha ?? 0;
684 697
685 698 entity.object.transform.rotation = walkTilt;
686 699 this.#applyDamageFlash(entity.object, flashStrength);
@@ -697,20 +710,38 @@ export class WorldView
697 710 overlay.transform.rotation = walkTilt;
698 711 this.#placePivoted(overlay, pivotX, pivotY, entity.visualY + 0.002, SORT_ENTITY);
699 712 }
700 entity.spriteShade = this.#placeSpriteShade(entity.spriteShade, entity.object, pivotX, pivotY);
701 const nextOverlayShades = [];
702 for (let index = 0; index < (entity.overlays ?? []).length; index++)
713 if (flashStrength > 0)
703 714 {
704 nextOverlayShades.push(this.#placeSpriteShade(
705 entity.overlayShades?.[index] ?? null,
706 entity.overlays[index],
707 pivotX,
708 pivotY + 0.001
709 ));
715 entity.spriteShade?.destroy();
716 entity.spriteShade = null;
717 for (const shade of entity.overlayShades ?? [])
718 { shade?.destroy(); }
719 entity.overlayShades = [];
720 }
721 else
722 {
723 entity.spriteShade = this.#placeSpriteShade(entity.spriteShade, entity.object, pivotX, pivotY);
724 const nextOverlayShades = [];
725 for (let index = 0; index < (entity.overlays ?? []).length; index++)
726 {
727 nextOverlayShades.push(this.#placeSpriteShade(
728 entity.overlayShades?.[index] ?? null,
729 entity.overlays[index],
730 pivotX,
731 pivotY + 0.001
732 ));
733 }
734 for (let index = nextOverlayShades.length; index < (entity.overlayShades ?? []).length; index++)
735 { entity.overlayShades[index]?.destroy(); }
736 entity.overlayShades = nextOverlayShades;
737 if (entity.spriteShade)
738 { entity.spriteShade.renderer.alpha = tileShade; }
739 for (const shade of entity.overlayShades ?? [])
740 {
741 if (shade)
742 { shade.renderer.alpha = tileShade; }
743 }
710 744 }
711 for (let index = nextOverlayShades.length; index < (entity.overlayShades ?? []).length; index++)
712 { entity.overlayShades[index]?.destroy(); }
713 entity.overlayShades = nextOverlayShades;
714 745 this.#placeHpBar(entity, pivotX, pivotY);
715 746 }
716 747
@@ -1215,6 +1246,43 @@ export class WorldView
1215 1246 });
1216 1247 }
1217 1248
1249 #updateDamageNumbers (now)
1250 {
1251 const layer = this.damageNumbersEl;
1252 if (!layer)
1253 { return; }
1254 this.damageFloats = this.damageFloats.filter((entry) =>
1255 {
1256 const elapsed = now - entry.started;
1257 if (elapsed >= DAMAGE_FLOAT_MS)
1258 {
1259 entry.element?.remove();
1260 return false;
1261 }
1262 const entity = this.entities.get(entry.entityId);
1263 if (!entity)
1264 {
1265 entry.element?.remove();
1266 return false;
1267 }
1268 if (!entry.element)
1269 {
1270 entry.element = document.createElement("span");
1271 entry.element.className = "damage-number";
1272 entry.element.textContent = String(entry.damage);
1273 layer.append(entry.element);
1274 }
1275 const anchor = this.nametagAnchor(entity);
1276 if (!anchor)
1277 { return true; }
1278 const t = elapsed / DAMAGE_FLOAT_MS;
1279 entry.element.style.left = `${anchor.x}px`;
1280 entry.element.style.top = `${anchor.y - 6 - t * 28}px`;
1281 entry.element.style.opacity = String(1 - t);
1282 return true;
1283 });
1284 }
1285
1218 1286 #syncBloomLayer ()
1219 1287 {
1220 1288 const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;
@@ -15,6 +15,7 @@ const SORT_SHADE = 2;
15const SORT_ENTITY = 3;
15const SORT_ENTITY = 3;
16const SORT_SPRITE_SHADE = 4;
16const SORT_SPRITE_SHADE = 4;
17const SORT_HP_BAR = 5;
17const SORT_HP_BAR = 5;
18const SORT_FX = 6;
18const RENDER_LAYER_BLOOM = "bloom";
19const RENDER_LAYER_BLOOM = "bloom";
19
20
20const HP_BAR_W = 14;
21const HP_BAR_W = 14;
@@ -24,6 +25,7 @@ const RUN_TILT_DEG = 8;
24const SHOVE_TILE_FRACTION = 0.25;
25const SHOVE_TILE_FRACTION = 0.25;
25const SHOVE_MS = 280;
26const SHOVE_MS = 280;
26const DAMAGE_FLASH_MS = 180;
27const DAMAGE_FLASH_MS = 180;
28const DAMAGE_FLOAT_MS = 900;
27
29
28const SPRITE_SHADE_FRAG = [
30const SPRITE_SHADE_FRAG = [
29 "precision mediump float;",
31 "precision mediump float;",
@@ -89,6 +91,8 @@ export class WorldView
89 this.followPlayer = true;
91 this.followPlayer = true;
90 this.dynamicLights = [];
92 this.dynamicLights = [];
91 this.swipes = [];
93 this.swipes = [];
94 this.damageFloats = [];
95 this.damageNumbersEl = document.getElementById("damage-numbers");
92 this.#syncBloomLayer();
96 this.#syncBloomLayer();
93 }
97 }
94
98
@@ -239,6 +243,18 @@ export class WorldView
239 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
243 entity.damageFlashUntil = performance.now() + DAMAGE_FLASH_MS;
240 }
244 }
241
245
246 spawnDamageNumber (entityId, damage)
247 {
248 const amount = damage | 0;
249 if (amount <= 0)
250 { return; }
251 this.damageFloats.push({
252 entityId,
253 damage: amount,
254 started: performance.now()
255 });
256 }
257
242 setAppearance (payload)
258 setAppearance (payload)
243 {
259 {
244 const existing = this.entities.get(payload.entityId);
260 const existing = this.entities.get(payload.entityId);
@@ -431,6 +447,7 @@ export class WorldView
431 }
447 }
432
448
433 this.#updateSwipes(now);
449 this.#updateSwipes(now);
450 this.#updateDamageNumbers(now);
434 this.#centerCamera();
451 this.#centerCamera();
435 this.#updateShade(deltaTime);
452 this.#updateShade(deltaTime);
436 }
453 }
@@ -478,20 +495,15 @@ export class WorldView
478 };
495 };
479 const midX = (attacker.visualX + target.visualX) / 2;
496 const midX = (attacker.visualX + target.visualX) / 2;
480 const midY = (attacker.visualY + target.visualY) / 2;
497 const midY = (attacker.visualY + target.visualY) / 2;
498 const sortY = Math.max(attacker.visualY, target.visualY) + 0.02;
481 const angle = Math.atan2(target.visualY - attacker.visualY, target.visualX - attacker.visualX) * (180 / Math.PI);
499 const angle = Math.atan2(target.visualY - attacker.visualY, target.visualX - attacker.visualX) * (180 / Math.PI);
482 const spriteName = "fx:melee-swipe:melee-swipe";
500 const spriteName = "fx:melee-swipe:melee-swipe";
483 const object = new GameObject(midX, midY, this.game.images[spriteName], SORT_ENTITY + 1);
501 const object = new GameObject(0, 0, this.game.images[spriteName], SORT_FX);
484 if (object.transform)
502 if (object.transform)
485 { object.transform.rotation = angle; }
503 { object.transform.rotation = angle; }
486 this.scene.addObject(object);
504 this.scene.addObject(object);
505 this.#placePivoted(object, midX, midY, sortY, SORT_FX);
487 this.swipes.push({ object, until: performance.now() + 500 });
506 this.swipes.push({ object, until: performance.now() + 500 });
488 this.addDynamicLight({
489 worldX: (attacker.tileX + target.tileX) / 2 + 0.5,
490 worldY: (attacker.tileY + target.tileY) / 2 + 0.5,
491 radiusTiles: 2.5,
492 intensity: 0.55,
493 durationMs: 220
494 });
495 }
507 }
496
508
497 addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 0.5, durationMs = 250 })
509 addDynamicLight ({ worldX, worldY, radiusTiles = 3, intensity = 0.5, durationMs = 250 })
@@ -681,6 +693,7 @@ export class WorldView
681 const flashStrength = (entity.damageFlashUntil ?? 0) > now
693 const flashStrength = (entity.damageFlashUntil ?? 0) > now
682 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
694 ? (entity.damageFlashUntil - now) / DAMAGE_FLASH_MS
683 : 0;
695 : 0;
696 const tileShade = this.tiles.get(`${entity.tileX},${entity.tileY}`)?.shadeAlpha ?? 0;
684
697
685 entity.object.transform.rotation = walkTilt;
698 entity.object.transform.rotation = walkTilt;
686 this.#applyDamageFlash(entity.object, flashStrength);
699 this.#applyDamageFlash(entity.object, flashStrength);
@@ -697,20 +710,38 @@ export class WorldView
697 overlay.transform.rotation = walkTilt;
710 overlay.transform.rotation = walkTilt;
698 this.#placePivoted(overlay, pivotX, pivotY, entity.visualY + 0.002, SORT_ENTITY);
711 this.#placePivoted(overlay, pivotX, pivotY, entity.visualY + 0.002, SORT_ENTITY);
699 }
712 }
700 entity.spriteShade = this.#placeSpriteShade(entity.spriteShade, entity.object, pivotX, pivotY);
713 if (flashStrength > 0)
701 const nextOverlayShades = [];
702 for (let index = 0; index < (entity.overlays ?? []).length; index++)
703 {
714 {
704 nextOverlayShades.push(this.#placeSpriteShade(
715 entity.spriteShade?.destroy();
705 entity.overlayShades?.[index] ?? null,
716 entity.spriteShade = null;
706 entity.overlays[index],
717 for (const shade of entity.overlayShades ?? [])
707 pivotX,
718 { shade?.destroy(); }
708 pivotY + 0.001
719 entity.overlayShades = [];
709 ));
720 }
721 else
722 {
723 entity.spriteShade = this.#placeSpriteShade(entity.spriteShade, entity.object, pivotX, pivotY);
724 const nextOverlayShades = [];
725 for (let index = 0; index < (entity.overlays ?? []).length; index++)
726 {
727 nextOverlayShades.push(this.#placeSpriteShade(
728 entity.overlayShades?.[index] ?? null,
729 entity.overlays[index],
730 pivotX,
731 pivotY + 0.001
732 ));
733 }
734 for (let index = nextOverlayShades.length; index < (entity.overlayShades ?? []).length; index++)
735 { entity.overlayShades[index]?.destroy(); }
736 entity.overlayShades = nextOverlayShades;
737 if (entity.spriteShade)
738 { entity.spriteShade.renderer.alpha = tileShade; }
739 for (const shade of entity.overlayShades ?? [])
740 {
741 if (shade)
742 { shade.renderer.alpha = tileShade; }
743 }
710 }
744 }
711 for (let index = nextOverlayShades.length; index < (entity.overlayShades ?? []).length; index++)
712 { entity.overlayShades[index]?.destroy(); }
713 entity.overlayShades = nextOverlayShades;
714 this.#placeHpBar(entity, pivotX, pivotY);
745 this.#placeHpBar(entity, pivotX, pivotY);
715 }
746 }
716
747
@@ -1215,6 +1246,43 @@ export class WorldView
1215 });
1246 });
1216 }
1247 }
1217
1248
1249 #updateDamageNumbers (now)
1250 {
1251 const layer = this.damageNumbersEl;
1252 if (!layer)
1253 { return; }
1254 this.damageFloats = this.damageFloats.filter((entry) =>
1255 {
1256 const elapsed = now - entry.started;
1257 if (elapsed >= DAMAGE_FLOAT_MS)
1258 {
1259 entry.element?.remove();
1260 return false;
1261 }
1262 const entity = this.entities.get(entry.entityId);
1263 if (!entity)
1264 {
1265 entry.element?.remove();
1266 return false;
1267 }
1268 if (!entry.element)
1269 {
1270 entry.element = document.createElement("span");
1271 entry.element.className = "damage-number";
1272 entry.element.textContent = String(entry.damage);
1273 layer.append(entry.element);
1274 }
1275 const anchor = this.nametagAnchor(entity);
1276 if (!anchor)
1277 { return true; }
1278 const t = elapsed / DAMAGE_FLOAT_MS;
1279 entry.element.style.left = `${anchor.x}px`;
1280 entry.element.style.top = `${anchor.y - 6 - t * 28}px`;
1281 entry.element.style.opacity = String(1 - t);
1282 return true;
1283 });
1284 }
1285
1218 #syncBloomLayer ()
1286 #syncBloomLayer ()
1219 {
1287 {
1220 const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;
1288 const settings = this.settings ?? DEFAULT_WORLD_SETTINGS;
client/ui/editor.css +5 −0
@@ -57,6 +57,11 @@ button, input {
57 57 }
58 58
59 59 button { cursor: pointer; }
60 button:disabled {
61 opacity: 0.45;
62 cursor: not-allowed;
63 }
64 #apply-status.ok { color: #b8d4a0; }
60 65 .error { color: #f0a0a0; }
61 66 .hint { color: #9aa3b2; font-size: 0.85rem; }
62 67 .open-toggle { display: flex; gap: 0.4rem; align-items: center; }
@@ -57,6 +57,11 @@ button, input {
57}
57}
58
58
59button { cursor: pointer; }
59button { cursor: pointer; }
60button:disabled {
61 opacity: 0.45;
62 cursor: not-allowed;
63}
64#apply-status.ok { color: #b8d4a0; }
60.error { color: #f0a0a0; }
65.error { color: #f0a0a0; }
61.hint { color: #9aa3b2; font-size: 0.85rem; }
66.hint { color: #9aa3b2; font-size: 0.85rem; }
62.open-toggle { display: flex; gap: 0.4rem; align-items: center; }
67.open-toggle { display: flex; gap: 0.4rem; align-items: center; }
client/ui/play.css +20 −0
@@ -662,6 +662,26 @@ a { color: #d4c48a; }
662 662 background: rgba(12, 14, 18, 0.92);
663 663 }
664 664
665 #damage-numbers {
666 position: fixed;
667 inset: 0;
668 z-index: 4;
669 pointer-events: none;
670 overflow: hidden;
671 }
672
673 .damage-number {
674 position: absolute;
675 transform: translate(-50%, -100%);
676 font-size: 0.85rem;
677 font-weight: 700;
678 color: #fff;
679 text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
680 white-space: nowrap;
681 pointer-events: none;
682 user-select: none;
683 }
684
665 685 .chat-bubble {
666 686 position: fixed;
667 687 z-index: 4;
@@ -662,6 +662,26 @@ a { color: #d4c48a; }
662 background: rgba(12, 14, 18, 0.92);
662 background: rgba(12, 14, 18, 0.92);
663}
663}
664
664
665#damage-numbers {
666 position: fixed;
667 inset: 0;
668 z-index: 4;
669 pointer-events: none;
670 overflow: hidden;
671}
672
673.damage-number {
674 position: absolute;
675 transform: translate(-50%, -100%);
676 font-size: 0.85rem;
677 font-weight: 700;
678 color: #fff;
679 text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
680 white-space: nowrap;
681 pointer-events: none;
682 user-select: none;
683}
684
665.chat-bubble {
685.chat-bubble {
666 position: fixed;
686 position: fixed;
667 z-index: 4;
687 z-index: 4;
server/src/combat/service.js +9 −0
@@ -99,8 +99,15 @@ export function engageTarget (ecs, attackerId, targetId, now = Date.now())
99 99 let combat = ecs.get(handle, Component.combat);
100 100 if (!combat)
101 101 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0 }); }
102 const targetChanged = combat.targetEntityId !== targetId;
102 103 combat.targetEntityId = targetId;
103 104 combat.nextSwingAt = Math.min(combat.nextSwingAt || 0, now);
105 if (targetChanged)
106 {
107 const path = ecs.get(handle, Component.path);
108 if (path)
109 { path.tiles = []; }
110 }
104 111 return true;
105 112 }
106 113
@@ -117,6 +124,8 @@ export function stepCombat (world, now = Date.now())
117 124 const events = [];
118 125 for (const entity of world.ecs.query(Component.combat, Component.position))
119 126 {
127 if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
128 { continue; }
120 129 const combat = entity.combat;
121 130 const targetId = combat.targetEntityId;
122 131 if (targetId == null)
@@ -99,8 +99,15 @@ export function engageTarget (ecs, attackerId, targetId, now = Date.now())
99 let combat = ecs.get(handle, Component.combat);
99 let combat = ecs.get(handle, Component.combat);
100 if (!combat)
100 if (!combat)
101 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0 }); }
101 { combat = ecs.add(handle, Component.combat, { targetEntityId: null, nextSwingAt: 0 }); }
102 const targetChanged = combat.targetEntityId !== targetId;
102 combat.targetEntityId = targetId;
103 combat.targetEntityId = targetId;
103 combat.nextSwingAt = Math.min(combat.nextSwingAt || 0, now);
104 combat.nextSwingAt = Math.min(combat.nextSwingAt || 0, now);
105 if (targetChanged)
106 {
107 const path = ecs.get(handle, Component.path);
108 if (path)
109 { path.tiles = []; }
110 }
104 return true;
111 return true;
105}
112}
106
113
@@ -117,6 +124,8 @@ export function stepCombat (world, now = Date.now())
117 const events = [];
124 const events = [];
118 for (const entity of world.ecs.query(Component.combat, Component.position))
125 for (const entity of world.ecs.query(Component.combat, Component.position))
119 {
126 {
127 if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
128 { continue; }
120 const combat = entity.combat;
129 const combat = entity.combat;
121 const targetId = combat.targetEntityId;
130 const targetId = combat.targetEntityId;
122 if (targetId == null)
131 if (targetId == null)
server/src/editor/service.js +8 −0
@@ -133,6 +133,14 @@ export class EditorService
133 133 return this.worldDb.promotePendingRevision();
134 134 }
135 135
136 revisionStatus ()
137 {
138 return {
139 activeRevisionId: this.worldDb.getActiveRevisionId(),
140 pendingRevisionId: this.worldDb.getPendingRevisionId()
141 };
142 }
143
136 144 #loadForBake (chunkX, chunkY, revisionId, defaultGroundTypeId, savedX, savedY, savedData)
137 145 {
138 146 if (chunkX === savedX && chunkY === savedY)
@@ -133,6 +133,14 @@ export class EditorService
133 return this.worldDb.promotePendingRevision();
133 return this.worldDb.promotePendingRevision();
134 }
134 }
135
135
136 revisionStatus ()
137 {
138 return {
139 activeRevisionId: this.worldDb.getActiveRevisionId(),
140 pendingRevisionId: this.worldDb.getPendingRevisionId()
141 };
142 }
143
136 #loadForBake (chunkX, chunkY, revisionId, defaultGroundTypeId, savedX, savedY, savedData)
144 #loadForBake (chunkX, chunkY, revisionId, defaultGroundTypeId, savedX, savedY, savedData)
137 {
145 {
138 if (chunkX === savedX && chunkY === savedY)
146 if (chunkX === savedX && chunkY === savedY)
server/src/gateway/websocket.js +18 −6
@@ -356,14 +356,26 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
356 356 break;
357 357 case MessageType.editorApplyRevision:
358 358 requireAdmin(session);
359 editor.applyPendingRevision();
360 simulation.reloadWorld();
361 for (const other of sessions.values())
359 if (!editor.revisionStatus().pendingRevisionId)
362 360 {
363 if (other.entityId)
364 { syncSubscriptions(other, true); }
361 send(session, { type: MessageType.error, message: "Nothing pending to apply." });
362 break;
363 }
364 {
365 const appliedRevisionId = editor.applyPendingRevision();
366 simulation.reloadWorld();
367 for (const other of sessions.values())
368 {
369 if (other.entityId)
370 { syncSubscriptions(other, true); }
371 }
372 broadcastStatus();
373 send(session, {
374 type: MessageType.editorRevisionApplied,
375 ...editor.revisionStatus(),
376 appliedRevisionId
377 });
365 378 }
366 broadcastStatus();
367 379 break;
368 380 default:
369 381 send(session, { type: MessageType.error, message: `Unknown message ${message.type}` });
@@ -356,14 +356,26 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
356 break;
356 break;
357 case MessageType.editorApplyRevision:
357 case MessageType.editorApplyRevision:
358 requireAdmin(session);
358 requireAdmin(session);
359 editor.applyPendingRevision();
359 if (!editor.revisionStatus().pendingRevisionId)
360 simulation.reloadWorld();
361 for (const other of sessions.values())
362 {
360 {
363 if (other.entityId)
361 send(session, { type: MessageType.error, message: "Nothing pending to apply." });
364 { syncSubscriptions(other, true); }
362 break;
363 }
364 {
365 const appliedRevisionId = editor.applyPendingRevision();
366 simulation.reloadWorld();
367 for (const other of sessions.values())
368 {
369 if (other.entityId)
370 { syncSubscriptions(other, true); }
371 }
372 broadcastStatus();
373 send(session, {
374 type: MessageType.editorRevisionApplied,
375 ...editor.revisionStatus(),
376 appliedRevisionId
377 });
365 }
378 }
366 broadcastStatus();
367 break;
379 break;
368 default:
380 default:
369 send(session, { type: MessageType.error, message: `Unknown message ${message.type}` });
381 send(session, { type: MessageType.error, message: `Unknown message ${message.type}` });
server/src/lighting/baker.js +8 −12
@@ -39,10 +39,9 @@ export function rayReaches (fromX, fromY, toX, toY, isPassable)
39 39 if (fromX === toX && fromY === toY)
40 40 { return isPassable(toX, toY); }
41 41
42 if (!isPassable(toX, toY))
43 { return false; }
44
45 42 const tiles = bresenhamTiles(fromX, fromY, toX, toY);
43 // Only tiles strictly between source and target can occlude. The destination
44 // may be an impassable block that still catches light on its facing surface.
46 45 for (let i = 1; i < tiles.length - 1; i++)
47 46 {
48 47 if (!isPassable(tiles[i].x, tiles[i].y))
@@ -120,17 +119,14 @@ export function bakeLightMaps (centerChunkX, centerChunkY, loadChunk, maxRange)
120 119 const tileY = coord.chunkY * CHUNK_SIZE + localY;
121 120 const index = localY * CHUNK_SIZE + localX;
122 121 let best = 0;
123 if (isPassable(tileX, tileY))
122 for (const source of sources)
124 123 {
125 for (const source of sources)
124 const dist = Math.hypot(tileX - source.tileX, tileY - source.tileY);
125 if (dist > source.range)
126 { continue; }
127 if (rayReaches(source.tileX, source.tileY, tileX, tileY, isPassable))
126 128 {
127 const dist = Math.hypot(tileX - source.tileX, tileY - source.tileY);
128 if (dist > source.range)
129 { continue; }
130 if (rayReaches(source.tileX, source.tileY, tileX, tileY, isPassable))
131 {
132 best = Math.max(best, encodeLight(dist, source.range));
133 }
129 best = Math.max(best, encodeLight(dist, source.range));
134 130 }
135 131 }
136 132 data.light[index] = best;
@@ -39,10 +39,9 @@ export function rayReaches (fromX, fromY, toX, toY, isPassable)
39 if (fromX === toX && fromY === toY)
39 if (fromX === toX && fromY === toY)
40 { return isPassable(toX, toY); }
40 { return isPassable(toX, toY); }
41
41
42 if (!isPassable(toX, toY))
43 { return false; }
44
45 const tiles = bresenhamTiles(fromX, fromY, toX, toY);
42 const tiles = bresenhamTiles(fromX, fromY, toX, toY);
43 // Only tiles strictly between source and target can occlude. The destination
44 // may be an impassable block that still catches light on its facing surface.
46 for (let i = 1; i < tiles.length - 1; i++)
45 for (let i = 1; i < tiles.length - 1; i++)
47 {
46 {
48 if (!isPassable(tiles[i].x, tiles[i].y))
47 if (!isPassable(tiles[i].x, tiles[i].y))
@@ -120,17 +119,14 @@ export function bakeLightMaps (centerChunkX, centerChunkY, loadChunk, maxRange)
120 const tileY = coord.chunkY * CHUNK_SIZE + localY;
119 const tileY = coord.chunkY * CHUNK_SIZE + localY;
121 const index = localY * CHUNK_SIZE + localX;
120 const index = localY * CHUNK_SIZE + localX;
122 let best = 0;
121 let best = 0;
123 if (isPassable(tileX, tileY))
122 for (const source of sources)
124 {
123 {
125 for (const source of sources)
124 const dist = Math.hypot(tileX - source.tileX, tileY - source.tileY);
125 if (dist > source.range)
126 { continue; }
127 if (rayReaches(source.tileX, source.tileY, tileX, tileY, isPassable))
126 {
128 {
127 const dist = Math.hypot(tileX - source.tileX, tileY - source.tileY);
129 best = Math.max(best, encodeLight(dist, source.range));
128 if (dist > source.range)
129 { continue; }
130 if (rayReaches(source.tileX, source.tileY, tileX, tileY, isPassable))
131 {
132 best = Math.max(best, encodeLight(dist, source.range));
133 }
134 }
130 }
135 }
131 }
136 data.light[index] = best;
132 data.light[index] = best;
server/src/simulation/simulation.js +1 −1
@@ -1109,7 +1109,7 @@ export class Simulation
1109 1109 {
1110 1110 try
1111 1111 {
1112 this.spawnEntity(mobComponents(request));
1112 this.spawnEntity(mobComponents(request), { requireResident: true });
1113 1113 }
1114 1114 catch
1115 1115 { continue; }
@@ -1109,7 +1109,7 @@ export class Simulation
1109 {
1109 {
1110 try
1110 try
1111 {
1111 {
1112 this.spawnEntity(mobComponents(request));
1112 this.spawnEntity(mobComponents(request), { requireResident: true });
1113 }
1113 }
1114 catch
1114 catch
1115 { continue; }
1115 { continue; }
server/tests/lighting.test.js +6 −3
@@ -12,14 +12,16 @@ test("Bresenham visits start and end tiles", () =>
12 12 assert.deepEqual(tiles.at(-1), { x: 2, y: 1 });
13 13 });
14 14
15 test("walls block light rays", () =>
15 test("walls block light rays but can be lit themselves", () =>
16 16 {
17 17 const blocked = (x, y) => !(x === 1 && y === 0);
18 18 assert.equal(rayReaches(0, 0, 2, 0, blocked), false);
19 19 assert.equal(rayReaches(0, 0, 2, 0, () => true), true);
20 const wallAtTarget = (x, y) => !(x === 2 && y === 0);
21 assert.equal(rayReaches(0, 0, 2, 0, wallAtTarget), true);
20 22 });
21 23
22 test("a torch lights passable tiles and not tiles behind walls", () =>
24 test("a torch lights passable tiles, facing walls, and not tiles behind walls", () =>
23 25 {
24 26 const origin = createEmptyChunkData();
25 27 origin.open = true;
@@ -38,7 +40,8 @@ test("a torch lights passable tiles and not tiles behind walls", () =>
38 40 assert.ok(self.light[1] > 0, "tile beside torch is lit");
39 41 assert.ok(self.light[0] > self.light[1], "torch tile is brighter than its neighbour");
40 42 assert.ok(self.light[1] > self.light[32], "one tile away is brighter than two tiles south");
41 assert.equal(self.light[2], 0, "wall is unlit");
43 assert.ok(self.light[2] > 0, "wall facing the torch is lit");
44 assert.ok(self.light[1] > self.light[2], "open tile beside torch is brighter than the wall one step further");
42 45 assert.equal(self.light[3], 0, "tile behind wall is unlit");
43 46 assert.equal(self.light.length, CHUNK_SIZE * CHUNK_SIZE);
44 47 });
@@ -12,14 +12,16 @@ test("Bresenham visits start and end tiles", () =>
12 assert.deepEqual(tiles.at(-1), { x: 2, y: 1 });
12 assert.deepEqual(tiles.at(-1), { x: 2, y: 1 });
13});
13});
14
14
15test("walls block light rays", () =>
15test("walls block light rays but can be lit themselves", () =>
16{
16{
17 const blocked = (x, y) => !(x === 1 && y === 0);
17 const blocked = (x, y) => !(x === 1 && y === 0);
18 assert.equal(rayReaches(0, 0, 2, 0, blocked), false);
18 assert.equal(rayReaches(0, 0, 2, 0, blocked), false);
19 assert.equal(rayReaches(0, 0, 2, 0, () => true), true);
19 assert.equal(rayReaches(0, 0, 2, 0, () => true), true);
20 const wallAtTarget = (x, y) => !(x === 2 && y === 0);
21 assert.equal(rayReaches(0, 0, 2, 0, wallAtTarget), true);
20});
22});
21
23
22test("a torch lights passable tiles and not tiles behind walls", () =>
24test("a torch lights passable tiles, facing walls, and not tiles behind walls", () =>
23{
25{
24 const origin = createEmptyChunkData();
26 const origin = createEmptyChunkData();
25 origin.open = true;
27 origin.open = true;
@@ -38,7 +40,8 @@ test("a torch lights passable tiles and not tiles behind walls", () =>
38 assert.ok(self.light[1] > 0, "tile beside torch is lit");
40 assert.ok(self.light[1] > 0, "tile beside torch is lit");
39 assert.ok(self.light[0] > self.light[1], "torch tile is brighter than its neighbour");
41 assert.ok(self.light[0] > self.light[1], "torch tile is brighter than its neighbour");
40 assert.ok(self.light[1] > self.light[32], "one tile away is brighter than two tiles south");
42 assert.ok(self.light[1] > self.light[32], "one tile away is brighter than two tiles south");
41 assert.equal(self.light[2], 0, "wall is unlit");
43 assert.ok(self.light[2] > 0, "wall facing the torch is lit");
44 assert.ok(self.light[1] > self.light[2], "open tile beside torch is brighter than the wall one step further");
42 assert.equal(self.light[3], 0, "tile behind wall is unlit");
45 assert.equal(self.light[3], 0, "tile behind wall is unlit");
43 assert.equal(self.light.length, CHUNK_SIZE * CHUNK_SIZE);
46 assert.equal(self.light.length, CHUNK_SIZE * CHUNK_SIZE);
44});
47});
shared/protocol/constants.js +1 −0
@@ -84,6 +84,7 @@ export const MessageType = Object.freeze({
84 84 editorLoadSettings: "EDITOR_LOAD_SETTINGS",
85 85 editorSettings: "EDITOR_SETTINGS",
86 86 editorApplyRevision: "EDITOR_APPLY_REVISION",
87 editorRevisionApplied: "EDITOR_REVISION_APPLIED",
87 88 friendRequest: "FRIEND_REQUEST",
88 89 friendAccept: "FRIEND_ACCEPT",
89 90 friendDecline: "FRIEND_DECLINE",
@@ -84,6 +84,7 @@ export const MessageType = Object.freeze({
84 editorLoadSettings: "EDITOR_LOAD_SETTINGS",
84 editorLoadSettings: "EDITOR_LOAD_SETTINGS",
85 editorSettings: "EDITOR_SETTINGS",
85 editorSettings: "EDITOR_SETTINGS",
86 editorApplyRevision: "EDITOR_APPLY_REVISION",
86 editorApplyRevision: "EDITOR_APPLY_REVISION",
87 editorRevisionApplied: "EDITOR_REVISION_APPLIED",
87 friendRequest: "FRIEND_REQUEST",
88 friendRequest: "FRIEND_REQUEST",
88 friendAccept: "FRIEND_ACCEPT",
89 friendAccept: "FRIEND_ACCEPT",
89 friendDecline: "FRIEND_DECLINE",
90 friendDecline: "FRIEND_DECLINE",