gg/cmd/test/debug.go
2024-05-19 23:11:58 +05:00

101 lines
2.2 KiB
Go

package main
import "surdeus.su/core/gg"
import (
"strings"
"fmt"
)
type Debug struct {
gg.Object
gg.Visibility
}
func (d *Debug) Update(c *Context) {
for _, e := range c.Events {
switch ec := e.(type) {
case *gg.KeyDown:
switch ec.Key {
case gg.KeyF11:
d.Visible = !d.Visible
}
}
}
}
func (d *Debug) Draw(c *Context) []gg.EVertex {
e := c.Engine
relTri := tri.Rel()
relPlayer := player.Rel()
keyStrs := []string{}
keyStrs = append(keyStrs, fmt.Sprintf(
"counter: %d", counter,
))
keyStrs = append(keyStrs, fmt.Sprintf(
"tps: %d", int(c.Tps()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"fps: %d", int(c.Fps()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"dframe: %d", int(c.Dframe()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"frame: %d", int(c.Frame()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"relPlayerPos: %v", relPlayer.Position(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absPlayerPos: %v", player.Position(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"relTriPos: %v", relTri.Position(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriPos: %v", tri.Position(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriRot: %v", gg.Degree(tri.Rotation()),
))
keys := []string{}
for _, k := range e.Keys() {
keys = append(keys, k.String())
}
keyStrs = append(keyStrs, fmt.Sprintf(
"keys: %s", strings.Join(keys, ", "),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"buttons: %v", c.MouseButtons(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"wheel: %v", c.Wheel(),
))
/*if rectMove.ContainsPoint(e.AbsCursorPosition()) {
keyStrs = append(keyStrs, "contains cursor")
}
if rectMove.Vertices().Contained(rect).Len() > 0 ||
rect.Vertices().Contained(rectMove).Len() > 0 {
keyStrs = append(keyStrs, "rectangles intersect")
}*/
keyStrs = append(keyStrs, fmt.Sprintf(
"camera position: %v %v",
c.Camera.Position().X,
c.Camera.Position().Y,
))
keyStrs = append(keyStrs, fmt.Sprintf("realCursorPos: %v", e.CursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf("absCursorPos: %v", e.AbsCursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf("absWinSize: %v", c.AbsWinSize()))
e.DebugPrint(c.Image,
strings.Join(keyStrs, "\n"))
return nil
}