feat: added way to acquire the input runes.

This commit is contained in:
Andrey Parhomenko 2024-01-14 03:51:11 +03:00
parent 6994dff47b
commit 7dcf0eeca8
5 changed files with 21 additions and 11 deletions

View file

@ -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{

View file

@ -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

View file

@ -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())
}

View file

@ -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

View file

@ -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,
},