render GetImage and replace Options prefix to Args
This commit is contained in:
@@ -9,7 +9,9 @@ func (d *Domain) InitLevel() {
|
||||
Name: "Level I.",
|
||||
Playgrounds: []entity.Playground{
|
||||
{
|
||||
Background: "assets/images/playgrounds/level_1_playground_1.png",
|
||||
Render: entity.Render{
|
||||
Image: "assets/images/playgrounds/level_1_playground_1.png",
|
||||
},
|
||||
Objects: []entity.Object{
|
||||
{
|
||||
ID: "test_object",
|
||||
@@ -20,7 +22,7 @@ func (d *Domain) InitLevel() {
|
||||
},
|
||||
Type: entity.ObjectType{
|
||||
ID: "test_object_type",
|
||||
RenderOptions: entity.RenderOptions{
|
||||
Render: entity.Render{
|
||||
Image: "assets/images/objects/test_object.png",
|
||||
Width: 30,
|
||||
Height: 30,
|
||||
|
||||
@@ -2,6 +2,6 @@ package domain
|
||||
|
||||
import "game/konstructor/entity"
|
||||
|
||||
func (d *Domain) Process(options entity.DomainProcessOptions) {
|
||||
func (d *Domain) Process(options entity.DomainProcessArgs) {
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import "image/color"
|
||||
type DialogMap map[string]Dialog
|
||||
|
||||
type DialogLayout struct {
|
||||
Background string
|
||||
Render Render
|
||||
ChoiceFont FontLayout
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package entity
|
||||
|
||||
type ItemType struct {
|
||||
ID string
|
||||
RenderOptions RenderOptions
|
||||
Render Render
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
|
||||
@@ -5,7 +5,6 @@ import "image/color"
|
||||
type MenuMap map[string]Menu
|
||||
|
||||
type MenuLayout struct {
|
||||
Background string
|
||||
MenuItemFont FontLayout
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package entity
|
||||
|
||||
type NPCType struct {
|
||||
ID string
|
||||
RenderOptions RenderOptions
|
||||
Render Render
|
||||
}
|
||||
|
||||
type NPC struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package entity
|
||||
|
||||
type ObjectType struct {
|
||||
ID string
|
||||
RenderOptions RenderOptions
|
||||
Render Render
|
||||
}
|
||||
|
||||
type Object struct {
|
||||
|
||||
@@ -12,7 +12,7 @@ type Inventory struct {
|
||||
|
||||
type Player struct {
|
||||
ID string
|
||||
RenderOptions RenderOptions
|
||||
Render Render
|
||||
Position Position
|
||||
Inventory Inventory
|
||||
}
|
||||
|
||||
@@ -6,15 +6,8 @@ type Position struct {
|
||||
Z int
|
||||
}
|
||||
|
||||
type RenderOptions struct {
|
||||
Image string
|
||||
Width int
|
||||
Height int
|
||||
Visible bool
|
||||
}
|
||||
|
||||
type Playground struct {
|
||||
Background string
|
||||
Render Render
|
||||
Objects []Object
|
||||
NPCs []NPC
|
||||
Items []Item
|
||||
|
||||
28
konstructor/entity/entity.render.go
Normal file
28
konstructor/entity/entity.render.go
Normal 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
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user