From abd612c15799f604e671e83dc7c410ed2b44185f Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Thu, 25 Jun 2026 15:40:48 -0400 Subject: slop refactor --- internal/game/craft_index.go | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'internal/game/craft_index.go') diff --git a/internal/game/craft_index.go b/internal/game/craft_index.go index 078ec3c..648ccc8 100644 --- a/internal/game/craft_index.go +++ b/internal/game/craft_index.go @@ -3,31 +3,31 @@ package game import ( "sync" - "thehouseoficarus/internal/object" + "thehouseoficarus/internal/item" ) type CraftIndex struct { mu sync.RWMutex - byType map[string][]*object.ItemDef - byInput map[string][]*object.ItemDef - byStation map[string][]*object.ItemDef + byType map[string][]*item.ItemDef + byInput map[string][]*item.ItemDef + byStation map[string][]*item.ItemDef } func NewCraftIndex() *CraftIndex { return &CraftIndex{ - byType: make(map[string][]*object.ItemDef), - byInput: make(map[string][]*object.ItemDef), - byStation: make(map[string][]*object.ItemDef), + byType: make(map[string][]*item.ItemDef), + byInput: make(map[string][]*item.ItemDef), + byStation: make(map[string][]*item.ItemDef), } } -func (idx *CraftIndex) Build(items []*object.ItemDef) { +func (idx *CraftIndex) Build(items []*item.ItemDef) { idx.mu.Lock() defer idx.mu.Unlock() - idx.byType = make(map[string][]*object.ItemDef) - idx.byInput = make(map[string][]*object.ItemDef) - idx.byStation = make(map[string][]*object.ItemDef) + idx.byType = make(map[string][]*item.ItemDef) + idx.byInput = make(map[string][]*item.ItemDef) + idx.byStation = make(map[string][]*item.ItemDef) for _, def := range items { if len(def.Craft) == 0 { @@ -54,7 +54,7 @@ func (idx *CraftIndex) Build(items []*object.ItemDef) { } } -func appendUnique(items []*object.ItemDef, item *object.ItemDef) []*object.ItemDef { +func appendUnique(items []*item.ItemDef, item *item.ItemDef) []*item.ItemDef { for _, existing := range items { if existing == item { return items @@ -63,34 +63,34 @@ func appendUnique(items []*object.ItemDef, item *object.ItemDef) []*object.ItemD return append(items, item) } -func (idx *CraftIndex) ByType(craftType string) []*object.ItemDef { +func (idx *CraftIndex) ByType(craftType string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() items := idx.byType[craftType] - out := make([]*object.ItemDef, len(items)) + out := make([]*item.ItemDef, len(items)) copy(out, items) return out } -func (idx *CraftIndex) ByStation(stationDefID string) []*object.ItemDef { +func (idx *CraftIndex) ByStation(stationDefID string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() items := idx.byStation[stationDefID] - out := make([]*object.ItemDef, len(items)) + out := make([]*item.ItemDef, len(items)) copy(out, items) return out } -func (idx *CraftIndex) ByInput(itemID string) []*object.ItemDef { +func (idx *CraftIndex) ByInput(itemID string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() items := idx.byInput[itemID] - out := make([]*object.ItemDef, len(items)) + out := make([]*item.ItemDef, len(items)) copy(out, items) return out } -func (idx *CraftIndex) FindByTwoInputs(itemA, itemB string) []*object.ItemDef { +func (idx *CraftIndex) FindByTwoInputs(itemA, itemB string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() @@ -104,7 +104,7 @@ func (idx *CraftIndex) FindByTwoInputs(itemA, itemB string) []*object.ItemDef { candidateSetB[def.ID] = true } - var results []*object.ItemDef + var results []*item.ItemDef for _, def := range candidatesA { if !candidateSetB[def.ID] { continue @@ -121,11 +121,11 @@ func (idx *CraftIndex) FindByTwoInputs(itemA, itemB string) []*object.ItemDef { return results } -func (idx *CraftIndex) FindByStationInput(stationDefID, itemID string) []*object.ItemDef { +func (idx *CraftIndex) FindByStationInput(stationDefID, itemID string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() - var results []*object.ItemDef + var results []*item.ItemDef for _, def := range idx.byStation[stationDefID] { for _, craft := range def.Craft { if craftMatchesEntry(&craft, itemID) { @@ -137,7 +137,7 @@ func (idx *CraftIndex) FindByStationInput(stationDefID, itemID string) []*object return results } -func craftEntryFor(def *object.ItemDef, itemID string) int { +func craftEntryFor(def *item.ItemDef, itemID string) int { for _, craft := range def.Craft { if ei := craftEntry(craft, itemID); ei >= 0 { return ei @@ -146,7 +146,7 @@ func craftEntryFor(def *object.ItemDef, itemID string) int { return -1 } -func craftEntry(craft object.CraftDef, itemID string) int { +func craftEntry(craft item.CraftDef, itemID string) int { for ei, e := range craft.Consume { for _, id := range e.Items { if id == itemID { @@ -157,7 +157,7 @@ func craftEntry(craft object.CraftDef, itemID string) int { return -1 } -func craftMatchesEntry(c *object.CraftDef, itemID string) bool { +func craftMatchesEntry(c *item.CraftDef, itemID string) bool { if c == nil { return false } @@ -171,7 +171,7 @@ func craftMatchesEntry(c *object.CraftDef, itemID string) bool { return false } -func craftHasAllItems(c *object.CraftDef, hasItem func(string) bool) bool { +func craftHasAllItems(c *item.CraftDef, hasItem func(string) bool) bool { if c == nil { return false } @@ -190,7 +190,7 @@ func craftHasAllItems(c *object.CraftDef, hasItem func(string) bool) bool { return true } -func craftHasAllItemsQty(c *object.CraftDef, countItem func(string) int) bool { +func craftHasAllItemsQty(c *item.CraftDef, countItem func(string) int) bool { if c == nil { return false } @@ -213,7 +213,7 @@ func craftHasAllItemsQty(c *object.CraftDef, countItem func(string) int) bool { return true } -func craftConsumeAll(c *object.CraftDef, hasItem func(string) bool, removeItem func(string, int) bool) bool { +func craftConsumeAll(c *item.CraftDef, hasItem func(string) bool, removeItem func(string, int) bool) bool { if c == nil { return false } -- cgit v1.2.3