Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6a24ba393 | ||
|
|
7dca06e4b1 | ||
|
|
6dfdb824e2 | ||
|
|
de49a53172 | ||
|
|
1030dc9a43 | ||
|
|
3d25734dfa | ||
|
|
12f628c469 | ||
|
|
1529213434 | ||
|
|
f8bb865920 | ||
|
|
f5fb32565e | ||
|
|
f1a8f538d3 | ||
|
|
963b01a011 |
@@ -37,6 +37,10 @@ jobs:
|
||||
- run: go vet ./platform/sdl
|
||||
- run: make lint
|
||||
- run: make depcheck
|
||||
- name: packaging tools
|
||||
run: sudo apt-get install -y nsis squashfs-tools
|
||||
- name: installer dry run
|
||||
run: make nsis-check
|
||||
|
||||
build:
|
||||
strategy:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Aego
|
||||
|
||||
A 2D and 3D game engine with an editor, a scripting language and a web export, written in Go.
|
||||
|
||||
- Documentation and the playground: <https://aego.akarpov.ru>
|
||||
- Installing and building from source: [engine/res/docs/install.md](engine/res/docs/install.md)
|
||||
- Contributing, check levels and rules for engine code: [docs/contributing.md](docs/contributing.md)
|
||||
- Architecture and decisions: [ARCHITECTURE.md](ARCHITECTURE.md)
|
||||
@@ -2,6 +2,7 @@ package agent
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
@@ -65,9 +66,8 @@ func sceneCommands() []*Command {
|
||||
{Name: "scene.rename", Doc: "rename a node", Write: true, Args: []Arg{argFile, argNode, {Name: "name", Type: "string", Doc: "new name", Required: true, Pos: true}}, Run: func(s *Session, a Args) (*Output, error) {
|
||||
return s.sceneTx(a, "Rename", mutate.Rename(a.Str("node"), a.Str("name")))
|
||||
}},
|
||||
{Name: "scene.add-comp", Doc: "add a component with its defaults", Write: true, Args: []Arg{argFile, argNode, {Name: "comp", Type: "string", Doc: "component name, full or a unique suffix (Body2D)", Required: true, Pos: true}}, Run: func(s *Session, a Args) (*Output, error) {
|
||||
return s.sceneTx(a, "Add Component", mutate.AddComp(a.Str("node"), a.Str("comp")))
|
||||
}},
|
||||
{Name: "scene.add-comp", Doc: "add a component with its defaults and the components it requires", Write: true, Args: []Arg{argFile, argNode, {Name: "comp", Type: "string", Doc: "component name, full or a unique suffix (Body2D)", Required: true, Pos: true},
|
||||
{Name: "no-required", Type: "boolean", Doc: "add only this component; missing requirements stay as problems"}}, Run: (*Session).sceneAddComp},
|
||||
{Name: "scene.remove-comp", Doc: "remove a component", Write: true, Args: []Arg{argFile, argNode, {Name: "comp", Type: "string", Doc: "component name", Required: true, Pos: true}}, Run: func(s *Session, a Args) (*Output, error) {
|
||||
return s.sceneTx(a, "Remove Component", mutate.RemoveComp(a.Str("node"), a.Str("comp")))
|
||||
}},
|
||||
@@ -93,6 +93,49 @@ func (s *Session) scene(a Args) (string, []byte, *mutate.Document, error) {
|
||||
return rel, src, doc, err
|
||||
}
|
||||
|
||||
// sceneAddComp adds a component and, unless no-required is set, the components it requires first, in one transaction (D144).
|
||||
func (s *Session) sceneAddComp(a Args) (*Output, error) {
|
||||
rel, src, doc, err := s.scene(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, comp := a.Str("node"), a.Str("comp")
|
||||
ops := []mutate.Op{mutate.AddComp(node, comp)}
|
||||
var notes []string
|
||||
if !a.Bool("no-required") {
|
||||
td, err := doc.Component(comp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h, err := doc.Node(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := mutate.Required(doc.Scene, td, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ops = ops[:0]
|
||||
for _, r := range req {
|
||||
ops = append(ops, mutate.AddComp(node, r.FullName))
|
||||
notes = append(notes, "added "+label(r)+" (required by "+label(td)+")")
|
||||
}
|
||||
ops = append(ops, mutate.AddComp(node, td.FullName))
|
||||
}
|
||||
out, err := s.applyDoc(a, rel, src, doc, mutate.Tx{Label: "Add Component", Ops: ops})
|
||||
if out != nil {
|
||||
out.Notes = append(notes, out.Notes...)
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
func label(td *schema.TypeDescriptor) string {
|
||||
if td.DisplayName != "" {
|
||||
return td.DisplayName
|
||||
}
|
||||
return td.FullName
|
||||
}
|
||||
|
||||
func (s *Session) sceneTx(a Args, label string, ops ...mutate.Op) (*Output, error) {
|
||||
rel, src, doc, err := s.scene(a)
|
||||
if err != nil {
|
||||
@@ -245,6 +288,9 @@ func (s *Session) sceneRun(a Args) (*Output, error) {
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("frames: " + strconv.Itoa(rep.Frames) + "\nhash: " + rep.Hash + "\n")
|
||||
for _, k := range slices.Sorted(maps.Keys(rep.Counters)) {
|
||||
b.WriteString(k + ": " + strconv.FormatUint(rep.Counters[k], 10) + "\n")
|
||||
}
|
||||
for _, l := range rep.Log {
|
||||
b.WriteString(l + "\n")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"aego/script/abi"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
@@ -34,6 +35,14 @@ type TypeView struct {
|
||||
Requires []string `json:"requires,omitempty"`
|
||||
Doc string `json:"doc,omitempty"`
|
||||
Fields []FieldView `json:"fields,omitempty"`
|
||||
Methods []CallView `json:"methods,omitempty"`
|
||||
Signals []CallView `json:"signals,omitempty"`
|
||||
}
|
||||
|
||||
type CallView struct {
|
||||
Name string `json:"name"`
|
||||
Sig string `json:"sig"`
|
||||
Doc string `json:"doc,omitempty"`
|
||||
}
|
||||
|
||||
func schemaCommands() []*Command {
|
||||
@@ -90,6 +99,7 @@ func (s *Session) lookupType(name string) (*schema.TypeDescriptor, error) {
|
||||
found = append(found, td)
|
||||
}
|
||||
}
|
||||
found = schema.PreferProject(found)
|
||||
switch len(found) {
|
||||
case 1:
|
||||
return found[0], nil
|
||||
@@ -162,5 +172,51 @@ func (s *Session) schemaShow(a Args) (*Output, error) {
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
if s.kit != nil {
|
||||
for _, cm := range s.kit.methods(td.FullName) {
|
||||
v.Methods = append(v.Methods, CallView{Name: cm.Name, Sig: methodSig(cm.Sig, cm.Params), Doc: summary(cm.Doc)})
|
||||
}
|
||||
}
|
||||
for _, sg := range td.Signals {
|
||||
params := make([]string, len(sg.Params))
|
||||
for i, p := range sg.Params {
|
||||
params[i] = p
|
||||
if i < len(sg.Names) && sg.Names[i] != "" {
|
||||
params[i] = sg.Names[i] + " " + p
|
||||
}
|
||||
}
|
||||
v.Signals = append(v.Signals, CallView{Name: sg.Name, Sig: "(" + strings.Join(params, ", ") + ")", Doc: summary(sg.Doc)})
|
||||
}
|
||||
for _, sec := range []struct {
|
||||
title string
|
||||
list []CallView
|
||||
}{{"methods", v.Methods}, {"signals", v.Signals}} {
|
||||
if len(sec.list) == 0 {
|
||||
continue
|
||||
}
|
||||
b.WriteString(sec.title + ":\n")
|
||||
for _, c := range sec.list {
|
||||
b.WriteString(" " + c.Name + c.Sig)
|
||||
if c.Doc != "" {
|
||||
b.WriteString(" — " + c.Doc)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
}
|
||||
return &Output{Value: v, Text: b.String()}, nil
|
||||
}
|
||||
|
||||
func methodSig(sig abi.Signature, names []string) string {
|
||||
params := make([]string, len(sig.Params))
|
||||
for i, p := range sig.Params {
|
||||
params[i] = p.String()
|
||||
if i < len(names) && names[i] != "" {
|
||||
params[i] = names[i] + " " + params[i]
|
||||
}
|
||||
}
|
||||
out := "(" + strings.Join(params, ", ") + ")"
|
||||
if sig.Result.Kind != abi.Void {
|
||||
out += " " + sig.Result.String()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"aego/scene/sceneio"
|
||||
"aego/schema"
|
||||
"aego/script/bind"
|
||||
"aego/script/bind/manifest"
|
||||
"aego/script/reload"
|
||||
"aego/script/runtime"
|
||||
"aego/script/workspace"
|
||||
@@ -46,10 +47,11 @@ type RunRequest struct {
|
||||
}
|
||||
|
||||
type RunReport struct {
|
||||
Frames int `json:"frames"`
|
||||
Hash string `json:"hash"`
|
||||
Log []string `json:"log,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Frames int `json:"frames"`
|
||||
Hash string `json:"hash"`
|
||||
Counters map[string]uint64 `json:"counters,omitempty"`
|
||||
Log []string `json:"log,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type Runner func(p *project.Project, r RunRequest) (RunReport, error)
|
||||
@@ -79,6 +81,25 @@ type Kit struct {
|
||||
ws *workspace.Workspace
|
||||
binds *bind.Registry
|
||||
opt Options
|
||||
man *manifest.Manifest
|
||||
}
|
||||
|
||||
// methods lists the script methods the bindings give a component type, built once per kit.
|
||||
func (k *Kit) methods(comp string) []manifest.CompMethod {
|
||||
if k.man == nil {
|
||||
m, err := manifest.FromRegistry(k.binds, k.Types.Schema())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
k.man = m
|
||||
}
|
||||
var out []manifest.CompMethod
|
||||
for _, cm := range k.man.CompMethods {
|
||||
if cm.Comp == comp {
|
||||
out = append(out, cm)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func NewKit(p *project.Project, opt Options) (*Kit, error) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"aego/modules/dataasset"
|
||||
"aego/modules/debug"
|
||||
"aego/modules/display"
|
||||
"aego/modules/gameplay"
|
||||
inputmod "aego/modules/input"
|
||||
"aego/modules/physics"
|
||||
"aego/modules/render2d"
|
||||
@@ -76,6 +77,10 @@ func cameraEntry() assembly.Entry {
|
||||
return assembly.Entry{ID: camera.ID, Requires: []string{scripting.ID}, New: func(assembly.Options) module.Module { return camera.New() }}
|
||||
}
|
||||
|
||||
func gameplayEntry() assembly.Entry {
|
||||
return assembly.Entry{ID: gameplay.ID, Requires: []string{physics.ID, scripting.ID}, New: func(assembly.Options) module.Module { return gameplay.New() }}
|
||||
}
|
||||
|
||||
func dataEntry() assembly.Entry {
|
||||
return assembly.Entry{ID: dataasset.ID, New: func(assembly.Options) module.Module { return dataasset.New() }}
|
||||
}
|
||||
@@ -90,5 +95,5 @@ func savegameEntry() assembly.Entry {
|
||||
|
||||
func Default() assembly.Catalog {
|
||||
return assembly.Catalog{core(), dataEntry(), inputEntry(), render2dEntry(), render3dEntry(), scriptEntry(), physicsEntry(), debugEntry(),
|
||||
displayEntry(), audioEntry(), accessibilityEntry(), settingsEntry(), tweenEntry(), cameraEntry(), spawnEntry(), savegameEntry()}
|
||||
displayEntry(), audioEntry(), accessibilityEntry(), settingsEntry(), tweenEntry(), cameraEntry(), gameplayEntry(), spawnEntry(), savegameEntry()}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ package editors
|
||||
|
||||
import (
|
||||
"aego/app/assembly"
|
||||
"aego/modules/audio"
|
||||
audioeditor "aego/modules/audio/editor"
|
||||
"aego/modules/camera"
|
||||
cameraeditor "aego/modules/camera/editor"
|
||||
"aego/modules/debug"
|
||||
debugeditor "aego/modules/debug/editor"
|
||||
"aego/modules/gameplay"
|
||||
gameplayeditor "aego/modules/gameplay/editor"
|
||||
inputmod "aego/modules/input"
|
||||
inputeditor "aego/modules/input/editor"
|
||||
"aego/modules/physics"
|
||||
@@ -23,5 +27,7 @@ func With(c assembly.Catalog) assembly.Catalog {
|
||||
With(render3d.ID, render3deditor.Hook).
|
||||
With(physics.ID, physicseditor.Hook).
|
||||
With(camera.ID, cameraeditor.Hook).
|
||||
With(gameplay.ID, gameplayeditor.Hook).
|
||||
With(audio.ID, audioeditor.Hook).
|
||||
With(debug.ID, debugeditor.Hook)
|
||||
}
|
||||
|
||||
@@ -4,13 +4,17 @@ import (
|
||||
"aego/app/assembly"
|
||||
"aego/engine/base"
|
||||
"aego/engine/module"
|
||||
"aego/modules/audio"
|
||||
"aego/modules/camera"
|
||||
"aego/modules/debug"
|
||||
"aego/modules/gameplay"
|
||||
inputmod "aego/modules/input"
|
||||
"aego/modules/physics"
|
||||
"aego/modules/render2d"
|
||||
"aego/modules/render3d"
|
||||
"aego/modules/savegame"
|
||||
"aego/modules/scripting"
|
||||
"aego/modules/spawn"
|
||||
"aego/modules/tween"
|
||||
"aego/script/stdlib"
|
||||
"aego/script/vm"
|
||||
@@ -28,7 +32,11 @@ func Catalog() assembly.Catalog {
|
||||
{ID: debug.ID, New: func(assembly.Options) module.Module { return debug.New() }},
|
||||
{ID: tween.ID, Requires: []string{scripting.ID}, New: func(assembly.Options) module.Module { return tween.New() }},
|
||||
{ID: camera.ID, Requires: []string{scripting.ID}, New: func(assembly.Options) module.Module { return camera.New() }},
|
||||
{ID: gameplay.ID, Requires: []string{physics.ID, scripting.ID}, New: func(assembly.Options) module.Module { return gameplay.New() }},
|
||||
{ID: render3d.ID, New: func(assembly.Options) module.Module { return render3d.New() }},
|
||||
{ID: spawn.ID, New: func(assembly.Options) module.Module { return spawn.New() }},
|
||||
{ID: savegame.ID, Requires: []string{scripting.ID, spawn.ID}, New: func(assembly.Options) module.Module { return savegame.New() }},
|
||||
{ID: audio.ID, New: func(assembly.Options) module.Module { return audio.New() }},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package playground
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"aego/contracts/persistence"
|
||||
"aego/engine"
|
||||
"aego/platform"
|
||||
"aego/save"
|
||||
)
|
||||
|
||||
// UseMemorySaves gives e a save store kept in memory, for runs in a browser page that must not touch the visitor's storage.
|
||||
func UseMemorySaves(e *engine.Engine) {
|
||||
e.SetService(persistence.StoreID, save.NewStoreFS("saves", &memUser{files: map[string][]byte{}}))
|
||||
}
|
||||
|
||||
type memUser struct {
|
||||
files map[string][]byte
|
||||
}
|
||||
|
||||
func (m *memUser) ReadFile(p string) ([]byte, error) {
|
||||
data, ok := m.files[path.Clean(p)]
|
||||
if !ok {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
return append([]byte(nil), data...), nil
|
||||
}
|
||||
|
||||
func (m *memUser) WriteFile(p string, data []byte) error {
|
||||
m.files[path.Clean(p)] = append([]byte(nil), data...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memUser) Remove(p string) error {
|
||||
delete(m.files, path.Clean(p))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *memUser) Stat(p string) (platform.UserEntry, error) {
|
||||
data, ok := m.files[path.Clean(p)]
|
||||
if !ok {
|
||||
return platform.UserEntry{}, fs.ErrNotExist
|
||||
}
|
||||
return platform.UserEntry{Name: path.Base(p), Size: int64(len(data)), Mod: time.Time{}}, nil
|
||||
}
|
||||
|
||||
func (m *memUser) List(dir string) ([]platform.UserEntry, error) {
|
||||
prefix := path.Clean(dir) + "/"
|
||||
var out []platform.UserEntry
|
||||
for p, data := range m.files {
|
||||
if rest, ok := strings.CutPrefix(p, prefix); ok && !strings.Contains(rest, "/") {
|
||||
out = append(out, platform.UserEntry{Name: rest, Size: int64(len(data))})
|
||||
}
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package playground
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"aego/asset"
|
||||
"aego/asset/loader"
|
||||
"aego/core/ids"
|
||||
"aego/script/bytecode"
|
||||
"aego/vfs"
|
||||
"aego/vfs/memfs"
|
||||
)
|
||||
|
||||
// EncodeTry packs the compiled script of a try scene for a docs page: base64 modules joined by commas.
|
||||
func EncodeTry(mods []*bytecode.Module) string {
|
||||
parts := make([]string, len(mods))
|
||||
for i, m := range mods {
|
||||
parts[i] = base64.StdEncoding.EncodeToString(bytecode.Encode(m))
|
||||
}
|
||||
return strings.Join(parts, ",")
|
||||
}
|
||||
|
||||
func DecodeTry(code string) ([]*bytecode.Module, error) {
|
||||
if code == "" {
|
||||
return nil, nil
|
||||
}
|
||||
var mods []*bytecode.Module
|
||||
for _, part := range strings.Split(code, ",") {
|
||||
b, err := base64.StdEncoding.DecodeString(part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, err := bytecode.Decode(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mods = append(mods, m)
|
||||
}
|
||||
return mods, nil
|
||||
}
|
||||
|
||||
// MountTry gives the loader the prefabs of a try scene, keyed by asset id; none unmounts them.
|
||||
func MountTry(l *loader.Loader, prefabs map[string]string) error {
|
||||
idx := asset.NewIndex()
|
||||
files := map[string][]byte{}
|
||||
for key, text := range prefabs {
|
||||
id, err := ids.ParseAssetID(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p := id.String() + ".aeprefab"
|
||||
files[p] = []byte(text)
|
||||
idx.Put(asset.Entry{ID: id, Kind: asset.ArtPrefab, Name: p, Source: p,
|
||||
Artifacts: []asset.Artifact{{Kind: asset.ArtPrefab, Path: "try://" + p}}})
|
||||
}
|
||||
fs, err := vfs.New(vfs.Mount{Scheme: "try", ReadOnly: true, Source: memfs.New(files)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.Mount(idx, fs)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"aego/app/proc"
|
||||
"aego/core/errs"
|
||||
"aego/core/log"
|
||||
"aego/project"
|
||||
@@ -169,6 +170,7 @@ func Build(p *project.Project, t Target, mode Mode, engineVersion string, lg *lo
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Dir = p.Root
|
||||
cmd.Env = append(os.Environ(), "GOOS="+t.OS, "GOARCH="+t.Arch)
|
||||
proc.Hide(cmd)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
os.RemoveAll(outDir)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"aego/app/proc"
|
||||
"aego/core/errs"
|
||||
"aego/core/log"
|
||||
"aego/project"
|
||||
@@ -32,12 +33,14 @@ func RunIcons(p *project.Project, engineVersion string, out io.Writer) (int, err
|
||||
defer os.Remove(bin)
|
||||
build := exec.Command("go", "build", "-tags", strings.Join(t.Tags, ","), "-o", bin, "./.aego/generated/icons")
|
||||
build.Dir = p.Root
|
||||
proc.Hide(build)
|
||||
if output, err := build.CombinedOutput(); err != nil {
|
||||
return 2, errs.New(errs.BuildFailed, "native icons helper does not compile",
|
||||
log.F("output", strings.TrimSpace(string(output))))
|
||||
}
|
||||
run := exec.Command(bin)
|
||||
run.Dir, run.Stdout, run.Stderr = p.Root, out, out
|
||||
proc.Hide(run)
|
||||
err = run.Run()
|
||||
var ee *exec.ExitError
|
||||
if errors.As(err, &ee) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"aego/app/proc"
|
||||
"aego/core/errs"
|
||||
"aego/core/log"
|
||||
"aego/project"
|
||||
@@ -52,6 +53,7 @@ func BuildManifest(p *project.Project, engineVersion string, lg *log.Logger) (st
|
||||
defer os.Remove(bin)
|
||||
build := exec.Command("go", "build", "-tags", strings.Join(t.Tags, ","), "-o", bin, "./.aego/generated/manifest")
|
||||
build.Dir = p.Root
|
||||
proc.Hide(build)
|
||||
if output, err := build.CombinedOutput(); err != nil {
|
||||
return "", errs.New(errs.BuildFailed, "native bindings helper does not compile",
|
||||
log.F("output", strings.TrimSpace(string(output))))
|
||||
@@ -59,6 +61,7 @@ func BuildManifest(p *project.Project, engineVersion string, lg *log.Logger) (st
|
||||
tmp := out + ".tmp"
|
||||
run := exec.Command(bin, tmp)
|
||||
run.Dir = p.Root
|
||||
proc.Hide(run)
|
||||
if output, err := run.CombinedOutput(); err != nil {
|
||||
os.Remove(tmp)
|
||||
return "", errs.New(errs.BuildFailed, "native module Register failed",
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package brand
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"image"
|
||||
"image/png"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//go:embed png/aego-*.png
|
||||
var files embed.FS
|
||||
|
||||
var windowSizes = []int{16, 24, 32, 48, 64, 128, 256}
|
||||
|
||||
func PNG(n int) ([]byte, bool) {
|
||||
data, err := files.ReadFile("png/aego-" + strconv.Itoa(n) + ".png")
|
||||
return data, err == nil
|
||||
}
|
||||
|
||||
func Window() []image.Image {
|
||||
out := make([]image.Image, 0, len(windowSizes))
|
||||
for _, n := range windowSizes {
|
||||
data, ok := PNG(n)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if img, err := png.Decode(bytes.NewReader(data)); err == nil {
|
||||
out = append(out, img)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 563 B |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 878 B |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
@@ -41,6 +41,7 @@ type Config struct {
|
||||
Editor bool
|
||||
FailOnScriptErrors bool
|
||||
Catalog assembly.Catalog
|
||||
Platform platform.Platform
|
||||
Profile string
|
||||
NoProfile bool
|
||||
}
|
||||
@@ -98,6 +99,9 @@ func (h *Host) build(cfg Config, mods []module.Module) error {
|
||||
ecfg.LoopScope = cfg.LoopScope
|
||||
}
|
||||
builder := engine.NewBuilder(ecfg).WithLogger(lg).Use(rmod)
|
||||
if cfg.Platform != nil {
|
||||
builder.WithPlatform(cfg.Platform)
|
||||
}
|
||||
if h.Types, err = assembly.NewTypes(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -187,6 +191,7 @@ func (h *Host) build(cfg Config, mods []module.Module) error {
|
||||
}
|
||||
h.Settings.SetNames(h.Sections.Names)
|
||||
h.Engine.SetService(settings.ServiceID, h.Settings)
|
||||
h.Engine.OnClose(h.Modules.Shutdown)
|
||||
if err = h.Modules.Init(&module.InitContext{Engine: h.Engine, Assets: h.Loader, Log: lg, Editor: cfg.Editor, Sections: h.Sections, Problems: h.Problems, Settings: h.Settings}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -227,9 +232,6 @@ func (h *Host) Close() {
|
||||
return
|
||||
}
|
||||
h.closed = true
|
||||
if h.Modules != nil {
|
||||
h.Modules.Shutdown()
|
||||
}
|
||||
if h.Engine != nil {
|
||||
h.Engine.Close()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package docstool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"aego/app/playground"
|
||||
"aego/engine/docs"
|
||||
"aego/engine/module"
|
||||
)
|
||||
|
||||
// CheckExamples loads the example scene of every module code, validates it and runs it headless; the code must be among the problems it reports (D146).
|
||||
func CheckExamples(reg *docs.Registry, w io.Writer) int {
|
||||
pg, err := playground.New()
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "examples: cannot start the docs runtime:", err)
|
||||
return 1
|
||||
}
|
||||
pg.SetGame(playground.GameConfig{Headless: true, FrameTime: 1.0 / 60})
|
||||
defer func() {
|
||||
if g := pg.Game(); g != nil {
|
||||
g.Close()
|
||||
}
|
||||
}()
|
||||
bad := 0
|
||||
for _, e := range reg.All() {
|
||||
if e.Kind != docs.Code || e.Diag == nil || e.Diag.Example == "" {
|
||||
continue
|
||||
}
|
||||
found, why := false, ""
|
||||
code := ""
|
||||
if e.Diag.ExampleScript != "" {
|
||||
c, err := pg.TryCode(e.Diag.ExampleScript)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%s: error: example script does not compile: %v\n", e.ID, err)
|
||||
bad++
|
||||
continue
|
||||
}
|
||||
code = c
|
||||
}
|
||||
if res := pg.PlayScene("example-"+e.ID, []byte(e.Diag.Example), code, nil); !res.Started {
|
||||
why = "does not load: " + res.Error
|
||||
} else {
|
||||
for _, d := range module.ValidateScene(pg.Game().Scene(), nil) {
|
||||
found = found || d.Code == e.ID
|
||||
}
|
||||
if err := pg.Game().Step(tryFrames); err != nil {
|
||||
why = "stops the engine: " + err.Error()
|
||||
}
|
||||
}
|
||||
poll := pg.Poll()
|
||||
for _, f := range poll.Faults {
|
||||
found = found || f.Code == e.ID
|
||||
}
|
||||
for _, l := range poll.Log {
|
||||
found = found || strings.Contains(l.Text, e.ID)
|
||||
}
|
||||
switch {
|
||||
case why != "":
|
||||
fmt.Fprintf(w, "%s: error: example %s %s\n", e.ID, e.Diag.ExampleFile, why)
|
||||
bad++
|
||||
case !found:
|
||||
fmt.Fprintf(w, "%s: error: example of %s does not produce %s\n", e.ID, e.ID, e.ID)
|
||||
bad++
|
||||
}
|
||||
}
|
||||
pg.Stop()
|
||||
return bad
|
||||
}
|
||||
@@ -21,7 +21,8 @@ import (
|
||||
"aego/script/workspace"
|
||||
)
|
||||
|
||||
func build(p *project.Project, mods []module.Module, diagnose func(string, *docs.DiagInfo)) (*docs.Registry, *workspace.Workspace, error) {
|
||||
// build assembles the registry; with pg it also compiles the diagnostics examples and the try scripts.
|
||||
func build(p *project.Project, mods []module.Module, pg *playground.Playground) (*docs.Registry, *workspace.Workspace, error) {
|
||||
types, err := assembly.NewTypes()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -42,7 +43,10 @@ func build(p *project.Project, mods []module.Module, diagnose func(string, *docs
|
||||
return nil, nil, err
|
||||
}
|
||||
src := docs.SourcesOf(bm, types.Schema(), man)
|
||||
src.Diagnose = diagnose
|
||||
if pg != nil {
|
||||
src.Diagnose = diagnoser(pg)
|
||||
src.CompileTry = pg.TryCode
|
||||
}
|
||||
var ws *workspace.Workspace
|
||||
if p != nil {
|
||||
ws, err = workspace.Open(workspace.Config{Root: p.Root, Module: p.Module, Scripts: p.ScriptsDir(), Bindings: reg.Table(), Docs: bm})
|
||||
@@ -67,13 +71,13 @@ func Registry(p *project.Project, mods []module.Module) (*docs.Registry, error)
|
||||
return r, err
|
||||
}
|
||||
|
||||
// ExportRegistry is Registry with the diagnostics examples compiled for their messages and positions.
|
||||
// ExportRegistry is Registry with the diagnostics examples compiled for their messages and positions, and the try scripts compiled.
|
||||
func ExportRegistry(p *project.Project, mods []module.Module) (*docs.Registry, error) {
|
||||
pg, err := playground.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r, _, err := build(p, mods, diagnoser(pg))
|
||||
r, _, err := build(p, mods, pg)
|
||||
return r, err
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,9 @@ func (e *Env) Check(strict bool) int {
|
||||
if CheckTry(reg, e.Stdout) > 0 && code == 0 {
|
||||
code = 1
|
||||
}
|
||||
if CheckExamples(reg, e.Stdout) > 0 && code == 0 {
|
||||
code = 1
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,16 @@ func CheckTry(reg *docs.Registry, w io.Writer) int {
|
||||
}
|
||||
msgs = append(msgs, msg)
|
||||
}
|
||||
switch res := pg.PlayScene(e.ID, []byte(e.Try)); {
|
||||
var code string
|
||||
var err error
|
||||
if e.TryScript != "" {
|
||||
code, err = pg.TryCode(e.TryScript)
|
||||
}
|
||||
switch res := pg.PlayScene(e.ID, []byte(e.Try), code, e.TryPrefabs); {
|
||||
case !sandbox[e.ID]:
|
||||
add("belongs to a module the docs runtime does not include")
|
||||
case err != nil:
|
||||
add("script does not compile: " + err.Error())
|
||||
case !res.Started:
|
||||
add("does not load: " + res.Error)
|
||||
default:
|
||||
|
||||
@@ -75,6 +75,7 @@ type App struct {
|
||||
ui *core.Context
|
||||
clip *docsession.Clipboard
|
||||
session *docsession.Session
|
||||
scripts *scriptHost
|
||||
insp *inspector.Panel
|
||||
game *gameview.Panel
|
||||
list *draw.List
|
||||
@@ -143,15 +144,17 @@ func New(opt Options) (*App, error) {
|
||||
return nil, err
|
||||
}
|
||||
a.e.SetService(loader.ServiceID, a.loader)
|
||||
playmods.UseMemorySaves(a.e)
|
||||
a.e.SetService(renderhost.ServiceID, a.renderer)
|
||||
if err := a.man.Init(&module.InitContext{Engine: a.e, Assets: a.loader, Log: a.log, Editor: true, Sections: sections}); err != nil {
|
||||
a.Close()
|
||||
return nil, err
|
||||
}
|
||||
a.initUI()
|
||||
a.scripts = &scriptHost{reg: reg, types: a.types, man: a.man, log: a.log}
|
||||
a.session = docsession.New(docsession.Options{
|
||||
Engine: a.e, Renderer: a.renderer, Loader: a.loader, Types: a.types, Sections: sections,
|
||||
Scripts: &scriptHost{reg: reg, types: a.types, man: a.man, log: a.log},
|
||||
Scripts: a.scripts,
|
||||
UI: a.ui,
|
||||
Clipboard: a.clip,
|
||||
Log: a.log,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package docsview
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -46,11 +47,22 @@ func errorsOf(a *App) []string {
|
||||
|
||||
func TestTryScenesRun(t *testing.T) {
|
||||
a := newHeadless(t)
|
||||
p, err := playground.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range tries(t) {
|
||||
if err := a.session.Load([]byte(e.Try), e.TrySelect); err != nil {
|
||||
t.Fatalf("%s: %v", e.ID, err)
|
||||
var code string
|
||||
if e.TryScript != "" {
|
||||
if code, err = p.TryCode(e.TryScript); err != nil {
|
||||
t.Fatalf("%s: %v", e.ID, err)
|
||||
}
|
||||
}
|
||||
if err := a.Step(60); err != nil {
|
||||
req, _ := json.Marshal(map[string]any{"scene": e.Try, "select": e.TrySelect, "code": code, "prefabs": e.TryPrefabs})
|
||||
if r := a.Call("load", req); r.Error != "" {
|
||||
t.Fatalf("%s: %s", e.ID, r.Error)
|
||||
}
|
||||
if err := a.Step(400); err != nil {
|
||||
t.Fatalf("%s: %v", e.ID, err)
|
||||
}
|
||||
st := a.session.State()
|
||||
|
||||
@@ -6,16 +6,20 @@ import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
playmods "aego/app/assembly/playground"
|
||||
"aego/editor/core/docsession"
|
||||
"aego/scene/sceneio"
|
||||
)
|
||||
|
||||
type request struct {
|
||||
Scene string `json:"scene"`
|
||||
Select string `json:"select"`
|
||||
Component string `json:"component"`
|
||||
Field string `json:"field"`
|
||||
Value float64 `json:"value"`
|
||||
Scene string `json:"scene"`
|
||||
Select string `json:"select"`
|
||||
Code string `json:"code"`
|
||||
Prefabs map[string]string `json:"prefabs"`
|
||||
Component string `json:"component"`
|
||||
Field string `json:"field"`
|
||||
Value float64 `json:"value"`
|
||||
Node string `json:"node"`
|
||||
}
|
||||
|
||||
type Reply struct {
|
||||
@@ -24,6 +28,7 @@ type Reply struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
State *docsession.State `json:"state,omitempty"`
|
||||
Log []Line `json:"log,omitempty"`
|
||||
Pose []float64 `json:"pose,omitempty"`
|
||||
}
|
||||
|
||||
func (a *App) Call(method string, payload []byte) Reply {
|
||||
@@ -37,7 +42,16 @@ func (a *App) Call(method string, payload []byte) Reply {
|
||||
var err error
|
||||
switch method {
|
||||
case "load":
|
||||
err = s.Load([]byte(req.Scene), req.Select)
|
||||
mods, derr := playmods.DecodeTry(req.Code)
|
||||
if err = derr; err == nil {
|
||||
err = a.scripts.use(mods)
|
||||
}
|
||||
if err == nil {
|
||||
err = playmods.MountTry(a.loader, req.Prefabs)
|
||||
}
|
||||
if err == nil {
|
||||
err = s.Load([]byte(req.Scene), req.Select)
|
||||
}
|
||||
case "reset":
|
||||
err = s.Reset()
|
||||
case "text":
|
||||
@@ -52,6 +66,17 @@ func (a *App) Call(method string, payload []byte) Reply {
|
||||
case "state":
|
||||
st := s.State()
|
||||
return Reply{State: &st}
|
||||
case "pose":
|
||||
sc := s.Controller().Scene()
|
||||
if sc == nil {
|
||||
return Reply{Error: "the scene is not running"}
|
||||
}
|
||||
h := sc.Find(sc.Root(), req.Node)
|
||||
if h.IsZero() || !sc.IsAlive(h) {
|
||||
return Reply{Error: "no node " + strconv.Quote(req.Node)}
|
||||
}
|
||||
p := sc.WorldPosition(h)
|
||||
return Reply{Pose: []float64{float64(p.X), float64(p.Y)}}
|
||||
case "log":
|
||||
out := Reply{Log: a.lines}
|
||||
a.lines = nil
|
||||
|
||||
@@ -22,6 +22,15 @@ type scriptHost struct {
|
||||
mods []*bytecode.Module
|
||||
}
|
||||
|
||||
// use makes mods the scripts of the next scene and publishes their types, so the scene keeps their fields.
|
||||
func (h *scriptHost) use(mods []*bytecode.Module) error {
|
||||
if err := scriptruntime.Publish(h.types.Schema(), mods, h.reg.Surface()); err != nil {
|
||||
return err
|
||||
}
|
||||
h.mods = mods
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *scriptHost) Errors() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"aego/engine"
|
||||
"aego/platform"
|
||||
)
|
||||
|
||||
func startBoot(verb string) {
|
||||
wd, _ := os.Getwd()
|
||||
exe, _ := os.Executable()
|
||||
gobin, err := exec.LookPath("go")
|
||||
if err != nil {
|
||||
gobin = "not on PATH"
|
||||
}
|
||||
_ = platform.StartBoot(platform.DefaultBootPath(),
|
||||
"aego "+engine.Version+" "+runtime.GOOS+"/"+runtime.GOARCH+" "+verb,
|
||||
"exe "+exe,
|
||||
"args "+strings.Join(os.Args[1:], " "),
|
||||
"cwd "+wd,
|
||||
"go "+gobin,
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"aego/app/bootstrap"
|
||||
"aego/app/export"
|
||||
"aego/app/projects"
|
||||
"aego/asset/pipeline"
|
||||
"aego/editor/core/services"
|
||||
"aego/editor/core/sysopen"
|
||||
"aego/engine/problems"
|
||||
"aego/project"
|
||||
)
|
||||
@@ -87,3 +92,47 @@ func (x *exporter) Reveal(path string) error {
|
||||
}
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
var webServers sync.Map
|
||||
|
||||
func serveWeb(dir string) (string, error) {
|
||||
if u, ok := webServers.Load(dir); ok {
|
||||
return u.(string), nil
|
||||
}
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
files := http.FileServer(http.Dir(dir))
|
||||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cross-Origin-Opener-Policy", "same-origin")
|
||||
w.Header().Set("Cross-Origin-Embedder-Policy", "require-corp")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
files.ServeHTTP(w, r)
|
||||
})
|
||||
go http.Serve(ln, h)
|
||||
u := "http://" + ln.Addr().String() + "/"
|
||||
webServers.Store(dir, u)
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (x *exporter) Run(out, target string) error {
|
||||
path, err := export.Launchable(x.p, target, out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t, _ := export.ParseTarget(target)
|
||||
switch {
|
||||
case t.Web():
|
||||
u, err := serveWeb(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sysopen.Open(u)
|
||||
case t.OS == "darwin":
|
||||
return exec.Command("open", path).Start()
|
||||
}
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = filepath.Dir(path)
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"aego/app/projects"
|
||||
"aego/editor/shell/launcher"
|
||||
"aego/project"
|
||||
)
|
||||
|
||||
func TestLauncherCreatesAndOpens(t *testing.T) {
|
||||
recent := filepath.Join(t.TempDir(), "recent")
|
||||
ls, err := OpenLauncher(Config{Headless: true, Recent: recent})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ls.UI.SetTab(launcher.TabNew)
|
||||
dir := filepath.Join(t.TempDir(), "Aego Projects", "game")
|
||||
if _, err := ls.UI.Create(dir, projects.Template2D, "", ""); err != nil {
|
||||
ls.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 0; i < 3 && ls.Step(); i++ {
|
||||
}
|
||||
ls.Close()
|
||||
root, ok := ls.UI.Result()
|
||||
if !ok {
|
||||
t.Fatal("the launcher has no result")
|
||||
}
|
||||
p, err := project.Load(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := Open(p, Config{Headless: true, NoWatch: true, Recent: recent})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
for i := 0; i < 3; i++ {
|
||||
s.Step()
|
||||
}
|
||||
if s.App.Context().Docs.Active() == nil {
|
||||
t.Fatal("no scene is open after creating the project")
|
||||
}
|
||||
list, _ := launcher.LoadRecent(recent)
|
||||
if len(list) == 0 || list[0].Path != root {
|
||||
t.Fatalf("recent list %+v", list)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"aego/core/log"
|
||||
)
|
||||
|
||||
const keepLogs = 10
|
||||
|
||||
type logFile struct {
|
||||
f *os.File
|
||||
}
|
||||
|
||||
func LogsDir() string {
|
||||
dir, err := os.UserCacheDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(dir, "aego", "logs")
|
||||
}
|
||||
|
||||
func attachLogs(cfg *Config) *logFile {
|
||||
if cfg.Logger == nil {
|
||||
cfg.Logger = log.New(log.NewTextSink(os.Stderr))
|
||||
if cfg.Debug {
|
||||
cfg.Logger.SetLevel(log.Debug)
|
||||
}
|
||||
}
|
||||
dir := LogsDir()
|
||||
if dir == "" || os.MkdirAll(dir, 0o755) != nil {
|
||||
return &logFile{}
|
||||
}
|
||||
name := "editor-" + time.Now().Format("20060102-150405") + "-" + strconv.Itoa(os.Getpid()) + ".log"
|
||||
f, err := os.Create(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
return &logFile{}
|
||||
}
|
||||
cfg.Logger.AddSink(log.NewTextSink(f))
|
||||
pruneLogs(dir)
|
||||
return &logFile{f: f}
|
||||
}
|
||||
|
||||
func (l *logFile) writer(w io.Writer) io.Writer {
|
||||
if l.f == nil {
|
||||
return w
|
||||
}
|
||||
return io.MultiWriter(w, l.f)
|
||||
}
|
||||
|
||||
func (l *logFile) close() {
|
||||
if l.f != nil {
|
||||
l.f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func pruneLogs(dir string) {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var names []string
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasSuffix(e.Name(), ".log") {
|
||||
names = append(names, e.Name())
|
||||
}
|
||||
}
|
||||
sort.Strings(names)
|
||||
for i := 0; i+keepLogs < len(names); i++ {
|
||||
os.Remove(filepath.Join(dir, names[i]))
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func TestProfilerSectionsFollowPlay(t *testing.T) {
|
||||
s.Step()
|
||||
}
|
||||
drawPanel(s, prof)
|
||||
expectSections(t, prof.Sections(), "Frame", "Memory", "Game", "Scripts", "Physics")
|
||||
expectSections(t, prof.Sections(), "Frame", "Memory", "Game", "Scripts", "Physics", "Audio", "Camera", "Gameplay")
|
||||
if _, err := ctx.Docs.Open("scenes/other.aescene"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"aego/app/proc"
|
||||
"aego/editor/core/session"
|
||||
)
|
||||
|
||||
const (
|
||||
EnvEditorExe = "AEGO_EDITOR_EXE"
|
||||
EnvEditorVerb = "AEGO_EDITOR_VERB"
|
||||
)
|
||||
|
||||
func markEntry(verb string) {
|
||||
if os.Getenv(EnvEditorExe) != "" {
|
||||
return
|
||||
}
|
||||
if img := os.Getenv("APPIMAGE"); img != "" {
|
||||
os.Setenv(EnvEditorExe, img)
|
||||
os.Setenv(EnvEditorVerb, "")
|
||||
return
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
os.Setenv(EnvEditorExe, exe)
|
||||
os.Setenv(EnvEditorVerb, verb)
|
||||
}
|
||||
|
||||
func relaunchArgs(verb, target, tab string) []string {
|
||||
if verb != "" {
|
||||
args := []string{verb}
|
||||
if target != "" {
|
||||
args = append(args, target)
|
||||
}
|
||||
if tab != "" {
|
||||
args = append(args, "--launcher", tab)
|
||||
}
|
||||
return args
|
||||
}
|
||||
var args []string
|
||||
if tab != "" {
|
||||
args = append(args, "-launcher", tab)
|
||||
}
|
||||
if target != "" {
|
||||
args = append(args, target)
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func withoutEnv(env []string, key string) []string {
|
||||
out := env[:0:0]
|
||||
for _, kv := range env {
|
||||
if !strings.HasPrefix(kv, key+"=") {
|
||||
out = append(out, kv)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func Relaunch(target, tab string) error {
|
||||
exe := os.Getenv(EnvEditorExe)
|
||||
if exe == "" {
|
||||
var err error
|
||||
if exe, err = os.Executable(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cmd := exec.Command(exe, relaunchArgs(os.Getenv(EnvEditorVerb), target, tab)...)
|
||||
cmd.Env = withoutEnv(os.Environ(), session.EnvSupervised)
|
||||
proc.Hide(cmd)
|
||||
return cmd.Start()
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"aego/project"
|
||||
)
|
||||
|
||||
func TestRelaunchArgs(t *testing.T) {
|
||||
cases := []struct {
|
||||
verb, target, tab string
|
||||
want []string
|
||||
}{
|
||||
{"", "/p", "", []string{"/p"}},
|
||||
{"", "", "recent", []string{"-launcher", "recent"}},
|
||||
{"edit", "/p", "", []string{"edit", "/p"}},
|
||||
{"edit", "", "new", []string{"edit", "--launcher", "new"}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := relaunchArgs(c.verb, c.target, c.tab); !slices.Equal(got, c.want) {
|
||||
t.Errorf("%q %q %q: %v, want %v", c.verb, c.target, c.tab, got, c.want)
|
||||
}
|
||||
}
|
||||
env := withoutEnv([]string{"A=1", "AEGO_SUPERVISED=1", "B=2"}, "AEGO_SUPERVISED")
|
||||
if !slices.Equal(env, []string{"A=1", "B=2"}) {
|
||||
t.Fatal(env)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveArg(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
os.WriteFile(filepath.Join(root, project.FileName), []byte("project version=1 {\n}\n"), 0o644)
|
||||
os.MkdirAll(filepath.Join(root, "scenes"), 0o755)
|
||||
scene := filepath.Join(root, "scenes", "main.aescene")
|
||||
os.WriteFile(scene, []byte("scene version=1 {\n}\n"), 0o644)
|
||||
if dir, file := resolveArg(filepath.Join(root, project.FileName)); dir != root || file != "" {
|
||||
t.Fatalf("project.aego: %q %q", dir, file)
|
||||
}
|
||||
dir, file := resolveArg(scene)
|
||||
if dir != filepath.Join(root, "scenes") || file != scene {
|
||||
t.Fatalf("scene: %q %q", dir, file)
|
||||
}
|
||||
if rel, ok := relInside(root, file); !ok || rel != "scenes/main.aescene" {
|
||||
t.Fatalf("rel %q %v", rel, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewer(t *testing.T) {
|
||||
cases := []struct {
|
||||
latest, current string
|
||||
want bool
|
||||
}{
|
||||
{"v0.9.0", "0.9.0-beta.1", true},
|
||||
{"v0.9.0-beta.1", "0.9.0-beta.1", false},
|
||||
{"v0.9.0-beta.2", "0.9.0-beta.1", true},
|
||||
{"v0.8.5", "0.9.0-beta.1", false},
|
||||
{"v1.0.0", "0.9.0", true},
|
||||
{"nightly", "0.9.0", false},
|
||||
{"", "0.9.0", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := newer(c.latest, c.current); got != c.want {
|
||||
t.Errorf("newer(%q, %q) = %v", c.latest, c.current, got)
|
||||
}
|
||||
}
|
||||
file := filepath.Join(t.TempDir(), "update")
|
||||
st := updateState{Enabled: false, Latest: "v1.2.3"}
|
||||
if err := saveUpdate(file, st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if back := loadUpdate(file); back.Enabled || back.Latest != "v1.2.3" {
|
||||
t.Fatalf("round trip %+v", back)
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,10 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"aego/core/ids"
|
||||
"aego/editor/core/command"
|
||||
"aego/editor/core/context"
|
||||
"aego/editor/core/vectors"
|
||||
"aego/editor/core/workspace"
|
||||
"aego/editor/panels/gameview"
|
||||
"aego/editor/shell"
|
||||
@@ -56,7 +58,60 @@ func (s *Session) shots(dir string) error {
|
||||
}
|
||||
return selectNamed(ctx, "Player")
|
||||
}},
|
||||
{name: "hitbox-gizmo", frames: 60, setup: func(s *Session) error {
|
||||
sc := ctx.Scene()
|
||||
var span []ids.NodeID
|
||||
for _, n := range []string{"EnemyLeft", "PatrolA1", "PatrolB1"} {
|
||||
span = append(span, sc.ID(sc.Find(sc.Root(), n)))
|
||||
}
|
||||
ctx.Select(span...)
|
||||
if err := ctx.Commands.Run(command.SceneFrame); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Step()
|
||||
}
|
||||
return selectNamed(ctx, "EnemyLeft")
|
||||
}},
|
||||
{name: "camera-follow", frames: 60, setup: func(s *Session) error {
|
||||
sc := ctx.Scene()
|
||||
ctx.Select(sc.ID(sc.Find(sc.Root(), "Camera")), sc.ID(sc.Find(sc.Root(), "Player")))
|
||||
if err := ctx.Commands.Run(command.SceneFrame); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Step()
|
||||
}
|
||||
return selectNamed(ctx, "Camera")
|
||||
}},
|
||||
{name: "camera-zone", frames: 60, setup: func(s *Session) error {
|
||||
sc := ctx.Scene()
|
||||
ctx.Select(sc.ID(sc.Find(sc.Root(), "ArenaZone")), sc.ID(sc.Find(sc.Root(), "PatrolA2")), sc.ID(sc.Find(sc.Root(), "PatrolB2")), sc.ID(sc.Find(sc.Root(), "GroundRight")))
|
||||
if err := ctx.Commands.Run(command.SceneFrame); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Step()
|
||||
}
|
||||
return selectNamed(ctx, "ArenaZone")
|
||||
}},
|
||||
{name: "clip-inspector", frames: 60, setup: func(s *Session) error {
|
||||
id, ok := s.Pipeline.Lookup("assets/audio/music.ogg")
|
||||
if !ok {
|
||||
return fmt.Errorf("no assets/audio/music.ogg")
|
||||
}
|
||||
s.App.Data().Inspect(id)
|
||||
return nil
|
||||
}},
|
||||
{name: "add-required", frames: 30, setup: func(s *Session) error {
|
||||
if err := selectNamed(ctx, "PatrolA1"); err != nil {
|
||||
return err
|
||||
}
|
||||
s.App.Inspector().OpenAdd("follow")
|
||||
return nil
|
||||
}},
|
||||
{name: "tags", frames: 60, setup: func(s *Session) error {
|
||||
ctx.UI.CloseAllPopups()
|
||||
return selectNamed(ctx, "Player")
|
||||
}},
|
||||
{name: "prefab", frames: 60, setup: func(s *Session) error {
|
||||
@@ -83,12 +138,23 @@ func (s *Session) shots(dir string) error {
|
||||
scene()
|
||||
return ctx.Commands.Run(command.PlayStart)
|
||||
}},
|
||||
{name: "motion-play", frames: 30, setup: func(s *Session) error {
|
||||
s.App.Workspace().Show(workspace.Inspector)
|
||||
s.App.Inspector().ScrollTo("gameplay.Motion2D")
|
||||
return selectNamed(ctx, "Player")
|
||||
}},
|
||||
{name: "mixer", frames: 120, setup: func(s *Session) error {
|
||||
s.App.Workspace().Switch(workspace.Audio)
|
||||
s.App.Workspace().Show(workspace.Mixer)
|
||||
return nil
|
||||
}},
|
||||
{name: "physics-debug", frames: 30, setup: func(s *Session) error {
|
||||
s.App.Workspace().Switch(workspace.Design)
|
||||
ctx.Overlay.Set("physics.debug.contacts", true)
|
||||
return ctx.Commands.Run(gameview.CommandOverlays)
|
||||
}},
|
||||
{name: "demo", frames: 60, inset: 2, bottom: 28, setup: func(s *Session) error {
|
||||
for _, f := range []string{"physics.debug", "physics.debug.shapes", "physics.debug.contacts", "physics.debug.joints"} {
|
||||
for _, f := range []string{gameview.CommandOverlays, vectors.CommandToggle} {
|
||||
ctx.Overlay.Set(f, false)
|
||||
}
|
||||
return ctx.Commands.Run(shell.CommandFullscreenPlay)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"aego/app/run"
|
||||
)
|
||||
|
||||
func (s *Session) runTests(done func(out string, failed bool)) error {
|
||||
p, mods := s.Project, s.mods
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
code := run.Tool(p, []string{"test", "-v"}, &buf, &buf, mods...)
|
||||
s.Engine.Jobs().OnMain(func() { done(buf.String(), code != 0) })
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"aego/app/export/icon"
|
||||
"aego/app/export/winres"
|
||||
"aego/app/proc"
|
||||
"aego/core/errs"
|
||||
"aego/core/log"
|
||||
"aego/runtime/bundle"
|
||||
@@ -121,7 +122,7 @@ func (j *job) resources(dir string) error {
|
||||
var icons []winres.Icon
|
||||
if j.icon != nil {
|
||||
for _, n := range winres.IconSizes {
|
||||
data, err := icon.PNG(icon.Resize(j.icon, n, n))
|
||||
data, err := icon.PNG(icon.Sized(j.icon, n))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -175,6 +176,7 @@ func (j *job) build() error {
|
||||
args = append(args, pkg)
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd.Dir = root
|
||||
proc.Hide(cmd)
|
||||
cgo := "CGO_ENABLED=1"
|
||||
if j.t.Web() {
|
||||
cgo = "CGO_ENABLED=0"
|
||||
|
||||
@@ -189,8 +189,9 @@ func (j *job) license(lib bundle.Lib, src, name string) bundle.Lib {
|
||||
}
|
||||
|
||||
func (j *job) libs() []bundle.Lib {
|
||||
vorbis := j.license(bundle.Lib{Name: "oggvorbis", Link: "static"}, filepath.Join(j.opt.Engine, "audio", "codec", "vorbis", "internal", "oggvorbis", "LICENSE"), "oggvorbis.txt")
|
||||
if j.t.Web() {
|
||||
return []bundle.Lib{j.license(bundle.Lib{Name: "Go wasm_exec.js", Link: "script", File: webExec}, filepath.Join(j.goroot, "LICENSE"), "Go.txt")}
|
||||
return []bundle.Lib{j.license(bundle.Lib{Name: "Go wasm_exec.js", Link: "script", File: webExec}, filepath.Join(j.goroot, "LICENSE"), "Go.txt"), vorbis}
|
||||
}
|
||||
return []bundle.Lib{j.license(bundle.Lib{Name: "SDL3", Link: "static"}, j.sdlLicense(), "SDL3.txt")}
|
||||
return []bundle.Lib{j.license(bundle.Lib{Name: "SDL3", Link: "static"}, j.sdlLicense(), "SDL3.txt"), vorbis}
|
||||
}
|
||||
|
||||