Files
aego/scene/scriptcomp/script.go
T
sanspie f22242e5aa
ci / release (push) Successful in 5m5s
ci-platforms / build (amd64, windows, windows-2022) (push) Skipped
ci-platforms / build (arm64, darwin, macos-15) (push) Skipped
ci-platforms / build (amd64, darwin, macos-15-intel) (push) Skipped
ci / checks (push) Successful in 4m41s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 7m14s
Stage 11g2–11g3: registry texts, CLI and the site in Russian (D348)
The remaining editor strings and undo step names; component, field, enum, setting, diagnostic and Script API texts under schema.*, enum.*, setting.*, diag.* and api.*; the launcher, the in-game Settings View with a Language setting, the CLI and aego schema show --lang. Every documentation page has a .ru.md translation; the site has a full Russian tree with hreflang, a language switch and ru/llms.txt; aego docs check --lang ru. New doc.tutorial and doc.recipe icons. Fix: an animator restored by a rewind prepares its controller before the replayed step.
2026-10-25 15:31:22 +03:00

107 lines
2.1 KiB
Go

package scriptcomp
import (
"unsafe"
"aego/format/aetext"
"aego/scene"
"aego/schema"
)
const ScriptName = "engine.Script"
var ScriptTypeID = schema.HashName(ScriptName)
func ScriptsOf(s *scene.Scene, h scene.NodeHandle) (*ScriptComponent, bool) {
p, ok := s.GetByType(h, ScriptTypeID)
if !ok {
return nil, false
}
return (*ScriptComponent)(p), true
}
type Attachment struct {
TypeName string
Enabled bool
Props schema.PropertyBag
Unknown []aetext.Field
}
func (a *Attachment) Clone() Attachment {
out := *a
out.Props = a.Props.Clone()
out.Unknown = append([]aetext.Field(nil), a.Unknown...)
return out
}
func (a *Attachment) Is(td *schema.TypeDescriptor) bool {
if a.TypeName == td.FullName {
return true
}
for _, f := range td.Former {
if a.TypeName == f {
return true
}
}
return false
}
type ScriptComponent struct {
Attachments []Attachment `aego:"-"`
}
func (c *ScriptComponent) Index(name string) int {
for i := range c.Attachments {
if c.Attachments[i].TypeName == name {
return i
}
}
return -1
}
func (c *ScriptComponent) Find(td *schema.TypeDescriptor) *Attachment {
for i := range c.Attachments {
if c.Attachments[i].Is(td) {
return &c.Attachments[i]
}
}
return nil
}
type Overlay struct{}
func (Overlay) Bag(s *scene.Scene, h scene.NodeHandle, td *schema.TypeDescriptor) (unsafe.Pointer, bool) {
sc, ok := ScriptsOf(s, h)
if !ok {
return nil, false
}
a := sc.Find(td)
if a == nil {
return nil, false
}
return unsafe.Pointer(&a.Props), true
}
func Options() []schema.Option {
return []schema.Option{schema.Name(ScriptName), schema.Doc("Holds the Aego Script attachments of a node."), schema.Clone(cloneScripts)}
}
func cloneScripts(dst, src *ScriptComponent) {
if src.Attachments == nil {
dst.Attachments = nil
return
}
dst.Attachments = make([]Attachment, len(src.Attachments))
for i := range src.Attachments {
dst.Attachments[i] = src.Attachments[i].Clone()
}
}
func Register(t *scene.Types) error {
if err := scene.RegisterComponent[ScriptComponent](t, Options()...); err != nil {
return err
}
t.SetOverlay(Overlay{})
return nil
}