Files
aego/app/docsview/control.go
T
sanspie 50be5c04bc
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
Stage 12.5: Art Workspace and asset authoring
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.
2026-11-15 10:37:50 +03:00

115 lines
2.7 KiB
Go

//go:build aego_editor
package docsview
import (
"fmt"
"strings"
"aego/core/mathx"
"aego/platform/input"
)
// ControlState lets the native/browser contract harness replay bounded input
// at fixed frame boundaries. Ordinary documentation sessions leave it disabled.
type ControlState struct {
Enabled bool `json:"enabled"`
Remaining int `json:"remaining"`
keys []input.Scancode
started bool
}
const maxControlFrames = 600
func controlKey(name string) (input.Scancode, bool) {
if len(name) == 1 && name[0] >= 'A' && name[0] <= 'Z' {
return input.KeyA + input.Scancode(name[0]-'A'), true
}
switch name {
case "Space":
return input.KeySpace, true
case "Left":
return input.KeyLeft, true
case "Right":
return input.KeyRight, true
case "Up":
return input.KeyUp, true
case "Down":
return input.KeyDown, true
}
return input.KeyUnknown, false
}
func (a *App) releaseControlKeys() {
if a.control.started {
for _, key := range a.control.keys {
a.e.Input().ApplyKeyUp(key, 0, 0)
}
}
a.control.keys = nil
a.control.started = false
}
func (a *App) cancelControlAdvance() {
a.control.Remaining = 0
a.releaseControlKeys()
}
func (a *App) setControl(on bool) error {
if a.control.Remaining != 0 {
return fmt.Errorf("a controlled input sequence is still running")
}
a.releaseControlKeys()
a.control.Enabled = on
return nil
}
func (a *App) advanceControl(frames int, names []string) error {
if !a.control.Enabled || a.control.Remaining != 0 {
return fmt.Errorf("frame control is disabled or busy")
}
if frames < 1 || frames > maxControlFrames || len(names) > 8 {
return fmt.Errorf("controlled input exceeds its frame or key budget")
}
keys := make([]input.Scancode, 0, len(names))
seen := make(map[input.Scancode]bool, len(names))
for _, name := range names {
key, ok := controlKey(strings.TrimSpace(name))
if !ok || seen[key] {
return fmt.Errorf("unknown or duplicate gameplay key %q", name)
}
seen[key] = true
keys = append(keys, key)
}
if !a.session.State().Running || a.session.State().Paused {
return fmt.Errorf("the Try world must be playing before advancing it")
}
a.releaseControlKeys()
a.control.keys, a.control.Remaining = keys, frames
return nil
}
func (a *App) tickSession(dt float64) {
if !a.control.Enabled {
a.session.Tick(dt)
return
}
if a.control.Remaining == 0 {
return
}
if !a.control.started {
for _, key := range a.control.keys {
a.e.Input().ApplyKeyDown(key, 0, 0, false)
}
a.control.started = true
}
if len(a.control.keys) != 0 {
a.session.Controller().SetCapture(true, mathx.Vec2{}, mathx.Vec2{X: float32(a.opt.Width), Y: float32(a.opt.Height)})
}
a.session.Tick(1.0 / 60.0)
a.control.Remaining--
if a.control.Remaining == 0 {
a.releaseControlKeys()
}
}