ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 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 / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
515 lines
14 KiB
Go
515 lines
14 KiB
Go
//go:build aego_editor
|
|
|
|
package docsview
|
|
|
|
import (
|
|
"aego/app/assembly"
|
|
playmods "aego/app/assembly/playground"
|
|
"aego/asset"
|
|
"aego/asset/loader"
|
|
"aego/contracts/debugdraw"
|
|
"aego/core/log"
|
|
"aego/core/mathx"
|
|
edclip "aego/editor/core/clipboard"
|
|
"aego/editor/core/context"
|
|
"aego/editor/core/docsession"
|
|
"aego/editor/core/services"
|
|
"aego/editor/ext/inspect"
|
|
"aego/editor/panels/gameview"
|
|
"aego/editor/panels/inspector"
|
|
"aego/engine"
|
|
"aego/engine/base"
|
|
"aego/engine/i18n"
|
|
"aego/engine/module"
|
|
"aego/format/aetext"
|
|
"aego/modules/physics"
|
|
scriptsystems "aego/modules/scripting/systems"
|
|
"aego/platform"
|
|
"aego/platform/input"
|
|
"aego/render"
|
|
renderhost "aego/render/host"
|
|
"aego/render/icons"
|
|
"aego/render/text"
|
|
"aego/render/view"
|
|
"aego/scene"
|
|
"aego/scene/frame"
|
|
"aego/script/bind"
|
|
"aego/ui/core"
|
|
"aego/ui/draw"
|
|
"aego/ui/theme"
|
|
"aego/ui/widgets"
|
|
)
|
|
|
|
const (
|
|
appID = "aego-docs"
|
|
maxSprites = 16384
|
|
gameShare = 0.6
|
|
stackBelow = 640
|
|
// inspectorMin keeps field names and values readable in narrow embeds.
|
|
inspectorMin = 400
|
|
maxLines = 200
|
|
defaultW = 960
|
|
defaultH = 440
|
|
)
|
|
|
|
var coreBlocks = []string{"window", "defaults"}
|
|
|
|
type Options struct {
|
|
Headless bool
|
|
FrameTime float64
|
|
Width int
|
|
Height int
|
|
}
|
|
|
|
type Line struct {
|
|
Text string `json:"text"`
|
|
Error bool `json:"error"`
|
|
}
|
|
|
|
type App struct {
|
|
OnChange func(text string)
|
|
opt Options
|
|
types *scene.Types
|
|
man *module.Manifest
|
|
e *engine.Engine
|
|
renderer *render.Renderer
|
|
loader *loader.Loader
|
|
ui *core.Context
|
|
clip *docsession.Clipboard
|
|
session *docsession.Session
|
|
scripts *scriptHost
|
|
insp *inspector.Panel
|
|
game *gameview.Panel
|
|
list *draw.List
|
|
log *log.Logger
|
|
lines []Line
|
|
textOn bool
|
|
shown *engine.World
|
|
closed bool
|
|
control ControlState
|
|
viewport Viewport
|
|
}
|
|
|
|
func noBlock(string) *aetext.Node {
|
|
return nil
|
|
}
|
|
|
|
func New(opt Options) (*App, error) {
|
|
if opt.Width <= 0 || opt.Height <= 0 {
|
|
opt.Width, opt.Height = defaultW, defaultH
|
|
}
|
|
a := &App{opt: opt, clip: &docsession.Clipboard{}}
|
|
a.log = log.New(log.FuncSink(a.record))
|
|
a.log.SetLevel(log.Info)
|
|
var err error
|
|
if a.types, err = assembly.NewTypes(); err != nil {
|
|
return nil, err
|
|
}
|
|
reg := bind.New()
|
|
if a.man, err = playmods.Catalog().Load(a.types, reg, assembly.Options{Seed: 1}); err != nil {
|
|
return nil, err
|
|
}
|
|
sections, err := a.man.LoadSections(noBlock, coreBlocks...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := a.types.Schema().Freeze(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := scriptsystems.Freeze(reg, a.types.Schema()); err != nil {
|
|
return nil, err
|
|
}
|
|
rmod := renderhost.New(render.Options{MaxSprites: maxSprites})
|
|
b := engine.NewBuilder(engine.Config{
|
|
Title: "Aego",
|
|
Width: opt.Width,
|
|
Height: opt.Height,
|
|
Headless: opt.Headless,
|
|
HeadlessFrameTime: opt.FrameTime,
|
|
VSync: platform.VSyncOn,
|
|
AppID: appID,
|
|
Seed: 1,
|
|
LoopScope: engine.ScopeEditor,
|
|
}).WithLogger(a.log).Use(rmod)
|
|
if err := frame.Register(b.Registry()); err != nil {
|
|
return nil, err
|
|
}
|
|
if ts, ok := module.SectionValue[base.Settings](sections, base.Section); ok {
|
|
b.Configure(ts.Apply)
|
|
}
|
|
b.Use(a.man.Engine())
|
|
if a.e, err = b.Build(); err != nil {
|
|
return nil, err
|
|
}
|
|
a.renderer = rmod.Renderer()
|
|
a.loader = loader.New(a.e.GPU(), a.renderer.Textures(), a.log)
|
|
a.loader.SetMaterials(a.renderer.Materials())
|
|
if err := a.loader.Mount(asset.NewIndex(), a.e.VFS()); err != nil {
|
|
a.Close()
|
|
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: a.scripts,
|
|
UI: a.ui,
|
|
Clipboard: a.clip,
|
|
Log: a.log,
|
|
Bare: true,
|
|
BeforeStart: func() {
|
|
// Each Try run owns its ephemeral saves. A worker from a previous
|
|
// run can finish without writing into the replacement scene's store.
|
|
playmods.UseMemorySaves(a.e)
|
|
},
|
|
OnChange: func(t []byte) {
|
|
if a.OnChange != nil {
|
|
a.OnChange(string(t))
|
|
}
|
|
},
|
|
})
|
|
return a, a.initPanels()
|
|
}
|
|
|
|
// SetTheme switches the Try it view to the site's theme, "light" or "dark" (D345).
|
|
func (a *App) SetTheme(name string) {
|
|
if a.ui == nil {
|
|
return
|
|
}
|
|
if name == "light" {
|
|
a.ui.Theme = theme.Light()
|
|
return
|
|
}
|
|
a.ui.Theme = theme.Editor()
|
|
}
|
|
|
|
func (a *App) initUI() {
|
|
r := a.renderer
|
|
ui := core.New(r.UIFont())
|
|
ui.Theme = theme.Editor()
|
|
ui.Clipboard = a.clip
|
|
if sh, err := draw.NewShapes(a.e.GPU(), r.Textures()); err == nil {
|
|
ui.SetShapes(sh)
|
|
}
|
|
if set, err := text.LoadSet(a.e.VFS(), r.Textures(), "engine://fonts", "ui", []int{12, 14, 16, 20}, []int{1, 2}); err == nil {
|
|
ui.SetFonts(set)
|
|
}
|
|
if set, err := text.LoadSet(a.e.VFS(), r.Textures(), "engine://fonts", "ui-mono", []int{12, 14, 16, 20}, []int{1, 2}); err == nil {
|
|
ui.SetMonoFonts(set)
|
|
}
|
|
if set, err := icons.Load(a.e.VFS(), r.Textures(), "engine://icons"); err == nil {
|
|
ui.Icons = set
|
|
}
|
|
a.ui = ui
|
|
}
|
|
|
|
func (a *App) initPanels() error {
|
|
ctx := a.session.Editor()
|
|
reg := inspect.NewRegistry()
|
|
if err := reg.Load(a.types.Schema()); err != nil {
|
|
return err
|
|
}
|
|
reg.SetEditor(ctx)
|
|
ids := make([]string, len(a.man.Modules))
|
|
for i, m := range a.man.Modules {
|
|
ids[i] = m.ID
|
|
}
|
|
reg.SetModules(ids)
|
|
a.insp = inspector.New(reg, inspector.Deps{
|
|
Docs: a.session,
|
|
Selection: a.session,
|
|
Commands: ctx.Commands,
|
|
Notices: ctx,
|
|
Nav: ctx,
|
|
Problems: ctx,
|
|
Sections: ctx.Sections,
|
|
Clip: edclip.EnvOf(ctx),
|
|
Assets: docsession.Unavailable{},
|
|
Scenes: docsession.Unavailable{},
|
|
Collapsed: ctx.Collapsed,
|
|
Schema: a.types.Schema(),
|
|
})
|
|
e := a.e
|
|
a.game = gameview.New(a.session.Controller(), &services.Viewport{
|
|
UI: a.ui,
|
|
GPU: e.GPU(),
|
|
Renderer: a.renderer,
|
|
Shapes: ctx.Shapes,
|
|
Overlay: &ctx.Overlay,
|
|
OnRender: ctx.OnRender,
|
|
Bare: a.session.Bare(),
|
|
RenderWorld: func(w *engine.World) {
|
|
e.RunPhase(w, engine.PhaseRenderPrepare, engine.ScopeEditor, 0, 0)
|
|
e.RunPhase(w, engine.PhaseRender, engine.ScopeEditor, 0, 0)
|
|
},
|
|
})
|
|
if w, ok := e.Window().(interface {
|
|
FenceTextInputClicks(func(mathx.Vec2, bool) bool)
|
|
}); ok {
|
|
w.FenceTextInputClicks(a.fenceInspectorClick)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) record(r log.Record) {
|
|
if len(a.lines) >= maxLines {
|
|
a.lines = append(a.lines[:0], a.lines[len(a.lines)-maxLines/2:]...)
|
|
}
|
|
a.lines = append(a.lines, Line{Text: r.Msg, Error: r.Level > log.Info})
|
|
}
|
|
|
|
func (a *App) Session() *docsession.Session {
|
|
return a.session
|
|
}
|
|
|
|
func (a *App) Run() error {
|
|
return a.e.Run(a)
|
|
}
|
|
|
|
func (a *App) Step(n int) error {
|
|
for i := 0; i < n; i++ {
|
|
if !a.e.Step(a) {
|
|
return a.e.Err()
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) Init(*engine.Engine) error {
|
|
return nil
|
|
}
|
|
|
|
func (a *App) Event(ev platform.Event) {
|
|
switch ev.Kind {
|
|
case platform.EvTextEditing:
|
|
a.ui.SetComposition(ev.Str, int(ev.EditStart))
|
|
case platform.EvTextInput:
|
|
a.ui.SetComposition("", 0)
|
|
case platform.EvWindowFocusLost:
|
|
a.game.Release()
|
|
case platform.EvMouseDown:
|
|
if ev.Mouse.Button == input.MouseLeft {
|
|
a.captureGameOnPointerDown(ev.Mouse.Pos)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Capture a click on the already presented game view before the next scene
|
|
// tick. A short key tap can arrive in the same platform frame as the click;
|
|
// waiting for game.Draw to capture would otherwise discard its edge. Leave
|
|
// focused text and active UI interactions to their normal commit/routing path.
|
|
func (a *App) captureGameOnPointerDown(pos mathx.Vec2) {
|
|
if a.ui == nil || a.session == nil || a.session.Controller().Captured() ||
|
|
a.ui.Focus() != 0 || a.ui.Active() != 0 || a.ui.Captured() != 0 ||
|
|
a.ui.ModalActive() || a.ui.AnyPopup() {
|
|
return
|
|
}
|
|
m := a.e.Metrics()
|
|
if a.viewport.CanvasWidth != m.LogicalW || a.viewport.CanvasHeight != m.LogicalH {
|
|
return
|
|
}
|
|
barHeight := a.ui.Theme.BarHeight
|
|
body := mathx.Rect{Y: barHeight, W: float32(m.LogicalW), H: max(0, float32(m.LogicalH)-barHeight)}
|
|
game, _ := layout(body, 1)
|
|
if game.W <= 0 || game.H <= 0 || a.viewport.X != game.X || a.viewport.Y != game.Y ||
|
|
a.viewport.Width != game.W || a.viewport.Height != game.H || !game.Contains(pos) {
|
|
return
|
|
}
|
|
a.session.Controller().SetCapture(true, mathx.Vec2{X: game.X, Y: game.Y}, mathx.Vec2{X: game.W, Y: game.H})
|
|
}
|
|
|
|
// Fence only clicks in the Inspector actually presented at the current size.
|
|
// Keyboard input after a game-view click must not be delayed by this path.
|
|
func (a *App) fenceInspectorClick(pos mathx.Vec2, release bool) bool {
|
|
if a.ui == nil || a.session == nil || !a.session.State().Loaded || a.ui.ModalActive() || a.ui.AnyPopup() ||
|
|
(!release && (a.ui.Active() != 0 || a.ui.Captured() != 0)) {
|
|
return false
|
|
}
|
|
m := a.e.Metrics()
|
|
if a.viewport.CanvasWidth != m.LogicalW || a.viewport.CanvasHeight != m.LogicalH {
|
|
return false
|
|
}
|
|
barHeight := a.ui.Theme.BarHeight
|
|
body := mathx.Rect{Y: barHeight, W: float32(m.LogicalW), H: max(0, float32(m.LogicalH)-barHeight)}
|
|
game, inspector := layout(body, 1)
|
|
return game.W > 0 && game.H > 0 && inspector.W > 0 && inspector.H > 0 &&
|
|
a.viewport.X == game.X && a.viewport.Y == game.Y && a.viewport.Width == game.W && a.viewport.Height == game.H &&
|
|
inspector.Contains(pos)
|
|
}
|
|
|
|
func (a *App) cancelTextInputFence() {
|
|
if a.e == nil {
|
|
return
|
|
}
|
|
if w, ok := a.e.Window().(interface{ CancelTextInputFence() }); ok {
|
|
w.CancelTextInputFence()
|
|
}
|
|
}
|
|
|
|
func (a *App) discardDocumentText() {
|
|
if a.ui != nil {
|
|
a.ui.DiscardTextEdit()
|
|
}
|
|
a.cancelTextInputFence()
|
|
}
|
|
|
|
func (a *App) FixedUpdate(float64) {}
|
|
|
|
func layout(body mathx.Rect, gap float32) (game, insp mathx.Rect) {
|
|
if body.W < stackBelow {
|
|
h := body.H * gameShare
|
|
return mathx.Rect{X: body.X, Y: body.Y, W: body.W, H: h},
|
|
mathx.Rect{X: body.X, Y: body.Y + h + gap, W: body.W, H: max(0, body.H-h-gap)}
|
|
}
|
|
w := min(body.W*gameShare, body.W-inspectorMin)
|
|
return mathx.Rect{X: body.X, Y: body.Y, W: w, H: body.H},
|
|
mathx.Rect{X: body.X + w + gap, Y: body.Y, W: max(0, body.W-w-gap), H: body.H}
|
|
}
|
|
|
|
func (a *App) panel(f *services.Frame, r mathx.Rect, drawFn func(*services.Frame, mathx.Rect)) {
|
|
ui := a.ui
|
|
ui.Region(r)
|
|
ui.PushClip(r)
|
|
drawFn(f, r)
|
|
ui.PopClip()
|
|
ui.PopCursor()
|
|
}
|
|
|
|
func (a *App) toolbar(r mathx.Rect) {
|
|
ui := a.ui
|
|
st := a.session.State()
|
|
label, tip := i18n.Tr("editor.docsview.pause", "Pause"), i18n.Tr("editor.docsview.pause_tip", "Pause the simulation")
|
|
if !st.Running || st.Paused {
|
|
label, tip = i18n.Tr("editor.docsview.play", "Play"), i18n.Tr("editor.docsview.play_tip", "Run the simulation")
|
|
}
|
|
tb := widgets.BeginToolbar(ui, r)
|
|
if c, _ := tb.TextButton(ui.ID("play"), label, tip); c {
|
|
a.session.TogglePause()
|
|
}
|
|
if c, _ := tb.TextButton(ui.ID("reset"), i18n.Tr("editor.docsview.reset", "Reset"), i18n.Tr("editor.docsview.reset_tip", "Load the original scene again")); c {
|
|
if err := a.session.Reset(); err != nil {
|
|
a.session.Editor().Notify(context.LevelError, err.Error())
|
|
} else {
|
|
a.cancelControlAdvance()
|
|
a.discardDocumentText()
|
|
}
|
|
}
|
|
if c, _ := tb.TextButton(ui.ID("undo"), i18n.Tr("editor.docsview.undo", "Undo"), i18n.Tr("editor.docsview.undo_tip", "Undo the last change")); c && st.CanUndo {
|
|
a.session.Undo()
|
|
}
|
|
if c, _ := tb.TextButton(ui.ID("redo"), i18n.Tr("editor.docsview.redo", "Redo"), i18n.Tr("editor.docsview.redo_tip", "Redo the change")); c && st.CanRedo {
|
|
a.session.Redo()
|
|
}
|
|
}
|
|
|
|
// showPhysics draws collider and joint outlines in the game view, since docs scenes have no art for them.
|
|
func (a *App) showPhysics() {
|
|
w := a.session.Controller().World()
|
|
if w == nil || w == a.shown {
|
|
return
|
|
}
|
|
if d, ok := engine.ServiceOf[debugdraw.Draw](w, debugdraw.ServiceID); ok {
|
|
d.Hide(physics.ChannelShapes, false)
|
|
d.Hide(physics.ChannelJoints, false)
|
|
a.shown = w
|
|
}
|
|
}
|
|
|
|
func (a *App) Update(dt float64) {
|
|
e := a.e
|
|
now := e.Platform().Now()
|
|
a.tickSession(dt)
|
|
a.showPhysics()
|
|
ui := a.ui
|
|
ui.Time = now
|
|
m := e.Metrics()
|
|
size := mathx.Vec2{X: float32(m.LogicalW), Y: float32(m.LogicalH)}
|
|
ui.Begin(e.Input(), size, m.Density())
|
|
th := &ui.Theme
|
|
ui.Rect(mathx.Rect{W: size.X, H: size.Y}, th.Background)
|
|
ctx := a.session.Editor()
|
|
frame := services.Frame{UI: ui, DnD: ctx.DnD, Now: now, Focused: true}
|
|
bar := mathx.Rect{W: size.X, H: th.BarHeight}
|
|
a.toolbar(bar)
|
|
body := mathx.Rect{Y: bar.H, W: size.X, H: max(0, size.Y-bar.H)}
|
|
gameR, inspR := layout(body, 1)
|
|
a.viewport = Viewport{X: gameR.X, Y: gameR.Y, Width: gameR.W, Height: gameR.H, CanvasWidth: m.LogicalW, CanvasHeight: m.LogicalH}
|
|
a.panel(&frame, gameR, a.game.Draw)
|
|
a.panel(&frame, inspR, a.insp.Draw)
|
|
ctx.DnD.Frame(ui)
|
|
a.list = ui.End()
|
|
a.applyPlatform()
|
|
}
|
|
|
|
func (a *App) applyPlatform() {
|
|
w := a.e.Window()
|
|
if ti, ok := w.(platform.TextInputer); ok {
|
|
want, r, cur := a.ui.WantsTextInput()
|
|
if want != a.textOn {
|
|
if want {
|
|
ti.StartTextInput()
|
|
} else {
|
|
ti.StopTextInput()
|
|
}
|
|
a.textOn = want
|
|
}
|
|
if want {
|
|
ti.SetTextInputArea(r, cur)
|
|
}
|
|
}
|
|
if c, ok := w.(platform.Cursorer); ok {
|
|
c.SetCursor(platform.CursorShape(a.ui.CursorShape()))
|
|
}
|
|
}
|
|
|
|
func (a *App) Render(float64) {
|
|
a.session.Editor().RunRenderHooks()
|
|
if a.list == nil || a.list.Empty() {
|
|
return
|
|
}
|
|
m := a.e.Metrics()
|
|
v := view.ScreenView(m.PixelW, m.PixelH, m.Density())
|
|
v.Clear = a.ui.Theme.Background
|
|
v.DoClear = true
|
|
v.Label = "docs.ui"
|
|
white := a.renderer.White()
|
|
if f := a.ui.Font(); f != nil && !f.White.IsZero() {
|
|
white = f.White
|
|
}
|
|
f := a.renderer.View(v)
|
|
a.list.Flush(f, a.ui.Font(), white, 0)
|
|
f.End()
|
|
}
|
|
|
|
func (a *App) Shutdown() {
|
|
a.session.Close()
|
|
a.game.Close()
|
|
}
|
|
|
|
func (a *App) Close() {
|
|
if a.closed {
|
|
return
|
|
}
|
|
a.closed = true
|
|
if a.session != nil {
|
|
a.session.Close()
|
|
}
|
|
if a.game != nil {
|
|
a.game.Close()
|
|
}
|
|
a.man.Shutdown()
|
|
if a.e != nil {
|
|
a.e.Close()
|
|
}
|
|
if a.loader != nil {
|
|
a.loader.Close()
|
|
}
|
|
}
|