From 41a32a8fe50c96cfe17afb4c2bd745b4fa75061d Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Wed, 5 Jul 2023 22:55:37 +0200 Subject: [PATCH] move GetFontFace into FontLayout struct --- konstructor/engine/engine.utils.go | 14 -------------- konstructor/engine/screen.dialog.go | 2 +- konstructor/engine/screen.menu.go | 2 +- konstructor/entity/entity.font.go | 19 ++++++++++++++++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/konstructor/engine/engine.utils.go b/konstructor/engine/engine.utils.go index faf6a7c..2e28c84 100644 --- a/konstructor/engine/engine.utils.go +++ b/konstructor/engine/engine.utils.go @@ -2,7 +2,6 @@ package engine import ( "bytes" - "game/konstructor/entity" "image" "io/ioutil" "log" @@ -10,8 +9,6 @@ import ( _ "image/png" "github.com/hajimehoshi/ebiten" - "golang.org/x/image/font" - "golang.org/x/image/font/opentype" ) func LoadImage(path string) *ebiten.Image { @@ -33,14 +30,3 @@ func LoadImage(path string) *ebiten.Image { return out } - -func GetFontFace(layout entity.FontLayout) font.Face { - file, _ := ioutil.ReadFile(layout.Path) - tt, _ := opentype.Parse(file) - face, _ := opentype.NewFace(tt, &opentype.FaceOptions{ - Size: layout.DPI, - DPI: layout.Size, - Hinting: font.HintingVertical, - }) - return face -} diff --git a/konstructor/engine/screen.dialog.go b/konstructor/engine/screen.dialog.go index bc27834..e0d13f7 100644 --- a/konstructor/engine/screen.dialog.go +++ b/konstructor/engine/screen.dialog.go @@ -25,7 +25,7 @@ func (e *Engine) DialogUpdate() { func (e *Engine) DialogDraw(screen *ebiten.Image) { dialog := e.Domain.GetDialog(e.KContext.ScreenValue) - face := GetFontFace(dialog.Layout.ChoiceFont) + face := dialog.Layout.ChoiceFont.GetFontFace() for i, choice := range dialog.Choices { offset := int(dialog.Layout.ChoiceFont.Size) * (i + 1) diff --git a/konstructor/engine/screen.menu.go b/konstructor/engine/screen.menu.go index 2434244..7140128 100644 --- a/konstructor/engine/screen.menu.go +++ b/konstructor/engine/screen.menu.go @@ -25,7 +25,7 @@ func (e *Engine) MenuUpdate() { func (e *Engine) MenuDraw(screen *ebiten.Image) { menu := e.Domain.GetMenu(e.KContext.ScreenValue) - face := GetFontFace(menu.Layout.MenuItemFont) + face := menu.Layout.MenuItemFont.GetFontFace() for i, menu_item := range menu.MenuItems { color := menu.GetMenuItemColor(i) diff --git a/konstructor/entity/entity.font.go b/konstructor/entity/entity.font.go index 02746e7..aedaede 100644 --- a/konstructor/entity/entity.font.go +++ b/konstructor/entity/entity.font.go @@ -1,6 +1,12 @@ package entity -import "image/color" +import ( + "image/color" + "io/ioutil" + + "golang.org/x/image/font" + "golang.org/x/image/font/opentype" +) type FontLayout struct { Path string @@ -9,3 +15,14 @@ type FontLayout struct { Color color.Color SelectedColor color.Color } + +func (fl *FontLayout) GetFontFace() font.Face { + file, _ := ioutil.ReadFile(fl.Path) + tt, _ := opentype.Parse(file) + face, _ := opentype.NewFace(tt, &opentype.FaceOptions{ + Size: fl.DPI, + DPI: fl.Size, + Hinting: font.HintingVertical, + }) + return face +}