ci-platforms / build (amd64, darwin, macos-15-intel) (push) Skipped
ci-platforms / build (amd64, windows, windows-2022) (push) Skipped
ci-platforms / build (arm64, darwin, macos-15) (push) Skipped
ci / checks (push) Successful in 21m2s
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 22m8s
40 lines
802 B
Go
40 lines
802 B
Go
package gizmo
|
|
|
|
import (
|
|
"aego/core/errs"
|
|
"aego/editor/core/history/commands"
|
|
"aego/editor/core/props"
|
|
"aego/schema"
|
|
)
|
|
|
|
func SetProperty(e *EditCtx, t schema.TypeID, fd *schema.FieldDescriptor, v schema.Value) {
|
|
if e.Err != nil || e.Tx == nil || fd == nil {
|
|
return
|
|
}
|
|
h := e.Scene.Handle(e.Node)
|
|
if h.IsZero() {
|
|
return
|
|
}
|
|
td, ok := e.Scene.Registry().ByID(t)
|
|
if !ok {
|
|
e.Err = errs.New(errs.SchemaUnknownType, "component type is not registered")
|
|
return
|
|
}
|
|
nv, err := props.Normalize(fd, v)
|
|
if err != nil {
|
|
e.Err = err
|
|
return
|
|
}
|
|
before, err := e.Scene.GetProperty(h, t, fd.ID)
|
|
if err != nil {
|
|
e.Err = err
|
|
return
|
|
}
|
|
if props.Equal(before, nv) {
|
|
return
|
|
}
|
|
if err := e.Tx.Exec(commands.SetField(e.Scene, e.Node, td, fd, nv, props.Label(fd))); err != nil {
|
|
e.Err = err
|
|
}
|
|
}
|