aboutsummaryrefslogtreecommitdiff
path: root/internal/object
diff options
context:
space:
mode:
Diffstat (limited to 'internal/object')
-rw-r--r--internal/object/doc.go14
-rw-r--r--internal/object/item.go31
2 files changed, 21 insertions, 24 deletions
diff --git a/internal/object/doc.go b/internal/object/doc.go
new file mode 100644
index 0000000..89f6db9
--- /dev/null
+++ b/internal/object/doc.go
@@ -0,0 +1,14 @@
+// Package object defines item and object definitions with their YAML-backed
+// loading stores.
+//
+// ItemDef covers all game items: equipment stats, weapon types, tool
+// properties (tool_type, tool_speed for gathering/firemaking), firemaking
+// fields (burn_ticks, fire_level, fire_xp), and stackable/quality metadata.
+//
+// ObjectDef covers interactive world objects: their behavior reference,
+// hidden flag for unlisted-but-interactable objects, in-room description
+// overrides, removal items, and arbitrary props.
+//
+// ItemStore and ObjectStore load definitions from YAML files in the
+// data/items/ and data/objects/ directories, caching results in memory.
+package object
diff --git a/internal/object/item.go b/internal/object/item.go
index 009f10e..18fd034 100644
--- a/internal/object/item.go
+++ b/internal/object/item.go
@@ -1,6 +1,10 @@
package object
-import "strings"
+import (
+ "strings"
+
+ "thirdcollapse/internal/world"
+)
type EquipSlot string
@@ -67,34 +71,13 @@ func (d *ItemDef) MatchesName(input string) bool {
return true
}
}
- if wordPrefixMatch(lower, d.Name) {
+ if world.WordPrefixMatch(lower, d.Name) {
return true
}
for _, alias := range d.Aliases {
- if wordPrefixMatch(lower, alias) {
+ if world.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
-}