Add Location struct and fixed possible panic

This commit is contained in:
Héctor Giménez
2024-05-19 20:40:20 +09:00
parent 2a5f31885e
commit e4b4f8e1b5
3 changed files with 33 additions and 22 deletions

View File

@@ -1,19 +1,22 @@
package item
type Location string
type LocationType string
type Location struct {
LocationType
Page int
}
const (
LocationEquipped Location = "equipped"
LocationStash Location = "stash"
LocationSharedStash1 Location = "shared_stash_1"
LocationSharedStash2 Location = "shared_stash_2"
LocationSharedStash3 Location = "shared_stash_3"
LocationBelt Location = "belt"
LocationInventory Location = "inventory"
LocationCube Location = "cube"
LocationVendor Location = "vendor"
LocationGround Location = "ground"
LocationSocket Location = "socket"
LocationUnknown Location = "unknown"
LocationCursor Location = "cursor"
LocationEquipped LocationType = "equipped"
LocationStash LocationType = "stash"
LocationSharedStash LocationType = "shared_stash"
LocationBelt LocationType = "belt"
LocationInventory LocationType = "inventory"
LocationCube LocationType = "cube"
LocationVendor LocationType = "vendor"
LocationGround LocationType = "ground"
LocationSocket LocationType = "socket"
LocationUnknown LocationType = "unknown"
LocationCursor LocationType = "cursor"
)

View File

@@ -33,12 +33,12 @@ func (i Inventory) Find(name item.Name, locations ...item.Location) (Item, bool)
return Item{}, false
}
func (i Inventory) ByLocation(locations ...item.Location) []Item {
func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
var items []Item
for _, it := range i.AllItems {
for _, l := range locations {
if it.Location == l {
if it.Location.LocationType == l {
items = append(items, it)
}
}
@@ -56,7 +56,6 @@ type Item struct {
Quality item.Quality
Position Position
Location item.Location
Page int // Used for shared stash
Ethereal bool
IsHovered bool
BaseStats stat.Stats