mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 18:02:02 +01:00
Remove ui.Keys
This commit is contained in:
parent
f0f77c1a2f
commit
71d9bb8958
@ -65,7 +65,7 @@ func (game *Game) Update(state ui.InputState) {
|
||||
if !game.isInitialized() {
|
||||
return
|
||||
}
|
||||
game.input.Update(state.PressedKeys())
|
||||
game.input.Update(state)
|
||||
game.sceneManager.Update(&GameState{
|
||||
SceneManager: game.sceneManager,
|
||||
Input: game.input,
|
||||
|
@ -22,9 +22,9 @@ func (i *Input) StateForKey(key ui.Key) int {
|
||||
return i.states[key]
|
||||
}
|
||||
|
||||
func (i *Input) Update(keys ui.Keys) {
|
||||
func (i *Input) Update(inputState ui.InputState) {
|
||||
for key := range i.states {
|
||||
if !keys.Includes(key) {
|
||||
if !inputState.IsPressedKey(key) {
|
||||
i.states[key] = 0
|
||||
continue
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ func newInputState() *InputState {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InputState) PressedKeys() ui.Keys {
|
||||
return i.pressedKeys
|
||||
func (i *InputState) IsPressedKey(key ui.Key) bool {
|
||||
return i.pressedKeys.Includes(key)
|
||||
}
|
||||
|
||||
func (i *InputState) MouseX() int {
|
||||
|
@ -2,7 +2,6 @@ package glfw
|
||||
|
||||
import (
|
||||
glfw "github.com/go-gl/glfw3"
|
||||
"github.com/hajimehoshi/ebiten/graphics"
|
||||
"github.com/hajimehoshi/ebiten/ui"
|
||||
"log"
|
||||
)
|
||||
@ -17,13 +16,13 @@ type UI struct {
|
||||
canvas *Canvas
|
||||
}
|
||||
|
||||
func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, graphics.TextureFactory) {
|
||||
func (u *UI) Start(width, height, scale int, title string) ui.Canvas {
|
||||
if !glfw.Init() {
|
||||
panic("glfw.Init() fails")
|
||||
}
|
||||
glfw.WindowHint(glfw.Resizable, glfw.False)
|
||||
u.canvas = NewCanvas(width, height, scale, title)
|
||||
return u.canvas, u.canvas
|
||||
return u.canvas
|
||||
}
|
||||
|
||||
func (u *UI) DoEvents() {
|
||||
|
@ -15,8 +15,8 @@ type Game interface {
|
||||
}
|
||||
|
||||
func Run(u UI, game Game, width, height, scale int, title string, fps int) {
|
||||
canvas, textureFactory := u.Start(width, height, scale, title)
|
||||
game.SetTextureFactory(textureFactory)
|
||||
canvas := u.Start(width, height, scale, title)
|
||||
game.SetTextureFactory(canvas)
|
||||
|
||||
frameTime := time.Duration(int64(time.Second) / int64(fps))
|
||||
tick := time.Tick(frameTime)
|
||||
|
9
ui/ui.go
9
ui/ui.go
@ -16,22 +16,19 @@ const (
|
||||
)
|
||||
|
||||
type UI interface {
|
||||
Start(widht, height, scale int, title string) (Canvas, graphics.TextureFactory)
|
||||
Start(widht, height, scale int, title string) Canvas
|
||||
DoEvents()
|
||||
Terminate()
|
||||
}
|
||||
|
||||
type Keys interface {
|
||||
Includes(key Key) bool
|
||||
}
|
||||
|
||||
type InputState interface {
|
||||
PressedKeys() Keys
|
||||
IsPressedKey(key Key) bool
|
||||
MouseX() int
|
||||
MouseY() int
|
||||
}
|
||||
|
||||
type Canvas interface {
|
||||
graphics.TextureFactory
|
||||
Draw(func(graphics.Context))
|
||||
IsClosed() bool
|
||||
InputState() InputState
|
||||
|
Loading…
Reference in New Issue
Block a user