Add terrain biomes jumping and extensible gathering professions

This commit is contained in:
dingo
2026-09-08 21:54:23 -04:00
parent 141cb9e6b2
commit df7b245ca7
34 changed files with 1895 additions and 184 deletions
+22 -2
View File
@@ -17,6 +17,11 @@ var ErrCatalogInvalid = errors.New("invalid catalog change")
var catalogRequestID = regexp.MustCompile(`^[a-f0-9-]{32,36}$`)
type CatalogChange struct {
GatheringSkill *content.GatheringSkill `json:"gatheringSkill,omitempty"`
Resource *content.ResourceDefinition `json:"resource,omitempty"`
Biome *content.BiomeDefinition `json:"biome,omitempty"`
Consumable *content.GatheringConsumable `json:"consumable,omitempty"`
ID string `json:"id"`
ExpectedVersion int64 `json:"expectedVersion"`
Op string `json:"op"`
@@ -37,7 +42,7 @@ type CatalogResult struct {
// Explicit definition IDs are reserved for trusted seed/import code. Browser
// publications omit them; the server assigns an ID after resolving request replay.
func (c CatalogChange) HasDefinitionID() bool {
return (c.Title != nil && c.Title.ID != "") || (c.Item != nil && c.Item.ID != "") || (c.RequirementSet != nil && c.RequirementSet.ID != "") || (c.EffectSet != nil && c.EffectSet.ID != "")
return (c.GatheringSkill != nil && c.GatheringSkill.ID != "") || (c.Resource != nil && c.Resource.ID != "") || (c.Biome != nil && c.Biome.ID != "") || (c.Consumable != nil && c.Consumable.ID != "") || (c.Title != nil && c.Title.ID != "") || (c.Item != nil && c.Item.ID != "") || (c.RequirementSet != nil && c.RequirementSet.ID != "") || (c.EffectSet != nil && c.EffectSet.ID != "")
}
type CatalogAudit struct {
@@ -94,6 +99,13 @@ func decodeCatalog(version int64, raw string) (content.Catalog, error) {
if catalog.Version != version {
return catalog, errors.New("catalog version mismatch")
}
if catalog.Gathering == nil {
b, err := content.Load()
if err != nil {
return catalog, err
}
catalog.Gathering = b.Gathering
}
return catalog, catalog.Validate()
}
func (d *DB) Catalog(ctx context.Context) (content.Catalog, error) {
@@ -123,12 +135,20 @@ func (c CatalogChange) validate() error {
}
valid := false
count := 0
for _, present := range []bool{c.Title != nil, c.Item != nil, c.Stats != nil, c.RequirementSet != nil, c.EffectSet != nil} {
for _, present := range []bool{c.GatheringSkill != nil, c.Resource != nil, c.Biome != nil, c.Consumable != nil, c.Title != nil, c.Item != nil, c.Stats != nil, c.RequirementSet != nil, c.EffectSet != nil} {
if present {
count++
}
}
switch c.Op {
case "create-gathering-skill":
valid = c.GatheringSkill != nil
case "create-resource":
valid = c.Resource != nil
case "create-biome":
valid = c.Biome != nil
case "create-consumable":
valid = c.Consumable != nil
case "create-title":
valid = c.Title != nil && c.Item == nil && c.Stats == nil
case "create-item":
+53
View File
@@ -35,6 +35,18 @@ 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.GatheringSkill != nil {
resolved.GatheringSkill.ID = ""
}
if resolved.Resource != nil {
resolved.Resource.ID = ""
}
if resolved.Biome != nil {
resolved.Biome.ID = ""
}
if resolved.Consumable != nil {
resolved.Consumable.ID = ""
}
if resolved.Title != nil {
resolved.Title.ID = ""
}
@@ -64,7 +76,48 @@ func buildCatalog(c content.Catalog, change CatalogChange) (content.Catalog, str
resolved.RequirementSetIDs = nil
resolved.EffectSetIDs = nil
target := "stats"
if c.Gathering == nil {
b, e := content.Load()
if e != nil {
return invalid(e)
}
c.Gathering = b.Gathering
}
gathering := *c.Gathering
c.Gathering = &gathering
switch change.Op {
case "create-gathering-skill":
v := *change.GatheringSkill
if v.ID == "" {
v.ID = "skill_" + game.ID()
}
resolved.GatheringSkill = &v
c.Gathering.Skills = append(slices.Clone(c.Gathering.Skills), v)
target = v.ID
case "create-resource":
v := *change.Resource
if v.ID == "" {
v.ID = "resource_" + game.ID()
}
resolved.Resource = &v
c.Gathering.Resources = append(slices.Clone(c.Gathering.Resources), v)
target = v.ID
case "create-biome":
v := *change.Biome
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 "create-consumable":
v := *change.Consumable
if v.ID == "" {
v.ID = "consumable_" + game.ID()
}
resolved.Consumable = &v
c.Gathering.Consumables = append(slices.Clone(c.Gathering.Consumables), v)
target = v.ID
case "create-title":
title := *change.Title
if title.ID == "" {
@@ -0,0 +1,54 @@
package store
import (
"aeternalis/server/content"
"aeternalis/server/internal/game"
"context"
"errors"
"path/filepath"
"testing"
)
func TestReusableGatheringCatalogPublication(t *testing.T) {
ctx := context.Background()
db, err := Open(ctx, "file:"+filepath.ToSlash(filepath.Join(t.TempDir(), "gathering.db")))
if err != nil {
t.Fatal(err)
}
defer db.Close()
c, _ := db.Catalog(ctx)
publish := func(change CatalogChange) string {
t.Helper()
change.ID = game.ID()
change.ExpectedVersion = c.Version
change.Reason = "Gathering content test"
if _, err := db.PreviewCatalog(ctx, change); err != nil {
t.Fatal(err)
}
result, err := db.PublishCatalog(ctx, "admin", change)
if err != nil {
t.Fatal(err)
}
replay, err := db.PublishCatalog(ctx, "admin", change)
if err != nil || replay != result {
t.Fatal("publication replay changed identity", err)
}
c, err = db.Catalog(ctx)
if err != nil {
t.Fatal(err)
}
return result.ID
}
skill := publish(CatalogChange{Op: "create-gathering-skill", GatheringSkill: &content.GatheringSkill{Name: "Forager", BaseXP: 20, XPPerLevel: 10, MaxLevel: 1000}})
biome := publish(CatalogChange{Op: "create-biome", Biome: &content.BiomeDefinition{Name: "Wetlands", Color: "#445566", Weight: 1}})
publish(CatalogChange{Op: "create-resource", Resource: &content.ResourceDefinition{Name: "Reeds", SkillID: skill, Model: "herb", Output: "self", RequiredLevel: 2, Amount: 2, XP: 5, Seconds: 1, RespawnSeconds: 30, Density: 4, Biomes: []string{biome}}})
publish(CatalogChange{Op: "create-consumable", Consumable: &content.GatheringConsumable{Name: "Forager tonic", Seconds: 60, Modifiers: []content.StatModifier{{Stat: "gatheringLevel", Skill: skill, Flat: 5}}}})
bad := CatalogChange{ID: game.ID(), ExpectedVersion: c.Version, Reason: "Invalid skill scope", Op: "create-effect-set", EffectSet: &content.EffectSet{Name: "Bad scope", Modifiers: []content.StatModifier{{Stat: "gatheringXP", Skill: "missing", Percent: 50}}}}
if _, err := db.PublishCatalog(ctx, "admin", bad); !errors.Is(err, ErrCatalogInvalid) {
t.Fatal("unknown skill reference accepted", err)
}
after, _ := db.Catalog(ctx)
if after.Version != c.Version {
t.Fatal("invalid publication mutated version")
}
}