Move all package-level vars into gameData; finish lint adoption
gochecknoglobals: all 37 package-level tables consolidated into the gameData struct (game/tables.go), built by newGameData() and carried on RogueGame as g.data (set in NewGame and Restore). ObjectKind Glyph()/objectKindForGlyph are now switches; the table-reading subtype Stringer methods are gone; isMagic is a RogueGame method. goconst: repeated words named (potionName/scrollName/ringName/goldName in object.go, wandName/staffName in sticks.go, ripWall in tables.go). exhaustive, testpackage: disabled in .golangci.yml with sneak's approval (2026-07-07). Also reverts misspell's silent corruption of the "ther" scroll-name syllable (it had become "there", changing generated scroll names vs C). Remaining red: cyclop/gocognit/nestif until refactor step 7; mnd awaits a ruling. TODO.md rotated; MEMORY.md lint notes updated.
This commit is contained in:
@@ -26,36 +26,49 @@ const (
|
||||
KindRingOrStick ObjectKind = -2
|
||||
)
|
||||
|
||||
// kindGlyphs maps each kind to the character Rogue draws for it.
|
||||
var kindGlyphs = [...]byte{
|
||||
KindNone: ' ',
|
||||
KindPotion: Potion,
|
||||
KindScroll: Scroll,
|
||||
KindFood: Food,
|
||||
KindWeapon: Weapon,
|
||||
KindArmor: Armor,
|
||||
KindRing: Ring,
|
||||
KindWand: Stick,
|
||||
KindAmulet: Amulet,
|
||||
KindGold: Gold,
|
||||
}
|
||||
// Category words shared by ObjectKind.String, the discovery list, and the
|
||||
// ident table. (The bare identifiers Potion, Scroll, Ring, Gold are the
|
||||
// glyph byte constants.)
|
||||
const (
|
||||
potionName = "potion"
|
||||
scrollName = "scroll"
|
||||
ringName = "ring"
|
||||
goldName = "gold"
|
||||
)
|
||||
|
||||
// Glyph returns the map/display character for this kind of object.
|
||||
func (k ObjectKind) Glyph() byte {
|
||||
if k < 0 || int(k) >= len(kindGlyphs) {
|
||||
return ' '
|
||||
switch k {
|
||||
case KindPotion:
|
||||
return Potion
|
||||
case KindScroll:
|
||||
return Scroll
|
||||
case KindFood:
|
||||
return Food
|
||||
case KindWeapon:
|
||||
return Weapon
|
||||
case KindArmor:
|
||||
return Armor
|
||||
case KindRing:
|
||||
return Ring
|
||||
case KindWand:
|
||||
return Stick
|
||||
case KindAmulet:
|
||||
return Amulet
|
||||
case KindGold:
|
||||
return Gold
|
||||
}
|
||||
|
||||
return kindGlyphs[k]
|
||||
return ' '
|
||||
}
|
||||
|
||||
// String names the category the way the C type_name() did.
|
||||
func (k ObjectKind) String() string {
|
||||
switch k {
|
||||
case KindPotion:
|
||||
return "potion"
|
||||
return potionName
|
||||
case KindScroll:
|
||||
return "scroll"
|
||||
return scrollName
|
||||
case KindFood:
|
||||
return "food"
|
||||
case KindWeapon:
|
||||
@@ -63,13 +76,13 @@ func (k ObjectKind) String() string {
|
||||
case KindArmor:
|
||||
return "suit of armor"
|
||||
case KindRing:
|
||||
return "ring"
|
||||
return ringName
|
||||
case KindWand:
|
||||
return "wand or staff"
|
||||
case KindAmulet:
|
||||
return "amulet"
|
||||
case KindGold:
|
||||
return "gold"
|
||||
return goldName
|
||||
case KindRingOrStick:
|
||||
return "ring, wand or staff"
|
||||
}
|
||||
@@ -80,10 +93,25 @@ func (k ObjectKind) String() string {
|
||||
// objectKindForGlyph is the reverse of Glyph: what category of item does a
|
||||
// map character denote. Returns KindNone for non-item characters.
|
||||
func objectKindForGlyph(ch byte) ObjectKind {
|
||||
for k, g := range kindGlyphs {
|
||||
if g == ch && ObjectKind(k) != KindNone {
|
||||
return ObjectKind(k)
|
||||
}
|
||||
switch ch {
|
||||
case Potion:
|
||||
return KindPotion
|
||||
case Scroll:
|
||||
return KindScroll
|
||||
case Food:
|
||||
return KindFood
|
||||
case Weapon:
|
||||
return KindWeapon
|
||||
case Armor:
|
||||
return KindArmor
|
||||
case Ring:
|
||||
return KindRing
|
||||
case Stick:
|
||||
return KindWand
|
||||
case Amulet:
|
||||
return KindAmulet
|
||||
case Gold:
|
||||
return KindGold
|
||||
}
|
||||
|
||||
return KindNone
|
||||
|
||||
Reference in New Issue
Block a user