Skip to content

Commit

Permalink
feat: fix subtree loader
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed Sep 22, 2021
1 parent 15cb595 commit fdab367
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/agent/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,28 @@ func (b *Behavior) BuildEngineFromConfig(conf []byte) *Engine {
}
}
engine.plans = cfg.Plans
core.SetSubTreeLoadFunc(func(name string) *core.BehaviorTree {
if t, ok := b.trees[name]; ok {
return loader.CreateBevTreeFromConfig(&t, b.registerMap)
}
log.Panic("create sub tree not found.")
return nil
})
b.registerSubTreeLoadFunc()
return engine
}

func (b *Behavior) BuildTestEngine(envs map[string]string, plan *transfer.Plan) *Engine {
engine := &Engine{Behavior: b}
engine.envs = envs
engine.plans = append(engine.plans, plan)
b.registerSubTreeLoadFunc()
return engine
}

func (b *Behavior) registerSubTreeLoadFunc() {
core.SetSubTreeLoadFunc(func(name string) *core.BehaviorTree {
if t, ok := b.trees[name]; ok {
return loader.CreateBevTreeFromConfig(&t, b.registerMap)
}
log.Panic("create sub tree not found.")
return nil
})
}

type Engine struct {
*Behavior
plans []*transfer.Plan
Expand Down

0 comments on commit fdab367

Please sign in to comment.