Remove ui.Keys

This commit is contained in:
Hajime Hoshi 2014-12-07 02:27:08 +09:00
parent f0f77c1a2f
commit 71d9bb8958
6 changed files with 12 additions and 16 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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 {

View File

@ -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() {

View File

@ -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)

View File

@ -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