Files
aego/scene/sceneio/prefab.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

99 lines
2.5 KiB
Go

package sceneio
import (
"maps"
"aego/core/errs"
"aego/core/ids"
"aego/core/log"
"aego/format/aetext"
"aego/scene"
"aego/scene/prefab"
"aego/schema"
)
const PrefabName = "engine.PrefabInstance"
var prefabTypeID = schema.HashName(PrefabName)
type PrefabInstance struct {
Prefab ids.AssetID `aego:"-"`
Owner bool `aego:"-"`
Nested bool `aego:"-"`
Missing bool `aego:"-"`
Keys map[ids.NodeID]prefab.Key `aego:"-"`
Orphans prefab.Overrides `aego:"-"`
Extra []*aetext.Node `aego:"-"`
Block *aetext.Node `aego:"-"`
}
func RegisterPrefab(t *scene.Types) error {
if err := scene.RegisterComponent[PrefabInstance](t, schema.Name(PrefabName),
schema.Doc("Links a node to the prefab it was created from."), schema.FullClone(clonePrefab)); err != nil {
return err
}
if td, ok := t.Schema().ByName(PrefabName); ok {
td.Hidden, td.DisplayName = true, "Prefab Instance"
}
return nil
}
func clonePrefab(dst, src *PrefabInstance) {
*dst = *src
dst.Keys = maps.Clone(src.Keys)
dst.Orphans = src.Orphans.Clone()
dst.Extra = cloneNodes(src.Extra)
dst.Block = src.Block.Clone()
}
func InstanceOf(s *scene.Scene, h scene.NodeHandle) (*PrefabInstance, bool) {
p, ok := s.GetByType(h, prefabTypeID)
if !ok {
return nil, false
}
return (*PrefabInstance)(p), true
}
func addInstance(s *scene.Scene, h scene.NodeHandle) (*PrefabInstance, bool) {
p, err := s.AddByType(h, prefabTypeID)
if err != nil {
return nil, false
}
return (*PrefabInstance)(p), true
}
func PrefabRoot(s *scene.Scene, h scene.NodeHandle) (scene.NodeHandle, bool) {
for c := h; !c.IsZero() && c != s.Root() && s.IsAlive(c); c = s.Parent(c) {
if _, ok := InstanceOf(s, c); ok {
return c, true
}
}
return scene.NodeHandle{}, false
}
type Template struct {
Prefab ids.AssetID
Doc []byte
}
func Instantiate(s *scene.Scene, parent scene.NodeHandle, t *Template) (scene.NodeHandle, error) {
created, _, err := LoadInto(s, parent, t.Doc, "prefab "+t.Prefab.Short(), LoadOptions{})
if err != nil {
return scene.NodeHandle{}, err
}
at := parent
if at.IsZero() {
at = s.Root()
}
for _, h := range created {
if s.Parent(h) != at {
continue
}
if pi, ok := addInstance(s, h); ok {
pi.Prefab, pi.Owner, pi.Nested = t.Prefab, false, false
}
return h, nil
}
return scene.NodeHandle{}, errs.New(errs.SceneIOParse, "prefab template has no root node", log.F("prefab", t.Prefab.String()))
}