-
Notifications
You must be signed in to change notification settings - Fork 0
/
classTarget.go
49 lines (42 loc) · 1.09 KB
/
classTarget.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
package internal
import (
E "github.com/ionous/sashimi/event"
"github.com/ionous/sashimi/meta"
"github.com/ionous/sashimi/util/ident"
)
// Implements E.ITarget for classes.
// The objects and classes form a uniform chain of targets
type ClassTarget struct {
from ObjectTarget
class ident.Id
upObject meta.Instance
}
//
func (ct ClassTarget) Id() ident.Id {
return ct.class
}
//
func (ct ClassTarget) Class() ident.Id {
return ident.MakeId("class")
}
//
func (ct ClassTarget) String() string {
return ct.class.String()
}
// Walk up the class hierarchy; when we reach the end, move to the next instance.
// (from E.ITarget)
func (ct ClassTarget) Parent() (ret E.ITarget, okay bool) {
if cls, ok := ct.from.game.Model.GetClass(ct.class); ok {
ret = ClassTarget{ct.from, cls.GetParentClass(), ct.upObject}
okay = true
} else if next := ct.upObject; next != nil {
ret = ObjectTarget{ct.from.game, next}
okay = true
}
return
}
// Send an event to ct target.
// (from E.ITarget)
func (ct ClassTarget) TargetDispatch(evt E.IEvent) (err error) {
return ct.from.game.dispatch(evt, ct.class)
}