aboutsummaryrefslogtreecommitdiff
path: root/internal/object/item.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/object/item.go')
-rw-r--r--internal/object/item.go39
1 files changed, 35 insertions, 4 deletions
diff --git a/internal/object/item.go b/internal/object/item.go
index 170e07f..c9b2717 100644
--- a/internal/object/item.go
+++ b/internal/object/item.go
@@ -37,7 +37,6 @@ type ItemDef struct {
WeaponType WeaponType `yaml:"weapon_type"`
Stats ItemStats `yaml:"stats"`
Speed int `yaml:"speed"`
- Toolbelt bool `yaml:"toolbelt"`
ToolType string `yaml:"tool_type"`
ToolSpeed int `yaml:"tool_speed"`
}
@@ -51,14 +50,46 @@ type ItemStats struct {
}
func (d *ItemDef) MatchesName(input string) bool {
- lower := strings.ToLower(input)
+ lower := strings.ToLower(strings.TrimSpace(input))
+ if lower == "" {
+ return false
+ }
if strings.ToLower(d.Name) == lower {
return true
}
- for _, word := range strings.Fields(d.Name) {
- if strings.HasPrefix(strings.ToLower(word), lower) {
+ for _, alias := range d.Aliases {
+ if strings.ToLower(alias) == lower {
+ return true
+ }
+ }
+ if wordPrefixMatch(lower, d.Name) {
+ return true
+ }
+ for _, alias := range d.Aliases {
+ if wordPrefixMatch(lower, alias) {
return true
}
}
return false
}
+
+func wordPrefixMatch(input, name string) bool {
+ inputWords := strings.Fields(input)
+ if len(inputWords) == 0 {
+ return false
+ }
+ nameWords := strings.Fields(strings.ToLower(name))
+ for _, iw := range inputWords {
+ found := false
+ for _, nw := range nameWords {
+ if strings.HasPrefix(nw, iw) || strings.HasPrefix(iw, nw) {
+ found = true
+ break
+ }
+ }
+ if !found {
+ return false
+ }
+ }
+ return true
+}