-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.go
More file actions
73 lines (54 loc) · 1.86 KB
/
Copy pathnode.go
File metadata and controls
73 lines (54 loc) · 1.86 KB
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
package scaff
import (
"github.com/Liphium/scaff/paint"
"github.com/hajimehoshi/ebiten/v2"
)
// TODO: Only rebuild props of nodes when their tracker is dirty: Check in the node builder, if not own thing dirty, just return old thingy (nothing changed anyway).
// All the context for nodes being created within ScaffUI
type BuildContext struct {
assetManager *paint.AssetManager
updateQueue *UpdateQueue
}
func (bc BuildContext) UpdateQueue() *UpdateQueue {
return bc.updateQueue
}
func (bc BuildContext) AssetManager() *paint.AssetManager {
return bc.assetManager
}
func (bc BuildContext) CopyWithNewUpdateQueue() *BuildContext {
return &BuildContext{
updateQueue: NewUpdateQueue(),
assetManager: bc.assetManager,
}
}
type NodeBuilder func(*BuildContext) Node
type Loadable[T any] interface {
// Called when the Node is initialized in the tree
Load(parent T)
// Called when the Node is removed from the tree
Unload()
}
type Node interface {
Tracking
Identifiable
Loadable[Node]
// Should return your own parent
Parent() Node
// Should return your own children
Children() []Node
// Called on every physics tick (like 60 times a second, depending on what ebitens tick rate is)
Update(c *Context) TracedError
// Handle events from the system (you do not have to handle any, but should always push them along to children at least)
HandleEvent(c *Context, event Event) TracedError
// Draw the thing onto the screen
Draw(c *Context, image *ebiten.Image)
}
// An interface for props of a node that has children. This helps nodes like single child not rebuild as often.
type ChildProps[B any] interface {
// GetBuilders gets all the builders for the children of this node
GetBuilders() []B
// GetChanged gets all the changed indices since the last time ClearChanged was called.
GetChanged() []uint
// ClearChanged clears all the changed indices
ClearChanged()
}