grow-graphics / gd

Go + Godot 4.3
https://learn.grow.graphics/
MIT License
244 stars 11 forks source link

Gather inputs #37

Closed Ullanar closed 4 months ago

Ullanar commented 4 months ago

Hi!

Here is simple code snippet from examples

func (p *Player) Process(delta gd.Float) {
    Input := gd.Input(p.Temporary)
    //...
}

gd.Input returns classdb.Input. I want to create function which handles all inputs and returns action name which should be processed into my state machine.

So i want to make function like

func (p *Player) HandleInput(event gd.InputEvent) {
       // trying to handle mouse modes
    if event.AsInputEvent().IsActionPressed(p.Temporary.StringName("ui_cancel"), true, true) {
        mouseMode := gd.Input(p.Temporary).GetMouseMode()
        if mouseMode == gd.InputMouseMode(0) {
            gd.Input(p.Temporary).SetMouseMode(gd.InputMouseMode(1))
        } else {
            gd.Input(p.Temporary).SetMouseMode(gd.InputMouseMode(0))
        }
    }

    // rest of strange code to collect movements
}

How can I get that gd.InputEvent type from classdb.Input? And also specific InputEventMouseMotion to handle rotation?