From 7dcf0eeca8faf5a6bd5da9b39e76b9957860c16e Mon Sep 17 00:00:00 2001 From: surdeus Date: Sun, 14 Jan 2024 03:51:11 +0300 Subject: [PATCH] feat: added way to acquire the input runes. --- cmd/test/main.go | 4 ++-- cmd/test/player.go | 5 ++--- cmd/test/text.go | 9 ++++++--- engine.go | 10 +++++++++- text.go | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cmd/test/main.go b/cmd/test/main.go index a7e4149..2fb2c83 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -75,13 +75,13 @@ func main() { circle.Visible = true //e.Spawn(circle) - txt := &gg.Text{} + txt := &Text{} txt.Transform = gg.T() //txt.Position = gg.V2(400) txt.Color = gg.Rgba(1, 1, 1, 1) txt.Layer = HighestL txt.Visible = true - txt.Text = "Hello, World!\nПривет, Мир!" + txt.Data = "Hello, World!\nПривет, Мир!" txt.Face, err = gg.MakeFaceFromTtf( bytes.NewReader(fonts.MPlus1pRegular_ttf), &gg.TtfFaceOptions{ diff --git a/cmd/test/player.go b/cmd/test/player.go index 64191e5..f45b78a 100644 --- a/cmd/test/player.go +++ b/cmd/test/player.go @@ -2,7 +2,7 @@ package main import ( //"math/rand" - "fmt" + //"fmt" "time" ) @@ -20,11 +20,10 @@ func NewPlayer() *Player { ret.Transform = gg.T() ret.Scale = gg.V2(1) ret.Around = gg.V2(.5) - ret.MoveSpeed = 30. + ret.MoveSpeed = 40. ret.ScaleSpeed = .2 ret.Animations = playerAnimations ret.TimeBetweenFrames = time.Second/10 - fmt.Println("player-walk", ret.Animate(Stand)) ret.Visible = true ret.Layer = PlayerL diff --git a/cmd/test/text.go b/cmd/test/text.go index 9cca67c..bab9183 100644 --- a/cmd/test/text.go +++ b/cmd/test/text.go @@ -2,6 +2,7 @@ package main import ( "vultras.su/core/gg" + //"fmt" ) type Objecter interface{ @@ -17,8 +18,10 @@ type Context2 struct { *gg.Context } -type Text Wrap[struct{ +type Text struct{ gg.Text -}] +} -//func (txt *Text) Update() +func (txt *Text) Update(c *Context) { + txt.Data += string(c.Runes()) +} diff --git a/engine.go b/engine.go index 2bad949..7b82329 100644 --- a/engine.go +++ b/engine.go @@ -4,7 +4,7 @@ import ( "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" "vultras.su/core/gods/maps" - //"fmt" + "fmt" "time" "slices" "sync" @@ -85,6 +85,8 @@ type Engine struct { // Frame. frame uint + + runes []rune } type engine Engine @@ -226,10 +228,16 @@ func (e *Engine) AbsCursorPosition() Vector { return e.CursorPosition().Apply(e.Camera.AbsMatrix()) } +func (e *Engine) Runes() []rune { + return e.runes +} + func (e *engine) Update() error { eng := (*Engine)(e) e.dt = time.Since(e.lastTime) + e.runes = ebiten.AppendInputChars(e.runes[:0]) + fmt.Println("runes:", e.runes) // Buffering the context for faster. e.prevKeys = e.keys diff --git a/text.go b/text.go index e34c5d3..544054b 100644 --- a/text.go +++ b/text.go @@ -48,7 +48,7 @@ func NewTtfFace(fnt *TtfFont, opts *TtfFaceOptions) (Face, error) { type Text struct { Object Transform - Text string + Data string Face Face Colority Visibility @@ -59,7 +59,7 @@ func (txt *Text) Draw(c *Context) []EVertex { m.Concat(c.Camera.RealMatrix()) //x, y := txt.Position.XY() //text.Draw(c.Image) - text.DrawWithOptions(c.Image, txt.Text, txt.Face, + text.DrawWithOptions(c.Image, txt.Data, txt.Face, &ebiten.DrawImageOptions{ GeoM: m, },