-
Notifications
You must be signed in to change notification settings - Fork 1
/
componentlist.go
83 lines (63 loc) · 1.73 KB
/
componentlist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package lowcode
import (
"log/slog"
"github.com/zhs007/goutils"
"github.com/zhs007/slotsgamecore7/stats2"
)
type ComponentList struct {
Components []IComponent
MapComponents map[string]IComponent
Stats2 *stats2.Stats
statsNodeData *SPCNode
}
func (lst *ComponentList) AddComponent(name string, component IComponent) {
lst.Components = append(lst.Components, component)
lst.MapComponents[name] = component
}
func (lst *ComponentList) onInit(start string) error {
if gAllowStats2 {
node, err := ParseStepParentChildren(lst, start)
if err != nil {
goutils.Error("ComponentList.onInit:ParseStepParentChildren",
slog.String("start", start),
goutils.Err(err))
return err
}
lst.statsNodeData = node
lst.Stats2 = NewStats2(lst)
lst.Stats2.Start()
}
for _, v := range lst.MapComponents {
v.OnGameInited(lst)
}
return nil
}
// GetAllLinkComponents - get all link components
func (lst *ComponentList) GetAllLinkComponents(componentName string) []string {
ic, isok := lst.MapComponents[componentName]
if !isok {
goutils.Error("ComponentList.GetAllLinkComponents",
slog.String("name", componentName),
goutils.Err(ErrInvalidComponentName))
return nil
}
allcomponents := []string{componentName}
curlst := ic.GetAllLinkComponents()
for _, v := range curlst {
if v == "" {
continue
}
allcomponents = InsStringSliceNonRep(allcomponents, v)
// allcomponents = append(allcomponents, v)
children := lst.GetAllLinkComponents(v)
allcomponents = InsSliceNonRep(allcomponents, children)
// allcomponents = append(allcomponents, children...)
}
return allcomponents
}
func NewComponentList() *ComponentList {
lst := &ComponentList{
MapComponents: make(map[string]IComponent),
}
return lst
}