53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package game
|
|
|
|
import (
|
|
"aeternalis/server/content"
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestBiomeResourceRevisionPreservesExploredChunks(t *testing.T) {
|
|
w, _ := fixture(t)
|
|
g := w.Balance.Gathering
|
|
g.Biomes = []content.BiomeDefinition{{ID: "valley", Name: "Valley", Color: "#445566", Weight: 1, Revision: 1, Resources: []string{"tree"}}}
|
|
before := w.chunk(2, 2)
|
|
if len(before.Resources) == 0 {
|
|
t.Fatal("existing tree could not be reused in a new biome")
|
|
}
|
|
for _, r := range before.Resources {
|
|
if stringValue(r.ResourceID) != "tree" {
|
|
t.Fatal("unselected resource generated")
|
|
}
|
|
}
|
|
g.Biomes[0].Revision = 2
|
|
g.Biomes[0].Resources = []string{}
|
|
delete(w.chunks, before.Key)
|
|
after := w.chunk(2, 2)
|
|
if !reflect.DeepEqual(before, after) {
|
|
t.Fatal("biome revision rewrote an explored chunk")
|
|
}
|
|
if len(w.chunk(3, 3).Resources) != 0 {
|
|
t.Fatal("new chunk ignored empty resource selection")
|
|
}
|
|
// Saved geometry/resource identity survives restart independently of the active revision.
|
|
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)
|
|
}
|
|
// Restore validates all resource biome references; use the normal default list,
|
|
// while keeping the explored layout under test.
|
|
b, _ := content.Load()
|
|
restored.Balance.Gathering = b.Gathering
|
|
if err = restored.Restore(w.now); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(before, restored.chunk(2, 2)) {
|
|
t.Fatal("restart rewrote explored layout")
|
|
}
|
|
}
|