(subFS fs.ReadFileFS, path string, dst map[int]*ItemSpec)
| 66 | } |
| 67 | |
| 68 | func loadItemFileFromFS(subFS fs.ReadFileFS, path string, dst map[int]*ItemSpec) { |
| 69 | b, err := subFS.ReadFile(path) |
| 70 | if err != nil { |
| 71 | mudlog.Error("items.loadItemsFromFS", "path", path, "error", err) |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | var spec ItemSpec |
| 76 | if err := yaml.Unmarshal(b, &spec); err != nil { |
| 77 | mudlog.Error("items.loadItemsFromFS", "path", path, "error", err) |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | // Validate the Filepath() claim matches the actual path so the same |
| 82 | // rules as the disk loader apply. |
| 83 | if !strings.HasSuffix(path, spec.Filepath()) { |
| 84 | mudlog.Error("items.loadItemsFromFS", "path", path, "expected suffix", spec.Filepath(), "error", "filepath mismatch") |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | if err := spec.Validate(); err != nil { |
| 89 | mudlog.Error("items.loadItemsFromFS", "path", path, "error", err) |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | if _, exists := dst[spec.ItemId]; exists { |
| 94 | mudlog.Error("items.loadItemsFromFS", "itemId", spec.ItemId, "path", path, "error", "duplicate item id") |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | dst[spec.ItemId] = &spec |
| 99 | } |
no test coverage detected