35 lines
606 B
Go
35 lines
606 B
Go
package gut
|
|
|
|
import "time"
|
|
|
|
type Animation interface {
|
|
Animate(start, now time.Duration) bool
|
|
}
|
|
|
|
type Animations struct {
|
|
anis []animation
|
|
}
|
|
|
|
type animation struct {
|
|
start time.Duration
|
|
ani Animation
|
|
}
|
|
|
|
func (a *Animations) Idle() bool {
|
|
return len(a.anis) == 0
|
|
}
|
|
|
|
func (a *Animations) Start(now time.Duration, ani Animation) {
|
|
a.anis = append(a.anis, animation{now, ani})
|
|
}
|
|
|
|
func (a *Animations) Animate(now time.Duration) {
|
|
active := make([]animation, 0, len(a.anis))
|
|
for _, ani := range a.anis {
|
|
if ani.ani.Animate(ani.start, now) {
|
|
active = append(active, ani)
|
|
}
|
|
}
|
|
a.anis = active
|
|
}
|