package content import ( p "aeternalis/server/internal/protocol" "fmt" "regexp" "slices" ) // Appearance is a bounded, versioned presentation recipe. It never changes combat // radius, collision, movement speed, or any character/creature stats. type Appearance = p.Appearance type VisualPreset struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Appearance Appearance `json:"appearance"` } var appearanceColor = regexp.MustCompile(`^#[0-9a-fA-F]{6}$`) func ValidateAppearance(a *Appearance, families ...string) error { if a == nil { return nil } // Existing worlds retain their original models. if !slices.Contains(families, a.Family) || (a.Version != 1 && a.Version != 2) || a.Variant < 0 || a.Variant > 3 || a.Seed < 1 || a.Seed > 65535 || !finiteRange(a.Height, .75, 1.25) || !finiteRange(a.Width, .75, 1.25) || !finiteRange(a.Detail, 0, 1) || !appearanceColor.MatchString(a.Primary) || !appearanceColor.MatchString(a.Secondary) || !appearanceColor.MatchString(a.Accent) { return fmt.Errorf("invalid appearance: choose a supported form, bounded proportions, and six-digit colors") } if a.Version == 1 { if a.Body != nil { return fmt.Errorf("legacy appearance cannot include anatomy") } return nil } b := a.Body if a.Family != "human" || b == nil || !finiteRange(a.Height, .9, 1.1) || a.Width != 1 || !appearanceColor.MatchString(b.EyeColor) || !slices.Contains([]string{"none", "thin", "bushy"}, b.Eyebrows) || !slices.Contains([]string{"neutral", "smile", "stern"}, b.MouthStyle) || !slices.Contains([]string{"male", "female"}, b.Chest) { return fmt.Errorf("invalid humanoid anatomy") } for _, v := range []float64{b.HeadLength, b.HeadWidth, b.HeadDepth, b.ChestWidth, b.HipsWidth, b.FootSize} { if !finiteRange(v, .85, 1.15) { return fmt.Errorf("body proportion outside supported range") } } for _, v := range []float64{b.EyeSpacing, b.ArmWidth, b.LegWidth} { if !finiteRange(v, .8, 1.2) { return fmt.Errorf("body width outside supported range") } } if !finiteRange(b.ArmLength, .9, 1.1) || !finiteRange(b.LegLength, .9, 1.1) || !finiteRange(b.NoseScale, .75, 1.25) || !finiteRange(b.EyeHeight, -.035, .035) || !finiteRange(b.NoseHeight, -.035, .035) || !finiteRange(b.MouthHeight, -.025, .025) { return fmt.Errorf("facial feature or limb outside supported range") } return nil } func DefaultCharacterAppearance() *Appearance { return &Appearance{Version: 2, Family: "human", Seed: 42, Height: 1, Width: 1, Detail: .5, Primary: "#c99573", Secondary: "#392b28", Accent: "#456c70", Body: &p.HumanoidBody{ HeadLength: 1, HeadWidth: 1, HeadDepth: 1, EyeSpacing: 1, EyeColor: "#547d75", Eyebrows: "thin", NoseScale: 1, MouthStyle: "neutral", Chest: "male", ChestWidth: 1, HipsWidth: 1, ArmLength: 1, ArmWidth: 1, LegLength: 1, LegWidth: 1, FootSize: 1, }} } func (c Catalog) validateVisuals() error { if len(c.Visuals) > 1024 { return fmt.Errorf("visual library is full") } seen := map[string]bool{} for _, v := range c.Visuals { if !titleID.MatchString(v.ID) || len(v.Name) < 1 || len(v.Name) > 80 || len(v.Description) > 500 || seen[v.ID] { return fmt.Errorf("invalid visual identity") } if err := ValidateAppearance(&v.Appearance, "human", "creature", "tree", "rock", "plant"); err != nil { return err } seen[v.ID] = true } return nil }