Add anatomical character customization at initial creation
This commit is contained in:
@@ -24,12 +24,41 @@ 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.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) {
|
||||
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")
|
||||
|
||||
@@ -23,3 +23,29 @@ func TestAppearanceValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHumanoidAppearanceBounds(t *testing.T) {
|
||||
base := DefaultCharacterAppearance()
|
||||
if err := ValidateAppearance(base, "human"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, mutate := range []func(*Appearance){
|
||||
func(a *Appearance) { a.Body.HeadWidth = math.NaN() },
|
||||
func(a *Appearance) { a.Body.LegLength = 1.2 },
|
||||
func(a *Appearance) { a.Body.NoseHeight = .1 },
|
||||
func(a *Appearance) { a.Body.EyeColor = "red" },
|
||||
func(a *Appearance) { a.Body.Eyebrows = "unknown" },
|
||||
func(a *Appearance) { a.Body.Chest = "unknown" },
|
||||
func(a *Appearance) { a.Body.MouthStyle = "unknown" },
|
||||
func(a *Appearance) { a.Family = "creature" },
|
||||
func(a *Appearance) { a.Width = 1.1 },
|
||||
func(a *Appearance) { a.Body = nil },
|
||||
func(a *Appearance) { a.Version = 1 },
|
||||
} {
|
||||
a := DefaultCharacterAppearance()
|
||||
mutate(a)
|
||||
if ValidateAppearance(a, "human", "creature") == nil {
|
||||
t.Fatal("invalid anatomy accepted", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user