Files
aego/app/docsview/material_test.go
sanspie a46347e2c6
ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 12m19s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / checks (push) Failing after 23m57s
ci / release (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: failure
GitHub / darwin arm64 native GitHub-hosted native CI: failure
GitHub / darwin amd64 native GitHub-hosted native CI: failure
GitHub / linux amd64 native GitHub-hosted native CI: success
editor: add art studio and stage 12.5 workflows
2026-11-08 18:47:57 +03:00

95 lines
2.3 KiB
Go

//go:build aego_editor
package docsview
import (
"encoding/json"
"math"
"testing"
playmods "aego/app/assembly/playground"
"aego/app/playground"
"aego/engine/docs"
"aego/modules/render2d"
)
func TestMaterialTryCompilesItsQualifiedScriptAndAnimatesFlash(t *testing.T) {
p, err := playground.New()
if err != nil {
t.Fatal(err)
}
entries := p.TryScenes()
for _, id := range []string{"render2d/materials"} {
t.Run(id, func(t *testing.T) {
var entry docs.Entry
for _, e := range entries {
if e.ID == id {
entry = e
}
}
if entry.Try == "" || entry.TryScript == "" {
t.Fatal("material try scene or adjacent script missing")
}
code, err := p.TryCode(entry.TryScript)
if err != nil {
t.Fatal(err)
}
mods, err := playmods.DecodeTry(code)
if err != nil {
t.Fatal(err)
}
compiled := false
for _, mod := range mods {
for _, script := range mod.Scripts {
compiled = compiled || script.FullName == "game.demo.MaterialPulse"
}
}
if !compiled {
t.Fatal("TryCode did not prepare the qualified material script")
}
a := newHeadless(t)
request, err := json.Marshal(map[string]any{"scene": entry.Try, "select": entry.TrySelect, "code": code, "prefabs": entry.TryPrefabs})
if err != nil {
t.Fatal(err)
}
if reply := a.Call("load", request); reply.Error != "" {
t.Fatal(reply.Error)
}
if err := a.Step(2); err != nil {
t.Fatal(err)
}
sc := a.session.Controller().Scene()
if sc == nil {
t.Fatal("try did not start a play scene")
}
node := sc.Find(sc.Root(), "Flash instance")
if node.IsZero() {
t.Fatal("animated material node missing")
}
read := func() float64 {
t.Helper()
value, err := render2d.GetMaterialParameter(sc, node, "Flash")
if err != nil {
t.Fatal(err)
}
return value.F
}
first := read()
low, high := first, first
for range 12 {
if err := a.Step(15); err != nil {
t.Fatal(err)
}
value := read()
low, high = math.Min(low, value), math.Max(high, value)
}
if low < 0 || high > 1 || high-low < .8 {
t.Fatalf("Try material parameter did not animate through its range: first=%g range=[%g,%g]", first, low, high)
}
if errors := errorsOf(a); len(errors) != 0 {
t.Fatalf("try emitted script/runtime errors: %v", errors)
}
})
}
}