EngineWrapper, engine via interfaces

This commit is contained in:
2023-07-05 18:31:27 +02:00
parent 25b03cfd2f
commit ad30de96d9
4 changed files with 91 additions and 35 deletions

View File

@@ -0,0 +1,25 @@
package engine
import (
"game/konstructor/entity"
"github.com/hajimehoshi/ebiten"
)
type EngineWrapper struct {
Engine Engine
}
func (ew *EngineWrapper) Init(options entity.EngineOptions) {
ew.Engine = Engine{
KContext: &options.KContext,
Domain: options.Domain,
Settings: &options.Settings,
}
ebiten.SetWindowSize(options.Settings.Screen.Width, options.Settings.Screen.Height)
ebiten.SetWindowTitle(options.Settings.Name)
}
func (ew *EngineWrapper) Run() {
ebiten.RunGame(&ew.Engine)
}

View File

@@ -0,0 +1,37 @@
package entity
type EngineInterface interface {
ClearKeyPresed()
UpPressed() bool
DownPressed() bool
RightPressed() bool
LeftPressed() bool
Action0Pressed() bool
Action1Pressed() bool
Action2Pressed() bool
Action3Pressed() bool
ScreenTypeIs(name string) bool
Update(screen any) error
Draw(screen any)
AddToInventory(item *Item)
RemoveFromInventory(item *Item)
UseInventoryItem(item *Item)
DialogDraw(screen any)
DialogUpdate()
MenuDraw(screen any)
MenuUpdate()
PlaygroundDraw(screen any)
PlaygroundUpdate()
}
type EngineOptions struct {
Engine EngineInterface
Domain DomainInterface
KContext KContext
Settings Settings
}
type EngineWrapperInterface interface {
Init(options EngineOptions)
Run()
}

View File

@@ -1,33 +1,22 @@
package konstructor
import (
"game/konstructor/engine"
"game/konstructor/entity"
"github.com/hajimehoshi/ebiten"
)
type Konstructor struct {
Domain entity.DomainInterface
Settings *entity.Settings
KContext *entity.KContext
Domain entity.DomainInterface
Settings entity.Settings
KContext *entity.KContext
EngineWrapper entity.EngineWrapperInterface
}
func (k Konstructor) Init() {
k.Domain.Init()
k.SetWindow()
k.Run()
}
func (k Konstructor) SetWindow() {
ebiten.SetWindowSize(k.Settings.Screen.Width, k.Settings.Screen.Height)
ebiten.SetWindowTitle(k.Settings.Name)
}
func (k Konstructor) Run() {
ebiten.RunGame(&engine.Engine{
KContext: k.KContext,
k.EngineWrapper.Init(entity.EngineOptions{
KContext: *k.KContext,
Domain: k.Domain,
Settings: k.Settings,
})
k.EngineWrapper.Run()
}