Add durable recipe discovery and profession crafting

This commit is contained in:
dingo
2026-09-09 13:28:07 -04:00
parent 940a345613
commit b65f3e8562
42 changed files with 2183 additions and 136 deletions
+57
View File
@@ -35,6 +35,15 @@ func (d *DB) PreviewCatalog(ctx context.Context, change CatalogChange) (CatalogP
}
// Preview validates a provisional identity but does not reserve or expose it.
if !change.HasDefinitionID() {
if resolved.CraftRecipe != nil && change.Op != "update-craft-recipe" {
resolved.CraftRecipe.ID = ""
}
if resolved.CraftProfession != nil {
resolved.CraftProfession.ID = ""
}
if resolved.CraftMaterial != nil {
resolved.CraftMaterial.ID = ""
}
if resolved.Attack != nil {
resolved.Attack.ID = ""
}
@@ -106,7 +115,55 @@ func buildCatalog(c content.Catalog, change CatalogChange) (content.Catalog, str
}
combat := *c.Combat
c.Combat = &combat
if c.Crafting == nil {
b, e := content.Load()
if e != nil {
return invalid(e)
}
c.RestoreCrafting(b)
}
crafting := *c.Crafting
c.Crafting = &crafting
switch change.Op {
case "create-craft-recipe", "update-craft-recipe":
v := *change.CraftRecipe
v.Revision = 1
if change.Op == "update-craft-recipe" {
i := slices.IndexFunc(c.Crafting.Recipes, func(r content.CraftRecipe) bool { return r.ID == change.TargetID })
if i < 0 {
return invalid(fmt.Errorf("recipe not found"))
}
v.ID = c.Crafting.Recipes[i].ID
v.Revision = c.Crafting.Recipes[i].Revision + 1
c.Crafting.Recipes = slices.Clone(c.Crafting.Recipes)
c.Crafting.Recipes[i] = v
} else {
if v.ID == "" {
v.ID = "recipe_" + game.ID()
}
c.Crafting.Recipes = append(slices.Clone(c.Crafting.Recipes), v)
}
resolved.CraftRecipe = &v
target = v.ID
case "create-craft-profession":
v := *change.CraftProfession
if v.ID == "" {
v.ID = "profession_" + game.ID()
}
c.Crafting.Professions = append(slices.Clone(c.Crafting.Professions), v)
resolved.CraftProfession = &v
target = v.ID
case "create-craft-material":
v := *change.CraftMaterial
if v.ID == "" {
v.ID = "material_" + game.ID()
}
c.Crafting.Materials = append(slices.Clone(c.Crafting.Materials), v)
resolved.CraftMaterial = &v
target = v.ID
case "update-craft-rules":
c.Crafting.Rules = *change.CraftRules
target = "crafting-rules"
case "create-attack":
v := *change.Attack
if v.ID == "" {