-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
executable file
·55 lines (46 loc) · 1.26 KB
/
context.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
package zinc
// EntityEventFunc ...
type EntityEventFunc func(key uint, id EntityID)
// CTX ...
type CTX interface {
ComponentAdded(key uint, id EntityID)
ComponentDeleted(key uint, id EntityID)
ComponentUpdated(key uint, id EntityID)
HasEntity(id EntityID) bool
}
type ctx struct {
componentAddedFunc EntityEventFunc
componentDeletedFunc EntityEventFunc
componentUpdatedFunc EntityEventFunc
hasEntityFunc func(id EntityID) bool
}
func newContext(
// Component Event(s)
componentAddedFunc EntityEventFunc,
componentDeletedFunc EntityEventFunc,
componentUpdatedFunc EntityEventFunc,
// HasEntity
hasEntityFunc func(id EntityID) bool) CTX {
return ctx{
componentAddedFunc: componentAddedFunc,
componentDeletedFunc: componentDeletedFunc,
componentUpdatedFunc: componentUpdatedFunc,
hasEntityFunc: hasEntityFunc,
}
}
// ComponentAdded ...
func (c ctx) ComponentAdded(key uint, id EntityID) {
c.componentAddedFunc(key, id)
}
// ComponentDeleted ...
func (c ctx) ComponentDeleted(key uint, id EntityID) {
c.componentDeletedFunc(key, id)
}
// ComponentUpdated ...
func (c ctx) ComponentUpdated(key uint, id EntityID) {
c.componentUpdatedFunc(key, id)
}
// HasEntity ...
func (c ctx) HasEntity(id EntityID) bool {
return c.hasEntityFunc(id)
}