fix(feed): print weapons by name, not "ak47u entity"
The bridge names a kill's weapon by the held entity's short prefab name (ak47u.entity), and the feed printed it with the dots turned to spaces: "with ak47u entity". Every event read now gives the frame a weaponName (server/model/titles/weaponNames.js): the game's own English name for the 53 ranged weapons (guns, bows, crossbows, launchers, flamethrowers), read off the Oxide rig's item list on Rust 26139947, and for anything else the prefab name as words with its .entity/.weapon ending dropped. The site prints weaponName and falls back to the same stripping for an older server. The prefab name stays in the frame: the title lists count by it. Added at read, so stored rows are renamed too. No protocol change; the events route's Swagger description names the new field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
49
server/test/weaponNames.test.js
Normal file
49
server/test/weaponNames.test.js
Normal file
@@ -0,0 +1,49 @@
|
||||
// ── 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)
|
||||
})
|
||||
Reference in New Issue
Block a user