Files
aeternalis/server/internal/game/appearance_test.go
T

37 lines
1.0 KiB
Go

package game
import (
p "aeternalis/server/internal/protocol"
"encoding/json"
"testing"
)
func TestAppearanceRestartAndReplacement(t *testing.T) {
w, c := fixture(t)
a := p.Appearance{Version: 1, Family: "human", Variant: 1, Seed: 42, Height: 1, Width: 1, Detail: .5, Primary: "#d8a582", Secondary: "#493947", Accent: "#578f8b"}
c.View.Entity.Appearance = &a
raw, err := json.Marshal(w)
if err != nil {
t.Fatal(err)
}
var restored World
if err = json.Unmarshal(raw, &restored); err != nil {
t.Fatal(err)
}
if err = restored.Restore(w.now); err != nil {
t.Fatal(err)
}
life := restored.Characters[c.View.Entity.ID]
if life.View.Entity.Appearance == nil || *life.View.Entity.Appearance != a {
t.Fatal("appearance lost on restart")
}
restored.kill(life, "test replacement")
replacement, err := restored.Join(c.Account, "Replacement")
if err != nil {
t.Fatal(err)
}
if replacement.View.Entity.ID == life.View.Entity.ID || replacement.View.Entity.Appearance != nil {
t.Fatal("replacement inherited prior life's appearance")
}
}