Add rounded fantasy character and admin visual creators
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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.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")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppearanceValidation(t *testing.T) {
|
||||
base := Appearance{Version: 1, Family: "human", Variant: 0, Seed: 42, Height: 1, Width: 1, Detail: .5, Primary: "#d8a582", Secondary: "#493947", Accent: "#578f8b"}
|
||||
if err := ValidateAppearance(&base, "human"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, mutate := range []func(*Appearance){
|
||||
func(a *Appearance) { a.Family = "tree" }, func(a *Appearance) { a.Version = 2 },
|
||||
func(a *Appearance) { a.Height = 100 }, func(a *Appearance) { a.Width = math.NaN() },
|
||||
func(a *Appearance) { a.Detail = math.Inf(1) }, func(a *Appearance) { a.Variant = 4 },
|
||||
func(a *Appearance) { a.Seed = 0 }, func(a *Appearance) { a.Primary = "url(bad)" },
|
||||
} {
|
||||
v := base
|
||||
mutate(&v)
|
||||
if ValidateAppearance(&v, "human") == nil {
|
||||
t.Fatal("invalid appearance accepted", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-16
@@ -51,22 +51,23 @@ type LootTable struct {
|
||||
Entries []LootEntry `json:"entries" yaml:"entries"`
|
||||
}
|
||||
type MobDefinition struct {
|
||||
ID string `json:"id" yaml:"id"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description string `json:"description" yaml:"description"`
|
||||
Model string `json:"model" yaml:"model"`
|
||||
Behavior string `json:"behavior" yaml:"behavior"`
|
||||
Level int64 `json:"level" yaml:"level"`
|
||||
HP float64 `json:"hp" yaml:"hp"`
|
||||
Damage float64 `json:"damage" yaml:"damage"`
|
||||
Defence float64 `json:"defence" yaml:"defence"`
|
||||
Speed float64 `json:"speed" yaml:"speed"`
|
||||
AggroRange float64 `json:"aggroRange" yaml:"aggroRange"`
|
||||
LeashRange float64 `json:"leashRange" yaml:"leashRange"`
|
||||
ScalePerDay float64 `json:"scalePerDay" yaml:"scalePerDay"`
|
||||
XP int64 `json:"xp" yaml:"xp"`
|
||||
AttackID string `json:"attackId" yaml:"attackId"`
|
||||
LootID string `json:"lootId" yaml:"lootId"`
|
||||
Appearance *Appearance `json:"appearance,omitempty" yaml:"appearance,omitempty"`
|
||||
ID string `json:"id" yaml:"id"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description string `json:"description" yaml:"description"`
|
||||
Model string `json:"model" yaml:"model"`
|
||||
Behavior string `json:"behavior" yaml:"behavior"`
|
||||
Level int64 `json:"level" yaml:"level"`
|
||||
HP float64 `json:"hp" yaml:"hp"`
|
||||
Damage float64 `json:"damage" yaml:"damage"`
|
||||
Defence float64 `json:"defence" yaml:"defence"`
|
||||
Speed float64 `json:"speed" yaml:"speed"`
|
||||
AggroRange float64 `json:"aggroRange" yaml:"aggroRange"`
|
||||
LeashRange float64 `json:"leashRange" yaml:"leashRange"`
|
||||
ScalePerDay float64 `json:"scalePerDay" yaml:"scalePerDay"`
|
||||
XP int64 `json:"xp" yaml:"xp"`
|
||||
AttackID string `json:"attackId" yaml:"attackId"`
|
||||
LootID string `json:"lootId" yaml:"lootId"`
|
||||
}
|
||||
type MobSpawn struct {
|
||||
ID string `json:"id" yaml:"id"`
|
||||
@@ -168,6 +169,9 @@ func (c Catalog) validateCombat() error {
|
||||
}
|
||||
}
|
||||
for _, m := range v.Mobs {
|
||||
if err := ValidateAppearance(m.Appearance, "creature", "human"); err != nil {
|
||||
return err
|
||||
}
|
||||
if !identity(m.ID, m.Name, m.Description) || !slices.Contains([]string{"sentinel", "boss"}, m.Model) || !slices.Contains([]string{"aggressive", "guard", "passive"}, m.Behavior) || m.Level < 1 || m.Level > 10000 || !finiteRange(m.HP, 1, 1000000) || !finiteRange(m.Damage, 0, 100000) || !finiteRange(m.Defence, 0, 100000) || !finiteRange(m.Speed, .1, 30) || !finiteRange(m.AggroRange, 1, 128) || !finiteRange(m.LeashRange, m.AggroRange, 512) || !finiteRange(m.ScalePerDay, 0, 10) || m.XP < 0 || m.XP > 1000000000 || !attacks[m.AttackID] || (m.LootID != "" && !loot[m.LootID]) {
|
||||
return fmt.Errorf("invalid mob %q or missing attack/loot reference", m.ID)
|
||||
}
|
||||
|
||||
+17
-13
@@ -16,19 +16,20 @@ type GatheringSkill struct {
|
||||
MaxLevel int64 `json:"maxLevel" yaml:"maxLevel"`
|
||||
}
|
||||
type ResourceDefinition struct {
|
||||
ID string `json:"id" yaml:"id"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description string `json:"description" yaml:"description"`
|
||||
SkillID string `json:"skillId" yaml:"skillId"`
|
||||
Model string `json:"model" yaml:"model"`
|
||||
Output string `json:"output" yaml:"output"`
|
||||
RequiredLevel int64 `json:"requiredLevel" yaml:"requiredLevel"`
|
||||
Amount int64 `json:"amount" yaml:"amount"`
|
||||
XP int64 `json:"xp" yaml:"xp"`
|
||||
Seconds float64 `json:"seconds" yaml:"seconds"`
|
||||
RespawnSeconds float64 `json:"respawnSeconds" yaml:"respawnSeconds"`
|
||||
Density int64 `json:"density" yaml:"density"`
|
||||
Biomes []string `json:"biomes" yaml:"biomes"`
|
||||
Appearance *Appearance `json:"appearance,omitempty" yaml:"appearance,omitempty"`
|
||||
ID string `json:"id" yaml:"id"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Description string `json:"description" yaml:"description"`
|
||||
SkillID string `json:"skillId" yaml:"skillId"`
|
||||
Model string `json:"model" yaml:"model"`
|
||||
Output string `json:"output" yaml:"output"`
|
||||
RequiredLevel int64 `json:"requiredLevel" yaml:"requiredLevel"`
|
||||
Amount int64 `json:"amount" yaml:"amount"`
|
||||
XP int64 `json:"xp" yaml:"xp"`
|
||||
Seconds float64 `json:"seconds" yaml:"seconds"`
|
||||
RespawnSeconds float64 `json:"respawnSeconds" yaml:"respawnSeconds"`
|
||||
Density int64 `json:"density" yaml:"density"`
|
||||
Biomes []string `json:"biomes" yaml:"biomes"`
|
||||
}
|
||||
type BiomeDefinition struct {
|
||||
Revision int64 `json:"revision,omitempty" yaml:"revision"`
|
||||
@@ -121,6 +122,9 @@ func (g GatheringContent) Validate() error {
|
||||
biomes[b.ID] = true
|
||||
}
|
||||
for _, r := range g.Resources {
|
||||
if err := ValidateAppearance(r.Appearance, map[string]string{"tree": "tree", "ore": "rock", "herb": "plant"}[r.Model]); err != nil {
|
||||
return err
|
||||
}
|
||||
if !identity(r.ID, r.Name, r.Description) || !skills[r.SkillID] || !slices.Contains([]string{"tree", "ore", "herb"}, r.Model) || !slices.Contains([]string{"wood", "ore", "herb", "self"}, r.Output) || r.RequiredLevel < 1 || r.RequiredLevel > 10000 || r.Amount < 1 || r.Amount > 1000 || r.XP < 0 || r.XP > 1000000 || !finiteRange(r.Seconds, 0.1, 3600) || !finiteRange(r.RespawnSeconds, 1, 604800) || r.Density < 0 || r.Density > 32 || len(r.Biomes) < 1 || len(r.Biomes) > 32 {
|
||||
return fmt.Errorf("invalid resource %q", r.ID)
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ type ItemDefinition struct {
|
||||
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
|
||||
}
|
||||
type Catalog struct {
|
||||
Visuals []VisualPreset `json:"visuals,omitempty"`
|
||||
HousingVersion int `json:"housingVersion,omitempty"`
|
||||
Building *BuildingContent `json:"building,omitempty"`
|
||||
Powers *PowerContent `json:"powers,omitempty"`
|
||||
@@ -145,6 +146,9 @@ func (item ItemDefinition) Validate() error {
|
||||
return ValidateModifiers(item.Modifiers)
|
||||
}
|
||||
func (c Catalog) Validate() error {
|
||||
if err := c.validateVisuals(); err != nil {
|
||||
return err
|
||||
}
|
||||
if e := c.validateBuilding(); e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user