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() { if !game.isInitialized() {
return return
} }
game.input.Update(state.PressedKeys()) game.input.Update(state)
game.sceneManager.Update(&GameState{ game.sceneManager.Update(&GameState{
SceneManager: game.sceneManager, SceneManager: game.sceneManager,
Input: game.input, Input: game.input,

View File

@ -22,9 +22,9 @@ func (i *Input) StateForKey(key ui.Key) int {
return i.states[key] return i.states[key]
} }
func (i *Input) Update(keys ui.Keys) { func (i *Input) Update(inputState ui.InputState) {
for key := range i.states { for key := range i.states {
if !keys.Includes(key) { if !inputState.IsPressedKey(key) {
i.states[key] = 0 i.states[key] = 0
continue continue
} }

View File

@ -38,8 +38,8 @@ func newInputState() *InputState {
} }
} }
func (i *InputState) PressedKeys() ui.Keys { func (i *InputState) IsPressedKey(key ui.Key) bool {
return i.pressedKeys return i.pressedKeys.Includes(key)
} }
func (i *InputState) MouseX() int { func (i *InputState) MouseX() int {

View File

@ -2,7 +2,6 @@ package glfw
import ( import (
glfw "github.com/go-gl/glfw3" glfw "github.com/go-gl/glfw3"
"github.com/hajimehoshi/ebiten/graphics"
"github.com/hajimehoshi/ebiten/ui" "github.com/hajimehoshi/ebiten/ui"
"log" "log"
) )
@ -17,13 +16,13 @@ type UI struct {
canvas *Canvas 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() { if !glfw.Init() {
panic("glfw.Init() fails") panic("glfw.Init() fails")
} }
glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.Resizable, glfw.False)
u.canvas = NewCanvas(width, height, scale, title) u.canvas = NewCanvas(width, height, scale, title)
return u.canvas, u.canvas return u.canvas
} }
func (u *UI) DoEvents() { 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) { func Run(u UI, game Game, width, height, scale int, title string, fps int) {
canvas, textureFactory := u.Start(width, height, scale, title) canvas := u.Start(width, height, scale, title)
game.SetTextureFactory(textureFactory) game.SetTextureFactory(canvas)
frameTime := time.Duration(int64(time.Second) / int64(fps)) frameTime := time.Duration(int64(time.Second) / int64(fps))
tick := time.Tick(frameTime) tick := time.Tick(frameTime)

View File

@ -16,22 +16,19 @@ const (
) )
type UI interface { type UI interface {
Start(widht, height, scale int, title string) (Canvas, graphics.TextureFactory) Start(widht, height, scale int, title string) Canvas
DoEvents() DoEvents()
Terminate() Terminate()
} }
type Keys interface {
Includes(key Key) bool
}
type InputState interface { type InputState interface {
PressedKeys() Keys IsPressedKey(key Key) bool
MouseX() int MouseX() int
MouseY() int MouseY() int
} }
type Canvas interface { type Canvas interface {
graphics.TextureFactory
Draw(func(graphics.Context)) Draw(func(graphics.Context))
IsClosed() bool IsClosed() bool
InputState() InputState InputState() InputState