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 circle.Visible = true
//e.Spawn(circle) //e.Spawn(circle)
txt := &gg.Text{} txt := &Text{}
txt.Transform = gg.T() txt.Transform = gg.T()
//txt.Position = gg.V2(400) //txt.Position = gg.V2(400)
txt.Color = gg.Rgba(1, 1, 1, 1) txt.Color = gg.Rgba(1, 1, 1, 1)
txt.Layer = HighestL txt.Layer = HighestL
txt.Visible = true txt.Visible = true
txt.Text = "Hello, World!\nПривет, Мир!" txt.Data = "Hello, World!\nПривет, Мир!"
txt.Face, err = gg.MakeFaceFromTtf( txt.Face, err = gg.MakeFaceFromTtf(
bytes.NewReader(fonts.MPlus1pRegular_ttf), bytes.NewReader(fonts.MPlus1pRegular_ttf),
&gg.TtfFaceOptions{ &gg.TtfFaceOptions{

View file

@ -2,7 +2,7 @@ package main
import ( import (
//"math/rand" //"math/rand"
"fmt" //"fmt"
"time" "time"
) )
@ -20,11 +20,10 @@ func NewPlayer() *Player {
ret.Transform = gg.T() ret.Transform = gg.T()
ret.Scale = gg.V2(1) ret.Scale = gg.V2(1)
ret.Around = gg.V2(.5) ret.Around = gg.V2(.5)
ret.MoveSpeed = 30. ret.MoveSpeed = 40.
ret.ScaleSpeed = .2 ret.ScaleSpeed = .2
ret.Animations = playerAnimations ret.Animations = playerAnimations
ret.TimeBetweenFrames = time.Second/10 ret.TimeBetweenFrames = time.Second/10
fmt.Println("player-walk", ret.Animate(Stand))
ret.Visible = true ret.Visible = true
ret.Layer = PlayerL ret.Layer = PlayerL

View file

@ -2,6 +2,7 @@ package main
import ( import (
"vultras.su/core/gg" "vultras.su/core/gg"
//"fmt"
) )
type Objecter interface{ type Objecter interface{
@ -17,8 +18,10 @@ type Context2 struct {
*gg.Context *gg.Context
} }
type Text Wrap[struct{ type Text struct{
gg.Text 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"
"github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/hajimehoshi/ebiten/v2/inpututil"
"vultras.su/core/gods/maps" "vultras.su/core/gods/maps"
//"fmt" "fmt"
"time" "time"
"slices" "slices"
"sync" "sync"
@ -85,6 +85,8 @@ type Engine struct {
// Frame. // Frame.
frame uint frame uint
runes []rune
} }
type engine Engine type engine Engine
@ -226,10 +228,16 @@ func (e *Engine) AbsCursorPosition() Vector {
return e.CursorPosition().Apply(e.Camera.AbsMatrix()) return e.CursorPosition().Apply(e.Camera.AbsMatrix())
} }
func (e *Engine) Runes() []rune {
return e.runes
}
func (e *engine) Update() error { func (e *engine) Update() error {
eng := (*Engine)(e) eng := (*Engine)(e)
e.dt = time.Since(e.lastTime) e.dt = time.Since(e.lastTime)
e.runes = ebiten.AppendInputChars(e.runes[:0])
fmt.Println("runes:", e.runes)
// Buffering the context for faster. // Buffering the context for faster.
e.prevKeys = e.keys e.prevKeys = e.keys

View file

@ -48,7 +48,7 @@ func NewTtfFace(fnt *TtfFont, opts *TtfFaceOptions) (Face, error) {
type Text struct { type Text struct {
Object Object
Transform Transform
Text string Data string
Face Face Face Face
Colority Colority
Visibility Visibility
@ -59,7 +59,7 @@ func (txt *Text) Draw(c *Context) []EVertex {
m.Concat(c.Camera.RealMatrix()) m.Concat(c.Camera.RealMatrix())
//x, y := txt.Position.XY() //x, y := txt.Position.XY()
//text.Draw(c.Image) //text.Draw(c.Image)
text.DrawWithOptions(c.Image, txt.Text, txt.Face, text.DrawWithOptions(c.Image, txt.Data, txt.Face,
&ebiten.DrawImageOptions{ &ebiten.DrawImageOptions{
GeoM: m, GeoM: m,
}, },