diff options
Diffstat (limited to 'internal/game/core_startup.go')
| -rw-r--r-- | internal/game/core_startup.go | 95 |
1 files changed, 34 insertions, 61 deletions
diff --git a/internal/game/core_startup.go b/internal/game/core_startup.go index ef33ff7..4bdb50d 100644 --- a/internal/game/core_startup.go +++ b/internal/game/core_startup.go @@ -25,7 +25,6 @@ func (g *Game) ValidateStartup() []StartupIssue { issues = append(issues, validateIDs(g.DataDir, "mobs", "mob")...) issues = append(issues, validateIDs(g.DataDir, "objects", "object")...) issues = append(issues, validateIDs(g.DataDir, "drops", "drop table")...) - issues = append(issues, validateIDs(g.DataDir, "recipes", "recipe")...) issues = append(issues, validateIDs(g.DataDir, "courses", "course")...) issues = append(issues, validateIDs(g.DataDir, "modules", "module")...) issues = append(issues, validateIDs(g.DataDir, "help", "help topic")...) @@ -34,7 +33,7 @@ func (g *Game) ValidateStartup() []StartupIssue { issues = append(issues, validateMobs(g)...) issues = append(issues, validateObjects(g)...) issues = append(issues, validateItems(g)...) - issues = append(issues, validateRecipes(g)...) + issues = append(issues, validateCraftBlocks(g)...) issues = append(issues, validateDropTables(g)...) issues = append(issues, validateCourses(g)...) issues = append(issues, validateRoomWiring(g)...) @@ -368,29 +367,6 @@ func validateItems(g *Game) []StartupIssue { }) } - for _, mf := range def.MadeFrom { - for _, item := range mf.Items { - if item != "" && !itemIDs[item] { - issues = append(issues, StartupIssue{ - Level: "ERROR", - Type: "reference", - Message: fmt.Sprintf("Item %q: made_from item %q does not exist", - id, item), - }) - } - } - for _, bp := range mf.Byproducts { - if bp != "" && !itemIDs[bp] { - issues = append(issues, StartupIssue{ - Level: "ERROR", - Type: "reference", - Message: fmt.Sprintf("Item %q: made_from byproduct %q does not exist", - id, bp), - }) - } - } - } - if def.FarmProduct != "" && !itemIDs[def.FarmProduct] { issues = append(issues, StartupIssue{ Level: "ERROR", @@ -404,64 +380,61 @@ func validateItems(g *Game) []StartupIssue { return issues } -func validateRecipes(g *Game) []StartupIssue { +func validateCraftBlocks(g *Game) []StartupIssue { var issues []StartupIssue itemIDs := g.ItemStore.IDSet() + objIDs := g.ObjectStore.IDSet() - allRecipes, err := g.RecipeStore.LoadAll() + allItems, err := g.ItemStore.LoadAll() if err != nil { issues = append(issues, StartupIssue{ Level: "ERROR", Type: "reference", - Message: fmt.Sprintf("Failed to load recipes: %v", err), + Message: fmt.Sprintf("Failed to load items: %v", err), }) return issues } - recipeIDs := make(map[string]bool) - for _, r := range allRecipes { - if r.ID != "" { - if recipeIDs[r.ID] { + for _, item := range allItems { + if len(item.Craft) == 0 { + continue + } + for ci := range item.Craft { + c := &item.Craft[ci] + + for _, e := range c.Consume { + for _, consumeItem := range e.Items { + if consumeItem != "" && !itemIDs[consumeItem] { + issues = append(issues, StartupIssue{ + Level: "ERROR", + Type: "reference", + Message: fmt.Sprintf("Item %q (craft: %s): consumes nonexistent item %q", + item.ID, c.Type, consumeItem), + }) + } + } + } + + if c.Fail != "" && !itemIDs[c.Fail] { issues = append(issues, StartupIssue{ Level: "ERROR", - Type: "duplicate", - Message: fmt.Sprintf("Recipe %q: duplicate ID field (two recipe files with same ID value)", - r.ID), + Type: "reference", + Message: fmt.Sprintf("Item %q (craft: %s): fail product %q does not exist", + item.ID, c.Type, c.Fail), }) } - recipeIDs[r.ID] = true - } - for _, e := range r.Consume { - for _, item := range e.Items { - if item != "" && !itemIDs[item] { + for _, sid := range c.Station { + if sid != "" && !objIDs[sid] { issues = append(issues, StartupIssue{ Level: "ERROR", Type: "reference", - Message: fmt.Sprintf("Recipe %q (%s): consumes nonexistent item %q", - r.ID, r.Type, item), + Message: fmt.Sprintf("Item %q (craft: %s): station object %q does not exist", + item.ID, c.Type, sid), }) } } } - - if r.Output != "" && !itemIDs[r.Output] { - issues = append(issues, StartupIssue{ - Level: "ERROR", - Type: "reference", - Message: fmt.Sprintf("Recipe %q (%s): output item %q does not exist", - r.ID, r.Type, r.Output), - }) - } - - if r.Fail != "" && !itemIDs[r.Fail] { - issues = append(issues, StartupIssue{ - Level: "ERROR", - Type: "reference", - Message: fmt.Sprintf("Recipe %q (%s): fail product %q does not exist", - r.ID, r.Type, r.Fail), - }) - } } return issues @@ -778,4 +751,4 @@ func LogStartupIssues(issues []StartupIssue) { if errors > 0 { fmt.Fprintf(os.Stderr, "*** %d startup errors detected. The server may behave unexpectedly. ***\n", errors) } -}
\ No newline at end of file +} |
