gg/cmd/test/debug.go
2024-06-02 00:01:17 +05:00

115 lines
2.5 KiB
Go

package main
import "surdeus.su/core/gg"
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
import (
"strings"
"fmt"
)
type Debug struct {
ox.ObjectImpl
ox.Visibility
}
func (d *Debug) OnUpdate(c Context) {
for _, key := range c.Events().Keyboard.KeyDowns {
switch key.Key {
case gg.KeyF11:
d.ToggleVisibility()
//d.Visible = !d.IsVisible()
}
}
}
func (d *Debug) OnStart(c Context) {
d.Visible = true
}
func (d *Debug) GetLayer() gg.Layer {return LayerHighest}
func (d *Debug) Draw(c Context) *gg.Drawing {
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.Engine().TPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"fps: %d", int(c.Engine().FPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"dframe: %d", int(c.Engine().Dframe()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"frame: %d", int(c.Engine().Frame()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"relPlayerPos: %v", relPlayer.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absPlayerPos: %v", player.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"relTriPos: %v", relTri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriPos: %v", tri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriRot: %v", mx.Degree(tri.GetRotation()),
))
keys := []string{}
for _, k := range e.GetKeyboardKeys() {
keys = append(keys, k.String())
}
keyStrs = append(keyStrs, fmt.Sprintf(
"keys: %s", strings.Join(keys, ", "),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"buttons: %v", c.Engine().MouseButtons(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"wheel: %v", c.Engine().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",
camera.GetPosition().X,
camera.GetPosition().Y,
))
keyStrs = append(keyStrs, fmt.Sprintf(
"realCursorPos: %v", e.GetRealCursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf(
"absCursorPos: %v", e.GetAbsCursorPosition() ))
keyStrs = append(keyStrs,
fmt.Sprintf(
"absWinSize: %v",
c.Engine().GetAbsWinSize(),
),
)
e.DebugPrint(c.Image(),
strings.Join(keyStrs, "\n"))
return nil
}