From 5f37dc9b6f6b79da04da70ae0c33ec8d02998587 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Wed, 1 Jul 2026 02:21:42 -0400 Subject: feat: qol improvements to items crud in admin gui --- internal/game/production_index.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'internal/game/production_index.go') diff --git a/internal/game/production_index.go b/internal/game/production_index.go index 648ccc8..77fc08a 100644 --- a/internal/game/production_index.go +++ b/internal/game/production_index.go @@ -9,6 +9,7 @@ import ( type CraftIndex struct { mu sync.RWMutex byType map[string][]*item.ItemDef + bySubtype map[string][]*item.ItemDef byInput map[string][]*item.ItemDef byStation map[string][]*item.ItemDef } @@ -16,6 +17,7 @@ type CraftIndex struct { func NewCraftIndex() *CraftIndex { return &CraftIndex{ byType: make(map[string][]*item.ItemDef), + bySubtype: make(map[string][]*item.ItemDef), byInput: make(map[string][]*item.ItemDef), byStation: make(map[string][]*item.ItemDef), } @@ -26,6 +28,7 @@ func (idx *CraftIndex) Build(items []*item.ItemDef) { defer idx.mu.Unlock() idx.byType = make(map[string][]*item.ItemDef) + idx.bySubtype = make(map[string][]*item.ItemDef) idx.byInput = make(map[string][]*item.ItemDef) idx.byStation = make(map[string][]*item.ItemDef) @@ -41,7 +44,11 @@ func (idx *CraftIndex) Build(items []*item.ItemDef) { } idx.byType[t] = appendUnique(idx.byType[t], def) - for _, e := range craft.Consume { + if craft.Subtype != "" { + idx.bySubtype[craft.Subtype] = appendUnique(idx.bySubtype[craft.Subtype], def) + } + + for _, e := range craft.Ingredients { for _, id := range e.Items { idx.byInput[id] = appendUnique(idx.byInput[id], def) } @@ -72,6 +79,15 @@ func (idx *CraftIndex) ByType(craftType string) []*item.ItemDef { return out } +func (idx *CraftIndex) BySubtype(subtype string) []*item.ItemDef { + idx.mu.RLock() + defer idx.mu.RUnlock() + items := idx.bySubtype[subtype] + out := make([]*item.ItemDef, len(items)) + copy(out, items) + return out +} + func (idx *CraftIndex) ByStation(stationDefID string) []*item.ItemDef { idx.mu.RLock() defer idx.mu.RUnlock() @@ -147,7 +163,7 @@ func craftEntryFor(def *item.ItemDef, itemID string) int { } func craftEntry(craft item.CraftDef, itemID string) int { - for ei, e := range craft.Consume { + for ei, e := range craft.Ingredients { for _, id := range e.Items { if id == itemID { return ei @@ -161,7 +177,7 @@ func craftMatchesEntry(c *item.CraftDef, itemID string) bool { if c == nil { return false } - for _, e := range c.Consume { + for _, e := range c.Ingredients { for _, id := range e.Items { if id == itemID { return true @@ -175,7 +191,7 @@ func craftHasAllItems(c *item.CraftDef, hasItem func(string) bool) bool { if c == nil { return false } - for _, e := range c.Consume { + for _, e := range c.Ingredients { found := false for _, id := range e.Items { if hasItem(id) { @@ -194,7 +210,7 @@ func craftHasAllItemsQty(c *item.CraftDef, countItem func(string) int) bool { if c == nil { return false } - for _, e := range c.Consume { + for _, e := range c.Ingredients { found := false for _, id := range e.Items { qty := e.Quantity @@ -213,11 +229,11 @@ func craftHasAllItemsQty(c *item.CraftDef, countItem func(string) int) bool { return true } -func craftConsumeAll(c *item.CraftDef, hasItem func(string) bool, removeItem func(string, int) bool) bool { +func consumeIngredients(c *item.CraftDef, hasItem func(string) bool, removeItem func(string, int) bool) bool { if c == nil { return false } - for _, e := range c.Consume { + for _, e := range c.Ingredients { found := false for _, id := range e.Items { if hasItem(id) { -- cgit v1.2.3