aboutsummaryrefslogtreecommitdiff
path: root/internal/game/production_index.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-07-01 02:21:42 -0400
committerhistoria <[not public]>2026-07-01 02:21:42 -0400
commit5f37dc9b6f6b79da04da70ae0c33ec8d02998587 (patch)
treef7c309e36267a4c456fcf5bca800e614507a80af /internal/game/production_index.go
parentfee376102192dc6f24297a7b11324636ace3a07d (diff)
downloadthehouseoficarus-5f37dc9b6f6b79da04da70ae0c33ec8d02998587.tar.gz
feat: qol improvements to items crud in admin gui
Diffstat (limited to 'internal/game/production_index.go')
-rw-r--r--internal/game/production_index.go30
1 files changed, 23 insertions, 7 deletions
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) {