render GetImage and replace Options prefix to Args
This commit is contained in:
@@ -9,7 +9,9 @@ func (d *Domain) InitLevel() {
|
|||||||
Name: "Level I.",
|
Name: "Level I.",
|
||||||
Playgrounds: []entity.Playground{
|
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{
|
Objects: []entity.Object{
|
||||||
{
|
{
|
||||||
ID: "test_object",
|
ID: "test_object",
|
||||||
@@ -20,7 +22,7 @@ func (d *Domain) InitLevel() {
|
|||||||
},
|
},
|
||||||
Type: entity.ObjectType{
|
Type: entity.ObjectType{
|
||||||
ID: "test_object_type",
|
ID: "test_object_type",
|
||||||
RenderOptions: entity.RenderOptions{
|
Render: entity.Render{
|
||||||
Image: "assets/images/objects/test_object.png",
|
Image: "assets/images/objects/test_object.png",
|
||||||
Width: 30,
|
Width: 30,
|
||||||
Height: 30,
|
Height: 30,
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ package domain
|
|||||||
|
|
||||||
import "game/konstructor/entity"
|
import "game/konstructor/entity"
|
||||||
|
|
||||||
func (d *Domain) Process(options entity.DomainProcessOptions) {
|
func (d *Domain) Process(options entity.DomainProcessArgs) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"game/konstructor/entity"
|
||||||
"image"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
@@ -11,22 +9,11 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadImage(path string) *ebiten.Image {
|
func (e *Engine) GetImage(render_options entity.Render) *ebiten.Image {
|
||||||
|
img := render_options.GetImage()
|
||||||
file, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
img, _, err := image.Decode(bytes.NewReader(file))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := ebiten.NewImageFromImage(img, 0)
|
out, err := ebiten.NewImageFromImage(img, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type EngineWrapper struct {
|
|||||||
Engine Engine
|
Engine Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ew *EngineWrapper) Init(options entity.EngineOptions) {
|
func (ew *EngineWrapper) Init(options entity.EngineArgs) {
|
||||||
ew.Engine = Engine{
|
ew.Engine = Engine{
|
||||||
KContext: options.KContext,
|
KContext: options.KContext,
|
||||||
Domain: options.Domain,
|
Domain: options.Domain,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func (e *Engine) PlaygroundUpdate() {
|
func (e *Engine) PlaygroundUpdate() {
|
||||||
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
level := e.Domain.GetLevel(e.KContext.CurrentLevel)
|
||||||
e.Domain.Process(entity.DomainProcessOptions{
|
e.Domain.Process(entity.DomainProcessArgs{
|
||||||
Level: &level,
|
Level: &level,
|
||||||
KContext: e.KContext,
|
KContext: e.KContext,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import "image/color"
|
|||||||
type DialogMap map[string]Dialog
|
type DialogMap map[string]Dialog
|
||||||
|
|
||||||
type DialogLayout struct {
|
type DialogLayout struct {
|
||||||
Background string
|
Render Render
|
||||||
ChoiceFont FontLayout
|
ChoiceFont FontLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ type DomainInterface interface {
|
|||||||
RemoveFromInventory(item *Item) bool
|
RemoveFromInventory(item *Item) bool
|
||||||
UseInventoryItem(item *Item) bool
|
UseInventoryItem(item *Item) bool
|
||||||
|
|
||||||
Process(DomainProcessOptions)
|
Process(DomainProcessArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DomainProcessOptions struct {
|
type DomainProcessArgs struct {
|
||||||
Level *Level
|
Level *Level
|
||||||
KContext *KContext
|
KContext *KContext
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
type EngineOptions struct {
|
type EngineArgs struct {
|
||||||
Domain DomainInterface
|
Domain DomainInterface
|
||||||
KContext *KContext
|
KContext *KContext
|
||||||
Settings *Settings
|
Settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
type EngineWrapperInterface interface {
|
type EngineWrapperInterface interface {
|
||||||
Init(options EngineOptions)
|
Init(options EngineArgs)
|
||||||
Run()
|
Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ type FontLayout struct {
|
|||||||
|
|
||||||
func (fl *FontLayout) GetFontFace() font.Face {
|
func (fl *FontLayout) GetFontFace() font.Face {
|
||||||
file, _ := ioutil.ReadFile(fl.Path)
|
file, _ := ioutil.ReadFile(fl.Path)
|
||||||
tt, _ := opentype.Parse(file)
|
true_type, _ := opentype.Parse(file)
|
||||||
face, _ := opentype.NewFace(tt, &opentype.FaceOptions{
|
font_face, _ := opentype.NewFace(true_type, &opentype.FaceOptions{
|
||||||
Size: fl.DPI,
|
Size: fl.DPI,
|
||||||
DPI: fl.Size,
|
DPI: fl.Size,
|
||||||
Hinting: font.HintingVertical,
|
Hinting: font.HintingVertical,
|
||||||
})
|
})
|
||||||
return face
|
return font_face
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package entity
|
|||||||
|
|
||||||
type ItemType struct {
|
type ItemType struct {
|
||||||
ID string
|
ID string
|
||||||
RenderOptions RenderOptions
|
Render Render
|
||||||
}
|
}
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import "image/color"
|
|||||||
type MenuMap map[string]Menu
|
type MenuMap map[string]Menu
|
||||||
|
|
||||||
type MenuLayout struct {
|
type MenuLayout struct {
|
||||||
Background string
|
|
||||||
MenuItemFont FontLayout
|
MenuItemFont FontLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package entity
|
|||||||
|
|
||||||
type NPCType struct {
|
type NPCType struct {
|
||||||
ID string
|
ID string
|
||||||
RenderOptions RenderOptions
|
Render Render
|
||||||
}
|
}
|
||||||
|
|
||||||
type NPC struct {
|
type NPC struct {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package entity
|
|||||||
|
|
||||||
type ObjectType struct {
|
type ObjectType struct {
|
||||||
ID string
|
ID string
|
||||||
RenderOptions RenderOptions
|
Render Render
|
||||||
}
|
}
|
||||||
|
|
||||||
type Object struct {
|
type Object struct {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type Inventory struct {
|
|||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
ID string
|
ID string
|
||||||
RenderOptions RenderOptions
|
Render Render
|
||||||
Position Position
|
Position Position
|
||||||
Inventory Inventory
|
Inventory Inventory
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ type Position struct {
|
|||||||
Z int
|
Z int
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenderOptions struct {
|
|
||||||
Image string
|
|
||||||
Width int
|
|
||||||
Height int
|
|
||||||
Visible bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Playground struct {
|
type Playground struct {
|
||||||
Background string
|
Render Render
|
||||||
Objects []Object
|
Objects []Object
|
||||||
NPCs []NPC
|
NPCs []NPC
|
||||||
Items []Item
|
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() {
|
func (k Konstructor) Init() {
|
||||||
k.Domain.Init()
|
k.Domain.Init()
|
||||||
k.EngineWrapper.Init(entity.EngineOptions{
|
k.EngineWrapper.Init(entity.EngineArgs{
|
||||||
Domain: k.Domain,
|
Domain: k.Domain,
|
||||||
KContext: k.KContext,
|
KContext: k.KContext,
|
||||||
Settings: k.Settings,
|
Settings: k.Settings,
|
||||||
|
|||||||
Reference in New Issue
Block a user