render GetImage and replace Options prefix to Args

This commit is contained in:
2023-07-06 01:20:23 +02:00
parent 731548ef86
commit 701205ac82
17 changed files with 61 additions and 52 deletions

View File

@@ -1,9 +1,7 @@
package engine
import (
"bytes"
"image"
"io/ioutil"
"game/konstructor/entity"
"log"
_ "image/png"
@@ -11,22 +9,11 @@ import (
"github.com/hajimehoshi/ebiten"
)
func LoadImage(path string) *ebiten.Image {
file, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(bytes.NewReader(file))
if err != nil {
log.Fatal(err)
}
func (e *Engine) GetImage(render_options entity.Render) *ebiten.Image {
img := render_options.GetImage()
out, err := ebiten.NewImageFromImage(img, 0)
if err != nil {
log.Fatal(err)
}
return out
}

View File

@@ -10,7 +10,7 @@ type EngineWrapper struct {
Engine Engine
}
func (ew *EngineWrapper) Init(options entity.EngineOptions) {
func (ew *EngineWrapper) Init(options entity.EngineArgs) {
ew.Engine = Engine{
KContext: options.KContext,
Domain: options.Domain,

View File

@@ -8,7 +8,7 @@ import (
func (e *Engine) PlaygroundUpdate() {
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
e.Domain.Process(entity.DomainProcessOptions{
e.Domain.Process(entity.DomainProcessArgs{
Level: &level,
KContext: e.KContext,
})

View File

@@ -5,7 +5,7 @@ import "image/color"
type DialogMap map[string]Dialog
type DialogLayout struct {
Background string
Render Render
ChoiceFont FontLayout
}

View File

@@ -18,10 +18,10 @@ type DomainInterface interface {
RemoveFromInventory(item *Item) bool
UseInventoryItem(item *Item) bool
Process(DomainProcessOptions)
Process(DomainProcessArgs)
}
type DomainProcessOptions struct {
type DomainProcessArgs struct {
Level *Level
KContext *KContext
}

View File

@@ -1,12 +1,12 @@
package entity
type EngineOptions struct {
type EngineArgs struct {
Domain DomainInterface
KContext *KContext
Settings *Settings
}
type EngineWrapperInterface interface {
Init(options EngineOptions)
Init(options EngineArgs)
Run()
}

View File

@@ -18,11 +18,11 @@ type FontLayout struct {
func (fl *FontLayout) GetFontFace() font.Face {
file, _ := ioutil.ReadFile(fl.Path)
tt, _ := opentype.Parse(file)
face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
true_type, _ := opentype.Parse(file)
font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{
Size: fl.DPI,
DPI: fl.Size,
Hinting: font.HintingVertical,
})
return face
return font_face
}

View File

@@ -1,8 +1,8 @@
package entity
type ItemType struct {
ID string
RenderOptions RenderOptions
ID string
Render Render
}
type Item struct {

View File

@@ -5,7 +5,6 @@ import "image/color"
type MenuMap map[string]Menu
type MenuLayout struct {
Background string
MenuItemFont FontLayout
}

View File

@@ -1,8 +1,8 @@
package entity
type NPCType struct {
ID string
RenderOptions RenderOptions
ID string
Render Render
}
type NPC struct {

View File

@@ -1,8 +1,8 @@
package entity
type ObjectType struct {
ID string
RenderOptions RenderOptions
ID string
Render Render
}
type Object struct {

View File

@@ -11,8 +11,8 @@ type Inventory struct {
}
type Player struct {
ID string
RenderOptions RenderOptions
Position Position
Inventory Inventory
ID string
Render Render
Position Position
Inventory Inventory
}

View File

@@ -6,18 +6,11 @@ type Position struct {
Z int
}
type RenderOptions struct {
Image string
Width int
Height int
Visible bool
}
type Playground struct {
Background string
Objects []Object
NPCs []NPC
Items []Item
Render Render
Objects []Object
NPCs []NPC
Items []Item
}
type Level struct {

View File

@@ -0,0 +1,28 @@
package entity
import (
"bytes"
"image"
"io/ioutil"
"log"
)
type Render struct {
Image string
Width int
Height int
Visible bool
}
func (ro *Render) GetImage() image.Image {
file, err := ioutil.ReadFile(ro.Image)
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(bytes.NewReader(file))
if err != nil {
log.Fatal(err)
}
return img
}

View File

@@ -13,7 +13,7 @@ type Konstructor struct {
func (k Konstructor) Init() {
k.Domain.Init()
k.EngineWrapper.Init(entity.EngineOptions{
k.EngineWrapper.Init(entity.EngineArgs{
Domain: k.Domain,
KContext: k.KContext,
Settings: k.Settings,