move KeyMap to Settings

This commit is contained in:
2023-07-04 23:53:03 +02:00
parent 6041c26eaa
commit 2c556a3dac
6 changed files with 33 additions and 36 deletions

View File

@@ -9,7 +9,7 @@ import (
)
func (e *Engine) WatchKeyPress() {
values := reflect.ValueOf(e.KeyMap)
values := reflect.ValueOf(e.Settings.KeyMap)
for i := 0; i < values.NumField(); i++ {
key := values.Field(i).Interface().(ebiten.Key)
@@ -25,33 +25,33 @@ func (e *Engine) ClearKeyPresed() {
}
func (e *Engine) UpPressed() bool {
return e.PressedKey == e.KeyMap.Up
return e.PressedKey == e.Settings.KeyMap.Up
}
func (e *Engine) DownPressed() bool {
return e.PressedKey == e.KeyMap.Down
return e.PressedKey == e.Settings.KeyMap.Down
}
func (e *Engine) RightPressed() bool {
return e.PressedKey == e.KeyMap.Right
return e.PressedKey == e.Settings.KeyMap.Right
}
func (e *Engine) LeftPressed() bool {
return e.PressedKey == e.KeyMap.Left
return e.PressedKey == e.Settings.KeyMap.Left
}
func (e *Engine) Action0Pressed() bool {
return e.PressedKey == e.KeyMap.Action0
return e.PressedKey == e.Settings.KeyMap.Action0
}
func (e *Engine) Action1Pressed() bool {
return e.PressedKey == e.KeyMap.Action1
return e.PressedKey == e.Settings.KeyMap.Action1
}
func (e *Engine) Action2Pressed() bool {
return e.PressedKey == e.KeyMap.Action2
return e.PressedKey == e.Settings.KeyMap.Action2
}
func (e *Engine) Action3Pressed() bool {
return e.PressedKey == e.KeyMap.Action3
return e.PressedKey == e.Settings.KeyMap.Action3
}

View File

@@ -11,7 +11,6 @@ type Engine struct {
Domain entity.DomainInterface
Settings *entity.Settings
KContext *entity.KContext
KeyMap entity.KeyMap
PressedKey ebiten.Key
}

View File

@@ -1,14 +0,0 @@
package entity
import "github.com/hajimehoshi/ebiten"
type KeyMap struct {
Up ebiten.Key
Down ebiten.Key
Right ebiten.Key
Left ebiten.Key
Action0 ebiten.Key
Action1 ebiten.Key
Action2 ebiten.Key
Action3 ebiten.Key
}

View File

@@ -1,5 +1,18 @@
package entity
import "github.com/hajimehoshi/ebiten"
type KeyMap struct {
Up ebiten.Key
Down ebiten.Key
Right ebiten.Key
Left ebiten.Key
Action0 ebiten.Key
Action1 ebiten.Key
Action2 ebiten.Key
Action3 ebiten.Key
}
type ScreenSettings struct {
Width int
Height int
@@ -8,4 +21,5 @@ type ScreenSettings struct {
type Settings struct {
Name string
Screen *ScreenSettings
KeyMap *KeyMap
}

View File

@@ -9,7 +9,6 @@ import (
type Konstructor struct {
Domain entity.DomainInterface
KeyMap entity.KeyMap
Settings *entity.Settings
KContext *entity.KContext
}
@@ -29,7 +28,6 @@ func (k Konstructor) Run() {
ebiten.RunGame(&engine.Engine{
KContext: k.KContext,
Domain: k.Domain,
KeyMap: k.KeyMap,
Settings: k.Settings,
})
}