diff options
| author | historia <[not public]> | 2026-06-11 04:46:27 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-11 08:58:37 +0000 |
| commit | 1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (patch) | |
| tree | 62264f24420bf4cfaa734942c65cc8dd45ba3d3b /internal/object | |
| parent | 06c02a697e5daf8832a462de5970dd4c0e13a02c (diff) | |
| download | thehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz | |
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/object')
| -rw-r--r-- | internal/object/item.go | 39 |
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 +} |
