oakmound/oak

Best way to play back key inputs?

Closed this issue · 6 comments

I want to make a replay system for my game, but I don't know how to play back key inputs (and preferably block user inputs).

I had the idea of sending key events through shiny.EventDeque.Send(), but I can't find a function that exposes that in oak.

the closest I could find was event.Trigger, but it's not clear if that will affect calls to oak.IsDown.

Update: after some testing, I found event.Trigger did not affect oak.IsDown.

Update2: Since I'm already using a custom version of oak, I just implemented it myself (shinysend.go):

package oak

// ShinySend calls Send(event) on the underlying shiny.Window
func ShinySend(event interface{}) {
	windowControl.Send(event)
}

// ShinySendFirst is the same as ShinySend, but uses SendFirst instead of Send
func ShinySendFirst(event interface{}) {
	windowControl.SendFirst(event)
}
200sc commented

This is correct, event.Trigger does not affect oak.IsDown or oak.IsHeld. That seems like a valid feature request to add in. Something like oak.SimulateKeyPress(key string) with similar functions for mouse, release actions.

I guess my question here is why cant we just export setDown and setUp.
It looks like when the documentation for them was written they were orignally exported...

That being said if we add some extra tracker for simulation (a la allow disallow) then I see a valid use case for making an entirely new function that handles the simulation of the aforementioned key presses.

I cant remember why they were converted from exported but Chestertons fence comes to mind. In other words there probably should be a quick check to understand what if any extra safegaurds need to be put in place for this functionality.

200sc commented

I wouldn't want to export setUp and setDown because it has the opposite problem an event trigger does-- it would effect IsDown but not bindings. I'd prefer a simulate function that worked just like a key event, with a bit nicer API than needing to build an event struct.

Yeah, the structure of the key events was definitely a bit intimidating.
Would there be a way to do a similar thing with joystick events? There doesn't seem to be a good equivalent to sending raw key events.