// ── What a weapon is called on a page ───────────────────────────────────── // // The feed printed "with ak47u entity". Every event read now carries a // `weaponName`: the game's own name for a ranged weapon, or the prefab name as // words with its ending dropped. const test = require('node:test') const assert = require('node:assert') const { fakeCtx } = require('./_fakes') const weaponNames = require('../model/titles/weaponNames') test('a gun is called what the game calls it', () => { assert.equal(weaponNames.nameOf('ak47u.entity'), 'Assault Rifle') assert.equal(weaponNames.nameOf('bolt_rifle.entity'), 'Bolt Action Rifle') assert.equal(weaponNames.nameOf('lr300.entity'), 'LR-300 Assault Rifle') assert.equal(weaponNames.nameOf('semi_auto_rifle.entity'), 'Semi-Automatic Rifle') assert.equal(weaponNames.nameOf('bow_hunting.entity'), 'Hunting Bow') }) test('anything the table does not hold reads as words, without its ending', () => { assert.equal(weaponNames.nameOf('machete.weapon'), 'machete') assert.equal(weaponNames.nameOf('salvaged_sword.entity'), 'salvaged sword') assert.equal(weaponNames.nameOf('bone.knife.obsidian.entity'), 'bone knife obsidian') assert.equal(weaponNames.nameOf('some_new_gun.entity'), 'some new gun') assert.equal(weaponNames.nameOf('rifle.ak'), 'rifle ak') assert.equal(weaponNames.nameOf(''), null) assert.equal(weaponNames.nameOf(null), null) }) test('no name in the table still carries a prefab ending', () => { for (const [prefab, name] of weaponNames.NAMES) { assert.ok(prefab.endsWith('.entity'), `${prefab} is a held entity's short prefab name`) assert.doesNotMatch(name, /entity|weapon|_/, `${prefab} -> ${name}`) } }) test('every event read gives a weapon its name, and leaves a frame without one alone', () => { require('../core')._reset() require('../core').init(fakeCtx()) const { shape } = require('../model/events/events.model') const kill = shape({ id: 1, kind: 'player.death', t: 1, raw: JSON.stringify({ weapon: 'ak47u.entity', distance: 22 }) }) assert.equal(kill.frame.weaponName, 'Assault Rifle') assert.equal(kill.frame.weapon, 'ak47u.entity', 'the prefab name stays: the title lists count by it') const fall = shape({ id: 2, kind: 'player.death', t: 1, raw: JSON.stringify({ attackerType: 'environment' }) }) assert.equal('weaponName' in fall.frame, false) })