fix names
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user