BlueGit

timfa questward

Fix equipment stat columns: bows Archery, clubs Clubs, war axes Axes.

Melee/ranged editor sections now use per-section skills instead of one shared category column.

timfa Tim Falken · pushed by timfa

Authored 2026-09-02 · 2 months ago

Hash
a776ee4a65541704fbc233ba8498952899471bf1
Parent
b4a30091
4 files changed +72 −10
client/src/editor/settingsModal.js +4 −2
@@ -28,7 +28,8 @@ import
28 28 normalizeEquipmentStatBonuses,
29 29 equipmentStatBonusMapsEqual,
30 30 equipmentStatRowItemId,
31 equipmentStatRowDefaultTier
31 equipmentStatRowDefaultTier,
32 equipmentStatSectionStats
32 33 } from "/shared/definitions/equipmentStatCategories.js";
33 34 import { applyItemIcon } from "/src/render/potionIcon.js";
34 35
@@ -556,6 +557,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
556 557
557 558 for (const section of category.sections)
558 559 {
560 const sectionStats = equipmentStatSectionStats(category, section);
559 561 if (section.label)
560 562 {
561 563 const heading = document.createElement("h3");
@@ -627,7 +629,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
627 629 const draftCell = draftEquipmentStats[category.id]?.[row.pieceKey]?.[tier] ?? {};
628 630 const baseCell = baselineTable[category.id]?.[row.pieceKey]?.[tier] ?? {};
629 631
630 for (const skillId of category.stats)
632 for (const skillId of sectionStats)
631 633 {
632 634 const line = document.createElement("label");
633 635 line.className = "equip-stats-stat";
@@ -28,7 +28,8 @@ import
28 normalizeEquipmentStatBonuses,
28 normalizeEquipmentStatBonuses,
29 equipmentStatBonusMapsEqual,
29 equipmentStatBonusMapsEqual,
30 equipmentStatRowItemId,
30 equipmentStatRowItemId,
31 equipmentStatRowDefaultTier
31 equipmentStatRowDefaultTier,
32 equipmentStatSectionStats
32 } from "/shared/definitions/equipmentStatCategories.js";
33 } from "/shared/definitions/equipmentStatCategories.js";
33import { applyItemIcon } from "/src/render/potionIcon.js";
34import { applyItemIcon } from "/src/render/potionIcon.js";
34
35
@@ -556,6 +557,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
556
557
557 for (const section of category.sections)
558 for (const section of category.sections)
558 {
559 {
560 const sectionStats = equipmentStatSectionStats(category, section);
559 if (section.label)
561 if (section.label)
560 {
562 {
561 const heading = document.createElement("h3");
563 const heading = document.createElement("h3");
@@ -627,7 +629,7 @@ export function initSettingsModal ({ socket, MessageType, onApplied, onPreviewNi
627 const draftCell = draftEquipmentStats[category.id]?.[row.pieceKey]?.[tier] ?? {};
629 const draftCell = draftEquipmentStats[category.id]?.[row.pieceKey]?.[tier] ?? {};
628 const baseCell = baselineTable[category.id]?.[row.pieceKey]?.[tier] ?? {};
630 const baseCell = baselineTable[category.id]?.[row.pieceKey]?.[tier] ?? {};
629
631
630 for (const skillId of category.stats)
632 for (const skillId of sectionStats)
631 {
633 {
632 const line = document.createElement("label");
634 const line = document.createElement("label");
633 line.className = "equip-stats-stat";
635 line.className = "equip-stats-stat";
server/tests/equipment.test.js +33 −0
@@ -309,6 +309,39 @@ test("full helm keeps +1 defence only, not magic or archery penalty", () =>
309 309 assert.equal(defaults.bronze.archery, -1);
310 310 });
311 311
312 test("bows bonus archery and arrows bonus dexterity", () =>
313 {
314 const defaults = defaultEquipmentStatBonuses().rangedWeapons;
315 assert.ok(Object.hasOwn(defaults.bow.pine, SkillId.archery));
316 assert.equal(Object.hasOwn(defaults.bow.pine, SkillId.dexterity), false);
317 assert.ok(Object.hasOwn(defaults.arrow.bronze, SkillId.dexterity));
318 assert.equal(Object.hasOwn(defaults.arrow.bronze, SkillId.archery), false);
319 assert.equal(defaults.bow.pine.archery, tierStatBonus(WoodTier.pine));
320 assert.equal(defaults.arrow.bronze.dexterity, tierStatBonus(MaterialTier.bronze));
321 });
322
323 test("melee weapon sections use Clubs, Swords, and Axes skills", () =>
324 {
325 const defaults = defaultEquipmentStatBonuses().meleeWeapons;
326 assert.ok(Object.hasOwn(defaults.club.pine, SkillId.clubfighting));
327 assert.equal(Object.hasOwn(defaults.club.pine, SkillId.swordfighting), false);
328 assert.ok(Object.hasOwn(defaults.sword.bronze, SkillId.swordfighting));
329 assert.ok(Object.hasOwn(defaults.warAxe.bronze, SkillId.axefighting));
330 assert.equal(Object.hasOwn(defaults.warAxe.bronze, SkillId.swordfighting), false);
331 assert.equal(Object.hasOwn(defaults.warAxe.bronze, SkillId.clubfighting), false);
332 });
333
334 test("legacy bow dexterity settings migrate to archery", () =>
335 {
336 const migrated = normalizeEquipmentStatBonuses({
337 rangedWeapons: {
338 bow: { pine: { dexterity: 4 } }
339 }
340 });
341 assert.equal(migrated.rangedWeapons.bow.pine.archery, 4);
342 assert.equal(Object.hasOwn(migrated.rangedWeapons.bow.pine, SkillId.dexterity), false);
343 });
344
312 345 test("wizard robe bottoms use single cloth tint", () =>
313 346 {
314 347 const def = itemDefinition(WizardItemId.cottonRobeBottoms);
@@ -309,6 +309,39 @@ test("full helm keeps +1 defence only, not magic or archery penalty", () =>
309 assert.equal(defaults.bronze.archery, -1);
309 assert.equal(defaults.bronze.archery, -1);
310});
310});
311
311
312test("bows bonus archery and arrows bonus dexterity", () =>
313{
314 const defaults = defaultEquipmentStatBonuses().rangedWeapons;
315 assert.ok(Object.hasOwn(defaults.bow.pine, SkillId.archery));
316 assert.equal(Object.hasOwn(defaults.bow.pine, SkillId.dexterity), false);
317 assert.ok(Object.hasOwn(defaults.arrow.bronze, SkillId.dexterity));
318 assert.equal(Object.hasOwn(defaults.arrow.bronze, SkillId.archery), false);
319 assert.equal(defaults.bow.pine.archery, tierStatBonus(WoodTier.pine));
320 assert.equal(defaults.arrow.bronze.dexterity, tierStatBonus(MaterialTier.bronze));
321});
322
323test("melee weapon sections use Clubs, Swords, and Axes skills", () =>
324{
325 const defaults = defaultEquipmentStatBonuses().meleeWeapons;
326 assert.ok(Object.hasOwn(defaults.club.pine, SkillId.clubfighting));
327 assert.equal(Object.hasOwn(defaults.club.pine, SkillId.swordfighting), false);
328 assert.ok(Object.hasOwn(defaults.sword.bronze, SkillId.swordfighting));
329 assert.ok(Object.hasOwn(defaults.warAxe.bronze, SkillId.axefighting));
330 assert.equal(Object.hasOwn(defaults.warAxe.bronze, SkillId.swordfighting), false);
331 assert.equal(Object.hasOwn(defaults.warAxe.bronze, SkillId.clubfighting), false);
332});
333
334test("legacy bow dexterity settings migrate to archery", () =>
335{
336 const migrated = normalizeEquipmentStatBonuses({
337 rangedWeapons: {
338 bow: { pine: { dexterity: 4 } }
339 }
340 });
341 assert.equal(migrated.rangedWeapons.bow.pine.archery, 4);
342 assert.equal(Object.hasOwn(migrated.rangedWeapons.bow.pine, SkillId.dexterity), false);
343});
344
312test("wizard robe bottoms use single cloth tint", () =>
345test("wizard robe bottoms use single cloth tint", () =>
313{
346{
314 const def = itemDefinition(WizardItemId.cottonRobeBottoms);
347 const def = itemDefinition(WizardItemId.cottonRobeBottoms);
shared/definitions/equipmentStatCategories.js +34 −8
@@ -163,6 +163,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
163 163 Object.freeze({
164 164 id: "wood",
165 165 label: "Clubs",
166 stats: Object.freeze([SkillId.strength, SkillId.clubfighting]),
166 167 tierOrder: WOOD_TIER_ORDER,
167 168 tierDisplayName: woodDisplayName,
168 169 rows: Object.freeze([
@@ -180,6 +181,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
180 181 Object.freeze({
181 182 id: "swords",
182 183 label: "Swords",
184 stats: Object.freeze([SkillId.strength, SkillId.swordfighting]),
183 185 tierOrder: MATERIAL_TIER_ORDER,
184 186 tierDisplayName: metalDisplayName,
185 187 rows: Object.freeze([
@@ -198,6 +200,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
198 200 Object.freeze({
199 201 id: "warAxes",
200 202 label: "War axes",
203 stats: Object.freeze([SkillId.strength, SkillId.axefighting]),
201 204 tierOrder: MATERIAL_TIER_ORDER,
202 205 tierDisplayName: metalDisplayName,
203 206 rows: Object.freeze([
@@ -221,6 +224,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
221 224 Object.freeze({
222 225 id: "bows",
223 226 label: "Bows",
227 stats: Object.freeze([SkillId.archery]),
224 228 tierOrder: WOOD_TIER_ORDER,
225 229 tierDisplayName: woodDisplayName,
226 230 rows: Object.freeze([
@@ -234,6 +238,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
234 238 Object.freeze({
235 239 id: "arrows",
236 240 label: "Arrows",
241 stats: Object.freeze([SkillId.dexterity]),
237 242 tierOrder: MATERIAL_TIER_ORDER,
238 243 tierDisplayName: metalDisplayName,
239 244 rows: Object.freeze([
@@ -387,6 +392,12 @@ export function equipmentStatCategory (categoryId)
387 392 return EQUIPMENT_STAT_CATEGORIES.find((entry) => entry.id === categoryId) ?? null;
388 393 }
389 394
395 /** Stats columns for a section (section override, else category). */
396 export function equipmentStatSectionStats (category, section)
397 {
398 return section?.stats ?? category?.stats ?? [];
399 }
400
390 401 /** Flat list of all piece rows with category + section context. */
391 402 export function listEquipmentStatRows ()
392 403 {
@@ -395,11 +406,12 @@ export function listEquipmentStatRows ()
395 406 {
396 407 for (const section of category.sections)
397 408 {
409 const stats = equipmentStatSectionStats(category, section);
398 410 for (const row of section.rows)
399 411 {
400 412 out.push({
401 413 categoryId: category.id,
402 stats: category.stats,
414 stats,
403 415 section,
404 416 row
405 417 });
@@ -527,6 +539,7 @@ export function defaultEquipmentStatBonuses ()
527 539 const cat = {};
528 540 for (const section of category.sections)
529 541 {
542 const stats = equipmentStatSectionStats(category, section);
530 543 for (const row of section.rows)
531 544 {
532 545 const byTier = {};
@@ -535,7 +548,7 @@ export function defaultEquipmentStatBonuses ()
535 548 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
536 549 if (itemId == null && !row.singleton)
537 550 { continue; }
538 byTier[tier] = defaultCellForRow(row, category.stats, tier);
551 byTier[tier] = defaultCellForRow(row, stats, tier);
539 552 }
540 553 cat[row.pieceKey] = byTier;
541 554 }
@@ -571,6 +584,7 @@ export function normalizeEquipmentStatBonuses (raw)
571 584 const cat = {};
572 585 for (const section of category.sections)
573 586 {
587 const stats = equipmentStatSectionStats(category, section);
574 588 for (const row of section.rows)
575 589 {
576 590 const srcPiece = srcCat[row.pieceKey] && typeof srcCat[row.pieceKey] === "object"
@@ -586,13 +600,24 @@ export function normalizeEquipmentStatBonuses (raw)
586 600 const srcCell = srcPiece[tier] && typeof srcPiece[tier] === "object"
587 601 ? srcPiece[tier]
588 602 : null;
589 const defCell = defPiece[tier] ?? defaultCellForRow(row, category.stats, tier);
603 const defCell = defPiece[tier] ?? defaultCellForRow(row, stats, tier);
590 604 const cell = {};
591 for (const skillId of category.stats)
605 for (const skillId of stats)
592 606 {
593 cell[skillId] = srcCell && Object.prototype.hasOwnProperty.call(srcCell, skillId)
594 ? coerceBonusInt(srcCell[skillId])
595 : coerceBonusInt(defCell[skillId]);
607 if (srcCell && Object.prototype.hasOwnProperty.call(srcCell, skillId))
608 { cell[skillId] = coerceBonusInt(srcCell[skillId]); }
609 else if (
610 skillId === SkillId.archery
611 && row.pieceKey === "bow"
612 && srcCell
613 && Object.prototype.hasOwnProperty.call(srcCell, SkillId.dexterity)
614 )
615 {
616 // Legacy: bows stored dexterity before archery column split.
617 cell[skillId] = coerceBonusInt(srcCell[SkillId.dexterity]);
618 }
619 else
620 { cell[skillId] = coerceBonusInt(defCell[skillId]); }
596 621 }
597 622 byTier[tier] = cell;
598 623 }
@@ -648,6 +673,7 @@ export function diffEquipmentStatBonuses (previous, next, displayNameFor = null)
648 673 {
649 674 for (const section of category.sections)
650 675 {
676 const stats = equipmentStatSectionStats(category, section);
651 677 for (const row of section.rows)
652 678 {
653 679 for (const tier of section.tierOrder)
@@ -656,7 +682,7 @@ export function diffEquipmentStatBonuses (previous, next, displayNameFor = null)
656 682 const to = upcoming[category.id]?.[row.pieceKey]?.[tier];
657 683 if (!from && !to)
658 684 { continue; }
659 for (const skillId of category.stats)
685 for (const skillId of stats)
660 686 {
661 687 const a = coerceBonusInt(from?.[skillId]);
662 688 const b = coerceBonusInt(to?.[skillId]);
@@ -163,6 +163,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
163 Object.freeze({
163 Object.freeze({
164 id: "wood",
164 id: "wood",
165 label: "Clubs",
165 label: "Clubs",
166 stats: Object.freeze([SkillId.strength, SkillId.clubfighting]),
166 tierOrder: WOOD_TIER_ORDER,
167 tierOrder: WOOD_TIER_ORDER,
167 tierDisplayName: woodDisplayName,
168 tierDisplayName: woodDisplayName,
168 rows: Object.freeze([
169 rows: Object.freeze([
@@ -180,6 +181,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
180 Object.freeze({
181 Object.freeze({
181 id: "swords",
182 id: "swords",
182 label: "Swords",
183 label: "Swords",
184 stats: Object.freeze([SkillId.strength, SkillId.swordfighting]),
183 tierOrder: MATERIAL_TIER_ORDER,
185 tierOrder: MATERIAL_TIER_ORDER,
184 tierDisplayName: metalDisplayName,
186 tierDisplayName: metalDisplayName,
185 rows: Object.freeze([
187 rows: Object.freeze([
@@ -198,6 +200,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
198 Object.freeze({
200 Object.freeze({
199 id: "warAxes",
201 id: "warAxes",
200 label: "War axes",
202 label: "War axes",
203 stats: Object.freeze([SkillId.strength, SkillId.axefighting]),
201 tierOrder: MATERIAL_TIER_ORDER,
204 tierOrder: MATERIAL_TIER_ORDER,
202 tierDisplayName: metalDisplayName,
205 tierDisplayName: metalDisplayName,
203 rows: Object.freeze([
206 rows: Object.freeze([
@@ -221,6 +224,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
221 Object.freeze({
224 Object.freeze({
222 id: "bows",
225 id: "bows",
223 label: "Bows",
226 label: "Bows",
227 stats: Object.freeze([SkillId.archery]),
224 tierOrder: WOOD_TIER_ORDER,
228 tierOrder: WOOD_TIER_ORDER,
225 tierDisplayName: woodDisplayName,
229 tierDisplayName: woodDisplayName,
226 rows: Object.freeze([
230 rows: Object.freeze([
@@ -234,6 +238,7 @@ export const EQUIPMENT_STAT_CATEGORIES = Object.freeze([
234 Object.freeze({
238 Object.freeze({
235 id: "arrows",
239 id: "arrows",
236 label: "Arrows",
240 label: "Arrows",
241 stats: Object.freeze([SkillId.dexterity]),
237 tierOrder: MATERIAL_TIER_ORDER,
242 tierOrder: MATERIAL_TIER_ORDER,
238 tierDisplayName: metalDisplayName,
243 tierDisplayName: metalDisplayName,
239 rows: Object.freeze([
244 rows: Object.freeze([
@@ -387,6 +392,12 @@ export function equipmentStatCategory (categoryId)
387 return EQUIPMENT_STAT_CATEGORIES.find((entry) => entry.id === categoryId) ?? null;
392 return EQUIPMENT_STAT_CATEGORIES.find((entry) => entry.id === categoryId) ?? null;
388}
393}
389
394
395/** Stats columns for a section (section override, else category). */
396export function equipmentStatSectionStats (category, section)
397{
398 return section?.stats ?? category?.stats ?? [];
399}
400
390/** Flat list of all piece rows with category + section context. */
401/** Flat list of all piece rows with category + section context. */
391export function listEquipmentStatRows ()
402export function listEquipmentStatRows ()
392{
403{
@@ -395,11 +406,12 @@ export function listEquipmentStatRows ()
395 {
406 {
396 for (const section of category.sections)
407 for (const section of category.sections)
397 {
408 {
409 const stats = equipmentStatSectionStats(category, section);
398 for (const row of section.rows)
410 for (const row of section.rows)
399 {
411 {
400 out.push({
412 out.push({
401 categoryId: category.id,
413 categoryId: category.id,
402 stats: category.stats,
414 stats,
403 section,
415 section,
404 row
416 row
405 });
417 });
@@ -527,6 +539,7 @@ export function defaultEquipmentStatBonuses ()
527 const cat = {};
539 const cat = {};
528 for (const section of category.sections)
540 for (const section of category.sections)
529 {
541 {
542 const stats = equipmentStatSectionStats(category, section);
530 for (const row of section.rows)
543 for (const row of section.rows)
531 {
544 {
532 const byTier = {};
545 const byTier = {};
@@ -535,7 +548,7 @@ export function defaultEquipmentStatBonuses ()
535 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
548 const itemId = row.resolveItemId?.(tier) ?? (row.singleton ? row.itemId : null);
536 if (itemId == null && !row.singleton)
549 if (itemId == null && !row.singleton)
537 { continue; }
550 { continue; }
538 byTier[tier] = defaultCellForRow(row, category.stats, tier);
551 byTier[tier] = defaultCellForRow(row, stats, tier);
539 }
552 }
540 cat[row.pieceKey] = byTier;
553 cat[row.pieceKey] = byTier;
541 }
554 }
@@ -571,6 +584,7 @@ export function normalizeEquipmentStatBonuses (raw)
571 const cat = {};
584 const cat = {};
572 for (const section of category.sections)
585 for (const section of category.sections)
573 {
586 {
587 const stats = equipmentStatSectionStats(category, section);
574 for (const row of section.rows)
588 for (const row of section.rows)
575 {
589 {
576 const srcPiece = srcCat[row.pieceKey] && typeof srcCat[row.pieceKey] === "object"
590 const srcPiece = srcCat[row.pieceKey] && typeof srcCat[row.pieceKey] === "object"
@@ -586,13 +600,24 @@ export function normalizeEquipmentStatBonuses (raw)
586 const srcCell = srcPiece[tier] && typeof srcPiece[tier] === "object"
600 const srcCell = srcPiece[tier] && typeof srcPiece[tier] === "object"
587 ? srcPiece[tier]
601 ? srcPiece[tier]
588 : null;
602 : null;
589 const defCell = defPiece[tier] ?? defaultCellForRow(row, category.stats, tier);
603 const defCell = defPiece[tier] ?? defaultCellForRow(row, stats, tier);
590 const cell = {};
604 const cell = {};
591 for (const skillId of category.stats)
605 for (const skillId of stats)
592 {
606 {
593 cell[skillId] = srcCell && Object.prototype.hasOwnProperty.call(srcCell, skillId)
607 if (srcCell && Object.prototype.hasOwnProperty.call(srcCell, skillId))
594 ? coerceBonusInt(srcCell[skillId])
608 { cell[skillId] = coerceBonusInt(srcCell[skillId]); }
595 : coerceBonusInt(defCell[skillId]);
609 else if (
610 skillId === SkillId.archery
611 && row.pieceKey === "bow"
612 && srcCell
613 && Object.prototype.hasOwnProperty.call(srcCell, SkillId.dexterity)
614 )
615 {
616 // Legacy: bows stored dexterity before archery column split.
617 cell[skillId] = coerceBonusInt(srcCell[SkillId.dexterity]);
618 }
619 else
620 { cell[skillId] = coerceBonusInt(defCell[skillId]); }
596 }
621 }
597 byTier[tier] = cell;
622 byTier[tier] = cell;
598 }
623 }
@@ -648,6 +673,7 @@ export function diffEquipmentStatBonuses (previous, next, displayNameFor = null)
648 {
673 {
649 for (const section of category.sections)
674 for (const section of category.sections)
650 {
675 {
676 const stats = equipmentStatSectionStats(category, section);
651 for (const row of section.rows)
677 for (const row of section.rows)
652 {
678 {
653 for (const tier of section.tierOrder)
679 for (const tier of section.tierOrder)
@@ -656,7 +682,7 @@ export function diffEquipmentStatBonuses (previous, next, displayNameFor = null)
656 const to = upcoming[category.id]?.[row.pieceKey]?.[tier];
682 const to = upcoming[category.id]?.[row.pieceKey]?.[tier];
657 if (!from && !to)
683 if (!from && !to)
658 { continue; }
684 { continue; }
659 for (const skillId of category.stats)
685 for (const skillId of stats)
660 {
686 {
661 const a = coerceBonusInt(from?.[skillId]);
687 const a = coerceBonusInt(from?.[skillId]);
662 const b = coerceBonusInt(to?.[skillId]);
688 const b = coerceBonusInt(to?.[skillId]);
shared/equipment/stats.js +1 −0
@@ -102,6 +102,7 @@ function emptyBonuses ()
102 102 [SkillId.mind]: 0,
103 103 [SkillId.swordfighting]: 0,
104 104 [SkillId.clubfighting]: 0,
105 [SkillId.axefighting]: 0,
105 106 [SkillId.archery]: 0
106 107 };
107 108 }
@@ -102,6 +102,7 @@ function emptyBonuses ()
102 [SkillId.mind]: 0,
102 [SkillId.mind]: 0,
103 [SkillId.swordfighting]: 0,
103 [SkillId.swordfighting]: 0,
104 [SkillId.clubfighting]: 0,
104 [SkillId.clubfighting]: 0,
105 [SkillId.axefighting]: 0,
105 [SkillId.archery]: 0
106 [SkillId.archery]: 0
106 };
107 };
107}
108}