switched to ebitengine-input
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/knadh/koanf"
|
||||
"github.com/knadh/koanf/providers/env"
|
||||
"github.com/knadh/koanf/providers/posflag"
|
||||
input "github.com/quasilyte/ebitengine-input"
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
@@ -22,11 +23,26 @@ type Config struct {
|
||||
Loglevel string `koanf:"loglevel"`
|
||||
Debug bool `koanf:"debug"` // loglevel=debug
|
||||
Startlevel int
|
||||
Keymap input.Keymap `koanf:"keymap"` // we put it here so we can eventually customize it later
|
||||
}
|
||||
|
||||
func InitConfig() (*Config, error) {
|
||||
var kloader = koanf.New(".")
|
||||
|
||||
// Load default values using the confmap provider.
|
||||
/*
|
||||
if err := kloader.Load(confmap.Provider(map[string]interface{}{
|
||||
"keymap": input.Keymap{
|
||||
InputMoveLeft: {input.KeyGamepadLeft, input.KeyLeft, input.KeyA},
|
||||
InputMoveRight: {input.KeyGamepadRight, input.KeyRight, input.KeyD},
|
||||
InputMoveUp: {input.KeyGamepadUp, input.KeyUp, input.KeyW},
|
||||
InputMoveDown: {input.KeyGamepadDown, input.KeyDown, input.KeyS},
|
||||
},
|
||||
}, "."), nil); err != nil {
|
||||
return nil, fmt.Errorf("failed to load default values into koanf: %w", err)
|
||||
}
|
||||
*/
|
||||
|
||||
flagset := flag.NewFlagSet("config", flag.ContinueOnError)
|
||||
flagset.BoolP("debug", "d", false, "enable debug log")
|
||||
|
||||
@@ -72,6 +88,17 @@ func InitConfig() (*Config, error) {
|
||||
conf.Startlevel = level
|
||||
}
|
||||
|
||||
conf.Keymap = input.Keymap{
|
||||
MoveLeft: {input.KeyGamepadLeft, input.KeyLeft, input.KeyA},
|
||||
MoveRight: {input.KeyGamepadRight, input.KeyRight, input.KeyD},
|
||||
MoveUp: {input.KeyGamepadUp, input.KeyUp, input.KeyW},
|
||||
MoveDown: {input.KeyGamepadDown, input.KeyDown, input.KeyS},
|
||||
SwitchPlayer: {input.KeyTab},
|
||||
Abort: {input.KeyEscape},
|
||||
Activate: {input.KeyEnter, input.KeyMouseLeft},
|
||||
Any: {},
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package config
|
||||
import (
|
||||
"image/color"
|
||||
"time"
|
||||
|
||||
input "github.com/quasilyte/ebitengine-input"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,3 +35,14 @@ var VERSION string // maintained by -x
|
||||
|
||||
var FontColorFG = color.RGBA{0, 255, 128, 255} // blue
|
||||
//var FontColorFG = color.RGBA{117, 167, 67, 255} // green
|
||||
|
||||
const (
|
||||
MoveLeft input.Action = iota
|
||||
MoveRight
|
||||
MoveUp
|
||||
MoveDown
|
||||
SwitchPlayer
|
||||
Abort
|
||||
Activate
|
||||
Any
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user