Add biome revisions readable content and visible projectile outcomes
This commit is contained in:
@@ -53,7 +53,7 @@ func (d *DB) PreviewCatalog(ctx context.Context, change CatalogChange) (CatalogP
|
||||
if resolved.Resource != nil {
|
||||
resolved.Resource.ID = ""
|
||||
}
|
||||
if resolved.Biome != nil {
|
||||
if resolved.Biome != nil && change.Op != "update-biome" {
|
||||
resolved.Biome.ID = ""
|
||||
}
|
||||
if resolved.Consumable != nil {
|
||||
@@ -153,16 +153,44 @@ func buildCatalog(c content.Catalog, change CatalogChange) (content.Catalog, str
|
||||
v.ID = "resource_" + game.ID()
|
||||
}
|
||||
resolved.Resource = &v
|
||||
for i, b := range c.Gathering.Biomes {
|
||||
if slices.Contains(v.Biomes, b.ID) {
|
||||
if b.Resources == nil {
|
||||
b.Resources = []string{}
|
||||
for _, r := range c.Gathering.Resources {
|
||||
if slices.Contains(r.Biomes, b.ID) {
|
||||
b.Resources = append(b.Resources, r.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
b.Resources = append(slices.Clone(b.Resources), v.ID)
|
||||
reviseBiome(c.Gathering, i, b)
|
||||
}
|
||||
}
|
||||
c.Gathering.Resources = append(slices.Clone(c.Gathering.Resources), v)
|
||||
target = v.ID
|
||||
case "create-biome":
|
||||
v := *change.Biome
|
||||
v.Revision = 1
|
||||
if v.ID == "" {
|
||||
v.ID = "biome_" + game.ID()
|
||||
}
|
||||
resolved.Biome = &v
|
||||
c.Gathering.Biomes = append(slices.Clone(c.Gathering.Biomes), v)
|
||||
target = v.ID
|
||||
case "update-biome":
|
||||
i := slices.IndexFunc(c.Gathering.Biomes, func(b content.BiomeDefinition) bool { return b.ID == change.TargetID })
|
||||
if i < 0 {
|
||||
return invalid(fmt.Errorf("biome not found"))
|
||||
}
|
||||
v := *change.Biome
|
||||
if v.Resources == nil {
|
||||
return invalid(fmt.Errorf("select biome resources, or an empty list"))
|
||||
}
|
||||
reviseBiome(c.Gathering, i, v)
|
||||
v = c.Gathering.Biomes[i]
|
||||
resolved.Biome = &v
|
||||
target = v.ID
|
||||
case "create-consumable":
|
||||
v := *change.Consumable
|
||||
if v.ID == "" {
|
||||
@@ -247,3 +275,20 @@ func buildCatalog(c content.Catalog, change CatalogChange) (content.Catalog, str
|
||||
}
|
||||
return c, target, resolved, nil
|
||||
}
|
||||
|
||||
func reviseBiome(g *content.GatheringContent, index int, next content.BiomeDefinition) {
|
||||
previous := g.Biomes[index]
|
||||
previous.Revision = max(1, previous.Revision)
|
||||
if previous.Resources == nil {
|
||||
previous.Resources = []string{}
|
||||
for _, r := range g.Resources {
|
||||
if slices.Contains(r.Biomes, previous.ID) {
|
||||
previous.Resources = append(previous.Resources, r.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
g.BiomeHistory = append(slices.Clone(g.BiomeHistory), previous)
|
||||
next.ID, next.Revision = previous.ID, previous.Revision+1
|
||||
g.Biomes = slices.Clone(g.Biomes)
|
||||
g.Biomes[index] = next
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user