fix names

This commit is contained in:
guiyomu-dev
2026-02-14 19:33:39 +01:00
parent c19cbe348c
commit 285129e47e
2 changed files with 64 additions and 19 deletions

View File

@@ -7,10 +7,26 @@ import (
"go/format"
"os"
"regexp"
"strconv"
"strings"
"unicode"
)
// keep legacy name to avoid breaking nip rules
var canonicalNameOverridesByID = map[int]string{
27: "Sabre", // was generated as Saber
41: "Kris", // was generated as Kriss
135: "Stiletto", // was generated as Stilleto
166: "LargeSiegeBow", // was generated as LongSiegeBow
236: "MithrilPoint", // was generated as MithralPoint
379: "AncientShield", // was generated as KurastShield (xts)
417: "DemonHeadShield", // was generated as DemonHead (necro head)
428: "DemonHead", // was generated as Demonhead (helm)
157: "QuarterStaff", // was generated as Quarterstaff
275: "DemonCrossBow", // was generated as DemonCrossbow
469: "GriffonHeaddress", // was generated as GriffonHeadress
}
func main() {
if err := run(); err != nil {
panic(err)
@@ -25,35 +41,63 @@ func run() error {
}
defer f.Close()
nameRe := regexp.MustCompile(`Name:\s*"([^"]*)"`)
var names []string
seenNames := make(map[string]string)
nameIDRe := regexp.MustCompile(`Name:\s*"([^"]*)".*\bID:\s*([0-9]+)\b`)
namesByID := make(map[int]string)
seenCanonicalRaw := make(map[string]string)
maxID := -1
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
m := nameRe.FindStringSubmatch(line)
m := nameIDRe.FindStringSubmatch(line)
if m == nil {
continue
}
raw := m[1]
id, err := strconv.Atoi(m[2])
if err != nil {
return fmt.Errorf("parsing item id %q: %w", m[2], err)
}
canonical := canonicalizeName(raw)
if canonical == "" {
return fmt.Errorf("unable to generate canonical name for item %q", raw)
}
if override, ok := canonicalNameOverridesByID[id]; ok {
canonical = override
}
if existingRaw, exists := seenNames[canonical]; exists && existingRaw != raw {
if existing, exists := namesByID[id]; exists && existing != canonical {
return fmt.Errorf("item id %d produced inconsistent canonical names %q and %q", id, existing, canonical)
}
namesByID[id] = canonical
key := strings.ToLower(canonical)
if existingRaw, exists := seenCanonicalRaw[key]; exists && existingRaw != raw {
return fmt.Errorf("duplicate generated item name %q from %q and %q", canonical, existingRaw, raw)
}
if _, exists := seenNames[canonical]; !exists {
seenNames[canonical] = raw
if _, exists := seenCanonicalRaw[key]; !exists {
seenCanonicalRaw[key] = raw
}
if id > maxID {
maxID = id
}
names = append(names, canonical)
}
if err := scanner.Err(); err != nil {
return err
}
if maxID < 0 {
return fmt.Errorf("no item names found in pkg/data/item/items.go")
}
names := make([]string, maxID+1)
for id := 0; id <= maxID; id++ {
name, ok := namesByID[id]
if !ok {
return fmt.Errorf("missing item name for id %d in pkg/data/item/items.go", id)
}
names[id] = name
}
fmt.Printf("Extracted %d names from items.go\n", len(names))
// Write name.go
@@ -107,6 +151,7 @@ func GetIDByName(itemName string) int {
type Name string
var Names = []string{
`)
for _, n := range names {

View File

@@ -75,7 +75,7 @@ var Names = []string{
"GreatMaul",
"ShortSword",
"Scimitar",
"Saber",
"Sabre",
"Falchion",
"CrystalSword",
"BroadSword",
@@ -89,7 +89,7 @@ var Names = []string{
"GreatSword",
"Dagger",
"Dirk",
"Kriss",
"Kris",
"Blade",
"ThrowingKnife",
"ThrowingAxe",
@@ -183,7 +183,7 @@ var Names = []string{
"Poignard",
"Rondel",
"Cinquedeas",
"Stilleto",
"Stiletto",
"BattleDart",
"Francisca",
"WarDart",
@@ -205,7 +205,7 @@ var Names = []string{
"BecDeCorbin",
"GrimScythe",
"JoStaff",
"Quarterstaff",
"QuarterStaff",
"CedarStaff",
"GothicStaff",
"RuneStaff",
@@ -214,7 +214,7 @@ var Names = []string{
"CedarBow",
"DoubleBow",
"ShortSiegeBow",
"LongSiegeBow",
"LargeSiegeBow",
"RuneBow",
"GothicBow",
"Arbalest",
@@ -284,7 +284,7 @@ var Names = []string{
"ColossusSword",
"ColossusBlade",
"BoneKnife",
"MithralPoint",
"MithrilPoint",
"FangedKnife",
"LegendSpike",
"FlyingKnife",
@@ -323,7 +323,7 @@ var Names = []string{
"PelletBow",
"GorgonCrossbow",
"ColossusCrossbow",
"DemonCrossbow",
"DemonCrossBow",
"EagleOrb",
"SacredGlobe",
"SmokedSphere",
@@ -427,7 +427,7 @@ var Names = []string{
"Scutum",
"DragonShield",
"Pavise",
"KurastShield",
"AncientShield",
"DemonhideGloves",
"SharkskinGloves",
"HeavyBracers",
@@ -465,7 +465,7 @@ var Names = []string{
"ZombieHead",
"UnravellerHead",
"GargoyleHead",
"DemonHead",
"DemonHeadShield",
"Circlet",
"Coronet",
"Tiara",
@@ -476,7 +476,7 @@ var Names = []string{
"GiantConch",
"SpiredHelm",
"Corona",
"Demonhead",
"DemonHead",
"DuskShroud",
"Wyrmhide",
"ScarabHusk",
@@ -517,7 +517,7 @@ var Names = []string{
"TrollNest",
"BladeBarrier",
"AlphaHelm",
"GriffonHeadress",
"GriffonHeaddress",
"HuntersGuise",
"SacredFeathers",
"TotemicMask",