diff options
Diffstat (limited to 'internal/object')
| -rw-r--r-- | internal/object/item.go | 24 | ||||
| -rw-r--r-- | internal/object/item_store.go | 22 |
2 files changed, 31 insertions, 15 deletions
diff --git a/internal/object/item.go b/internal/object/item.go index ecdb1e9..7b2a107 100644 --- a/internal/object/item.go +++ b/internal/object/item.go @@ -34,7 +34,6 @@ type ItemDef struct { ID string `yaml:"id"` Name string `yaml:"name"` Color string `yaml:"color"` - Aliases []string `yaml:"aliases"` Description string `yaml:"description"` Value int `yaml:"value"` Stackable bool `yaml:"stackable"` @@ -53,6 +52,14 @@ type ItemDef struct { SearchMiscTable string `yaml:"search_misc_table"` SearchTicks float64 `yaml:"search_ticks"` SearchMessage string `yaml:"search_message"` + HealValue int `yaml:"heal_value"` + EatMessage string `yaml:"eat_message"` + MadeFrom []MadeFromEntry `yaml:"made_from,omitempty"` +} + +type MadeFromEntry struct { + Items []string `yaml:"items"` + Qty int `yaml:"qty"` } type ItemStats struct { @@ -71,18 +78,5 @@ func (d *ItemDef) MatchesName(input string) bool { if strings.ToLower(d.Name) == lower { return true } - for _, alias := range d.Aliases { - if strings.ToLower(alias) == lower { - return true - } - } - if world.WordPrefixMatch(lower, d.Name) { - return true - } - for _, alias := range d.Aliases { - if world.WordPrefixMatch(lower, alias) { - return true - } - } - return false + return world.WordPrefixMatch(lower, d.Name) } diff --git a/internal/object/item_store.go b/internal/object/item_store.go index 6d62143..9e932ba 100644 --- a/internal/object/item_store.go +++ b/internal/object/item_store.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "gopkg.in/yaml.v3" ) @@ -36,3 +37,24 @@ func (s *ItemStore) Load(id string) (*ItemDef, error) { s.cache[id] = &def return &def, nil } + +func (s *ItemStore) LoadAll() ([]*ItemDef, error) { + dir := filepath.Join(s.dataDir, "items") + entries, err := os.ReadDir(dir) + if err != nil { + return nil, err + } + var defs []*ItemDef + for _, e := range entries { + if e.IsDir() || filepath.Ext(e.Name()) != ".yaml" { + continue + } + id := strings.TrimSuffix(e.Name(), ".yaml") + def, err := s.Load(id) + if err != nil { + continue + } + defs = append(defs, def) + } + return defs, nil +} |
