refactor: rewrite loop to use update directly
make it less cursed. add a choice to wait for execute or just run right away. might be breaking change but may not depending on implementation
I don't like that name
I think kaboom style is like
Hey kaboom, add a game object destroy a game object tween this make an object loop this function
This is not about renaming loop, it is about refactoring it to not use wait. Instead it should use an update event directly.
Lol, my bad
@niceEli something like this
loop(this: GameObj<TimerComp>, time: number, action: () => void, count: number = -1): EventController {
let t:number = 0
const ev = this.onUpdate(() => {
t += dt()
if (t >= time) {
action()
t -= time
if (count != -1 && --count === 0) {
ev.cancel()
}
}
})
return {
get paused() {
return ev.paused
},
set paused(p) {
ev.paused = p
},
cancel: ev.cancel,
}
},
wait(this: GameObj<TimerComp>, time: number, action?: () => void): EventController {
return this.loop(time, action, 1)
}
BTW, does anyone really use the then or onEnd stuff of wait? It only adds complexity I think. It makes more sense to add an onEnd to loop, since you might want to do something when it stops looping.
loop(this: GameObj<TimerComp>, time: number, action: () => void, count: number = -1): EventController { let t:number = 0 const ev = this.onUpdate(() => { t += dt() if (t >= time) { action() t -= time if (count != -1 && --count === 0) { ev.cancel() } } }) return { get paused() { return ev.paused }, set paused(p) { ev.paused = p }, cancel: ev.cancel, } }, wait(this: GameObj<TimerComp>, time: number, action?: () => void): EventController { return this.loop(time, action, 1) }
should i add?
Replace you mean? You can.