fix names
This commit is contained in:
@@ -7,10 +7,26 @@ import (
|
|||||||
"go/format"
|
"go/format"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"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() {
|
func main() {
|
||||||
if err := run(); err != nil {
|
if err := run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -25,35 +41,63 @@ func run() error {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
nameRe := regexp.MustCompile(`Name:\s*"([^"]*)"`)
|
nameIDRe := regexp.MustCompile(`Name:\s*"([^"]*)".*\bID:\s*([0-9]+)\b`)
|
||||||
var names []string
|
namesByID := make(map[int]string)
|
||||||
seenNames := make(map[string]string)
|
seenCanonicalRaw := make(map[string]string)
|
||||||
|
maxID := -1
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
m := nameRe.FindStringSubmatch(line)
|
m := nameIDRe.FindStringSubmatch(line)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
raw := m[1]
|
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)
|
canonical := canonicalizeName(raw)
|
||||||
if canonical == "" {
|
if canonical == "" {
|
||||||
return fmt.Errorf("unable to generate canonical name for item %q", raw)
|
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)
|
return fmt.Errorf("duplicate generated item name %q from %q and %q", canonical, existingRaw, raw)
|
||||||
}
|
}
|
||||||
if _, exists := seenNames[canonical]; !exists {
|
if _, exists := seenCanonicalRaw[key]; !exists {
|
||||||
seenNames[canonical] = raw
|
seenCanonicalRaw[key] = raw
|
||||||
|
}
|
||||||
|
if id > maxID {
|
||||||
|
maxID = id
|
||||||
}
|
}
|
||||||
names = append(names, canonical)
|
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
return err
|
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))
|
fmt.Printf("Extracted %d names from items.go\n", len(names))
|
||||||
|
|
||||||
// Write name.go
|
// Write name.go
|
||||||
@@ -107,6 +151,7 @@ func GetIDByName(itemName string) int {
|
|||||||
|
|
||||||
type Name string
|
type Name string
|
||||||
|
|
||||||
|
|
||||||
var Names = []string{
|
var Names = []string{
|
||||||
`)
|
`)
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ var Names = []string{
|
|||||||
"GreatMaul",
|
"GreatMaul",
|
||||||
"ShortSword",
|
"ShortSword",
|
||||||
"Scimitar",
|
"Scimitar",
|
||||||
"Saber",
|
"Sabre",
|
||||||
"Falchion",
|
"Falchion",
|
||||||
"CrystalSword",
|
"CrystalSword",
|
||||||
"BroadSword",
|
"BroadSword",
|
||||||
@@ -89,7 +89,7 @@ var Names = []string{
|
|||||||
"GreatSword",
|
"GreatSword",
|
||||||
"Dagger",
|
"Dagger",
|
||||||
"Dirk",
|
"Dirk",
|
||||||
"Kriss",
|
"Kris",
|
||||||
"Blade",
|
"Blade",
|
||||||
"ThrowingKnife",
|
"ThrowingKnife",
|
||||||
"ThrowingAxe",
|
"ThrowingAxe",
|
||||||
@@ -183,7 +183,7 @@ var Names = []string{
|
|||||||
"Poignard",
|
"Poignard",
|
||||||
"Rondel",
|
"Rondel",
|
||||||
"Cinquedeas",
|
"Cinquedeas",
|
||||||
"Stilleto",
|
"Stiletto",
|
||||||
"BattleDart",
|
"BattleDart",
|
||||||
"Francisca",
|
"Francisca",
|
||||||
"WarDart",
|
"WarDart",
|
||||||
@@ -205,7 +205,7 @@ var Names = []string{
|
|||||||
"BecDeCorbin",
|
"BecDeCorbin",
|
||||||
"GrimScythe",
|
"GrimScythe",
|
||||||
"JoStaff",
|
"JoStaff",
|
||||||
"Quarterstaff",
|
"QuarterStaff",
|
||||||
"CedarStaff",
|
"CedarStaff",
|
||||||
"GothicStaff",
|
"GothicStaff",
|
||||||
"RuneStaff",
|
"RuneStaff",
|
||||||
@@ -214,7 +214,7 @@ var Names = []string{
|
|||||||
"CedarBow",
|
"CedarBow",
|
||||||
"DoubleBow",
|
"DoubleBow",
|
||||||
"ShortSiegeBow",
|
"ShortSiegeBow",
|
||||||
"LongSiegeBow",
|
"LargeSiegeBow",
|
||||||
"RuneBow",
|
"RuneBow",
|
||||||
"GothicBow",
|
"GothicBow",
|
||||||
"Arbalest",
|
"Arbalest",
|
||||||
@@ -284,7 +284,7 @@ var Names = []string{
|
|||||||
"ColossusSword",
|
"ColossusSword",
|
||||||
"ColossusBlade",
|
"ColossusBlade",
|
||||||
"BoneKnife",
|
"BoneKnife",
|
||||||
"MithralPoint",
|
"MithrilPoint",
|
||||||
"FangedKnife",
|
"FangedKnife",
|
||||||
"LegendSpike",
|
"LegendSpike",
|
||||||
"FlyingKnife",
|
"FlyingKnife",
|
||||||
@@ -323,7 +323,7 @@ var Names = []string{
|
|||||||
"PelletBow",
|
"PelletBow",
|
||||||
"GorgonCrossbow",
|
"GorgonCrossbow",
|
||||||
"ColossusCrossbow",
|
"ColossusCrossbow",
|
||||||
"DemonCrossbow",
|
"DemonCrossBow",
|
||||||
"EagleOrb",
|
"EagleOrb",
|
||||||
"SacredGlobe",
|
"SacredGlobe",
|
||||||
"SmokedSphere",
|
"SmokedSphere",
|
||||||
@@ -427,7 +427,7 @@ var Names = []string{
|
|||||||
"Scutum",
|
"Scutum",
|
||||||
"DragonShield",
|
"DragonShield",
|
||||||
"Pavise",
|
"Pavise",
|
||||||
"KurastShield",
|
"AncientShield",
|
||||||
"DemonhideGloves",
|
"DemonhideGloves",
|
||||||
"SharkskinGloves",
|
"SharkskinGloves",
|
||||||
"HeavyBracers",
|
"HeavyBracers",
|
||||||
@@ -465,7 +465,7 @@ var Names = []string{
|
|||||||
"ZombieHead",
|
"ZombieHead",
|
||||||
"UnravellerHead",
|
"UnravellerHead",
|
||||||
"GargoyleHead",
|
"GargoyleHead",
|
||||||
"DemonHead",
|
"DemonHeadShield",
|
||||||
"Circlet",
|
"Circlet",
|
||||||
"Coronet",
|
"Coronet",
|
||||||
"Tiara",
|
"Tiara",
|
||||||
@@ -476,7 +476,7 @@ var Names = []string{
|
|||||||
"GiantConch",
|
"GiantConch",
|
||||||
"SpiredHelm",
|
"SpiredHelm",
|
||||||
"Corona",
|
"Corona",
|
||||||
"Demonhead",
|
"DemonHead",
|
||||||
"DuskShroud",
|
"DuskShroud",
|
||||||
"Wyrmhide",
|
"Wyrmhide",
|
||||||
"ScarabHusk",
|
"ScarabHusk",
|
||||||
@@ -517,7 +517,7 @@ var Names = []string{
|
|||||||
"TrollNest",
|
"TrollNest",
|
||||||
"BladeBarrier",
|
"BladeBarrier",
|
||||||
"AlphaHelm",
|
"AlphaHelm",
|
||||||
"GriffonHeadress",
|
"GriffonHeaddress",
|
||||||
"HuntersGuise",
|
"HuntersGuise",
|
||||||
"SacredFeathers",
|
"SacredFeathers",
|
||||||
"TotemicMask",
|
"TotemicMask",
|
||||||
|
|||||||
Reference in New Issue
Block a user